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:com.carlrice.reader.activity.EditFeedActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        finish();/*from   ww w . ja  va2s .  c  o  m*/
        return true;
    case R.id.menu_add_filter: {
        final View dialogView = getLayoutInflater().inflate(R.layout.dialog_filter_edit, null);

        new AlertDialog.Builder(this) //
                .setTitle(R.string.filter_add_title) //
                .setView(dialogView) //
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        String filterText = ((EditText) dialogView.findViewById(R.id.filterText)).getText()
                                .toString();
                        if (filterText.length() != 0) {
                            String feedId = getIntent().getData().getLastPathSegment();

                            ContentValues values = new ContentValues();
                            values.put(FilterColumns.FILTER_TEXT, filterText);
                            values.put(FilterColumns.IS_REGEX,
                                    ((CheckBox) dialogView.findViewById(R.id.regexCheckBox)).isChecked());
                            values.put(FilterColumns.IS_APPLIED_TO_TITLE,
                                    ((RadioButton) dialogView.findViewById(R.id.applyTitleRadio)).isChecked());
                            values.put(FilterColumns.IS_ACCEPT_RULE,
                                    ((RadioButton) dialogView.findViewById(R.id.acceptRadio)).isChecked());

                            ContentResolver cr = getContentResolver();
                            cr.insert(FilterColumns.FILTERS_FOR_FEED_CONTENT_URI(feedId), values);
                        }
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                    }
                }).show();
        return true;
    }
    case R.id.menu_search_feed: {
        final View dialogView = getLayoutInflater().inflate(R.layout.dialog_search_feed, null);
        final EditText searchText = (EditText) dialogView.findViewById(R.id.searchText);
        if (!mUrlEditText.getText().toString().startsWith(Constants.HTTP_SCHEME)
                && !mUrlEditText.getText().toString().startsWith(Constants.HTTPS_SCHEME)) {
            searchText.setText(mUrlEditText.getText());
        }
        final RadioGroup radioGroup = (RadioGroup) dialogView.findViewById(R.id.radioGroup);

        new AlertDialog.Builder(EditFeedActivity.this) //
                .setIcon(R.drawable.action_search) //
                .setTitle(R.string.feed_search) //
                .setView(dialogView) //
                .setPositiveButton(android.R.string.search_go, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        if (searchText.getText().length() > 0) {
                            String tmp = searchText.getText().toString();
                            try {
                                tmp = URLEncoder.encode(searchText.getText().toString(), Constants.UTF8);
                            } catch (UnsupportedEncodingException ignored) {
                            }
                            final String text = tmp;

                            switch (radioGroup.getCheckedRadioButtonId()) {
                            case R.id.byWebSearch:
                                final ProgressDialog pd = new ProgressDialog(EditFeedActivity.this);
                                pd.setMessage(getString(R.string.loading));
                                pd.setCancelable(true);
                                pd.setIndeterminate(true);
                                pd.show();

                                getLoaderManager().restartLoader(1, null,
                                        new LoaderManager.LoaderCallbacks<ArrayList<HashMap<String, String>>>() {

                                            @Override
                                            public Loader<ArrayList<HashMap<String, String>>> onCreateLoader(
                                                    int id, Bundle args) {
                                                return new GetFeedSearchResultsLoader(EditFeedActivity.this,
                                                        text);
                                            }

                                            @Override
                                            public void onLoadFinished(
                                                    Loader<ArrayList<HashMap<String, String>>> loader,
                                                    final ArrayList<HashMap<String, String>> data) {
                                                pd.cancel();

                                                if (data == null) {
                                                    Toast.makeText(EditFeedActivity.this, R.string.error,
                                                            Toast.LENGTH_SHORT).show();
                                                } else if (data.isEmpty()) {
                                                    Toast.makeText(EditFeedActivity.this, R.string.no_result,
                                                            Toast.LENGTH_SHORT).show();
                                                } else {
                                                    AlertDialog.Builder builder = new AlertDialog.Builder(
                                                            EditFeedActivity.this);
                                                    builder.setTitle(R.string.feed_search);

                                                    // create the grid item mapping
                                                    String[] from = new String[] { FEED_SEARCH_TITLE,
                                                            FEED_SEARCH_DESC };
                                                    int[] to = new int[] { android.R.id.text1,
                                                            android.R.id.text2 };

                                                    // fill in the grid_item layout
                                                    SimpleAdapter adapter = new SimpleAdapter(
                                                            EditFeedActivity.this, data,
                                                            R.layout.item_search_result, from, to);
                                                    builder.setAdapter(adapter,
                                                            new DialogInterface.OnClickListener() {
                                                                @Override
                                                                public void onClick(DialogInterface dialog,
                                                                        int which) {
                                                                    mNameEditText.setText(data.get(which)
                                                                            .get(FEED_SEARCH_TITLE));
                                                                    mUrlEditText.setText(data.get(which)
                                                                            .get(FEED_SEARCH_URL));
                                                                }
                                                            });
                                                    builder.show();
                                                }
                                            }

                                            @Override
                                            public void onLoaderReset(
                                                    Loader<ArrayList<HashMap<String, String>>> loader) {
                                            }
                                        });
                                break;

                            case R.id.byTopic:
                                mUrlEditText.setText("http://www.faroo.com/api?q=" + text
                                        + "&start=1&length=10&l=en&src=news&f=rss");
                                break;

                            case R.id.byYoutube:
                                mUrlEditText.setText("http://www.youtube.com/rss/user/"
                                        + text.replaceAll("\\+", "") + "/videos.rss");
                                break;
                            }
                        }
                    }
                }).setNegativeButton(android.R.string.cancel, null).show();
        return true;
    }
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.development.androrb.listfolders.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case 1:/*from   w w  w .j  a va2  s .c om*/
        // This example shows how to add a custom layout to an AlertDialog
        LayoutInflater factory = LayoutInflater.from(this);
        final View textEntryView = factory.inflate(R.layout.login_dialog, null);

        EditText dusernamefield = (EditText) textEntryView.findViewById(R.id.username_edit);
        dusernamefield.setText(Username);

        EditText dpasswordfield = (EditText) textEntryView.findViewById(R.id.password_edit);
        dpasswordfield.setText(Password);

        return new AlertDialog.Builder(listfolders.this).setIcon(R.drawable.alert_dialog_icon)
                .setTitle("Login Data").setView(textEntryView)
                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        Dialog curDialog = (Dialog) dialog;
                        EditText dusernamefield = (EditText) curDialog.findViewById(R.id.username_edit);
                        EditText dpasswordfield = (EditText) curDialog.findViewById(R.id.password_edit);
                        String dusername = dusernamefield.getText().toString();
                        String dpassword = dpasswordfield.getText().toString();

                        SharedPreferences preferences = getPreferences(MODE_PRIVATE);
                        SharedPreferences.Editor editor = preferences.edit();
                        editor.putString("UID", dusername);
                        editor.commit();
                        editor.putString("PW", dpassword);
                        editor.commit();

                        Intent mainIntent = new Intent(listfolders.this, listfolders.class);
                        listfolders.this.startActivity(mainIntent);
                        listfolders.this.finish();
                        /* User clicked OK so do some stuff */
                    }
                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked cancel so do some stuff */
                    }
                }).create();
    case 2:
        // This example shows how to add a custom layout to an AlertDialog
        LayoutInflater factory2 = LayoutInflater.from(this);
        final View apiEntryView = factory2.inflate(R.layout.apikey, null);

        EditText dapikeyfield = (EditText) apiEntryView.findViewById(R.id.api_edit);
        dapikeyfield.setText(apikey);

        return new AlertDialog.Builder(listfolders.this).setIcon(R.drawable.alert_dialog_icon)
                .setTitle("API KEY").setView(apiEntryView)
                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        Dialog curDialog = (Dialog) dialog;
                        EditText dapikeyfield = (EditText) curDialog.findViewById(R.id.api_edit);

                        String dapikey = dapikeyfield.getText().toString();

                        SharedPreferences preferences = getPreferences(MODE_PRIVATE);
                        SharedPreferences.Editor editor = preferences.edit();

                        editor.putString("API", dapikey);
                        editor.commit();

                        Intent mainIntent = new Intent(listfolders.this, listfolders.class);
                        listfolders.this.startActivity(mainIntent);
                        listfolders.this.finish();

                        /* User clicked OK so do some stuff */
                    }
                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked cancel so do some stuff */
                    }
                }).create();
    case 3:
        // This example shows how to add a custom layout to an AlertDialog
        LayoutInflater factory3 = LayoutInflater.from(this);
        final View maxEntryView = factory3.inflate(R.layout.maxcount, null);

        EditText dmaxkeyfield = (EditText) maxEntryView.findViewById(R.id.maxcount_edit);
        dmaxkeyfield.setText(maxcount);
        dmaxkeyfield.setKeyListener(new NumberKeyListener() {
            @Override
            protected char[] getAcceptedChars() {
                char[] numberChars = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
                return numberChars;
            }

            @Override
            public int getInputType() {
                return InputType.TYPE_CLASS_NUMBER;
            }
        });

        return new AlertDialog.Builder(listfolders.this).setIcon(R.drawable.alert_dialog_icon)
                .setTitle("Max Item p.Page").setView(maxEntryView)
                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        Dialog curDialog = (Dialog) dialog;
                        EditText dmaxkeyfield = (EditText) curDialog.findViewById(R.id.maxcount_edit);

                        String dmaxcount = dmaxkeyfield.getText().toString();
                        int idmaxcount = Integer.parseInt(dmaxcount);
                        if (idmaxcount < 10)
                            dmaxcount = "10";
                        if (idmaxcount > 500)
                            dmaxcount = "500";

                        SharedPreferences preferences = getPreferences(MODE_PRIVATE);
                        SharedPreferences.Editor editor = preferences.edit();

                        editor.putString("MAX", dmaxcount);
                        editor.commit();

                        Intent mainIntent = new Intent(listfolders.this, listfolders.class);
                        listfolders.this.startActivity(mainIntent);
                        listfolders.this.finish();

                        /* User clicked OK so do some stuff */
                    }
                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked cancel so do some stuff */
                    }
                }).create();
    }
    return null;
}

