Example #1
0
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);
   AutoCompleteTextView autotext = (AutoCompleteTextView) findViewById(R.id.autotext);
   autotext.setInputType(InputType.TYPE_CLASS_TEXT);
   String[] arr = {"aa", "aab", "aac", "bb", "bc"};
   ArrayAdapter<String> arrayAdapter =
       new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arr);
   autotext.setAdapter(arrayAdapter);
 }
Example #2
0
  private void init(final Context context) {
    LayoutInflater mInflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mInflater.inflate(R.layout.jdb_expand_editext_layout, this);
    mProgressBar = (ProgressBar) findViewById(R.id.progress);
    mRightView = (ImageView) findViewById(R.id.icon_right);
    checkStatusOfIcon(mRightView, rightIconVisiable);
    mLeftView = (ImageView) findViewById(R.id.icon_left);
    checkStatusOfIcon(mLeftView, leftIconVisiable);
    mRightView.setOnClickListener(this);
    mTextView = (AutoCompleteTextView) findViewById(R.id.edittext);
    mTextView.setHint(this.hint);
    mTextView.setFocusableInTouchMode(enabled);
    if (this.password)
      mTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    mTextView.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {}

          @Override
          public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            if (withProgress) {
              if (mCanLoad) {
                if (charSequence.length() >= threshold) {
                  if (onEditCompleted != null)
                    onEditCompleted.startSearch(ExpandEditText.this, charSequence.toString());
                } else {
                  if (onEditCompleted != null) onEditCompleted.endSearch(ExpandEditText.this);
                }
              } else {
                mCanLoad = !mCanLoad;
              }
            } else {
              // 有内容显示
              if (charSequence.length() >= 1) mRightView.setVisibility(View.VISIBLE);
              else mRightView.setVisibility(View.GONE);
            }
          }

          @Override
          public void afterTextChanged(Editable editable) {}
        });
  }
