android.widget.EditText#selectAll ( )源码实例Demo

下面列出了android.widget.EditText#selectAll ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: APDE   文件: APDE.java
public EditText createAlertDialogEditText(Activity context, AlertDialog.Builder builder, String content, boolean selectAll) {
	final EditText input = new EditText(context);
	input.setSingleLine();
	input.setText(content);
	if (selectAll) {
		input.selectAll();
	}
	
	// http://stackoverflow.com/a/27776276/
	FrameLayout frameLayout = new FrameLayout(context);
	FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
	
	// http://stackoverflow.com/a/35211225/
	float dpi = getResources().getDisplayMetrics().density;
	params.leftMargin = (int) (19 * dpi);
	params.topMargin = (int) (5 * dpi);
	params.rightMargin = (int) (14 * dpi);
	params.bottomMargin = (int) (5 * dpi);
	
	frameLayout.addView(input, params);
	
	builder.setView(frameLayout);
	
	return input;
}
 
源代码2 项目: habpanelviewer   文件: ClientWebView.java
public void enterUrl(Context ctx) {
    AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
    builder.setTitle("Enter URL");

    final EditText input = new EditText(ctx);
    input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    input.setText(getUrl());
    input.selectAll();
    builder.setView(input);

    builder.setPositiveButton("OK", (dialog, which) -> {
        String url = input.getText().toString();
        mKioskMode = isHabPanelUrl(url) && url.toLowerCase().contains("kiosk=on");
        loadUrl(url);
    });
    builder.setNegativeButton("Cancel", (dialog, which) -> dialog.cancel());

    builder.show();
}
 
源代码3 项目: GPS2SMS   文件: SlideTabsActivity.java
protected void onPrepareDialog(int id, Dialog dialog) {
    //AlertDialog aDialog = (AlertDialog) dialog;

    switch (id) {

        case DIALOG_COORD_PROPS_ID:
            try {
                EditText e1 = (EditText) dialog
                        .findViewById(R.id.mycoords_name);
                e1.requestFocus();

                DBHelper dbHelper = new DBHelper(SlideTabsActivity.this);
                RepoCoordsFragment fragment = (RepoCoordsFragment) getSupportFragmentManager().findFragmentByTag(DBHelper.getFragmentTag(R.id.viewpager, 0));
                e1.setText(dbHelper.getMyccordName(fragment.actionCoordsId));
                dbHelper.close();
                e1.selectAll();
            } catch (Exception e) {
                Log.d("gps", "EXCEPTION! " + e.toString() + " Message:" + e.getMessage());
            }

            break;

        default:
            break;
    }
}
 
源代码4 项目: FormValidations   文件: Form.java
public boolean isValid() {
    boolean result = true;
    try {
        resetErrors();
        for (final Field field : mFields) {
            result &= field.isValid();
        }
    } catch (final FieldValidationException e) {
        result = false;

        final EditText textView = e.getTextView();
        textView.requestFocus();
        textView.selectAll();

        FormUtils.showKeyboard(textView.getContext(), textView);

        showErrorMessage(e);
    }
    return result;
}
 
@ActionMethod(ids = R.id.bookmenu_rename)
public void renameBook(final ActionEx action) {
    final File file = action.getParameter("source");
    if (file == null) {
        return;
    }

    final FileUtils.FilePath path = FileUtils.parseFilePath(file.getAbsolutePath(), CodecType.getAllExtensions());
    final EditText input = new AppCompatEditText(getManagedComponent());
    input.setSingleLine();
    input.setText(path.name);
    input.selectAll();

    final ActionDialogBuilder builder = new ActionDialogBuilder(this.getManagedComponent(), this);
    builder.setTitle(R.string.book_rename_title);
    builder.setMessage(R.string.book_rename_msg);
    builder.setView(input);
    builder.setPositiveButton(R.id.actions_doRenameBook, new Constant("source", file), new Constant("file", path),
            new EditableValue("input", input));
    builder.setNegativeButton().show();
}
 
