Exemplo n.º 1
0
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View v = inflater.inflate(R.layout.sync_enter_passphrase, null);

    TextView promptText = (TextView) v.findViewById(R.id.prompt_text);
    promptText.setText(getPromptText());

    TextView resetText = (TextView) v.findViewById(R.id.reset_text);
    resetText.setText(getResetText());
    resetText.setMovementMethod(LinkMovementMethod.getInstance());
    resetText.setVisibility(View.VISIBLE);

    EditText passphrase = (EditText) v.findViewById(R.id.passphrase);
    passphrase.setHint(R.string.sync_enter_custom_passphrase_hint);
    passphrase.setOnEditorActionListener(
        new OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_NEXT) {
              handleOk();
            }
            return false;
          }
        });

    final AlertDialog d =
        new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme)
            .setView(v)
            .setPositiveButton(
                R.string.ok,
                new Dialog.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface d, int which) {
                    // We override the onclick. This is a hack to not dismiss the dialog after
                    // click of OK and instead dismiss it after confirming the passphrase
                    // is correct.
                  }
                })
            .setNegativeButton(R.string.cancel, this)
            .setTitle(R.string.sign_in_google_account)
            .create();
    d.getDelegate().setHandleNativeActionModesEnabled(false);
    d.setOnShowListener(
        new DialogInterface.OnShowListener() {
          @Override
          public void onShow(DialogInterface dialog) {
            Button b = d.getButton(AlertDialog.BUTTON_POSITIVE);
            b.setOnClickListener(
                new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                    handleOk();
                  }
                });
          }
        });
    return d;
  }
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
      AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
      LayoutInflater inflater = getActivity().getLayoutInflater();
      final View v = inflater.inflate(R.layout.fragment_show_ssh_key, null);
      builder.setView(v);

      TextView textView = (TextView) v.findViewById(R.id.public_key);
      File file = new File(getActivity().getFilesDir() + "/.ssh_key.pub");
      try {
        textView.setText(FileUtils.readFileToString(file));
      } catch (Exception e) {
        System.out.println("Exception caught :(");
        e.printStackTrace();
      }

      builder.setPositiveButton(
          getResources().getString(R.string.dialog_ok),
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
              if (getActivity() instanceof SshKeyGen) getActivity().finish();
            }
          });

      builder.setNegativeButton(
          getResources().getString(R.string.dialog_cancel),
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {}
          });

      builder.setNeutralButton(getResources().getString(R.string.ssh_keygen_copy), null);

      final AlertDialog ad = builder.setTitle("Your public key").create();
      ad.setOnShowListener(
          new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
              Button b = ad.getButton(AlertDialog.BUTTON_NEUTRAL);
              b.setOnClickListener(
                  new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                      TextView textView = (TextView) getDialog().findViewById(R.id.public_key);
                      ClipboardManager clipboard =
                          (ClipboardManager)
                              getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                      ClipData clip =
                          ClipData.newPlainText("public key", textView.getText().toString());
                      clipboard.setPrimaryClip(clip);
                    }
                  });
            }
          });
      return ad;
    }
    @NonNull
    @Override
    public Dialog onCreateDialog(final Bundle savedInstanceState) {
      final FragmentActivity activity = getActivity();
      final Context wrapped = ThemeUtils.getDialogThemedContext(activity);
      final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped);
      buildDialog(builder);
      builder.setView(R.layout.dialog_auto_complete_textview);

      builder.setTitle(R.string.add_rule);
      builder.setPositiveButton(android.R.string.ok, this);
      builder.setNegativeButton(android.R.string.cancel, this);
      final AlertDialog dialog = builder.create();
      dialog.setOnShowListener(
          new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
              AlertDialog alertDialog = (AlertDialog) dialog;
              final AutoCompleteTextView editText =
                  (AutoCompleteTextView) alertDialog.findViewById(R.id.edit_text);
              final Bundle args = getArguments();
              final int autoCompleteType;
              autoCompleteType = args.getInt(EXTRA_AUTO_COMPLETE_TYPE, 0);
              if (autoCompleteType != 0) {
                SimpleCursorAdapter mUserAutoCompleteAdapter;
                if (autoCompleteType == AUTO_COMPLETE_TYPE_SOURCES) {
                  mUserAutoCompleteAdapter = new SourceAutoCompleteAdapter(activity);
                } else {
                  final ComposeAutoCompleteAdapter adapter =
                      new ComposeAutoCompleteAdapter(activity);
                  adapter.setAccountId(Utils.getDefaultAccountId(activity));
                  mUserAutoCompleteAdapter = adapter;
                }
                editText.setAdapter(mUserAutoCompleteAdapter);
                editText.setThreshold(1);
              }
            }
          });
      return dialog;
    }
  @NonNull
  @Override
  public AlertDialog create() {
    AlertDialog dialog = super.create();

    input = new EditText(context);
    input.setText(inputText);

    dialog.setView(input);

    dialog.setOnShowListener(
        new DialogInterface.OnShowListener() {

          @Override
          public void onShow(DialogInterface dialog) {
            InputMethodManager imm =
                (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT);
            input.setSelection(input.getText().length());
          }
        });

    return dialog;
  }
