com.google.android.gms.common.api.Api Java Examples

The following examples show how to use com.google.android.gms.common.api.Api. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SignIn.java    From easygoogle with Apache License 2.0 6 votes vote down vote up
@Override
public Api.ApiOptions.HasOptions getOptionsFor(Api<? extends Api.ApiOptions> api) {
    if (Auth.GOOGLE_SIGN_IN_API.equals(api)) {
        GoogleSignInOptions.Builder googleSignInOptions =  new GoogleSignInOptions.Builder(
                GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail();

        // Check server client id for OAuth, so GoogleSignInAccount.getIdToken(); is non-null
        String serverClientId = getFragment().getServerClientId();
        if(serverClientId != null){
            googleSignInOptions.requestIdToken(serverClientId);
        }
        return googleSignInOptions.build();
    } else {
        return super.getOptionsFor(api);
    }
}
 
Example #2
Source File: GoogleApiClientImpl.java    From android_external_GmsLib with Apache License 2.0 6 votes vote down vote up
public GoogleApiClientImpl(Context context, Looper looper, AccountInfo accountInfo,
                           Map<Api, Api.ApiOptions> apis,
                           Set<ConnectionCallbacks> connectionCallbacks,
                           Set<OnConnectionFailedListener> connectionFailedListeners, int clientId) {
    this.context = context;
    this.looper = looper;
    this.handler = new Handler(looper);
    this.accountInfo = accountInfo;
    this.apis.putAll(apis);
    this.connectionCallbacks.addAll(connectionCallbacks);
    this.connectionFailedListeners.addAll(connectionFailedListeners);
    this.clientId = clientId;

    for (Api api : apis.keySet()) {
        apiConnections.put(api, api.getBuilder().build(context, looper,
                apis.get(api), accountInfo, baseConnectionCallbacks,
                baseConnectionFailedListener));
    }
}
 
Example #3
Source File: RxLocationBaseOnSubscribe.java    From RxGps with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #4
Source File: GacFragment.java    From easygoogle with Apache License 2.0 5 votes vote down vote up
private void buildGoogleApiClient() {
    Log.d(TAG, "buildGoogleApiClient: " + mModules);

    // Can't build a GoogleApiClient with no APIs
    if (mModules.size() == 0) {
        Log.w(TAG, "No APIs, not building GoogleApiClient.");
        return;
    }

    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(getActivity())
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this);

    for (GacModule<?> api : mModules.values()) {
        for (Api apiObj : api.getApis()) {
            // Add Api with options, if possible
            Api.ApiOptions.HasOptions options = api.getOptionsFor(apiObj);
            if (options != null) {
                builder.addApi(apiObj, options);
            } else {
                builder.addApi(apiObj);
            }
        }

        for (Scope scopeObj : api.getScopes()) {
            builder.addScope(scopeObj);
        }
    }

    mGoogleApiClient = builder.build();
}
 
Example #5
Source File: AppLocationIntentService.java    From GooglePlayServiceLocationSupport with Apache License 2.0 5 votes vote down vote up
@Override
public void addApi(@NonNull Api<? extends Api.ApiOptions.NotRequiredOptions> value) {
    if (mGoogleApiClient != null)
        mGoogleApiClient.disconnect();
    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this).addApi(LocationServices.API).
            addConnectionCallbacks(this).addOnConnectionFailedListener(this);
    if (!value.getName().equalsIgnoreCase(LocationServices.API.getName())) {
        addApi(value);
    }
    mGoogleApiClient = builder.build();
    if (!servicesConnected())
        mGoogleApiClient.connect();
}
 
Example #6
Source File: AppLocationIntentService.java    From GooglePlayServiceLocationSupport with Apache License 2.0 5 votes vote down vote up
@Override
public void addApi(@NonNull Api<? extends Api.ApiOptions.NotRequiredOptions>[] value) {
    if (mGoogleApiClient != null)
        mGoogleApiClient.disconnect();
    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this).addApi(LocationServices.API).
            addConnectionCallbacks(this).addOnConnectionFailedListener(this);
    for (Api<? extends Api.ApiOptions.NotRequiredOptions> options : value) {
        if (!options.getName().equalsIgnoreCase(LocationServices.API.getName())) {
            builder.addApi(options);
        }
    }
    mGoogleApiClient = builder.build();
    if (!servicesConnected())
        mGoogleApiClient.connect();
}
 
