private void obterSenha() {
    final String saida = "";
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    Resources res = getResources();

    alert.setMessage(res.getString(R.string.msg_informar_senha_backup));

    // Set an EditText view to get user input
    final EditText input = new EditText(this.getApplicationContext());
    input.setTransformationMethod(android.text.method.PasswordTransformationMethod.getInstance());
    alert.setView(input);

    alert.setPositiveButton(
        res.getString(R.string.opc_ok),
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
            Editable value = input.getText();
            comandarRestaurar(value.toString());
          }
        });

    alert.setNegativeButton(
        res.getString(R.string.opc_cancelar),
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
            // Canceled.
          }
        });

    alert.show();
  }
Пример #2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.facebook_login_ui);

    // start login sub activity
    loghelper = FacebookLoginHelper.instance(this);
    handler = new LoginHandler();

    facebook_info_span = (View) this.findViewById(R.id.facebook_info_span);
    facebook_info = (TextView) this.findViewById(R.id.facebook_info);
    facebook_info_span.setVisibility(View.VISIBLE);
    orm = SocialORM.instance(this);
    boolean forinvalidsession = getIntent().getBooleanExtra("forinvalidsession", false);
    if (forinvalidsession) {
      Log.d(TAG, "for invalid session issue=" + this);
      loghelper.clearSesion();
      AccountListener.AccountManager.logout();
    }

    // for UI
    email = (EditText) this.findViewById(R.id.facebook_login_email);
    email.setHint(R.string.facebook_email_address);
    pwd = (EditText) this.findViewById(R.id.facebook_login_pwd);
    pwd.setTransformationMethod(PasswordTransformationMethod.getInstance());
    pwd.setHint(R.string.facebook_password);

    login = (Button) this.findViewById(R.id.facebook_login_ok_button);
    sign_up = (Button) this.findViewById(R.id.facebook_login_sign_up_button);

    Paint p = login.getPaint();
    float width1 = p.measureText(login.getText().toString());
    p = null;

    p = sign_up.getPaint();
    float width2 = p.measureText(sign_up.getText().toString());
    int width = Math.round(Math.max(width1, width1));

    width = width + 40;
    login.getLayoutParams().width = width;
    sign_up.getLayoutParams().width = width;
    p = null;

    login.setText(R.string.facebook_login_ok);
    sign_up.setText(R.string.facebook_login_sign_up);
    checkbox_sync_phonebook = (CheckBox) this.findViewById(R.id.checkbox_sync_phonebook);
    checkbox_sync_phonebook.setChecked(orm.isEnableSyncPhonebook());
    checkbox_sync_phonebook.setOnCheckedChangeListener(checkedListener);

    login.setOnClickListener(loginClick);
    sign_up.setOnClickListener(signupClick);

    SocialORM.Account ac = orm.getFacebookAccount();
    email.setText(ac.email);
    pwd.setText(ac.password);

    setTitle(R.string.menu_title_login);
  }
