public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    mPhone = PhoneGlobals.getPhone();

    resolveIntent();

    setContentView(R.layout.change_sim_pin_screen);

    mOldPin = (EditText) findViewById(R.id.old_pin);
    mOldPin.setKeyListener(DigitsKeyListener.getInstance());
    mOldPin.setMovementMethod(null);
    mOldPin.setOnClickListener(mClicked);

    mNewPin1 = (EditText) findViewById(R.id.new_pin1);
    mNewPin1.setKeyListener(DigitsKeyListener.getInstance());
    mNewPin1.setMovementMethod(null);
    mNewPin1.setOnClickListener(mClicked);

    mNewPin2 = (EditText) findViewById(R.id.new_pin2);
    mNewPin2.setKeyListener(DigitsKeyListener.getInstance());
    mNewPin2.setMovementMethod(null);
    mNewPin2.setOnClickListener(mClicked);

    mBadPinError = (TextView) findViewById(R.id.bad_pin);
    mMismatchError = (TextView) findViewById(R.id.mismatch);

    mButton = (Button) findViewById(R.id.button);
    mButton.setOnClickListener(mClicked);

    mScrollView = (ScrollView) findViewById(R.id.scroll);

    mPUKCode = (EditText) findViewById(R.id.puk_code);
    mPUKCode.setKeyListener(DigitsKeyListener.getInstance());
    mPUKCode.setMovementMethod(null);
    mPUKCode.setOnClickListener(mClicked);

    mPUKSubmit = (Button) findViewById(R.id.puk_submit);
    mPUKSubmit.setOnClickListener(mClicked);

    mIccPUKPanel = (LinearLayout) findViewById(R.id.puk_panel);

    int id = mChangePin2 ? R.string.change_pin2 : R.string.change_pin;
    setTitle(getResources().getText(id));

    mState = EntryState.ES_PIN;
  }
Exemplo n.º 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.task_preferences);

    // Set the time default to a numeric number only
    EditTextPreference timeDefault =
        (EditTextPreference) findPreference(getString(R.string.pref_default_time_from_now_key));
    timeDefault.getEditText().setKeyListener(DigitsKeyListener.getInstance());
  }
  @Override
  protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    setContentView(R.layout.get_pin2_screen);

    mPin2Field = (EditText) findViewById(R.id.pin);
    mPin2Field.setKeyListener(DigitsKeyListener.getInstance());
    mPin2Field.setMovementMethod(null);
    mPin2Field.setOnEditorActionListener(this);

    mOkButton = (Button) findViewById(R.id.ok);
    mOkButton.setOnClickListener(mClicked);
  }
Exemplo n.º 4
0
  @Override
  public void setInputType(int type) {
    if (type == -1) {
      type = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_PASSWORD;
    }

    if (type == InputType.TYPE_CLASS_NUMBER
        || type == InputType.TYPE_NUMBER_FLAG_SIGNED
        || type == InputType.TYPE_NUMBER_FLAG_DECIMAL
        || type == InputType.TYPE_CLASS_PHONE) {
      final String symbolExceptions = getSymbolExceptions();
      this.setKeyListener(DigitsKeyListener.getInstance("0123456789." + symbolExceptions));
    } else {
      super.setInputType(type);
    }
  }
