Search in sources :

Example 41 with AutoCompleteTextView

use of android.widget.AutoCompleteTextView in project double-espresso by JakeWharton.

the class SendActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.send_activity);
    EditText editText = (EditText) findViewById(R.id.enter_data_edit_text);
    editText.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View view, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                EditText editText = (EditText) view;
                TextView responseText = (TextView) findViewById(R.id.enter_data_response_text);
                responseText.setText(editText.getText());
                return true;
            } else {
                return false;
            }
        }
    });
    final EditText searchBox = (EditText) findViewById(R.id.search_box);
    searchBox.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                TextView result = (TextView) findViewById(R.id.search_result);
                result.setText(getString(R.string.searching_for_label) + " " + v.getText());
                result.setVisibility(View.VISIBLE);
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(searchBox.getWindowToken(), 0);
                return true;
            }
            return false;
        }
    });
    AutoCompleteTextView autoComplete = (AutoCompleteTextView) findViewById(R.id.auto_complete_text_view);
    String[] completions = new String[] { "Pacific Ocean", "Atlantic Ocean", "Indian Ocean", "Southern Ocean", "Artic Ocean", "Mediterranean Sea", "Caribbean Sea", "South China Sea", "Bering Sea", "Gulf of Mexico", "Okhotsk Sea", "East China Sea", "Hudson Bay", "Japan Sea", "Andaman Sea", "North Sea", "Red Sea", "Baltic Sea" };
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, completions);
    autoComplete.setAdapter(adapter);
}
Also used : EditText(android.widget.EditText) InputMethodManager(android.view.inputmethod.InputMethodManager) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) View(android.view.View) KeyEvent(android.view.KeyEvent) OnKeyListener(android.view.View.OnKeyListener) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) ArrayAdapter(android.widget.ArrayAdapter) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 42 with AutoCompleteTextView

use of android.widget.AutoCompleteTextView in project KeepScore by nolanlawson.

the class DialogHelper method showPlayerNameDialog.

public static void showPlayerNameDialog(final Context context, final int titleResId, final String startingValue, final int newPlayerNumber, final Callback<String> onResult) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final AutoCompleteTextView editText = (AutoCompleteTextView) inflater.inflate(R.layout.change_player_name, null, false);
    editText.setHint(context.getString(R.string.text_player) + " " + (newPlayerNumber + 1));
    editText.setText(StringUtil.nullToEmpty(startingValue));
    new AlertDialog.Builder(context).setTitle(titleResId).setView(editText).setCancelable(true).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            String newName = StringUtil.nullToEmpty(editText.getText().toString());
            onResult.onCallback(newName);
            dialog.dismiss();
        }
    }).setNegativeButton(android.R.string.cancel, null).show();
    // fetch suggestions in the background to avoid jankiness
    new AsyncTask<Void, Void, List<String>>() {

        @Override
        protected List<String> doInBackground(Void... params) {
            return PlayerNameHelper.getPlayerNameSuggestions(context);
        }

        @Override
        protected void onPostExecute(List<String> result) {
            super.onPostExecute(result);
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, R.layout.simple_dropdown_small, result);
            editText.setAdapter(adapter);
        }
    }.execute((Void) null);
}
Also used : DialogInterface(android.content.DialogInterface) ExpressionBuilder(de.congrace.exp4j.ExpressionBuilder) LayoutInflater(android.view.LayoutInflater) ArrayList(java.util.ArrayList) List(java.util.List) ArrayAdapter(android.widget.ArrayAdapter) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 43 with AutoCompleteTextView

