PlayServiceDialogManager.java 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package com.epson.iprint.storage.gdrivev3;
  2. import android.app.Activity;
  3. import android.app.Dialog;
  4. import android.content.DialogInterface;
  5. import com.google.android.gms.common.GoogleApiAvailability;
  6. public class PlayServiceDialogManager {
  7. private Dialog mGooglePlayServiceDialog;
  8. public interface SingInCancelNotifier {
  9. void playServiceInstallCancel();
  10. }
  11. private boolean checkPlayService(@NonNull Activity activity, int i, @NonNull final SingInCancelNotifier singInCancelNotifier) {
  12. Dialog dialog = this.mGooglePlayServiceDialog;
  13. if (dialog != null && dialog.isShowing()) {
  14. this.mGooglePlayServiceDialog.dismiss();
  15. }
  16. GoogleApiAvailability instance = GoogleApiAvailability.getInstance();
  17. int isGooglePlayServicesAvailable = instance.isGooglePlayServicesAvailable(activity);
  18. if (isGooglePlayServicesAvailable == 0) {
  19. return false;
  20. }
  21. if (instance.isUserResolvableError(isGooglePlayServicesAvailable)) {
  22. this.mGooglePlayServiceDialog = instance.getErrorDialog(activity, isGooglePlayServicesAvailable, i, new DialogInterface.OnCancelListener() {
  23. public void onCancel(DialogInterface dialogInterface) {
  24. singInCancelNotifier.playServiceInstallCancel();
  25. }
  26. });
  27. this.mGooglePlayServiceDialog.show();
  28. return true;
  29. }
  30. singInCancelNotifier.playServiceInstallCancel();
  31. return false;
  32. }
  33. public boolean checkPlayService(@NonNull ActivityWrapper activityWrapper, @NonNull SingInCancelNotifier singInCancelNotifier) {
  34. return checkPlayService(activityWrapper.getActivity(), activityWrapper.getPlayServiceRequestCode(), singInCancelNotifier);
  35. }
  36. public void onActivityPaused() {
  37. Dialog dialog = this.mGooglePlayServiceDialog;
  38. if (dialog != null && dialog.isShowing()) {
  39. this.mGooglePlayServiceDialog.dismiss();
  40. }
  41. }
  42. }