Example #7
Source File: AppLocationCompatActivity.java    From GooglePlayServiceLocationSupport with Apache License 2.0 5 votes vote down vote up
@Override
public void addApi(@NonNull Api<? extends Api.ApiOptions.NotRequiredOptions>[] value) {
    if (mGoogleApiClient != null)
        mGoogleApiClient.disconnect();
    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this).addApi(LocationServices.API).enableAutoManage(this, new Random().nextInt(Integer.MAX_VALUE), this).
            addConnectionCallbacks(this).addOnConnectionFailedListener(this);
    for (Api<? extends Api.ApiOptions.NotRequiredOptions> options : value) {
        if (!options.getName().equalsIgnoreCase(LocationServices.API.getName())) {
            builder.addApi(options);
        }
    }
    mGoogleApiClient = builder.build();
    if (!servicesConnected())
        mGoogleApiClient.connect();
}
 
Example #8
Source File: AppLocationCompatActivity.java    From GooglePlayServiceLocationSupport with Apache License 2.0 5 votes vote down vote up
@Override
public void addApi(@NonNull Api<? extends Api.ApiOptions.NotRequiredOptions> value) {
    if (mGoogleApiClient != null)
        mGoogleApiClient.disconnect();
    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this).addApi(LocationServices.API).enableAutoManage(this, new Random().nextInt(Integer.MAX_VALUE), this).
            addConnectionCallbacks(this).addOnConnectionFailedListener(this);
    if (!value.getName().equalsIgnoreCase(LocationServices.API.getName())) {
        addApi(value);
    }
    mGoogleApiClient = builder.build();
    if (!servicesConnected())
        mGoogleApiClient.connect();
}
 
Example #9
Source File: AppLocationService.java    From GooglePlayServiceLocationSupport with Apache License 2.0 5 votes vote down vote up
@Override
public void addApi(@NonNull Api<? extends Api.ApiOptions.NotRequiredOptions> value) {
    if (mGoogleApiClient != null)
        mGoogleApiClient.disconnect();
    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this).addApi(LocationServices.API).
            addConnectionCallbacks(this).addOnConnectionFailedListener(this);
    if (!value.getName().equalsIgnoreCase(LocationServices.API.getName())) {
        addApi(value);
    }
    mGoogleApiClient = builder.build();
    if (!servicesConnected())
        mGoogleApiClient.connect();
}
 
Example #10
Source File: AppLocationService.java    From GooglePlayServiceLocationSupport with Apache License 2.0 5 votes vote down vote up
@Override
public void addApi(@NonNull Api<? extends Api.ApiOptions.NotRequiredOptions>[] value) {
    if (mGoogleApiClient != null)
        mGoogleApiClient.disconnect();
    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this).addApi(LocationServices.API).
            addConnectionCallbacks(this).addOnConnectionFailedListener(this);
    for (Api<? extends Api.ApiOptions.NotRequiredOptions> options : value) {
        if (!options.getName().equalsIgnoreCase(LocationServices.API.getName())) {
            builder.addApi(options);
        }
    }
    mGoogleApiClient = builder.build();
    if (!servicesConnected())
        mGoogleApiClient.connect();
}
 
Example #11
Source File: AppLocationSupportFragment.java    From GooglePlayServiceLocationSupport with Apache License 2.0 5 votes vote down vote up
@Override
public void addApi(@NonNull Api<? extends Api.ApiOptions.NotRequiredOptions>[] value) {
    if (mGoogleApiClient != null)
        mGoogleApiClient.disconnect();
    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(mContext).addApi(LocationServices.API).enableAutoManage((FragmentActivity) mContext, new Random().nextInt(Integer.MAX_VALUE), this).
            addConnectionCallbacks(this).addOnConnectionFailedListener(this);
    for (Api<? extends Api.ApiOptions.NotRequiredOptions> options : value) {
        if (!options.getName().equalsIgnoreCase(LocationServices.API.getName())) {
            builder.addApi(options);
        }
    }
    mGoogleApiClient = builder.build();
    if (!servicesConnected())
        mGoogleApiClient.connect();
}
 
Example #12
Source File: AppLocationSupportFragment.java    From GooglePlayServiceLocationSupport with Apache License 2.0 5 votes vote down vote up
@Override
public void addApi(@NonNull Api<? extends Api.ApiOptions.NotRequiredOptions> value) {
    if (mGoogleApiClient != null)
        mGoogleApiClient.disconnect();
    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(mContext).addApi(LocationServices.API).enableAutoManage((FragmentActivity) mContext, new Random().nextInt(Integer.MAX_VALUE), this).
            addConnectionCallbacks(this).addOnConnectionFailedListener(this);
    if (!value.getName().equalsIgnoreCase(LocationServices.API.getName())) {
        addApi(value);
    }
    mGoogleApiClient = builder.build();
    if (!servicesConnected())
        mGoogleApiClient.connect();
}
 
