123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- package com.epson.iprint.storage.gdrivev3;
- import android.app.Activity;
- import android.content.Context;
- import android.content.Intent;
- import android.os.Bundle;
- import android.support.annotation.NonNull;
- import android.support.annotation.Nullable;
- import androidx.appcompat.app.AppCompatActivity;
- import com.epson.iprint.storage.Network;
- import com.epson.iprint.storage.OneButtonDialogFragment;
- import com.epson.iprint.storage.gdrivev3.IprintGoogleSignIn;
- import com.epson.iprint.storage.gdrivev3.PlayServiceDialogManager;
- import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
- import epson.print.R;
- import java.util.Iterator;
- import java.util.LinkedList;
- public class GoogleV3UploadSignInActivity extends AppCompatActivity implements ActivityWrapper, PlayServiceDialogManager.SingInCancelNotifier, OneButtonDialogFragment.DialogCallback, IprintGoogleSignIn.SignInListener {
- private static final String DIALOG_TAG_OFFLINE_ERROR = "offline_error";
- private static final String DIALOG_TAG_SIGN_IN_FAILED = "sign-in_failed";
- private static final String PARAM_KEY_CHECK_SERVICE_ONLY = "check-service_only";
- private static final String PARAM_KEY_FOR_DISCONNECT = "for-disconnect";
- private static final int REQUEST_CODE_CHECK_PLAY_SERVICE = 11;
- private static final int REQUEST_CODE_SIGN_IN = 10;
- private static final int REQUEST_CODE_SIGN_IN_ADD_SCOPE = 12;
- private boolean mActivityForeground;
- private boolean mCheckServiceOnly;
- private LinkedList<Runnable> mForegroundRunnableList;
- private IprintGoogleSignIn mIprintGoogleSignIn;
- private Network mMisc;
- private PlayServiceDialogManager mPlayServiceDialogManager;
- private IprintGoogleSignIn.StartActivityResultCallback mSignInStartActivityCallback;
- private boolean mStartForDisconnect;
- private boolean mWaitSingInProcess;
- @NonNull
- public Activity getActivity() {
- return this;
- }
- public int getPlayServiceRequestCode() {
- return 11;
- }
- public int getSingInAddScopeRequestCode() {
- return 12;
- }
- @NonNull
- public static Intent getDisconnectIntent(@NonNull Context context) {
- Intent intent = new Intent(context, GoogleV3UploadSignInActivity.class);
- intent.putExtra(PARAM_KEY_FOR_DISCONNECT, true);
- return intent;
- }
- @NonNull
- public static Intent getPlayServiceCheckIntent(@NonNull Context context) {
- Intent intent = new Intent(context, GoogleV3UploadSignInActivity.class);
- intent.putExtra(PARAM_KEY_CHECK_SERVICE_ONLY, true);
- return intent;
- }
- /* access modifiers changed from: protected */
- public void onCreate(Bundle bundle) {
- super.onCreate(bundle);
- this.mPlayServiceDialogManager = new PlayServiceDialogManager();
- this.mMisc = new Network();
- this.mIprintGoogleSignIn = new IprintGoogleSignIn();
- this.mWaitSingInProcess = false;
- this.mActivityForeground = false;
- this.mForegroundRunnableList = new LinkedList<>();
- Intent intent = getIntent();
- this.mStartForDisconnect = intent.getBooleanExtra(PARAM_KEY_FOR_DISCONNECT, false);
- this.mCheckServiceOnly = intent.getBooleanExtra(PARAM_KEY_CHECK_SERVICE_ONLY, false);
- }
- /* access modifiers changed from: private */
- public void showErrorDialog(final int i, final String str) {
- if (!this.mActivityForeground) {
- this.mForegroundRunnableList.addLast(new Runnable() {
- public void run() {
- GoogleV3UploadSignInActivity.this.showErrorDialog(i, str);
- }
- });
- } else {
- OneButtonDialogFragment.newInstance(i, str).show(getSupportFragmentManager(), str);
- }
- }
- /* access modifiers changed from: protected */
- public void onPostResume() {
- super.onPostResume();
- this.mMisc.selectSimpleAp(this, false);
- this.mActivityForeground = true;
- processForegroundList();
- if (!this.mMisc.isOnline(this)) {
- showErrorDialog(R.string.network_error_mes, DIALOG_TAG_OFFLINE_ERROR);
- } else if (!this.mPlayServiceDialogManager.checkPlayService(this, this)) {
- if (this.mCheckServiceOnly) {
- finishWithResult(true);
- } else if (!this.mWaitSingInProcess) {
- this.mWaitSingInProcess = true;
- if (this.mStartForDisconnect) {
- this.mIprintGoogleSignIn.disconnectAccount(this, this);
- } else {
- this.mIprintGoogleSignIn.startSignIn(this, this, IprintGoogleSignIn.OperationType.UPLOAD);
- }
- }
- }
- }
- private void processForegroundList() {
- Iterator it = this.mForegroundRunnableList.iterator();
- while (it.hasNext()) {
- it.remove();
- ((Runnable) it.next()).run();
- }
- }
- /* access modifiers changed from: protected */
- public void onPause() {
- super.onPause();
- this.mPlayServiceDialogManager.onActivityPaused();
- this.mActivityForeground = false;
- }
- public void requestSignIn(@NonNull Intent intent, @NonNull IprintGoogleSignIn.StartActivityResultCallback startActivityResultCallback) {
- this.mSignInStartActivityCallback = startActivityResultCallback;
- startActivityForResult(intent, 10);
- }
- public void playServiceInstallCancel() {
- if (this.mCheckServiceOnly) {
- finishWithResult(false);
- } else {
- showErrorDialog(R.string.authenticate_error_mes, DIALOG_TAG_SIGN_IN_FAILED);
- }
- }
- public void buttonPressed(@Nullable String str) {
- if (str != null) {
- char c = 65535;
- int hashCode = str.hashCode();
- if (hashCode != -683930452) {
- if (hashCode == 366991495 && str.equals(DIALOG_TAG_SIGN_IN_FAILED)) {
- c = 0;
- }
- } else if (str.equals(DIALOG_TAG_OFFLINE_ERROR)) {
- c = 1;
- }
- switch (c) {
- case 0:
- finishWithResult(false);
- return;
- case 1:
- startActivity(new Intent("android.settings.WIRELESS_SETTINGS"));
- finishWithResult(false);
- return;
- default:
- return;
- }
- }
- }
- /* access modifiers changed from: protected */
- public void onActivityResult(int i, int i2, Intent intent) {
- switch (i) {
- case 10:
- IprintGoogleSignIn.StartActivityResultCallback startActivityResultCallback = this.mSignInStartActivityCallback;
- if (startActivityResultCallback != null) {
- startActivityResultCallback.onActivityResult(i2, intent);
- this.mSignInStartActivityCallback = null;
- return;
- }
- return;
- case 11:
- return;
- case 12:
- if (i2 == -1) {
- finishWithResult(true);
- return;
- } else {
- showErrorDialog(R.string.authenticate_error_mes, DIALOG_TAG_SIGN_IN_FAILED);
- return;
- }
- default:
- return;
- }
- }
- public void onSignInComplete(boolean z, GoogleSignInAccount googleSignInAccount) {
- if (z) {
- finishWithResult(true);
- } else {
- showErrorDialog(R.string.authenticate_error_mes, DIALOG_TAG_SIGN_IN_FAILED);
- }
- }
- public void onDisconnectCompleted() {
- finishWithResult(true);
- }
- private void finishWithResult(boolean z) {
- GoogleV3UploadClient.setSingInValue(z);
- setResult(z ? -1 : 0);
- finish();
- }
- }
|