Пример #3
0
  @Override
  protected Dialog onCreateDialog(int id) {
    switch (id) {
      case PASSWORD_DIALOG:
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        final AlertDialog passwordDialog = builder.create();

        passwordDialog.setTitle(getString(R.string.enter_admin_password));
        final EditText input = new EditText(this);
        input.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
        input.setTransformationMethod(PasswordTransformationMethod.getInstance());
        passwordDialog.setView(input, 20, 10, 20, 10);

        passwordDialog.setButton(
            AlertDialog.BUTTON_POSITIVE,
            getString(R.string.ok),
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int whichButton) {
                String value = input.getText().toString();
                String pw = mAdminPreferences.getString(AdminPreferencesActivity.KEY_ADMIN_PW, "");
                if (pw.compareTo(value) == 0) {
                  Intent i = new Intent(getApplicationContext(), AdminPreferencesActivity.class);
                  startActivity(i);
                  input.setText("");
                  passwordDialog.dismiss();
                } else {
                  Toast.makeText(
                          MainMenuActivity.this,
                          getString(R.string.admin_password_incorrect),
                          Toast.LENGTH_SHORT)
                      .show();
                  MyStatus.getInstance()
                      .getActivityLogger()
                      .logAction(this, "adminPasswordDialog", "PASSWORD_INCORRECT");
                }
              }
            });

        passwordDialog.setButton(
            AlertDialog.BUTTON_NEGATIVE,
            getString(R.string.cancel),
            new DialogInterface.OnClickListener() {

              public void onClick(DialogInterface dialog, int which) {
                MyStatus.getInstance()
                    .getActivityLogger()
                    .logAction(this, "adminPasswordDialog", "cancel");
                input.setText("");
                return;
              }
            });

        passwordDialog
            .getWindow()
            .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        return passwordDialog;
    }
    return null;
  }
 // CURRENCY
 public void setInputTypeEx(String str) {
   bufStr = new String(str.toString());
   if (str.equals("NUMBER")) {
     this.setInputType(android.text.InputType.TYPE_CLASS_NUMBER);
   } else if (str.equals("CURRENCY")) { // thanks to @renabor	
     this.setInputType(
         InputType.TYPE_CLASS_NUMBER
             | InputType.TYPE_NUMBER_FLAG_DECIMAL
             | InputType.TYPE_NUMBER_FLAG_SIGNED);
   } else if (str.equals("CAPCHARACTERS")) {
     if (!mFlagSuggestion)
       this.setInputType(
           android.text.InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS
               | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
     else this.setInputType(android.text.InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);
   } else if (str.equals("TEXT")) {
     if (!mFlagSuggestion)
       this.setInputType(
           android.text.InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
     else this.setInputType(android.text.InputType.TYPE_CLASS_TEXT);
   } else if (str.equals("PHONE")) {
     this.setInputType(android.text.InputType.TYPE_CLASS_PHONE);
   } else if (str.equals("PASSNUMBER")) {
     this.setInputType(android.text.InputType.TYPE_CLASS_NUMBER);
     this.setTransformationMethod(android.text.method.PasswordTransformationMethod.getInstance());
   } else if (str.equals("PASSTEXT")) {
     this.setInputType(android.text.InputType.TYPE_CLASS_TEXT);
     this.setTransformationMethod(android.text.method.PasswordTransformationMethod.getInstance());
   } else if (str.equals("TEXTMULTILINE")) {
     if (!mFlagSuggestion)
       this.setInputType(
           android.text.InputType.TYPE_CLASS_TEXT
               | android.text.InputType.TYPE_TEXT_FLAG_MULTI_LINE
               | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
     else
       this.setInputType(
           android.text.InputType.TYPE_CLASS_TEXT
               | android.text.InputType.TYPE_TEXT_FLAG_MULTI_LINE);
   } else {
     this.setInputType(
         android.text.InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
   }
   ;
 }
Пример #5
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String accountUuid = getIntent().getStringExtra("account");
    mAccount = Preferences.getPreferences(this).getAccount(accountUuid);

    setContentView(R.layout.encryption_pin);
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT)) {
      accountUuid = savedInstanceState.getString(EXTRA_ACCOUNT);
      mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
    }

    pinStatus = (TextView) findViewById(R.id.pin_status);
    firstPin = (EditText) findViewById(R.id.pin);
    firstPin.setInputType(InputType.TYPE_CLASS_PHONE);
    firstPin.setTransformationMethod(
        android.text.method.PasswordTransformationMethod.getInstance());

    confirmPin = (EditText) findViewById(R.id.confirm_pin);
    confirmPin.setInputType(InputType.TYPE_CLASS_PHONE);
    confirmPin.setTransformationMethod(
        android.text.method.PasswordTransformationMethod.getInstance());

    nextButton = (Button) findViewById(R.id.next);
    nextButton.setOnClickListener(this);
    nextButton.setEnabled(true);

    deleteButton = (Button) findViewById(R.id.delete_pin);
    deleteButton.setOnClickListener(this);
    deleteButton.setEnabled(false);

    // If pin exists, enable delete button and disable next button
    if (Hash.pinExists(this, mAccount.getEmail())) {
      nextButton.setEnabled(false);
      deleteButton.setEnabled(true);
    }
    redraw();
  }
 private void showPassword() {
   if (isShown) {
     passwordEdit.setTransformationMethod(PasswordTransformationMethod.getInstance());
   } else {
     passwordEdit.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
   }
   isShown = !isShown;
   if (isShown) {
     showPassword.setImageResource(R.drawable.ic_hide);
   } else {
     showPassword.setImageResource(R.drawable.ic_show);
   }
 }
Пример #7
0
 public void showHidePassword(View view) {
   switch (view.getId()) {
     case R.id.login_show_button:
       showPasswordImgButton.setVisibility(View.GONE);
       hidePasswordImgButton.setVisibility(View.VISIBLE);
       passwordLogin.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
       break;
     case R.id.login_hide_button:
       hidePasswordImgButton.setVisibility(View.GONE);
       showPasswordImgButton.setVisibility(View.VISIBLE);
       passwordLogin.setTransformationMethod(PasswordTransformationMethod.getInstance());
       break;
   }
 }
  @SuppressWarnings("deprecation")
  protected void setPasswordButtonShown(boolean shouldShow) {
    // Changing input type loses position in edit text; let's try to maintain it.
    int start = passwordEdit.getSelectionStart();
    int stop = passwordEdit.getSelectionEnd();

    if (!shouldShow) {
      passwordEdit.setTransformationMethod(PasswordTransformationMethod.getInstance());
      showPasswordButton.setText(R.string.fxaccount_password_show);
      showPasswordButton.setBackgroundDrawable(
          getResources().getDrawable(R.drawable.fxaccount_password_button_show_background));
      showPasswordButton.setTextColor(
          getResources().getColor(R.color.fxaccount_password_show_textcolor));
    } else {
      passwordEdit.setTransformationMethod(SingleLineTransformationMethod.getInstance());
      showPasswordButton.setText(R.string.fxaccount_password_hide);
      showPasswordButton.setBackgroundDrawable(
          getResources().getDrawable(R.drawable.fxaccount_password_button_hide_background));
      showPasswordButton.setTextColor(
          getResources().getColor(R.color.fxaccount_password_hide_textcolor));
    }
    passwordEdit.setSelection(start, stop);
  }
Пример #9
0
  // Delete account pin file
  private void deletePin() {
    if (Hash.pinExists(this, mAccount.getEmail().toLowerCase())) {
      AlertDialog.Builder alert = new AlertDialog.Builder(this);
      alert.setTitle("Confirm PIN");
      alert.setMessage("Enter your PIN to unlink it from this account");

      // Set an EditText view to get user input
      final EditText input = new EditText(this);
      input.setInputType(InputType.TYPE_CLASS_PHONE);
      input.setTransformationMethod(android.text.method.PasswordTransformationMethod.getInstance());

      alert.setView(input);

      alert.setPositiveButton(
          "Ok",
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
              if (input.getText().length() < 4) {
                Toast.makeText(
                        EncryptionPin.this, "Pin must be at least 4 characters", Toast.LENGTH_LONG)
                    .show();
                return;
              }

              // Check .pin2
              FileInputStream fis1;
              try {
                fis1 = openFileInput((mAccount.getEmail().toLowerCase()) + ".pin2");
                BufferedReader in1 = new BufferedReader(new InputStreamReader(fis1));
                String test = in1.readLine();
                String storedHash = "";
                while (test != null) {
                  storedHash = storedHash + test;
                  test = in1.readLine();
                }

                char[] inputPin = new char[input.getText().length()];
                for (int i = 0; i < input.getText().length(); i++)
                  inputPin[i] = input.getText().charAt(i);

                String storedStatic =
                    Hash.getStatic(storedHash, input.getText().length(), EncryptionPin.this);
                String storedRand =
                    Hash.getRandom(storedHash, input.getText().length(), EncryptionPin.this);
                String userHash =
                    Hash.verify(mAccount.getEmail().toString(), inputPin, storedRand, storedStatic);

                if (storedHash != null && userHash != null)
                  if (Hash.compareHashes(storedHash, userHash)) {
                    Toast.makeText(
                            EncryptionPin.this, "Hashes match. Pin deleted.", Toast.LENGTH_SHORT)
                        .show();

                    EncryptionPin.this.deleteFile((mAccount.getEmail() + ".pin").toLowerCase());
                    EncryptionPin.this.deleteFile((mAccount.getEmail() + ".pin2").toLowerCase());

                    mAccount.setAskForPin("Never");
                    redraw();
                    MessageList.actionHandleFolder(
                        EncryptionPin.this, mAccount, mAccount.getAutoExpandFolderName());
                    finish();
                  } else
                    Toast.makeText(EncryptionPin.this, "Hash mismatch", Toast.LENGTH_SHORT).show();

              } catch (FileNotFoundException e) {
                Toast.makeText(EncryptionPin.this, "Hashed PIN not found", Toast.LENGTH_LONG)
                    .show();

              } catch (IOException e) {
                Toast.makeText(EncryptionPin.this, "Error retreiving PIN", Toast.LENGTH_SHORT)
                    .show();
              }

              char[] pinFromFile = new char[input.getText().length()];
              for (int i = 0; i < input.getText().length(); i++)
                pinFromFile[i] = input.getText().charAt(i);

              // Check .pin
              FileInputStream fis;
              try {
                fis = openFileInput((mAccount.getEmail().toLowerCase()) + ".pin");
                BufferedReader in = new BufferedReader(new InputStreamReader(fis));
                char[] pin = in.readLine().toCharArray();

                if (Arrays.equals(pin, pinFromFile)) {
                  mAccount.setAskForPin("0");
                  EncryptionPin.this.deleteFile(
                      mAccount.getEmail().toString().toLowerCase() + ".pin");
                  Toast.makeText(EncryptionPin.this, "PIN removed", Toast.LENGTH_SHORT).show();
                  redraw();
                  ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
                      .hideSoftInputFromWindow(input.getWindowToken(), 0);

                  mAccount.setAskForPin("Never");

                  // Return to settings
                  EncryptionSettings.encryptionSettings(EncryptionPin.this, mAccount);
                } else
                  Toast.makeText(EncryptionPin.this, "Incorrect PIN", Toast.LENGTH_SHORT).show();

                if (pin != null) Arrays.fill(pin, '0');
                if (pinFromFile != null) Arrays.fill(pinFromFile, '0');

              } catch (FileNotFoundException e) {

              } catch (IOException e) {
              }
            }
          });

      alert.setNegativeButton(
          "Cancel",
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
              // Canceled.

            }
          });

      alert.setIcon(R.drawable.pin);
      alert.show();

    } else
      Toast.makeText(
              EncryptionPin.this, "PIN not yet created for this account.", Toast.LENGTH_SHORT)
          .show();
  }
