List of usage examples for android.widget AutoCompleteTextView AutoCompleteTextView
public AutoCompleteTextView(Context context)
From source file:au.com.domain.AccountsAutoCompleteTextView.java
private void init(Context context) { addView(mAccountsAutocomplete = new AutoCompleteTextView(context)); mAccountsAutocomplete.setImeOptions(EditorInfo.IME_ACTION_NEXT); mAccountsAutocomplete.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); if (TextUtils.isEmpty(getHint())) { setHint("Email"); }/*ww w . j a v a 2 s . c o m*/ // TODO Make this a custom attr (currently does nothing) mThreshold = mAccountsAutocomplete.getThreshold(); setAccountOptions(); mAccountsAutocomplete.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean b) { if (b && !isPermissionGranted()) { mAccountsAutocomplete.showDropDown(); } } }); mAccountsAutocomplete.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { String currentText = charSequence.toString(); if (!currentText.equalsIgnoreCase(getContext().getString(R.string.allow_accounts_suggestion))) { mCurrentText = charSequence.toString(); } } @Override public void afterTextChanged(Editable editable) { if (isErrorEnabled()) { setError(null); setErrorEnabled(false); } } }); }
From source file:com.tinfoil.sms.settings.UserKeySettings.java
public void exportKey(View view) { if (SMSUtility.isMediaWritable()) { phoneBook = new AutoCompleteTextView(this); List<String> contact = null; if (tc == null) { //Do in thread. tc = dba.getAllRows(DBAccessor.ALL); }/* ww w . jav a2s . c o m*/ if (tc != null) { if (contact == null) { contact = SMSUtility.contactDisplayMaker(tc); } } else { contact = null; } final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getBaseContext(), R.layout.auto_complete_list_item, contact); phoneBook.setAdapter(adapter); final AlertDialog.Builder popup_builder = new AlertDialog.Builder(this); popup_builder.setTitle(R.string.import_contacts_title).setCancelable(true).setView(phoneBook) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int which) { String[] contactInfo = SMSUtility.parseAutoComplete(phoneBook.getText().toString()); //String number = null; boolean invalid = false; if (contactInfo != null) { if (contactInfo[0] == null) { contactInfo[0] = contactInfo[1]; } final Number number = dba.getNumber(contactInfo[1]); if (number != null) { AlertDialog.Builder builder = new AlertDialog.Builder(UserKeySettings.this); LinearLayout linearLayout = new LinearLayout(UserKeySettings.this); linearLayout.setOrientation(LinearLayout.VERTICAL); final EditText sharedSecret1 = new EditText(UserKeySettings.this); sharedSecret1 .setHint(UserKeySettings.this.getString(R.string.shared_secret_hint_1)); sharedSecret1.setMaxLines(EditNumber.SHARED_INFO_MAX); sharedSecret1.setInputType(InputType.TYPE_CLASS_TEXT); linearLayout.addView(sharedSecret1); final EditText sharedSecret2 = new EditText(UserKeySettings.this); sharedSecret2 .setHint(UserKeySettings.this.getString(R.string.shared_secret_hint_2)); sharedSecret2.setMaxLines(EditNumber.SHARED_INFO_MAX); sharedSecret2.setInputType(InputType.TYPE_CLASS_TEXT); linearLayout.addView(sharedSecret2); builder.setMessage(UserKeySettings.this.getString(R.string.set_shared_secrets) + " " + contactInfo[0] + ", " + number.getNumber()) .setTitle(R.string.set_shared_secrets_title).setCancelable(true) .setPositiveButton(R.string.save, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { //Save the shared secrets String s1 = sharedSecret1.getText().toString(); String s2 = sharedSecret2.getText().toString(); if (SMSUtility.checksharedSecret(s1) && SMSUtility.checksharedSecret(s2)) { number.setSharedInfo1(s1); number.setSharedInfo2(s2); dba.updateNumberRow(number, number.getNumber(), number.getId()); number.setInitiator(true); dba.updateInitiator(number); //TODO add check for shared secrets String keyExchangeMessage = KeyExchange.sign(number, dba, SMSUtility.user); writeToFile(number.getNumber(), keyExchangeMessage); Toast.makeText(UserKeySettings.this, UserKeySettings.this .getString(R.string.written_path) + " " + path + "/" + number.getNumber() + "_" + file, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(UserKeySettings.this, R.string.invalid_secrets, Toast.LENGTH_LONG) .show(); } } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { //Cancel the key exchange Toast.makeText(UserKeySettings.this, R.string.key_exchange_cancelled, Toast.LENGTH_LONG).show(); } }); AlertDialog alert = builder.create(); alert.setView(linearLayout); alert.show(); } else { invalid = true; } } else { invalid = true; } if (invalid) { Toast.makeText(UserKeySettings.this, R.string.invalid_number_message, Toast.LENGTH_LONG).show(); } } }); popup_alert = popup_builder.create(); popup_alert.show(); //getExternalFilesDir(null); } }
From source file:pl.wasat.smarthma.ui.frags.base.BaseCollectionDetailsFragment.java
@NonNull private AutoCompleteTextView buildAutoCompleteTextView(Parameter param) { String[] AUTO_PHRASES = new String[] { "[]", "[,]", "{}", "{,}", "1", "}", "]", "," }; AutoCompleteTextView autoTextView = new AutoCompleteTextView(getActivity()); TableLayout.LayoutParams layoutParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT, 1f); layoutParams.setMargins(40, 10, 40, 10); autoTextView.setLayoutParams(layoutParams); autoTextView.setHint(String.format(getActivity().getString(R.string.set_), param.getName())); autoTextView.setHintTextColor(Color.GRAY); autoTextView.setBackgroundColor(Color.WHITE); autoTextView.setTextSize(14);//from w w w. j av a2 s . co m autoTextView = resolvePattern(autoTextView, param.getPattern()); autoTextView.addTextChangedListener(new EditTextViewInputWatcher(param)); autoTextView.setOnTouchListener(new EditTextViewInputWatcher(param)); autoTextView.setOnFocusChangeListener(new EditTextViewInputWatcher(param)); ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_dropdown_item_1line, AUTO_PHRASES); autoTextView.setAdapter(adapter); return autoTextView; }
From source file:at.jclehner.rxdroid.preferences.DrugNamePreference2.java
@Override protected View onCreateDialogView() { mEditText = new AutoCompleteTextView(getContext()); mAutoCompleteAdapter = new ArrayAdapter<String>(this.getContext(), android.R.layout.simple_dropdown_item_1line); System.out.println("Initializing autocomplete..."); mEditText.setThreshold(3);//from w w w .jav a 2 s .co m mEditText.setAdapter(mAutoCompleteAdapter); mEditText.addTextChangedListener(new TextWatcher() { private boolean shouldAutoComplete = true; @Override public void onTextChanged(CharSequence s, int start, int before, int count) { shouldAutoComplete = true; for (int position = 0; position < mAutoCompleteAdapter.getCount(); position++) { if (mAutoCompleteAdapter.getItem(position).equalsIgnoreCase(s.toString())) { shouldAutoComplete = false; break; } } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { if (shouldAutoComplete) { new DoAutoCompleteSearch().execute(s.toString()); } } }); // mEditText = new EditText(getContext()); mEditText.setText(getValue()); mEditText.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS); //mEditText.setSelectAllOnFocus(true); mEditText.addTextChangedListener(mWatcher); return mEditText; }
From source file:cz.maresmar.sfm.view.WithExtraFragment.java
@SuppressLint("ClickableViewAccessibility") @UiThread//from w w w . j a v a 2s .co m private void inflateExtraFormat() { // Remove old extras from UI mExtraLinearLayout.removeAllViewsInLayout(); mExtraUiBindings = new EditText[mExtrasFormat.size()]; final LinearLayout.LayoutParams matchWrapParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); // For each extra int index = 0; for (ExtraFormat extraFormat : mExtrasFormat) { //noinspection ConstantConditions TextInputLayout textInputLayout = new TextInputLayout(getContext()); textInputLayout.setLayoutParams(matchWrapParams); textInputLayout.setHint(extraFormat.name); // If edit text extra if (extraFormat.valuesList.length == 0) { TextInputEditText editText = new TextInputEditText(getContext()); editText.setLayoutParams(matchWrapParams); mExtraUiBindings[index] = editText; textInputLayout.addView(editText); } else { // If extra with dropdown // Prepare adapter for values ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), R.layout.support_simple_spinner_dropdown_item, extraFormat.valuesList); AutoCompleteTextView autoCompleteTextView = new AutoCompleteTextView(getContext()); autoCompleteTextView.setLayoutParams(matchWrapParams); autoCompleteTextView.setAdapter(adapter); // Some UI tweaks to make it look nice autoCompleteTextView.setKeyListener(null); autoCompleteTextView.setOnTouchListener((v, event) -> { ((AutoCompleteTextView) v).showDropDown(); return false; }); // Set default value autoCompleteTextView.setText(extraFormat.valuesList[0]); // setText disable other values so I have un-filter them adapter.getFilter().filter(null); mExtraUiBindings[index] = autoCompleteTextView; textInputLayout.addView(autoCompleteTextView); } mExtraLinearLayout.addView(textInputLayout); // Adds optimal extra description if (extraFormat.description != null) { TextView description = new TextView(getContext()); description.setText(extraFormat.description); TextViewCompat.setTextAppearance(description, R.style.StaticLabel); LinearLayout.LayoutParams descriptionLayoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); descriptionLayoutParams.setMargins(getResources().getDimensionPixelSize(R.dimen.content_margin), 0, 0, 0); description.setLayoutParams(descriptionLayoutParams); mExtraLinearLayout.addView(description); } index++; } }
From source file:com.cmput301w15t15.travelclaimsapp.activitys.EditClaimActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { final AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); switch (item.getItemId()) { case R.id.cmenu_dlist_delete: ClaimListController.removeDestination(destAdaptor.getItem(info.position), theClaim); destAdaptor.notifyDataSetChanged(); return true; case R.id.cmenu_dlist_edit: //show a dialog for editing destinations final EditText enterLocation = new EditText(this); final EditText enterReason = new EditText(this); enterLocation.setText(destAdaptor.getItem(info.position).getLocation()); enterReason.setText(destAdaptor.getItem(info.position).getReason()); enterLocation.setHint("Enter location"); enterReason.setHint("Enter reason"); LinearLayout linearLayout = new LinearLayout(this); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.addView(enterLocation); linearLayout.addView(enterReason); AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setView(linearLayout);//from ww w . ja v a2 s . c o m alert.setPositiveButton("Add", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { destAdaptor.getItem(info.position).setLocation(enterLocation.getText().toString()); destAdaptor.getItem(info.position).setReason(enterReason.getText().toString()); destAdaptor.notifyDataSetChanged(); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); alert.show(); return true; case R.id.cmenu_dlist_geolocation: adaptorPos = info.position; AlertDialog.Builder alertGl = new AlertDialog.Builder(this); alertGl.setPositiveButton("GPS", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (GeoLocationController.checkGPSEnabled()) { GeoLocationController.setDestinationGeoLocationGPS(destAdaptor.getItem(info.position)); destAdaptor.notifyDataSetChanged(); } } }); alertGl.setNegativeButton("Map", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //Open map view \ Intent intent = GeoLocationController.pickLocationIntent(EditClaimActivity.this); startActivityForResult(intent, GET_GEOLOCATION_CODE); } }); alertGl.show(); return true; case R.id.cmenu_delete_tag: ClaimListController.removeTag(theClaim, tagAdaptor.getItem(info.position)); tagAdaptor.notifyDataSetChanged(); return true; case R.id.cmenu_rename_tag: //create a Alert dialog for editing tag name final TextView enterTag = new AutoCompleteTextView(this); enterTag.setHint("Enter tag"); AlertDialog.Builder alertTag = new AlertDialog.Builder(this); alertTag.setView(enterTag); alertTag.setPositiveButton("Add", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { tagAdaptor.getItem(info.position).setName(enterTag.getText().toString()); tagAdaptor.notifyDataSetChanged(); } }); alertTag.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); alertTag.show(); return true; default: return super.onContextItemSelected(item); } }
From source file:com.secbro.qark.customintent.CreateCustomIntentActivity.java
private void createExtrasView() { LinearLayout topLayout = (LinearLayout) findViewById(R.id.extras_key_value_container); LinearLayout.LayoutParams llpTextView = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); llpTextView.setMargins(10, 20, 10, 10); // llp.setMargins(left, top, right, bottom); LinearLayout.LayoutParams llpEditText = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); llpEditText.setMargins(10, 20, 10, 10); // llp.setMargins(left, top, right, bottom); //key// www. ja v a2 s. c om LinearLayout keyLinearLayout = new LinearLayout(this); keyLinearLayout.setOrientation(LinearLayout.HORIZONTAL); TextView keyTextView = new TextView(this); keyTextView.setText(getResources().getString(R.string.intent_extras_key)); keyTextView.setLayoutParams(llpTextView); AutoCompleteTextView keyEditText = new AutoCompleteTextView(this); keyEditText.setLayoutParams(llpEditText); ArrayAdapter<String> adapter3 = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, getResources().getStringArray(R.array.intent_extras_array)); keyEditText.setAdapter(adapter3); keyEditText.setSelection(keyEditText.getText().length()); keyEditText.setTag("key_field"); keyLinearLayout.addView(keyTextView); keyLinearLayout.addView(keyEditText); //value LinearLayout valueLinearLayout = new LinearLayout(this); valueLinearLayout.setOrientation(LinearLayout.HORIZONTAL); TextView valueTextView = new TextView(this); valueTextView.setText(getResources().getString(R.string.intent_extras_value)); valueTextView.setLayoutParams(llpTextView); EditText valueEditText = new EditText(this); valueEditText.setTag("value_field"); valueEditText.setLayoutParams(llpEditText); valueLinearLayout.addView(valueTextView); valueLinearLayout.addView(valueEditText); topLayout.addView(keyLinearLayout); topLayout.addView(valueLinearLayout); }
From source file:com.tinfoil.sms.sms.SendMessageActivity.java
private void setupMessageViewUI() { //TODO fix this ConversationView.messageViewActive = true; /*/*from w w w . ja va 2 s. co m*/ * Create a list of messages sent between the user and the contact */ messageList = (ListView) this.findViewById(R.id.message_list); messageList.setVisibility(ListView.VISIBLE); //This allows for the loading to be cancelled /*this.dialog = ProgressDialog.show(this, "Loading Messages", "Please wait...", true, true, new OnCancelListener() { public void onCancel(DialogInterface dialog) { MessageView.this.dialog.dismiss(); MessageView.this.onBackPressed(); } });*/ runThread = new MessageLoader(selectedNumber, this, false, handler); //Set an action for when a user clicks on a message messageList.setOnItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { final int item_num = position; final AlertDialog.Builder popup_builder = new AlertDialog.Builder(SendMessageActivity.this); popup_builder.setTitle(contact_name) .setItems(SendMessageActivity.this.getResources().getStringArray(R.array.sms_options), new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int which) { final String[] messageValue = (String[]) messageList .getItemAtPosition(item_num); if (which == 0) { //option = Delete dba.deleteMessage(Long.valueOf(messageValue[3])); updateList(); } else if (which == 1) { copyText(messageValue[1]); } else if (which == 2) { //option = Forward message phoneBox = new AutoCompleteTextView( SendMessageActivity.this.getBaseContext()); List<String> contact = null; if (tc == null) { //TODO Do in thread. tc = dba.getAllRows(DBAccessor.ALL); } if (tc != null) { if (contact == null) { contact = SMSUtility.contactDisplayMaker(tc); } } else { contact = null; } final ArrayAdapter<String> adapter = new ArrayAdapter<String>( SendMessageActivity.this.getBaseContext(), R.layout.auto_complete_list_item, contact); phoneBox.setAdapter(adapter); final AlertDialog.Builder contact_builder = new AlertDialog.Builder( SendMessageActivity.this); contact_builder.setTitle(R.string.forward_title).setCancelable(true) .setView(phoneBox).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int which) { forward(messageValue[1]); } }); final AlertDialog contact_alert = contact_builder.create(); SendMessageActivity.this.popup_alert.cancel(); contact_alert.show(); } } }) .setCancelable(true); SendMessageActivity.this.popup_alert = popup_builder.create(); SendMessageActivity.this.popup_alert.show(); return false; } }); }