Exemplo n.º 5
0
 public void handleKeyboardType(int type, boolean autocorrect) {
   // Switched the keyboard handler to use the inputType rather than the rawInputType
   // This is kinda brute-force but more effective for most use-cases
   switch (type) {
     case KEYBOARD_ASCII:
       tv.setKeyListener(TextKeyListener.getInstance(autocorrect, Capitalize.NONE));
       tv.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL);
       // tv.setRawInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL);
       break;
     case KEYBOARD_NUMBERS_PUNCTUATION:
       tv.setInputType(InputType.TYPE_CLASS_NUMBER);
       // tv.setKeyListener(DigitsKeyListener.getInstance());
       break;
     case KEYBOARD_URL:
       Log.i(LCAT, "Setting keyboard type URL-3");
       // tv.setKeyListener(TextKeyListener.getInstance(autocorrect, Capitalize.NONE));
       tv.setImeOptions(EditorInfo.IME_ACTION_GO);
       // tv.setRawInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
       tv.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
       break;
     case KEYBOARD_NUMBER_PAD:
       tv.setKeyListener(DigitsKeyListener.getInstance(true, true));
       // tv.setRawInputType(InputType.TYPE_CLASS_NUMBER);
       tv.setInputType(InputType.TYPE_CLASS_NUMBER);
       break;
     case KEYBOARD_PHONE_PAD:
       tv.setKeyListener(DialerKeyListener.getInstance());
       // tv.setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_CLASS_PHONE);
       tv.setInputType(InputType.TYPE_CLASS_PHONE);
       break;
     case KEYBOARD_EMAIL_ADDRESS:
       // tv.setKeyListener(TextKeyListener.getInstance(autocorrect, Capitalize.NONE));
       tv.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
       break;
     case KEYBOARD_DEFAULT:
       tv.setKeyListener(TextKeyListener.getInstance(autocorrect, Capitalize.NONE));
       // tv.setRawInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL);
       tv.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL);
       break;
     case KEYBOARD_PASSWORD:
       tv.setKeyListener(TextKeyListener.getInstance(false, Capitalize.NONE));
       // tv.setRawInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
       tv.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
       break;
   }
 }
  public PasswordUnlockScreen(
      Context context,
      Configuration configuration,
      LockPatternUtils lockPatternUtils,
      KeyguardUpdateMonitor updateMonitor,
      KeyguardScreenCallback callback) {
    super(context);

    mCreationHardKeyboardHidden = configuration.hardKeyboardHidden;
    mCreationOrientation = configuration.orientation;
    mUpdateMonitor = updateMonitor;
    mCallback = callback;
    mLockPatternUtils = lockPatternUtils;

    LayoutInflater layoutInflater = LayoutInflater.from(context);
    if (mCreationOrientation != Configuration.ORIENTATION_LANDSCAPE) {
      layoutInflater.inflate(R.layout.keyguard_screen_password_portrait, this, true);
    } else {
      layoutInflater.inflate(R.layout.keyguard_screen_password_landscape, this, true);
    }
    LockScreen.setBackground(context, (ViewGroup) findViewById(R.id.root));
    mStatusViewManager =
        new KeyguardStatusViewManager(this, mUpdateMonitor, mLockPatternUtils, mCallback, true);

    final int quality = lockPatternUtils.getKeyguardStoredPasswordQuality();
    mIsAlpha =
        DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC == quality
            || DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC == quality
            || DevicePolicyManager.PASSWORD_QUALITY_COMPLEX == quality;

    mKeyboardView = (PasswordEntryKeyboardView) findViewById(R.id.keyboard);
    mPasswordEntry = (EditText) findViewById(R.id.passwordEntry);
    mPasswordEntry.setOnEditorActionListener(this);

    mKeyboardHelper = new PasswordEntryKeyboardHelper(context, mKeyboardView, this, false);
    mKeyboardHelper.setEnableHaptics(mLockPatternUtils.isTactileFeedbackEnabled());
    boolean imeOrDeleteButtonVisible = false;
    if (mIsAlpha) {
      // We always use the system IME for alpha keyboard, so hide lockscreen's soft keyboard
      mKeyboardHelper.setKeyboardMode(PasswordEntryKeyboardHelper.KEYBOARD_MODE_ALPHA);
      mKeyboardView.setVisibility(View.GONE);
    } else {
      // Use lockscreen's numeric keyboard if the physical keyboard isn't showing
      mKeyboardHelper.setKeyboardMode(PasswordEntryKeyboardHelper.KEYBOARD_MODE_NUMERIC);
      mKeyboardView.setVisibility(
          mCreationHardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO
              ? View.INVISIBLE
              : View.VISIBLE);

      // The delete button is of the PIN keyboard itself in some (e.g. tablet) layouts,
      // not a separate view
      View pinDelete = findViewById(R.id.pinDel);
      if (pinDelete != null) {
        pinDelete.setVisibility(View.VISIBLE);
        imeOrDeleteButtonVisible = true;
        pinDelete.setOnClickListener(
            new OnClickListener() {
              @Override
              public void onClick(View v) {
                mKeyboardHelper.handleBackspace();
              }
            });
      }
    }

    mPasswordEntry.requestFocus();

    // This allows keyboards with overlapping qwerty/numeric keys to choose just numeric keys.
    if (mIsAlpha) {
      mPasswordEntry.setKeyListener(TextKeyListener.getInstance());
      mPasswordEntry.setInputType(
          InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
      // mStatusViewManager.setHelpMessage(R.string.keyguard_password_enter_password_code,
      // KeyguardStatusViewManager.LOCK_ICON);
    } else {
      mPasswordEntry.setKeyListener(DigitsKeyListener.getInstance());
      mPasswordEntry.setInputType(
          InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
      // mStatusViewManager.setHelpMessage(R.string.keyguard_password_enter_pin_code,
      // KeyguardStatusViewManager.LOCK_ICON);
    }

    // Poke the wakelock any time the text is selected or modified
    mPasswordEntry.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            mCallback.pokeWakelock();
          }
        });

    mQuickUnlock =
        (Settings.System.getInt(
                mContext.getContentResolver(), Settings.System.LOCKSCREEN_QUICK_UNLOCK_CONTROL, 0)
            == 1);

    mPasswordEntry.addTextChangedListener(
        new TextWatcher() {
          public void onTextChanged(CharSequence s, int start, int before, int count) {}

          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          public void afterTextChanged(Editable s) {
            if (!mResuming) {
              mCallback.pokeWakelock();
            }
            if (mQuickUnlock) {
              String entry = mPasswordEntry.getText().toString();
              if (entry.length() > MINIMUM_PASSWORD_LENGTH_BEFORE_REPORT
                  && mLockPatternUtils.checkPassword(entry)) {
                mCallback.keyguardDone(true);
                mCallback.reportSuccessfulUnlockAttempt();
                KeyStore.getInstance().password(entry);
              }
            }
          }
        });

    // If there's more than one IME, enable the IME switcher button
    View switchImeButton = findViewById(R.id.switch_ime_button);
    final InputMethodManager imm =
        (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    if (mIsAlpha && switchImeButton != null && hasMultipleEnabledIMEsOrSubtypes(imm, false)) {
      switchImeButton.setVisibility(View.VISIBLE);
      imeOrDeleteButtonVisible = true;
      switchImeButton.setOnClickListener(
          new OnClickListener() {
            public void onClick(View v) {
              mCallback.pokeWakelock(); // Leave the screen on a bit longer
              imm.showInputMethodPicker();
            }
          });
    }

    // If no icon is visible, reset the left margin on the password field so the text is
    // still centered.
    if (!imeOrDeleteButtonVisible) {
      android.view.ViewGroup.LayoutParams params = mPasswordEntry.getLayoutParams();
      if (params instanceof MarginLayoutParams) {
        ((MarginLayoutParams) params).leftMargin = 0;
        mPasswordEntry.setLayoutParams(params);
      }
    }
  }
