List of usage examples for android.widget TextView setInputType
public void setInputType(int type)
From source file:Main.java
/** Suppress virtual keyboard until user's first tap */ public static void suppressVirtualKeyboard(final TextView editor) { final int inputType = editor.getInputType(); editor.setInputType(InputType.TYPE_NULL); editor.setOnTouchListener((v, event) -> { editor.setInputType(inputType);/*from w w w. ja va2 s . co m*/ editor.setOnTouchListener(null); return false; }); }
From source file:com.jefftharris.passwdsafe.lib.view.GuiUtils.java
/** * Set whether the view shows a visible password */// w w w . ja v a2 s .c o m public static void setPasswordVisible(TextView tv, boolean visible, Context ctx) { int pos = tv.getSelectionStart(); tv.setInputType(visible ? INPUT_TEXT_PASSWORD_VISIBLE : INPUT_TEXT_PASSWORD); // Reset monospace as the input type change resets to default monospace // font TypefaceUtils.setMonospace(tv, ctx); if (tv instanceof EditText) { // Keep selection location after the type change ((EditText) tv).setSelection(pos); } }
From source file:eu.geopaparazzi.core.maptools.FeaturePageAdapter.java
private TextView getEditView(final Feature feature, final String fieldName, EDataType type, String value) { final TextView editView; switch (type) { case DATE:/*from w ww. j a v a 2 s .com*/ editView = new TextView(context); editView.setInputType(InputType.TYPE_CLASS_DATETIME); editView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { FeaturePageAdapter.this.openDatePicker((EditText) view); } }); if (value == null || value.equals("")) { value = "____-__-__"; } break; default: editView = new EditText(context); break; } editView.setText(value); switch (type) { case DOUBLE: case FLOAT: editView.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); break; case PHONE: editView.setInputType(InputType.TYPE_CLASS_PHONE); break; case DATE: editView.setInputType(InputType.TYPE_CLASS_DATETIME); editView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { FeaturePageAdapter.this.openDatePicker((TextView) view); } }); break; case INTEGER: editView.setInputType(InputType.TYPE_CLASS_NUMBER); break; default: break; } editView.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { // ignore } public void beforeTextChanged(CharSequence s, int start, int count, int after) { // ignore } public void afterTextChanged(Editable s) { String text = editView.getText().toString(); feature.setAttribute(fieldName, text); } }); return editView; }
From source file:net.henryco.opalette.application.MainActivity.java
@Override public void setResultBitmap(Bitmap bitmap) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); ImageView imageView = new ImageView(this); imageView.setImageBitmap(bitmap);/* w ww . j a v a 2 s .com*/ String name = GodConfig.genDefaultImgFileName(); new OPallAlertDialog().title("").content(imageView) .positive(getResources().getString(R.string.save), () -> { View v = new LinearLayout(this); OPallViewInjector.inject(this, new OPallViewInjector<AppMainProto>(v, R.layout.textline) { @Override protected void onInject(AppMainProto context, View view) { TextView imageNameLine = (TextView) view.findViewById(R.id.lineText); imageNameLine.setInputType(InputType.TYPE_CLASS_TEXT); imageNameLine.setText(name); new OPallAlertDialog().title(getResources().getString(R.string.save_as)).content(v) .positive(getResources().getString(R.string.save), () -> { Utils.saveBitmapAction(bitmap, imageNameLine.getText().toString(), context.getActivityContext()); createSaveSuccessNotification(context.getActivityContext(), name); }).negative(getResources().getString(R.string.cancel)) .show(getSupportFragmentManager(), "Bitmap save"); } }); }) .negative(getResources().getString(R.string.share), () -> Utils.shareBitmapAction(bitmap, name, this, preferences.getBoolean(GodConfig.PREF_KEY_SAVE_AFTER, false), () -> createSaveSuccessNotification(this, name))) .neutral(getResources().getString(R.string.cancel)) .show(getSupportFragmentManager(), "Bitmap preview"); }
From source file:export.UploadManager.java
private void askUsernamePassword(final Uploader l, boolean showPassword) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setTitle(l.getName());/*from w w w .jav a 2s . c o m*/ // Get the layout inflater LayoutInflater inflater = activity.getLayoutInflater(); final View view = inflater.inflate(R.layout.userpass, null); final CheckBox cb = (CheckBox) view.findViewById(R.id.showpass); final TextView tv1 = (TextView) view.findViewById(R.id.username); final TextView tv2 = (TextView) view.findViewById(R.id.password_input); String authConfigStr = l.getAuthConfig(); final JSONObject authConfig = newObj(authConfigStr); String username = authConfig.optString("username", ""); String password = authConfig.optString("password", ""); tv1.setText(username); tv2.setText(password); cb.setChecked(showPassword); tv2.setInputType(InputType.TYPE_CLASS_TEXT | (showPassword ? 0 : InputType.TYPE_TEXT_VARIATION_PASSWORD)); cb.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { tv2.setInputType( InputType.TYPE_CLASS_TEXT | (isChecked ? 0 : InputType.TYPE_TEXT_VARIATION_PASSWORD)); } }); // Inflate and set the layout for the dialog // Pass null as the parent view because its going in the dialog layout builder.setView(view); builder.setPositiveButton("OK", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { authConfig.put("username", tv1.getText()); authConfig.put("password", tv2.getText()); } catch (JSONException e) { e.printStackTrace(); } testUserPass(l, authConfig, cb.isChecked()); } }); builder.setNeutralButton("Skip", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { handleAuthComplete(l, Status.SKIP); } }); builder.setNegativeButton("Cancel", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { handleAuthComplete(l, Status.SKIP); } }); final AlertDialog dialog = builder.create(); dialog.show(); }
From source file:org.runnerup.export.UploadManager.java
private void askUsernamePassword(final Uploader l, boolean showPassword) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setTitle(l.getName());//from w w w . j a v a2 s. c o m // Get the layout inflater LayoutInflater inflater = activity.getLayoutInflater(); final View view = inflater.inflate(R.layout.userpass, null); final CheckBox cb = (CheckBox) view.findViewById(R.id.showpass); final TextView tv1 = (TextView) view.findViewById(R.id.username); final TextView tv2 = (TextView) view.findViewById(R.id.password_input); String authConfigStr = l.getAuthConfig(); final JSONObject authConfig = newObj(authConfigStr); String username = authConfig.optString("username", ""); String password = authConfig.optString("password", ""); tv1.setText(username); tv2.setText(password); cb.setChecked(showPassword); tv2.setInputType(InputType.TYPE_CLASS_TEXT | (showPassword ? 0 : InputType.TYPE_TEXT_VARIATION_PASSWORD)); cb.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { tv2.setInputType( InputType.TYPE_CLASS_TEXT | (isChecked ? 0 : InputType.TYPE_TEXT_VARIATION_PASSWORD)); } }); // Inflate and set the layout for the dialog // Pass null as the parent view because its going in the dialog layout builder.setView(view); builder.setPositiveButton(getResources().getString(R.string.ok), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { authConfig.put("username", tv1.getText()); authConfig.put("password", tv2.getText()); } catch (JSONException e) { e.printStackTrace(); } testUserPass(l, authConfig, cb.isChecked()); } }); builder.setNeutralButton("Skip", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { handleAuthComplete(l, Status.SKIP); } }); builder.setNegativeButton(getResources().getString(R.string.cancel), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { handleAuthComplete(l, Status.SKIP); } }); final AlertDialog dialog = builder.create(); dialog.show(); }
From source file:com.geecko.QuickLyric.fragment.LyricsViewFragment.java
private void startEditTagsMode() { ImageButton editButton = (ImageButton) getActivity().findViewById(R.id.edit_tags_btn); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { editButton.setImageResource(R.drawable.ic_edit_anim); ((Animatable) editButton.getDrawable()).start(); } else/* w w w . jav a 2 s. c om*/ editButton.setImageResource(R.drawable.ic_done); ((DrawerLayout) ((MainActivity) getActivity()).drawer) .setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); mRefreshLayout.setEnabled(false); getActivity().findViewById(R.id.refresh_fab).setEnabled(false); ((RefreshIcon) getActivity().findViewById(R.id.refresh_fab)).hide(); ((Toolbar) getActivity().findViewById(R.id.toolbar)).getMenu().clear(); TextSwitcher textSwitcher = ((TextSwitcher) getActivity().findViewById(R.id.switcher)); EditText songTV = (EditText) getActivity().findViewById(R.id.song); TextView artistTV = ((TextView) getActivity().findViewById(R.id.artist)); EditText newLyrics = (EditText) getActivity().findViewById(R.id.edit_lyrics); newLyrics.setTypeface(LyricsTextFactory.FontCache.get("light", getActivity())); newLyrics.setText(((TextView) textSwitcher.getCurrentView()).getText(), TextView.BufferType.EDITABLE); textSwitcher.setVisibility(View.GONE); newLyrics.setVisibility(View.VISIBLE); songTV.setInputType(InputType.TYPE_CLASS_TEXT); artistTV.setInputType(InputType.TYPE_CLASS_TEXT); songTV.setBackgroundResource(R.drawable.abc_textfield_search_material); artistTV.setBackgroundResource(R.drawable.abc_textfield_search_material); if (songTV.requestFocus()) { InputMethodManager imm = (InputMethodManager) getActivity().getApplicationContext() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.SHOW_IMPLICIT); } }
From source file:org.runnerup.export.SyncManager.java
private void askUsernamePassword(final Synchronizer sync, boolean showPassword) { AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setTitle(sync.getName());/*from w w w.java 2 s .c o m*/ final View view = View.inflate(mActivity, R.layout.userpass, null); final CheckBox cb = (CheckBox) view.findViewById(R.id.showpass); final TextView tv1 = (TextView) view.findViewById(R.id.username); final TextView tv2 = (TextView) view.findViewById(R.id.password_input); final TextView tvAuthNotice = (TextView) view.findViewById(R.id.textViewAuthNotice); String authConfigStr = sync.getAuthConfig(); final JSONObject authConfig = newObj(authConfigStr); String username = authConfig.optString("username", ""); String password = authConfig.optString("password", ""); tv1.setText(username); tv2.setText(password); cb.setChecked(showPassword); tv2.setInputType(InputType.TYPE_CLASS_TEXT | (showPassword ? 0 : InputType.TYPE_TEXT_VARIATION_PASSWORD)); cb.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { tv2.setInputType( InputType.TYPE_CLASS_TEXT | (isChecked ? 0 : InputType.TYPE_TEXT_VARIATION_PASSWORD)); } }); if (sync.getAuthNotice() != null) { tvAuthNotice.setVisibility(View.VISIBLE); tvAuthNotice.setText(sync.getAuthNotice()); } else { tvAuthNotice.setVisibility(View.GONE); } // Inflate and set the layout for the dialog // Pass null as the parent view because its going in the dialog layout builder.setView(view); builder.setPositiveButton(getResources().getString(R.string.OK), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { authConfig.put("username", tv1.getText()); authConfig.put("password", tv2.getText()); } catch (JSONException e) { e.printStackTrace(); } testUserPass(sync, authConfig, cb.isChecked()); } }); builder.setNeutralButton("Skip", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { handleAuthComplete(sync, Status.SKIP); } }); builder.setNegativeButton(getResources().getString(R.string.Cancel), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { handleAuthComplete(sync, Status.SKIP); } }); builder.setOnKeyListener(new DialogInterface.OnKeyListener() { @Override public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) { if (i == KeyEvent.KEYCODE_BACK && keyEvent.getAction() == KeyEvent.ACTION_UP) { handleAuthComplete(sync, Status.CANCEL); } return false; } }); final AlertDialog dialog = builder.create(); dialog.show(); }
From source file:android.support.v17.leanback.widget.GuidedActionsStylist.java
protected void onEditingModeChange(ViewHolder vh, GuidedAction action, boolean editing) { action = vh.getAction();/*www .java2 s. c om*/ TextView titleView = vh.getTitleView(); TextView descriptionView = vh.getDescriptionView(); if (editing) { CharSequence editTitle = action.getEditTitle(); if (titleView != null && editTitle != null) { titleView.setText(editTitle); } CharSequence editDescription = action.getEditDescription(); if (descriptionView != null && editDescription != null) { descriptionView.setText(editDescription); } if (action.isDescriptionEditable()) { if (descriptionView != null) { descriptionView.setVisibility(View.VISIBLE); descriptionView.setInputType(action.getDescriptionEditInputType()); } vh.mEditingMode = EDITING_DESCRIPTION; } else if (action.isEditable()) { if (titleView != null) { titleView.setInputType(action.getEditInputType()); } vh.mEditingMode = EDITING_TITLE; } else if (vh.mActivatorView != null) { onEditActivatorView(vh, action, editing); vh.mEditingMode = EDITING_ACTIVATOR_VIEW; } } else { if (titleView != null) { titleView.setText(action.getTitle()); } if (descriptionView != null) { descriptionView.setText(action.getDescription()); } if (vh.mEditingMode == EDITING_DESCRIPTION) { if (descriptionView != null) { descriptionView .setVisibility(TextUtils.isEmpty(action.getDescription()) ? View.GONE : View.VISIBLE); descriptionView.setInputType(action.getDescriptionInputType()); } } else if (vh.mEditingMode == EDITING_TITLE) { if (titleView != null) { titleView.setInputType(action.getInputType()); } } else if (vh.mEditingMode == EDITING_ACTIVATOR_VIEW) { if (vh.mActivatorView != null) { onEditActivatorView(vh, action, editing); } } vh.mEditingMode = EDITING_NONE; } }
From source file:com.aslanoba.hwc.SettingsActivity.java
/** * Click handler for the list items. Will create the appropriate edit * box for the clicked setting.//from w w w . j a v a2 s . c om */ @Override public void onListItemClick(ListView oParent, View v, int iPos, long id) { final ListView oParentListView = oParent; final SettingsListItem oItem = m_filteredSettings.get(iPos); if (oItem instanceof ChoiceSettingsListItem) { final ChoiceSettingsListItem oChoiceItem = (ChoiceSettingsListItem) oItem; // Show dialog new AlertDialog.Builder(SettingsActivity.this) .setTitle(getString(R.string.Label_Edit) + " " + oItem.m_sLabel) .setSingleChoiceItems(oChoiceItem.m_asText, oChoiceItem.m_iSelectedItem, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { oChoiceItem.select(whichButton); if (oItem.m_iPropId == PropertyID.CONNECTION_AUTO_REGISTRATION_HINT) { m_iRegistrationMethod = (Integer) oChoiceItem.m_oValue; if (m_iRegistrationMethod == Settings.REGISTRATION_METHOD.CERTIFICATE) { handleLocalCertificateSelection(); } } // refresh in ui refreshList(); oParentListView.invalidate(); // Close dialog dialog.dismiss(); } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Close dialog dialog.dismiss(); } }).show(); } else { // inflate the xml layout final View oView = m_oInflater.inflate(R.layout.settings_edit, null); TextView tv = (TextView) oView.findViewById(R.id.TextViewEditSettings); if (tv != null) tv.setText(getItemLabel(oItem)); // set value tv = (TextView) oView.findViewById(R.id.EditTextEditSettings); if (tv != null) tv.setText(oItem.m_oValue.toString()); // special input validator for integers if (oItem.m_oValue instanceof Integer) tv.setInputType(InputType.TYPE_CLASS_NUMBER); if (oItem.m_bPassword) tv.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); // show dialog, valid value when user clicks ok button new AlertDialog.Builder(this).setTitle(getString(R.string.Label_Edit) + " " + getItemLabel(oItem)) .setView(oView).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { TextView tv = (TextView) oView.findViewById(R.id.EditTextEditSettings); String sText = tv.getText().toString(); if (oItem.m_oValue instanceof Integer) oItem.m_oValue = Integer.parseInt(sText); else if (oItem.m_oValue instanceof Boolean) oItem.m_oValue = Boolean.parseBoolean(sText); else oItem.m_oValue = sText; InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(tv.getWindowToken(), 0); //validate the input value if (!validateField(oItem)) { // validation failed, reset to original value oItem.m_oValue = oItem.m_oOrigValue; showValidationErrorDialog(oItem.m_sLabel); } else { // refresh in ui refreshList(); oParentListView.invalidate(); } } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { TextView tv = (TextView) oView.findViewById(R.id.EditTextEditSettings); InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(tv.getWindowToken(), 0); dialog.dismiss(); } }).show(); } }