Example #13
Source File: AppLocationActivity.java    From GooglePlayServiceLocationSupport with Apache License 2.0 5 votes vote down vote up
@Override
public void addApi(@NonNull Api<? extends Api.ApiOptions.NotRequiredOptions>[] value) {
    if (mGoogleApiClient != null)
        mGoogleApiClient.disconnect();
    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this).addApi(LocationServices.API).enableAutoManage(this, new Random().nextInt(Integer.MAX_VALUE), this).
            addConnectionCallbacks(this).addOnConnectionFailedListener(this);
    for (Api<? extends Api.ApiOptions.NotRequiredOptions> options : value) {
        if (!options.getName().equalsIgnoreCase(LocationServices.API.getName())) {
            builder.addApi(options);
        }
    }
    mGoogleApiClient = builder.build();
    if (!servicesConnected())
        mGoogleApiClient.connect();
}
 
Example #14
Source File: AppLocationActivity.java    From GooglePlayServiceLocationSupport with Apache License 2.0 5 votes vote down vote up
@Override
public void addApi(@NonNull Api<? extends Api.ApiOptions.NotRequiredOptions> value) {
    if (mGoogleApiClient != null)
        mGoogleApiClient.disconnect();
    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this).addApi(LocationServices.API).enableAutoManage(this, new Random().nextInt(Integer.MAX_VALUE), this).
            addConnectionCallbacks(this).addOnConnectionFailedListener(this);
    if (!value.getName().equalsIgnoreCase(LocationServices.API.getName())) {
        addApi(value);
    }
    mGoogleApiClient = builder.build();
    if (!servicesConnected())
        mGoogleApiClient.connect();
}
 
Example #15
Source File: AppLocationFragment.java    From GooglePlayServiceLocationSupport with Apache License 2.0 5 votes vote down vote up
@Override
public void addApi(@NonNull Api<? extends Api.ApiOptions.NotRequiredOptions>[] value) {
    if (mGoogleApiClient != null)
        mGoogleApiClient.disconnect();
    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(mContext).addApi(LocationServices.API).enableAutoManage((FragmentActivity) mContext, new Random().nextInt(Integer.MAX_VALUE), this).
            addConnectionCallbacks(this).addOnConnectionFailedListener(this);
    for (Api<? extends Api.ApiOptions.NotRequiredOptions> options : value) {
        if (!options.getName().equalsIgnoreCase(LocationServices.API.getName())) {
            builder.addApi(options);
        }
    }
    mGoogleApiClient = builder.build();
    if (!servicesConnected())
        mGoogleApiClient.connect();
}
 
Example #16
Source File: AppLocationFragment.java    From GooglePlayServiceLocationSupport with Apache License 2.0 5 votes vote down vote up
@Override
public void addApi(@NonNull Api<? extends Api.ApiOptions.NotRequiredOptions> value) {
    if (mGoogleApiClient != null)
        mGoogleApiClient.disconnect();
    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(mContext).addApi(LocationServices.API).enableAutoManage((FragmentActivity) mContext, new Random().nextInt(Integer.MAX_VALUE), this).
            addConnectionCallbacks(this).addOnConnectionFailedListener(this);
    if (!value.getName().equalsIgnoreCase(LocationServices.API.getName())) {
        addApi(value);
    }
    mGoogleApiClient = builder.build();
    if (!servicesConnected())
        mGoogleApiClient.connect();
}
 
Example #17
Source File: LocationServicesApiBuilder.java    From android_external_GmsLib with Apache License 2.0 5 votes vote down vote up
@Override
public ApiConnection build(Context context, Looper looper,
        Api.ApiOptions.NoOptions options,
        AccountInfo accountInfo, GoogleApiClient.ConnectionCallbacks callbacks,
        GoogleApiClient.OnConnectionFailedListener connectionFailedListener) {
    return new LocationClientImpl(context, callbacks, connectionFailedListener);
}
 
