Ejemplo n.º 1
0
  private void init() {
    strings = new ArrayList<String>();
    values = new ArrayList<Integer>();

    setOrientation(LinearLayout.VERTICAL);

    sizeET = new EditText(getContext());
    sizeET.setRawInputType(InputType.TYPE_CLASS_NUMBER);
    sizeET.addTextChangedListener(
        new TextWatcher() {
          public void afterTextChanged(Editable s) {}

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

          public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (updated) changed();
          }
        });

    radioGroup = new RadioGroup(getContext());
    radioGroup.setOnCheckedChangeListener(
        new RadioGroup.OnCheckedChangeListener() {
          public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (updated) changed();
          }
        });

    addView(sizeET);
    addView(radioGroup);
  }
  @SuppressWarnings({"UnusedDeclaration"})
  public NumberPicker(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);
    setOrientation(VERTICAL);
    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.number_picker, this, true);
    mHandler = new Handler();
    InputFilter inputFilter = new NumberPickerInputFilter();
    mNumberInputFilter = new NumberRangeKeyListener();
    mIncrementButton = (NumberPickerButton) findViewById(R.id.increment);
    mIncrementButton.setOnClickListener(this);
    mIncrementButton.setOnLongClickListener(this);
    mIncrementButton.setNumberPicker(this);
    mDecrementButton = (NumberPickerButton) findViewById(R.id.decrement);
    mDecrementButton.setOnClickListener(this);
    mDecrementButton.setOnLongClickListener(this);
    mDecrementButton.setNumberPicker(this);

    mText = (EditText) findViewById(R.id.timepicker_input);
    mText.setOnFocusChangeListener(this);
    mText.setFilters(new InputFilter[] {inputFilter});
    mText.setRawInputType(InputType.TYPE_CLASS_NUMBER);

    if (!isEnabled()) {
      setEnabled(false);
    }

    mStart = DEFAULT_MIN;
    mEnd = DEFAULT_MAX;
  }
Ejemplo n.º 3
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.addPreferencesFromResource(R.layout.layout_five_settings_activity);

    PreferenceScreen screen = this.getPreferenceScreen();

    ListPreference idList = new ListPreference(this);
    idList.setTitle(R.string.config_identifiers_title);
    idList.setDialogTitle(R.string.config_identifiers_title);
    idList.setKey("config_five_identifier");

    String[] identifiers = IdentifiersManager.fetchIdentifiers(this);

    idList.setEntries(identifiers);
    idList.setEntryValues(identifiers);

    screen.addPreference(idList);

    EditTextPreference editPreference =
        (EditTextPreference) screen.findPreference("config_five_one");
    EditText field = editPreference.getEditText();
    field.setRawInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);

    editPreference = (EditTextPreference) screen.findPreference("config_five_two");
    field = editPreference.getEditText();
    field.setRawInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);

    editPreference = (EditTextPreference) screen.findPreference("config_five_three");
    field = editPreference.getEditText();
    field.setRawInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);

    editPreference = (EditTextPreference) screen.findPreference("config_five_four");
    field = editPreference.getEditText();
    field.setRawInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);

    editPreference = (EditTextPreference) screen.findPreference("config_five_five");
    field = editPreference.getEditText();
    field.setRawInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
  }
Ejemplo n.º 4
0
  @Override
  protected AlertDialog.Builder getInputDialog() throws IllegalStateException {
    if (round.hasAnyWins()) {
      throw new IllegalStateException(getString(R.string.cannot_set_bet_after_wins));
    }

    final EditText betInput = new EditText(this);
    betInput.setRawInputType(InputType.TYPE_CLASS_NUMBER);

    return new AlertDialog.Builder(this)
        .setTitle(selectedPlayerRound.getPlayer().toString())
        .setMessage(getString(R.string.bets))
        .setView(betInput)
        .setPositiveButton(getString(R.string.ok), getDoMakeBetClick(betInput))
        .setNegativeButton(getString(R.string.cancel), null);
  }
