Java Code Examples for android.widget.EditText#selectAll()

The following examples show how to use android.widget.EditText#selectAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: APDE.java    From APDE with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: RecentActivityController.java    From document-viewer with GNU General Public License v3.0 6 votes vote down vote up
@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();
}
 
Example 3
Source File: ViewerActivityController.java    From document-viewer with GNU General Public License v3.0 6 votes vote down vote up
@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();
}
 
Example 4
Source File: BrowserActivityController.java    From document-viewer with GNU General Public License v3.0 6 votes vote down vote up
@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();
}
 
Example 5
Source File: Form.java    From FormValidations with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 6
Source File: SlideTabsActivity.java    From GPS2SMS with GNU General Public License v3.0 6 votes vote down vote up
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;
    }
}
 
Example 7
Source File: ClientWebView.java    From habpanelviewer with GNU General Public License v3.0 6 votes vote down vote up
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();
}
 
Example 8
Source File: JavascriptAppModalDialog.java    From delion with Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 9
Source File: JavascriptAppModalDialog.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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();
    }
}
 
Example 10
Source File: JavascriptAppModalDialog.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 11
Source File: Utils.java    From HgLauncher with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 12
Source File: JavascriptAppModalDialog.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 13
Source File: Utils.java    From HgLauncher with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 14
Source File: JavascriptAppModalDialog.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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();
    }
}
 
Example 15
Source File: GoToPageDialog.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 16
Source File: EditableInputViewWithDate.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@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();
}
 
Example 17
Source File: BodyPartDetailsFragment.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@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();
}
 
Example 18
Source File: RvEditFolderAdapter.java    From SuperNote with GNU General Public License v3.0 4 votes vote down vote up
private void editItem(BaseViewHolder helper){
    EditFolderConstans.isNewFolder=false;
    EditText editText=(EditText)helper.getView(R.id.et_edit_folder_name);
    editText.selectAll();
    setFoucus(editText);
}
 
Example 19
Source File: OOM.java    From Kernel-Tuner with GNU General Public License v3.0 4 votes vote down vote up
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();
}
 
Example 20
Source File: PartitionDialogFragment.java    From mcumgr-android with Apache License 2.0 4 votes vote down vote up
@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;
}