From source file:com.app.uafeed.activity.EditFeedActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        finish();//from  w  ww.  j ava2s  .com
        return true;
    case R.id.menu_add_filter: {
        final View dialogView = getLayoutInflater().inflate(R.layout.dialog_filter_edit, null);

        new AlertDialog.Builder(this) //
                .setTitle(R.string.filter_add_title) //
                .setView(dialogView) //
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        String filterText = ((EditText) dialogView.findViewById(R.id.filterText)).getText()
                                .toString();
                        if (filterText.length() != 0) {
                            String feedId = getIntent().getData().getLastPathSegment();

                            ContentValues values = new ContentValues();
                            values.put(FilterColumns.FILTER_TEXT, filterText);
                            values.put(FilterColumns.IS_REGEX,
                                    ((CheckBox) dialogView.findViewById(R.id.regexCheckBox)).isChecked());
                            values.put(FilterColumns.IS_APPLIED_TO_TITLE,
                                    ((RadioButton) dialogView.findViewById(R.id.applyTitleRadio)).isChecked());

                            ContentResolver cr = getContentResolver();
                            cr.insert(FilterColumns.FILTERS_FOR_FEED_CONTENT_URI(feedId), values);
                        }
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                    }
                }).show();
        return true;
    }
    case R.id.menu_search_feed: {
        final View dialogView = getLayoutInflater().inflate(R.layout.dialog_search_feed, null);
        final EditText searchText = (EditText) dialogView.findViewById(R.id.searchText);
        if (!mUrlEditText.getText().toString().startsWith(Constants.HTTP_SCHEME)
                && !mUrlEditText.getText().toString().startsWith(Constants.HTTPS_SCHEME)) {
            searchText.setText(mUrlEditText.getText());
        }
        final RadioGroup radioGroup = (RadioGroup) dialogView.findViewById(R.id.radioGroup);

        new AlertDialog.Builder(EditFeedActivity.this) //
                .setIcon(R.drawable.action_search) //
                .setTitle(R.string.feed_search) //
                .setView(dialogView) //
                .setPositiveButton(android.R.string.search_go, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        if (searchText.getText().length() > 0) {
                            String tmp = searchText.getText().toString();
                            try {
                                tmp = URLEncoder.encode(searchText.getText().toString(), Constants.UTF8);
                            } catch (UnsupportedEncodingException ignored) {
                            }
                            final String text = tmp;

                            switch (radioGroup.getCheckedRadioButtonId()) {
                            case R.id.byWebSearch:
                                final ProgressDialog pd = new ProgressDialog(EditFeedActivity.this);
                                pd.setMessage(getString(R.string.loading));
                                pd.setCancelable(true);
                                pd.setIndeterminate(true);
                                pd.show();

                                getLoaderManager().restartLoader(1, null,
                                        new LoaderManager.LoaderCallbacks<ArrayList<HashMap<String, String>>>() {

                                            @Override
                                            public Loader<ArrayList<HashMap<String, String>>> onCreateLoader(
                                                    int id, Bundle args) {
                                                return new GetFeedSearchResultsLoader(EditFeedActivity.this,
                                                        text);
                                            }

                                            @Override
                                            public void onLoadFinished(
                                                    Loader<ArrayList<HashMap<String, String>>> loader,
                                                    final ArrayList<HashMap<String, String>> data) {
                                                pd.cancel();

                                                if (data == null) {
                                                    Toast.makeText(EditFeedActivity.this, R.string.error,
                                                            Toast.LENGTH_SHORT).show();
                                                } else if (data.isEmpty()) {
                                                    Toast.makeText(EditFeedActivity.this, R.string.no_result,
                                                            Toast.LENGTH_SHORT).show();
                                                } else {
                                                    AlertDialog.Builder builder = new AlertDialog.Builder(
                                                            EditFeedActivity.this);
                                                    builder.setTitle(R.string.feed_search);

                                                    // create the grid item mapping
                                                    String[] from = new String[] { FEED_SEARCH_TITLE,
                                                            FEED_SEARCH_DESC };
                                                    int[] to = new int[] { android.R.id.text1,
                                                            android.R.id.text2 };

                                                    // fill in the grid_item layout
                                                    SimpleAdapter adapter = new SimpleAdapter(
                                                            EditFeedActivity.this, data,
                                                            R.layout.item_search_result, from, to);
                                                    builder.setAdapter(adapter,
                                                            new DialogInterface.OnClickListener() {
                                                                @Override
                                                                public void onClick(DialogInterface dialog,
                                                                        int which) {
                                                                    mNameEditText.setText(data.get(which)
                                                                            .get(FEED_SEARCH_TITLE));
                                                                    mUrlEditText.setText(data.get(which)
                                                                            .get(FEED_SEARCH_URL));
                                                                }
                                                            });
                                                    builder.show();
                                                }
                                            }

                                            @Override
                                            public void onLoaderReset(
                                                    Loader<ArrayList<HashMap<String, String>>> loader) {
                                            }
                                        });
                                break;

                            case R.id.byTopic:
                                mUrlEditText.setText("http://www.faroo.com/api?q=" + text
                                        + "&start=1&length=10&l=en&src=news&f=rss");
                                break;

                            case R.id.byYoutube:
                                mUrlEditText.setText("http://www.youtube.com/rss/user/"
                                        + text.replaceAll("\\+", "") + "/videos.rss");
                                break;
                            }
                        }
                    }
                }).setNegativeButton(android.R.string.cancel, null).show();
        return true;
    }
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.entertailion.android.dial.ServerFinder.java