use of android.widget.AutoCompleteTextView in project FlatUI by eluleci.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // converts the default values to dp to be compatible with different screen sizes
    FlatUI.initDefaultValues(this);
    // Default theme should be set before content view is added
    FlatUI.setDefaultTheme(APP_THEME);
    setContentView(R.layout.activity_main);
    // Getting action bar background and applying it
    getSupportActionBar().setBackgroundDrawable(FlatUI.getActionBarDrawable(this, APP_THEME, false, 2));
    // titles
    flatTextViews.add((FlatTextView) findViewById(R.id.title_edittexts));
    flatTextViews.add((FlatTextView) findViewById(R.id.title_seekbar));
    flatTextViews.add((FlatTextView) findViewById(R.id.title_buttons));
    flatTextViews.add((FlatTextView) findViewById(R.id.title_buttons_shape));
    flatTextViews.add((FlatTextView) findViewById(R.id.title_buttons_text_appearance));
    flatTextViews.add((FlatTextView) findViewById(R.id.title_buttons_touch_effect));
    flatTextViews.add((FlatTextView) findViewById(R.id.title_checkbox));
    flatTextViews.add((FlatTextView) findViewById(R.id.title_checkbox_enabled));
    flatTextViews.add((FlatTextView) findViewById(R.id.title_checkbox_disabled));
    flatTextViews.add((FlatTextView) findViewById(R.id.title_radiobutton));
    flatTextViews.add((FlatTextView) findViewById(R.id.title_radiobutton_enabled));
    flatTextViews.add((FlatTextView) findViewById(R.id.title_radiobutton_disabled));
    flatTextViews.add((FlatTextView) findViewById(R.id.title_toggle_button));
    flatTextViews.add((FlatTextView) findViewById(R.id.title_toggle_enabled));
    flatTextViews.add((FlatTextView) findViewById(R.id.title_toggle_disabled));
    flatTextViews.add((FlatTextView) findViewById(R.id.title_themes));
    flatTextViews.add((FlatTextView) findViewById(R.id.title_themes_note));
    // edit texts
    flatEditTexts.add((FlatEditText) findViewById(R.id.edittext_flat));
    flatEditTexts.add((FlatEditText) findViewById(R.id.edittext_box));
    flatEditTexts.add((FlatEditText) findViewById(R.id.edittext_transparentbox));
    flatEditTexts.add((FlatEditText) findViewById(R.id.edittext_transparent));
    // buttons
    flatButtons.add((FlatButton) findViewById(R.id.button_block));
    flatButtons.add((FlatButton) findViewById(R.id.button_flat));
    flatButtons.add((FlatButton) findViewById(R.id.button_light));
    flatButtons.add((FlatButton) findViewById(R.id.button_white));
    flatButtons.add((FlatButton) findViewById(R.id.button_dark_text));
    flatButtons.add((FlatButton) findViewById(R.id.button_ease));
    flatButtons.add((FlatButton) findViewById(R.id.button_ripple));
    // check boxes
    flatCheckBoxes.add((FlatCheckBox) findViewById(R.id.checkbox_unchecked_enabled));
    flatCheckBoxes.add((FlatCheckBox) findViewById(R.id.checkbox_checked_enabled));
    flatCheckBoxes.add((FlatCheckBox) findViewById(R.id.checkbox_unchecked_disabled));
    flatCheckBoxes.add((FlatCheckBox) findViewById(R.id.checkbox_checked_disabled));
    // radio buttons
    flatRadioButtons.add((FlatRadioButton) findViewById(R.id.radio_unchecked_enabled));
    flatRadioButtons.add((FlatRadioButton) findViewById(R.id.radio_unchecked_disabled));
    flatRadioButtons.add((FlatRadioButton) findViewById(R.id.radio_checked_disabled));
    radioCheckedEnabled = (FlatRadioButton) findViewById(R.id.radio_checked_enabled);
    flatRadioButtons.add(radioCheckedEnabled);
    radioCheckedEnabled.setChecked(true);
    // toggle buttons
    flatToggleButtons.add((FlatToggleButton) findViewById(R.id.toggle_unchecked_enabled));
    flatToggleButtons.add((FlatToggleButton) findViewById(R.id.toggle_checked_enabled));
    flatToggleButtons.add((FlatToggleButton) findViewById(R.id.toggle_unchecked_disabled));
    flatToggleButtons.add((FlatToggleButton) findViewById(R.id.toggle_checked_disabled));
    flatSeekBar = (FlatSeekBar) findViewById(R.id.seekbar);
    flatSeekBar.setProgress(30);
    flatSeekBar.setSecondaryProgress(40);
    /**
     * This part is an example of spinner usage. You can change the theme of this spinner by
     * editing the layout files spinner_button and simple_flat_list_item.
     */
    Spinner spinner = (Spinner) findViewById(R.id.themes_spinner);
    // Create an ArrayAdapter using the string array and a custom spinner layout
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.themes_array, R.layout.spinner_button);
    // Specify the layout to use when the list of choices appears
    adapter.setDropDownViewResource(R.layout.simple_flat_list_item);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // preventing the spinner to change the theme on start
            if (!isSpinnerSelectedBefore) {
                isSpinnerSelectedBefore = true;
                return;
            }
            int themeReference = APP_THEME;
            switch(position) {
                case 0:
                    themeReference = FlatUI.SAND;
                    break;
                case 1:
                    themeReference = FlatUI.ORANGE;
                    break;
                case 2:
                    themeReference = FlatUI.CANDY;
                    break;
                case 3:
                    themeReference = FlatUI.BLOSSOM;
                    break;
                case 4:
                    themeReference = FlatUI.GRAPE;
                    break;
                case 5:
                    themeReference = FlatUI.DEEP;
                    break;
                case 6:
                    themeReference = FlatUI.SKY;
                    break;
                case 7:
                    themeReference = FlatUI.GRASS;
                    break;
                case 8:
                    themeReference = FlatUI.DARK;
                    break;
                case 9:
                    themeReference = FlatUI.SNOW;
                    break;
                case 10:
                    themeReference = FlatUI.SEA;
                    break;
                case 11:
                    themeReference = FlatUI.BLOOD;
                    break;
            }
            changeTheme(themeReference);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    /**
     * Autocomplete textview. You can change the EditText color via theme but
     * you need to set a layout for the rows as shown below. This is the same
     * row that is used in the spinner example.
     */
    AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
    String[] themes = getResources().getStringArray(R.array.themes_array);
    ArrayAdapter acAdapter = new ArrayAdapter(this, R.layout.simple_flat_list_item, themes);
    actv.setAdapter(acAdapter);
}
Also used : Spinner(android.widget.Spinner) AutoCompleteTextView(android.widget.AutoCompleteTextView) FlatTextView(com.cengalabs.flatui.views.FlatTextView) View(android.view.View) AdapterView(android.widget.AdapterView) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 44 with AutoCompleteTextView