@ActionMethod(ids = R.id.mainmenu_bookmark)
public void showBookmarkDialog(final ActionEx action) {
    final int page = documentModel.getCurrentViewPageIndex();

    final String message = getManagedComponent().getString(R.string.add_bookmark_name);

    final BookSettings bs = getBookSettings();
    final int offset = bs != null ? bs.firstPageOffset : 1;

    final EditText input = (EditText) LayoutInflater.from(getManagedComponent()).inflate(R.layout.bookmark_edit,
            null);
    input.setText(getManagedComponent().getString(R.string.text_page) + " " + (page + offset));
    input.selectAll();

    final ActionDialogBuilder builder = new ActionDialogBuilder(getManagedComponent(), this);
    builder.setTitle(R.string.menu_add_bookmark).setMessage(message).setView(input);
    builder.setPositiveButton(R.id.actions_addBookmark, new EditableValue("input", input));
    builder.setNegativeButton().show();
}
 
@ActionMethod(ids = R.id.bookmenu_rename)
public void renameBook(final ActionEx action) {
    final BookNode book = action.getParameter("source");
    if (book == null) {
        return;
    }

    final FileUtils.FilePath file = FileUtils.parseFilePath(book.path, CodecType.getAllExtensions());
    final EditText input = new AppCompatEditText(getManagedComponent());
    input.setSingleLine();
    input.setText(file.name);
    input.selectAll();

    final ActionDialogBuilder builder = new ActionDialogBuilder(getContext(), this);
    builder.setTitle(R.string.book_rename_title);
    builder.setMessage(R.string.book_rename_msg);
    builder.setView(input);
    builder.setPositiveButton(R.id.actions_doRenameBook, new Constant("source", book), new Constant("file", file),
            new EditableValue("input", input));
    builder.setNegativeButton().show();
}
 
源代码8 项目: HgLauncher   文件: Utils.java
/**
 * Handles common input shortcut from an EditText.
 *
 * @param activity The activity to reference for copying and pasting.
 * @param editText The EditText where the text is being copied/pasted.
 * @param keyCode  Keycode to handle.
 *
 * @return True if key is handled.
 */
public static boolean handleInputShortcut(AppCompatActivity activity, EditText editText, int keyCode) {
    // Get selected text for cut and copy.
    int start = editText.getSelectionStart();
    int end = editText.getSelectionEnd();
    final String text = editText.getText().toString().substring(start, end);

    switch (keyCode) {
        case KeyEvent.KEYCODE_A:
            editText.selectAll();
            return true;
        case KeyEvent.KEYCODE_X:
            editText.setText(editText.getText().toString().replace(text, ""));
            return true;
        case KeyEvent.KEYCODE_C:
            ActivityServiceUtils.copyToClipboard(activity, text);
            return true;
        case KeyEvent.KEYCODE_V:
            editText.setText(
                    editText.getText().replace(Math.min(start, end), Math.max(start, end),
                            ActivityServiceUtils.pasteFromClipboard(activity), 0,
                            ActivityServiceUtils.pasteFromClipboard(activity).length()));
            return true;
        default:
            // Do nothing.
            return false;
    }
}
 
源代码9 项目: delion   文件: JavascriptAppModalDialog.java
@Override
protected void prepare(ViewGroup layout) {
    super.prepare(layout);
    EditText prompt = (EditText) layout.findViewById(R.id.js_modal_dialog_prompt);
    prompt.setVisibility(View.VISIBLE);

    if (mDefaultPromptText.length() > 0) {
        prompt.setText(mDefaultPromptText);
        prompt.selectAll();
    }
}
 
@Override
public void prepare(ViewGroup layout) {
    super.prepare(layout);
    EditText prompt = (EditText) layout.findViewById(R.id.js_modal_dialog_prompt);
    prompt.setVisibility(View.VISIBLE);

    if (mDefaultPromptText.length() > 0) {
        prompt.setText(mDefaultPromptText);
        prompt.selectAll();
    }
}
 
源代码11 项目: AndroidChromium   文件: JavascriptAppModalDialog.java
@Override
protected void prepare(ViewGroup layout) {
    super.prepare(layout);
    EditText prompt = (EditText) layout.findViewById(R.id.js_modal_dialog_prompt);
    prompt.setVisibility(View.VISIBLE);

    if (mDefaultPromptText.length() > 0) {
        prompt.setText(mDefaultPromptText);
        prompt.selectAll();
    }
}
 
源代码12 项目: HgLauncher   文件: Utils.java
/**
 * Handles common input shortcut from an EditText.
 *
 * @param activity The activity to reference for copying and pasting.
 * @param editText The EditText where the text is being copied/pasted.
 * @param keyCode  Keycode to handle.
 *
 * @return True if key is handled.
 */
