Ejemplo n.º 1
0
  @Override
  public void onCreate() {
    super.onCreate();

    instance = this;
    Esperandro.setSerializer(new FastJsonSerial());
    ControlFactory.init(this);
    FrescoUtil.init(this);
    CrashHandler.getInstance().init(this);
    PluginHelper.getInstance().applicationOnCreate(getBaseContext());
  }
    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
      AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
      final DefaultPrefs defaultPrefs =
          Esperandro.getPreferences(DefaultPrefs.class, getActivity());
      builder.setPositiveButton(android.R.string.ok, null);
      builder.setNegativeButton(
          android.R.string.cancel,
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
              App.get().getBus().post(new VerifyPasswordCancelEvent());
              dismiss();
            }
          });
      builder.setCancelable(false);
      builder.setTitle(R.string.title_confirmPassword);
      View dialogView = View.inflate(getContext(), R.layout.dialog_verifypassword, null);
      final EditText masterPassword =
          ButterKnife.findById(dialogView, R.id.editText_masterPassword);
      final EditText masterPasswordConfirm =
          ButterKnife.findById(dialogView, R.id.editText_masterPasswordConfirm);
      builder.setView(dialogView);

      final AlertDialog dialog = builder.create();
      dialog.setOnShowListener(
          new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface unused) {
              Button okButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
              okButton.setOnClickListener(
                  new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                      if (masterPassword.getText() == null
                          || masterPassword.getText().toString().equals("")) {
                        masterPassword.setError(getActivity().getString(R.string.errorEmpty));
                        return;
                      } else if (masterPasswordConfirm.getText() == null
                          || masterPasswordConfirm.getText().toString().equals("")) {
                        masterPasswordConfirm.setError(
                            getActivity().getString(R.string.errorEmpty));
                        return;
                      }

                      String password = masterPassword.getText().toString();
                      String passwordConfirm = masterPasswordConfirm.getText().toString();

                      if (password.equals(passwordConfirm)) {
                        String passwordHash =
                            SCryptUtil.scrypt(
                                password, 1024, // N
                                8, // r
                                1); // p
                        defaultPrefs.masterPasswordHash(passwordHash);
                        dismiss();
                      } else {
                        masterPasswordConfirm.setError(
                            getContext().getString(R.string.errorPasswordMatch));
                      }
                    }
                  });
            }
          });

      return dialog;
    }
 private void init() {
   defaultPrefs = Esperandro.getPreferences(DefaultPrefs.class, getContext());
   setOnPreferenceChangeListener(this);
   App.get().getBus().register(this);
 }