List of usage examples for android.widget EditText selectAll
public void selectAll()
From source file:group.pals.android.lib.ui.filechooser.utils.ui.bookmark.BookmarkFragment.java
/** * Shows a dialog to let user enter new name or change current name of a * bookmark./*from w ww.j ava 2 s. c om*/ * * @param context * {@link Context} * @param providerId * the provider ID. * @param id * the bookmark ID. * @param uri * the URI to the bookmark. * @param name * the name. To enter new name, this is the suggested name you * provide. To rename, this is the old name. */ public static void doEnterNewNameOrRenameBookmark(final Context context, final String providerId, final int id, final Uri uri, final String name) { final AlertDialog dialog = Dlg.newDlg(context); View view = LayoutInflater.from(context).inflate(R.layout.afc_simple_text_input_view, null); final EditText textName = (EditText) view.findViewById(R.id.afc_text1); textName.setText(name); textName.selectAll(); textName.setHint(R.string.afc_hint_new_name); textName.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { Ui.showSoftKeyboard(textName, false); Button btn = dialog.getButton(DialogInterface.BUTTON_POSITIVE); if (btn.isEnabled()) btn.performClick(); return true; } return false; }// onEditorAction() }); dialog.setView(view); dialog.setIcon(R.drawable.afc_bookmarks_dark); dialog.setTitle(id < 0 ? R.string.afc_title_new_bookmark : R.string.afc_title_rename); dialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String newName = textName.getText().toString().trim(); if (android.text.TextUtils.isEmpty(newName)) { Dlg.toast(context, R.string.afc_msg_bookmark_name_is_invalid, Dlg._LengthShort); return; } Ui.showSoftKeyboard(textName, false); ContentValues values = new ContentValues(); values.put(BookmarkContract.Bookmark._ColumnName, newName); if (id >= 0) { values.put(BookmarkContract.Bookmark._ColumnModificationTime, DbUtils.formatNumber(new Date().getTime())); context.getContentResolver() .update(Uri.withAppendedPath(BookmarkContract.Bookmark._ContentIdUriBase, Uri.encode(Integer.toString(id))), values, null, null); } else { /* * Check if the URI exists or doesn't. If it exists, * update it instead of inserting the new one. */ Cursor cursor = context.getContentResolver().query( BookmarkContract.Bookmark._ContentUri, null, String.format("%s = %s AND %s LIKE %s", BookmarkContract.Bookmark._ColumnProviderId, DatabaseUtils.sqlEscapeString(providerId), BookmarkContract.Bookmark._ColumnUri, DatabaseUtils.sqlEscapeString(uri.toString())), null, null); try { if (cursor != null && cursor.moveToFirst()) { values.put(BookmarkContract.Bookmark._ColumnModificationTime, DbUtils.formatNumber(new Date().getTime())); context.getContentResolver().update( Uri.withAppendedPath(BookmarkContract.Bookmark._ContentIdUriBase, Uri.encode(cursor.getString( cursor.getColumnIndex(BookmarkContract.Bookmark._ID)))), values, null, null); } else { values.put(BookmarkContract.Bookmark._ColumnProviderId, providerId); values.put(BookmarkContract.Bookmark._ColumnUri, uri.toString()); context.getContentResolver().insert(BookmarkContract.Bookmark._ContentUri, values); } } finally { if (cursor != null) cursor.close(); } } Dlg.toast(context, context.getString(R.string.afc_msg_done), Dlg._LengthShort); }// onClick() }); dialog.show(); Ui.showSoftKeyboard(textName, true); final Button buttonOk = dialog.getButton(DialogInterface.BUTTON_POSITIVE); buttonOk.setEnabled(id < 0); textName.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { String newName = s.toString().trim(); boolean enabled = !android.text.TextUtils.isEmpty(newName); buttonOk.setEnabled(enabled); /* * If renaming, only enable button OK if new name is not equal * to the old one. */ if (enabled && id >= 0) buttonOk.setEnabled(!newName.equals(name)); } }); }
From source file:com.haibison.android.anhuu.utils.ui.bookmark.BookmarkFragment.java
/** * Shows a dialog to let the user enter new name or change current name of a * bookmark.//from w ww .ja v a 2s . co m * * @param context * {@link Context} * @param providerId * the provider ID. * @param id * the bookmark ID. * @param uri * the URI to the bookmark. * @param name * the name. To enter new name, this is the suggested name you * provide. To rename, this is the old name. */ public static void doEnterNewNameOrRenameBookmark(final Context context, final String providerId, final int id, final Uri uri, final String name) { final AlertDialog dialog = Dlg.newAlertDlg(context); View view = LayoutInflater.from(context).inflate(R.layout.anhuu_f5be488d_simple_text_input_view, null); final EditText textName = (EditText) view.findViewById(R.id.anhuu_f5be488d_text1); textName.setText(name); textName.selectAll(); textName.setHint(R.string.anhuu_f5be488d_hint_new_name); textName.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { UI.showSoftKeyboard(textName, false); Button btn = dialog.getButton(DialogInterface.BUTTON_POSITIVE); if (btn.isEnabled()) btn.performClick(); return true; } return false; }// onEditorAction() }); dialog.setView(view); dialog.setIcon(R.drawable.anhuu_f5be488d_bookmarks_dark); dialog.setTitle(id < 0 ? R.string.anhuu_f5be488d_title_new_bookmark : R.string.anhuu_f5be488d_title_rename); dialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String newName = textName.getText().toString().trim(); if (android.text.TextUtils.isEmpty(newName)) { Dlg.toast(context, R.string.anhuu_f5be488d_msg_bookmark_name_is_invalid, Dlg.LENGTH_SHORT); return; } UI.showSoftKeyboard(textName, false); ContentValues values = new ContentValues(); values.put(BookmarkContract.COLUMN_NAME, newName); if (id >= 0) { values.put(BookmarkContract.COLUMN_MODIFICATION_TIME, DbUtils.formatNumber(new Date().getTime())); context.getContentResolver().update( ContentUris.withAppendedId(BookmarkContract.genContentIdUriBase(context), id), values, null, null); } else { /* * Check if the URI exists or doesn't. If it exists, * update it instead of inserting the new one. */ Cursor cursor = context.getContentResolver().query( BookmarkContract.genContentUri(context), null, String.format("%s = %s AND %s LIKE %s", BookmarkContract.COLUMN_PROVIDER_ID, DatabaseUtils.sqlEscapeString(providerId), BookmarkContract.COLUMN_URI, DatabaseUtils.sqlEscapeString(uri.toString())), null, null); try { if (cursor != null && cursor.moveToFirst()) { values.put(BookmarkContract.COLUMN_MODIFICATION_TIME, DbUtils.formatNumber(new Date().getTime())); context.getContentResolver().update( Uri.withAppendedPath(BookmarkContract.genContentIdUriBase(context), Uri.encode(cursor.getString( cursor.getColumnIndex(BookmarkContract._ID)))), values, null, null); } else { values.put(BookmarkContract.COLUMN_PROVIDER_ID, providerId); values.put(BookmarkContract.COLUMN_URI, uri.toString()); context.getContentResolver().insert(BookmarkContract.genContentUri(context), values); } } finally { if (cursor != null) cursor.close(); } } Dlg.toast(context, context.getString(R.string.anhuu_f5be488d_msg_done), Dlg.LENGTH_SHORT); }// onClick() }); dialog.show(); UI.showSoftKeyboard(textName, true); final Button buttonOk = dialog.getButton(DialogInterface.BUTTON_POSITIVE); buttonOk.setEnabled(id < 0); textName.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { String newName = s.toString().trim(); boolean enabled = !android.text.TextUtils.isEmpty(newName); buttonOk.setEnabled(enabled); /* * If renaming, only enable button OK if new name is not equal * to the old one. */ if (enabled && id >= 0) buttonOk.setEnabled(!newName.equals(name)); } }); }
From source file:com.bt.download.android.gui.adapters.menu.RenameFileMenuAction.java
@Override protected void onClick(Context context) { String filePath = fd.filePath; String name = FilenameUtils.getBaseName(filePath); final String ext = FilenameUtils.getExtension(filePath); final EditText input = new EditText(context); input.setText(name);//from www . java2s . c om input.selectAll(); UIUtils.showOkCancelDialog(context, input, R.string.rename, new OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String newFileName = input.getText().toString() + "." + ext; if (isValidFileName(newFileName)) { renameFile(newFileName); adapter.notifyDataSetChanged(); } else { // FIXME } } }); }
From source file:com.ruesga.rview.fragments.NewChangeDialogFragment.java
@Override public void onDialogReveled() { super.onDialogReveled(); EditText v = mBinding.project; v.clearFocus();/*from w w w .ja v a 2 s .com*/ v.requestFocus(); v.selectAll(); }
From source file:net.naonedbus.fragment.impl.GroupesFragment.java
private void menuAdd() { final View alertDialogView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_input, null); final EditText input = (EditText) alertDialogView.findViewById(R.id.text); input.selectAll(); final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setView(alertDialogView);//ww w.ja va2 s. c o m builder.setTitle(R.string.action_groupes_add); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { final Groupe groupe = new Groupe(); groupe.setNom(input.getText().toString().trim()); groupe.setOrdre(mCursor.getCount()); mGroupeManager.add(getActivity().getContentResolver(), groupe); } }); builder.setNegativeButton(android.R.string.cancel, null); final AlertDialog alert = builder.create(); alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); alert.show(); }
From source file:net.naonedbus.fragment.impl.GroupesFragment.java
private void editCheckedItem() { final int checkedItem = getFirstSelectedItemPosition(); final CursorWrapper wrapper = (CursorWrapper) mListView.getItemAtPosition(checkedItem); final Groupe groupe = mGroupeManager.getSingleFromCursor(wrapper); final View alertDialogView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_input, null); final EditText input = (EditText) alertDialogView.findViewById(R.id.text); input.setText(groupe.getNom());/* ww w. ja v a 2 s . c o m*/ input.selectAll(); final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setView(alertDialogView); builder.setTitle(R.string.action_rename); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { final String nom = input.getText().toString().trim(); groupe.setNom((nom.length() == 0) ? null : nom); mGroupeManager.update(getActivity().getContentResolver(), groupe); } }); builder.setNegativeButton(android.R.string.cancel, null); final AlertDialog alert = builder.create(); alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); alert.show(); }
From source file:com.ruesga.rview.fragments.EditFileChooserDialogFragment.java
@Override public void onDialogReveled() { super.onDialogReveled(); EditText v = mModel.mode.equals(MODE.RENAME) && mBinding.edit1.isEnabled() ? mBinding.edit1 : mBinding.edit2;//w w w. j a v a 2s.c o m v.clearFocus(); v.requestFocus(); v.selectAll(); }
From source file:rs.pedjaapps.kerneltuner.ui.BuildpropEditor.java
@Override public void onCreate(Bundle savedInstanceState) { entries = new ArrayList<>(); preferences = PreferenceManager.getDefaultSharedPreferences(this); super.onCreate(savedInstanceState); setContentView(R.layout.build);//from www.j a v a2s .co m getSupportActionBar().setDisplayHomeAsUpEnabled(true); bListView = (ListView) findViewById(R.id.list); bAdapter = new BuildAdapter(this, new ArrayList<Build>()); bListView.setAdapter(bAdapter); bListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View v, final int pos, long is) { AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext()); final Build build = bAdapter.getItem(pos); builder.setTitle(build.key); builder.setIcon(R.drawable.build); final EditText input = new EditText(v.getContext()); input.setText(build.value); input.selectAll(); input.setGravity(Gravity.CENTER_HORIZONTAL); input.requestFocus(); builder.setPositiveButton(getString(R.string.Change), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { build.value = input.getText().toString().trim(); saveBuildProp(build); } }); builder.setNegativeButton(getResources().getString(R.string.cancel), null); builder.setView(input); AlertDialog alert = builder.create(); alert.show(); } }); new GetBuildEntries().execute(); }
From source file:com.eugene.fithealthmaingit.UI.ManualEntrySaveMealFragment.java
private void updateItems() { mToolbar.setNavigationIcon(R.mipmap.ic_arrow_back); mToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override/*from ww w . ja v a2 s. co m*/ public void onClick(View v) { Intent intent = new Intent(getActivity(), ChooseAddMealActivity.class); intent.putExtra(Globals.MEAL_TYPE, mealType); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } }); mToolbar.inflateMenu(R.menu.menu_user_info); mToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { if (menuItem.getItemId() == R.id.action_save) saveMeal(); return false; } }); mServingSizeUpdated.setText("1"); LinearLayout changeServing = (LinearLayout) v.findViewById(R.id.changeServing); changeServing.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); alert.setTitle("Update Serving Size: "); alert.setMessage("Servings Consumed"); final EditText input = new EditText(getActivity()); input.setText(mServingg.getText().toString()); input.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); input.selectAll(); input.setGravity(Gravity.CENTER_HORIZONTAL); alert.setView(input, 64, 0, 64, 0); alert.setPositiveButton("Update", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { double values = Double.valueOf(input.getText().toString()); mServingg.setText(df.format(values)); mServingSizeUpdated.setText(df.format(values)); mCalUpdate.setText(dfW.format(Double.valueOf(mCalories) * values)); mCalorieProgress = Double.valueOf(mCalories) * values; mFattieUpdate.setText(df.format(Double.valueOf(mFat) * values)); mFatProgress = Double.valueOf(mFat) * values; mSaturatedFatUpdate.setText(df.format(Double.valueOf(mSaturatedFat) * values)); mCholesterolUpdate.setText(df.format(Double.valueOf(mCholesterol) * values)); mSodiumUpdate.setText(df.format(Double.valueOf(mSodium) * values)); mCarbUpdate.setText(df.format(Double.valueOf(mCarbohydrates) * values)); mCarbProgress = Double.valueOf(mCarbohydrates) * values; mFiberUpdate.setText(df.format(Double.valueOf(mFiber) * values)); mSugarUpdate.setText(df.format(Double.valueOf(mSugar) * values)); mProUpdate.setText(df.format(Double.valueOf(mProtein) * values)); mProteinProgress = Double.valueOf(mProtein) * values; mVitAUpdate.setText(df.format(Double.valueOf(mVitA) * values)); mVitCUpdate.setText(df.format(Double.valueOf(mVitC) * values)); mCalciumUpdate.setText(df.format(Double.valueOf(mCalcium) * values)); mIronUpdate.setText(df.format(Double.valueOf(mIron) * values)); progressBars(); ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(input.getWindowToken(), 0); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(input.getWindowToken(), 0); } }); alert.setCancelable(false); alert.show(); ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_NOT_ALWAYS); } }); }
From source file:com.eugene.fithealthmaingit.UI.SaveSearchAddItemActivityMain.java
private void updateItems() { mServingSizeUpdated.setText("1"); LinearLayout changeServing = (LinearLayout) findViewById(R.id.changeServing); changeServing.setOnClickListener(new View.OnClickListener() { @Override/* w w w . j av a 2 s . com*/ public void onClick(View v) { AlertDialog.Builder alert = new AlertDialog.Builder(SaveSearchAddItemActivityMain.this); alert.setTitle("Update Serving Size: "); alert.setMessage("Servings Consumed"); final EditText input = new EditText(SaveSearchAddItemActivityMain.this); input.setText(mServingg.getText().toString()); input.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); input.selectAll(); input.setGravity(Gravity.CENTER_HORIZONTAL); alert.setView(input, 64, 0, 64, 0); alert.setPositiveButton("Update", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { double values = Double.valueOf(input.getText().toString()); mServingg.setText(df.format(values)); mServingSizeUpdated.setText(df.format(values)); mCalUpdate.setText(dfW.format(Double.valueOf(mCalories) * values)); mCalorieProgress = Double.valueOf(mCalories) * values; mFattieUpdate.setText(df.format(Double.valueOf(mFat) * values)); mFatProgress = Double.valueOf(mFat) * values; mSaturatedFatUpdate.setText(df.format(Double.valueOf(mSaturatedFat) * values)); mCholesterolUpdate.setText(df.format(Double.valueOf(mCholesterol) * values)); mSodiumUpdate.setText(df.format(Double.valueOf(mSodium) * values)); mCarbUpdate.setText(df.format(Double.valueOf(mCarbohydrates) * values)); mCarbProgress = Double.valueOf(mCarbohydrates) * values; mFiberUpdate.setText(df.format(Double.valueOf(mFiber) * values)); mSugarUpdate.setText(df.format(Double.valueOf(mSugar) * values)); mProUpdate.setText(df.format(Double.valueOf(mProtein) * values)); mProteinProgress = Double.valueOf(mProtein) * values; mVitAUpdate.setText(df.format(Double.valueOf(mVitA) * values)); mVitCUpdate.setText(df.format(Double.valueOf(mVitC) * values)); mCalciumUpdate.setText(df.format(Double.valueOf(mCalcium) * values)); mIronUpdate.setText(df.format(Double.valueOf(mIron) * values)); progressBars(); ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(input.getWindowToken(), 0); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(input.getWindowToken(), 0); } }); alert.setCancelable(false); alert.show(); ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)) .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_NOT_ALWAYS); } }); }