Beispiel #1
0
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   /*
      Test To See if The Result is coming from the login Activity
   */
   if (requestCode == LOGIN_REQUEST_CODE) {
     AuthenticationResponse authenticationResponse =
         AuthenticationClient.getResponse(resultCode, data);
     /*
        If a token is returned, the user logged in and we can now Initialize the Player.
     */
     if (authenticationResponse.getType() == AuthenticationResponse.Type.TOKEN) {
       /*
          Store Access Token in Shared Preferences
       */
       SharedPreferences sharedPreferences = getSharedPreferences(SESSION_PREFS, MODE_PRIVATE);
       SharedPreferences.Editor editor = sharedPreferences.edit();
       editor.putString(LAST_VALID_SESSION_TOKEN, authenticationResponse.getAccessToken());
       editor.commit();
       /*
          Initialize Player
       */
       PlayerUtils.init(this, authenticationResponse.getAccessToken());
     }
     /*
        If Login does not Return Token.... Try Again
     */
     else {
       LoginManager.startLoginActivity(this, LOGIN_REQUEST_CODE);
     }
   }
 }
Beispiel #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    Log.d("DEBUG_JRM", "ONCREATE");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    /*
       Initialize UI member fields
    */

    mActivity = this;
    // mToolbar = (Toolbar) findViewById(R.id.toolbar);
    slidingUpPanelLayout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout);
    playPauseFloatingActionButton =
        (FloatingActionButton) findViewById(R.id.playPauseFloatingActionButton);
    mPlayPauseButton = (ImageButton) findViewById(R.id.imageButton);
    mSlideDragView = findViewById(R.id.slide_drag_view);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
    /*
       Initialize Other Member Fields
    */
    // setSupportActionBar( mToolbar );
    mActionBar = getSupportActionBar();
    mPlayerStatusTask = new PlayerStatusTask();
    /*
       Set Event Listeners on
    */
    playPauseFloatingActionButton.setOnClickListener(playPauseButtonClickListener);
    mDrawerList.setAdapter(
        new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, tiles));

    /** Try to Access Account with last access Token, or start login activity and get a new one */
    SharedPreferences sharedPreferences = getSharedPreferences(SESSION_PREFS, MODE_PRIVATE);
    String token = sharedPreferences.getString(LAST_VALID_SESSION_TOKEN, "");

    if (token.equals("")) {
      LoginManager.startLoginActivity(this, LOGIN_REQUEST_CODE);
    } else {
      PlayerUtils.init(this, token);
      if (mPlayerStatusTask.getStatus() == AsyncTask.Status.PENDING
          || mPlayerStatusTask.getStatus() == AsyncTask.Status.RUNNING) {
        mPlayerStatusTask.cancel(true);
        mPlayerStatusTask = new PlayerStatusTask();
      }
    }
  }