Guest User

Untitled

a guest
Apr 19th, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.27 KB | None | 0 0
  1. package com.neoseeker.android;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.content.SharedPreferences;
  6. import android.os.Bundle;
  7. import android.util.Log;
  8. import android.widget.Toast;
  9.  
  10. public class NeoEntry extends Activity {
  11.    
  12.     private static final String TAG = "NeoEntry";
  13.    
  14.     /**
  15.      * Called whenever the Activity is started
  16.      */
  17.     @Override
  18.     public void onCreate(Bundle savedInstanceState) {
  19.         super.onCreate(savedInstanceState);
  20.        
  21.         // Anything needed to be done on entry
  22.         this.setUpOAuth();
  23.        
  24.         // After entry stuff are all done... Forward to NeoMain
  25.         Intent neoMain = new Intent(this, NeoMain.class);
  26.         startActivity(neoMain);
  27.         finish();
  28.     }
  29.    
  30.     /**
  31.      * Sets up OAuth authentication, so the app can use the NeoAPI under the user,
  32.      * with correct permissions to the account.
  33.      */
  34.     private void setUpOAuth() {
  35.         Log.v(TAG, "Entering setUpOAuth()");
  36.        
  37.         SharedPreferences sharedSettings = getSharedPreferences(Neoseeker.PREFS_NAME, 0);
  38.         String accessToken = sharedSettings.getString("accessToken", "");
  39.         String accessTokenSecret = sharedSettings.getString("accessTokenSecret", "");
  40.        
  41.         Log.v(TAG, "Saved accessToken: \"" + accessToken + "\"");
  42.         Log.v(TAG, "Saved accessTokenSecret: \"" + accessTokenSecret + "\"");
  43.         Toast.makeText(this, "Saved accessToken: \"" + accessToken + "\"", Toast.LENGTH_LONG).show();
  44.         Toast.makeText(this, "Saved accessTokenSecret: \"" + accessTokenSecret + "\"", Toast.LENGTH_LONG).show();
  45.        
  46.         if (accessToken.equals("") && accessTokenSecret.equals("")) {
  47.             Log.v(TAG, "Must get authentication");
  48.            
  49.             String authUrl = Neoseeker.API().getAuthenticationUrl();
  50.            
  51.             Intent webAuthentication = new Intent(this, OAuthCustomWeb.class);
  52.             webAuthentication.putExtra("authUrl", authUrl);
  53.             startActivity(webAuthentication);
  54.         } else {
  55.             Log.v(TAG, "Already authenticated");
  56.             // Tokens already exist, meaning they can be used (hopefully)
  57.             Neoseeker.API().setAccessToken(accessToken);
  58.             Neoseeker.API().setAccessTokenSecret(accessTokenSecret);
  59.         }
  60.     }
  61. }
Add Comment
Please, Sign In to add comment