Example #18
Source File: RxLocationBaseOnSubscribe.java    From RxGps with Apache License 2.0 5 votes vote down vote up
protected RxLocationBaseOnSubscribe(@NonNull RxLocation rxLocation, Long timeout, TimeUnit timeUnit) {
    this.ctx = rxLocation.ctx;
    this.services = new Api[]{ LocationServices.API, ActivityRecognition.API };
    this.scopes = null;

    if (timeout != null && timeUnit != null) {
        this.timeoutTime = timeout;
        this.timeoutUnit = timeUnit;
    } else {
        this.timeoutTime = rxLocation.timeoutTime;
        this.timeoutUnit = rxLocation.timeoutUnit;
    }
}
 
Example #19
Source File: AppInvites.java    From easygoogle with Apache License 2.0 4 votes vote down vote up
@Override
public List<Api> getApis() {
    return Arrays.asList(new Api[]{
        AppInvite.API
    });
}
 
Example #20
Source File: GoogleApiClientImpl.java    From android_external_GmsLib with Apache License 2.0 4 votes vote down vote up
public ApiConnection getApiConnection(Api api) {
    return apiConnections.get(api);
}
 
Example #21
Source File: SignIn.java    From easygoogle with Apache License 2.0 4 votes vote down vote up
@Override
public List<Api> getApis() {
    return Arrays.asList(new Api[]{Auth.GOOGLE_SIGN_IN_API});
}
 
Example #22
Source File: GmsConnector.java    From android_external_GmsLib with Apache License 2.0 4 votes vote down vote up
public GmsConnector(GoogleApiClient apiClient, Api api, Callback<C, R> callback) {
    this.apiClient = (GoogleApiClientImpl) apiClient;
    this.api = api;
    this.callback = callback;
}
 
Example #23
Source File: GmsConnector.java    From android_external_GmsLib with Apache License 2.0 4 votes vote down vote up
public static <C extends ApiConnection, R extends Result> PendingResult<R> call(GoogleApiClient client, Api api, GmsConnector.Callback<C, R> callback) {
    return new GmsConnector<C, R>(client, api, callback).connect();
}
 
Example #24
Source File: ActivityRecognitionApiBuilder.java    From android_external_GmsLib with Apache License 2.0 4 votes vote down vote up
@Override
public ApiConnection build(Context context, Looper looper, Api.ApiOptions.NoOptions options, AccountInfo accountInfo, GoogleApiClient.ConnectionCallbacks callbacks, GoogleApiClient.OnConnectionFailedListener connectionFailedListener) {
    return new ActivityRecognitionClientImpl(context, callbacks, connectionFailedListener);
}
 
Example #25
Source File: SmartLock.java    From easygoogle with Apache License 2.0 4 votes vote down vote up
@Override
public List<Api> getApis() {
    return Arrays.asList(new Api[]{Auth.CREDENTIALS_API});
}
 
Example #26
Source File: GacModule.java    From easygoogle with Apache License 2.0 4 votes vote down vote up
public Api.ApiOptions.HasOptions getOptionsFor(Api<? extends Api.ApiOptions> api) {
    return null;
}
 
Example #27
Source File: RxLocationSingleOnSubscribe.java    From RxGps with Apache License 2.0 4 votes vote down vote up
protected RxLocationSingleOnSubscribe(@NonNull Context ctx, @NonNull Api<? extends Api.ApiOptions.NotRequiredOptions>[] services, Scope[] scopes) {
    super(ctx, services, scopes);
}
 
Example #28
Source File: GoogleApiClientFlowable.java    From RxGps with Apache License 2.0 4 votes vote down vote up
public static Flowable<GoogleApiClient> create(@NonNull Context context, @NonNull Api<? extends Api.ApiOptions.NotRequiredOptions>[] apis, Scope[] scopes) {
    return Flowable.create(new GoogleApiClientFlowable(context, apis, scopes), BackpressureStrategy.LATEST);
}
 
Example #29
Source File: GoogleApiClientFlowable.java    From RxGps with Apache License 2.0 4 votes vote down vote up
@SafeVarargs
public static Flowable<GoogleApiClient> create(@NonNull Context context, @NonNull Api<? extends Api.ApiOptions.NotRequiredOptions>... apis) {
    return Flowable.create(new GoogleApiClientFlowable(context, apis, null), BackpressureStrategy.LATEST);
}
 
Example #30
Source File: GoogleApiClientFlowable.java    From RxGps with Apache License 2.0 4 votes vote down vote up
GoogleApiClientFlowable(Context ctx, Api<? extends Api.ApiOptions.NotRequiredOptions>[] apis, Scope[] scopes) {
    super(ctx, apis, scopes);
}