public static boolean handleInputShortcut(AppCompatActivity activity, EditText editText, int keyCode) {
    // Get selected text for cut and copy.
    int start = editText.getSelectionStart();
    int end = editText.getSelectionEnd();
    final String text = editText.getText().toString().substring(start, end);

    switch (keyCode) {
        case KeyEvent.KEYCODE_A:
            editText.selectAll();
            return true;
        case KeyEvent.KEYCODE_X:
            editText.setText(editText.getText().toString().replace(text, ""));
            return true;
        case KeyEvent.KEYCODE_C:
            ActivityServiceUtils.copyToClipboard(activity, text);
            return true;
        case KeyEvent.KEYCODE_V:
            editText.setText(
                    editText.getText().replace(Math.min(start, end), Math.max(start, end),
                            ActivityServiceUtils.pasteFromClipboard(activity), 0,
                            ActivityServiceUtils.pasteFromClipboard(activity).length()));
            return true;
        default:
            // Do nothing.
            return false;
    }
}
 
源代码13 项目: 365browser   文件: JavascriptAppModalDialog.java
@Override
protected void prepare(ViewGroup layout) {
    super.prepare(layout);
    EditText prompt = (EditText) layout.findViewById(R.id.js_modal_dialog_prompt);
    prompt.setVisibility(View.VISIBLE);

    if (mDefaultPromptText.length() > 0) {
        prompt.setText(mDefaultPromptText);
        prompt.selectAll();
    }
}
 
@Override
public void prepare(ViewGroup layout) {
    super.prepare(layout);
    EditText prompt = (EditText) layout.findViewById(R.id.js_modal_dialog_prompt);
    prompt.setVisibility(View.VISIBLE);

    if (mDefaultPromptText.length() > 0) {
        prompt.setText(mDefaultPromptText);
        prompt.selectAll();
    }
}
 
源代码15 项目: document-viewer   文件: GoToPageDialog.java
private void updateControls(final int viewIndex, final boolean updateBar) {
    final SeekBar seekbar = (SeekBar) findViewById(R.id.seekbar);
    final EditText editText = (EditText) findViewById(R.id.pageNumberTextEdit);

    editText.setText("" + (viewIndex + offset));
    editText.selectAll();

    if (updateBar) {
        seekbar.setProgress(viewIndex);
    }

    current = null;
}
 
源代码16 项目: mcumgr-android   文件: PartitionDialogFragment.java
@NonNull
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final LayoutInflater inflater = requireActivity().getLayoutInflater();
    final View view = inflater.inflate(R.layout.dialog_files_settings, null);
    final EditText partition = view.findViewById(R.id.partition);
    partition.setText(mFsUtils.getPartitionString());
    partition.selectAll();

    final AlertDialog dialog = new AlertDialog.Builder(requireContext())
            .setTitle(R.string.files_settings_title)
            .setView(view)
            // Setting the positive button listener here would cause the dialog to dismiss.
            // We have to validate the value before.
            .setPositiveButton(R.string.files_settings_action_save, null)
            .setNegativeButton(android.R.string.cancel, null)
            // Setting the neutral button listener here would cause the dialog to dismiss.
            .setNeutralButton(R.string.files_settings_action_restore, null)
            .create();
    dialog.setOnShowListener(d -> mImm.showSoftInput(partition, InputMethodManager.SHOW_IMPLICIT));

    // The neutral button should not dismiss the dialog.
    // We have to overwrite the default OnClickListener.
    // This can be done only after the dialog was shown.
    dialog.show();
    dialog.getButton(DialogInterface.BUTTON_NEUTRAL).setOnClickListener(v -> {
        final String defaultPartition = mFsUtils.getDefaultPartition();
        partition.setText(defaultPartition);
        partition.setSelection(defaultPartition.length());
    });
    dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(v -> {
        final String newPartition = partition.getText().toString().trim();
        if (!TextUtils.isEmpty(newPartition)) {
            mFsUtils.setPartition(newPartition);
            dismiss();
        } else {
            partition.setError(getString(R.string.files_settings_error));
        }
    });
    return dialog;
}
 