private AlertDialog buildManualIpDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    View view = LayoutInflater.from(this).inflate(R.layout.manual_ip, null);
    final EditText ipEditText = (EditText) view.findViewById(R.id.manual_ip_entry);

    ipEditText.setFilters(new InputFilter[] { new NumberKeyListener() {
        @Override//from www .  ja  v  a2  s  .  c om
        protected char[] getAcceptedChars() {
            return "0123456789.:".toCharArray();
        }

        public int getInputType() {
            return InputType.TYPE_CLASS_NUMBER;
        }
    } });

    SharedPreferences settings = getSharedPreferences(MainActivity.PREFS_NAME, Activity.MODE_PRIVATE);
    String ip = settings.getString(MANUAL_IP_ADDRESS, "");
    ipEditText.setText(ip);

    builder.setPositiveButton(R.string.manual_ip_connect, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            DialServer DialServer = DialServerFromString(ipEditText.getText().toString());
            if (DialServer != null) {
                connectToEntry(DialServer);
                try {
                    SharedPreferences settings = getSharedPreferences(MainActivity.PREFS_NAME,
                            Activity.MODE_PRIVATE);
                    SharedPreferences.Editor editor = settings.edit();
                    editor.putString(MANUAL_IP_ADDRESS, ipEditText.getText().toString());
                    editor.commit();
                } catch (Exception e) {
                }
            } else {
                Toast.makeText(ServerFinder.this, getString(R.string.manual_ip_error_address),
                        Toast.LENGTH_LONG).show();
            }
        }
    }).setNegativeButton(R.string.manual_ip_cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // do nothing
        }
    }).setCancelable(true).setTitle(R.string.manual_ip_label).setMessage(R.string.manual_ip_entry_label)
            .setView(view);
    return builder.create();
}

