Android Open Source - SnapetsAndroid Base Activity






From Project

Back to project page SnapetsAndroid.

License

The source code is released under:

Apache License

If you think the Android project SnapetsAndroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.keyconsultant.parse.logintutorial.activity;
/*from  w  w  w .  j  a  v  a  2  s  .  c o m*/
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi;
import android.os.Build;
import android.support.v4.app.FragmentActivity;
import android.view.View;

import com.keyconsultant.parse.logintutorial.R;
import com.squareup.otto.BusProvider;

/**
 * Base activity class that handles the interaction of the Activity with the service bus. Also includes
 * an application wide implementation of the progress dialog.  
 * 
 * 
 * @author Trey Robinson
 *
 */
public class BaseActivity extends FragmentActivity {

  protected StatusView mStatusView;
  protected View mMainView;
  
  @Override
  protected void onResume() {
    super.onResume();
    //register the activity to the service bus
    BusProvider.getInstance().register(this);
    
    //required view components for the loading screen
        mMainView = findViewById(R.id.main_view);
        mStatusView = (StatusView) findViewById(R.id.statusView);
  }
  
  @Override
  protected void onPause() {
    /**activity must be removed from the service bus in onPause or an error will occur
      when the bus attempts to dispatch an event to the paused activity. **/ 
    BusProvider.getInstance().unregister(this);
    super.onPause();
  }
  
  /**
   * Post the event to the service bus
   * @param event
   *     The event to dispatch on the service bus
   */
  protected void postEvent(Object event) {
    BusProvider.getInstance().post(event);
  }
  
    /**
     * Shows the progress UI and hides the login form.
     */
    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
    protected void showProgress(final boolean show, String message) {
        // On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
        // for very easy animations. If available, use these APIs to fade-in
        // the progress spinner.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
            int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);

            mStatusView.setVisibility(View.VISIBLE);
            mStatusView.animate()
                    .setDuration(shortAnimTime)
                    .alpha(show ? 1 : 0)
                    .setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            mStatusView.setVisibility(show ? View.VISIBLE : View.GONE);
                        }
                    });

            mMainView.setVisibility(View.VISIBLE);
            mMainView.animate()
                    .setDuration(shortAnimTime)
                    .alpha(show ? 0 : 1)
                    .setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            mMainView.setVisibility(show ? View.GONE : View.VISIBLE);
                        }
                    });
        } else {
            // The ViewPropertyAnimator APIs are not available, so simply show
            // and hide the relevant UI components.
            mStatusView.setVisibility(show ? View.VISIBLE : View.GONE);
            mMainView.setVisibility(show ? View.GONE : View.VISIBLE);
        }
    }
  
}




Java Source Code List

com.keyconsultant.parse.logintutorial.CreateAccountFragment.java
com.keyconsultant.parse.logintutorial.LoginActivity.java
com.keyconsultant.parse.logintutorial.LoginFragment.java
com.keyconsultant.parse.logintutorial.MainActivity.java
com.keyconsultant.parse.logintutorial.activity.BaseActivity.java
com.keyconsultant.parse.logintutorial.activity.StatusView.java
com.keyconsultant.parse.logintutorial.error.UnknownErrorDialogFactory.java
com.keyconsultant.parse.logintutorial.event.ErrorEvent.java
com.keyconsultant.parse.logintutorial.forgotpassword.ForgotPasswordDialogFragment.java
com.keyconsultant.parse.logintutorial.fragment.BaseFragment.java
com.keyconsultant.parse.logintutorial.model.manager.BaseManager.java
com.keyconsultant.parse.logintutorial.model.user.UserManager.java
com.keyconsultant.parse.logintutorial.model.user.User.java
com.keyconsultant.parse.logintutorial.model.user.authenticate.AuthenticateUserErrorEvent.java
com.keyconsultant.parse.logintutorial.model.user.authenticate.AuthenticateUserStartEvent.java
com.keyconsultant.parse.logintutorial.model.user.authenticate.AuthenticateUserSuccessEvent.java
com.keyconsultant.parse.logintutorial.model.user.authenticate.UserForgotPasswordErrorEvent.java
com.keyconsultant.parse.logintutorial.model.user.authenticate.UserForgotPasswordStartEvent.java
com.keyconsultant.parse.logintutorial.model.user.authenticate.UserForgotPasswordSuccessEvent.java
com.squareup.otto.AnnotatedHandlerFinder.java
com.squareup.otto.BusProvider.java
com.squareup.otto.Bus.java
com.squareup.otto.DeadEvent.java
com.squareup.otto.EventHandler.java
com.squareup.otto.EventProducer.java
com.squareup.otto.HandlerFinder.java
com.squareup.otto.Produce.java
com.squareup.otto.Subscribe.java
com.squareup.otto.ThreadEnforcer.java