Example usage for android.widget EditText getText

List of usage examples for android.widget EditText getText

Introduction

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

Prototype

@Override
    public Editable getText() 

Source Link

Usage

From source file:be.brunoparmentier.wifikeyshare.ui.activities.WifiNetworkActivity.java

void showWifiPasswordDialog() {
    final LayoutInflater inflater = getLayoutInflater();
    final View wifiPasswordDialogLayout = inflater.inflate(R.layout.dialog_wifi_password, null);

    final TextInputLayout wifiPasswordWrapper = (TextInputLayout) wifiPasswordDialogLayout
            .findViewById(R.id.wifi_key_wrapper);
    final EditText passwordEditText = (EditText) wifiPasswordDialogLayout.findViewById(R.id.wifi_key);
    //setPasswordRestrictions(passwordEditText);
    final CheckBox showPasswordCheckBox = (CheckBox) wifiPasswordDialogLayout
            .findViewById(R.id.show_password_checkbox);
    showPasswordCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override//from  w w w  . j ava  2  s .  c om
        public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
            int selectionIndex = passwordEditText.getSelectionStart();
            if (isChecked) {
                passwordEditText.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
            } else {
                passwordEditText
                        .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
            }
            passwordEditText.setSelection(selectionIndex);
        }
    });

    final AlertDialog wifiPasswordDialog = new AlertDialog.Builder(this)
            .setTitle(getString(R.string.wifi_dialog_password_title))
            .setMessage(String.format(getString(R.string.wifi_dialog_password_msg), wifiNetwork.getSsid()))
            .setView(wifiPasswordDialogLayout)
            .setPositiveButton(getString(R.string.action_ok), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    // this method gets overriden after we show the dialog
                }
            }).setNegativeButton(getString(R.string.action_cancel), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    finish();
                }
            }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialogInterface) {
                    finish();
                }
            }).create();

    passwordEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            wifiPasswordDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(editable.length() >= 5);
            if (wifiPasswordWrapper.getError() != null) {
                try {
                    if (WifiNetwork.isValidKeyLength(wifiNetwork.getAuthType(), editable.toString())) {
                        wifiPasswordWrapper.setError(null);
                    }
                } catch (final WifiException e) {
                    switch (e.getErrorCode()) {
                    case WifiException.WEP_KEY_LENGTH_ERROR:
                        wifiPasswordWrapper.setError(getString(R.string.error_wep_password_length));
                        break;
                    case WifiException.WPA_KEY_LENGTH_ERROR:
                        wifiPasswordWrapper.setError(getString(R.string.error_wpa_password_length));
                        break;
                    default:
                        wifiPasswordWrapper.setError(e.getMessage());
                        break;
                    }
                }
            }
        }
    });

    wifiPasswordDialog.show();

    wifiPasswordDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false); // disabled by default
    wifiPasswordDialog.getButton(DialogInterface.BUTTON_POSITIVE)
            .setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    try {
                        if (WifiNetwork.isValidKeyLength(wifiNetwork.getAuthType(),
                                passwordEditText.getText().toString())) {

                            wifiPasswordWrapper.setError(null);
                            wifiNetwork.setKey(passwordEditText.getText().toString());

                            // Update QR code image
                            FragmentManager fm = getSupportFragmentManager();
                            QrCodeFragment qrCodeFragment = (QrCodeFragment) fm.getFragments().get(0);
                            qrCodeFragment.updateQrCode(wifiNetwork);

                            WifiKeysDataSource.getInstance().insertWifiKey(wifiNetwork);

                            Intent passwordResultIntent = new Intent();
                            passwordResultIntent.putExtra(KEY_NETWORK_ID, wifiNetworkId);
                            setResult(RESULT_OK, passwordResultIntent);

                            wifiPasswordDialog.dismiss();
                        }
                    } catch (WifiException e) {
                        switch (e.getErrorCode()) {
                        case WifiException.WEP_KEY_LENGTH_ERROR:
                            wifiPasswordWrapper.setError(getString(R.string.error_wep_password_length));
                            break;
                        case WifiException.WPA_KEY_LENGTH_ERROR:
                            wifiPasswordWrapper.setError(getString(R.string.error_wpa_password_length));
                            break;
                        default:
                            wifiPasswordWrapper.setError(null);
                            break;
                        }
                    }
                }
            });
}

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 .j  a va  2s  .  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:edu.mit.viral.shen.DroidFish.java

