Example usage for android.widget EditText EditText

List of usage examples for android.widget EditText EditText

Introduction

In this page you can find the example usage for android.widget EditText EditText.

Prototype

public EditText(Context context) 

Source Link

Usage

From source file:im.vector.fragments.VectorSettingsPreferencesFragment.java

/**
 * Display an alert dialog to rename a device
 *
 * @param aDeviceInfoToRename device info
 *//*from w w  w. jav a2s .  com*/
private void displayDeviceRenameDialog(final DeviceInfo aDeviceInfoToRename) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.devices_details_device_name);

    final EditText input = new EditText(getActivity());
    input.setText(aDeviceInfoToRename.display_name);
    builder.setView(input);

    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            displayLoadingView();

            mSession.setDeviceName(aDeviceInfoToRename.device_id, input.getText().toString(),
                    new ApiCallback<Void>() {
                        @Override
                        public void onSuccess(Void info) {
                            // search which preference is updated
                            int count = mDevicesListSettingsCategory.getPreferenceCount();

                            for (int i = 0; i < count; i++) {
                                VectorCustomActionEditTextPreference pref = (VectorCustomActionEditTextPreference) mDevicesListSettingsCategory
                                        .getPreference(i);

                                if (TextUtils.equals(aDeviceInfoToRename.device_id, pref.getTitle())) {
                                    pref.setSummary(input.getText());
                                }
                            }

                            // detect if the updated device is the current account one
                            Preference pref = findPreference(
                                    PreferencesManager.SETTINGS_ENCRYPTION_INFORMATION_DEVICE_ID_PREFERENCE_KEY);
                            if (TextUtils.equals(pref.getSummary(), aDeviceInfoToRename.device_id)) {
                                findPreference(
                                        PreferencesManager.SETTINGS_ENCRYPTION_INFORMATION_DEVICE_ID_PREFERENCE_KEY)
                                                .setSummary(input.getText());
                            }

                            hideLoadingView();
                        }

                        @Override
                        public void onNetworkError(Exception e) {
                            onCommonDone(e.getLocalizedMessage());
                        }

                        @Override
                        public void onMatrixError(MatrixError e) {
                            onCommonDone(e.getLocalizedMessage());
                        }

                        @Override
                        public void onUnexpectedError(Exception e) {
                            onCommonDone(e.getLocalizedMessage());
                        }
                    });
        }
    });
    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    builder.show();
}

From source file:com.guardtrax.ui.screens.HomeScreen.java

private void show_username_dialog() {
    AlertDialog.Builder dialog = new AlertDialog.Builder(HomeScreen.this);
    dialog.setTitle("User name: " + GTConstants.report_name);
    dialog.setMessage("Enter your name");
    final EditText input = new EditText(this);
    dialog.setView(input);//from  w w  w  .ja v a2  s  .  c o  m

    dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            //store in GTConstants for current use
            GTConstants.report_name = input.getText().toString().trim();

            //store in preferences for later use
            SharedPreferences settings = getSharedPreferences("GTPrefs", 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString("userName", GTConstants.report_name);
            editor.commit();

            setuserBanner();
        }
    });

    //if no email to be sent then exit
    dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {

        }
    });
    dialog.show();
}

From source file:com.guardtrax.ui.screens.HomeScreen.java

private void show_license_dialog() {
    AlertDialog.Builder dialog = new AlertDialog.Builder(HomeScreen.this);
    dialog.setTitle("Traffic Violation Database");
    dialog.setMessage("Enter Plate #");
    final EditText input = new EditText(this);
    dialog.setView(input);/*from   w w  w .  j  a  v a 2s  .  c  o  m*/

    dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Cursor c = Utility.getTrafficViolations(HomeScreen.this, input.getText().toString().trim());

            show_alert_title = "License Plate: " + input.getText().toString().trim().toUpperCase();
            if (c != null && c.moveToFirst()) {
                show_alert_message = "State: " + c.getString(1) + CRLF;
                show_alert_message = show_alert_message + "Number of Violations: " + c.getString(5) + CRLF;
                show_alert_message = show_alert_message + "Last Violation: " + c.getString(4) + CRLF;
                show_alert_message = show_alert_message + "Days since last violation: "
                        + Utility.getdayssincelastViolation(HomeScreen.this, input.getText().toString().trim());
            } else
                show_alert_message = "No Recorded Violations";

            showAlert(show_alert_title, show_alert_message, true);
        }
    });

    //if no email to be sent then exit
    dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {

        }
    });
    dialog.show();
}

From source file:com.rfo.basic.Run.java

private void doInputDialog(DialogArgs args) {
    Context context = getContext();
    Log.d(LOGTAG, "InputDialog context " + context);

    EditText text = new EditText(context);
    text.setText(args.mInputDefault);//w w  w . j a v a  2  s.c om
    Var.Val returnVal = args.mReturnVal;
    if (returnVal.isNumeric()) {
        text.setInputType(0x00003002); // Limits keys to signed decimal numbers
    }
    String btnLabel = args.mButton1;
    if (btnLabel == null) {
        btnLabel = "Ok";
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setView(text).setCancelable(true).setTitle(args.mTitle) // default null, no title displayed if null or empty
            .setPositiveButton(btnLabel, null); // need to override default View click handler to prevent
    // auto-dismiss, but can't do it until after show()

    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            Log.d(LOGTAG, "Input Dialog onCancel");
            mInputCancelled = true; // signal read by executeINPUT
        }
    });

    final AlertDialog dialog = builder.create();
    dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
        public void onDismiss(DialogInterface dialog) {
            Log.d(LOGTAG, "Input Dialog onDismiss");
            releaseLOCK(); // release the lock that executeINPUT is waiting for
        }
    });
    dialog.getWindow().setSoftInputMode(android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    dialog.show();
    dialog.getButton(DialogInterface.BUTTON_POSITIVE) // now we can replace the View click listener
            .setOnClickListener(new InputDialogClickListener(dialog, text, args)); // to prevent auto-dismiss
}

From source file:com.android.launcher3.Launcher.java

