Java 类com.google.android.gms.common.api.Scope 实例源码

项目:GodotGoogleService    文件:PlayService.java   
public void init (final int instanceID) {
    script_id = instanceID;
    GUtils.setScriptInstance(script_id);

    if (GUtils.checkGooglePlayService(activity)) {
        Log.d(TAG, "Play Service Available.");
    }

    GoogleSignInOptions gso =
    new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
    .requestScopes(new Scope(Scopes.GAMES))
    .requestEmail()
    .build();

    mGoogleSignInClient = GoogleSignIn.getClient(activity, gso);

    Log.d(TAG, "Google::Initialized");
    onStart();
}
项目:RxGooglePhotos    文件:GoogleSignOutOnSubscribe.java   
private void initGoogleApiClient() {
    final GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .requestProfile()
            .requestScopes(new Scope(SCOPE_PICASA))
            .build();
    googleApiClient = new GoogleApiClient.Builder(activity)
            .enableAutoManage(activity,
                    connectionResult -> emitter.onError(new SignInException("Connecting", connectionResult.getErrorMessage(), connectionResult.getErrorCode())))
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
                @Override
                public void onConnected(@Nullable Bundle bundle) {
                    actWhenConnected();
                }

                @Override
                public void onConnectionSuspended(int i) {

                }
            })
            .build();
}
项目:enklave    文件:LoginGoogle.java   
public LoginGoogle(final Context context, SignInButton button, final Activity act, PreferencesShared pref) {
    this.context = context;
    preferencesShared = pref;
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestIdToken("473547758853-nm840bumsu5km04gbgtdee1fhtod1ji6.apps.googleusercontent.com").build();
    gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestScopes(new Scope(Scopes.PLUS_LOGIN)).requestScopes(new Scope(Scopes.PLUS_ME)).requestEmail().requestIdToken("473547758853-nm840bumsu5km04gbgtdee1fhtod1ji6.apps.googleusercontent.com").build();
    mGoogleApiClient = new GoogleApiClient.Builder(context.getApplicationContext())
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

    button.setSize(SignInButton.SIZE_STANDARD);
    button.setScopes(gso.getScopeArray());

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
            act.startActivityForResult(signInIntent, 101);

        }
    });
}
项目:RoadLab-Pro    文件:GoogleAPIHelper.java   
private void loginGoogleAPI() {
    if (!(context instanceof FragmentActivity)) {
        return;
    }
    gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .requestProfile()
            .requestId()
            .requestScopes(new Scope(Scopes.PLUS_LOGIN), new Scope(Scopes.DRIVE_FILE))
            .requestServerAuthCode(CLIENT_ID)
            .build();
    if (mGoogleApiClient == null) {
        mGoogleApiClient = new GoogleApiClient.Builder(context)
            .addApi(com.google.android.gms.auth.api.Auth.GOOGLE_SIGN_IN_API, gso)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
    }
    if (!mGoogleApiClient.isConnected()) {
        mGoogleApiClient.connect();
    } else {
        sendAuthRequest();
    }
}
项目:cast-dashboard-android-app    文件:AuthHelper.java   
private void exchangeServerAuthCodeForJWT(String firebaseUserId, String authCode, Set<Scope> grantedScopes, final SimpleCallback<String> jwtCallback) {
    Ion.with(context)
            .load(context.getString(R.string.APP_URL) + "/exchangeServerAuthCodeForJWT")
            .setBodyParameter("serverCode", authCode)
            .setBodyParameter("firebaseUserId", firebaseUserId)
            .setBodyParameter("grantedScopes", android.text.TextUtils.join(",", grantedScopes))
            .asJsonObject()
            .setCallback(new com.koushikdutta.async.future.FutureCallback<JsonObject>() {
                @Override
                public void onCompleted(Exception e, JsonObject result) {
                    if (e != null) {
                        jwtCallback.onError(e);
                        return;
                    }
                    String jwt = result.get("serviceAccessToken").getAsString();
                    AuthHelper.userJwt = jwt;
                    jwtCallback.onComplete(jwt);
                }
            });
}
项目:cast-dashboard-android-app    文件:GoogleCalendarWidget.java   
@Override
public int requestPermissions(Activity activity) {
    AuthHelper authHelper = new AuthHelper(context);

    Set<Scope> scopes = new HashSet<>();
    scopes.addAll(AuthHelper.grantedScopes);
    scopes.add(new Scope(RequiredScope));

    GoogleApiClient mGoogleApiClient = new GoogleApiClient
        .Builder(context)
        .addApi(Auth.GOOGLE_SIGN_IN_API, authHelper.getGoogleGSO(scopes))
        .build();

    Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
    activity.startActivityForResult(signInIntent, GoogleCalendarSettings.PERMISSIONS_REQUEST_READ_GOOGLE_CALENDAR);

    return GoogleCalendarSettings.PERMISSIONS_REQUEST_READ_GOOGLE_CALENDAR;
}
项目:SocialSignIn_Demo    文件:GooglePlusLoginHelper.java   
public void createConnection(AppCompatActivity mActivity)
{

    this.activity = mActivity;
    userData = new UserLoginDetails();

    if (Utility.checkPlayServices(mActivity)) {

        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestScopes(new Scope(Scopes.PROFILE))
                .requestScopes(new Scope(Scopes.PLUS_LOGIN))
                .requestProfile()
                .requestEmail()
                .build();

        if (mGoogleApiClient == null) {
            // [START create_google_api_client]
            // Build GoogleApiClient with access to basic profile
            mGoogleApiClient = new GoogleApiClient.Builder(mActivity)
                    .enableAutoManage(mActivity,this)
                    .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                    //.addApi(Plus.API)
                    .build();
        }
    }
}
项目:RxLogin    文件:RxLoginTest.java   
@Test public void testLoginGoogleSuccess() throws Exception {
    InOrder inOrder = inOrder(mMockGoogleApiClient);
    mRxLogin.mGoogleApiClient = mMockGoogleApiClient;
    mRxLogin.loginGoogle(mActivity, new Scope(Scopes.PLUS_LOGIN))
        .subscribe(mGoogleSubscriber);
    // wait for connection
    Thread.sleep(20);
    mRxLogin.mGoogleCallback.onSuccess(mGoogleSignInResult);
    mGoogleSubscriber.awaitTerminalEvent();
    verify(mActivity).startActivityForResult(eq(mTestIntent), eq(5712));
    inOrder.verify(mMockGoogleApiClient).blockingConnect(eq(10L), eq(TimeUnit.SECONDS));
    inOrder.verify(mMockGoogleApiClient).disconnect();
    mGoogleSubscriber.assertNoErrors();
    mGoogleSubscriber.assertValueCount(1);
    mGoogleSubscriber.assertTerminated();
    assertThat(mRxLogin.mGoogleApiClient).isNull();
    assertThat(mRxLogin.mGoogleCallback).isNull();
}
项目:RxLogin    文件:RxLoginTest.java   
@Test public void testLoginGoogleCancel() throws Exception {
    InOrder inOrder = inOrder(mMockGoogleApiClient);
    mRxLogin.mGoogleApiClient = mMockGoogleApiClient;
    mRxLogin.loginGoogle(mActivity, new Scope(Scopes.PLUS_LOGIN))
        .subscribe(mGoogleSubscriber);
    // wait for connection
    Thread.sleep(20);
    mRxLogin.mGoogleCallback.onCancel();
    mGoogleSubscriber.awaitTerminalEvent();
    verify(mActivity).startActivityForResult(eq(mTestIntent), eq(5712));
    inOrder.verify(mMockGoogleApiClient).blockingConnect(eq(10L), eq(TimeUnit.SECONDS));
    inOrder.verify(mMockGoogleApiClient).disconnect();
    mGoogleSubscriber.assertError(LoginException.class);
    mGoogleSubscriber.assertTerminated();
    assertThat(mRxLogin.mGoogleApiClient).isNull();
    assertThat(mRxLogin.mGoogleCallback).isNull();
}
项目:RxLogin    文件:RxLoginTest.java   
@Test public void testLoginGoogleError() throws Exception {
    InOrder inOrder = inOrder(mMockGoogleApiClient);
    mRxLogin.mGoogleApiClient = mMockGoogleApiClient;
    mRxLogin.loginGoogle(mActivity, new Scope(Scopes.PLUS_LOGIN))
        .subscribe(mGoogleSubscriber);
    // wait for connection
    Thread.sleep(20);
    mRxLogin.mGoogleCallback.onError(mGoogleSignInResult);
    mGoogleSubscriber.awaitTerminalEvent();
    verify(mActivity).startActivityForResult(eq(mTestIntent), eq(5712));
    inOrder.verify(mMockGoogleApiClient).blockingConnect(eq(10L), eq(TimeUnit.SECONDS));
    inOrder.verify(mMockGoogleApiClient).disconnect();
    mGoogleSubscriber.assertError(LoginException.class);
    mGoogleSubscriber.assertTerminated();
    assertThat(mRxLogin.mGoogleApiClient).isNull();
    assertThat(mRxLogin.mGoogleCallback).isNull();
}
项目:RxLogin    文件:RxLoginTest.java   
@Test public void testLoginGoogleConnectionError() throws Exception {
    when(mMockGoogleApiClient.blockingConnect(eq(10L), eq(TimeUnit.SECONDS)))
        .thenReturn(new ConnectionResult(ConnectionResult.API_UNAVAILABLE));
    InOrder inOrder = inOrder(mMockGoogleApiClient);
    mRxLogin.mGoogleApiClient = mMockGoogleApiClient;
    mRxLogin.loginGoogle(mActivity, new Scope(Scopes.PLUS_LOGIN))
        .subscribe(mGoogleSubscriber);
    mGoogleSubscriber.awaitTerminalEvent();
    verify(mActivity).startActivityForResult(eq(mTestIntent), eq(5712));
    inOrder.verify(mMockGoogleApiClient).blockingConnect(eq(10L), eq(TimeUnit.SECONDS));
    inOrder.verify(mMockGoogleApiClient).disconnect();
    mGoogleSubscriber.assertError(LoginException.class);
    mGoogleSubscriber.assertTerminated();
    assertThat(mRxLogin.mGoogleApiClient).isNull();
    assertThat(mRxLogin.mGoogleCallback).isNull();
}
项目:DietDiaryApp    文件:SettingsSupportFragment.java   
private void loadDriveApiClients() {
    Set<Scope> requiredScopes = new HashSet<>(2);
    requiredScopes.add(Drive.SCOPE_FILE);
    requiredScopes.add(Drive.SCOPE_APPFOLDER);

    GoogleSignInAccount signInAccount = GoogleSignIn.getLastSignedInAccount(getContext());
    if (signInAccount != null && signInAccount.getGrantedScopes().containsAll(requiredScopes)) {
        initializeDriveClient(signInAccount);
    } else {
        GoogleSignInOptions signInOptions =
                new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                        .requestScopes(Drive.SCOPE_FILE)
                        .requestScopes(Drive.SCOPE_APPFOLDER)
                        .build();
        GoogleSignInClient googleSignInClient = GoogleSignIn.getClient(getActivity(), signInOptions);
        startActivityForResult(googleSignInClient.getSignInIntent(), REQUEST_RESOLVE_ERROR);
    }
}
项目:Android-Sensor-Programming-By-Example    文件:HistoryActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.historydata_layout);

    mClient = new GoogleApiClient.Builder(this)
            .addApi(Fitness.HISTORY_API)
            .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
            .addScope(new Scope(Scopes.FITNESS_BODY_READ))
            .addScope(new Scope(Scopes.FITNESS_LOCATION_READ))
            .addScope(new Scope(Scopes.FITNESS_NUTRITION_READ))
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

    mAggregateCheckBox = (CheckBox)findViewById(R.id.aggregatecheckbox);
    mStartDateText = (TextView)findViewById(R.id.startdate);
    mEndDateText = (TextView)findViewById(R.id.enddate);
    mResultsText = (TextView)findViewById(R.id.results);

    setUpSpinnerDropDown();
    setUpListView();

}
项目:Android-Sensor-Programming-By-Example    文件:SubscriptionActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.subscriptiondata_layout);

    mClient = new GoogleApiClient.Builder(this)
            .addApi(Fitness.RECORDING_API)
            .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
            .addScope(new Scope(Scopes.FITNESS_BODY_READ))
            .addScope(new Scope(Scopes.FITNESS_LOCATION_READ))
            .addScope(new Scope(Scopes.FITNESS_NUTRITION_READ))
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

    setUpSpinnerDropDown();
    setUpListView();
}
项目:Android-Sensor-Programming-By-Example    文件:SensorActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sensordata_layout);
    mLiveDataText = (TextView)findViewById(R.id.livedata);

    setUpSpinnerDropDown();
    setUpListView();

    mClient = new GoogleApiClient.Builder(this)
            .addApi(Fitness.SENSORS_API)
            .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
            .addScope(new Scope(Scopes.FITNESS_BODY_READ))
            .addScope(new Scope(Scopes.FITNESS_LOCATION_READ))
            .addScope(new Scope(Scopes.FITNESS_NUTRITION_READ))
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
}
项目:FMTech    文件:zzi.java   
public final void zza(zzp paramzzp, Set<Scope> paramSet, zze paramzze)
{
  zzx.zzb(paramzze, "Expecting a valid ISignInCallbacks");
  try
  {
    ((zzf)zzqn()).zza(new AuthAccountRequest(paramzzp, paramSet), paramzze);
    return;
  }
  catch (RemoteException localRemoteException1)
  {
    Log.w("SignInClientImpl", "Remote service probably died when authAccount is called");
    try
    {
      paramzze.zza(new ConnectionResult(8, null), new AuthAccountResult(8));
      return;
    }
    catch (RemoteException localRemoteException2)
    {
      Log.wtf("SignInClientImpl", "ISignInCallbacks#onAuthAccount should be executed from the same process, unexpected RemoteException.", localRemoteException1);
    }
  }
}
项目:FMTech    文件:zzi.java   
public final void zza(final String paramString, final List<Scope> paramList, final zzf paramzzf)
  throws RemoteException
{
  this.zzbMf.submit(new Runnable()
  {
    public final void run()
    {
      try
      {
        GoogleApiClient.ServerAuthCodeCallbacks localServerAuthCodeCallbacks = zzi.zza.zza(zzi.zza.this);
        Collections.unmodifiableSet(new HashSet(paramList));
        GoogleApiClient.ServerAuthCodeCallbacks.CheckResult localCheckResult = localServerAuthCodeCallbacks.onCheckServerAuthorization$1acf187f();
        CheckServerAuthResult localCheckServerAuthResult = new CheckServerAuthResult(localCheckResult.zzaot, localCheckResult.zzXp);
        paramzzf.zza(localCheckServerAuthResult);
        return;
      }
      catch (RemoteException localRemoteException)
      {
        Log.e("SignInClientImpl", "RemoteException thrown when processing checkServerAuthorization callback", localRemoteException);
      }
    }
  });
}
项目:FMTech    文件:zzd.java   
public boolean onTransact(int paramInt1, Parcel paramParcel1, Parcel paramParcel2, int paramInt2)
  throws RemoteException
{
  switch (paramInt1)
  {
  default: 
    return super.onTransact(paramInt1, paramParcel1, paramParcel2, paramInt2);
  case 1598968902: 
    paramParcel2.writeString("com.google.android.gms.signin.internal.IOfflineAccessCallbacks");
    return true;
  case 2: 
    paramParcel1.enforceInterface("com.google.android.gms.signin.internal.IOfflineAccessCallbacks");
    zza(paramParcel1.readString(), paramParcel1.createTypedArrayList(Scope.CREATOR), zzf.zza.zzgQ(paramParcel1.readStrongBinder()));
    paramParcel2.writeNoException();
    return true;
  }
  paramParcel1.enforceInterface("com.google.android.gms.signin.internal.IOfflineAccessCallbacks");
  zza(paramParcel1.readString(), paramParcel1.readString(), zzf.zza.zzgQ(paramParcel1.readStrongBinder()));
  paramParcel2.writeNoException();
  return true;
}
项目:FMTech    文件:zznb.java   
final Set<Scope> zzpb()
{
  if (this.zzapu == null) {
    return Collections.emptySet();
  }
  HashSet localHashSet = new HashSet(this.zzapu.zzaod);
  Map localMap = this.zzapu.zzatx;
  Iterator localIterator = localMap.keySet().iterator();
  while (localIterator.hasNext())
  {
    Api localApi = (Api)localIterator.next();
    if (!this.zzape.zzaqj.containsKey(localApi.zzor())) {
      localHashSet.addAll(((zzf.zza)localMap.get(localApi)).zzXp);
    }
  }
  return localHashSet;
}
项目:FMTech    文件:zzf.java   
public zzf(Account paramAccount, Set<Scope> paramSet, Map<Api<?>, zza> paramMap, int paramInt, View paramView, String paramString1, String paramString2, zzxa paramzzxa)
{
  this.zzRE = paramAccount;
  if (paramSet == null) {}
  HashSet localHashSet;
  for (Set localSet = Collections.EMPTY_SET;; localSet = Collections.unmodifiableSet(paramSet))
  {
    this.zzaod = localSet;
    if (paramMap == null) {
      paramMap = Collections.EMPTY_MAP;
    }
    this.zzatx = paramMap;
    this.zzaog = paramView;
    this.zzaof = paramInt;
    this.zzUb = paramString1;
    this.zzaoh = paramString2;
    this.zzaor = paramzzxa;
    localHashSet = new HashSet(this.zzaod);
    Iterator localIterator = this.zzatx.values().iterator();
    while (localIterator.hasNext()) {
      localHashSet.addAll(((zza)localIterator.next()).zzXp);
    }
  }
  this.zzatw = Collections.unmodifiableSet(localHashSet);
}
项目:FMTech    文件:zzj.java   
public final void zza(zzp paramzzp)
{
  ValidateAccountRequest localValidateAccountRequest = new ValidateAccountRequest(paramzzp, (Scope[])this.zzXp.toArray(new Scope[this.zzXp.size()]), this.mContext.getPackageName(), null);
  try
  {
    this.zzatN.zza(new zzd(this, this.zzatW.get()), localValidateAccountRequest);
    return;
  }
  catch (DeadObjectException localDeadObjectException)
  {
    Log.w("GmsClient", "service died");
    zzdg$13462e();
    return;
  }
  catch (RemoteException localRemoteException)
  {
    Log.w("GmsClient", "Remote exception occurred", localRemoteException);
  }
}
项目:FMTech    文件:efw.java   
final Set<Scope> j()
{
  HashSet localHashSet = new HashSet(this.s.b);
  Map localMap = this.s.d;
  Iterator localIterator = localMap.keySet().iterator();
  while (localIterator.hasNext())
  {
    eew localeew = (eew)localIterator.next();
    if (!this.a.n.containsKey(localeew.b()))
    {
      localMap.get(localeew);
      localHashSet.addAll(null);
    }
  }
  return localHashSet;
}
项目:FMTech    文件:GetServiceRequest.java   
public GetServiceRequest(int paramInt1, int paramInt2, int paramInt3, String paramString, IBinder paramIBinder, Scope[] paramArrayOfScope, Bundle paramBundle, Account paramAccount)
{
  this.a = paramInt1;
  this.b = paramInt2;
  this.c = paramInt3;
  this.d = paramString;
  Account localAccount;
  if (paramInt1 < 2)
  {
    localAccount = null;
    if (paramIBinder != null) {
      localAccount = ehv.a(eht.a(paramIBinder));
    }
  }
  for (this.h = localAccount;; this.h = paramAccount)
  {
    this.f = paramArrayOfScope;
    this.g = paramBundle;
    return;
    this.e = paramIBinder;
  }
}
项目:FMTech    文件:fon.java   
public boolean onTransact(int paramInt1, Parcel paramParcel1, Parcel paramParcel2, int paramInt2)
{
  switch (paramInt1)
  {
  default: 
    return super.onTransact(paramInt1, paramParcel1, paramParcel2, paramInt2);
  case 1598968902: 
    paramParcel2.writeString("com.google.android.gms.signin.internal.IOfflineAccessCallbacks");
    return true;
  case 2: 
    paramParcel1.enforceInterface("com.google.android.gms.signin.internal.IOfflineAccessCallbacks");
    a(paramParcel1.readString(), paramParcel1.createTypedArrayList(Scope.CREATOR), fos.a(paramParcel1.readStrongBinder()));
    paramParcel2.writeNoException();
    return true;
  }
  paramParcel1.enforceInterface("com.google.android.gms.signin.internal.IOfflineAccessCallbacks");
  a(paramParcel1.readString(), paramParcel1.readString(), fos.a(paramParcel1.readStrongBinder()));
  paramParcel2.writeNoException();
  return true;
}
项目:FMTech    文件:ehq.java   
public ehq(Account paramAccount, Set<Scope> paramSet, Map<eew<?>, ehr> paramMap, int paramInt, View paramView, String paramString1, String paramString2, foh paramfoh)
{
  this.a = paramAccount;
  if (paramSet == null) {}
  HashSet localHashSet;
  for (Set localSet = Collections.EMPTY_SET;; localSet = Collections.unmodifiableSet(paramSet))
  {
    this.b = localSet;
    if (paramMap == null) {
      paramMap = Collections.EMPTY_MAP;
    }
    this.d = paramMap;
    this.e = paramString1;
    this.f = paramString2;
    this.g = paramfoh;
    localHashSet = new HashSet(this.b);
    Iterator localIterator = this.d.values().iterator();
    while (localIterator.hasNext())
    {
      localIterator.next();
      localHashSet.addAll(null);
    }
  }
  this.c = Collections.unmodifiableSet(localHashSet);
}
项目:FMTech    文件:fov.java   
public final void a(ehs paramehs, Set<Scope> paramSet, foo paramfoo)
{
  efj.b(paramfoo, "Expecting a valid ISignInCallbacks");
  try
  {
    ((for)l()).a(new AuthAccountRequest(paramehs, paramSet), paramfoo);
    return;
  }
  catch (RemoteException localRemoteException1)
  {
    try
    {
      paramfoo.a(new ConnectionResult(8, null), new AuthAccountResult());
      return;
    }
    catch (RemoteException localRemoteException2)
    {
      Log.wtf("SignInClientImpl", "ISignInCallbacks#onAuthAccount should be executed from the same process, unexpected RemoteException.");
    }
  }
}
项目:KeepOn    文件:GoogleApiClientService.java   
@Override
public void onCreate() {
    super.onCreate();
    googleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Plus.API)
            .addApi(Fitness.SENSORS_API)
            .addApi(Fitness.SESSIONS_API)
            .addApi(Fitness.HISTORY_API)
            .addApi(Fitness.RECORDING_API)
            .addApi(LocationServices.API)
            .addScope(new Scope(Scopes.PROFILE))
            .addScope(new Scope(Scopes.FITNESS_LOCATION_READ_WRITE))
            .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE))
            .addConnectionCallbacks(connectionListenerAdapter)
            .addOnConnectionFailedListener(connectionListenerAdapter)
            .build();
}
项目:Tasking    文件:LoginActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    if (getIntent().hasExtra("justSignedOut") && getIntent().getBooleanExtra("justSignedOut", false) && findViewById(R.id.activity_login) != null && !SharedPrefsHelper.getInstance().isSignOutSnackbarShown()) {
        Snackbar.make(findViewById(R.id.activity_login), R.string.just_signed_out, Snackbar.LENGTH_LONG).show();

        SharedPrefsHelper.getInstance().setSignOutSnackbarShown(true);
    }

    // Configure sign-in to request the user's ID, email address, and basic
    // profile. ID and basic profile are included in DEFAULT_SIGN_IN.
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .requestScopes(new Scope(App.TASK_SCOPE), new Scope(App.PROFILE_SCOPE))
            .build();

    // Build GoogleApiClient with access to basic profile
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this, this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

    findViewById(R.id.sign_in_button).setOnClickListener(this);
}
项目:rxactivityresponse    文件:CustomStateObserverExampleButton.java   
@Override
public void rxAction(int requestCode) {
    Assert.assertEquals(requestCode, ActivityResponses.GET_LOGINTOKEN);
    final Activity activity = (Activity) getContext();
    final String[] permissions = new String[]{Manifest.permission.GET_ACCOUNTS};

    final Scope[] scopes = {new Scope(Scopes.PROFILE), new Scope(Scopes.EMAIL)};

    // NB : Rationale is optional and can be null
    final SnackbarRationaleOperator rationaleOperator = new SnackbarRationaleOperator(this, "Need permission for ...");

    getLoginToken(activity, permissions, scopes, rationaleOperator)
            .subscribe(new Consumer<String>() {
                @Override
                public void accept(String s) {
                    Toast.makeText(getContext(), "Token is : " + s, Toast.LENGTH_SHORT).show();
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) {
                    Toast.makeText(getContext(), "Exception : " + throwable, Toast.LENGTH_SHORT).show();
                }
            });
}
项目:rxactivityresponse    文件:CustomStateObserverExampleButton.java   
private Observable<String> getLoginToken(final Activity activity, final String[] permissions, final Scope[] scopes, final SnackbarRationaleOperator rationale) {
    // we cant use RxPermission.getPermission directly, as it triggers state.reset() mid flow.
    return Observable.create(new GetPermissionStatusObservable(activity, permissions))
            .flatMap(new Function<PermissionResult, Observable<Boolean>>() {
                @Override
                public Observable<Boolean> apply(PermissionResult permissionResult) {
                    return Observable.create(new GetPermissionObservable(activity, state, rationale, permissionResult));
                }
            })
            .flatMap(new Function<Boolean, Observable<String>>() {
                @Override
                public Observable<String> apply(Boolean granted) {
                    if (granted) {
                        return Observable.create(new GoogleLoginObservable(activity, state, scopes, Plus.API))
                                .subscribeOn(Schedulers.computation()).observeOn(AndroidSchedulers.mainThread());
                    }
                    return Observable.error(new UserAbortedException());
                }
            })
            .compose(new BaseStateObservable.EndStateTransformer<String>(state));
}
项目:rxactivityresponse    文件:RxPlayServices.java   
@SafeVarargs
public static Observable<GoogleApiClient> getPlayServices(final Activity activity, final RxState state, final String[] permissions, final RxPermissionRationale rationale, final Scope[] scopes, final Api<? extends Api.ApiOptions.NotRequiredOptions>... services) {
    return Observable.create(new GetPermissionStatusObservable(activity, permissions))
            .flatMap(new Function<PermissionResult, Observable<Boolean>>() {
                @Override
                public Observable<Boolean> apply(PermissionResult permissionResult) {
                    return Observable.create(new GetPermissionObservable(activity, state, rationale, permissionResult));
                }
            })
            .flatMap(new Function<Boolean, Observable<GoogleApiClient>>() {
                @Override
                public Observable<GoogleApiClient> apply(Boolean granted) {
                    if (granted) {
                        return Observable.create(new PlayServicesObservable(activity, state, scopes, services));
                    }
                    return Observable.error(new UserAbortedException());
                }
            }).compose(new BaseStateObservable.EndStateTransformer<GoogleApiClient>(state));
}
项目:Android-Design-Support-Library    文件:GoogleLoginActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_social_login);

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API)
            .addScope(new Scope("profile"))
            .build();

    btnSignIn = findViewById(R.id.sign_in_button);
    btnSignIn.setOnClickListener(this);
    btnLogout = (Button) findViewById(R.id.logout);
    btnLogout.setOnClickListener(this);
    listView = (ListView) findViewById(R.id.listView);
    image = (ImageView) findViewById(R.id.imageGoogle);
    txtDetails = (TextView) findViewById(R.id.txtUserDetails);

    doIfLoggedOut();

}
项目:GoogleFitExample    文件:DataManager.java   
/**
 *  Build a {@link GoogleApiClient} that will authenticate the user and allow the application
 *  to connect to Fitness APIs. The scopes included should match the scopes your app needs
 *  (see documentation for details). Authentication will occasionally fail intentionally,
 *  and in those cases, there will be a known resolution, which the OnConnectionFailedListener()
 *  can address. Examples of this include the user never having signed in before, or
 *  having multiple accounts on the device and needing to specify which account to use, etc.
 */