Example #3
0
  // set up the search bar
  public void setUpSearchField() {
    final Button clearButton = (Button) findViewById(R.id.clear_search);
    clearButton.setVisibility(View.GONE);

    // create array containing all trail and bird names
    Set<String> keys = map.keySet();
    String[] trails = keys.toArray(new String[keys.size()]);
    String[] birdsAndTrails = new String[trails.length + TrailBirds.allBirds.length];
    for (int i = 0; i < trails.length; i++) {
      birdsAndTrails[i] = trails[i];
    }
    int k = trails.length;
    for (int j = 0; j < TrailBirds.allBirds.length; j++) {
      birdsAndTrails[k] = TrailBirds.allBirds[j];
      k++;
    }

    ArrayAdapter<String> adapter =
        new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, birdsAndTrails);
    final AutoCompleteTextView input = (AutoCompleteTextView) findViewById(R.id.search_text);
    input.setAdapter(adapter);
    input.setThreshold(1);
    input.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);

    // hide button, when field is empty
    input.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (input.getText().toString().equals("")) clearButton.setVisibility(View.GONE);
            else clearButton.setVisibility(View.VISIBLE);
          }

          @Override
          public void afterTextChanged(Editable s) {}
        });
    // perform search for selected suggestion
    input.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            performSearch(input.getText().toString());
            if (getCurrentFocus() != null) {
              InputMethodManager inputMethodManager =
                  (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
              inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
            }
          }
        });
    // perform search, hide keyboard when 'search' is clicked
    input.setOnEditorActionListener(
        new TextView.OnEditorActionListener() {
          @Override
          // perform search, and hide keyboard
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            performSearch(input.getText().toString());
            if (getCurrentFocus() != null) {
              InputMethodManager inputMethodManager =
                  (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
              inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
            }
            return false;
          }
        });
  }
  public void showSetBetDialog() {
    AlertDialog.Builder builder = new Builder(this);
    LayoutInflater infalInflater =
        (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    FrameLayout layout = (FrameLayout) infalInflater.inflate(R.layout.bet, null);

    final AutoCompleteTextView input =
        (AutoCompleteTextView) layout.findViewById(R.id.tv_bet_input);
    input.setInputType(InputType.TYPE_CLASS_NUMBER);

    LengthFilter filter = new LengthFilter(5);
    input.setFilters(new InputFilter[] {filter});
    input.setSelectAllOnFocus(true);
    input.setTextColor(Color.BLACK);
    input.setText("" + this.number);

    String[] betSuggestion = getResources().getStringArray(R.array.bet_suggestion);
    final ArrayAdapter<String> adapter =
        new ArrayAdapter<String>(this, R.layout.item_list_s, betSuggestion);
    adapter.setNotifyOnChange(true);
    input.setAdapter(adapter);
    input.setThreshold(1);
    input.setOnFocusChangeListener(
        new OnFocusChangeListener() {

          @Override
          public void onFocusChange(View v, boolean hasFocus) {
            if (input.isFocused()) {
              input.showDropDown();
            }
          }
        });

    input.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            if (input.isFocused()) {
              input.showDropDown();
            }
          }
        });

    builder.setView(layout);
    builder.setPositiveButton(
        getResources().getString(R.string.confirm_ok),
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
            int number = PasswordGeneratorActivity.this.number;
            try {
              number = Integer.parseInt(input.getText().toString());
            } catch (Exception e) {
              // TODO: handle exception
            }
            if (number < 4) number = 4;
            else if (number > 21) number = 21;
            setTextNumberCharacter(number);
          }
        });
    builder.setNegativeButton(getResources().getString(R.string.confirm_cancel), null);
    builder.setIcon(R.drawable.ic_launcher);
    builder.create().show();
  }
  private void setUpParseLoginAndSignup() {
    parseLogin.setVisibility(View.VISIBLE);

    if (config.isParseLoginEmailAsUsername()) {
      usernameField.setHint(R.string.com_parse_ui_email_input_hint);
      usernameField.setInputType(
          InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
    }

    if (config.getParseLoginButtonText() != null) {
      parseLoginButton.setText(config.getParseLoginButtonText());
    }

    parseLoginButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            String username = usernameField.getText().toString();
            String password = passwordField.getText().toString();

            if (username.length() == 0) {
              showToast(R.string.com_parse_ui_no_username_toast);
            } else if (password.length() == 0) {
              showToast(R.string.com_parse_ui_no_password_toast);
            } else {
              loadingStart(true);
              ParseUser.logInInBackground(
                  username,
                  password,
                  new LogInCallback() {
                    @Override
                    public void done(ParseUser user, ParseException e) {
                      if (isActivityDestroyed()) {
                        return;
                      }

                      if (user != null) {
                        loadingFinish();
                        loginSuccess();
                      } else {
                        loadingFinish();
                        if (e != null) {
                          debugLog(
                              getString(R.string.com_parse_ui_login_warning_parse_login_failed)
                                  + e.toString());
                          if (e.getCode() == ParseException.OBJECT_NOT_FOUND) {
                            if (config.getParseLoginInvalidCredentialsToastText() != null) {
                              showToast(config.getParseLoginInvalidCredentialsToastText());
                            } else {
                              showToast(
                                  R.string.com_parse_ui_parse_login_invalid_credentials_toast);
                            }
                            passwordField.selectAll();
                            passwordField.requestFocus();
                          } else {
                            showToast(R.string.com_parse_ui_parse_login_failed_unknown_toast);
                          }
                        }
                      }
                    }
                  });
            }
          }
        });

    if (config.getParseSignupButtonText() != null) {
      parseSignupButton.setText(config.getParseSignupButtonText());
    }

    parseSignupButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            String username = usernameField.getText().toString();
            String password = passwordField.getText().toString();

            loginFragmentListener.onSignUpClicked(username, password);
          }
        });

    if (config.getParseLoginHelpText() != null) {
      parseLoginHelpButton.setText(config.getParseLoginHelpText());
    }

    parseLoginHelpButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            loginFragmentListener.onLoginHelpClicked();
          }
        });
  }