Пример #10
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.new_login);
    tv_password_query = (TextView) findViewById(R.id.tv_password_query);
    tv_password_query.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            Intent intent = new Intent(NewLoginAct.this, PosswordQuery.class);
            startActivity(intent);
          }
        });
    btnBack = (Button) (findViewById(R.id.btnBack));
    btnBack.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            finish();
          }
        });

    emailEt = (LoginNameEditText) findViewById(R.id.login_et_email);
    passwordEt = (LoginPassEditText) findViewById(R.id.login_et_password);
    /*emailEt.getEdt().addTextChangedListener(
    new FilterTextWatcher(1)); */
    emailEt.getEdt().setHint("邮箱/手机号");
    InputFilter[] filters = {new LengthFilter(30)};
    emailEt.getEdt().setFilters(filters);
    emailEt.getEdt().setHeight(80);
    emailEt.getEdt().setCursorVisible(true);
    emailEt.getEdt().setTypeface(Typeface.SANS_SERIF);
    emailEt
        .getEdt()
        .setHintTextColor(NewLoginAct.this.getResources().getColor(R.color.login_register_text));
    emailEt.getEdt().setTextColor(NewLoginAct.this.getResources().getColor(R.color.dark));
    emailEt
        .getEdt()
        .setOnFocusChangeListener(
            new OnFocusChangeListener() {

              @Override
              public void onFocusChange(View v, boolean hasFocus) {
                String str_email = emailEt.getEditTextContent();
                if (hasFocus) {
                  // 获得光标
                  if (str_email != null && !str_email.equals("")) {
                    emailEt.getUNameDel().setVisibility(View.VISIBLE);
                    emailEt
                        .getUNameDel()
                        .setOnClickListener(
                            new OnClickListener() {

                              @Override
                              public void onClick(View v) {
                                emailEt.getEdt().setText("");
                              }
                            });
                    emailEt
                        .getTvwUname()
                        .setOnClickListener(
                            new OnClickListener() {

                              @Override
                              public void onClick(View v) {
                                emailEt.getEdt().setText("");
                              }
                            });
                  } else {
                    emailEt.getUNameDel().setVisibility(View.GONE);
                  }
                } else {
                  emailEt.getUNameDel().setVisibility(View.GONE);
                  if (str_email == null || str_email.equals("")) {
                    return;
                  }
                  if (StringUtils.length(emailEt.getEdt().getText().toString().trim()) < 4) {
                    StringUtils.showLongToast(
                        NewLoginAct.this.getApplicationContext(), "用户名不能少于4个字符");
                    return;
                  }
                  if (StringUtils.length(emailEt.getEdt().getText().toString().trim()) > 30) {
                    StringUtils.showLongToast(
                        NewLoginAct.this.getApplicationContext(), "用户名不能超过30个字符");
                    return;
                  }
                  // 验证用户名和邮箱
                  /*if (!chkName(emailEt.getEdt().getText().toString().trim())) {
                  	StringUtils.showLongToast(NewLoginAct.this.getApplicationContext(),"用户名只能使用数字或字符");
                  	return;
                  }*/
                }
              }
            });
    passwordEt.getEdt().addTextChangedListener(new FilterTextWatcher(2));
    passwordEt.getEdt().setTransformationMethod(PasswordTransformationMethod.getInstance());
    passwordEt.getEdt().setHint("密码");
    passwordEt.getEdt().setHeight(80);
    InputFilter[] filterPass = {new LengthFilter(20)};
    passwordEt.getEdt().setFilters(filterPass);
    passwordEt.getEdt().setCursorVisible(true);
    passwordEt.getEdt().setTypeface(Typeface.SANS_SERIF);
    passwordEt
        .getEdt()
        .setHintTextColor(NewLoginAct.this.getResources().getColor(R.color.login_register_text));
    passwordEt.getEdt().setTextColor(NewLoginAct.this.getResources().getColor(R.color.dark));
    passwordEt
        .getEdt()
        .setOnFocusChangeListener(
            new OnFocusChangeListener() {

              @Override
              public void onFocusChange(View v, boolean hasFocus) {
                String str_pass = passwordEt.getEditTextContent();
                if (hasFocus) {
                  // 获得光标
                  if (str_pass != null && !str_pass.equals("")) {
                    passwordEt.getUNameDel().setVisibility(View.VISIBLE);
                    passwordEt
                        .getUNameDel()
                        .setOnClickListener(
                            new OnClickListener() {

                              @Override
                              public void onClick(View v) {
                                passwordEt.getEdt().setText("");
                              }
                            });
                    passwordEt
                        .getTvwUname()
                        .setOnClickListener(
                            new OnClickListener() {

                              @Override
                              public void onClick(View v) {
                                passwordEt.getEdt().setText("");
                              }
                            });

                  } else {
                    passwordEt.getUNameDel().setVisibility(View.GONE);
                  }
                } else {
                  passwordEt.getUNameDel().setVisibility(View.GONE);
                  if (TextUtils.isEmpty(passwordEt.getEdt().getText().toString().trim())) {
                    return;
                  }
                  if (StringUtils.length(passwordEt.getEdt().getText().toString().trim()) < 6) {
                    StringUtils.showLongToast(
                        NewLoginAct.this.getApplicationContext(), "密码不能少于6个字符");
                    return;
                  }
                  /*if (StringUtils.length(passwordEt.getEdt().getText().toString().trim()) > 20) {
                  	StringUtils.showLongToast(NewLoginAct.this.getApplicationContext(),"密码不能超过20个字符");
                  	return;
                  }
                  // 验证密码
                  if (!chkPassword(passwordEt.getEdt().getText().toString().trim())) {
                  	StringUtils.showLongToast(NewLoginAct.this.getApplicationContext(),"密码必须包括数字和字母");
                  	return;
                  }*/
                }
              }
            });
    m1905Login = (Button) findViewById(R.id.login_btn_login);
    m1905Login.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            emailEt.getEdt().requestFocus();
            passwordEt.getEdt().requestFocus();
            emailEt.getEdt().setCursorVisible(false);
            passwordEt.getEdt().setCursorVisible(false);
            emailEt.getUNameDel().setVisibility(View.GONE);
            passwordEt.getUNameDel().setVisibility(View.GONE);
            // 隐藏软键盘
            ((InputMethodManager)
                    NewLoginAct.this
                        .getApplicationContext()
                        .getSystemService(
                            NewLoginAct.this.getApplicationContext().INPUT_METHOD_SERVICE))
                .hideSoftInputFromWindow(
                    NewLoginAct.this.getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
            String email = emailEt.getEdt().getText().toString().trim();
            String password = passwordEt.getEdt().getText().toString().trim();
            if (email.equals("") || password.equals("")) {
              StringUtils.showLongToast(NewLoginAct.this.getApplicationContext(), "请将信息填写完整");
            } else {
              if (Identify.currentUser == null) {
                if (email.length() >= 4 && email.length() <= 30) {
                  if (password.length() >= 6 && password.length() <= 20) {
                    progressDialog = DialogUtil.showProgressDialog(NewLoginAct.this, "登录中, 请稍候..");
                    new GetM1905LoginTask().execute(email, password);
                  } else {
                    StringUtils.showLongToast(
                        NewLoginAct.this.getApplicationContext(), "密码6-20个字符");
                  }

                } else {
                  StringUtils.showLongToast(NewLoginAct.this.getApplicationContext(), "用户名4-30个字符");
                }

              } else {
                StringUtils.showLongToast(NewLoginAct.this.getApplicationContext(), "您已登录");
                emailEt.getEdt().setText("");
                passwordEt.getEdt().setText("");
              }
            }
          }
        });
    login_btn_register = (Button) findViewById(R.id.login_btn_register);
    login_btn_register.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent(NewLoginAct.this, LoginAct.class);
            // startActivity(intent);
            startActivityForResult(intent, 1);
          }
        });
  }