@Override
public boolean onLongClick(View v) {
    if (!isDraggingEnabled())
        return false;
    if (isWorkspaceLocked())
        return false;
    if (mState != State.WORKSPACE)
        return false;

    if (creation != null)
        creation.clearAllLayout();// ww  w  .j a va 2 s  .c  om

    if ((FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && v instanceof PageIndicator)
            || (v == mAllAppsButton && mAllAppsButton != null)) {
        onLongClickAllAppsButton(v);
        return true;
    }

    if (v instanceof Workspace) {
        if (!mWorkspace.isInOverviewMode()) {
            if (!mWorkspace.isTouchActive()) {
                showOverviewMode(true);
                mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
                        HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

    CellLayout.CellInfo longClickCellInfo = null;
    View itemUnderLongClick = null;
    if (v.getTag() instanceof ItemInfo) {
        ItemInfo info = (ItemInfo) v.getTag();
        longClickCellInfo = new CellLayout.CellInfo(v, info);
        itemUnderLongClick = longClickCellInfo.cell;
        mPendingRequestArgs = null;
    }

    // The hotseat touch handling does not go through Workspace, and we always allow long press
    // on hotseat items.
    if (!mDragController.isDragging()) {
        if (itemUnderLongClick == null) {
            // User long pressed on empty space
            mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
                    HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
            if (mWorkspace.isInOverviewMode()) {
                mWorkspace.startReordering(v);
            } else {
                showOverviewMode(true);
            }
        } else {
            final boolean isAllAppsButton = !FeatureFlags.NO_ALL_APPS_ICON && isHotseatLayout(v)
                    && mDeviceProfile.inv.isAllAppsButtonRank(
                            mHotseat.getOrderInHotseat(longClickCellInfo.cellX, longClickCellInfo.cellY));
            if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
                // User long pressed on an item
                DragOptions dragOptions = new DragOptions();
                if (itemUnderLongClick instanceof BubbleTextView) {
                    BubbleTextView icon = (BubbleTextView) itemUnderLongClick;
                    if (icon.hasDeepShortcuts()) {
                        DeepShortcutsContainer dsc = DeepShortcutsContainer.showForIcon(icon);
                        if (dsc != null) {
                            dragOptions.deferDragCondition = dsc.createDeferDragCondition(null);
                        }
                    }
                }

                int positionInGrid = mHotseat.getOrderInHotseat(longClickCellInfo.cellX,
                        longClickCellInfo.cellY);

                List<Shortcuts> shortcutses = new ArrayList<Shortcuts>();

                if (creation != null)
                    creation.clearAllLayout();

                mWorkspace.startDrag(longClickCellInfo, dragOptions);

                //Get selected app info
                final Object tag = v.getTag();
                final ShortcutInfo shortcut;
                try {
                    shortcut = (ShortcutInfo) tag;
                    Drawable icon;
                    if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(),
                            shortcut.getTargetComponent().getPackageName()) != null) {
                        icon = new BitmapDrawable(activity.getResources(), Utilities.loadBitmapPref(activity,
                                shortcut.getTargetComponent().getPackageName()));
                    } else {
                        icon = new BitmapDrawable(activity.getResources(),
                                shortcut.getIcon(new IconCache(Launcher.this, getDeviceProfile().inv)));
                    }

                    shortcutses = ShortcutsManager.getShortcutsBasedOnTag(Launcher.this.getApplicationContext(),
                            Launcher.this, shortcut, icon);
                    ShortcutsBuilder builder = new ShortcutsBuilder.Builder(this, masterLayout)
                            .launcher3Shortcuts(gridSize, positionInGrid, (int) v.getY(), v.getBottom(),
                                    Hotseat.isHotseatTouched,
                                    Utilities.getDockSizeDefaultValue(getApplicationContext()))
                            .setOptionLayoutStyle(StyleOption.NONE).setPackageImage(icon)
                            .setShortcutsList(shortcutses).build();

                    creation = new ShortcutsCreation(builder);

                    creation.init();

                    Hotseat.isHotseatTouched = false;

                } catch (ClassCastException e) {
                    Log.e(TAG, "Clicked on Folder/Widget!");
                    positionInGrid = mHotseat.getOrderInHotseat(longClickCellInfo.cellX,
                            longClickCellInfo.cellY);
                    try {
                        //Get selected folder info
                        final View f = v;
                        final Object tagF = v.getTag();
                        final FolderInfo folder;
                        folder = (FolderInfo) tagF;

                        shortcutses = new ArrayList<Shortcuts>();
                        shortcutses.add(new Shortcuts(R.drawable.ic_folder_open_black_24dp,
                                getString(R.string.folder_open), new OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        if (f instanceof FolderIcon) {
                                            onClickFolderIcon(f);
                                            creation.clearAllLayout();
                                        }
                                    }
                                }));
                        shortcutses.add(new Shortcuts(R.drawable.ic_title_black_24dp,
                                getString(R.string.folder_rename), new OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        if (f instanceof FolderIcon) {
                                            AlertDialog.Builder alert = new AlertDialog.Builder(
                                                    new ContextThemeWrapper(Launcher.this,
                                                            R.style.AlertDialogCustom));
                                            LinearLayout layout = new LinearLayout(getApplicationContext());
                                            layout.setOrientation(LinearLayout.VERTICAL);
                                            layout.setPadding(100, 50, 100, 100);

                                            final EditText titleBox = new EditText(Launcher.this);

                                            titleBox.getBackground().mutate()
                                                    .setColorFilter(
                                                            ContextCompat.getColor(getApplicationContext(),
                                                                    R.color.colorPrimary),
                                                            PorterDuff.Mode.SRC_ATOP);
                                            alert.setMessage(getString(R.string.folder_title));
                                            alert.setTitle(getString(R.string.folder_enter_title));

                                            layout.addView(titleBox);
                                            alert.setView(layout);

                                            alert.setPositiveButton(getString(R.string.ok),
                                                    new DialogInterface.OnClickListener() {
                                                        public void onClick(DialogInterface dialog,
                                                                int whichButton) {
                                                            folder.setTitle(titleBox.getText().toString());
                                                            LauncherModel.updateItemInDatabase(
                                                                    Launcher.getLauncherActivity(), folder);
                                                        }
                                                    });

                                            alert.setNegativeButton(getString(R.string.cancel),
                                                    new DialogInterface.OnClickListener() {
                                                        public void onClick(DialogInterface dialog,
                                                                int whichButton) {
                                                            creation.clearAllLayout();
                                                        }
                                                    });
                                            alert.show();
                                            creation.clearAllLayout();
                                        }
                                    }
                                }));

                        ShortcutsBuilder builder = new ShortcutsBuilder.Builder(this, masterLayout)
                                .launcher3Shortcuts(gridSize, positionInGrid, (int) v.getY(), v.getBottom(),
                                        Hotseat.isHotseatTouched,
                                        Utilities.getDockSizeDefaultValue(getApplicationContext()))
                                .setOptionLayoutStyle(0)
                                .setPackageImage(
                                        ContextCompat.getDrawable(Launcher.this, R.mipmap.ic_launcher_home))
                                .setShortcutsList(shortcutses).build();

                        creation = new ShortcutsCreation(builder);

                        creation.init();
                    } catch (ClassCastException ee) {
                    }
                }
            }
        }
    }
    return true;
}

