Android Open Source - ParseUI-Android Parse Login Dispatch Activity






From Project

Back to project page ParseUI-Android.

License

The source code is released under:

Copyright (c) 2014, Parse, LLC. All rights reserved. You are hereby granted a non-exclusive, worldwide, royalty-free license to use, copy, modify, and distribute this software in source code or binar...

If you think the Android project ParseUI-Android 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

/*
 *  Copyright (c) 2014, Parse, LLC. All rights reserved.
 */*  w w w .j a  va2 s. c  om*/
 *  You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
 *  copy, modify, and distribute this software in source code or binary form for use
 *  in connection with the web services and APIs provided by Parse.
 *
 *  As with any software that integrates with the Parse platform, your use of
 *  this software is subject to the Parse Terms of Service
 *  [https://www.parse.com/about/terms]. This copyright notice shall be
 *  included in all copies or substantial portions of the software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */

package com.parse.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.parse.Parse;
import com.parse.ParseUser;

/**
 * Activity that starts ParseLoginActivity if the user is not logged in.
 * Otherwise, it starts the subclass-defined target activity.
 * 
 * To use this, you should subclass this activity and implement
 * {@link ParseLoginDispatchActivity#getTargetClass} to return the class of the
 * target activity that should be launched after login succeeds. If the user
 * cancels the login, your app will go back to whatever activity it was on before
 * your subclass dispatch activity was launched, or exit the app if your subclass
 * is the first activity in your app's backstack.
 * 
 * You can think of your subclass as a gate keeper for any activities that
 * require a logged-in user to function. You should have one gate keeper per
 * entry path into your app (e.g. launching the app, or entering through push
 * notifications). When your app launches or receives a push notification, you
 * should specify that your gate keeper activity be launched (and the gate
 * keeper will redirect to your target activity upon successful login).
 */
public abstract class ParseLoginDispatchActivity extends Activity {

  protected abstract Class<?> getTargetClass();

  private static final int LOGIN_REQUEST = 0;
  private static final int TARGET_REQUEST = 1;

  private static final String LOG_TAG = "ParseLoginDispatch";

  @Override
  final protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    runDispatch();
  }

  @Override
  final protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    setResult(resultCode);
    if (requestCode == LOGIN_REQUEST && resultCode == RESULT_OK) {
      runDispatch();
    } else {
      finish();
    }
  }

  /**
   * Override this to generate a customized intent for starting ParseLoginActivity.
   * However, the preferred method for configuring Parse Login UI components is by
   * specifying activity options in AndroidManifest.xml, not by overriding this.
   *
   * @return Intent that can be used to start ParseLoginActivity
   */
  protected Intent getParseLoginIntent() {
    ParseLoginBuilder builder = new ParseLoginBuilder(this);
    return builder.build();
  }

  private void runDispatch() {
    if (ParseUser.getCurrentUser() != null) {
      debugLog(getString(R.string.com_parse_ui_login_dispatch_user_logged_in) + getTargetClass());
      startActivityForResult(new Intent(this, getTargetClass()), TARGET_REQUEST);
    } else {
      debugLog(getString(R.string.com_parse_ui_login_dispatch_user_not_logged_in));
      startActivityForResult(getParseLoginIntent(), LOGIN_REQUEST);
    }
  }

  private void debugLog(String message) {
    if (Parse.getLogLevel() <= Parse.LOG_LEVEL_DEBUG &&
        Log.isLoggable(LOG_TAG, Log.DEBUG)) {
      Log.d(LOG_TAG, message);
    }
  }
}




Java Source Code List

com.parse.loginsample.basic.SampleApplication.java
com.parse.loginsample.basic.SampleProfileActivity.java
com.parse.loginsample.codecustomization.SampleApplication.java
com.parse.loginsample.codecustomization.SampleProfileActivity.java
com.parse.loginsample.layoutoverride.SampleApplication.java
com.parse.loginsample.layoutoverride.SampleProfileActivity.java
com.parse.loginsample.withdispatchactivity.SampleApplication.java
com.parse.loginsample.withdispatchactivity.SampleDispatchActivity.java
com.parse.loginsample.withdispatchactivity.SampleProfileActivity.java
com.parse.ui.ParseLoginActivity.java
com.parse.ui.ParseLoginBuilder.java
com.parse.ui.ParseLoginConfig.java
com.parse.ui.ParseLoginDispatchActivity.java
com.parse.ui.ParseLoginFragmentBase.java
com.parse.ui.ParseLoginFragment.java
com.parse.ui.ParseLoginHelpFragment.java
com.parse.ui.ParseOnLoadingListener.java
com.parse.ui.ParseOnLoginSuccessListener.java
com.parse.ui.ParseSignupFragment.java