Exemplo n.º 7
0
    @Override
    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
      final Intent it = getIntent();

      String prefKey = preference.getKey();

      if ("level_filter".equals(prefKey)) // $NON-NLS-1$
      {
        OnClickListener listener =
            new OnClickListener() {

              public void onClick(DialogInterface dialog, int which) {
                if (dmesgMode) {
                  it.putExtra(PREF_KEY_DLOG_LEVL, which);
                } else {
                  it.putExtra(PREF_KEY_CLOG_LEVL, which + 2);
                }

                dialog.dismiss();

                refreshLevelFilter();
              }
            };

        if (dmesgMode) {
          new AlertDialog.Builder(this)
              .setTitle(R.string.log_level)
              .setNeutralButton(R.string.close, null)
              .setSingleChoiceItems(
                  new CharSequence[] {
                    Html.fromHtml(
                        "<font color=\"#ff00ff\">● </font>" //$NON-NLS-1$
                            + getString(R.string.emmergency)),
                    Html.fromHtml(
                        "<font color=\"#F183BD\">● </font>" //$NON-NLS-1$
                            + getString(R.string.alert)),
                    Html.fromHtml(
                        "<font color=\"#8737CE\">● </font>" //$NON-NLS-1$
                            + getString(R.string.critical)),
                    Html.fromHtml(
                        "<font color=\"#ff0000\">● </font>" //$NON-NLS-1$
                            + getString(R.string.error)),
                    Html.fromHtml(
                        "<font color=\"#ffff00\">● </font>" //$NON-NLS-1$
                            + getString(R.string.warning)),
                    Html.fromHtml(
                        "<font color=\"#00ffff\">● </font>" //$NON-NLS-1$
                            + getString(R.string.notice)),
                    Html.fromHtml(
                        "<font color=\"#00ff00\">● </font>" //$NON-NLS-1$
                            + getString(R.string.info)),
                    Html.fromHtml(
                        "<font color=\"#888888\">● </font>" //$NON-NLS-1$
                            + getString(R.string.debug)),
                  },
                  it.getIntExtra(PREF_KEY_DLOG_LEVL, DM_LVL_DEBUG),
                  listener)
              .create()
              .show();
        } else {
          new AlertDialog.Builder(this)
              .setTitle(R.string.log_level)
              .setNeutralButton(R.string.close, null)
              .setSingleChoiceItems(
                  new CharSequence[] {
                    Html.fromHtml(
                        "<font color=\"#888888\">● </font>" //$NON-NLS-1$
                            + getString(R.string.verbose)),
                    Html.fromHtml(
                        "<font color=\"#00ffff\">● </font>" //$NON-NLS-1$
                            + getString(R.string.debug)),
                    Html.fromHtml(
                        "<font color=\"#00ff00\">● </font>" //$NON-NLS-1$
                            + getString(R.string.info)),
                    Html.fromHtml(
                        "<font color=\"#ffff00\">● </font>" //$NON-NLS-1$
                            + getString(R.string.warning)),
                    Html.fromHtml(
                        "<font color=\"#ff0000\">● </font>" //$NON-NLS-1$
                            + getString(R.string.error)),
                    Html.fromHtml(
                        "<font color=\"#ff00ff\">● </font>" //$NON-NLS-1$
                            + getString(R.string.asser_t)),
                  },
                  it.getIntExtra(PREF_KEY_CLOG_LEVL, Log.VERBOSE) - 2,
                  listener)
              .create()
              .show();
        }

        return true;
      } else if (PREF_KEY_RING_BUFFER.equals(prefKey)) {
        OnClickListener listener =
            new OnClickListener() {

              public void onClick(DialogInterface dialog, int which) {
                it.putExtra(PREF_KEY_RING_BUFFER, which);

                dialog.dismiss();

                refreshRingBuffer();
              }
            };

        new AlertDialog.Builder(this)
            .setTitle(R.string.ring_buffer)
            .setNeutralButton(R.string.close, null)
            .setSingleChoiceItems(
                new CharSequence[] {
                  getString(R.string.main), getString(R.string.radio), getString(R.string.events),
                },
                it.getIntExtra(PREF_KEY_RING_BUFFER, RING_BUFFER_MAIN),
                listener)
            .create()
            .show();

        return true;
      } else if (PREF_KEY_TAG_FILTER.equals(prefKey)) {
        final EditText txt = new EditText(this);
        txt.setText(it.getStringExtra(PREF_KEY_TAG_FILTER));

        OnClickListener listener =
            new OnClickListener() {

              public void onClick(DialogInterface dialog, int which) {
                String filter = txt.getText().toString();

                if (filter != null) {
                  filter = filter.trim();

                  if (filter.length() == 0) {
                    filter = null;
                  }
                }

                it.putExtra(PREF_KEY_TAG_FILTER, filter);

                dialog.dismiss();

                refreshTagFilter();
              }
            };

        new AlertDialog.Builder(this)
            .setTitle(R.string.tag_filter)
            .setPositiveButton(android.R.string.ok, listener)
            .setNegativeButton(android.R.string.cancel, null)
            .setView(txt)
            .create()
            .show();

        return true;
      } else if (PREF_KEY_PID_FILTER.equals(prefKey)) {
        final EditText txt = new EditText(this);
        txt.setFilters(new InputFilter[] {DigitsKeyListener.getInstance(false, false)});

        int pid = it.getIntExtra(PREF_KEY_PID_FILTER, 0);
        if (pid != 0) {
          txt.setText(String.valueOf(pid));
        }

        OnClickListener listener =
            new OnClickListener() {

              public void onClick(DialogInterface dialog, int which) {
                String filter = txt.getText().toString();

                if (filter != null) {
                  filter = filter.trim();

                  if (filter.length() == 0) {
                    filter = null;
                  }
                }

                int pid = 0;

                if (filter != null) {
                  try {
                    pid = Integer.parseInt(filter);
                  } catch (Exception e) {
                    Log.e(LogSettings.class.getName(), e.getLocalizedMessage(), e);
                  }
                }

                it.putExtra(PREF_KEY_PID_FILTER, pid);

                dialog.dismiss();

                refreshPidFilter();
              }
            };

        new AlertDialog.Builder(this)
            .setTitle(R.string.pid_filter)
            .setPositiveButton(android.R.string.ok, listener)
            .setNegativeButton(android.R.string.cancel, null)
            .setView(txt)
            .create()
            .show();

        return true;
      }
      return false;
    }