源代码17 项目: Kernel-Tuner   文件: OOM.java
private final void Dialog(String dialogTitle, String currentValue, final int option){
	AlertDialog.Builder builder = new AlertDialog.Builder(this);

	builder.setTitle(dialogTitle);

	builder.setMessage(getResources().getString(R.string.gov_new_value));

	builder.setIcon(isLight ? R.drawable.edit_light : R.drawable.edit_dark);


	final EditText input = new EditText(this);
	input.setHint(currentValue);
	input.selectAll();
	input.setInputType(InputType.TYPE_CLASS_NUMBER);
	input.setGravity(Gravity.CENTER_HORIZONTAL);

	builder.setPositiveButton(getResources().getString(R.string.apply), new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				switch(option){
				case 0:
					new setOOM().execute(Utility.mbToPages(Utility.parseInt(input.getText().toString(), 0)),
                               Utility.mbToPages(visibleSeek.getProgress()),
                               Utility.mbToPages(secondarySeek.getProgress()),
                               Utility.mbToPages(hiddenSeek.getProgress()),
                               Utility.mbToPages(contentSeek.getProgress()),
                               Utility.mbToPages(emptySeek.getProgress()));
					break;
				case 1:
					new setOOM().execute(Utility.mbToPages(foregroundSeek.getProgress()),
                               Utility.mbToPages(Utility.parseInt(input.getText().toString(), 0)),
                               Utility.mbToPages(secondarySeek.getProgress()),
                               Utility.mbToPages(hiddenSeek.getProgress()),
                               Utility.mbToPages(contentSeek.getProgress()),
                               Utility.mbToPages(emptySeek.getProgress()));
					break;
				case 2:
					new setOOM().execute(Utility.mbToPages(foregroundSeek.getProgress()),
                               Utility.mbToPages(visibleSeek.getProgress()),
                               Utility.mbToPages(Utility.parseInt(input.getText().toString(), 0)),
                               Utility.mbToPages(hiddenSeek.getProgress()),
                               Utility.mbToPages(contentSeek.getProgress()),
                               Utility.mbToPages(emptySeek.getProgress()));
					break;
				case 3:
					new setOOM().execute(Utility.mbToPages(foregroundSeek.getProgress()),
                               Utility.mbToPages(visibleSeek.getProgress()),
                               Utility.mbToPages(secondarySeek.getProgress()),
                               Utility.mbToPages(Utility.parseInt(input.getText().toString(), 0)),
                               Utility.mbToPages(contentSeek.getProgress()),
                               Utility.mbToPages(emptySeek.getProgress()));
					break;
				case 4:
					new setOOM().execute(Utility.mbToPages(foregroundSeek.getProgress()),
                               Utility.mbToPages(visibleSeek.getProgress()),
                               Utility.mbToPages(secondarySeek.getProgress()),
                               Utility.mbToPages(hiddenSeek.getProgress()),
                               Utility.mbToPages(Utility.parseInt(input.getText().toString(), 0)),
                               Utility.mbToPages(emptySeek.getProgress()));
					break;
				case 5:
					new setOOM().execute(Utility.mbToPages(foregroundSeek.getProgress()),
                               Utility.mbToPages(visibleSeek.getProgress()),
                               Utility.mbToPages(secondarySeek.getProgress()),
                               Utility.mbToPages(hiddenSeek.getProgress()),
                               Utility.mbToPages(contentSeek.getProgress()),
                               Utility.mbToPages(Utility.parseInt(input.getText().toString(), 0)));
					break;
					
				}
				

				
				
			}
		});
	builder.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener(){

			@Override
			public void onClick(DialogInterface arg0, int arg1)
			{
				

			}

		});
	builder.setView(input);

	AlertDialog alert = builder.create();

	alert.show();
}
 
源代码18 项目: SuperNote   文件: RvEditFolderAdapter.java
private void editItem(BaseViewHolder helper){
    EditFolderConstans.isNewFolder=false;
    EditText editText=(EditText)helper.getView(R.id.et_edit_folder_name);
    editText.selectAll();
    setFoucus(editText);
}
 
