Search in sources :

Example 56 with AutoCompleteTextView

use of android.widget.AutoCompleteTextView in project SeriesGuide by UweTrottmann.

the class SearchActivity method setupViews.

private void setupViews(boolean mayShowKeyboard) {
    ButterKnife.bind(this);
    clearButton.setVisibility(View.GONE);
    clearButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            searchView.setText(null);
            searchView.requestFocus();
        }
    });
    searchView.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) {
            boolean isEmptyText = TextUtils.isEmpty(s);
            triggerLocalSearch(isEmptyText ? "" : s.toString());
            clearButton.setVisibility(isEmptyText ? View.GONE : View.VISIBLE);
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    searchView.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH || (event != null && event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
                triggerTvdbSearch();
                return true;
            }
            return false;
        }
    });
    // manually retrieve the auto complete view popup background to override the theme
    TypedValue outValue = new TypedValue();
    getTheme().resolveAttribute(android.R.attr.autoCompleteTextViewStyle, outValue, true);
    int[] attributes = new int[] { android.R.attr.popupBackground };
    TypedArray a = getTheme().obtainStyledAttributes(outValue.data, attributes);
    if (a.hasValue(0)) {
        searchView.setDropDownBackgroundDrawable(a.getDrawable(0));
    }
    a.recycle();
    // setup search history (only used by TVDb search)
    searchHistory = new SearchHistory(this, SearchSettings.KEY_SUFFIX_THETVDB);
    searchHistoryAdapter = new ArrayAdapter<>(this, SeriesGuidePreferences.THEME == R.style.Theme_SeriesGuide_Light ? R.layout.item_dropdown_light : R.layout.item_dropdown, searchHistory.getSearchHistory());
    searchView.setThreshold(1);
    searchView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ((AutoCompleteTextView) v).showDropDown();
        }
    });
    searchView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            triggerTvdbSearch();
        }
    });
    // set in code as XML is overridden
    searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchView.setInputType(EditorInfo.TYPE_CLASS_TEXT);
    // drop-down is auto-shown on config change, ensure it is hidden when recreating views
    searchView.dismissDropDown();
    TabStripAdapter tabsAdapter = new TabStripAdapter(getSupportFragmentManager(), this, viewPager, tabs);
    tabs.setOnPageChangeListener(pageChangeListener);
    tabs.setOnTabClickListener(new SlidingTabLayout.OnTabClickListener() {

        @Override
        public void onTabClick(int position) {
            if (viewPager.getCurrentItem() == position) {
                EventBus.getDefault().post(new TabClickEvent(position));
            }
        }
    });
    tabsAdapter.addTab(R.string.shows, ShowSearchFragment.class, null);
    tabsAdapter.addTab(R.string.episodes, EpisodeSearchFragment.class, null);
    tabsAdapter.addTab(R.string.action_shows_add, TvdbAddFragment.class, null);
    if (TraktCredentials.get(this).hasCredentials()) {
        addTraktTab(tabsAdapter, R.string.recommended, TraktAddFragment.TYPE_RECOMMENDED);
        addTraktTab(tabsAdapter, R.string.watched_shows, TraktAddFragment.TYPE_WATCHED);
        addTraktTab(tabsAdapter, R.string.shows_collection, TraktAddFragment.TYPE_COLLECTION);
        addTraktTab(tabsAdapter, R.string.watchlist, TraktAddFragment.TYPE_WATCHLIST);
    }
    tabsAdapter.notifyTabsChanged();
    // set default tab
    if (getIntent() != null && getIntent().getExtras() != null) {
        int defaultTab = getIntent().getExtras().getInt(EXTRA_DEFAULT_TAB);
        if (defaultTab < tabsAdapter.getCount()) {
            viewPager.setCurrentItem(defaultTab);
        }
        if (mayShowKeyboard && (defaultTab == TAB_POSITION_SHOWS || defaultTab == TAB_POSITION_EPISODES)) {
            Utils.showSoftKeyboardOnSearchView(this, searchView);
        }
    } else if (mayShowKeyboard) {
        // also show keyboard when showing first tab (added tab)
        Utils.showSoftKeyboardOnSearchView(this, searchView);
    }
}
Also used : SlidingTabLayout(com.battlelancer.seriesguide.widgets.SlidingTabLayout) BindView(butterknife.BindView) View(android.view.View) AdapterView(android.widget.AdapterView) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) KeyEvent(android.view.KeyEvent) TabStripAdapter(com.battlelancer.seriesguide.adapters.TabStripAdapter) TypedArray(android.content.res.TypedArray) TabClickEvent(com.battlelancer.seriesguide.util.TabClickEvent) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) SearchHistory(com.battlelancer.seriesguide.util.SearchHistory) TypedValue(android.util.TypedValue)

Example 57 with AutoCompleteTextView

use of android.widget.AutoCompleteTextView in project android_frameworks_base by ParanoidAndroid.

the class AutoCompleteTextViewActivityLandscape method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.auto_complete_list);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, COUNTRIES);
    AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.edit);
    textView.setAdapter(adapter);
}
Also used : ArrayAdapter(android.widget.ArrayAdapter) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 58 with AutoCompleteTextView

use of android.widget.AutoCompleteTextView in project android_frameworks_base by ParanoidAndroid.

the class AutoCompleteTextViewActivityPortrait method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.auto_complete_list);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, COUNTRIES);
    AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.edit);
    textView.setAdapter(adapter);
}
Also used : ArrayAdapter(android.widget.ArrayAdapter) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 59 with AutoCompleteTextView

use of android.widget.AutoCompleteTextView in project android_frameworks_base by ParanoidAndroid.

the class PopupWindowVisibility method onCreate.

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.popup_window_visibility);
    mFrame = findViewById(R.id.frame);
    mHide = (Button) findViewById(R.id.hide);
    mHide.setOnClickListener(this);
    mShow = (Button) findViewById(R.id.show);
    mShow.setOnClickListener(this);
    Spinner spinner = (Spinner) findViewById(R.id.spinner);
    ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mStrings);
    spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(spinnerAdapter);
    ArrayAdapter<String> autoAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, COUNTRIES);
    AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.auto);
    textView.setAdapter(autoAdapter);
}
Also used : Spinner(android.widget.Spinner) ArrayAdapter(android.widget.ArrayAdapter) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 60 with AutoCompleteTextView

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

the class PopupWindowVisibility method onCreate.

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.popup_window_visibility);
    mFrame = findViewById(R.id.frame);
    mHide = (Button) findViewById(R.id.hide);
    mHide.setOnClickListener(this);
    mShow = (Button) findViewById(R.id.show);
    mShow.setOnClickListener(this);
    Spinner spinner = (Spinner) findViewById(R.id.spinner);
    ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mStrings);
    spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(spinnerAdapter);
    ArrayAdapter<String> autoAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, COUNTRIES);
    AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.auto);
    textView.setAdapter(autoAdapter);
}
Also used : Spinner(android.widget.Spinner) ArrayAdapter(android.widget.ArrayAdapter) AutoCompleteTextView(android.widget.AutoCompleteTextView)

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