Пример #11
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);
    }
  }
    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
      final Activity activity = getActivity();

      ContextThemeWrapper theme = ThemeChanger.getDialogThemeWrapper(activity);

      mRequiredInput = getArguments().getParcelable(EXTRA_REQUIRED_INPUT);

      CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(theme);

      // No title, see http://www.google.com/design/spec/components/dialogs.html#dialogs-alerts
      // alert.setTitle()

      if (mRequiredInput.mType == RequiredInputType.BACKUP_CODE) {
        LayoutInflater inflater = LayoutInflater.from(theme);
        View view = inflater.inflate(R.layout.passphrase_dialog_backup_code, null);
        alert.setView(view);

        mBackupCodeEditText = new EditText[4];
        mBackupCodeEditText[0] = (EditText) view.findViewById(R.id.backup_code_1);
        mBackupCodeEditText[1] = (EditText) view.findViewById(R.id.backup_code_2);
        mBackupCodeEditText[2] = (EditText) view.findViewById(R.id.backup_code_3);
        mBackupCodeEditText[3] = (EditText) view.findViewById(R.id.backup_code_4);
        setupEditTextFocusNext(mBackupCodeEditText);

        AlertDialog dialog = alert.create();
        dialog.setButton(
            DialogInterface.BUTTON_POSITIVE,
            activity.getString(R.string.btn_unlock),
            (DialogInterface.OnClickListener) null);
        return dialog;
      }

      long subKeyId = mRequiredInput.getSubKeyId();

      LayoutInflater inflater = LayoutInflater.from(theme);
      mLayout = (ViewAnimator) inflater.inflate(R.layout.passphrase_dialog, null);
      alert.setView(mLayout);

      mPassphraseText = (TextView) mLayout.findViewById(R.id.passphrase_text);
      mPassphraseEditText = (EditText) mLayout.findViewById(R.id.passphrase_passphrase);

      View vTimeToLiveLayout = mLayout.findViewById(R.id.remember_layout);
      vTimeToLiveLayout.setVisibility(mRequiredInput.mSkipCaching ? View.GONE : View.VISIBLE);

      mTimeToLiveSpinner = (CacheTTLSpinner) mLayout.findViewById(R.id.ttl_spinner);

      alert.setNegativeButton(
          android.R.string.cancel,
          new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int id) {
              dialog.cancel();
            }
          });

      String userId;
      CanonicalizedSecretKey.SecretKeyType keyType =
          CanonicalizedSecretKey.SecretKeyType.PASSPHRASE;

      String message;
      String hint;
      if (mRequiredInput.mType == RequiredInputType.PASSPHRASE_SYMMETRIC) {
        message = getString(R.string.passphrase_for_symmetric_encryption);
        hint = getString(R.string.label_passphrase);
      } else {
        try {
          ProviderHelper helper = new ProviderHelper(activity);
          mSecretRing =
              helper.getCanonicalizedSecretKeyRing(
                  KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId));
          // yes the inner try/catch block is necessary, otherwise the final variable
          // above can't be statically verified to have been set in all cases because
          // the catch clause doesn't return.
          try {
            String mainUserId = mSecretRing.getPrimaryUserIdWithFallback();
            KeyRing.UserId mainUserIdSplit = KeyRing.splitUserId(mainUserId);
            if (mainUserIdSplit.name != null) {
              userId = mainUserIdSplit.name;
            } else {
              userId = getString(R.string.user_id_no_name);
            }
          } catch (PgpKeyNotFoundException e) {
            userId = null;
          }

          keyType = mSecretRing.getSecretKey(subKeyId).getSecretKeyType();
          switch (keyType) {
            case PASSPHRASE:
              message = getString(R.string.passphrase_for, userId);
              hint = getString(R.string.label_passphrase);
              break;
            case PIN:
              message = getString(R.string.pin_for, userId);
              hint = getString(R.string.label_pin);
              break;
            case DIVERT_TO_CARD:
              message = getString(R.string.yubikey_pin_for, userId);
              hint = getString(R.string.label_pin);
              break;
              // special case: empty passphrase just returns the empty passphrase
            case PASSPHRASE_EMPTY:
              finishCaching(new Passphrase(""));
            default:
              throw new AssertionError("Unhandled SecretKeyType (should not happen)");
          }

        } catch (ProviderHelper.NotFoundException e) {
          alert.setTitle(R.string.title_key_not_found);
          alert.setMessage(getString(R.string.key_not_found, mRequiredInput.getSubKeyId()));
          alert.setPositiveButton(
              android.R.string.ok,
              new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                  dismiss();
                }
              });
          alert.setCancelable(false);
          return alert.create();
        }
      }

      mPassphraseText.setText(message);
      mPassphraseEditText.setHint(hint);

      // Hack to open keyboard.
      // This is the only method that I found to work across all Android versions
      // http://turbomanage.wordpress.com/2012/05/02/show-soft-keyboard-automatically-when-edittext-receives-focus/
      // Notes: * onCreateView can't be used because we want to add buttons to the dialog
      //        * opening in onActivityCreated does not work on Android 4.4
      mPassphraseEditText.setOnFocusChangeListener(
          new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
              mPassphraseEditText.post(
                  new Runnable() {
                    @Override
                    public void run() {
                      if (getActivity() == null || mPassphraseEditText == null) {
                        return;
                      }
                      InputMethodManager imm =
                          (InputMethodManager)
                              getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                      imm.showSoftInput(mPassphraseEditText, InputMethodManager.SHOW_IMPLICIT);
                    }
                  });
            }
          });
      mPassphraseEditText.requestFocus();

      mPassphraseEditText.setImeActionLabel(
          getString(android.R.string.ok), EditorInfo.IME_ACTION_DONE);
      mPassphraseEditText.setOnEditorActionListener(this);

      if ((keyType == CanonicalizedSecretKey.SecretKeyType.DIVERT_TO_CARD
              && Preferences.getPreferences(activity).useNumKeypadForYubiKeyPin())
          || keyType == CanonicalizedSecretKey.SecretKeyType.PIN) {
        mPassphraseEditText.setInputType(InputType.TYPE_CLASS_NUMBER);
        mPassphraseEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
      } else {
        mPassphraseEditText.setRawInputType(
            InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
      }

      mPassphraseEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());

      AlertDialog dialog = alert.create();
      dialog.setButton(
          DialogInterface.BUTTON_POSITIVE,
          activity.getString(R.string.btn_unlock),
          (DialogInterface.OnClickListener) null);

      return dialog;
    }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "onCreate");

    scroll = new ScrollView(this);
    setContentView(scroll);

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setLayoutParams(
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    layout.setPadding(10, 10, 10, 10);
    scroll.addView(
        layout,
        new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

    viewNetwork = new Button(this);
    viewNetwork.setLayoutParams(
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    viewNetwork.setText(getResources().getString(R.string.view_network_button));
    viewNetwork.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            final String[] networkTreeCopy = networkTree;
            AlertDialog.Builder builder = new AlertDialog.Builder(AddPrinterActivity.this);
            // builder.setTitle(R.string.network);
            builder.setItems(
                networkTreeCopy,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, final int which) {
                    dialog.dismiss();
                    String selected = networkTreeCopy[which];
                    selected = selected.trim();
                    if (!selected.startsWith("\\\\")) return;
                    selected = selected.substring(2);
                    if (selected.indexOf("\\") == -1) return;
                    String server = selected.substring(0, selected.indexOf("\\"));
                    String share = selected.substring(selected.indexOf("\\") + 1);
                    share = share.split("\\s+")[0];
                    AddPrinterActivity.this.server.setText(server);
                    AddPrinterActivity.this.printer.setText(share);
                    AddPrinterActivity.this.name.setText(server + "-" + share);
                    String workgroup = "";
                    for (int i = 0; i < which; i++) {
                      if (networkTreeCopy[i].indexOf("\\") == -1) workgroup = networkTreeCopy[i];
                    }
                    if (workgroup.length() > 0) AddPrinterActivity.this.domain.setText(workgroup);
                  }
                });
            builder.setNegativeButton(
                R.string.close,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface d, int s) {
                    d.dismiss();
                    if (user.getText().toString().length() == 0
                        || password.getText().toString().length() == 0)
                      Toast.makeText(
                              AddPrinterActivity.this,
                              R.string.login_password_hint,
                              Toast.LENGTH_LONG)
                          .show();
                  }
                });
            builder.setPositiveButton(
                R.string.view_network_button_scan_again,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface d, int s) {
                    d.dismiss();
                    updateNetworkTree();
                    if (user.getText().toString().length() == 0
                        || password.getText().toString().length() == 0)
                      Toast.makeText(
                              AddPrinterActivity.this,
                              R.string.login_password_hint,
                              Toast.LENGTH_LONG)
                          .show();
                  }
                });
            AlertDialog alert = builder.create();
            alert.setOwnerActivity(AddPrinterActivity.this);
            alert.show();
          }
        });
    layout.addView(viewNetwork);

    TextView text = null;

    text = new TextView(this);
    text.setText(R.string.name_desc);
    text.setTextSize(20);
    layout.addView(text);

    name = new EditText(this);
    name.setHint(R.string.name_hint);
    name.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    layout.addView(name);

    text = new TextView(this);
    text.setText(R.string.server_desc);
    text.setTextSize(20);
    layout.addView(text);

    server = new EditText(this);
    server.setHint(R.string.server_hint);
    server.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    layout.addView(server);

    text = new TextView(this);
    text.setText(R.string.printer_desc);
    text.setTextSize(20);
    layout.addView(text);

    printer = new EditText(this);
    printer.setHint(R.string.printer_hint);
    printer.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    layout.addView(printer);

    text = new TextView(this);
    text.setText(R.string.model_desc);
    text.setTextSize(20);
    layout.addView(text);

    model = new EditText(this);
    model.setHint(R.string.model_button_reading);
    model.setEnabled(false);
    model.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    model.addTextChangedListener(
        new TextWatcher() {
          public void afterTextChanged(Editable s) {
            if (s.length() >= 1 && modelList != null) {
              // selectModel.setEnabled(true);
              selectModel.setText(getResources().getString(R.string.model_button_search));
            } else {
              // selectModel.setEnabled(false);
              selectModel.setText(getResources().getString(R.string.model_button_type));
            }
          }

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

          public void onTextChanged(CharSequence s, int start, int before, int count) {}
        });
    layout.addView(model);

    selectModel = new Button(this);
    selectModel.setText(getResources().getString(R.string.model_button_reading));
    selectModel.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            if (!model.isEnabled()) {
              model.setEnabled(true);
              model.setText("");
              return;
            }
            String search = model.getText().toString().toLowerCase();
            final ArrayList<CharSequence> values = new ArrayList<CharSequence>();
            AlertDialog.Builder builder = new AlertDialog.Builder(AddPrinterActivity.this);
            builder.setTitle(R.string.select_printer_model);
            for (String s : modelList.keySet()) {
              if (s.toLowerCase().indexOf(search) != -1) {
                Log.d(TAG, "Found model: " + s);
                values.add(s);
              }
            }
            if (values.size() == 0) {
              builder.setMessage(R.string.no_models_found);
              builder.setPositiveButton(
                  R.string.ok,
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface d, int s) {
                      d.dismiss();
                    }
                  });
            } else {
              builder.setItems(
                  values.toArray(new CharSequence[0]),
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                      model.setText(values.get(which));
                      model.setEnabled(false);
                      selectModel.setText(getResources().getString(R.string.model_button_clear));
                    }
                  });
            }
            AlertDialog alert = builder.create();
            alert.setOwnerActivity(AddPrinterActivity.this);
            alert.show();
          }
        });
    selectModel.setEnabled(false);
    layout.addView(selectModel);

    text = new TextView(this);
    text.setText(R.string.domain_desc);
    text.setTextSize(20);
    layout.addView(text);

    domain = new EditText(this);
    domain.setHint(R.string.domain_hint);
    domain.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    layout.addView(domain);

    text = new TextView(this);
    text.setText(R.string.user_desc);
    text.setTextSize(20);
    layout.addView(text);

    user = new EditText(this);
    user.setHint(R.string.user_hint);
    user.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    layout.addView(user);

    text = new TextView(this);
    text.setText(R.string.password_desc);
    text.setTextSize(20);
    text.setLayoutParams(
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f));

    CheckBox showPassword = new CheckBox(this);
    showPassword.setText(R.string.show_password);
    showPassword.setTextSize(20);
    showPassword.setLayoutParams(
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0.0f));
    showPassword.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            int selection = password.getSelectionStart();
            if (isChecked) {
              password.setInputType(
                  InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
              password.setTransformationMethod(null);
            } else {
              password.setInputType(
                  InputType.TYPE_CLASS_TEXT
                      | InputType.TYPE_TEXT_VARIATION_PASSWORD
                      | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
              password.setTransformationMethod(PasswordTransformationMethod.getInstance());
            }
            password.setSelection(selection);
          }
        });

    LinearLayout layout2 = new LinearLayout(this);
    layout2.setOrientation(LinearLayout.HORIZONTAL);
    layout2.setLayoutParams(
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    layout2.addView(text);
    layout2.addView(showPassword);

    layout.addView(layout2);

    password = new EditText(this);
    password.setHint(R.string.password_hint);
    password.setInputType(
        InputType.TYPE_CLASS_TEXT
            | InputType.TYPE_TEXT_VARIATION_PASSWORD
            | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    password.setTransformationMethod(PasswordTransformationMethod.getInstance());
    layout.addView(password);

    text = new TextView(this);
    text.setText("");
    layout.addView(text);

    addPrinter = new Button(this);
    addPrinter.setEnabled(false);
    addPrinter.setText(
        getResources().getString(R.string.add_printer_button)
            + " - "
            + getResources().getString(R.string.model_button_reading));
    addPrinter.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            if (name.getText().length() == 0
                || server.getText().length() == 0
                || printer.getText().length() == 0
                || model.isEnabled()
                || model.getText().length() == 0) {
              AlertDialog.Builder builder = new AlertDialog.Builder(AddPrinterActivity.this);
              builder.setTitle(R.string.error);
              builder.setMessage(R.string.error_empty_fields);
              builder.setPositiveButton(
                  R.string.ok,
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface d, int s) {
                      d.dismiss();
                    }
                  });
              AlertDialog alert = builder.create();
              alert.setOwnerActivity(AddPrinterActivity.this);
              alert.show();
              return;
            }
            progressCircle.show();
            new Thread(
                    new Runnable() {
                      public void run() {
                        Cups.addPrinter(
                            AddPrinterActivity.this,
                            name.getText().toString(),
                            server.getText().toString(),
                            printer.getText().toString(),
                            modelList.get(model.getText().toString()),
                            domain.getText().toString().toUpperCase(),
                            user.getText().toString(),
                            password.getText().toString());
                        Cups.updatePrintersInfo(AddPrinterActivity.this);
                        runOnUiThread(
                            new Runnable() {
                              public void run() {
                                progressCircle.dismiss();
                                Toast.makeText(
                                        AddPrinterActivity.this,
                                        R.string.printer_added_successfully,
                                        Toast.LENGTH_LONG)
                                    .show();
                                finish();
                              }
                            });
                      }
                    })
                .start();
          }
        });
    layout.addView(addPrinter);

    progressCircle = new ProgressDialog(this);
    progressCircle.setMessage(getResources().getString(R.string.please_wait));

    updateNetworkTree();

    Uri uri = getIntent() != null ? getIntent().getData() : null;
    if (uri != null
        && uri.getScheme() != null
        && uri.getHost() != null
        && getResources().getString(R.string.add_printer_scheme).equals(uri.getScheme())
        && getResources().getString(R.string.add_printer_host).equals(uri.getHost())) {
      name.setText(uri.getQueryParameter("n"));
      server.setText(uri.getQueryParameter("s"));
      printer.setText(uri.getQueryParameter("p"));
      model.setText(uri.getQueryParameter("m"));
      domain.setText(uri.getQueryParameter("d"));
      user.setText(uri.getQueryParameter("u"));
      password.setText(uri.getQueryParameter("pw"));
    }

    updateModelList();
  }
