コード例 #1
0
ファイル: MainActivity.java プロジェクト: ZwS/keyrings
  private void changePassword(int position) {
    final KeyringInfo k = MainActivity.mKeyringAdapter.getItem(position);

    View mDialogLayout = getLayoutInflater().inflate(R.layout.changing_keyring_pasword, null);
    final EditText mCurrentPassword = (EditText) mDialogLayout.findViewById(R.id.current_password);
    final EditText mNewPassword = (EditText) mDialogLayout.findViewById(R.id.new_keyring_password);
    final EditText mConfirmNewPassword =
        (EditText) mDialogLayout.findViewById(R.id.confirm_new_keyring_password);

    AlertDialog mDialog =
        new Builder(this)
            .setTitle(
                String.format(
                    getResources().getString(R.string.changing_keyring_password), k.getName()))
            .setView(mDialogLayout)
            .setPositiveButton(
                R.string.ok,
                new OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    k.setPassword(mCurrentPassword.getText().toString());
                    if (k.check()) {
                      if (mNewPassword
                          .getText()
                          .toString()
                          .equals(mConfirmNewPassword.getText().toString())) {
                        try {
                          k.getKeyringItems();
                          k.changePassword(mNewPassword.getText().toString());
                          dialog.dismiss();
                        } catch (IOException e) {
                          Toast.makeText(
                                  getApplicationContext(),
                                  R.string.dialog_title_error,
                                  Toast.LENGTH_SHORT)
                              .show();
                          e.printStackTrace();
                        }
                      } else {
                        Toast.makeText(
                                getApplicationContext(),
                                R.string.message_password_different,
                                Toast.LENGTH_SHORT)
                            .show();
                      }
                    } else {
                      Toast.makeText(
                              getApplicationContext(), R.string.wrong_password, Toast.LENGTH_SHORT)
                          .show();
                      dialog.dismiss();
                    }
                  }
                })
            .setNegativeButton(R.string.cancel, null)
            .create();

    mDialog.show();
  }
コード例 #2
0
ファイル: MainActivity.java プロジェクト: ZwS/keyrings
 private void delete(int position) {
   KeyringInfo k = MainActivity.mKeyringAdapter.getItem(position);
   k.delete();
   MainActivity.mKeyringAdapter.remove(k);
   if (mPasswordfragment != null) {
     FragmentManager fragmentManager = getFragmentManager();
     fragmentManager.beginTransaction().remove(mPasswordfragment).commit();
   }
 }
コード例 #3
0
ファイル: MainActivity.java プロジェクト: ZwS/keyrings
    @Override
    public View onCreateView(
        LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      if (savedInstanceState != null) position = savedInstanceState.getInt("position");
      else position = getArguments().getInt(KEYRING_POSITION);

      KeyringInfo keyring = MainActivity.mKeyringAdapter.getItem(position);
      keyring.getKeyringItems();
      items = new ArrayAdapter<ItemInfo>(getActivity(), R.layout.password_list_item, keyring.items);

      View rootView;
      if (!items.isEmpty()) {
        rootView = inflater.inflate(R.layout.fragment_password, container, false);
        ListView mPasswords = (ListView) rootView.findViewById(R.id.passwords);
        mPasswords.setAdapter(items);
        mPasswords.setOnItemClickListener(this);
      } else {
        rootView = inflater.inflate(R.layout.fragment_no_items, container, false);
      }
      getActivity().setTitle(MainActivity.mKeyringAdapter.getItem(position).getName());
      return rootView;
    }