示例#1
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.dialog_pwd_generator, container, false);
    Button ok = (Button) rootView.findViewById(R.id.ok);
    ok.setOnClickListener(this);
    mPasswordView = (TextView) rootView.findViewById(R.id.text_pwd);
    mPasswordView.setOnClickListener(this);
    Button button = (Button) rootView.findViewById(R.id.cancel);
    button.setOnClickListener(this);
    button = (Button) rootView.findViewById(R.id.refresh);
    button.setOnClickListener(this);
    SeekBar sb = (SeekBar) rootView.findViewById(R.id.sb_length);
    tintSeekBar(sb);
    sb.setOnSeekBarChangeListener(
        new OnSeekBarChangeListener() {

          @Override
          public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mLength = progress + 4;
            mLengthTitle.setText(getResources().getString(R.string.length, mLength));
          }

          @Override
          public void onStartTrackingTouch(SeekBar seekBar) {}

          @Override
          public void onStopTrackingTouch(SeekBar seekBar) {}
        });
    mLengthTitle = (TextView) rootView.findViewById(R.id.tv_length);
    mCheckBoxes = new CheckBox[4];
    int ids[] = {R.id.cb_uppercase, R.id.cb_lowercase, R.id.cb_digit, R.id.cb_char};
    for (int i = 0; i < mCheckBoxes.length; ++i) {
      mCheckBoxes[i] = (CheckBox) rootView.findViewById(ids[i]);
    }
    if (mType == AccountManager.EntryType.PIN) {
      mCheckBoxes[0].setChecked(false);
      mCheckBoxes[1].setChecked(false);
      mCheckBoxes[3].setChecked(false);
      mLength = 6;
      mPasswordView.setText(Application.generate(false, false, true, false, false, 6, 6));
      sb.setProgress(2);
      mLengthTitle.setText(getResources().getString(R.string.length, 6));
    } else {
      mPasswordView.setText(Application.generate(true, true, true, true, true, 10, 10));
      sb.setProgress(6);
      mLength = 10;
      mLengthTitle.setText(getResources().getString(R.string.length, 10));
    }
    return rootView;
  }
示例#2
0
  @Override
  public void onClick(View v) {
    switch (v.getId()) {
      case R.id.refresh:
      case R.id.text_pwd:
        mPasswordView.setText(
            Application.generate(
                mCheckBoxes[0].isChecked(),
                mCheckBoxes[1].isChecked(),
                mCheckBoxes[2].isChecked(),
                mCheckBoxes[3].isChecked(),
                mCheckBoxes[3].isChecked(),
                mLength,
                mLength));
        break;

      case R.id.ok:
        if (mTargetView != null) {
          mTargetView.setText(mPasswordView.getText());
        }
      case R.id.cancel:
        this.dismiss();
        break;
    }
  }