From source file:com.guardtrax.ui.screens.HomeScreen.java

private void send_media_via_email(final String type) {
    //only send email if "allowed"
    if (Utility.allowSend(HomeScreen.this)) {
        AlertDialog.Builder dialog = new AlertDialog.Builder(HomeScreen.this);
        dialog.setTitle("email the media?");
        dialog.setMessage("Enter Email address");
        final EditText input = new EditText(this);
        dialog.setView(input);//from w  w  w .j a  va2 s .  c  o  m

        dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                String emailAddress = input.getText().toString().trim();
                File current_file = new File(file_name);
                //String attachment = GTConstants.receivefileFolder + current_file.getName();
                ArrayList<String> mediaList = new ArrayList<String>();
                mediaList.add(GTConstants.receivefileFolder + current_file.getName());

                if (type.equalsIgnoreCase("audio"))
                    Utility.send_email(HomeScreen.this, emailAddress, mediaList, "audio",
                            "email from GT android App",
                            "This email is being sent directly from the GuardTrax - Android App");
                if (type.equalsIgnoreCase("photo"))
                    Utility.send_email(HomeScreen.this, emailAddress, mediaList, "photo",
                            "email from GT android App",
                            "This email is being sent directly from the GuardTrax - Android App");
                if (type.equalsIgnoreCase("video"))
                    Utility.send_email(HomeScreen.this, emailAddress, mediaList, "video",
                            "email from GT android App",
                            "This email is being sent directly from the GuardTrax - Android App");
            }
        });

        //if no email to be sent then exit
        dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

            }
        });
        dialog.show();
    }
}

From source file:com.example.libwidgettv.bak.AbsListView.java

/**
 * Creates the window for the text filter and populates it with an EditText
 * field;//from w  w  w  .j  av a 2s.  c om
 * 
 * @param animateEntrance
 *            true if the window should appear with an animation
 */
private void createTextFilter(boolean animateEntrance) {
    if (mPopup == null) {
        Context c = getContext();
        PopupWindow p = new PopupWindow(c);
        LayoutInflater layoutInflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        // mTextFilter = (EditText) layoutInflater.inflate(
        // com.android.internal.R.layout.typing_filter, null);
        mTextFilter = new EditText(getContext());
        // For some reason setting this as the "real" input type changes
        // the text view in some way that it doesn't work, and I don't
        // want to figure out why this is.
        mTextFilter.setRawInputType(EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_FILTER);
        mTextFilter.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
        mTextFilter.addTextChangedListener(this);
        p.setFocusable(false);
        p.setTouchable(false);
        p.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
        p.setContentView(mTextFilter);
        p.setWidth(LayoutParams.WRAP_CONTENT);
        p.setHeight(LayoutParams.WRAP_CONTENT);
        p.setBackgroundDrawable(null);
        mPopup = p;
        getViewTreeObserver().addOnGlobalLayoutListener(this);
        mGlobalLayoutListenerAddedFilter = true;
    }
    // if (animateEntrance) {
    // mPopup.setAnimationStyle(com.android.internal.R.style.Animation_TypingFilter);
    // } else {
    // mPopup.setAnimationStyle(com.android.internal.R.style.Animation_TypingFilterRestore);
    // }
}

From source file:com.nttec.everychan.ui.presentation.BoardFragment.java