Пример #14
0
  @Override
  public void processProperties(TiDict d) {
    super.processProperties(d);

    if (d.containsKey("enabled")) {
      tv.setEnabled(d.getBoolean("enabled"));
    }
    if (d.containsKey("value")) {
      tv.setText(d.getString("value"));
    }
    if (d.containsKey("color")) {
      tv.setTextColor(TiConvert.toColor(d, "color"));
    }
    if (d.containsKey("hintText")) {
      tv.setHint(d.getString("hintText"));
    }
    if (d.containsKey("font")) {
      TiUIHelper.styleText(tv, d.getTiDict("font"));
    }
    if (d.containsKey("textAlign") || d.containsKey("verticalAlign")) {
      String textAlign = null;
      String verticalAlign = null;
      if (d.containsKey("textAlign")) {
        textAlign = d.getString("textAlign");
      }
      if (d.containsKey("verticalAlign")) {
        verticalAlign = d.getString("verticalAlign");
      }
      handleTextAlign(textAlign, verticalAlign);
    }
    if (d.containsKey("returnKeyType")) {
      handleReturnKeyType(d.getInt("returnKeyType"));
    }
    if (d.containsKey("keyboardType")) {
      boolean autocorrect = true;
      if (d.containsKey("autocorrect")) {
        autocorrect = d.getBoolean("autocorrect");
      }
      handleKeyboardType(d.getInt("keyboardType"), autocorrect);
    }

    if (d.containsKey("autocapitalization")) {

      Capitalize autoCapValue = null;

      switch (d.getInt("autocapitalization")) {
        case TEXT_AUTOCAPITALIZATION_NONE:
          autoCapValue = Capitalize.NONE;
          break;

        case TEXT_AUTOCAPITALIZATION_ALL:
          autoCapValue = Capitalize.CHARACTERS;
          break;

        case TEXT_AUTOCAPITALIZATION_SENTENCES:
          autoCapValue = Capitalize.SENTENCES;
          break;

        case TEXT_AUTOCAPITALIZATION_WORDS:
          autoCapValue = Capitalize.WORDS;
          break;

        default:
          Log.w(
              LCAT, "Unknown AutoCapitalization Value [" + d.getString("autocapitalization") + "]");
          break;
      }

      if (null != autoCapValue) {
        tv.setKeyListener(TextKeyListener.getInstance(false, autoCapValue));
      }
    }

    if (d.containsKey("passwordMask")) {
      if (TiConvert.toBoolean(d.get("passwordMask"))) {
        // This shouldn't be needed but it's belts & braces
        tv.setKeyListener(TextKeyListener.getInstance(false, Capitalize.NONE));
        // Both setTransform & keyboard type are required
        tv.setTransformationMethod(PasswordTransformationMethod.getInstance());
        // We also need to set the keyboard type - otherwise the password mask won't be applied
        handleKeyboardType(KEYBOARD_PASSWORD, false);
      }
    }
  }