From source file:com.hivewallet.androidclient.wallet.ui.WalletActivity.java

private Dialog createImportKeysDialog() {
    final View view = getLayoutInflater().inflate(R.layout.import_keys_from_storage_dialog, null);
    final Spinner fileView = (Spinner) view.findViewById(R.id.import_keys_from_storage_file);
    final EditText passwordView = (EditText) view.findViewById(R.id.import_keys_from_storage_password);

    final DialogBuilder dialog = new DialogBuilder(this);
    dialog.setTitle(R.string.import_keys_dialog_title);
    dialog.setView(view);//from   w  w w .  j ava  2  s . co m
    dialog.setPositiveButton(R.string.import_keys_dialog_button_import, new OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            final File file = (File) fileView.getSelectedItem();
            final String password = passwordView.getText().toString().trim();
            passwordView.setText(null); // get rid of it asap

            final boolean isProtobuf = file.getName()
                    .startsWith(Constants.Files.WALLET_KEY_BACKUP_PROTOBUF + '.')
                    || file.getName().startsWith(Constants.Files.EXTERNAL_WALLET_BACKUP + '-')
                    || file.getName().startsWith(Constants.Files.EXTERNAL_WALLET_TMP_FILE);

            if (isProtobuf)
                restoreWalletFromProtobuf(file, password);
            else
                importPrivateKeysFromBase58(file, password);
        }
    });
    dialog.setNegativeButton(R.string.button_cancel, new OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            passwordView.setText(null); // get rid of it asap
        }
    });
    dialog.setOnCancelListener(new OnCancelListener() {
        @Override
        public void onCancel(final DialogInterface dialog) {
            passwordView.setText(null); // get rid of it asap
        }
    });

    final FileAdapter adapter = new FileAdapter(this) {
        @Override
        public View getDropDownView(final int position, View row, final ViewGroup parent) {
            final File file = getItem(position);
            File externalWalletBackupDir = new File(getFilesDir(), Constants.Files.EXTERNAL_WALLET_BACKUP_DIR);
            File selectedExternalWalletBackup = new File(getFilesDir(),
                    Constants.Files.EXTERNAL_WALLET_TMP_FILE);
            final boolean isExternal = selectedExternalWalletBackup.equals(file);
            final boolean isManual = externalWalletBackupDir.equals(file.getParentFile());
            final boolean isEncrypted = Crypto.OPENSSL_FILE_FILTER.accept(file);

            if (row == null)
                row = inflater.inflate(R.layout.wallet_import_keys_file_row, null);

            final TextView filenameView = (TextView) row
                    .findViewById(R.id.wallet_import_keys_file_row_filename);
            filenameView.setText(file.getName());

            final TextView securityView = (TextView) row
                    .findViewById(R.id.wallet_import_keys_file_row_security);
            final String encryptedStr = context
                    .getString(isEncrypted ? R.string.import_keys_dialog_file_security_encrypted
                            : R.string.import_keys_dialog_file_security_unencrypted);
            final String storageStr = isExternal ? ""
                    : ", " + context.getString(R.string.import_keys_dialog_file_security_internal);
            securityView.setText(encryptedStr + storageStr);

            final TextView createdView = (TextView) row.findViewById(R.id.wallet_import_keys_file_row_created);
            if (isExternal) {
                createdView.setText(context.getString(R.string.import_keys_dialog_file_just_selected));
            } else if (isManual) {
                createdView.setText(context.getString(R.string.import_keys_dialog_file_created_manual,
                        DateUtils.getRelativeTimeSpanString(context, file.lastModified(), true)));
            } else {
                createdView.setText(context.getString(R.string.import_keys_dialog_file_created_automatic,
                        DateUtils.getRelativeTimeSpanString(context, file.lastModified(), true)));
            }

            return row;
        }
    };

    fileView.setAdapter(adapter);

    return dialog.create();
}