private void runReport(final DeletePostModel reportPostModel) {
    final EditText inputField = new EditText(activity);
    inputField.setSingleLine();/* w  w w . ja  va 2 s  . c om*/
    if (presentationModel.source.boardModel.allowReport != BoardModel.REPORT_WITH_COMMENT) {
        inputField.setEnabled(false);
        inputField.setKeyListener(null);
    } else {
        inputField.setText(reportPostModel.reportReason == null ? "" : reportPostModel.reportReason);
    }

    DialogInterface.OnClickListener dlgOnClick = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            if (currentTask != null)
                currentTask.cancel();
            if (pullableLayout.isRefreshing())
                setPullableNoRefreshing();
            reportPostModel.reportReason = inputField.getText().toString();
            final ProgressDialog progressDlg = new ProgressDialog(activity);
            final CancellableTask reportTask = new CancellableTask.BaseCancellableTask();
            progressDlg.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    reportTask.cancel();
                }
            });
            progressDlg.setCanceledOnTouchOutside(false);
            progressDlg.setMessage(resources.getString(R.string.dialog_report_progress));
            progressDlg.show();
            Async.runAsync(new Runnable() {
                @Override
                public void run() {
                    String error = null;
                    String targetUrl = null;
                    if (reportTask.isCancelled())
                        return;
                    try {
                        targetUrl = chan.reportPost(reportPostModel, null, reportTask);
                    } catch (Exception e) {
                        if (e instanceof InteractiveException) {
                            if (reportTask.isCancelled())
                                return;
                            ((InteractiveException) e).handle(activity, reportTask,
                                    new InteractiveException.Callback() {
                                        @Override
                                        public void onSuccess() {
                                            if (!reportTask.isCancelled()) {
                                                progressDlg.dismiss();
                                                onClick(dialog, which);
                                            }
                                        }

                                        @Override
                                        public void onError(String message) {
                                            if (!reportTask.isCancelled()) {
                                                progressDlg.dismiss();
                                                Toast.makeText(activity, message, Toast.LENGTH_LONG).show();
                                                runReport(reportPostModel);
                                            }
                                        }
                                    });
                            return;
                        }

                        Logger.e(TAG, "cannot report post", e);
                        error = e.getMessage() == null ? "" : e.getMessage();
                    }
                    if (reportTask.isCancelled())
                        return;
                    final boolean success = error == null;
                    final String result = success ? targetUrl : error;
                    Async.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            if (reportTask.isCancelled())
                                return;
                            progressDlg.dismiss();
                            if (success) {
                                if (result == null) {
                                    update();
                                } else {
                                    UrlHandler.open(result, activity);
                                }
                            } else {
                                Toast.makeText(activity,
                                        TextUtils.isEmpty(result) ? resources.getString(R.string.error_unknown)
                                                : result,
                                        Toast.LENGTH_LONG).show();
                            }
                        }
                    });
                }
            });
        }
    };
    new AlertDialog.Builder(activity).setTitle(R.string.dialog_report_reason).setView(inputField)
            .setPositiveButton(R.string.dialog_report_button, dlgOnClick)
            .setNegativeButton(android.R.string.cancel, null).create().show();
}

From source file:jmri.enginedriver.throttle.java

private void showTimerPasswordDialog() {

    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle(getApplicationContext().getResources().getString(R.string.timerDialogTitle));
    alert.setMessage(getApplicationContext().getResources().getString(R.string.timerDialogMessage));

    // Set an EditText view to get user input
    final EditText input = new EditText(this);
    input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    input.setHint(getApplicationContext().getResources().getString(R.string.timerDialogHint));
    alert.setView(input);/*from   w w  w  .j av  a 2s . co m*/

    alert.setPositiveButton(getApplicationContext().getResources().getString(R.string.ok),
            new DialogInterface.OnClickListener() {
                @SuppressLint("ApplySharedPref")
                public void onClick(DialogInterface dialog, int whichButton) {
                    passwordText = input.getText().toString();
                    Log.d("", "Password Value : " + passwordText);

                    if (passwordText.equals(prefKidsTimerResetPassword)) { //reset
                        kidsTimerActions(KIDS_TIMER_ENDED, 0);
                        kidsTimerActions(KIDS_TIMER_DISABLED, 0);
                        prefs.edit().putString("prefKidsTimer", PREF_KIDS_TIMER_NONE).commit(); //reset the preference
                        getKidsTimerPrefs();
                    }

                    if (passwordText.equals(prefKidsTimerRestartPassword)) { //reset
                        kidsTimerActions(KIDS_TIMER_ENABLED, 0);
                    }

                    //                return;
                }
            });

    alert.setNegativeButton(getApplicationContext().getResources().getString(R.string.cancel),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    //                        return;
                }
            });
    alert.show();

}