Search in sources :

Example 26 with GoogleApiClient

use of com.google.android.gms.common.api.GoogleApiClient in project PhoneProfilesPlus by henrichg.

the class LocationGeofenceEditorActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    // must by called before super.onCreate() for PreferenceActivity
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
        GlobalGUIRoutines.setTheme(this, false, true, false);
    else
        GlobalGUIRoutines.setTheme(this, false, false, false);
    GlobalGUIRoutines.setLanguage(getBaseContext());
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_location_geofence_editor);
    mResultReceiver = new AddressResultReceiver(new Handler(getMainLooper()));
    // Create a GoogleApiClient instance
    mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API).addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
    mLocationCallback = new LocationCallback() {

        @Override
        public void onLocationResult(LocationResult locationResult) {
            PPApplication.logE("LocationGeofenceEditorActivity.LocationCallback", "xxx");
            if (locationResult == null) {
                return;
            }
            for (Location location : locationResult.getLocations()) {
                mLastLocation = location;
                PPApplication.logE("LocationGeofenceEditorActivity.LocationCallback", "location=" + location);
                if (mLocation == null) {
                    mLocation = new Location(mLastLocation);
                    refreshActivity(true);
                } else
                    updateEditedMarker(false);
            }
        }
    };
    createLocationRequest();
    mResolvingError = savedInstanceState != null && savedInstanceState.getBoolean(STATE_RESOLVING_ERROR, false);
    Intent intent = getIntent();
    geofenceId = intent.getLongExtra(LocationGeofencePreference.EXTRA_GEOFENCE_ID, 0);
    if (geofenceId > 0) {
        geofence = DatabaseHandler.getInstance(getApplicationContext()).getGeofence(geofenceId);
        mLocation = new Location("LOC");
        mLocation.setLatitude(geofence._latitude);
        mLocation.setLongitude(geofence._longitude);
    }
    if (geofence == null) {
        geofenceId = 0;
        geofence = new Geofence();
        geofence._name = getString(R.string.event_preferences_location_new_location_name) + "_" + String.valueOf(DatabaseHandler.getInstance(getApplicationContext()).getGeofenceCount() + 1);
        geofence._radius = 100;
    }
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.location_editor_map);
    mapFragment.getMapAsync(this);
    radiusLabel = findViewById(R.id.location_pref_dlg_radius_seekbar_label);
    SeekBar radiusSeekBar = findViewById(R.id.location_pref_dlg_radius_seekbar);
    radiusSeekBar.setProgress(Math.round(geofence._radius / (float) 20.0) - 1);
    radiusSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            geofence._radius = (progress + 1) * 20;
            updateEditedMarker(false);
        // Log.d("LocationGeofenceEditorActivity.onProgressChanged", "radius="+geofence._radius);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    geofenceNameEditText = findViewById(R.id.location_editor_geofence_name);
    geofenceNameEditText.setText(geofence._name);
    addressText = findViewById(R.id.location_editor_address_text);
    okButton = findViewById(R.id.location_editor_ok);
    okButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String name = geofenceNameEditText.getText().toString();
            if ((!name.isEmpty()) && (mLocation != null)) {
                geofence._name = name;
                geofence._latitude = mLocation.getLatitude();
                geofence._longitude = mLocation.getLongitude();
                if (geofenceId > 0) {
                    DatabaseHandler.getInstance(getApplicationContext()).updateGeofence(geofence);
                } else {
                    DatabaseHandler.getInstance(getApplicationContext()).addGeofence(geofence);
                /*synchronized (PPApplication.geofenceScannerMutex) {
                            // start location updates
                            if ((PhoneProfilesService.instance != null) && PhoneProfilesService.isGeofenceScannerStarted())
                                PhoneProfilesService.getGeofencesScanner().connectForResolve();
                        }*/
                }
                DatabaseHandler.getInstance(getApplicationContext()).checkGeofence(String.valueOf(geofence._id), 1);
                Intent returnIntent = new Intent();
                returnIntent.putExtra(LocationGeofencePreference.EXTRA_GEOFENCE_ID, geofence._id);
                setResult(Activity.RESULT_OK, returnIntent);
                finish();
            }
        }
    });
    Button cancelButton = findViewById(R.id.location_editor_cancel);
    cancelButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent returnIntent = new Intent();
            setResult(Activity.RESULT_CANCELED, returnIntent);
            finish();
        }
    });
    AppCompatImageButton myLocationButton = findViewById(R.id.location_editor_my_location);
    myLocationButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mLastLocation != null)
                mLocation = new Location(mLastLocation);
            refreshActivity(true);
        }
    });
    addressButton = findViewById(R.id.location_editor_address_btn);
    addressButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getGeofenceAddress();
        }
    });
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) SeekBar(android.widget.SeekBar) LocationCallback(com.google.android.gms.location.LocationCallback) Handler(android.os.Handler) Intent(android.content.Intent) AppCompatImageButton(android.support.v7.widget.AppCompatImageButton) View(android.view.View) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) LocationResult(com.google.android.gms.location.LocationResult) SupportMapFragment(com.google.android.gms.maps.SupportMapFragment) Button(android.widget.Button) AppCompatImageButton(android.support.v7.widget.AppCompatImageButton) Location(android.location.Location)

Example 27 with GoogleApiClient

use of com.google.android.gms.common.api.GoogleApiClient in project connect-sdk-client-android by Ingenico-ePayments.

the class AndroidPayUtil method isAndroidPayAllowed.

private static boolean isAndroidPayAllowed(Collection<Integer> networks, Context context, C2sCommunicator communicator) {
    GoogleApiClient client = new GoogleApiClient.Builder(context).addApi(Wallet.API, new Wallet.WalletOptions.Builder().setEnvironment(getWalletEnvironment(communicator)).build()).build();
    client.connect();
    IsReadyToPayRequest request = createIsReadyToPayRequest(networks);
    PendingResult<BooleanResult> result = Wallet.Payments.isReadyToPay(client, request);
    BooleanResult actualResult = result.await(Constants.ACCEPTABLE_WAIT_TIME_IN_MILISECONDS, TimeUnit.MILLISECONDS);
    if (actualResult.getStatus().isSuccess()) {
        return actualResult.getValue();
    } else {
        Log.e(TAG, "Error while making isReadyToPay call: " + actualResult.getStatus());
        return false;
    }
}
Also used : BooleanResult(com.google.android.gms.common.api.BooleanResult) GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) Wallet(com.google.android.gms.wallet.Wallet) IsReadyToPayRequest(com.google.android.gms.wallet.IsReadyToPayRequest)

Example 28 with GoogleApiClient

use of com.google.android.gms.common.api.GoogleApiClient in project CodenameOne by codenameone.

the class GoogleImpl method getClient.

private GoogleApiClient getClient(SuccessCallback<GoogleApiClient> onConnected) {
    if (mGoogleApiClient == null) {
        Context ctx = AndroidNativeUtil.getContext();
        if (mGoogleApiClient == null) {
            GoogleSignInOptions gso;
            if (clientId != null && clientSecret != null) {
                System.out.println("Generating GoogleSignIn for clientID=" + clientId);
                List<Scope> includeScopes = new ArrayList<Scope>();
                Scope firstScope = new Scope(Scopes.PROFILE);
                if (scope != null) {
                    for (String str : Util.split(scope, " ")) {
                        if ("profile".equals(str)) {
                            // str = Scopes.PROFILE;
                            continue;
                        } else if ("email".equals(str)) {
                            str = Scopes.EMAIL;
                        } else if (Scopes.PROFILE.equals(str)) {
                            continue;
                        }
                        if (str.trim().isEmpty()) {
                            continue;
                        }
                        includeScopes.add(new Scope(str.trim()));
                    }
                }
                gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestIdToken(clientId).requestScopes(firstScope, includeScopes.toArray(new Scope[includeScopes.size()])).requestServerAuthCode(clientId).build();
            } else {
                System.out.println("Generating GoogleSignIn without ID token");
                gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).build();
            }
            mGoogleApiClient = new GoogleApiClient.Builder(ctx).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(Auth.GOOGLE_SIGN_IN_API, gso).build();
        }
    }
    if (mGoogleApiClient.isConnected()) {
        if (onConnected != null) {
            onConnected.onSucess(mGoogleApiClient);
        }
    } else {
        synchronized (onConnectedCallbacks) {
            if (onConnected != null) {
                onConnectedCallbacks.add(onConnected);
            }
            if (!mGoogleApiClient.isConnecting()) {
                mGoogleApiClient.connect(GoogleApiClient.SIGN_IN_MODE_OPTIONAL);
            }
        }
    }
    return mGoogleApiClient;
}
Also used : Context(android.content.Context) GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) Scope(com.google.android.gms.common.api.Scope) ArrayList(java.util.ArrayList) GoogleSignInOptions(com.google.android.gms.auth.api.signin.GoogleSignInOptions)

Example 29 with GoogleApiClient

use of com.google.android.gms.common.api.GoogleApiClient in project wire-android by wireapp.

the class LocationFragment method onCreate.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (isGooglePlayServicesAvailable()) {
        googleApiClient = new GoogleApiClient.Builder(getContext()).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(LocationServices.API).build();
        googleApiClient.connect();
    } else {
        locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
    }
    mainHandler = new Handler();
    handlerThread = new HandlerThread("Background handler");
    handlerThread.start();
    backgroundHandler = new Handler(handlerThread.getLooper());
    geocoder = new Geocoder(getContext(), Locale.getDefault());
    zoom = true;
    // retrieve the accent color to be used for the paint
    accentColor = AccentColor.defaultColor().color();
    ((BaseActivity) getContext()).injectJava(AccentColorController.class).accentColorForJava(new AccentColorCallback() {

        @Override
        public void color(AccentColor color) {
            selectedLocationPin.setTextColor(color.color());
            marker = null;
            accentColor = color.color();
        }
    }, EventContext.Implicits$.MODULE$.global());
}
Also used : AccentColor(com.waz.model.AccentColor) GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) HandlerThread(android.os.HandlerThread) AccentColorController(com.waz.zclient.common.controllers.global.AccentColorController) AccentColorCallback(com.waz.zclient.common.controllers.global.AccentColorCallback) Handler(android.os.Handler) Geocoder(android.location.Geocoder)

Example 30 with GoogleApiClient

use of com.google.android.gms.common.api.GoogleApiClient in project Thesis by bajnax.

the class LeScanActivity method enableLocation.

public void enableLocation() {
    if (googleApiClient == null) {
        googleApiClient = new GoogleApiClient.Builder(LeScanActivity.this).addApi(LocationServices.API).addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {

            @Override
            public void onConnected(Bundle bundle) {
            }

            @Override
            public void onConnectionSuspended(int i) {
                googleApiClient.connect();
            }
        }).addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {

            @Override
            public void onConnectionFailed(ConnectionResult connectionResult) {
                Log.d("Location error", "Location error " + connectionResult.getErrorCode());
            }
        }).build();
        googleApiClient.connect();
    }
    LocationRequest locationRequest = LocationRequest.create();
    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    locationRequest.setInterval(30 * 1000);
    locationRequest.setFastestInterval(5 * 1000);
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
    builder.setAlwaysShow(true);
    PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
    result.setResultCallback(new ResultCallback<LocationSettingsResult>() {

        @Override
        public void onResult(LocationSettingsResult result) {
            final Status status = result.getStatus();
            switch(status.getStatusCode()) {
                case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                    try {
                        // requesting to enable Bluetooth
                        status.startResolutionForResult(LeScanActivity.this, REQUEST_ENABLE_LS);
                    } catch (IntentSender.SendIntentException e) {
                    // Ignore the error.
                    }
                    break;
            }
        }
    });
}
Also used : Status(com.google.android.gms.common.api.Status) GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) LocationRequest(com.google.android.gms.location.LocationRequest) LocationSettingsResult(com.google.android.gms.location.LocationSettingsResult) Bundle(android.os.Bundle) LocationSettingsRequest(com.google.android.gms.location.LocationSettingsRequest) ConnectionResult(com.google.android.gms.common.ConnectionResult)

Aggregations

GoogleApiClient (com.google.android.gms.common.api.GoogleApiClient)32 ConnectionResult (com.google.android.gms.common.ConnectionResult)10 Bundle (android.os.Bundle)6 Intent (android.content.Intent)5 Handler (android.os.Handler)4 PendingIntent (android.app.PendingIntent)3 SharedPreferences (android.content.SharedPreferences)3 Bitmap (android.graphics.Bitmap)3 NonNull (android.support.annotation.NonNull)3 GoogleSignInOptions (com.google.android.gms.auth.api.signin.GoogleSignInOptions)3 NotificationManager (android.app.NotificationManager)2 NotificationCompat (android.support.v4.app.NotificationCompat)2 GoogleSignInResult (com.google.android.gms.auth.api.signin.GoogleSignInResult)2 Scope (com.google.android.gms.common.api.Scope)2 Status (com.google.android.gms.common.api.Status)2 DataItem (com.google.android.gms.wearable.DataItem)2 Node (com.google.android.gms.wearable.Node)2 PutDataMapRequest (com.google.android.gms.wearable.PutDataMapRequest)2 RemoteIntent (com.google.android.wearable.intent.RemoteIntent)2 SuppressLint (android.annotation.SuppressLint)1