From source file:com.remobile.dialogs.Notification.java

/**
 * Builds and shows a native Android prompt dialog with given title, message, buttons.
 * This dialog only shows up to 3 buttons.  Any labels after that will be ignored.
 * The following results are returned to the JavaScript callback identified by callbackId:
 * buttonIndex         Index number of the button selected
 * input1            The text entered in the prompt dialog box
 *
 * @param message         The message the dialog should display
 * @param title           The title of the dialog
 * @param buttonLabels    A comma separated list of button labels (Up to 3 buttons)
 * @param callbackContext The callback context.
 *//*from  w  ww .  j  a va  2s  .c o m*/
public synchronized void prompt(final String message, final String title, final JSONArray buttonLabels,
        final String defaultText, final CallbackContext callbackContext) {
    final Activity activity = this.cordova.getActivity();
    Runnable runnable = new Runnable() {
        public void run() {
            final EditText promptInput = new EditText(activity);
            promptInput.setHint(defaultText);
            AlertDialog.Builder dlg = createDialog(); // new AlertDialog.Builder(this.cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
            dlg.setMessage(message);
            dlg.setTitle(title);
            dlg.setCancelable(false);

            dlg.setView(promptInput);

            final JSONObject result = new JSONObject();

            // First button
            if (buttonLabels.length() > 0) {
                try {
                    dlg.setNegativeButton(buttonLabels.getString(0), new AlertDialog.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                            try {
                                result.put("buttonIndex", 1);
                                result.put("input1",
                                        promptInput.getText().toString().trim().length() == 0 ? defaultText
                                                : promptInput.getText());
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
                        }
                    });
                } catch (JSONException e) {
                }
            }

            // Second button
            if (buttonLabels.length() > 1) {
                try {
                    dlg.setNeutralButton(buttonLabels.getString(1), new AlertDialog.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                            try {
                                result.put("buttonIndex", 2);
                                result.put("input1",
                                        promptInput.getText().toString().trim().length() == 0 ? defaultText
                                                : promptInput.getText());
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
                        }
                    });
                } catch (JSONException e) {
                }
            }

            // Third button
            if (buttonLabels.length() > 2) {
                try {
                    dlg.setPositiveButton(buttonLabels.getString(2), new AlertDialog.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                            try {
                                result.put("buttonIndex", 3);
                                result.put("input1",
                                        promptInput.getText().toString().trim().length() == 0 ? defaultText
                                                : promptInput.getText());
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
                        }
                    });
                } catch (JSONException e) {
                }
            }
            dlg.setOnCancelListener(new AlertDialog.OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    dialog.dismiss();
                    try {
                        result.put("buttonIndex", 0);
                        result.put("input1", promptInput.getText().toString().trim().length() == 0 ? defaultText
                                : promptInput.getText());
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
                }
            });

            changeTextDirection(dlg);
        }

        ;
    };
    this.cordova.getActivity().runOnUiThread(runnable);
}