Exemplo n.º 5
0
  public void show(KrollDict options) {
    AlertDialog dialog = (AlertDialog) dialogWrapper.getDialog();
    if (dialog == null) {
      if (dialogWrapper.getActivity() == null) {
        TiBaseActivity dialogActivity = (TiBaseActivity) getCurrentActivity();
        dialogWrapper.setActivity(new WeakReference<TiBaseActivity>(dialogActivity));
      }
      //			processProperties(proxy.getProperties());
      getBuilder()
          .setOnCancelListener(
              new OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dlg) {
                  int cancelIndex =
                      (proxy.hasProperty(TiC.PROPERTY_CANCEL))
                          ? TiConvert.toInt(proxy.getProperty(TiC.PROPERTY_CANCEL))
                          : -1;
                  Log.d(
                      TAG,
                      "onCancelListener called. Sending index: "
                          + cancelIndex
                          + ", hideOnClick: "
                          + hideOnClick,
                      Log.DEBUG_MODE);
                  handleEvent(cancelIndex, false);
                  if (hideOnClick == true) hide(null);
                }
              });
      dialog = getBuilder().create();
      dialog.setOnShowListener(
          new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
              TiApplication.getInstance().cancelPauseEvent();
            }
          });
      dialog.setCancelable(hideOnClick);
      dialog.setCanceledOnTouchOutside(tapToDismiss);

      dialog.setOnKeyListener(
          new Dialog.OnKeyListener() {

            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
              if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
                if (proxy.hasListeners(TiC.EVENT_ANDROID_BACK)) {
                  proxy.fireEvent(TiC.EVENT_ANDROID_BACK);
                } else if (hideOnClick) {
                  handleEvent(cancelIndex, false);
                  hide(null);
                }
              }
              return true;
            }
          });

      // Initially apply accessibility properties here, the first time
      // the dialog actually becomes available. After this, propertyChanged
      // can also be used.
      ListView listView = dialog.getListView();
      if (listView != null) {
        listView.setContentDescription(composeContentDescription());
        int importance = ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
        if (proxy != null) {
          Object propertyValue = proxy.getProperty(TiC.PROPERTY_ACCESSIBILITY_HIDDEN);
          if (propertyValue != null && TiConvert.toBoolean(propertyValue)) {
            importance = ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO;
          }
        }
        ViewCompat.setImportantForAccessibility(listView, importance);
      }

      dialogWrapper.setDialog(dialog);
      builder = null;
    }

    try {
      Activity dialogActivity = dialogWrapper.getActivity();
      if (dialogActivity != null && !dialogActivity.isFinishing()) {
        if (dialogActivity instanceof TiBaseActivity) {
          // add dialog to its activity so we can clean it up later to prevent memory leak.
          ((TiBaseActivity) dialogActivity).addDialog(dialogWrapper);
          dialog.show();
          setButtonsListeners(dialog);
          fireEvent(TiC.EVENT_OPEN, null, false);
        }
      } else {
        dialog = null;
        Log.w(
            TAG,
            "Dialog activity is destroyed, unable to show dialog with message: "
                + TiConvert.toString(proxy.getProperty(TiC.PROPERTY_MESSAGE)));
      }
    } catch (Throwable t) {
      Log.w(TAG, "Context must have gone away: " + t.getMessage(), t);
    }
  }
    @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;
    }
  // Creates a New Character Dialog from the context and comparison for copy functionality
  private void NewCharacterDialog(final Context context, final String characterName) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    LayoutInflater layoutInflater = LayoutInflater.from(context);
    View dialogView = layoutInflater.inflate(R.layout.dialog_new_character, null);
    final TextInputLayout textInputLayout =
        (TextInputLayout) dialogView.findViewById(R.id.dialog_new_character_text_input_layer);
    textInputLayout.setErrorEnabled(true);
    builder
        .setTitle("New Character")
        .setView(dialogView)
        .setCancelable(true)
        .setPositiveButton(
            R.string.dialog_ok,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                // do nothing
              }
            })
        .setNegativeButton(
            R.string.dialog_cancel,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                // do nothing
              }
            });
    // create the dialog
    final AlertDialog alertDialog = builder.create();
    // OnShow listener for valid inputs, as well as manually setting the listeners
    alertDialog.setOnShowListener(
        new DialogInterface.OnShowListener() {
          @Override
          public void onShow(final DialogInterface dialog) {
            // set positive button listener
            Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            button.setOnClickListener(
                new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                    CharacterObject characterObject;
                    // in here we check for valid text

                    String newCharacterName = null;

                    if (textInputLayout.getEditText() != null) {
                      newCharacterName = textInputLayout.getEditText().getText().toString();
                    }

                    if (characterList.contains(newCharacterName)) {
                      textInputLayout.setError(
                          getResources().getString(R.string.dialog_error_name_already_found));
                    } else {
                      // if valid name, we copy over the object
                      if (characterName != null) {
                        copy(
                            getApplicationContext(),
                            new File(fileRootDir, characterName + ".chr"),
                            newCharacterName);
                        characterObject =
                            CharacterObject.loadFromFile(getApplicationContext(), newCharacterName);
                      } else {
                        characterObject = new CharacterObject();
                        characterObject.setName(newCharacterName);
                        characterObject.saveToFile(getApplicationContext());
                      }
                      characterList.add(newCharacterName);

                      // create the intent to pass activity
                      Intent intent = new Intent(context, NewCharacterActivity.class);
                      intent.putExtra("character", characterObject);
                      GenerateCharacterButtons();
                      dialog.dismiss();
                      startActivity(intent);
                    }
                  }
                });
          }
        });
    // show the dialog
    alertDialog.show();
  }