@OnClick(R.id.customView)
  public void showCustomView() {
    MaterialDialog dialog =
        new MaterialDialog.Builder(this)
            .title(R.string.googleWifi)
            .customView(R.layout.dialog_customview, true)
            .positiveText(R.string.connect)
            .negativeText(android.R.string.cancel)
            .onPositive(
                new MaterialDialog.SingleButtonCallback() {
                  @Override
                  public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    showToast("Password: " + passwordInput.getText().toString());
                  }
                })
            .build();

    positiveAction = dialog.getActionButton(DialogAction.POSITIVE);
    //noinspection ConstantConditions
    passwordInput = (EditText) dialog.getCustomView().findViewById(R.id.password);
    passwordInput.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            positiveAction.setEnabled(s.toString().trim().length() > 0);
          }

          @Override
          public void afterTextChanged(Editable s) {}
        });

    // Toggling the show password CheckBox will mask or unmask the password input EditText
    CheckBox checkbox = (CheckBox) dialog.getCustomView().findViewById(R.id.showPassword);
    checkbox.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            passwordInput.setInputType(
                !isChecked ? InputType.TYPE_TEXT_VARIATION_PASSWORD : InputType.TYPE_CLASS_TEXT);
            passwordInput.setTransformationMethod(
                !isChecked ? PasswordTransformationMethod.getInstance() : null);
          }
        });

    int widgetColor = ThemeSingleton.get().widgetColor;
    MDTintHelper.setTint(
        checkbox,
        widgetColor == 0 ? ContextCompat.getColor(this, R.color.material_teal_500) : widgetColor);

    MDTintHelper.setTint(
        passwordInput,
        widgetColor == 0 ? ContextCompat.getColor(this, R.color.material_teal_500) : widgetColor);

    dialog.show();
    positiveAction.setEnabled(false); // disabled by default
  }
