Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- protected void onCreate (Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- ImageView imageView1 = (ImageView) findViewById( R.id.imageView1 );
- imageView1.setOnClickListener( this );
- ImageView imageView2 = (ImageView) findViewById( R.id.imageView2 );
- imageView2.setOnClickListener( this );
- ImageView imageView3 = (ImageView) findViewById( R.id.imageView3 );
- imageView3.setOnClickListener( this );
- ImageView imageView4 = (ImageView) findViewById( R.id.imageView4 );
- imageView4.setOnClickListener( this );
- }
- @Override
- public void onClick(View v) {
- switch (v.getId()) {
- case R.id.imageView1:
- openActivity1();
- Intent intent = new Intent( this, Activity1.class );
- startActivity( intent );
- break;
- case R.id.imageView2:
- openActivity2();
- Intent intent1 = new Intent( this, Activity2.class );
- startActivity( intent1 );
- break;
- case R.id.imageView3:
- openActivity3();
- Intent intent2 = new Intent( this, Activity3.class );
- startActivity( intent2 );
- break;
- case R.id.imageView4:
- openActivity4();
- Intent intent3 = new Intent( this, Activity4.class );
- startActivity( intent3 );
- break;
- default:
- openActivity1();
- }
- }
- private void openActivity1() {
- }
- private void openActivity2() {
- }
- private void openActivity3() {
- }
- private void openActivity4() {
- } }
- private static final String TAG = LoginWithAmazonActivity.class.getName();
- private TextView mProfileText;
- private Button mLogoutButton;
- private ProgressBar mLogInProgress;
- private RequestContext requestContext;
- private boolean mIsLoggedIn;
- private View mLoginButton;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- requestContext = RequestContext.create(this);
- requestContext.registerListener(new AuthorizeListener() {
- @Override
- public void onSuccess(AuthorizeResult authorizeResult) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- // At this point we know the authorization completed, so remove the ability to return to the app to sign-in again
- setLoggingInState(true);
- }
- });
- fetchUserProfile();
- }
- @Override
- public void onError(AuthError authError) {
- Log.e(TAG, "AuthError during authorization", authError);
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- showAuthToast("Error during authorization. Please try again.");
- resetProfileView();
- setLoggingInState(false);
- }
- });
- }
- @Override
- public void onCancel(AuthCancellation authCancellation) {
- Log.e(TAG, "User cancelled authorization");
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- showAuthToast("Authorization cancelled");
- resetProfileView();
- }
- });
- }
- });
- setContentView(R.layout.activity_main);
- initializeUI();
- }
- @Override
- protected void onResume() {
- super.onResume();
- requestContext.onResume();
- }
- @Override
- protected void onStart() {
- super.onStart();
- Scope[] scopes = {ProfileScope.profile(), ProfileScope.postalCode()};
- AuthorizationManager.getToken(this, scopes, new Listener<AuthorizeResult, AuthError>() {
- @Override
- public void onSuccess(AuthorizeResult result) {
- if (result.getAccessToken() != null) {
- /* The user is signed in */
- fetchUserProfile();
- } else {
- }
- }
- @Override
- public void onError(AuthError ae) {
- /* The user is not signed in */
- }
- });
- }
- private void fetchUserProfile() {
- User.fetch(this, new Listener<User, AuthError>() {
- @Override
- public void onSuccess(User user) {
- final String name = user.getUserName();
- final String email = user.getUserEmail();
- final String account = user.getUserId();
- final String zipCode = user.getUserPostalCode();
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- updateProfileData(name, email, account, zipCode);
- }
- });
- }
- @Override
- public void onError(AuthError ae) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- setLoggedOutState();
- String errorMessage = "Error retrieving profile information.nPlease log in again";
- Toast errorToast = Toast.makeText(getApplicationContext(), errorMessage,
- private void updateProfileData(String name, String email, String account, String zipCode) {
- StringBuilder profileBuilder = new StringBuilder();
- profileBuilder.append(String.format("Welcome, %s!n", name));
- profileBuilder.append(String.format("Your email is %sn", email));
- profileBuilder.append(String.format("Your zipCode is %sn", zipCode));
- final String profile = profileBuilder.toString();
- Log.d(TAG, "Profile Response: " + profile);
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- updateProfileView(profile);
- setLoggedInState();
- }
- });
- }
- private void initializeUI() {
- mLoginButton = findViewById(R.id.login_with_amazon);
- mLoginButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- AuthorizationManager.authorize(
- new AuthorizeRequest.Builder(requestContext)
- .addScopes(ProfileScope.profile(), ProfileScope.postalCode())
- .build()
- );
- }
- });
- // Find the button with the logout ID and set up a click handler
- View logoutButton = findViewById(R.id.logout);
- logoutButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- AuthorizationManager.signOut(getApplicationContext(), new
- @Override
- public void onError(AuthError authError) {
- Log.e(TAG, "Error clearing authorization state.", authError);
- }
- });
- }
- });
- String logoutText = getString(R.string.logout);
- mProfileText = (TextView) findViewById(R.id.profile_info);
- mLogoutButton = (Button) logoutButton;
- mLogoutButton.setText(logoutText);
- mLogInProgress = (ProgressBar) findViewById(R.id.log_in_progress);
- }
- private void updateProfileView(String profileInfo) {
- Log.d(TAG, "Updating profile view");
- mProfileText.setText(profileInfo);
- }
- private void resetProfileView() {
- setLoggingInState(false);
- mProfileText.setText(getString(R.string.default_message));
- }
- private void setLoggedInState() {
- mLoginButton.setVisibility(Button.GONE);
- setLoggedInButtonsVisibility(Button.VISIBLE);
- mIsLoggedIn = true;
- setLoggingInState(false);
- }
- private void setLoggedOutState() {
- mLoginButton.setVisibility(Button.VISIBLE);
- setLoggedInButtonsVisibility(Button.GONE);
- mIsLoggedIn = false;
- resetProfileView();
- }
- private void setLoggedInButtonsVisibility(int visibility) {
- mLogoutButton.setVisibility(visibility);
- }
- private void setLoggingInState(final boolean loggingIn) {
- if (loggingIn) {
- mLoginButton.setVisibility(Button.GONE);
- setLoggedInButtonsVisibility(Button.GONE);
- mLogInProgress.setVisibility(ProgressBar.VISIBLE);
- mProfileText.setVisibility(TextView.GONE);
- } else {
- if (mIsLoggedIn) {
- setLoggedInButtonsVisibility(Button.VISIBLE);
- } else {
- mLoginButton.setVisibility(Button.VISIBLE);
- }
- mLogInProgress.setVisibility(ProgressBar.GONE);
- mProfileText.setVisibility(TextView.VISIBLE);
- }
- }
- private void showAuthToast(String authToastMessage) {
- Toast authToast = Toast.makeText(getApplicationContext(), authToastMessage, Toast.LENGTH_LONG);
- authToast.setGravity(Gravity.CENTER, 0, 0);
- authToast.show();
- }
- }
- <ImageView
- android:id="@+id/imageView1"
- android:layout_width="150dp"
- android:layout_height="150dp"
- android:src="@drawable/aggressive_momemnts"
- android:clickable="true"
- android:focusable="true"
- android:contentDescription="@string/todo" />
- <ImageView
- android:id="@+id/imageView2"
- android:layout_width="150dp"
- android:layout_height="150dp"
- android:layout_marginStart="30dp"
- android:clickable="true"
- android:focusable="true"
- android:visibility="gone"
- android:src="@drawable/best_moments"
- android:layout_marginLeft="30dp"
- android:contentDescription="@string/todo" />
- <ImageView
- android:id="@+id/imageView3"
- android:layout_width="150dp"
- android:layout_height="150dp"
- android:layout_marginStart="30dp"
- android:layout_marginEnd="99dp"
- android:clickable="true"
- android:focusable="true"
- android:src="@drawable/best_player"
- android:layout_marginLeft="30dp"
- android:layout_marginRight="99dp"
- android:contentDescription="@string/todo" />
- <ImageView
- android:id="@+id/imageView4"
- android:layout_width="150dp"
- android:layout_height="150dp"
- android:layout_marginStart="30dp"
- android:clickable="true"
- android:focusable="true"
- android:src="@drawable/coach"
- android:layout_marginLeft="30dp"
- android:contentDescription="@string/todo" />
- <FrameLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:id="@+id/fragment"/>
- <ProgressBar
- android:id="@+id/log_in_progress"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- style="@android:style/Widget.ProgressBar.Inverse"/>
- </LinearLayout>
- <TextView
- android:id="@+id/profile_info"
- android:layout_width="310dp"
- android:layout_height="wrap_content"
- android:text="@string/default_message"
- android:textSize="15sp"
- android:gravity="center"
- android:layout_gravity="center"/>
- <ImageButton
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
- android:layout_centerHorizontal="true"
- android:layout_marginBottom="10dp"
- android:id="@+id/login_with_amazon"
- android:src="@color/login_button_image_state"
- android:background="@android:color/transparent"
- android:padding="0dp"
- android:contentDescription="@string/login_button_content_description"
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:layout_alignParentRight="true"
- android:layout_marginTop="10dp"
- android:layout_marginRight="10dp"
- android:id="@+id/logout"
- android:text="@string/logout"
- android:visibility="gone"
- android:clickable="true"
- android:textColor="@color/logout_text_color_state"
- android:paddingBottom="10dp"
- android:layout_alignParentEnd="true"
- android:layout_marginEnd="10dp" />
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:layout_alignParentRight="true"
- android:layout_marginTop="10dp"
- android:layout_marginRight="10dp"
- android:id="@+id/return_to_app"
- android:text="@string/return_to_app"
- android:visibility="gone"
- android:clickable="true"
- android:textColor="@color/logout_text_color_state"
- android:paddingBottom="10dp"
- android:layout_alignParentEnd="true"
- android:layout_marginEnd="10dp" /> </RelativeLayout>
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".Activity1">
- <VideoView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:id="@+id/v1"
- />
- </RelativeLayout>
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_1);
- VideoView v1 = (VideoView) findViewById( R.id.v1 );
- v1.setVideoURI( Uri.parse( "https//.mp4" ) );
- v1.start();
- v1.requestFocus();
- v1.setKeepScreenOn( true );
- } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement