@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == PROFILE_REQUEST && resultCode == CommonStatusCodes.SUCCESS) { preferences.setIdAuth(""); preferences.setUserData(""); preferences.setUserDni(""); preferences.setEmail(""); preferences.setIsLogged(false); setDataToHeader(preferences); if (!(getSupportFragmentManager().findFragmentById(R.id.containerHome) instanceof MapFragment)) { navigationView.getMenu().getItem(0).setChecked(true); setTitleToolbar(getString(R.string.map_stations)); getSupportFragmentManager().popBackStack("", FragmentManager.POP_BACK_STACK_INCLUSIVE); } } else if (requestCode == 140) { Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.containerHome); if (fragment != null && fragment instanceof MapFragment) { fragment.onActivityResult(requestCode, resultCode, data); } } else if (resultCode == Activity.RESULT_OK && requestCode == LoginActivity.LOGIN_RESULT) { navigationView.getMenu().getItem(itemSelected).setChecked(true); preferences.setIsLogged(true); setDataToHeader(preferences); } }
protected void handleSignInResult(GoogleSignInResult result) { Schedulers.newThread() .scheduleDirect(() -> { if (result.isSuccess()) { if (result.getSignInAccount() != null && result.getSignInAccount().getAccount() != null) { Account account = result.getSignInAccount().getAccount(); try { String token = GoogleAuthUtil.getToken(activity, account, "oauth2:" + SCOPE_PICASA); emitter.onSuccess(new GoogleSignIn.SignInAccount(token, result.getSignInAccount())); } catch (IOException | GoogleAuthException e) { emitter.onError(new SignInException("SignIn", e)); } } else { emitter.onError(new SignInException("SignIn", "getSignInAccount is null!", 0)); } } else { if (result.getStatus().getStatusCode() == CommonStatusCodes.SIGN_IN_REQUIRED) { emitter.onError(new SignInRequiredException()); } else { emitter.onError(new SignInException("SignIn", result.getStatus().getStatusMessage(), result.getStatus().getStatusCode())); } } }); }
/** * onTap is called to capture the first TextBlock under the tap location and return it to * the Initializing Activity. * * @param rawX - the raw position of the tap * @param rawY - the raw position of the tap. * @return true if the activity is ending. */ private boolean onTap(float rawX, float rawY) { OcrGraphic graphic = mGraphicOverlay.getGraphicAtLocation(rawX, rawY); TextBlock text = null; if (graphic != null) { text = graphic.getTextBlock(); if (text != null && text.getValue() != null) { Intent data = new Intent(); data.putExtra(TextBlockObject, text.getValue()); setResult(CommonStatusCodes.SUCCESS, data); finish(); } else { Log.d(TAG, "text data is null"); } } else { Log.d(TAG,"no text detected"); } return text != null; }
/** * Called when an activity you launched exits, giving you the requestCode * you started it with, the resultCode it returned, and any additional * data from it. The <var>resultCode</var> will be * {@link #RESULT_CANCELED} if the activity explicitly returned that, * didn't return any result, or crashed during its operation. * <p/> * <p>You will receive this call immediately before onResume() when your * activity is re-starting. * <p/> * * @param requestCode The integer request code originally supplied to * startActivityForResult(), allowing you to identify who this * result came from. * @param resultCode The integer result code returned by the child activity * through its setResult(). * @param data An Intent, which can return result data to the caller * (various data can be attached to Intent "extras"). * @see #startActivityForResult * @see #createPendingResult * @see #setResult(int) */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(requestCode == RC_OCR_CAPTURE) { if (resultCode == CommonStatusCodes.SUCCESS) { if (data != null) { String text = data.getStringExtra(OcrCaptureActivity.TextBlockObject); statusMessage.setText(R.string.ocr_success); textValue.setText(text); Log.d(TAG, "Text read: " + text); } else { statusMessage.setText(R.string.ocr_failure); Log.d(TAG, "No Text captured, intent data is null"); } } else { statusMessage.setText(String.format(getString(R.string.ocr_error), CommonStatusCodes.getStatusCodeString(resultCode))); } } else { super.onActivityResult(requestCode, resultCode, data); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == BARCODE_READER_REQUEST_CODE) { if (resultCode == CommonStatusCodes.SUCCESS) { if (data != null) { Barcode barcode = data.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject); QRURLParser parser = QRURLParser.getInstance(); String extracted_address = parser.extractAddressFromQrString(barcode.displayValue); if (extracted_address == null) { Toast.makeText(this, R.string.toast_qr_code_no_address, Toast.LENGTH_SHORT).show(); return; } Point[] p = barcode.cornerPoints; toAddressText.setText(extracted_address); } } else { Log.e("SEND", String.format(getString(R.string.barcode_error_format), CommonStatusCodes.getStatusCodeString(resultCode))); } } else { super.onActivityResult(requestCode, resultCode, data); } }
private void resolveResult(Status status) { if (status.getStatusCode() == CommonStatusCodes.RESOLUTION_REQUIRED) { try { //status.startResolutionForResult(mActivity, RC_READ); startIntentSenderForResult(status.getResolution().getIntentSender(), RC_READ, null, 0, 0, 0, null); } catch (IntentSender.SendIntentException e) { e.printStackTrace(); mCredentialsApiClient.disconnect(); mAccountSubject.onError(new Throwable(e.toString())); } } else { // The user must create an account or sign in manually. mCredentialsApiClient.disconnect(); mAccountSubject.onError(new Throwable(getString(R.string.status_canceled_request_credential))); } }
/** * Facebook sign out */ public void signOut(PublishSubject<RxStatus> statusSubject) { LoginManager.getInstance().logOut(); // delete current user deleteCurrentUser(); statusSubject.onNext(new RxStatus( CommonStatusCodes.SUCCESS, getString(R.string.status_success_log_out_message) )); statusSubject.onCompleted(); }
private void handleUnsuccessfulNearbyResult(Status status) { Log.v(TAG, "Processing error, status = " + status); if (mResolvingError) { // Already attempting to resolve an error. return; } else if (status.hasResolution()) { try { mResolvingError = true; status.startResolutionForResult(getActivity(), REQUEST_RESOLVE_ERROR); } catch (IntentSender.SendIntentException e) { mResolvingError = false; Log.v(TAG, "Failed to resolve error status.", e); } } else { if (status.getStatusCode() == CommonStatusCodes.NETWORK_ERROR) { Toast.makeText(getActivity(), "No connectivity, cannot proceed. Fix in 'Settings' and try again.", Toast.LENGTH_LONG).show(); } else { // To keep things simple, pop a toast for all other error messages. Toast.makeText(getActivity(), "Unsuccessful: " + status.getStatusMessage(), Toast.LENGTH_LONG).show(); } } }
/** * Called when an activity you launched exits, giving you the requestCode * you started it with, the resultCode it returned, and any additional * data from it. The <var>resultCode</var> will be * {@link #RESULT_CANCELED} if the activity explicitly returned that, * didn't return any result, or crashed during its operation. * <p/> * <p>You will receive this call immediately before onResume() when your * activity is re-starting. * <p/> * * @param requestCode The integer request code originally supplied to * startActivityForResult(), allowing you to identify who this * result came from. * @param resultCode The integer result code returned by the child activity * through its setResult(). * @param data An Intent, which can return result data to the caller * (various data can be attached to Intent "extras"). * @see #startActivityForResult * @see #createPendingResult * @see #setResult(int) */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(requestCode == RC_OCR_CAPTURE) { if (resultCode == CommonStatusCodes.SUCCESS) { if (data != null) { String text = data.getStringExtra(OcrCaptureActivity.TextBlockObject); statusMessage.setText(R.string.ocr_success); textValue.setText(text); Log.d(TAG, "Text read: " + text); } else { statusMessage.setText(R.string.ocr_failure); Log.d(TAG, "No Text captured, intent data is null"); } } else { statusMessage.setText(String.format(getString(R.string.ocr_error), CommonStatusCodes.getStatusCodeString(resultCode))); } displayStatus(); } else { super.onActivityResult(requestCode, resultCode, data); } }
@Override public void onFailure(@NonNull Exception e) { // An error occurred while communicating with the service. mResult = null; if (e instanceof ApiException) { // An error with the Google Play Services API contains some additional details. ApiException apiException = (ApiException) e; Log.d(TAG, "Error: " + CommonStatusCodes.getStatusCodeString(apiException.getStatusCode()) + ": " + apiException.getStatusMessage()); } else { // A different, unknown type of error occurred. Log.d(TAG, "ERROR! " + e.getMessage()); } }
@VisibleForTesting protected void handleUnsuccessfulNearbyResult(Status status) { Log.v(TAG, "Processing error, status = " + status); if (resolvingError) { // Already attempting to resolve an error. return; } else if (status.hasResolution()) { try { resolvingError = true; status.startResolutionForResult(this, REQUEST_RESOLVE_ERROR); } catch (Exception e) { resolvingError = false; Log.v(TAG, "Failed to resolve error status.", e); } } else { if (status.getStatusCode() == CommonStatusCodes.NETWORK_ERROR) { Toast.makeText(this, "No connectivity, cannot proceed. Fix in 'Settings' and try again.", Toast.LENGTH_LONG).show(); } else { Toast.makeText(this, "Unsuccessful: " + status.getStatusMessage(), Toast.LENGTH_LONG).show(); } } }
/** * onTap is called to capture the oldest barcode currently detected and * return it to the caller. * * @param rawX - the raw position of the tap * @param rawY - the raw position of the tap. * @return true if the activity is ending. */ private boolean onTap(float rawX, float rawY) { //TODO: use the tap position to select the barcode. BarcodeGraphic graphic = mGraphicOverlay.getFirstGraphic(); Barcode barcode = null; if (graphic != null) { barcode = graphic.getBarcode(); if (barcode != null) { Intent data = new Intent(); data.putExtra(BarcodeObject, barcode); setResult(CommonStatusCodes.SUCCESS, data); finish(); } else { Log.d(TAG, "barcode data is null"); } } else { Log.d(TAG,"no barcode detected"); } return barcode != null; }
/** * Called when an activity you launched exits, giving you the requestCode * you started it with, the resultCode it returned, and any additional * data from it. The <var>resultCode</var> will be * {@link #RESULT_CANCELED} if the activity explicitly returned that, * didn't return any result, or crashed during its operation. * <p/> * <p>You will receive this call immediately before onResume() when your * activity is re-starting. * <p/> * * @param requestCode The integer request code originally supplied to * startActivityForResult(), allowing you to identify who this * result came from. * @param resultCode The integer result code returned by the child activity * through its setResult(). * @param data An Intent, which can return result data to the caller * (various data can be attached to Intent "extras"). * @see #startActivityForResult * @see #createPendingResult * @see #setResult(int) */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == RC_BARCODE_CAPTURE) { if (resultCode == CommonStatusCodes.SUCCESS) { if (data != null) { Barcode barcode = data.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject); statusMessage.setText(R.string.barcode_success); barcodeValue.setText(barcode.displayValue); Log.d(TAG, "Barcode read: " + barcode.displayValue); } else { statusMessage.setText(R.string.barcode_failure); Log.d(TAG, "No barcode captured, intent data is null"); } } else { statusMessage.setText(String.format(getString(R.string.barcode_error), CommonStatusCodes.getStatusCodeString(resultCode))); } } else { super.onActivityResult(requestCode, resultCode, data); } }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { Log.d(TAG, "onActivityResult"); if (requestCode == RC_BARCODE_CAPTURE) { if (resultCode == CommonStatusCodes.SUCCESS) { if (data != null) { Barcode barcode = data.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject); Log.d(TAG, "Barcode read: " + barcode.displayValue); mPresenter.newEvent(barcode); } else { Log.d(TAG, "No barcode captured, intent data is null"); } } else { Log.d(TAG, "onActivityResult is not a success"); } } else { super.onActivityResult(requestCode, resultCode, data); } }
@Override public void onConnected(@Nullable Bundle bundle) { googleApi.requestCredentials(new ResultCallback<CredentialRequestResult>() { @Override public void onResult(@NonNull CredentialRequestResult result) { if (result.getStatus().isSuccess()) { onCredentialRetrieved(result.getCredential()); } else if (result.getStatus().getStatusCode() != CommonStatusCodes.SIGN_IN_REQUIRED && result.getStatus().hasResolution()) { try { result.getStatus().startResolutionForResult(LoginActivity.this, GoogleApiAdapter.RETRIEVE_CREDENTIALS); } catch (IntentSender.SendIntentException e) { Snackbar.make(vLoginForm, R.string.error_smartlock_failed, Snackbar.LENGTH_LONG); } } } }); }
public static Status zzhO(int paramInt) { String str; switch (paramInt) { default: str = CommonStatusCodes.getStatusCodeString(paramInt); } for (;;) { return new Status(paramInt, str); str = "TARGET_NODE_NOT_CONNECTED"; continue; str = "DUPLICATE_LISTENER"; continue; str = "UNKNOWN_LISTENER"; continue; str = "DATA_ITEM_TOO_LARGE"; continue; str = "INVALID_TARGET_NODE"; continue; str = "ASSET_UNAVAILABLE"; } }
private List<String> getCurrentUsersGooglePlusIds() { ArrayList<String> friendGooglePlusIds = new ArrayList<>(); ConnectionResult connectionResult = googleApiClient .blockingConnect(Constants.CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS); if (connectionResult.isSuccess()) { People.LoadPeopleResult peopleData = Plus.PeopleApi.loadVisible(googleApiClient, null).await(); if (peopleData.getStatus().getStatusCode() == CommonStatusCodes.SUCCESS) { PersonBuffer personBuffer = peopleData.getPersonBuffer(); try { int count = personBuffer.getCount(); for (int i = 0; i < count; i++) { friendGooglePlusIds.add(personBuffer.get(i).getId()); } } finally { personBuffer.close(); } } else { Timber.w("Error requesting visible circles: %s", peopleData.getStatus()); } } if (googleApiClient.isConnected()) { googleApiClient.disconnect(); } return friendGooglePlusIds; }
private void addGeofence(GeofencingRequest geofencingRequest, PendingIntent geofencePendingIntent) { if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager .PERMISSION_GRANTED) { return; } LocationServices.GeofencingApi.addGeofences( googleApiClient, geofencingRequest, geofencePendingIntent ).setResultCallback(new ResultCallback<Status>() { @Override public void onResult(@NonNull Status status) { switch (status.getStatusCode()) { case CommonStatusCodes.SUCCESS: StatusMessageHandler.showInfoMessage(context, R.string.geofence_enabled, Snackbar.LENGTH_SHORT); } Log.d(GeofenceApiHandler.class, status.toString()); } }); }
private void removeGeofence(GoogleApiClient googleApiClient, final String geofenceId) { ArrayList<String> geofenceIds = new ArrayList<>(); geofenceIds.add(geofenceId); LocationServices.GeofencingApi.removeGeofences( googleApiClient, geofenceIds ).setResultCallback(new ResultCallback<Status>() { @Override public void onResult(@NonNull Status status) { switch (status.getStatusCode()) { case CommonStatusCodes.SUCCESS: StatusMessageHandler.showInfoMessage(context, R.string.geofence_disabled, Snackbar.LENGTH_SHORT); } Log.d(GeofenceApiHandler.class, status.toString()); } }); // Result processed in onResult(). }
/** * Remove all Geofences from Google Location Api */ public void removeAllGeofences() { LocationServices.GeofencingApi.removeGeofences( googleApiClient, // This is the same pending intent that was used in addGeofence(). getGeofencePendingIntent() ).setResultCallback(new ResultCallback<Status>() { @Override public void onResult(@NonNull Status status) { switch (status.getStatusCode()) { case CommonStatusCodes.SUCCESS: StatusMessageHandler.showInfoMessage(context, R.string.geofences_disabled, Snackbar .LENGTH_LONG); } Log.d(GeofenceApiHandler.class, status.toString()); } }); // Result processed in onResult(). }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == BARCODE_CAPTURE) { if (resultCode == CommonStatusCodes.SUCCESS) { if (data != null) { Barcode barcode = data.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject); statusMessage.setText("Success!"); barcodeValue.setText(barcode.displayValue); Log.d("BARCODER", "Barcode read: " + barcode.displayValue); } else { statusMessage.setText("Fail"); Log.d("BARCODER", "No barcode has been captured"); } } else { statusMessage.setText("Error"); } } else { super.onActivityResult(requestCode, resultCode, data); } }
/** * Begin the process of retrieving a {@link Credential} for the device user. This can have * a few different results: * 1) If the user has auto sign-in enabled and exactly one previously saved credential, * {@link SmartLockListener#onCredentialRetrieved(Credential)} will be called and * you can sign the user in immediately. * 2) If the user has multiple saved credentials or one saved credential and has disabled * auto sign-in, you will get the callback {@link SmartLockListener#onShouldShowCredentialPicker()} * at which point you can choose to show the picker dialog to continue. * 3) If the user has no saved credentials or cancels the operation, you will receive the * {@link SmartLockListener#onCredentialRetrievalFailed()} callback. */ public void getCredentials() { CredentialRequest request = buildCredentialRequest(); Auth.CredentialsApi.request(getFragment().getGoogleApiClient(), request) .setResultCallback(new ResultCallback<CredentialRequestResult>() { @Override public void onResult(CredentialRequestResult result) { if (result.getStatus().isSuccess()) { // Single credential, auto sign-in Credential credential = result.getCredential(); getListener().onCredentialRetrieved(credential); } else if (result.getStatus().hasResolution() && result.getStatus().getStatusCode() != CommonStatusCodes.SIGN_IN_REQUIRED) { // Multiple credentials or auto-sign in disabled. If the status // code is SIGN_IN_REQUIRED then it is a hint credential, which we // do not want at this point. getListener().onShouldShowCredentialPicker(); } else { // Could not retrieve credentials getListener().onCredentialRetrievalFailed(); } } }); }
private void onError(GoogleSignInResult result) { Status status = result.getStatus(); if (status.getStatusCode() == CommonStatusCodes.INVALID_ACCOUNT) { mGoogleApiClient.stopAutoManage(mActivity); mGoogleApiClient.disconnect(); mGoogleApiClient = new GoogleApiClient.Builder(mActivity) .enableAutoManage(mActivity, GoogleApiHelper.getSafeAutoManageId(), this) .addApi(Auth.GOOGLE_SIGN_IN_API, getSignInOptions(null)) .build(); startLogin(mActivity); } else { if (status.getStatusCode() == CommonStatusCodes.DEVELOPER_ERROR) { Log.w(TAG, "Developer error: this application is misconfigured. Check your SHA1 " + " and package name in the Firebase console."); Toast.makeText(mActivity, "Developer error.", Toast.LENGTH_SHORT).show(); } onError(status.getStatusCode() + " " + status.getStatusMessage()); } }
@Override public void onResult(@NonNull CredentialRequestResult result) { Status status = result.getStatus(); if (status.isSuccess()) { // Auto sign-in success handleCredential(result.getCredential()); return; } else { if (status.hasResolution()) { try { if (status.getStatusCode() == CommonStatusCodes.RESOLUTION_REQUIRED) { startIntentSenderForResult( status.getResolution().getIntentSender(), RC_CREDENTIALS_READ); return; } } catch (IntentSender.SendIntentException e) { Log.e(TAG, "Failed to send Credentials intent.", e); } } else { Log.e(TAG, "Status message:\n" + status.getStatusMessage()); } } startAuthMethodChoice(); }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE_SCAN_ICCID) { if (resultCode == CommonStatusCodes.SUCCESS && data != null) { Barcode barcode = data.getParcelableExtra(BarcodeScannerActivity.EXTRA_BARCODE); log.d("Barcode read: " + barcode.displayValue); this.onBarcodeScanningFinished(barcode.displayValue); } else { Toaster.s(this, "No barcode scanned."); } } else { super.onActivityResult(requestCode, resultCode, data); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.person_list_activity); PlusOptions options = PlusOptions.builder().addActivityTypes(MomentUtil.ACTIONS).build(); mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Plus.API, options) .addScope(Plus.SCOPE_PLUS_LOGIN) .build(); mListItems = new ArrayList<String>(); mListAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mListItems); mPersonListView = (ListView) findViewById(R.id.person_list); mResolvingError = savedInstanceState != null && savedInstanceState.getBoolean(STATE_RESOLVING_ERROR, false); int available = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (available != CommonStatusCodes.SUCCESS) { showDialog(DIALOG_GET_GOOGLE_PLAY_SERVICES); } }
@Override protected Dialog onCreateDialog(int id) { if (id != DIALOG_GET_GOOGLE_PLAY_SERVICES) { return super.onCreateDialog(id); } int available = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (available == CommonStatusCodes.SUCCESS) { return null; } if (GooglePlayServicesUtil.isUserRecoverableError(available)) { return GooglePlayServicesUtil.getErrorDialog( available, this, REQUEST_CODE_GET_GOOGLE_PLAY_SERVICES, this); } return new AlertDialog.Builder(this) .setMessage(R.string.plus_generic_error) .setCancelable(true) .setOnCancelListener(this) .create(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list_moments_activity); PlusOptions options = PlusOptions.builder().addActivityTypes(MomentUtil.ACTIONS).build(); mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Plus.API, options) .addScope(Plus.SCOPE_PLUS_LOGIN) .build(); mListItems = new ArrayList<Moment>(); mMomentListAdapter = new MomentListAdapter(this, android.R.layout.simple_list_item_1, mListItems); mMomentListView = (ListView) findViewById(R.id.moment_list); mMomentListView.setOnItemClickListener(this); mResolvingError = savedInstanceState != null && savedInstanceState.getBoolean(STATE_RESOLVING_ERROR, false); int available = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (available != CommonStatusCodes.SUCCESS) { showDialog(DIALOG_GET_GOOGLE_PLAY_SERVICES); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.multi_moment_activity); PlusOptions options = PlusOptions.builder().addActivityTypes(MomentUtil.ACTIONS).build(); mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Plus.API, options) .addScope(Plus.SCOPE_PLUS_LOGIN) .build(); mListAdapter = new ArrayAdapter<String>( this, android.R.layout.simple_list_item_1, MomentUtil.MOMENT_LIST); mMomentListView = (ListView) findViewById(R.id.moment_list); mMomentListView.setOnItemClickListener(this); mResolvingError = savedInstanceState != null && savedInstanceState.getBoolean(STATE_RESOLVING_ERROR, false); int available = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (available != CommonStatusCodes.SUCCESS) { showDialog(DIALOG_GET_GOOGLE_PLAY_SERVICES); } }