Example #2
0
  private void showCustomView() {
    MaterialDialog dialog =
        new MaterialDialog.Builder(this)
            .title(R.string.googleWifi)
            .positiveText(R.string.agree)
            .customView(R.layout.dialog_customview)
            .positiveText(R.string.connect)
            .negativeText(android.R.string.cancel)
            .callback(
                new MaterialDialog.Callback() {
                  @Override
                  public void onPositive(MaterialDialog dialog) {
                    Toast.makeText(
                            getApplicationContext(),
                            "Password: " + passwordInput.getText().toString(),
                            Toast.LENGTH_SHORT)
                        .show();
                  }

                  @Override
                  public void onNegative(MaterialDialog dialog) {}
                })
            .build();

    positiveAction = dialog.getActionButton(DialogAction.POSITIVE);
    passwordInput = (EditText) dialog.getCustomView().findViewById(R.id.password);
    passwordInput.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            positiveAction.setEnabled(s.toString().trim().length() > 0);
          }

          @Override
          public void afterTextChanged(Editable s) {}
        });

    // Toggling the show password CheckBox will mask or unmask the password input EditText
    ((CheckBox) dialog.getCustomView().findViewById(R.id.showPassword))
        .setOnCheckedChangeListener(
            new CompoundButton.OnCheckedChangeListener() {
              @Override
              public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                passwordInput.setInputType(
                    !isChecked
                        ? InputType.TYPE_TEXT_VARIATION_PASSWORD
                        : InputType.TYPE_CLASS_TEXT);
                passwordInput.setTransformationMethod(
                    !isChecked ? PasswordTransformationMethod.getInstance() : null);
              }
            });

    dialog.show();
    positiveAction.setEnabled(false); // disabled by default
  }
  @NonNull
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    if (getArguments() == null || !getArguments().containsKey("key_name"))
      throw new IllegalStateException(
          "FingerprintDialog must be shown with show(Activity, String, int).");
    else if (savedInstanceState != null)
      mStage = (Stage) savedInstanceState.getSerializable("stage");
    setCancelable(getArguments().getBoolean("cancelable", true));

    MaterialDialog dialog =
        new MaterialDialog.Builder(getActivity())
            .title(R.string.sign_in)
            .customView(R.layout.fingerprint_dialog_container, false)
            .positiveText(android.R.string.cancel)
            .negativeText(R.string.use_password)
            .autoDismiss(false)
            .cancelable(getArguments().getBoolean("cancelable", true))
            .onPositive(
                new MaterialDialog.SingleButtonCallback() {
                  @Override
                  public void onClick(
                      @NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
                    materialDialog.cancel();
                  }
                })
            .onNegative(
                new MaterialDialog.SingleButtonCallback() {
                  @Override
                  public void onClick(
                      @NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
                    if (mStage == Stage.FINGERPRINT) {
                      goToBackup(materialDialog);
                    } else {
                      verifyPassword();
                    }
                  }
                })
            .build();

    final View v = dialog.getCustomView();
    assert v != null;
    mFingerprintContent = v.findViewById(R.id.fingerprint_container);
    mBackupContent = v.findViewById(R.id.backup_container);
    mPassword = (EditText) v.findViewById(R.id.password);
    mPassword.setOnEditorActionListener(this);
    mPasswordDescriptionTextView = (TextView) v.findViewById(R.id.password_description);
    mUseFingerprintFutureCheckBox = (CheckBox) v.findViewById(R.id.use_fingerprint_in_future_check);
    mNewFingerprintEnrolledTextView =
        (TextView) v.findViewById(R.id.new_fingerprint_enrolled_description);
    mFingerprintIcon = (ImageView) v.findViewById(R.id.fingerprint_icon);
    mFingerprintStatus = (TextView) v.findViewById(R.id.fingerprint_status);
    mFingerprintStatus.setText(R.string.initializing);

    return dialog;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    tracer = LoggerFactory.getLogger(NotificationAnnotationActivity.class.getSimpleName());

    MaterialDialog alertDialog =
        new MaterialDialog.Builder(this)
            .title(R.string.add_description)
            .customView(R.layout.alertview, false)
            .positiveText(R.string.ok)
            .negativeText(R.string.cancel)
            .callback(
                new MaterialDialog.ButtonCallback() {
                  @Override
                  public void onNeutral(MaterialDialog dialog) {
                    super.onNeutral(dialog);
                  }

                  @Override
                  public void onNegative(MaterialDialog dialog) {
                    finish();
                  }

                  @Override
                  public void onPositive(MaterialDialog dialog) {

                    EditText userInput =
                        (EditText) dialog.getCustomView().findViewById(R.id.alert_user_input);
                    tracer.info("Annotation from notification: " + userInput.getText().toString());

                    EventBus.getDefault()
                        .postSticky(new CommandEvents.Annotate(userInput.getText().toString()));

                    Intent serviceIntent =
                        new Intent(getApplicationContext(), GpsLoggingService.class);
                    getApplicationContext().startService(serviceIntent);

                    finish();
                  }
                })
            .cancelListener(
                new DialogInterface.OnCancelListener() {
                  @Override
                  public void onCancel(DialogInterface dialog) {
                    dialog.dismiss();
                    finish();
                  }
                })
            .build();
    TextView tvMessage =
        (TextView) alertDialog.getCustomView().findViewById(R.id.alert_user_message);
    tvMessage.setText(R.string.letters_numbers);
    alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    alertDialog.show();
  }
  @SuppressWarnings("ResourceType")
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    assert getArguments() != null;
    MaterialDialog dialog =
        new MaterialDialog.Builder(getActivity())
            .title(getArguments().getInt(KEY_TITLE))
            .customView(R.layout.dialog_textsize, true)
            .negativeText(android.R.string.cancel)
            .positiveText(android.R.string.ok)
            .neutralText(R.string.defaultValue)
            .autoDismiss(false)
            .onAny(this)
            .build();

    final View view = dialog.getCustomView();
    assert view != null;
    mPreview = (TextView) view.findViewById(R.id.preview);
    mSeeker = (SeekBar) view.findViewById(R.id.seeker);
    mValue = (TextView) view.findViewById(R.id.value);

    final int defaultValue =
        Config.textSizeForMode(
            getActivity(),
            getArguments().getString(KEY_ATEKEY),
            getArguments().getString(KEY_MODE));
    mPreview.setTextSize(TypedValue.COMPLEX_UNIT_PX, defaultValue);
    mSeeker.setMax(111);
    final int dpValue = pxToSp(this, defaultValue);
    mSeeker.setProgress(dpValue - 1);
    mValue.setText(String.format("%dsp", dpValue));

    mSeeker.setOnSeekBarChangeListener(
        new SeekBar.OnSeekBarChangeListener() {
          @Override
          public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            progress++;
            if (fromUser) {
              final int pxValue = spToPx(progress);
              mPreview.setTextSize(TypedValue.COMPLEX_UNIT_PX, pxValue);
              mValue.setText(String.format("%dsp", progress));
            }
          }

          @Override
          public void onStartTrackingTouch(SeekBar seekBar) {}

          @Override
          public void onStopTrackingTouch(SeekBar seekBar) {}
        });

    ATE.apply(view, getArguments().getString(KEY_ATEKEY));
    return dialog;
  }
  private void showDialogCustomDates() {
    MaterialDialog dialog =
        new MaterialDialog.Builder(getActivity())
            .customView(R.layout.dialog_choose_date_report, false)
            .positiveText(android.R.string.ok)
            .onPositive(
                new MaterialDialog.SingleButtonCallback() {
                  @Override
                  public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) {
                    View view = materialDialog.getCustomView();
                    DatePicker fromDatePicker =
                        (DatePicker) view.findViewById(R.id.datePickerFromDate);
                    DatePicker toDatePicker = (DatePicker) view.findViewById(R.id.datePickerToDate);

                    mDateFrom = DateTimeUtils.fromDatePicker(fromDatePicker);
                    mDateTo = DateUtils.getDateFromDatePicker(toDatePicker);

                    String whereClause =
                        ViewMobileData.Date
                            + ">='"
                            + FormatUtilities.getIsoDateFrom(mDateFrom)
                            + "' AND "
                            + ViewMobileData.Date
                            + "<='"
                            + DateUtils.getIsoStringDate(mDateTo)
                            + "'";

                    Bundle args = new Bundle();
                    args.putString(KEY_WHERE_CLAUSE, whereClause);

                    startLoader(args);

                    // super.onPositive(dialog);
                  }
                })
            .show();
    // set date if is null
    if (mDateFrom == null) mDateFrom = DateTimeUtils.today();
    if (mDateTo == null) mDateTo = Calendar.getInstance().getTime();

    View view = dialog.getCustomView();
    DatePicker fromDatePicker = (DatePicker) view.findViewById(R.id.datePickerFromDate);
    DatePicker toDatePicker = (DatePicker) view.findViewById(R.id.datePickerToDate);

    DateTimeUtils.setDatePicker(mDateFrom, fromDatePicker);
    DateUtils.setDateToDatePicker(mDateTo, toDatePicker);
  }
  @Override
  public MaterialDialog onCreateDialog(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mType = getArguments().getInt("dialogType");
    Resources res = getResources();
    MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity());
    builder.cancelable(true).title(getTitle());

    boolean sqliteInstalled = false;
    try {
      sqliteInstalled = Runtime.getRuntime().exec("sqlite3 --version").waitFor() == 0;
    } catch (IOException | InterruptedException e) {
      e.printStackTrace();
    }

    switch (mType) {
      case DIALOG_CURSOR_SIZE_LIMIT_EXCEEDED:
      case DIALOG_LOAD_FAILED:
        // Collection failed to load; give user the option of either choosing from repair options,
        // or closing
        // the activity
        return builder
            .cancelable(false)
            .content(getMessage())
            .iconAttr(R.attr.dialogErrorIcon)
            .positiveText(res.getString(R.string.error_handling_options))
            .negativeText(res.getString(R.string.close))
            .callback(
                new MaterialDialog.ButtonCallback() {
                  @Override
                  public void onPositive(MaterialDialog dialog) {
                    ((DeckPicker) getActivity()).showDatabaseErrorDialog(DIALOG_ERROR_HANDLING);
                  }

                  @Override
                  public void onNegative(MaterialDialog dialog) {
                    ((DeckPicker) getActivity()).exit();
                  }
                })
            .show();

      case DIALOG_DB_ERROR:
        // Database Check failed to execute successfully; give user the option of either choosing
        // from repair
        // options, submitting an error report, or closing the activity
        MaterialDialog dialog =
            builder
                .cancelable(false)
                .content(getMessage())
                .iconAttr(R.attr.dialogErrorIcon)
                .positiveText(res.getString(R.string.error_handling_options))
                .negativeText(res.getString(R.string.answering_error_report))
                .neutralText(res.getString(R.string.close))
                .callback(
                    new MaterialDialog.ButtonCallback() {
                      @Override
                      public void onPositive(MaterialDialog dialog) {
                        ((DeckPicker) getActivity()).showDatabaseErrorDialog(DIALOG_ERROR_HANDLING);
                      }

                      @Override
                      public void onNegative(MaterialDialog dialog) {
                        ((DeckPicker) getActivity()).sendErrorReport();
                        dismissAllDialogFragments();
                      }

                      @Override
                      public void onNeutral(MaterialDialog dialog) {
                        ((DeckPicker) getActivity()).exit();
                      }
                    })
                .show();
        dialog
            .getCustomView()
            .findViewById(R.id.buttonDefaultNegative)
            .setEnabled(((DeckPicker) getActivity()).hasErrorFiles());
        return dialog;

      case DIALOG_ERROR_HANDLING:
        // The user has asked to see repair options; allow them to choose one of the repair options
        // or go back
        // to the previous dialog
        ArrayList<String> options = new ArrayList<>();
        ArrayList<Integer> values = new ArrayList<>();
        if (!((AnkiActivity) getActivity()).colIsOpen()) {
          // retry
          options.add(res.getString(R.string.backup_retry_opening));
          values.add(0);
        } else {
          // fix integrity
          options.add(res.getString(R.string.check_db));
          values.add(1);
        }
        // repair db with sqlite
        if (sqliteInstalled) {
          options.add(res.getString(R.string.backup_error_menu_repair));
          values.add(2);
        }
        // // restore from backup
        options.add(res.getString(R.string.backup_restore));
        values.add(3);
        // delete old collection and build new one
        options.add(res.getString(R.string.backup_full_sync_from_server));
        values.add(4);
        // delete old collection and build new one
        options.add(res.getString(R.string.backup_del_collection));
        values.add(5);

        String[] titles = new String[options.size()];
        mRepairValues = new int[options.size()];
        for (int i = 0; i < options.size(); i++) {
          titles[i] = options.get(i);
          mRepairValues[i] = values.get(i);
        }

        dialog =
            builder
                .iconAttr(R.attr.dialogErrorIcon)
                .negativeText(res.getString(R.string.dialog_cancel))
                .items(titles)
                .itemsCallback(
                    new MaterialDialog.ListCallback() {
                      @Override
                      public void onSelection(
                          MaterialDialog materialDialog,
                          View view,
                          int which,
                          CharSequence charSequence) {
                        switch (mRepairValues[which]) {
                          case 0:
                            ((DeckPicker) getActivity()).restartActivity();
                            return;
                          case 1:
                            ((DeckPicker) getActivity())
                                .showDatabaseErrorDialog(DIALOG_CONFIRM_DATABASE_CHECK);
                            return;
                          case 2:
                            ((DeckPicker) getActivity())
                                .showDatabaseErrorDialog(DIALOG_REPAIR_COLLECTION);
                            return;
                          case 3:
                            ((DeckPicker) getActivity())
                                .showDatabaseErrorDialog(DIALOG_RESTORE_BACKUP);
                            return;
                          case 4:
                            ((DeckPicker) getActivity())
                                .showDatabaseErrorDialog(DIALOG_FULL_SYNC_FROM_SERVER);
                            return;
                          case 5:
                            ((DeckPicker) getActivity())
                                .showDatabaseErrorDialog(DIALOG_NEW_COLLECTION);
                        }
                      }
                    })
                .show();
        return dialog;

      case DIALOG_REPAIR_COLLECTION:
        // Allow user to run BackupManager.repairCollection()
        return builder
            .content(getMessage())
            .iconAttr(R.attr.dialogErrorIcon)
            .positiveText(res.getString(R.string.dialog_positive_repair))
            .negativeText(res.getString(R.string.dialog_cancel))
            .callback(
                new MaterialDialog.ButtonCallback() {
                  @Override
                  public void onPositive(MaterialDialog dialog) {
                    ((DeckPicker) getActivity()).repairDeck();
                    dismissAllDialogFragments();
                  }
                })
            .show();

      case DIALOG_RESTORE_BACKUP:
        // Allow user to restore one of the backups
        String path = CollectionHelper.getInstance().getCollectionPath(getActivity());
        File[] files = BackupManager.getBackups(new File(path));
        mBackups = new File[files.length];
        for (int i = 0; i < files.length; i++) {
          mBackups[i] = files[files.length - 1 - i];
        }
        if (mBackups.length == 0) {
          builder
              .title(res.getString(R.string.backup_restore))
              .content(getMessage())
              .positiveText(res.getString(R.string.dialog_ok))
              .callback(
                  new MaterialDialog.ButtonCallback() {
                    @Override
                    public void onPositive(MaterialDialog dialog) {
                      ((DeckPicker) getActivity()).showDatabaseErrorDialog(DIALOG_ERROR_HANDLING);
                    }
                  });
        } else {
          String[] dates = new String[mBackups.length];
          for (int i = 0; i < mBackups.length; i++) {
            dates[i] =
                mBackups[i]
                    .getName()
                    .replaceAll(".*-(\\d{4}-\\d{2}-\\d{2})-(\\d{2})-(\\d{2}).apkg", "$1 ($2:$3 h)");
          }
          builder
              .title(res.getString(R.string.backup_restore_select_title))
              .negativeText(res.getString(R.string.dialog_cancel))
              .callback(
                  new MaterialDialog.ButtonCallback() {
                    @Override
                    public void onNegative(MaterialDialog dialog) {
                      dismissAllDialogFragments();
                    }
                  })
              .items(dates)
              .itemsCallbackSingleChoice(
                  dates.length,
                  new MaterialDialog.ListCallbackSingleChoice() {
                    @Override
                    public boolean onSelection(
                        MaterialDialog materialDialog,
                        View view,
                        int which,
                        CharSequence charSequence) {
                      if (mBackups[which].length() > 0) {
                        // restore the backup if it's valid
                        ((DeckPicker) getActivity()).restoreFromBackup(mBackups[which].getPath());
                        dismissAllDialogFragments();
                      } else {
                        // otherwise show an error dialog
                        new MaterialDialog.Builder(getActivity())
                            .title(R.string.backup_error)
                            .content(R.string.backup_invalid_file_error)
                            .positiveText(R.string.dialog_ok)
                            .build()
                            .show();
                      }
                      return true;
                    }
                  });
        }
        return builder.show();

      case DIALOG_NEW_COLLECTION:
        // Allow user to create a new empty collection
        return builder
            .content(getMessage())
            .positiveText(res.getString(R.string.dialog_positive_create))
            .negativeText(res.getString(R.string.dialog_cancel))
            .callback(
                new MaterialDialog.ButtonCallback() {
                  @Override
                  public void onPositive(MaterialDialog dialog) {
                    CollectionHelper.getInstance().closeCollection(false);
                    String path = CollectionHelper.getCollectionPath(getActivity());
                    if (BackupManager.moveDatabaseToBrokenFolder(path, false)) {
                      ((DeckPicker) getActivity()).restartActivity();
                    } else {
                      ((DeckPicker) getActivity()).showDatabaseErrorDialog(DIALOG_LOAD_FAILED);
                    }
                  }
                })
            .show();

      case DIALOG_CONFIRM_DATABASE_CHECK:
        // Confirmation dialog for database check
        return builder
            .content(getMessage())
            .positiveText(res.getString(R.string.dialog_ok))
            .negativeText(res.getString(R.string.dialog_cancel))
            .callback(
                new MaterialDialog.ButtonCallback() {
                  @Override
                  public void onPositive(MaterialDialog dialog) {
                    ((DeckPicker) getActivity()).integrityCheck();
                    dismissAllDialogFragments();
                  }
                })
            .show();

      case DIALOG_CONFIRM_RESTORE_BACKUP:
        // Confirmation dialog for backup restore
        return builder
            .content(getMessage())
            .positiveText(res.getString(R.string.dialog_continue))
            .negativeText(res.getString(R.string.dialog_cancel))
            .callback(
                new MaterialDialog.ButtonCallback() {
                  @Override
                  public void onPositive(MaterialDialog dialog) {
                    ((DeckPicker) getActivity()).showDatabaseErrorDialog(DIALOG_RESTORE_BACKUP);
                  }
                })
            .show();

      case DIALOG_FULL_SYNC_FROM_SERVER:
        // Allow user to do a full-sync from the server
        return builder
            .content(getMessage())
            .positiveText(res.getString(R.string.dialog_positive_overwrite))
            .negativeText(res.getString(R.string.dialog_cancel))
            .callback(
                new MaterialDialog.ButtonCallback() {
                  @Override
                  public void onPositive(MaterialDialog dialog) {
                    ((DeckPicker) getActivity()).sync("download");
                    dismissAllDialogFragments();
                  }
                })
            .show();

      default:
        return null;
    }
  }
  public void showSocialLoginDialog() {
    smsPB.setVisibility(View.GONE);
    final MaterialDialog dialog =
        new MaterialDialog.Builder(getActivity())
            .customView(R.layout.smartdialog, false)
            .title("Sign Up")
            .titleGravity(GravityEnum.CENTER)
            .positiveText("SKIP")
            .cancelable(false)
            .callback(
                new MaterialDialog.ButtonCallback() {
                  @Override
                  public void onPositive(MaterialDialog dialog) {
                    super.onPositive(dialog);
                    dialog.dismiss();

                    mixpanel.track("Login - Skipped");
                    Intent mIntent = new Intent(getActivity(), LoginUserDetails.class);
                    startActivity(mIntent);
                  }
                })
            .show();

    View view = dialog.getCustomView();

    callbackManager = CallbackManager.Factory.create();
    LoginButton facebookBtn = (LoginButton) view.findViewById(R.id.smartDialogFacebook);
    facebookBtn.setFragment(this);
    facebookBtn.setReadPermissions(Arrays.asList("public_profile, email, user_birthday"));
    facebookBtn.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            Log.d(TAG, "Facebook login success");
            try {
              getUserFacebookDetails(loginResult);
            } catch (Exception e) {
              Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
            }
          }

          @Override
          public void onCancel() {
            Log.d(TAG, "Facebook login cancel");
          }

          @Override
          public void onError(FacebookException e) {
            Log.d(TAG, "Facebook login error");
            Toast.makeText(
                    getActivity(),
                    "Couldn't login with facebook, try again" + e.getMessage(),
                    Toast.LENGTH_SHORT)
                .show();
          }
        });

    SignInButton googleBtn = (SignInButton) view.findViewById(R.id.smartDialogGoogle);

    googleBtn.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (mGoogleApiClient.isConnected()) {
              Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
              mGoogleApiClient.disconnect();
            } else {
              mShouldResolve = true;
              mGoogleApiClient.connect();
            }
          }
        });
  }