private void buildFitnessClient(final Context context) {
    if (context != null) {
        Log.i(TAG, "Creating the Google API Client with context: " + context.getClass().getName());
        // Create the Google API Client
        mClient = new GoogleApiClient.Builder(context)
                .addApiIfAvailable(Plus.API)
                .addApiIfAvailable(Fitness.SENSORS_API)
                .addApi(Fitness.SESSIONS_API)
                .addApi(Fitness.HISTORY_API)
                .addApi(Fitness.RECORDING_API)
                //.addApi(LocationServices.API)
                .addScope(new Scope(Scopes.PROFILE))
                //.addScope(new Scope(Scopes.FITNESS_LOCATION_READ_WRITE))
                .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE))
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();
    }

}
项目:Crowdi    文件:GooglePortal.java   
@Override
public void login(Activity activity) {
    mActivity = activity;
    mRequestMap = new HashMap<>();
    mSettingsManager = new SettingsManager(activity);

    mGoogleApiClient = new GoogleApiClient.Builder(mActivity)
            .addApi(Fitness.HISTORY_API)
            .addScope(new Scope(Scopes.FITNESS_LOCATION_READ))
            .addScope(new Scope(Scopes.FITNESS_NUTRITION_READ))
            .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
            .addScope(new Scope(Scopes.FITNESS_BODY_READ))
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

    if(mGoogleApiClient != null) {
        mGoogleApiClient.connect();
    }
}
项目:FirebaseUI-Android    文件:GoogleProvider.java   
private GoogleSignInOptions getSignInOptions(@Nullable String email) {
    String clientId = mActivity.getString(R.string.default_web_client_id);

    GoogleSignInOptions.Builder builder =
            new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestEmail()
                    .requestIdToken(clientId);

    // Add additional scopes
    for (String scopeString : mIdpConfig.getScopes()) {
        builder.requestScopes(new Scope(scopeString));
    }

    if (!TextUtils.isEmpty(email)) {
        builder.setAccountName(email);
    }

    return builder.build();
}
项目:nfcoauth    文件:SelectDomain.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.select_domain);
    TextView server = (TextView) findViewById(R.id.textView_server_url);
    url = getIntent().getStringExtra("server");
    server.setText(url);
    callbackManager = CallbackManager.Factory.create();

    findViewById(R.id.button_domain_google).setOnClickListener(this);
    ((SignInButton) findViewById(R.id.button_domain_google)).setSize(SignInButton.SIZE_WIDE);

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API)
            .addScope(new Scope(Scopes.PROFILE))
            .addScope(new Scope(Scopes.EMAIL))
            .build();
}
项目:Kv-009    文件:LoginFragment.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getActivity());
    loginManager = LoginManager.getInstance();
    callbackManager = CallbackManager.Factory.create();
    mActivity = getActivity();
    mContext = getActivity().getApplicationContext();
    //Google
    mGoogleApiClient = new GoogleApiClient.Builder(mContext)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API)
            .addScope(new Scope(Scopes.PROFILE))
            .build();
}
项目:RxJava2-weather-example    文件:RxLocationBaseOnSubscribe.java   
protected RxLocationBaseOnSubscribe(@NonNull Context ctx, @NonNull Api<? extends Api.ApiOptions.NotRequiredOptions>[] services, Scope[] scopes) {
    this.ctx = ctx;
    this.services = services;
    this.scopes = scopes;
    timeoutTime = null;
    timeoutUnit = null;
}
项目:RxGooglePhotos    文件:GoogleSignInOnSubscribeBase.java   
private void initGoogleApiClient() {
    final GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .requestProfile()
            .requestScopes(new Scope(SCOPE_PICASA))
            .build();
    googleApiClient = new GoogleApiClient.Builder(activity)
            .enableAutoManage(activity,
                    connectionResult -> emitter.onError(new SignInException("Connecting", connectionResult.getErrorMessage(), connectionResult.getErrorCode())))
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();
}
项目:iosched-reader    文件:LoginAndAuthHelper.java   
/** Starts the helper. Call this from your Activity's onStart(). */
public void start() {
    Activity activity = getActivity("start()");
    if (activity == null) {
        return;
    }

    if (mStarted) {
        LOGW(TAG, "Helper already started. Ignoring redundant call.");
        return;
    }

    mStarted = true;
    if (mResolving) {
        // if resolving, don't reconnect the plus client
        LOGD(TAG, "Helper ignoring signal to start because we're resolving a failure.");
        return;
    }
    LOGD(TAG, "Helper starting. Connecting " + mAccountName);
    if (mGoogleApiClient == null) {
        LOGD(TAG, "Creating client.");

        GoogleApiClient.Builder builder = new GoogleApiClient.Builder(activity);
        for (String scope : AUTH_SCOPES) {
            builder.addScope(new Scope(scope));
        }
        mGoogleApiClient = builder.addApi(Plus.API)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .setAccountName(mAccountName)
                .build();
    }
    LOGD(TAG, "Connecting client.");
    mGoogleApiClient.connect();
}