private final Dialog networkEngineConfigDialog() {
    View content = View.inflate(this, R.layout.network_engine_config, null);
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(content);//www. j a v  a  2 s.  c o  m
    builder.setTitle(R.string.configure_network_engine);
    final EditText hostNameView = (EditText) content.findViewById(R.id.network_engine_host);
    final EditText portView = (EditText) content.findViewById(R.id.network_engine_port);
    String hostName = "";
    String port = "0";
    try {
        String[] lines = Util.readFile(networkEngineToConfig);
        if ((lines.length >= 1) && lines[0].equals("NETE")) {
            if (lines.length > 1)
                hostName = lines[1];
            if (lines.length > 2)
                port = lines[2];
        }
    } catch (IOException e1) {
    }
    hostNameView.setText(hostName);
    portView.setText(port);
    final Runnable writeConfig = new Runnable() {
        public void run() {
            String hostName = hostNameView.getText().toString();
            String port = portView.getText().toString();
            try {
                FileWriter fw = new FileWriter(new File(networkEngineToConfig), false);
                fw.write("NETE\n");
                fw.write(hostName);
                fw.write("\n");
                fw.write(port);
                fw.write("\n");
                fw.close();
                setEngineOptions(true);
            } catch (IOException e) {
                Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
            }
        }
    };
    builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            writeConfig.run();
            removeDialog(NETWORK_ENGINE_DIALOG);
            showDialog(NETWORK_ENGINE_DIALOG);
        }
    });
    builder.setNegativeButton(R.string.cancel, new Dialog.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            removeDialog(NETWORK_ENGINE_DIALOG);
            showDialog(NETWORK_ENGINE_DIALOG);
        }
    });
    builder.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            removeDialog(NETWORK_ENGINE_DIALOG);
            showDialog(NETWORK_ENGINE_DIALOG);
        }
    });
    builder.setNeutralButton(R.string.delete, new Dialog.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            removeDialog(DELETE_NETWORK_ENGINE_DIALOG);
            showDialog(DELETE_NETWORK_ENGINE_DIALOG);
        }
    });

    final Dialog dialog = builder.create();
    portView.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                writeConfig.run();
                dialog.cancel();
                removeDialog(NETWORK_ENGINE_DIALOG);
                showDialog(NETWORK_ENGINE_DIALOG);
                return true;
            }
            return false;
        }
    });
    return dialog;
}

From source file:com.lgallardo.qbittorrentclient.RefreshListener.java

private void addUrlTorrent() {

    // get prompts.xml view
    LayoutInflater li = LayoutInflater.from(MainActivity.this);
    View addTorrentView = li.inflate(R.layout.add_torrent, null);

    // URL input/*  w w  w  . j av a  2 s.  com*/
    final EditText urlInput = (EditText) addTorrentView.findViewById(R.id.url);

    if (!isFinishing()) {
        // Dialog
        Builder builder = new Builder(MainActivity.this);

        // Set add_torrent.xml to AlertDialog builder
        builder.setView(addTorrentView);

        // Cancel
        builder.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                // User cancelled the dialog
            }
        });

        // Ok
        builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                // User accepted the dialog
                addTorrent(urlInput.getText().toString());
            }
        });

        // Create dialog
        AlertDialog dialog = builder.create();

        // Show dialog
        dialog.show();
    }

}

From source file:com.lgallardo.qbittorrentclient.RefreshListener.java

public void setLabelDialog(final String hash) {

    // get prompts.xml view
    LayoutInflater li = LayoutInflater.from(MainActivity.this);
    View view = li.inflate(R.layout.set_label, null);

    // URL input//from ww w. j av  a 2s.com
    final EditText label = (EditText) view.findViewById(R.id.set_label);

    if (!isFinishing()) {
        // Dialog
        Builder builder = new Builder(MainActivity.this);

        // Set add_torrent.xml to AlertDialog builder
        builder.setView(view);

        // Cancel
        builder.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                // User cancelled the dialog
            }
        });

        // Ok
        builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                // User accepted the dialog

                String labelEncoded = Uri.encode(label.getText().toString());

                setLabel(hash, labelEncoded);
            }
        });

        // Create dialog
        AlertDialog dialog = builder.create();

        // Show dialog
        dialog.show();
    }
}

From source file:com.lgallardo.qbittorrentclient.RefreshListener.java

public void uploadRateLimitDialog(final String hash) {

    // get prompts.xml view
    LayoutInflater li = LayoutInflater.from(MainActivity.this);
    View view = li.inflate(R.layout.upload_rate_limit, null);

    // URL input/*from  ww w. jav  a  2  s. co  m*/
    final EditText uploadRateLimit = (EditText) view.findViewById(R.id.upload_rate_limit);

    if (!isFinishing()) {
        // Dialog
        Builder builder = new Builder(MainActivity.this);

        // Set add_torrent.xml to AlertDialog builder
        builder.setView(view);

        // Cancel
        builder.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                // User cancelled the dialog
            }
        });

        // Ok
        builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                // User accepted the dialog
                setUploadRateLimit(hash, uploadRateLimit.getText().toString());
            }
        });

        // Create dialog
        AlertDialog dialog = builder.create();

        // Show dialog
        dialog.show();
    }
}

From source file:com.lgallardo.qbittorrentclient.RefreshListener.java

public void downloadRateLimitDialog(final String hash) {

    // get prompts.xml view
    LayoutInflater li = LayoutInflater.from(MainActivity.this);
    View view = li.inflate(R.layout.download_rate_limit, null);

    // URL input/*from  w ww .  j  a va  2  s . c o  m*/
    final EditText downloadRateLimit = (EditText) view.findViewById(R.id.download_rate_limit);

    if (!isFinishing()) {
        // Dialog
        Builder builder = new Builder(MainActivity.this);

        // Set add_torrent.xml to AlertDialog builder
        builder.setView(view);

        // Cancel
        builder.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                // User cancelled the dialog
            }
        });

        // Ok
        builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                // User accepted the dialog
                setDownloadRateLimit(hash, downloadRateLimit.getText().toString());
            }
        });

        // Create dialog
        AlertDialog dialog = builder.create();

        // Show dialog
        dialog.show();
    }
}

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);/*w w  w . j av a 2  s.co 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.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 .java2 s . co  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.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   www .  jav a  2 s .co  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();
}