From source file:reportsas.com.formulapp.Formulario.java

public int ObtenerRespuesta(LinearLayout contenedor, Pregunta Pregunta,
        ArrayList<PreguntaRespuesta> respuestaList) {
    PreguntaRespuesta result = new PreguntaRespuesta();
    int numRespuesta = 0;
    result.setIdPregunta(Pregunta.getIdPregunta());
    EditText resp;
    TextView selectio;/*w  ww .j  a v  a  2s  .co  m*/
    switch (Pregunta.getTipoPregunta()) {
    case 1:
        resp = (EditText) contenedor.findViewById(R.id.edtTexto);
        result.setItem(1);
        result.setRespuesta(resp.getText().toString());
        respuestaList.add(result);
        numRespuesta = 1;
        break;
    case 2:
        resp = (EditText) contenedor.findViewById(R.id.mtxtEdit);
        result.setItem(1);
        result.setRespuesta(resp.getText().toString());
        respuestaList.add(result);
        numRespuesta = 1;
        break;
    case 3:
        selectio = (TextView) contenedor.findViewById(R.id.respuestaGruop);
        result.setItem(1);
        result.setRespuesta(selectio.getText().toString());
        respuestaList.add(result);
        numRespuesta = 1;
        break;
    case 4:

        String resp_opcio = "";
        for (int j = 0; j < contenedor.getChildCount(); j++) {
            View child = contenedor.getChildAt(j);
            if (child instanceof CheckBox) {
                CheckBox hijo = (CheckBox) child;
                if (hijo.isChecked()) {
                    if (resp_opcio.length() == 0) {
                        if (Pregunta.isOpcionEditble(hijo.getText().toString())) {
                            EditText otrosR = (EditText) contenedor.findViewById(R.id.edtTexto);
                            resp_opcio = otrosR.getText().toString();
                        } else {
                            resp_opcio = hijo.getText().toString();
                        }
                    } else {
                        if (Pregunta.isOpcionEditble(hijo.getText().toString())) {
                            EditText otrosR = (EditText) contenedor.findViewById(R.id.edtTexto);
                            resp_opcio += " , " + otrosR.getText().toString() + " ";
                        } else {
                            resp_opcio = resp_opcio + " , " + hijo.getText() + " ";
                        }

                    }
                }
            }

        }
        result.setItem(1);
        result.setRespuesta(resp_opcio);
        respuestaList.add(result);
        numRespuesta = 1;
        break;
    case 5:
        selectio = (TextView) contenedor.findViewById(R.id.seleEscala);
        result.setItem(1);
        result.setRespuesta(selectio.getText().toString());
        respuestaList.add(result);
        numRespuesta = 1;
        break;
    case 6:
        Spinner lista = (Spinner) contenedor.findViewById(R.id.opcionesListado);
        result.setItem(1);
        result.setRespuesta(lista.getSelectedItem().toString() + "");
        respuestaList.add(result);
        numRespuesta = 1;
        break;
    case 7:
        TableLayout tabla = (TableLayout) contenedor.findViewById(R.id.tablaOpciones);
        for (int i = 0; i < tabla.getChildCount(); i++) {
            TableRow registro = (TableRow) tabla.getChildAt(i);
            TextView etiq = (TextView) registro.findViewById(R.id.textoRow);
            RadioGroup selector = (RadioGroup) registro.findViewById(R.id.valoresRow);
            PreguntaRespuesta itemA = new PreguntaRespuesta();
            itemA.setIdPregunta(Pregunta.getIdPregunta());
            itemA.setItem(i + 1);
            itemA.setRespuesta(etiq.getText().toString());
            if (selector.getCheckedRadioButtonId() > 0) {
                RadioButton rb = (RadioButton) selector.findViewById(selector.getCheckedRadioButtonId());
                itemA.setOpcion(rb.getText() + "");
            }

            respuestaList.add(itemA);
            numRespuesta++;
        }

        break;
    case 8:
        DatePicker dp = (DatePicker) contenedor.findViewById(R.id.Fecha_resutl);
        result.setItem(1);
        result.setRespuesta(dp.getYear() + "-" + dp.getMonth() + "-" + dp.getDayOfMonth());
        respuestaList.add(result);
        numRespuesta = 1;
        break;
    case 9:
        TimePicker tp = (TimePicker) contenedor.findViewById(R.id.hora_result);
        result.setItem(1);
        result.setRespuesta(tp.getCurrentHour() + ":" + tp.getCurrentMinute());
        respuestaList.add(result);
        numRespuesta = 1;
        break;

    default:
        result.setItem(1);
        result.setRespuesta("Proceso");
        break;

    }

    return numRespuesta;

}