Ejemplo n.º 5
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.add_repo);

    // Check to see if extras were passed to the intent. In that case, edit the repository
    if (getIntent().getExtras() != null) {
      Bundle rec_bundle = getIntent().getExtras();

      // Get the repository to edit
      edit_repo = rec_bundle.getLong("editRepo", -1);

      // If the repository id is valid, set the activity to edit mode
      if (edit_repo >= 0) {
        edit_mode = true;
        this.setTitle(R.string.add_repo_edit_title);
      }
    }

    encrypt_helper =
        EncryptionHelper.getInstance("DEADBEEF".toCharArray(), new byte[] {'L', 'O', 'L'});
    db_helper = DatabaseHelper.getInstance(this);

    repo_name = (EditText) findViewById(R.id.repo_name);

    username = (EditText) findViewById(R.id.add_repo_username);
    password = (EditText) findViewById(R.id.add_repo_password);
    password.setRawInputType(
        InputType.TYPE_TEXT_VARIATION_PASSWORD); // Make this into a password box
    password.setTransformationMethod(new PasswordTransformationMethod());

    key = (EditText) findViewById(R.id.add_repo_key);

    url = (EditText) findViewById(R.id.add_repo_url);

    repo_types = (Spinner) findViewById(R.id.repo_type_spinner);
    repo_auth = (Spinner) findViewById(R.id.repo_authentication_spinner);

    // Create a new list for storing the services the program can handle
    ArrayList<String> services = new ArrayList<String>();

    // Add the services supported by the program
    services.add("HGWeb Served");
    services.add("Google Code");
    services.add("Bitbucket");
    services.add("CodePlex");

    // Create a new adapter with the list of services
    AddRepoAdapter type_adapter = new AddRepoAdapter(this, services);

    // Add the adapter to the spinner that stores the list of services
    repo_types.setAdapter(type_adapter);

    // Create a new list to store authentication types
    ArrayList<String> authentication = new ArrayList<String>();

    // Add the authentication types
    authentication.add(0, "None");
    authentication.add(Mercury.AuthenticationTypes.HTTP, "HTTP");
    authentication.add(Mercury.AuthenticationTypes.TOKEN, "Token");
    // authentication.add(SSH, "SSH");

    // Create a new adapter based on the authentication types
    AddRepoAdapter auth_adapter = new AddRepoAdapter(this, authentication);

    // Add the adapter to the authentication spinner
    repo_auth.setAdapter(auth_adapter);

    // Create a listener that triggers whenever the authentication type is changed
    repo_auth.setOnItemSelectedListener(
        new OnItemSelectedListener() {

          @Override
          public void onItemSelected(AdapterView<?> adapterview, View view, int position, long id) {
            // If anything other than "None" is selected, enable the username and password or ssh
            // fields
            if (position > Mercury.AuthenticationTypes.NONE) {
              if (position == Mercury.AuthenticationTypes.TOKEN) {
                if (username.getVisibility() != View.GONE
                    || password.getVisibility() != View.GONE) {
                  // Hide both the username and password if they're not already gone
                  username.setVisibility(View.GONE);
                  password.setVisibility(View.GONE);
                }

                // Make the key text box visible
                key.setVisibility(View.VISIBLE);

                // Enable the controls on the key text box
                key.setEnabled(true);
                key.setFocusable(true);
                key.setClickable(true);
                key.setFocusableInTouchMode(true);

              } else {
                // Make the username and password visible
                username.setVisibility(View.VISIBLE);
                password.setVisibility(View.VISIBLE);

                key.setVisibility(View.GONE);
                key.setText("");

                // Re-enable the username and password text boxes
                username.setEnabled(true);
                username.setCursorVisible(true);
                username.setClickable(true);
                username.setFocusable(true);
                username.setFocusableInTouchMode(true);

                password.setEnabled(true);
                password.setCursorVisible(true);
                password.setClickable(true);
                password.setFocusable(true);
                password.setFocusableInTouchMode(true);
              }
              // Otherwise, disable all fields from user interaction
            } else {
              key.setEnabled(false);
              key.setFocusable(false);
              key.setClickable(false);

              username.setEnabled(false);
              username.setFocusable(false);
              username.setClickable(false);

              password.setEnabled(false);
              password.setClickable(false);
              password.setFocusable(false);
            }
          }

          @Override
          public void onNothingSelected(AdapterView<?> arg0) {
            // Will never be called on a spinner
          }
        });

    Button save_button = (Button) findViewById(R.id.add_repo_save);
    Button discard = (Button) findViewById(R.id.add_repo_discard);

    discard.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            killActivity(Activity.RESULT_CANCELED);
          }
        });

    save_button.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // Check the user input
            if (checkInput()) {
              // Attempt to save the repository
              if (saveRepository())
                // If successful go back to the list
                killActivity(Activity.RESULT_OK);
            }
          }
        });

    if (edit_mode) {
      // Get the information for this repository
      Beans.RepositoryBean repo_info = db_helper.getRepository(edit_repo, null);

      // Set the information in the activity
      repo_name.setText(repo_info.getTitle());
      url.setText(repo_info.getUrl());

      username.setText(repo_info.getUsername());
      password.setText(repo_info.getPassword());
      key.setText(repo_info.getSSHKey());

      repo_types.setSelection(repo_info.getType());
      repo_auth.setSelection(repo_info.getAuthentication());
    }
  }