源代码19 项目: fastnfitness   文件: EditableInputViewWithDate.java
@Override
protected void editDialog(Context context) {
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
        LinearLayout.LayoutParams.MATCH_PARENT,
        LinearLayout.LayoutParams.WRAP_CONTENT
    );

    final TextView editDate = new TextView(getContext());
    date = DateConverter.getNewDate();
    editDate.setLayoutParams(params);
    editDate.setText(DateConverter.dateToLocalDateStr(date, getContext()));
    editDate.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
    editDate.setGravity(Gravity.CENTER);
    editDate.setOnClickListener((view) -> {
            Calendar calendar = Calendar.getInstance();

            calendar.setTime(DateConverter.getNewDate());
            int day = calendar.get(Calendar.DAY_OF_MONTH);
            int month = calendar.get(Calendar.MONTH);
            int year = calendar.get(Calendar.YEAR);

            DatePickerDialog datePickerDialog = new DatePickerDialog(getContext(), getEditableInputViewWithDate(), year, month, day);
            dateEditView = editDate;
            datePickerDialog.show();
    });

    final EditText editText = new EditText(context);
    if (getText().contentEquals("-")) {
        editText.setText("");
        editText.setHint("Enter value here");
    } else {
        editText.setText(getText());
    }
    editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
    editText.setGravity(Gravity.CENTER);
    editText.setLayoutParams(params);
    editText.requestFocus();
    editText.selectAll();

    LinearLayout linearLayout = new LinearLayout(getContext().getApplicationContext());

    linearLayout.setLayoutParams(params);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.addView(editDate);
    linearLayout.addView(editText);

    final SweetAlertDialog dialog = new SweetAlertDialog(context, SweetAlertDialog.NORMAL_TYPE)
        .setTitleText(mTitle)
        .showCancelButton(true)
        .setCancelClickListener(sDialog -> {
            editText.clearFocus();
            Keyboard.hide(context, editText);
            sDialog.dismissWithAnimation();})
        .setCancelText(getContext().getString(R.string.global_cancel))
        .setConfirmText(getContext().getString(R.string.AddLabel))
        .setConfirmClickListener(sDialog -> {
            Keyboard.hide(sDialog.getContext(), editText);
            setText(editText.getText().toString());
            if (mConfirmClickListener != null)
                mConfirmClickListener.onTextChanged(EditableInputViewWithDate.this);
            sDialog.dismissWithAnimation();
        });
    dialog.setCustomView(linearLayout);
    dialog.setOnShowListener(sDialog -> Keyboard.show(getContext(), editText));
    dialog.show();
}
 
源代码20 项目: fastnfitness   文件: BodyPartDetailsFragment.java
@Override
public void onClick(View v) {
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
        LinearLayout.LayoutParams.MATCH_PARENT,
        LinearLayout.LayoutParams.WRAP_CONTENT
    );

    editDate = new TextView(getContext());
    Date date = DateConverter.getNewDate();
    editDate.setLayoutParams(params);
    editDate.setText(DateConverter.dateToLocalDateStr(date, getContext()));
    editDate.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
    editDate.setGravity(Gravity.CENTER);
    editDate.setOnClickListener((view) -> {
        Calendar calendar = Calendar.getInstance();

        calendar.setTime(DateConverter.getNewDate());
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        int month = calendar.get(Calendar.MONTH);
        int year = calendar.get(Calendar.YEAR);

        DatePickerDialog datePickerDialog = new DatePickerDialog(getContext(), getBodyPartDetailsFragment(), year, month, day);

        datePickerDialog.show();
    });

    editText = new EditText(getContext());
    editText.setText("");
    editText.setHint("Enter value here");
    editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
    editText.setGravity(Gravity.CENTER);
    editText.setLayoutParams(params);
    editText.requestFocus();
    editText.selectAll();

    LinearLayout linearLayout = new LinearLayout(getContext().getApplicationContext());

    linearLayout.setLayoutParams(params);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.addView(editDate);
    linearLayout.addView(editText);

    final SweetAlertDialog dialog = new SweetAlertDialog(getContext(), SweetAlertDialog.NORMAL_TYPE)
        .setTitleText(getString(R.string.new_measure))
        .showCancelButton(true)
        .setCancelClickListener(sDialog -> {
            editText.clearFocus();
            Keyboard.hide(getContext(), editText);
            sDialog.dismissWithAnimation();})
        .setCancelText(getContext().getString(R.string.global_cancel))
        .setConfirmText(getContext().getString(R.string.AddLabel))
        .setConfirmClickListener(sDialog -> {
            Keyboard.hide(sDialog.getContext(), editText);
            float value = 0;
            try {
                value = Float.parseFloat(editText.getText().toString());
                Date lDate = DateConverter.localDateStrToDate(editDate.getText().toString(), getContext());
                mBodyMeasureDb.addBodyMeasure(lDate, mInitialBodyPart.getId(), value, getProfile().getId());
                refreshData();
            } catch (Exception e) {
                KToast.errorToast(getActivity(),"Format Error", Gravity.BOTTOM, KToast.LENGTH_SHORT);
            }

            sDialog.dismissWithAnimation();
        });
    dialog.setCustomView(linearLayout);
    dialog.setOnShowListener(sDialog -> Keyboard.show(getContext(), editText));
    dialog.show();
}