List of usage examples for com.google.api.client.googleapis.extensions.android.gms.auth GoogleAccountCredential usingOAuth2
public static GoogleAccountCredential usingOAuth2(Context context, Collection<String> scopes)
From source file:net.xisberto.phonetodesktop.MainActivity.java
License:Open Source License
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.activity_main); preferences = new Preferences(this); credential = GoogleAccountCredential.usingOAuth2(this, Utils.scopes); credential.setSelectedAccountName(preferences.loadAccountName()); if (savedInstanceState == null) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); if (preferences.loadAccountName() == null) { showWelcome = true;/*w w w . j av a 2 s .co m*/ currentFragment = WelcomeFragment.newInstance(); transaction.replace(R.id.main_frame, currentFragment); } else { showWelcome = false; mainFragment = MainFragment.newInstance(); transaction.replace(R.id.main_frame, mainFragment, TAG_MAIN); } transaction.commit(); } else { mainFragment = (MainFragment) getSupportFragmentManager().findFragmentByTag(TAG_MAIN); } String action = getIntent().getAction(); if (action != null && action.equals(Utils.ACTION_AUTHENTICATE)) { updateMainLayout(true); startAuthorization(); } }
From source file:net.xisberto.phonetodesktop.network.GoogleTasksService.java
License:Open Source License
@Override public void onCreate() { super.onCreate(); preferences = new Preferences(this); list_id = preferences.loadListId();/*from ww w .j av a2 s . c o m*/ credential = GoogleAccountCredential.usingOAuth2(this, Utils.scopes); credential.setSelectedAccountName(preferences.loadAccountName()); transport = AndroidHttp.newCompatibleTransport(); jsonFactory = new GsonFactory(); client = new com.google.api.services.tasks.Tasks.Builder(transport, jsonFactory, credential) .setApplicationName("PhoneToDesktop").build(); }
From source file:net.xisberto.phonetodesktop.network.ListAsyncTask.java
License:Open Source License
public ListAsyncTask(MainActivity activity) { if (activity != null) { listener = (MainActivity) activity; } else {/*from www . j a v a2s. co m*/ throw new ClassCastException("Activity must implement TaskListTaskListener"); } transport = AndroidHttp.newCompatibleTransport(); jsonFactory = new GsonFactory(); Preferences preferences = new Preferences(listener); credential = GoogleAccountCredential.usingOAuth2(listener, Utils.scopes); credential.setSelectedAccountName(preferences.loadAccountName()); client = new com.google.api.services.tasks.Tasks.Builder(transport, jsonFactory, credential) .setApplicationName("PhoneToDesktop").build(); }
From source file:net.xisberto.phonetodesktop.ui.MainActivity.java
License:Open Source License
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.activity_main); preferences = new Preferences(this); credential = GoogleAccountCredential.usingOAuth2(this, Utils.scopes); credential.setSelectedAccountName(preferences.loadAccountName()); if (savedInstanceState == null) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); if (preferences.loadAccountName() == null) { showWelcome = true;// www. j av a2s . co m currentFragment = WelcomeFragment.newInstance(); transaction.replace(R.id.main_frame, currentFragment); } else { showWelcome = false; mainFragment = MainFragment.newInstance(); transaction.replace(R.id.main_frame, mainFragment, TAG_MAIN); } transaction.commit(); } else { mainFragment = (MainFragment) getSupportFragmentManager().findFragmentByTag(TAG_MAIN); } String action = getIntent().getAction(); if (action != null && action.equals(Utils.ACTION_AUTHENTICATE)) { updateMainLayout(true); startAuthorization(); } }
From source file:org.ktaka.picasasample.PicasaUploadActivity.java
License:Apache License
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_picasa_upload); credential = GoogleAccountCredential.usingOAuth2(this, Collections.singleton(PicasaUrl.ROOT_URL)); SharedPreferences settings = getPreferences(Context.MODE_PRIVATE); credential.setSelectedAccountName(settings.getString(PREF_ACCOUNT_NAME, null)); client = new PicasaClient(HTTP_TRANSPORT.createRequestFactory(credential)); client.setApplicationName(APPLICATION_NAME); }
From source file:org.mrpdaemon.android.encdroid.GoogleDriveAccount.java
License:Open Source License
public GoogleDriveAccount(EDApplication app) { mPrefs = app.getSharedPreferences(PREFS_KEY, 0); linkInProgress = false;//from www. j ava 2s . com authInProgress = false; authenticated = false; credential = GoogleAccountCredential.usingOAuth2(app.getApplicationContext(), Arrays.asList(DriveScopes.DRIVE)); // Figure out whether we're linked to an account linked = mPrefs.getBoolean(PREF_LINKED, false); if (linked) { accountName = mPrefs.getString(PREF_ACCOUNT_NAME, null); // Kick off authentication thread createDriveService(accountName); startAuthThread(null); } }
From source file:org.odk.collect.android.activities.GoogleSheetsUploaderActivity.java
License:Apache License
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.i(TAG, "onCreate: " + ((savedInstanceState == null) ? "creating" : "re-initializing")); // if we start this activity, the following must be true: // 1) Google Sheets is selected in preferences // 2) A google user is selected // default initializers mAlertMsg = getString(R.string.please_wait); mAlertShowing = false;/*from ww w. j a v a2 s . c o m*/ setTitle(getString(R.string.send_data)); // get any simple saved state... // resets alert message and showing dialog if the screen is rotated if (savedInstanceState != null) { if (savedInstanceState.containsKey(ALERT_MSG)) { mAlertMsg = savedInstanceState.getString(ALERT_MSG); } if (savedInstanceState.containsKey(ALERT_SHOWING)) { mAlertShowing = savedInstanceState.getBoolean(ALERT_SHOWING, false); } } long[] selectedInstanceIDs; Intent intent = getIntent(); selectedInstanceIDs = intent.getLongArrayExtra(FormEntryActivity.KEY_INSTANCES); mInstancesToSend = new Long[(selectedInstanceIDs == null) ? 0 : selectedInstanceIDs.length]; if (selectedInstanceIDs != null) { for (int i = 0; i < selectedInstanceIDs.length; ++i) { mInstancesToSend[i] = selectedInstanceIDs[i]; } } // at this point, we don't expect this to be empty... if (mInstancesToSend.length == 0) { Log.e(TAG, "onCreate: No instances to upload!"); // drop through -- // everything will process through OK } else { Log.i(TAG, "onCreate: Beginning upload of " + mInstancesToSend.length + " instances!"); } // Initialize credentials and service object. mCredential = GoogleAccountCredential .usingOAuth2(getApplicationContext(), Arrays.asList(GoogleSheetsTask.SCOPES)) .setBackOff(new ExponentialBackOff()); getResultsFromApi(); }
From source file:org.odk.collect.android.utilities.gdrive.GoogleAccountsManager.java
License:Apache License
private void initCredential(@NonNull Context context) { this.context = context; transport = AndroidHttp.newCompatibleTransport(); jsonFactory = JacksonFactory.getDefaultInstance(); preferences = GeneralSharedPreferences.getInstance(); credential = GoogleAccountCredential.usingOAuth2(context, Collections.singletonList(DriveScopes.DRIVE)) .setBackOff(new ExponentialBackOff()); intentChooseAccount = credential.newChooseAccountIntent(); themeUtils = new ThemeUtils(context); }
From source file:org.opensilk.music.library.drive.client.DriveClientModule.java
License:Open Source License
@Provides @DriveClientScope//from w w w.java 2s . c o m public GoogleAccountCredential provideCredential(@ForApplication Context context) { return GoogleAccountCredential.usingOAuth2(context, Constants.SCOPES).setSelectedAccountName(accountName); }
From source file:org.opensilk.music.library.drive.ui.DriveAuthService.java
License:Open Source License
public DriveAuthService(Context context) { this.context = context; this.credential = GoogleAccountCredential.usingOAuth2(context, Constants.SCOPES); }