use of android.widget.AutoCompleteTextView in project Android-CollapsibleSearchMenu by johnkil.

the class CollapsibleMenuUtils method addSearchMenuItem.

/**
 * Adding collapsible search menu item to the menu.
 *
 * @param menu
 * @param isLightTheme - true if use light them for ActionBar, else false
 * @return menu item
 */
public static MenuItem addSearchMenuItem(Menu menu, boolean isLightTheme, final OnQueryTextListener onQueryChangeListener) {
    final MenuItem menuItem = menu.add(Menu.NONE, R.id.collapsible_search_menu_item, Menu.NONE, R.string.search_go);
    menuItem.setIcon(isLightTheme ? R.drawable.ic_action_search_holo_light : R.drawable.ic_action_search_holo_dark).setActionView(isLightTheme ? R.layout.search_view_holo_light : R.layout.search_view_holo_dark).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    final View searchView = menuItem.getActionView();
    final AutoCompleteTextView editText = (AutoCompleteTextView) searchView.findViewById(R.id.search_src_text);
    final TextWatcher textWatcher = new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            onQueryChangeListener.onQueryTextChange(charSequence.toString());
        }

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    };
    final TextView.OnEditorActionListener onEditorActionListener = new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_SEARCH || keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                onQueryChangeListener.onQueryTextSubmit(textView.getText().toString());
                return true;
            }
            return false;
        }
    };
    menuItem.setOnActionExpandListener(new OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            editText.addTextChangedListener(textWatcher);
            editText.setOnEditorActionListener(onEditorActionListener);
            editText.requestFocus();
            showKeyboard(editText);
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            editText.setText(null);
            editText.removeTextChangedListener(textWatcher);
            // editText.clearFocus();
            hideKeyboard(editText);
            return true;
        }
    });
    final View searchPlate = searchView.findViewById(R.id.search_plate);
    editText.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, final boolean hasFocus) {
            searchView.post(new Runnable() {

                public void run() {
                    searchPlate.getBackground().setState(hasFocus ? new int[] { android.R.attr.state_focused } : new int[] { android.R.attr.state_empty });
                    searchView.invalidate();
                }
            });
        }
    });
    final ImageView closeBtn = (ImageView) menuItem.getActionView().findViewById(R.id.search_close_btn);
    closeBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!TextUtils.isEmpty(editText.getText())) {
                editText.setText(null);
            } else {
                menuItem.collapseActionView();
            }
        }
    });
    return menuItem;
}
Also used : OnFocusChangeListener(android.view.View.OnFocusChangeListener) MenuItem(com.actionbarsherlock.view.MenuItem) ImageView(android.widget.ImageView) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) View(android.view.View) KeyEvent(android.view.KeyEvent) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) OnActionExpandListener(com.actionbarsherlock.view.MenuItem.OnActionExpandListener) OnClickListener(android.view.View.OnClickListener) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 45 with AutoCompleteTextView

use of android.widget.AutoCompleteTextView in project robolectric by robolectric.

the class ShadowAutoCompleteTextViewTest method shouldInvokeFilter.

@Test
public void shouldInvokeFilter() {
    shadowMainLooper().pause();
    AutoCompleteTextView view = new AutoCompleteTextView(ApplicationProvider.getApplicationContext());
    view.setAdapter(adapter);
    view.setText("Foo");
    assertThat(adapter.getCount()).isEqualTo(2);
}
Also used : AutoCompleteTextView(android.widget.AutoCompleteTextView) Test(org.junit.Test)

Aggregations

AutoCompleteTextView (android.widget.AutoCompleteTextView)106 View (android.view.View)62 TextView (android.widget.TextView)44 ArrayAdapter (android.widget.ArrayAdapter)38 Button (android.widget.Button)27 EditText (android.widget.EditText)21 OnClickListener (android.view.View.OnClickListener)20 KeyEvent (android.view.KeyEvent)19 AdapterView (android.widget.AdapterView)17 Intent (android.content.Intent)16 ImageView (android.widget.ImageView)14 Editable (android.text.Editable)10 TextWatcher (android.text.TextWatcher)10 ArrayList (java.util.ArrayList)9 Dialog (android.app.Dialog)8 ListView (android.widget.ListView)8 Spinner (android.widget.Spinner)8 DialogInterface (android.content.DialogInterface)7 InputMethodManager (android.view.inputmethod.InputMethodManager)7 SuppressLint (android.annotation.SuppressLint)6