Пример #15
0
  @Override
  public void propertyChanged(String key, Object oldValue, Object newValue, TiProxy proxy) {
    if (DBG) {
      Log.d(LCAT, "Property: " + key + " old: " + oldValue + " new: " + newValue);
    }
    if (key.equals("enabled")) {
      tv.setEnabled(TiConvert.toBoolean(newValue));
    } else if (key.equals("value")) {
      tv.setText((String) newValue);
    } else if (key.equals("color")) {
      tv.setTextColor(TiConvert.toColor((String) newValue));
    } else if (key.equals("passwordMask")) {
      if (TiConvert.toBoolean(newValue) == true) {
        // This shouldn't be needed but it's belts & braces
        tv.setKeyListener(TextKeyListener.getInstance(false, Capitalize.NONE));
        // Both setTransform & keyboard type are required
        tv.setTransformationMethod(PasswordTransformationMethod.getInstance());
        // We also need to set the keyboard type - otherwise the password mask won't be applied
        handleKeyboardType(KEYBOARD_PASSWORD, false);
      } else {
        handleKeyboardType(KEYBOARD_DEFAULT, false);
      }
    } else if (key.equals("hintText")) {
      tv.setHint((String) newValue);
    } else if (key.equals("textAlign") || key.equals("verticalAlign")) {
      String textAlign = null;
      String verticalAlign = null;
      if (key.equals("textAlign")) {
        textAlign = TiConvert.toString(newValue);
      }
      if (key.equals("verticalAlign")) {
        verticalAlign = TiConvert.toString(newValue);
      }
      handleTextAlign(textAlign, verticalAlign);
    } else if (key.equals("autocapitalization")) {

      // TODO Missing
      Capitalize autoCapValue = null;

      switch (TiConvert.toInt(newValue)) {
        case TEXT_AUTOCAPITALIZATION_NONE:
          autoCapValue = Capitalize.NONE;
          break;

        case TEXT_AUTOCAPITALIZATION_ALL:
          autoCapValue = Capitalize.CHARACTERS;
          break;

        case TEXT_AUTOCAPITALIZATION_SENTENCES:
          autoCapValue = Capitalize.SENTENCES;
          break;

        case TEXT_AUTOCAPITALIZATION_WORDS:
          autoCapValue = Capitalize.WORDS;
          break;

        default:
          Log.w(LCAT, "Unknown AutoCapitalization Value [" + TiConvert.toString(newValue) + "]");
          break;
      }

      if (null != autoCapValue) {
        tv.setKeyListener(TextKeyListener.getInstance(false, autoCapValue));
      }

    } else if (key.equals("keyboardType") || (key.equals("autocorrect"))) {
      TiDict d = proxy.getDynamicProperties();
      boolean autocorrect = false;
      if (d.containsKey("autocorrect")) {
        autocorrect = d.getBoolean("autocorrect");
      }

      handleKeyboardType(TiConvert.toInt(d, "keyboardType"), autocorrect);
    } else if (key.equals("returnKeyType")) {
      handleReturnKeyType(TiConvert.toInt(newValue));
    } else if (key.equals("font")) {
      TiUIHelper.styleText(tv, (TiDict) newValue);
    } else {
      super.propertyChanged(key, oldValue, newValue, proxy);
    }
  }