Ejemplo n.º 6
0
 public View getView(final Context context) throws UnsupportedOperationException {
   EditText input = (EditText) super.getView(context);
   input.setRawInputType(Configuration.KEYBOARD_12KEY);
   input.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
   return input;
 }
    @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;
    }
Ejemplo n.º 8
0
  @Override
  public View onCreateView(
      LayoutInflater aInflater, ViewGroup aContainer, Bundle aSavedInstanceState) {
    View aView = aInflater.inflate(R.layout.task_page_item, aContainer, false);

    // Get controls
    mTaskHeaderView = (TextView) aView.findViewById(R.id.taskHeaderTextView);
    mTaskStatusView = (TextView) aView.findViewById(R.id.taskStatusTextView);
    mTaskViewAnimator = (ViewAnimator) aView.findViewById(R.id.taskViewAnimator);
    mRetryButton = (Button) aView.findViewById(R.id.retryButton);
    mTaskWebView = (TaskWebView) aView.findViewById(R.id.taskWebView);
    mAnswerTextView = (TextView) aView.findViewById(R.id.answerTextView);
    mBottomLayout = (RelativeLayout) aView.findViewById(R.id.bottomLayout);
    mAnswerEditText = (EditText) aView.findViewById(R.id.answerEditText);
    mAnswerButton = (Button) aView.findViewById(R.id.answerButton);

    // Set listeners
    mRetryButton.setOnClickListener(this);
    mAnswerButton.setOnClickListener(this);

    // Initialize controls
    mTaskHeaderView.setText(
        getString(R.string.task_header, mTask.getCategory(), mTask.getId() + 1));
    updateStatus();

    mTaskWebView.setInitialScale(30);

    WebSettings aSettings = mTaskWebView.getSettings();
    aSettings.setBuiltInZoomControls(true);
    aSettings.setSupportZoom(true);
    aSettings.setUseWideViewPort(true);

    downloadImage();

    switch (getCalculateActivity().getMode()) {
      case CalculateActivity.MODE_VIEW_TASK:
        mAnswerTextView.setVisibility(View.GONE);
        break;
      case CalculateActivity.MODE_TEST_TASK:
      case CalculateActivity.MODE_VERIFICATION:
        mAnswerTextView.setVisibility(View.GONE);
        mAnswerButton.setVisibility(View.GONE);
        break;
      case CalculateActivity.MODE_VIEW_RESULT:
        mBottomLayout.setVisibility(View.GONE);
        mAnswerTextView.setText(getString(R.string.answer, mTask.getAnswer()));
        break;
    }

    if (mTask.getCategory().charAt(0) == 'A') {
      mAnswerEditText.setRawInputType(
          InputType.TYPE_CLASS_NUMBER
              | InputType.TYPE_NUMBER_FLAG_SIGNED
              | InputType.TYPE_NUMBER_FLAG_DECIMAL);

      mAnswerEditText.setSingleLine(true);
    } else if (mTask.getCategory().charAt(0) == 'B') {
      if (GlobalData.selectedLesson.getId().equals("russian")) {
        mAnswerEditText.setRawInputType(
            InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL);
      } else {
        mAnswerEditText.setRawInputType(
            InputType.TYPE_CLASS_NUMBER
                | InputType.TYPE_NUMBER_FLAG_SIGNED
                | InputType.TYPE_NUMBER_FLAG_DECIMAL);
      }

      mAnswerEditText.setSingleLine(true);
    } else if (mTask.getCategory().charAt(0) == 'C') {
      mAnswerEditText.setRawInputType(
          InputType.TYPE_CLASS_TEXT
              | InputType.TYPE_TEXT_VARIATION_NORMAL
              | InputType.TYPE_TEXT_FLAG_MULTI_LINE);

      mAnswerEditText.setSingleLine(false);
    } else {
      Log.e(
          TAG,
          "Invalid category \""
              + mTask.getCategory()
              + "\" for task № "
              + String.valueOf(mTask.getId()));
    }

    return aView;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.addedit_scorecard_layout);
    Intent intent = getIntent();

    lRowID = intent.getLongExtra("RowID", 0);
    Integer iSeasonID = intent.getIntExtra("SeasonID", 0);

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    String sBowlersName = sharedPreferences.getString("BowlersName", "Not Entered");
    TextView tvBName = (TextView) findViewById(R.id.tvBName);
    tvBName.setText("Name: " + sBowlersName);

    String sBowlingDate = intent.getStringExtra("BowlingDate");
    btnDate = (Button) findViewById(R.id.btnDate);
    btnDate.setText(sBowlingDate);

    Integer iScore1 = intent.getIntExtra("Score1", 0);
    evScore1 = (EditText) findViewById(R.id.editTextScore1);
    evScore1.setRawInputType(Configuration.KEYBOARD_QWERTY);
    ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
        .showSoftInput(evScore1, InputMethodManager.SHOW_FORCED);
    evScore1.requestFocus();
    if (iScore1 != 0) {
      evScore1.setText(iScore1.toString());
    }

    Integer iScore2 = intent.getIntExtra("Score2", 0);
    evScore2 = (EditText) findViewById(R.id.editTextScore2);
    if (iScore2 != 0) {
      evScore2.setText(iScore2.toString());
    }

    Integer iScore3 = intent.getIntExtra("Score3", 0);
    evScore3 = (EditText) findViewById(R.id.editTextScore3);
    if (iScore3 != 0) {
      evScore3.setText(iScore3.toString());
    }

    Integer iTotalValue = intent.getIntExtra("Total", 0);
    tvTotal = (TextView) findViewById(R.id.tvTotalValue);
    tvTotal.setText(iTotalValue.toString());

    Integer iAvgValue = intent.getIntExtra("Average", 0);
    tvAverage = (TextView) findViewById(R.id.tvAverageValue);
    tvAverage.setText(iAvgValue.toString());
    //
    setupScoreChanges();
    setupSaveButton();
    setupCancelButton();
    setupDeleteButton();
    // get the current date
    final Calendar c = Calendar.getInstance();
    mYear = c.get(Calendar.YEAR);
    mMonth = c.get(Calendar.MONTH);
    mDay = c.get(Calendar.DAY_OF_MONTH);
    if (lRowID == 0) {
      String sMonth = Integer.toString(mMonth + 1);
      if (sMonth.length() == 1) sMonth = "0" + sMonth;
      String sDay = Integer.toString(mDay);
      if (sDay.length() == 1) sDay = "0" + sDay;
      //
      String sDate = Integer.toString(mYear) + "-" + sMonth + "-" + sDay;
      btnDate.setText(sDate);
    }
  }