Java Code Examples for android.widget.AutoCompleteTextView#setAdapter()
The following examples show how to use
android.widget.AutoCompleteTextView#setAdapter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrowserActivity.java From browser with GNU General Public License v2.0 | 6 votes |
/** * method to generate search suggestions for the AutoCompleteTextView from * previously searched URLs */ private void initializeSearchSuggestions(final AutoCompleteTextView getUrl) { getUrl.setThreshold(1); getUrl.setDropDownWidth(-1); getUrl.setDropDownAnchor(R.id.toolbar_layout); getUrl.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { } }); getUrl.setSelectAllOnFocus(true); mSearchAdapter = new SearchAdapter(mActivity, mDarkTheme, isIncognito()); getUrl.setAdapter(mSearchAdapter); }
Example 2
Source File: MainActivity.java From android with GNU General Public License v2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Configura el adapter que enlazará los datos con el control Spinner ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, elementos); autoSpinner = (AutoCompleteTextView) findViewById(R.id.autospinner); // Añade el Listener al control Spinner (está definido en la propia clase) autoSpinner.addTextChangedListener(this); // Enlaza el adapter con el control Spinner autoSpinner.setAdapter(adapter); seleccion = (TextView) findViewById(R.id.seleccion); }
Example 3
Source File: AutoCompleteActivity.java From coursera-android with MIT License | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); String[] mCountries = getResources().getStringArray(R.array.country_names); // Get a reference to the AutoCompleteTextView final AutoCompleteTextView textView = findViewById(R.id.autocomplete_country); // Create an ArrayAdapter containing country names ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.list_item, mCountries); // Set the adapter for the AutoCompleteTextView textView.setAdapter(adapter); // Display a Toast Message when the user clicks on an item in the AutoCompleteTextView textView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View view, int arg2, long arg3) { Toast.makeText(getApplicationContext(), getString(R.string.winner_is_string, arg0.getAdapter().getItem(arg2)), Toast.LENGTH_LONG).show(); textView.setText(""); } }); }
Example 4
Source File: AutoComplete2.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.autocomplete_2); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, AutoComplete1.COUNTRIES); AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.edit); textView.setAdapter(adapter); }
Example 5
Source File: GrantedPhonesEditableListAdapter.java From SimpleSmsRemote with MIT License | 5 votes |
@NonNull @Override public View getView(final int position, View convertView, @NonNull ViewGroup parent) { if (convertView == null) { LayoutInflater inflater = (LayoutInflater) getContext(). getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(LAYOUT_RES, parent, false); } String phone = phones.get(position); final AutoCompleteTextView phoneEditText = (AutoCompleteTextView) convertView.findViewById(R.id.edittext_phonenumber); ImageButton deleteButton = (ImageButton) convertView.findViewById(R.id.imageButton_delete); phoneEditText.setText(phone); if (phoneListAdapter != null) phoneEditText.setAdapter(phoneListAdapter); deleteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { removePhone(position); } }); return convertView; }
Example 6
Source File: MainActivity.java From android-play-places with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Construct a GeoDataClient for the Google Places API for Android. mGeoDataClient = Places.getGeoDataClient(this, null); setContentView(R.layout.activity_main); // Retrieve the AutoCompleteTextView that will display Place suggestions. mAutocompleteView = (AutoCompleteTextView) findViewById(R.id.autocomplete_places); // Register a listener that receives callbacks when a suggestion has been selected mAutocompleteView.setOnItemClickListener(mAutocompleteClickListener); // Retrieve the TextViews that will display details and attributions of the selected place. mPlaceDetailsText = (TextView) findViewById(R.id.place_details); mPlaceDetailsAttribution = (TextView) findViewById(R.id.place_attribution); // Set up the adapter that will retrieve suggestions from the Places Geo Data Client. mAdapter = new PlaceAutocompleteAdapter(this, mGeoDataClient, BOUNDS_GREATER_SYDNEY, null); mAutocompleteView.setAdapter(mAdapter); // Set up the 'clear text' button that clears the text in the autocomplete view Button clearButton = (Button) findViewById(R.id.button_clear); clearButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mAutocompleteView.setText(""); } }); }
Example 7
Source File: MarkerEditActivity.java From mytracks with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle bundle) { super.onCreate(bundle); trackId = getIntent().getLongExtra(EXTRA_TRACK_ID, -1L); markerId = getIntent().getLongExtra(EXTRA_MARKER_ID, -1L); trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, null); // Setup UI elements statisticsSection = findViewById(R.id.marker_edit_statistics_section); statisticsName = (EditText) findViewById(R.id.marker_edit_statistics_name); waypointSection = findViewById(R.id.marker_edit_waypoint_section); waypointName = (EditText) findViewById(R.id.marker_edit_waypoint_name); waypointMarkerType = (AutoCompleteTextView) findViewById(R.id.marker_edit_waypoint_marker_type); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( this, R.array.waypoint_types, android.R.layout.simple_dropdown_item_1line); waypointMarkerType.setAdapter(adapter); waypointDescription = (EditText) findViewById(R.id.marker_edit_waypoint_description); Button cancel = (Button) findViewById(R.id.marker_edit_cancel); cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { finish(); } }); done = (Button) findViewById(R.id.marker_edit_done); updateUiByMarkerId(); }
Example 8
Source File: ConnectActivity.java From Android-Remote with GNU General Public License v3.0 | 5 votes |
private void initializeUi() { setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); // Get the Layoutelements mBtnConnect = (Button) findViewById(R.id.btnConnect); mBtnConnect.setOnClickListener(oclConnect); mBtnConnect.requestFocus(); mBtnClementine = (ImageButton) findViewById(R.id.btnClementineIcon); mBtnClementine.setOnClickListener(oclClementine); // Setup the animation for the Clementine icon mAlphaDown = new AlphaAnimation(1.0f, 0.3f); mAlphaUp = new AlphaAnimation(0.3f, 1.0f); mAlphaDown.setDuration(ANIMATION_DURATION); mAlphaUp.setDuration(ANIMATION_DURATION); mAlphaDown.setFillAfter(true); mAlphaUp.setFillAfter(true); mAlphaUp.setAnimationListener(mAnimationListener); mAlphaDown.setAnimationListener(mAnimationListener); mAnimationCancel = false; // Ip and Autoconnect mEtIp = (AutoCompleteTextView) findViewById(R.id.etIp); mEtIp.setRawInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); mEtIp.setThreshold(3); // Get old ip and auto-connect from shared prefences mEtIp.setText(mSharedPref.getString(SharedPreferencesKeys.SP_KEY_IP, "")); mEtIp.setSelection(mEtIp.length()); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.select_dialog_item, mKnownIps.toArray(new String[0])); mEtIp.setAdapter(adapter); // Get the last auth code mAuthCode = mSharedPref.getInt(SharedPreferencesKeys.SP_LAST_AUTH_CODE, 0); }
Example 9
Source File: SelectOneTagValueFragment.java From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void setupAutoComplete(AutoCompleteTextView autoCompleteTextView) { Set<String> tagValues = OSMDataSet.tagValues(); String[] tagValuesArr = tagValues.toArray(new String[tagValues.size()]); ArrayAdapter<String> adapter = new ArrayAdapter<>(this.getActivity(), android.R.layout.simple_dropdown_item_1line, tagValuesArr); autoCompleteTextView.setAdapter(adapter); autoCompleteTextView.setThreshold(1); }
Example 10
Source File: AutoComplete1.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.autocomplete_1); 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); }
Example 11
Source File: SearchActivity.java From OpenHub with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_search, menu); MenuItem searchItem = menu.findItem(R.id.action_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); searchView.setOnQueryTextListener(this); searchView.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS); searchView.setQuery(mPresenter.getSearchModels().get(0).getQuery(), false); if (isInputMode) { MenuItemCompat.expandActionView(searchItem); } else { MenuItemCompat.collapseActionView(searchItem); } MenuItemCompat.setOnActionExpandListener(searchItem, this); AutoCompleteTextView autoCompleteTextView = searchView .findViewById(android.support.v7.appcompat.R.id.search_src_text); autoCompleteTextView.setThreshold(0); autoCompleteTextView.setAdapter(new ArrayAdapter<>(this, R.layout.layout_item_simple_list, mPresenter.getSearchRecordList())); autoCompleteTextView.setDropDownBackgroundDrawable(new ColorDrawable(ViewUtils.getWindowBackground(getActivity()))); autoCompleteTextView.setOnItemClickListener((parent, view, position, id) -> { onQueryTextSubmit(parent.getAdapter().getItem(position).toString()); }); return super.onCreateOptionsMenu(menu); }
Example 12
Source File: AutoCompleteDemo.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); AutoCompleteTextView view = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1); String[] values = new String[] { "Linux", "Ubuntu", "iPhone", "Android" }; ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, values); view.setAdapter(adapter); }
Example 13
Source File: TechnicolorFragment.java From upcKeygen with GNU General Public License v2.0 | 4 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_technicolor, container, false); loading = view.findViewById(R.id.loading_spinner); mainView = view.findViewById(R.id.main_view); final CheckBox freq24 = (CheckBox) view.findViewById(R.id.radio_24); final CheckBox freq5 = (CheckBox) view.findViewById(R.id.radio_5); final AutoCompleteTextView edit = (AutoCompleteTextView) view .findViewById(R.id.manual_autotext); final String[] routers = getResources().getStringArray( R.array.supported_routers); ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_dropdown_item_1line, routers); edit.setAdapter(adapter); edit.setThreshold(1); edit.requestFocus(); final InputFilter filterSSID = new InputFilter() { public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { for (int i = start; i < end; i++) { if (!Character.isLetterOrDigit(source.charAt(i)) && source.charAt(i) != '-' && source.charAt(i) != '_' && source.charAt(i) != ' ') { return ""; } } return null; } }; final InputFilter lengthFilter = new InputFilter.LengthFilter(8); //Filter to 10 characters edit.setFilters(new InputFilter[]{filterSSID, lengthFilter}); edit.setImeOptions(EditorInfo.IME_ACTION_DONE); Button calc = (Button) view.findViewById(R.id.bt_calc); calc.setOnClickListener(new View.OnClickListener() { @TargetApi(Build.VERSION_CODES.HONEYCOMB) public void onClick(View v) { String ssid = "UPC" + edit.getText().toString().trim(); if (!freq24.isChecked() && !freq5.isChecked()) { freq24.setChecked(true); freq5.setChecked(true); } int mode = (freq24.isChecked() ? 1 : 0) | (freq5.isChecked() ? 2 : 0); KeygenMatcherTask matcher = new KeygenMatcherTask(ssid, mode); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) { matcher.execute(); } else { matcher.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } }); return view; }
Example 14
Source File: AccountViewFragment.java From Zom-Android-XMPP with GNU General Public License v3.0 | 4 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.account_activity, container, false); mIsNewAccount = getIntent().getBooleanExtra("register", false); mEditUserAccount = (EditText) view.findViewById(R.id.edtName); mEditUserAccount.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { checkUserChanged(); } }); mEditPass = (EditText) view.findViewById(R.id.edtPass); mEditPassConfirm = (EditText) view.findViewById(R.id.edtPassConfirm); mSpinnerDomains = (AutoCompleteTextView) view.findViewById(R.id.spinnerDomains); if (mIsNewAccount) { mEditPassConfirm.setVisibility(View.VISIBLE); mSpinnerDomains.setVisibility(View.VISIBLE); mEditUserAccount.setHint(R.string.account_setup_new_username); ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_dropdown_item_1line, Server.getServersText(getActivity())); mSpinnerDomains.setAdapter(adapter); } // mRememberPass = (CheckBox) findViewById(R.id.rememberPassword); // mUseTor = (CheckBox) findViewById(R.id.useTor); mBtnSignIn = (Button) view.findViewById(R.id.btnSignIn); if (mIsNewAccount) mBtnSignIn.setText(R.string.btn_create_new_account); //mBtnAdvanced = (Button) findViewById(R.id.btnAdvanced); // mBtnQrDisplay = (Button) findViewById(R.id.btnQR); /* mRememberPass.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { updateWidgetState(); } });*/ return view; }
Example 15
Source File: LogcatActivity.java From javaide with GNU General Public License v3.0 | 4 votes |
private void showAddFilterDialog(final FilterAdapter filterAdapter) { // show a popup to add a new filter text LayoutInflater inflater = getLayoutInflater(); @SuppressLint("InflateParams") final AutoCompleteTextView editText = (AutoCompleteTextView) inflater.inflate(R.layout.dialog_new_filter, null, false); // show suggestions as the user types List<String> suggestions = new ArrayList<>(mSearchSuggestionsSet); SortedFilterArrayAdapter<String> suggestionAdapter = new SortedFilterArrayAdapter<>( this, R.layout.list_item_dropdown, suggestions); editText.setAdapter(suggestionAdapter); final MaterialDialog alertDialog = new MaterialDialog.Builder(this) .title(R.string.add_filter) .positiveText(android.R.string.ok) .onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { handleNewFilterText(editText.getText().toString(), filterAdapter); dialog.dismiss(); } }) .negativeText(android.R.string.cancel) .customView(editText, true) .build(); // when 'Done' is clicked (i.e. enter button), do the same as when "OK" is clicked editText.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { // dismiss soft keyboard handleNewFilterText(editText.getText().toString(), filterAdapter); alertDialog.dismiss(); return true; } return false; } }); alertDialog.show(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(editText, 0); }
Example 16
Source File: SearchPlaceOnMapActivity.java From Airbnb-Android-Google-Map-View with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search_place_on_map); getSupportActionBar().setTitle("Search Places"); SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); fabAdd= (FloatingActionButton) findViewById(R.id.fab_add); fabAdd.setOnClickListener(this); mAutocompleteView = (AutoCompleteTextView) findViewById(R.id.googleplacesearch); mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this, 0 /* clientId */, this) .addApi(Places.GEO_DATA_API) .build(); mAdapter = new PlaceAutocompleteAdapter(this, R.layout.google_places_search_items, mGoogleApiClient, null, null); //TODO:In order to Restrict search to India uncomment this and comment the above line /* mAdapter = new PlaceAutocompleteAdapter(this, R.layout.google_places_search_items, mGoogleApiClient, BOUNDS_GREATER_INDIA, null); */ mAutocompleteView.setAdapter(mAdapter); mAutocompleteView.setOnItemClickListener(mAutocompleteClickListener); mAutocompleteView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { final int DRAWABLE_LEFT = 0; final int DRAWABLE_TOP = 1; final int DRAWABLE_RIGHT = 2; final int DRAWABLE_BOTTOM = 3; if (event.getAction() == MotionEvent.ACTION_UP) { if (event.getRawX() >= (mAutocompleteView.getRight() - mAutocompleteView.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) { mAutocompleteView.setText(""); return true; } } if (event.getRawX() <= (mAutocompleteView.getCompoundDrawables()[DRAWABLE_LEFT].getBounds().width())) { Intent i = new Intent(SearchPlaceOnMapActivity.this, MainActivity.class); startActivity(i); finish(); return true; } return false; } }); }
Example 17
Source File: DialogHelper.java From matlog with GNU General Public License v3.0 | 4 votes |
public static void showFilterDialogForRecording(final Context context, final String queryFilterText, final String logLevelText, final List<String> filterQuerySuggestions, final Callback<FilterQueryWithLevel> callback) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); @SuppressLint("InflateParams") View filterView = inflater.inflate(R.layout.dialog_recording_filter, null, false); // add suggestions to autocompletetextview final AutoCompleteTextView autoCompleteTextView = filterView.findViewById(android.R.id.text1); autoCompleteTextView.setText(queryFilterText); SortedFilterArrayAdapter<String> suggestionAdapter = new SortedFilterArrayAdapter<>( context, R.layout.list_item_dropdown, filterQuerySuggestions); autoCompleteTextView.setAdapter(suggestionAdapter); // set values on spinner to be the log levels final Spinner spinner = filterView.findViewById(R.id.spinner); // put the word "default" after whatever the default log level is CharSequence[] logLevels = context.getResources().getStringArray(R.array.log_levels); String defaultLogLevel = Character.toString(PreferenceHelper.getDefaultLogLevelPreference(context)); int index = ArrayUtil.indexOf(context.getResources().getStringArray(R.array.log_levels_values), defaultLogLevel); logLevels[index] = logLevels[index].toString() + " " + context.getString(R.string.default_in_parens); ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>( context, android.R.layout.simple_spinner_item, logLevels); adapter.setDropDownViewResource(R.layout.list_item_dropdown); spinner.setAdapter(adapter); // in case the user has changed it, choose the pre-selected log level spinner.setSelection(ArrayUtil.indexOf(context.getResources().getStringArray(R.array.log_levels_values), logLevelText)); // create alertdialog for the "Filter..." button new MaterialDialog.Builder(context) .title(R.string.title_filter) .customView(filterView, true) .negativeText(android.R.string.cancel) .positiveText(android.R.string.ok) .onPositive((dialog, which) -> { int logLevelIdx = spinner.getSelectedItemPosition(); String[] logLevelValues = context.getResources().getStringArray(R.array.log_levels_values); String logLevelValue = logLevelValues[logLevelIdx]; String filterQuery = autoCompleteTextView.getText().toString(); callback.onCallback(new FilterQueryWithLevel(filterQuery, logLevelValue)); }) .show(); }
Example 18
Source File: LogcatActivity.java From matlog with GNU General Public License v3.0 | 4 votes |
private void showAddFilterDialog(final FilterAdapter filterAdapter) { // show a popup to add a new filter text LayoutInflater inflater = getLayoutInflater(); @SuppressLint("InflateParams") final AutoCompleteTextView editText = (AutoCompleteTextView) inflater.inflate(R.layout.dialog_new_filter, null, false); // show suggestions as the user types List<String> suggestions = new ArrayList<>(mSearchSuggestionsSet); SortedFilterArrayAdapter<String> suggestionAdapter = new SortedFilterArrayAdapter<>( this, R.layout.list_item_dropdown, suggestions); editText.setAdapter(suggestionAdapter); final MaterialDialog alertDialog = new MaterialDialog.Builder(this) .title(R.string.add_filter) .positiveText(android.R.string.ok) .onPositive((dialog, which) -> { handleNewFilterText(editText.getText().toString(), filterAdapter); dialog.dismiss(); }) .negativeText(android.R.string.cancel) .customView(editText, true) .build(); // when 'Done' is clicked (i.e. enter button), do the same as when "OK" is clicked editText.setOnEditorActionListener((v, actionId, event) -> { if (actionId == EditorInfo.IME_ACTION_DONE) { // dismiss soft keyboard handleNewFilterText(editText.getText().toString(), filterAdapter); alertDialog.dismiss(); return true; } return false; }); alertDialog.show(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(editText, 0); }
Example 19
Source File: DownloadManager.java From Dashchan with Apache License 2.0 | 4 votes |
@SuppressLint("InflateParams") public DownloadDialog(Context context, DialogCallback callback, String chanName, String boardName, String threadNumber, String threadTitle, boolean allowDetailedFileName, boolean allowOriginalName) { File root = Preferences.getDownloadDirectory(); this.context = context; this.callback = callback; this.chanName = chanName; this.boardName = boardName; this.threadNumber = threadNumber; inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); View view = LayoutInflater.from(context).inflate(R.layout.dialog_download_choice, null); RadioGroup radioGroup = view.findViewById(R.id.download_choice); radioGroup.check(R.id.download_common); radioGroup.setOnCheckedChangeListener(this); ((RadioButton) view.findViewById(R.id.download_common)).setText(context .getString(R.string.text_download_to_format, root.getName())); detailNameCheckBox = view.findViewById(R.id.download_detail_name); originalNameCheckBox = view.findViewById(R.id.download_original_name); if (chanName == null && boardName == null && threadNumber == null) { allowDetailedFileName = false; } if (allowDetailedFileName) { detailNameCheckBox.setChecked(Preferences.isDownloadDetailName()); } else { detailNameCheckBox.setVisibility(View.GONE); } if (allowOriginalName) { originalNameCheckBox.setChecked(Preferences.isDownloadOriginalName()); } else { originalNameCheckBox.setVisibility(View.GONE); } AutoCompleteTextView editText = view.findViewById(android.R.id.text1); if (!allowDetailedFileName && !allowOriginalName) { ((ViewGroup.MarginLayoutParams) editText.getLayoutParams()).topMargin = 0; } if (threadNumber != null) { String chanTitle = ChanConfiguration.get(chanName).getTitle(); if (threadTitle != null) { threadTitle = StringUtils.escapeFile(StringUtils.cutIfLongerToLine(threadTitle, 50, false), false); } String text = Preferences.getSubdir(chanName, chanTitle, boardName, threadNumber, threadTitle); editText.setText(text); editText.setSelection(text.length()); if (StringUtils.isEmpty(text)) { text = Preferences.formatSubdir(Preferences.DEFAULT_SUBDIR_PATTERN, chanName, chanTitle, boardName, threadNumber, threadTitle); } editText.setHint(text); } editText.setEnabled(false); editText.setOnEditorActionListener(this); editText.setOnItemClickListener(this); this.editText = editText; dropDownRunnable = this.editText::showDropDown; adapter = new DialogAdapter(root, () -> { if (DownloadDialog.this.editText.isEnabled()) { refreshDropDownContents(); } }); editText.setAdapter(adapter); dialog = new AlertDialog.Builder(context).setTitle(R.string.text_download_title).setView(view) .setNegativeButton(android.R.string.cancel, null) .setPositiveButton(android.R.string.ok, this).create(); dialog.setOnDismissListener(d -> adapter.shutdown()); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); dialog.show(); }
Example 20
Source File: LogcatActivity.java From java-n-IDE-for-Android with Apache License 2.0 | 4 votes |
private void showAddFilterDialog(final FilterAdapter filterAdapter) { // show a popup to add a new filter text LayoutInflater inflater = getLayoutInflater(); @SuppressLint("InflateParams") final AutoCompleteTextView editText = (AutoCompleteTextView) inflater.inflate(R.layout.dialog_new_filter, null, false); // show suggestions as the user types List<String> suggestions = new ArrayList<>(mSearchSuggestionsSet); SortedFilterArrayAdapter<String> suggestionAdapter = new SortedFilterArrayAdapter<>( this, R.layout.list_item_dropdown, suggestions); editText.setAdapter(suggestionAdapter); final MaterialDialog alertDialog = new MaterialDialog.Builder(this) .title(R.string.add_filter) .positiveText(android.R.string.ok) .onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { handleNewFilterText(editText.getText().toString(), filterAdapter); dialog.dismiss(); } }) .negativeText(android.R.string.cancel) .customView(editText, true) .build(); // when 'Done' is clicked (i.e. enter button), do the same as when "OK" is clicked editText.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { // dismiss soft keyboard handleNewFilterText(editText.getText().toString(), filterAdapter); alertDialog.dismiss(); return true; } return false; } }); alertDialog.show(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(editText, 0); }