Exemplo n.º 8
0
  public void handleKeyboard(KrollDict d) {
    int type = KEYBOARD_ASCII;
    boolean passwordMask = false;
    boolean editable = true;
    int autocorrect = InputType.TYPE_TEXT_FLAG_AUTO_CORRECT;
    int autoCapValue = 0;

    if (d.containsKey(TiC.PROPERTY_AUTOCORRECT)
        && !TiConvert.toBoolean(d, TiC.PROPERTY_AUTOCORRECT, true)) {
      autocorrect = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
    }

    if (d.containsKey(TiC.PROPERTY_EDITABLE)) {
      editable = TiConvert.toBoolean(d, TiC.PROPERTY_EDITABLE, true);
    }

    if (d.containsKey(TiC.PROPERTY_AUTOCAPITALIZATION)) {

      switch (TiConvert.toInt(
          d.get(TiC.PROPERTY_AUTOCAPITALIZATION), TEXT_AUTOCAPITALIZATION_NONE)) {
        case TEXT_AUTOCAPITALIZATION_NONE:
          autoCapValue = 0;
          break;
        case TEXT_AUTOCAPITALIZATION_ALL:
          autoCapValue =
              InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS
                  | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
                  | InputType.TYPE_TEXT_FLAG_CAP_WORDS;
          break;
        case TEXT_AUTOCAPITALIZATION_SENTENCES:
          autoCapValue = InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
          break;

        case TEXT_AUTOCAPITALIZATION_WORDS:
          autoCapValue = InputType.TYPE_TEXT_FLAG_CAP_WORDS;
          break;
        default:
          Log.w(
              TAG,
              "Unknown AutoCapitalization Value ["
                  + d.getString(TiC.PROPERTY_AUTOCAPITALIZATION)
                  + "]");
          break;
      }
    }

    if (d.containsKey(TiC.PROPERTY_PASSWORD_MASK)) {
      passwordMask = TiConvert.toBoolean(d, TiC.PROPERTY_PASSWORD_MASK, false);
    }

    if (d.containsKey(TiC.PROPERTY_KEYBOARD_TYPE)) {
      type = TiConvert.toInt(d.get(TiC.PROPERTY_KEYBOARD_TYPE), KEYBOARD_DEFAULT);
    }

    int typeModifiers = autocorrect | autoCapValue;
    int textTypeAndClass = typeModifiers;
    // For some reason you can't set both TYPE_CLASS_TEXT and TYPE_TEXT_FLAG_NO_SUGGESTIONS
    // together.
    // Also, we need TYPE_CLASS_TEXT for passwords.
    if ((autocorrect != InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS || passwordMask)
        && type != KEYBOARD_DECIMAL_PAD) {
      textTypeAndClass = textTypeAndClass | InputType.TYPE_CLASS_TEXT;
    }

    tv.setCursorVisible(true);
    switch (type) {
      case KEYBOARD_DEFAULT:
      case KEYBOARD_ASCII:
        // Don't need a key listener, inputType handles that.
        break;
      case KEYBOARD_NUMBERS_PUNCTUATION:
        textTypeAndClass |= (InputType.TYPE_CLASS_NUMBER | InputType.TYPE_CLASS_TEXT);
        tv.setKeyListener(
            new NumberKeyListener() {
              @Override
              public int getInputType() {
                return InputType.TYPE_CLASS_NUMBER | InputType.TYPE_CLASS_TEXT;
              }

              @Override
              protected char[] getAcceptedChars() {
                return new char[] {
                  '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '-', '+', '_', '*', '-',
                  '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '=', '{', '}', '[', ']', '|',
                  '\\', '<', '>', ',', '?', '/', ':', ';', '\'', '"', '~'
                };
              }
            });
        break;
      case KEYBOARD_URL:
        Log.d(TAG, "Setting keyboard type URL-3", Log.DEBUG_MODE);
        tv.setImeOptions(EditorInfo.IME_ACTION_GO);
        textTypeAndClass |= InputType.TYPE_TEXT_VARIATION_URI;
        break;
      case KEYBOARD_DECIMAL_PAD:
        textTypeAndClass |=
            (InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED);
      case KEYBOARD_NUMBER_PAD:
        tv.setKeyListener(DigitsKeyListener.getInstance(true, true));
        textTypeAndClass |= InputType.TYPE_CLASS_NUMBER;
        break;
      case KEYBOARD_PHONE_PAD:
        tv.setKeyListener(DialerKeyListener.getInstance());
        textTypeAndClass |= InputType.TYPE_CLASS_PHONE;
        break;
      case KEYBOARD_EMAIL_ADDRESS:
        textTypeAndClass |= InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
        break;
    }

    if (passwordMask) {
      textTypeAndClass |= InputType.TYPE_TEXT_VARIATION_PASSWORD;
      // Sometimes password transformation does not work properly when the input type is set after
      // the transformation method.
      // This issue has been filed at http://code.google.com/p/android/issues/detail?id=7092
      tv.setInputType(textTypeAndClass);
      tv.setTransformationMethod(PasswordTransformationMethod.getInstance());

      // turn off text UI in landscape mode b/c Android numeric passwords are not masked correctly
      // in landscape mode.
      if (type == KEYBOARD_NUMBERS_PUNCTUATION
          || type == KEYBOARD_DECIMAL_PAD
          || type == KEYBOARD_NUMBER_PAD) {
        tv.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
      }

    } else {
      tv.setInputType(textTypeAndClass);
      if (tv.getTransformationMethod() instanceof PasswordTransformationMethod) {
        tv.setTransformationMethod(null);
      }
    }
    if (!editable) {
      tv.setKeyListener(null);
      tv.setCursorVisible(false);
    }

    // setSingleLine() append the flag TYPE_TEXT_FLAG_MULTI_LINE to the current inputType, so we
    // want to call this
    // after we set inputType.
    if (!field) {
      tv.setSingleLine(false);
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.account_setup_incoming);

    mUsernameView = (EditText) findViewById(R.id.account_username);
    mPasswordView = (EditText) findViewById(R.id.account_password);
    mClientCertificateSpinner =
        (ClientCertificateSpinner) findViewById(R.id.account_client_certificate_spinner);
    mClientCertificateLabelView = (TextView) findViewById(R.id.account_client_certificate_label);
    mPasswordLabelView = (TextView) findViewById(R.id.account_password_label);
    TextView serverLabelView = (TextView) findViewById(R.id.account_server_label);
    mServerView = (EditText) findViewById(R.id.account_server);
    mPortView = (EditText) findViewById(R.id.account_port);
    mSecurityTypeView = (Spinner) findViewById(R.id.account_security_type);
    mAuthTypeView = (Spinner) findViewById(R.id.account_auth_type);
    mImapAutoDetectNamespaceView = (CheckBox) findViewById(R.id.imap_autodetect_namespace);
    mImapPathPrefixView = (EditText) findViewById(R.id.imap_path_prefix);
    mWebdavPathPrefixView = (EditText) findViewById(R.id.webdav_path_prefix);
    mWebdavAuthPathView = (EditText) findViewById(R.id.webdav_auth_path);
    mWebdavMailboxPathView = (EditText) findViewById(R.id.webdav_mailbox_path);
    mNextButton = (Button) findViewById(R.id.next);
    mCompressionMobile = (CheckBox) findViewById(R.id.compression_mobile);
    mCompressionWifi = (CheckBox) findViewById(R.id.compression_wifi);
    mCompressionOther = (CheckBox) findViewById(R.id.compression_other);
    // mSubscribedFoldersOnly = (CheckBox)findViewById(R.id.subscribed_folders_only);
    mRequiresCellular = (CheckBox) findViewById(R.id.account_requires_cellular);
    mAccountName = (EditText) findViewById(R.id.account_name);

    mNextButton.setOnClickListener(this);

    mImapAutoDetectNamespaceView.setOnCheckedChangeListener(
        new OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mImapPathPrefixView.setEnabled(!isChecked);
            if (isChecked && mImapPathPrefixView.hasFocus()) {
              mImapPathPrefixView.focusSearch(View.FOCUS_UP).requestFocus();
            } else if (!isChecked) {
              mImapPathPrefixView.requestFocus();
            }
          }
        });

    mAuthTypeAdapter = AuthTypeAdapter.get(this);
    mAuthTypeView.setAdapter(mAuthTypeAdapter);

    /*
     * Only allow digits in the port field.
     */
    mPortView.setKeyListener(DigitsKeyListener.getInstance("0123456789"));

    String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
    mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
    // mMakeDefault = getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false);

    /*
     * If we're being reloaded we override the original account with the one
     * we saved
     */
    if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT)) {
      accountUuid = savedInstanceState.getString(EXTRA_ACCOUNT);
      mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
    }

    boolean editSettings = Intent.ACTION_EDIT.equals(getIntent().getAction());

    try {
      ServerSettings settings = RemoteStore.decodeStoreUri(mAccount.getStoreUri());

      if (savedInstanceState == null) {
        // The first item is selected if settings.authenticationType is null or is not in
        // mAuthTypeAdapter
        mCurrentAuthTypeViewPosition =
            mAuthTypeAdapter.getAuthPosition(settings.authenticationType);
      } else {
        mCurrentAuthTypeViewPosition = savedInstanceState.getInt(STATE_AUTH_TYPE_POSITION);
      }
      mAuthTypeView.setSelection(mCurrentAuthTypeViewPosition, false);
      updateViewFromAuthType();

      if (settings.username != null) {
        mUsernameView.setText(settings.username);
      }

      if (settings.password != null) {
        mPasswordView.setText(settings.password);
      }

      if (settings.clientCertificateAlias != null) {
        mClientCertificateSpinner.setAlias(settings.clientCertificateAlias);
      }

      mStoreType = settings.type;
      if (Type.POP3 == settings.type) {
        serverLabelView.setText(R.string.account_setup_incoming_pop_server_label);
        findViewById(R.id.imap_path_prefix_section).setVisibility(View.GONE);
        findViewById(R.id.webdav_advanced_header).setVisibility(View.GONE);
        findViewById(R.id.webdav_mailbox_alias_section).setVisibility(View.GONE);
        findViewById(R.id.webdav_owa_path_section).setVisibility(View.GONE);
        findViewById(R.id.webdav_auth_path_section).setVisibility(View.GONE);
        findViewById(R.id.compression_section).setVisibility(View.GONE);
        findViewById(R.id.compression_label).setVisibility(View.GONE);
        // mSubscribedFoldersOnly.setVisibility(View.GONE);
      } else if (Type.IMAP == settings.type) {
        serverLabelView.setText(R.string.account_setup_incoming_imap_server_label);

        ImapStoreSettings imapSettings = (ImapStoreSettings) settings;

        mImapAutoDetectNamespaceView.setChecked(imapSettings.autoDetectNamespace);
        if (imapSettings.pathPrefix != null) {
          mImapPathPrefixView.setText(imapSettings.pathPrefix);
        }

        findViewById(R.id.webdav_advanced_header).setVisibility(View.GONE);
        findViewById(R.id.webdav_mailbox_alias_section).setVisibility(View.GONE);
        findViewById(R.id.webdav_owa_path_section).setVisibility(View.GONE);
        findViewById(R.id.webdav_auth_path_section).setVisibility(View.GONE);

        /*if (!editSettings) {
            findViewById(R.id.imap_folder_setup_section).setVisibility(View.GONE);
        }*/
      } else if (Type.WebDAV == settings.type) {
        serverLabelView.setText(R.string.account_setup_incoming_webdav_server_label);
        mConnectionSecurityChoices =
            new ConnectionSecurity[] {ConnectionSecurity.NONE, ConnectionSecurity.SSL_TLS_REQUIRED};

        // Hide the unnecessary fields
        findViewById(R.id.imap_path_prefix_section).setVisibility(View.GONE);
        findViewById(R.id.account_auth_type_label).setVisibility(View.GONE);
        findViewById(R.id.account_auth_type).setVisibility(View.GONE);
        findViewById(R.id.compression_section).setVisibility(View.GONE);
        findViewById(R.id.compression_label).setVisibility(View.GONE);
        // mSubscribedFoldersOnly.setVisibility(View.GONE);

        WebDavStoreSettings webDavSettings = (WebDavStoreSettings) settings;

        if (webDavSettings.path != null) {
          mWebdavPathPrefixView.setText(webDavSettings.path);
        }

        if (webDavSettings.authPath != null) {
          mWebdavAuthPathView.setText(webDavSettings.authPath);
        }

        if (webDavSettings.mailboxPath != null) {
          mWebdavMailboxPathView.setText(webDavSettings.mailboxPath);
        }
      } else {
        throw new Exception("Unknown account type: " + mAccount.getStoreUri());
      }

      if (!editSettings) {
        mAccount.setDeletePolicy(AccountCreator.getDefaultDeletePolicy(settings.type));
      }

      // Note that mConnectionSecurityChoices is configured above based on server type
      ConnectionSecurityAdapter securityTypesAdapter =
          ConnectionSecurityAdapter.get(this, mConnectionSecurityChoices);
      mSecurityTypeView.setAdapter(securityTypesAdapter);

      // Select currently configured security type
      if (savedInstanceState == null) {
        mCurrentSecurityTypeViewPosition =
            securityTypesAdapter.getConnectionSecurityPosition(settings.connectionSecurity);
      } else {

        /*
         * Restore the spinner state now, before calling
         * setOnItemSelectedListener(), thus avoiding a call to
         * onItemSelected(). Then, when the system restores the state
         * (again) in onRestoreInstanceState(), The system will see that
         * the new state is the same as the current state (set here), so
         * once again onItemSelected() will not be called.
         */
        mCurrentSecurityTypeViewPosition = savedInstanceState.getInt(STATE_SECURITY_TYPE_POSITION);
      }
      mSecurityTypeView.setSelection(mCurrentSecurityTypeViewPosition, false);

      updateAuthPlainTextFromSecurityType(settings.connectionSecurity);

      mCompressionMobile.setChecked(mAccount.useCompression(NetworkType.MOBILE));
      mCompressionWifi.setChecked(mAccount.useCompression(NetworkType.WIFI));
      mCompressionOther.setChecked(mAccount.useCompression(NetworkType.OTHER));

      if (settings.host != null) {
        mServerView.setText(settings.host);
      }

      if (settings.port != -1) {
        mPortView.setText(Integer.toString(settings.port));
      } else {
        updatePortFromSecurityType();
      }
      mCurrentPortViewSetting = mPortView.getText().toString();

      // mSubscribedFoldersOnly.setChecked(mAccount.subscribedFoldersOnly());
    } catch (Exception e) {
      failure(e);
    }
    // show & populate setup fields
    if (!Intent.ACTION_EDIT.equals(getIntent().getAction())) {
      findViewById(R.id.account_name_label).setVisibility(View.VISIBLE);
      mAccountName.setVisibility(View.VISIBLE);
      String desc = mAccount.getDescription();
      mAccountName.setText((desc != null ? desc : ""));
      findViewById(R.id.account_requires_cellular_label).setVisibility(View.VISIBLE);
      mRequiresCellular.setVisibility(View.VISIBLE);
      mRequiresCellular.setChecked(true);
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;
    setContentView(R.layout.activity_edit_alert);

    viewHeader = (TextView) findViewById(R.id.view_alert_header);

    buttonSave = (Button) findViewById(R.id.edit_alert_save);
    buttonRemove = (Button) findViewById(R.id.edit_alert_remove);
    buttonTest = (Button) findViewById(R.id.edit_alert_test);
    buttonalertMp3 = (Button) findViewById(R.id.Button_alert_mp3_file);
    buttonPreSnooze = (Button) findViewById(R.id.edit_alert_pre_snooze);

    alertText = (EditText) findViewById(R.id.edit_alert_text);
    alertThreshold = (EditText) findViewById(R.id.edit_alert_threshold);
    alertMp3File = (EditText) findViewById(R.id.edit_alert_mp3_file);

    checkboxAllDay = (CheckBox) findViewById(R.id.check_alert_time);

    layoutTimeBetween = (LinearLayout) findViewById(R.id.time_between);
    timeInstructions = (LinearLayout) findViewById(R.id.time_instructions);
    timeInstructionsStart = (TextView) findViewById(R.id.time_instructions_start);
    timeInstructionsEnd = (TextView) findViewById(R.id.time_instructions_end);

    viewTimeStart = (TextView) findViewById(R.id.view_alert_time_start);
    viewTimeEnd = (TextView) findViewById(R.id.view_alert_time_end);
    editSnooze = (EditText) findViewById(R.id.edit_snooze);
    reraise = (EditText) findViewById(R.id.reraise);

    viewAlertOverrideText = (TextView) findViewById(R.id.view_alert_override_silent);
    checkboxAlertOverride = (CheckBox) findViewById(R.id.check_override_silent);
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    addListenerOnButtons();

    if (BgGraphBuilder.isXLargeTablet(getApplicationContext())) {
      viewHeader.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      buttonSave.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      buttonRemove.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      buttonTest.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      buttonalertMp3.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      buttonSave.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      buttonPreSnooze.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      alertText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      alertThreshold.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      alertMp3File.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);

      checkboxAllDay.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);

      viewTimeStart.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      viewTimeEnd.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      editSnooze.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      reraise.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      viewAlertOverrideText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);

      ((TextView) findViewById(R.id.view_alert_text)).setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      ((TextView) findViewById(R.id.view_alert_threshold))
          .setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      ((TextView) findViewById(R.id.view_alert_default_snooze))
          .setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      ((TextView) findViewById(R.id.view_alert_mp3_file))
          .setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      ((TextView) findViewById(R.id.view_alert_time)).setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      ((TextView) findViewById(R.id.view_alert_time_between))
          .setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
    }
    SharedPreferences prefs =
        PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    doMgdl = (prefs.getString("units", "mgdl").compareTo("mgdl") == 0);

    if (!doMgdl) {
      alertThreshold.setInputType(InputType.TYPE_CLASS_NUMBER);
      alertThreshold.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
      alertThreshold.setKeyListener(DigitsKeyListener.getInstance(false, true));
    }

    uuid = getExtra(savedInstanceState, "uuid");
    String status;
    if (uuid == null) {
      // This is a new alert
      above = Boolean.parseBoolean(getExtra(savedInstanceState, "above"));
      checkboxAllDay.setChecked(true);
      checkboxAlertOverride.setChecked(true);

      audioPath = "";
      alertMp3File.setText(shortPath(audioPath));
      alertMp3File.setKeyListener(null);
      defaultSnooze = SnoozeActivity.getDefaultSnooze(above);
      buttonRemove.setVisibility(View.GONE);
      // One can not snooze an alert that is still not in the database...
      buttonPreSnooze.setVisibility(View.GONE);
      status = "Adding " + (above ? "high" : "low") + " alert";
      startHour = 0;
      startMinute = 0;
      endHour = 23;
      endMinute = 59;
      alertReraise = 1;
    } else {
      // We are editing an alert
      AlertType at = AlertType.get_alert(uuid);
      if (at == null) {
        Log.wtf(TAG, "Error editing alert, when that alert does not exist...");
        Intent returnIntent = new Intent();
        setResult(RESULT_CANCELED, returnIntent);
        finish();
        return;
      }

      above = at.above;
      alertText.setText(at.name);
      alertThreshold.setText(unitsConvert2Disp(doMgdl, at.threshold));
      checkboxAllDay.setChecked(at.all_day);
      checkboxAlertOverride.setChecked(at.override_silent_mode);
      defaultSnooze = at.default_snooze;
      if (defaultSnooze == 0) {
        SnoozeActivity.getDefaultSnooze(above);
      }

      audioPath = at.mp3_file;
      alertMp3File.setText(shortPath(audioPath));

      status = "editing " + (above ? "high" : "low") + " alert";
      startHour = AlertType.time2Hours(at.start_time_minutes);
      startMinute = AlertType.time2Minutes(at.start_time_minutes);
      endHour = AlertType.time2Hours(at.end_time_minutes);
      endMinute = AlertType.time2Minutes(at.end_time_minutes);
      alertReraise = at.minutes_between;

      if (uuid.equals(AlertType.LOW_ALERT_55)) {
        // This is the 55 alert, can not be edited
        alertText.setKeyListener(null);
        alertThreshold.setKeyListener(null);
        buttonalertMp3.setEnabled(false);
        checkboxAllDay.setEnabled(false);
        checkboxAlertOverride.setEnabled(false);
        reraise.setEnabled(false);
      }
    }
    reraise.setText(String.valueOf(alertReraise));
    alertMp3File.setKeyListener(null);
    viewHeader.setText(status);
    setDefaultSnoozeSpinner();
    setPreSnoozeSpinner();
    enableAllDayControls();
    enableVibrateControls();
  }
 public EditIntegerPreference(Context context, AttributeSet attrs, int defStyle) {
   super(context, attrs, defStyle);
   getEditText().setKeyListener(DigitsKeyListener.getInstance(true, true));
 }
 public EditIntegerPreference(Context context) {
   super(context);
   getEditText().setKeyListener(DigitsKeyListener.getInstance(true, true));
 }