List of usage examples for android.widget EditText selectAll
public void selectAll()
From source file:com.owncloud.android.ui.activity.ReceiveExternalFilesActivity.java
/** * Suggest a filename based on the extras in the intent. * Show soft keyboard when no filename could be suggested. * * @param alertDialog AlertDialog/*from ww w. j ava 2s . co m*/ * @param input EditText The view where to place the filename in. */ private void setFileNameFromIntent(AlertDialog alertDialog, EditText input) { String subject = getIntent().getStringExtra(Intent.EXTRA_SUBJECT); String title = getIntent().getStringExtra(Intent.EXTRA_TITLE); String fileName = subject != null ? subject : title; input.setText(fileName); input.selectAll(); if (fileName == null) { // Show soft keyboard Window window = alertDialog.getWindow(); if (window != null) window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); } }
From source file:net.fabiszewski.ulogger.MainActivity.java
/** * Display track name dialog// w w w .j av a2 s . c o m */ private void showTrackDialog() { final Dialog dialog = new Dialog(MainActivity.this); dialog.setTitle(R.string.title_newtrack); dialog.setContentView(R.layout.newtrack_dialog); final EditText editText = (EditText) dialog.findViewById(R.id.newtrack_edittext); final SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd_HH.mm.ss", Locale.getDefault()); sdf.setTimeZone(TimeZone.getDefault()); final String dateSuffix = sdf.format(Calendar.getInstance().getTime()); final String autoName = "Auto_" + dateSuffix; editText.setText(autoName); editText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { editText.selectAll(); } }); dialog.show(); final Button submit = (Button) dialog.findViewById(R.id.newtrack_button_submit); submit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String trackName = editText.getText().toString(); if (trackName.length() == 0) { return; } db.newTrack(trackName); LoggerService.resetUpdateRealtime(); updateTrackLabel(trackName); updateStatus(); dialog.cancel(); } }); final Button cancel = (Button) dialog.findViewById(R.id.newtrack_button_cancel); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.cancel(); } }); }
From source file:com.github.nutomic.pegasus.activities.ProfileList.java
/** * Show an AlertDialog to edit the name of a profile. * // w ww .j av a2 s . c o m * @param profile ID of the profile to rename. */ private void renameProfile(final long profile, String name) { final EditText input = new EditText(this); input.setText(name); input.setSingleLine(); AlertDialog alert = new AlertDialog.Builder(this).setTitle(R.string.profilelist_rename).setView(input) .setPositiveButton(android.R.string.ok, new OnClickListener() { public void onClick(DialogInterface dialog, int which) { new UpdateTask() { @Override protected Long doInBackground(Void... params) { ContentValues cv = new ContentValues(); cv.put(ProfileColumns.NAME, input.getText().toString()); Database.getInstance(ProfileList.this).getWritableDatabase().update( ProfileColumns.TABLE_NAME, cv, ProfileColumns._ID + " = ?", new String[] { Long.toString(profile) }); return null; } }.execute((Void) null); } }).setNegativeButton(android.R.string.cancel, null).create(); alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); alert.show(); input.selectAll(); }
From source file:com.github.nutomic.pegasus.activities.AreaList.java
/** * Show an AlertDialog to edit the name of an area. * // w w w . j a v a 2s . com * @param area ID of the area to rename. */ private void renameArea(final long id, String name) { final Database db = Database.getInstance(this); final EditText input = new EditText(this); input.setText(name); input.setSingleLine(); AlertDialog alert = new AlertDialog.Builder(this).setTitle(R.string.arealist_rename).setView(input) .setPositiveButton(android.R.string.ok, new OnClickListener() { public void onClick(DialogInterface dialog, int which) { new UpdateTask() { @Override protected Long doInBackground(Void... params) { // Don't rename default area. if (id != AreaColumns.AREA_DEFAULT) { ContentValues cv = new ContentValues(); cv.put(AreaColumns.NAME, input.getText().toString()); db.getWritableDatabase().update(AreaColumns.TABLE_NAME, cv, AreaColumns._ID + " = ?", new String[] { Long.toString(id) }); } return null; } }.execute((Void) null); } }).setNegativeButton(android.R.string.cancel, null).create(); alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); alert.show(); input.selectAll(); }
From source file:com.pdftron.pdf.tools.Tool.java
protected void setAuthor(Markup annot) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(mPDFView.getContext()); boolean authorNameHasBeenAsked = pref.getBoolean("pref_author_name_has_been_asked", false); String authorName = pref.getString("pref_author_name", ""); if (!authorNameHasBeenAsked && authorName.isEmpty()) { // Show dialog to get the author name. boolean askAuthor = false; if (mPDFView.getToolManager() instanceof ToolManager) { if (((ToolManager) mPDFView.getToolManager()).isShowAuthorDialog()) { askAuthor = true;/*from w w w . ja v a 2 s.co m*/ } } mMarkupToAuthor = annot; String possibleName = ""; // If the author name in the preferences is empty, we try to get // the name of the current user in the device. int res = mPDFView.getContext().checkCallingOrSelfPermission("android.permission.GET_ACCOUNTS"); if (res == PackageManager.PERMISSION_GRANTED) { Pattern emailPattern = Patterns.EMAIL_ADDRESS; //Account[] accounts = AccountManager.get(mPDFView.getContext()).getAccounts(); // for (Account account : accounts) { // if (emailPattern.matcher(account.name).matches()) { // possibleName = account.name; // break; // } // } } final SharedPreferences.Editor editor = pref.edit(); editor.putBoolean("pref_author_name_has_been_asked", true); editor.commit(); if (askAuthor) { LayoutInflater inflater = (LayoutInflater) mPDFView.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View authorNameDialog = inflater.inflate(R.layout.tools_dialog_author_name, null); final EditText authorNameEditText = (EditText) authorNameDialog .findViewById(R.id.tools_dialog_author_name_edittext); authorNameEditText.setText(possibleName); authorNameEditText.selectAll(); AlertDialog.Builder builder = new AlertDialog.Builder(mPDFView.getContext()); final AlertDialog authorDialog = builder.setView(authorNameDialog) .setTitle(R.string.tools_dialog_author_name_title) .setPositiveButton(R.string.tools_misc_ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String author = authorNameEditText.getText().toString().trim(); // Set author information on the markup setAuthor(mMarkupToAuthor, author); // Update preferences with the new name //SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(mPDFView.getContext()).edit(); editor.putString("pref_author_name", author); editor.commit(); } }).setNegativeButton(R.string.tools_misc_skip, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).create(); authorDialog.show(); if (authorNameEditText.getText().length() == 0) { // empty, don't allow OK authorDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false); } else { authorDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true); } authorNameEditText.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) { } @Override public void afterTextChanged(Editable s) { if (authorDialog != null) { if (s.length() == 0) { // empty, don't allow OK authorDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false); } else { authorDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true); } } } }); } else { // Set author information on the markup setAuthor(mMarkupToAuthor, possibleName); // Update preferences with the new name //SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(mPDFView.getContext()).edit(); editor.putString("pref_author_name", possibleName); editor.commit(); } } else { // Use author name in the preferences String author = pref.getString("pref_author_name", ""); setAuthor(annot, author); } }
From source file:com.afwsamples.testdpc.policy.PolicyManagementFragment.java
/** * Shows a prompt to ask for the certificate alias. This alias will be imported together with * the private key and certificate./*from w ww. j av a 2 s . co m*/ * * @param key The private key of a certificate. * @param certificate The certificate will be imported. * @param alias A name that represents the certificate in the profile. */ private void showPromptForKeyCertificateAlias(final PrivateKey key, final Certificate certificate, String alias) { if (getActivity() == null || getActivity().isFinishing() || key == null || certificate == null) { return; } View passwordInputView = getActivity().getLayoutInflater().inflate(R.layout.certificate_alias_prompt, null); final EditText input = (EditText) passwordInputView.findViewById(R.id.alias_input); if (!TextUtils.isEmpty(alias)) { input.setText(alias); input.selectAll(); } new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.certificate_alias_prompt_title)) .setView(passwordInputView) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String alias = input.getText().toString(); if (mDevicePolicyManager.installKeyPair(mAdminComponentName, key, certificate, alias) == true) { showToast(R.string.certificate_added, alias); } else { showToast(R.string.certificate_add_failed, alias); } dialog.dismiss(); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }).show(); }
From source file:saphion.fragments.alarm.AlarmFragment.java
private void showLabelDialog(final Alarm alarm) { /*/* w w w . j a va2 s . co m*/ * final FragmentTransaction ft = * getFragmentManager().beginTransaction(); final Fragment prev = * getFragmentManager().findFragmentByTag( "label_dialog"); if (prev != * null) { ft.remove(prev); } ft.addToBackStack(null); * * // Create and show the dialog. final LabelDialogFragment newFragment * = LabelDialogFragment .newInstance(alarm, alarm.label, getTag()); * newFragment.show(ft, "label_dialog"); */ AlertDialog.Builder builder = new AlertDialog.Builder(getBaseContext()); builder.setTitle("Enter Label"); View view = LayoutInflater.from(getBaseContext()).inflate(R.layout.label_picker, null); final EditText picker = (EditText) view.findViewById(R.id.labelPicker); picker.setText(alarm.label); picker.selectAll(); (new Handler()).postDelayed(new Runnable() { @SuppressLint("Recycle") public void run() { picker.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 0, 0, 0)); picker.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, 0, 0, 0)); picker.selectAll(); } }, 200); builder.setView(view); builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { setLabel(alarm, picker.getText().toString()); } }); builder.setNegativeButton(android.R.string.cancel, null); builder.show(); }
From source file:com.sentaroh.android.TaskAutomation.Config.ProfileMaintenanceActionProfile.java
final static private void setProfileActionActivityListener(final GlobalParameters mGlblParms, final Dialog dialog, final AdapterProfileList pfla, final String curr_grp, final ArrayList<ActivityExtraDataItem> p_aed_edit_list) { final Button uri_fl = (Button) dialog .findViewById(R.id.edit_profile_action_exec_activity_uri_data_filelist); final EditText uri_data = (EditText) dialog.findViewById(R.id.edit_profile_action_exec_activity_uri_data); uri_data.setOnKeyListener(new OnKeyListener() { @Override/*w ww .j av a 2 s . co m*/ public boolean onKey(View arg0, int keyCode, KeyEvent event) { if (//event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { return true; } return false; } }); // Uri filelist ? uri_fl.setOnClickListener(new View.OnClickListener() { final public void onClick(View v) { NotifyEvent ntfy = new NotifyEvent(mGlblParms.context); ntfy.setListener(new NotifyEventListener() { @Override final public void positiveResponse(Context c, Object[] o) { uri_data.selectAll(); uri_data.setText(Uri.parse((String) o[0]).toString()); } @Override final public void negativeResponse(Context c, Object[] o) { } }); mGlblParms.commonDlg.fileSelectWithoutCreate(LocalMountPoint.getExternalStorageDir(), "", "", "Select file", ntfy); } }); mGlblParms.activityExtraDataEditListAdapter = new AdapterActivityExtraDataEditList(mGlblParms.context, R.layout.edit_activity_extra_data_list_item, p_aed_edit_list); ListView lv_aed = (ListView) dialog .findViewById(R.id.edit_profile_action_exec_activity_extra_data_listview); lv_aed.setAdapter(mGlblParms.activityExtraDataEditListAdapter); if (mGlblParms.activityExtraDataEditListAdapter.getCount() == 0) { ActivityExtraDataItem aedi = new ActivityExtraDataItem(); aedi.key_value = ""; aedi.data_value = mGlblParms.context .getString(R.string.msgs_edit_profile_action_activity_extra_data_no_data_exists); mGlblParms.activityExtraDataEditListAdapter.add(aedi); } lv_aed.setOnItemClickListener(new OnItemClickListener() { @Override final public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) { int t_pos; if (mGlblParms.activityExtraDataEditListAdapter.getItem(pos).key_value.equals("")) t_pos = -1; else t_pos = pos; editActivityExtraDataItem(mGlblParms, t_pos); } }); lv_aed.setOnItemLongClickListener(new OnItemLongClickListener() { @Override final public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int pos, long arg3) { mGlblParms.ccMenu .addMenuItem(mGlblParms.context .getString(R.string.msgs_edit_profile_action_activity_extra_data_ccmenu_add)) .setOnClickListener(new CustomContextMenuOnClickListener() { @Override final public void onClick(CharSequence menuTitle) { editActivityExtraDataItem(mGlblParms, -1); } }); if (!mGlblParms.activityExtraDataEditListAdapter.getItem(pos).key_value.equals("")) { mGlblParms.ccMenu .addMenuItem(mGlblParms.context .getString(R.string.msgs_edit_profile_action_activity_extra_data_ccmenu_edit)) .setOnClickListener(new CustomContextMenuOnClickListener() { @Override final public void onClick(CharSequence menuTitle) { editActivityExtraDataItem(mGlblParms, pos); } }); mGlblParms.ccMenu .addMenuItem(mGlblParms.context .getString(R.string.msgs_edit_profile_action_activity_extra_data_ccmenu_delete)) .setOnClickListener(new CustomContextMenuOnClickListener() { @Override final public void onClick(CharSequence menuTitle) { mGlblParms.activityExtraDataEditListAdapter.remove(pos); if (mGlblParms.activityExtraDataEditListAdapter.getCount() == 0) { ActivityExtraDataItem aedi = new ActivityExtraDataItem(); aedi.key_value = ""; aedi.data_value = mGlblParms.context.getString( R.string.msgs_edit_profile_action_activity_extra_data_no_data_exists); mGlblParms.activityExtraDataEditListAdapter.add(aedi); } mGlblParms.activityExtraDataEditListAdapter.notifyDataSetChanged(); } }); } mGlblParms.ccMenu.createMenu(); return false; } }); }
From source file:com.sentaroh.android.TaskAutomation.Config.ActivityMain.java
final private void createNewProfileGroup() { // ??//from www .jav a2s . co m final Dialog dialog = new Dialog(mContext); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // dialog.getWindow().setSoftInputMode( // WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); dialog.setContentView(R.layout.single_item_input_dlg); final TextView dlg_title = (TextView) dialog.findViewById(R.id.single_item_input_title); final EditText dlg_et_name = (EditText) dialog.findViewById(R.id.single_item_input_dir); // final TextView dlg_msg = (TextView) dialog.findViewById(R.id.single_item_input_msg); final Button btnCancel = (Button) dialog.findViewById(R.id.single_item_input_cancel_btn); final Button btnOK = (Button) dialog.findViewById(R.id.single_item_input_ok_btn); btnOK.setEnabled(false); dlg_title.setText(mContext.getString(R.string.msgs_profile_group_create_new_profile_group)); CommonDialog.setDlgBoxSizeCompact(dialog); dlg_et_name.addTextChangedListener(new TextWatcher() { @Override final public void afterTextChanged(Editable s) { if (s.length() != 0) { // dlg_et_name.selectAll(); String newgrp = dlg_et_name.getText().toString(); if (!newgrp.startsWith("*")) { btnOK.setEnabled(true); for (int i = 0; i < mGlblParms.profileGroupAdapter.getCount(); i++) { if (mGlblParms.profileGroupAdapter.getItem(i).getProfileGroupName().equals(newgrp)) { btnOK.setEnabled(false); break; } } } else btnOK.setEnabled(false); } else btnOK.setEnabled(false); } @Override final public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override final public void onTextChanged(CharSequence s, int start, int before, int count) { } }); final NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override final public void positiveResponse(Context c, Object[] o) { dlg_et_name.selectAll(); String newloc = dlg_et_name.getText().toString(); mGlblParms.profileGroupAdapter.add(new ProfileGroupListItem(newloc, false, 0, 0, 0)); mGlblParms.profileGroupAdapter.sort(); mGlblParms.profileGroupAdapter.notifyDataSetChanged(); ProfileListItem tpli = new ProfileListItem(); tpli.setTaskEntry(PROFILE_VERSION_CURRENT, newloc, false, System.currentTimeMillis(), "", mContext.getString(R.string.msgs_no_profile_entry), "", "", "", "", null, null); mGlblParms.profileAdapter.addDataListItem(tpli); mGlblParms.profileAdapter.updateShowList(); setProfileGroupSelectorListener(); } @Override final public void negativeResponse(Context c, Object[] o) { } }); // CANCEL? btnCancel.setOnClickListener(new View.OnClickListener() { final public void onClick(View v) { dialog.dismiss(); } }); // OK? btnOK.setOnClickListener(new View.OnClickListener() { final public void onClick(View v) { ntfy.notifyToListener(POSITIVE, null); dialog.dismiss(); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btnCancel.performClick(); } }); // dialog.setOnKeyListener(new DialogOnKeyListener(context)); // dialog.setCancelable(false); dialog.show(); }
From source file:com.sentaroh.android.TaskAutomation.Config.ActivityMain.java
final private void copyProfileGroupDlg(final String old_loc) { // ??//from w w w . j ava 2 s . c o m final Dialog dialog = new Dialog(mContext); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // dialog.getWindow().setSoftInputMode( // WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); dialog.setContentView(R.layout.single_item_input_dlg); final TextView dlg_title = (TextView) dialog.findViewById(R.id.single_item_input_title); final EditText dlg_et_name = (EditText) dialog.findViewById(R.id.single_item_input_dir); // final TextView dlg_msg = (TextView) dialog.findViewById(R.id.single_item_input_msg); final Button btnCancel = (Button) dialog.findViewById(R.id.single_item_input_cancel_btn); final Button btnOK = (Button) dialog.findViewById(R.id.single_item_input_ok_btn); btnOK.setEnabled(false); dlg_title.setText(mContext.getString(R.string.msgs_profile_group_copy_profile_group)); CommonDialog.setDlgBoxSizeCompact(dialog); dlg_et_name.setText(old_loc); dlg_et_name.addTextChangedListener(new TextWatcher() { @Override final public void afterTextChanged(Editable s) { if (s.length() != 0) { // dlg_et_name.selectAll(); String newgrp = dlg_et_name.getText().toString(); if (!newgrp.startsWith("*")) { btnOK.setEnabled(true); for (int i = 0; i < mGlblParms.profileGroupAdapter.getCount(); i++) { if (mGlblParms.profileGroupAdapter.getItem(i).getProfileGroupName().equals(newgrp)) { btnOK.setEnabled(false); break; } } } else btnOK.setEnabled(false); } else btnOK.setEnabled(false); } @Override final public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override final public void onTextChanged(CharSequence s, int start, int before, int count) { } }); final NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override final public void positiveResponse(Context c, Object[] o) { dlg_et_name.selectAll(); String new_loc = dlg_et_name.getText().toString(); copyProfileGroup(true, old_loc, new_loc); } @Override final public void negativeResponse(Context c, Object[] o) { } }); // CANCEL? btnCancel.setOnClickListener(new View.OnClickListener() { final public void onClick(View v) { dialog.dismiss(); } }); // OK? btnOK.setOnClickListener(new View.OnClickListener() { final public void onClick(View v) { ntfy.notifyToListener(POSITIVE, null); dialog.dismiss(); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btnCancel.performClick(); } }); // dialog.setOnKeyListener(new DialogOnKeyListener(context)); // dialog.setCancelable(false); dialog.show(); }