From source file:de.baumann.hhsmoodle.data_random.Random_Fragment.java

private void setRandomList() {

    if (isFABOpen) {
        closeFABMenu();/*from w  w w.j a  v a2 s .  c  om*/
    }

    //display data
    final int layoutstyle = R.layout.list_item_notes;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "random_title", "random_content", "random_creation" };
    final Cursor row = db.fetchAllData();
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) {
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            View v = super.getView(position, convertView, parent);
            ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes);
            iv_icon.setVisibility(View.GONE);

            return v;
        }
    };

    lv.setAdapter(adapter);
    //onClick function
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {

            if (isFABOpen) {
                closeFABMenu();
            }

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String random_content = row2.getString(row2.getColumnIndexOrThrow("random_content"));
            final String random_title = row2.getString(row2.getColumnIndexOrThrow("random_title"));

            if (random_content.isEmpty()) {
                Snackbar.make(lv, getActivity().getString(R.string.number_enterData), Snackbar.LENGTH_LONG)
                        .show();
            } else {
                getActivity().setTitle(random_title);
                lv.setVisibility(View.GONE);
                lvItems.setVisibility(View.VISIBLE);

                try {
                    FileOutputStream fOut = new FileOutputStream(newFile());
                    OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
                    myOutWriter.append(random_content);
                    myOutWriter.close();

                    fOut.flush();
                    fOut.close();
                } catch (IOException e) {
                    Log.e("Exception", "File write failed: " + e.toString());
                }

                items = new ArrayList<>();
                readItems();

                setAdapter(1000);

                fab.setVisibility(View.GONE);
                fab_dice.setVisibility(View.VISIBLE);
            }
        }
    });

    lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            if (isFABOpen) {
                closeFABMenu();
            }

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String random_title = row2.getString(row2.getColumnIndexOrThrow("random_title"));
            final String random_content = row2.getString(row2.getColumnIndexOrThrow("random_content"));
            final String random_icon = row2.getString(row2.getColumnIndexOrThrow("random_icon"));
            final String random_attachment = row2.getString(row2.getColumnIndexOrThrow("random_attachment"));
            final String random_creation = row2.getString(row2.getColumnIndexOrThrow("random_creation"));

            final CharSequence[] options = { getString(R.string.number_edit_entry),
                    getString(R.string.bookmark_remove_bookmark) };
            new android.app.AlertDialog.Builder(getActivity())
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {

                            if (options[item].equals(getString(R.string.number_edit_entry))) {

                                android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(
                                        getActivity());
                                View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_entry, null);

                                final EditText edit_title = (EditText) dialogView
                                        .findViewById(R.id.note_title_input);
                                edit_title.setHint(R.string.title_hint);
                                edit_title.setText(random_title);

                                final EditText edit_cont = (EditText) dialogView
                                        .findViewById(R.id.note_text_input);
                                edit_cont.setHint(R.string.text_hint);
                                edit_cont.setText(random_content);

                                builder.setView(dialogView);
                                builder.setTitle(R.string.number_edit_entry);
                                builder.setPositiveButton(R.string.toast_yes,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {

                                                String inputTitle = edit_title.getText().toString().trim();
                                                String inputCont = edit_cont.getText().toString().trim();
                                                db.update(Integer.parseInt(_id), inputTitle, inputCont,
                                                        random_icon, random_attachment, random_creation);
                                                setRandomList();
                                                Snackbar.make(lv, R.string.bookmark_added,
                                                        Snackbar.LENGTH_SHORT).show();
                                            }
                                        });
                                builder.setNegativeButton(R.string.toast_cancel,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                dialog.cancel();
                                            }
                                        });

                                final android.app.AlertDialog dialog2 = builder.create();
                                // Display the custom alert dialog on interface
                                dialog2.show();
                                helper_main.showKeyboard(getActivity(), edit_title);
                            }

                            if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) {
                                Snackbar snackbar = Snackbar
                                        .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG)
                                        .setAction(R.string.toast_yes, new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                db.delete(Integer.parseInt(_id));
                                                setRandomList();
                                            }
                                        });
                                snackbar.show();
                            }

                        }
                    }).show();

            return true;
        }
    });
}

From source file:com.krayzk9s.imgurholo.ui.SingleImageFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // handle item selection
    final Activity activity = getActivity();
    switch (item.getItemId()) {
    case R.id.action_sort:
        return true;
    case R.id.menuSortNewest:
        sort = "New";
        refreshComments();//  w w  w  . j  a  va2 s .  co  m
        activity.invalidateOptionsMenu();
        return true;
    case R.id.menuSortTop:
        sort = "Top";
        refreshComments();
        activity.invalidateOptionsMenu();
        return true;
    case R.id.menuSortBest:
        sort = "Best";
        refreshComments();
        activity.invalidateOptionsMenu();
        return true;
    case R.id.action_refresh:
        refreshComments();
        return true;
    case R.id.action_submit:
        final EditText newGalleryTitle = new EditText(activity);
        newGalleryTitle.setHint("Title");
        newGalleryTitle.setSingleLine();
        new AlertDialog.Builder(activity).setTitle("Set Gallery Title/Press OK to remove")
                .setView(newGalleryTitle)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        if (newGalleryTitle.getText() == null)
                            return;
                        HashMap<String, Object> galleryMap = new HashMap<String, Object>();
                        galleryMap.put("terms", "1");
                        galleryMap.put(ImgurHoloActivity.IMAGE_DATA_TITLE,
                                newGalleryTitle.getText().toString());
                        newGalleryString = newGalleryTitle.getText().toString();
                        try {
                            Fetcher fetcher = new Fetcher(singleImageFragment,
                                    "3/gallery/image/" + imageData.getJSONObject().getString("id"), ApiCall.GET,
                                    galleryMap, ((ImgurHoloActivity) getActivity()).getApiCall(), GALLERY);
                            fetcher.execute();
                        } catch (Exception e) {
                            Log.e("Error!", e.toString());
                        }
                    }
                }).setNegativeButton(R.string.dialog_answer_cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Do nothing.
                    }
                }).show();

        return true;
    case R.id.action_edit:
        try {
            final EditText newTitle = new EditText(activity);
            newTitle.setSingleLine();
            if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE).equals("null"))
                newTitle.setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE));
            final EditText newBody = new EditText(activity);
            newBody.setHint(R.string.body_hint_description);
            newTitle.setHint(R.string.body_hint_title);
            if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION).equals("null"))
                newBody.setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION));
            LinearLayout linearLayout = new LinearLayout(activity);
            linearLayout.setOrientation(LinearLayout.VERTICAL);
            linearLayout.addView(newTitle);
            linearLayout.addView(newBody);
            new AlertDialog.Builder(activity).setTitle(R.string.dialog_edit_title).setView(linearLayout)
                    .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            TextView imageTitle = (TextView) imageLayoutView
                                    .findViewById(R.id.single_image_title);
                            TextView imageDescription = (TextView) imageLayoutView
                                    .findViewById(R.id.single_image_description);
                            if (newTitle.getText() != null && !newTitle.getText().toString().equals("")) {
                                imageTitle.setText(newTitle.getText().toString());
                                imageTitle.setVisibility(View.VISIBLE);
                            } else
                                imageTitle.setVisibility(View.GONE);
                            if (newBody.getText() != null && !newBody.getText().toString().equals("")) {
                                imageDescription.setText(newBody.getText().toString());
                                imageDescription.setVisibility(View.VISIBLE);
                            } else
                                imageDescription.setVisibility(View.GONE);
                            HashMap<String, Object> editImageMap = new HashMap<String, Object>();
                            editImageMap.put(ImgurHoloActivity.IMAGE_DATA_TITLE, newTitle.getText().toString());
                            editImageMap.put(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION,
                                    newBody.getText().toString());
                            try {
                                Fetcher fetcher = new Fetcher(singleImageFragment,
                                        "3/image/" + imageData.getJSONObject().getString("id"), ApiCall.POST,
                                        editImageMap, ((ImgurHoloActivity) getActivity()).getApiCall(),
                                        EDITIMAGE);
                                fetcher.execute();
                            } catch (JSONException e) {
                                Log.e("Error!", e.toString());
                            }
                        }
                    }).setNegativeButton(R.string.dialog_answer_cancel, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            // Do nothing.
                        }
                    }).show();
        } catch (JSONException e) {
            Log.e("Error!", "oops, some image fields missing values" + e.toString());
        }
        return true;
    case R.id.action_download:
        ImageUtils.downloadImage(this, imageData);
        return true;
    case R.id.action_delete:
        new AlertDialog.Builder(activity).setTitle(R.string.dialog_delete_confirmation_title)
                .setMessage(R.string.dialog_delete_confirmation_summary)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        try {
                            Fetcher fetcher = new Fetcher(singleImageFragment,
                                    "3/image/" + imageData.getJSONObject().getString("id"), ApiCall.DELETE,
                                    null, ((ImgurHoloActivity) getActivity()).getApiCall(), DELETE);
                            fetcher.execute();
                        } catch (JSONException e) {
                            Log.e("Error!", e.toString());
                        }
                    }
                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Do nothing.
                    }
                }).show();
        return true;
    case R.id.action_copy:
        ImageUtils.copyImageURL(this, imageData);
        return true;
    case R.id.action_share:
        ImageUtils.shareImage(this, imageData);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}