Example #9
0
  public static void error(
      String title,
      final String friendlyMessage,
      final String errorMessage,
      final Throwable throwable,
      final Context context) {

    final String messageFormatted = getFormattedErrorMessageForDisplay(errorMessage, throwable);

    MaterialDialog alertDialog =
        new MaterialDialog.Builder(context)
            .title(title)
            .customView(R.layout.error_alertview, true)
            .autoDismiss(false)
            .negativeText("Copy")
            .positiveText(R.string.ok)
            .neutralText("Details")
            .onNeutral(
                new MaterialDialog.SingleButtonCallback() {
                  @Override
                  public void onClick(
                      @NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {

                    final ExpandableTextView expTv1 =
                        (ExpandableTextView)
                            materialDialog
                                .getCustomView()
                                .findViewById(R.id.error_expand_text_view);
                    expTv1.findViewById(R.id.expand_collapse).performClick();
                  }
                })
            .onNegative(
                new MaterialDialog.SingleButtonCallback() {
                  @Override
                  public void onClick(
                      @NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {

                    android.content.ClipboardManager clipboard =
                        (android.content.ClipboardManager)
                            context.getSystemService(Context.CLIPBOARD_SERVICE);
                    android.content.ClipData clip =
                        android.content.ClipData.newPlainText(
                            "Gpslogger error message",
                            getFormattedErrorMessageForPlainText(errorMessage, throwable));
                    clipboard.setPrimaryClip(clip);

                    materialDialog.dismiss();
                  }
                })
            .onPositive(
                new MaterialDialog.SingleButtonCallback() {
                  @Override
                  public void onClick(
                      @NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
                    materialDialog.dismiss();
                  }
                })
            .build();

    final ExpandableTextView expTv1 =
        (ExpandableTextView) alertDialog.getCustomView().findViewById(R.id.error_expand_text_view);
    expTv1.setText(Html.fromHtml(messageFormatted));
    TextView tv = (TextView) expTv1.findViewById(R.id.expandable_text);
    tv.setMovementMethod(LinkMovementMethod.getInstance());

    TextView tvFriendly =
        (TextView) alertDialog.getCustomView().findViewById(R.id.error_friendly_message);
    tvFriendly.setText(friendlyMessage);

    if (context instanceof Activity && !((Activity) context).isFinishing()) {
      alertDialog.show();
    } else {
      alertDialog.show();
    }
  }
  @Override
  public boolean onLongClick(View v) {

    final Point pointToAdd =
        new Point(new LatLng(-31.90, 115.86), "Point " + route.getPointsNumber(), false);

    final MaterialDialog dialog =
        new MaterialDialog.Builder(this)
            .title(R.string.new_point)
            .titleColor(getResources().getColor(R.color.colorAccent))
            .customView(R.layout.dialog_new_point_define, true)
            .positiveText(R.string.add)
            .backgroundColorRes(R.color.background)
            .negativeText(android.R.string.cancel)
            .onPositive(
                new MaterialDialog.SingleButtonCallback() {
                  @Override
                  public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    if (pointToAdd.getPosition().latitude != -31.90
                        && pointToAdd.getPosition().longitude != 115.86) {
                      route.addPoint(pointToAdd);
                      MapUtilities.drawPathOnMap(mMap, route, getResources());
                      robotMarker =
                          MapUtilities.placeRobotMarkerOnMap(
                              robotMarker,
                              mMap,
                              Utilities.convertLocationToLatLng(robotLocation),
                              true,
                              getResources(),
                              getApplicationContext());
                      dialog.dismiss();
                    } else {
                      Toast.makeText(
                              getApplicationContext(),
                              "Please define coordinates for the new Point",
                              Toast.LENGTH_SHORT)
                          .show();
                    }
                  }
                })
            .build();

    final EditText etLatitude = (EditText) dialog.getCustomView().findViewById(R.id.etLatitude);
    final EditText etLongitude = (EditText) dialog.getCustomView().findViewById(R.id.etLongitude);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
      etLatitude.setTextColor(getColor(R.color.green));
      etLongitude.setTextColor(getColor(R.color.colorPrimaryDark));
    }

    etLatitude.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {}

          @Override
          public void afterTextChanged(Editable s) {
            pointToAdd.setPosition(
                new LatLng(Double.parseDouble(s.toString()), pointToAdd.getPosition().longitude));
          }
        });

    etLongitude.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {}

          @Override
          public void afterTextChanged(Editable s) {
            pointToAdd.setPosition(
                new LatLng(pointToAdd.getPosition().latitude, Double.parseDouble(s.toString())));
          }
        });

    dialog.show();
    return false;
  }