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);
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations