Example usage for android.text.method PasswordTransformationMethod PasswordTransformationMethod

List of usage examples for android.text.method PasswordTransformationMethod PasswordTransformationMethod

Introduction

In this page you can find the example usage for android.text.method PasswordTransformationMethod PasswordTransformationMethod.

Prototype

PasswordTransformationMethod

Source Link

Usage

From source file:com.manning.androidhacks.hack017.CreateAccountAdapter.java

private void populateSecondForm(LinearLayout formLayout) {
    formLayout.addView(createTitle(mContext.getString(R.string.account_create_password_title)));
    EditText passwordEditText = createEditText(mContext.getString(R.string.account_create_password_hint),
            InputType.TYPE_CLASS_TEXT, EditorInfo.IME_ACTION_DONE, false, PASSWORD_KEY);
    passwordEditText.setTransformationMethod(new PasswordTransformationMethod());

    formLayout.addView(passwordEditText);
    formLayout.addView(createErrorView(PASSWORD_KEY));

    formLayout.addView(createTitle(mContext.getString(R.string.account_create_gender_title)));
    Spinner spinner = new Spinner(mContext);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);//www.j  a v  a  2  s.c  om
    params.bottomMargin = 17;
    spinner.setLayoutParams(params);

    final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(mContext, R.array.sexes_array,
            android.R.layout.simple_spinner_item);
    spinner.setAdapter(adapter);
    spinner.setPrompt(mContext.getString(R.string.account_create_sex_spinner_prompt));
    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {

            mFormData.put(GENDER_KEY, adapter.getItem(pos).toString());
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

    if (mFormData.get(GENDER_KEY) != null) {
        spinner.setSelection(adapter.getPosition(mFormData.get(GENDER_KEY)));
    }

    formLayout.addView(spinner);

}

From source file:com.prey.activities.CheckPasswordActivity.java

protected void bindPasswordControls() {
    Button checkPasswordOkButton = (Button) findViewById(R.id.password_btn_login);
    final EditText pass1 = ((EditText) findViewById(R.id.password_pass_txt));
    checkPasswordOkButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            final String passwordtyped = pass1.getText().toString();
            final Context ctx = getApplicationContext();
            if (passwordtyped.equals(""))
                Toast.makeText(ctx, R.string.preferences_password_length_error, Toast.LENGTH_LONG).show();
            else {
                if (passwordtyped.length() < 6 || passwordtyped.length() > 32) {
                    Toast.makeText(ctx, ctx.getString(R.string.error_password_out_of_range, 6, 32),
                            Toast.LENGTH_LONG).show();
                } else {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
                        new CheckPassword().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, passwordtyped);
                    else
                        new CheckPassword().execute(passwordtyped);
                }//from  w ww . j a v  a 2s  .  co  m
            }

        }
    });

    //Hack to fix hint's typeface: http://stackoverflow.com/questions/3406534/password-hint-font-in-android
    EditText password = (EditText) findViewById(R.id.password_pass_txt);
    password.setTypeface(Typeface.DEFAULT);
    password.setTransformationMethod(new PasswordTransformationMethod());
}

From source file:com.googlecode.android_scripting.facade.ui.NFCBeamTask.java

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@SuppressLint("NewApi")
@Override/*from  www  .j ava2 s.  c o  m*/
public void onCreate() {
    super.onCreate();
    if (initNFCBeam()) {

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        if (mTitle != null) {
            builder.setTitle(mTitle);
        }
        // Can't display both a message and items. We'll elect to show the items instead.
        if (mMessage != null && mItems.isEmpty()) {
            builder.setMessage(mMessage);
        }
        switch (mInputType) {
        // Add single choice menu items to dialog.
        case SINGLE_CHOICE:
            builder.setSingleChoiceItems(getItemsAsCharSequenceArray(), mSelectedItems.iterator().next(),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            mSelectedItems.clear();
                            mSelectedItems.add(item);
                        }
                    });
            break;
        // Add multiple choice items to the dialog.
        case MULTI_CHOICE:
            boolean[] selectedItems = new boolean[mItems.size()];
            for (int i : mSelectedItems) {
                selectedItems[i] = true;
            }
            builder.setMultiChoiceItems(getItemsAsCharSequenceArray(), selectedItems,
                    new DialogInterface.OnMultiChoiceClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item, boolean isChecked) {
                            if (isChecked) {
                                mSelectedItems.add(item);
                            } else {
                                mSelectedItems.remove(item);
                            }
                        }
                    });
            break;
        // Add standard, menu-like, items to dialog.
        case MENU:
            builder.setItems(getItemsAsCharSequenceArray(), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    Map<String, Integer> result = new HashMap<String, Integer>();
                    result.put("item", item);
                    dismissDialog();
                    setResult(result);
                }
            });
            break;
        case PLAIN_TEXT:
            mEditText = new EditText(getActivity());
            if (mDefaultText != null) {
                mEditText.setText(mDefaultText);
            }
            mEditText.setInputType(mEditInputType);
            builder.setView(mEditText);
            break;
        case PASSWORD:
            mEditText = new EditText(getActivity());
            mEditText.setInputType(android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD);
            mEditText.setTransformationMethod(new PasswordTransformationMethod());
            builder.setView(mEditText);
            break;
        default:
            // No input type specified.
        }
        configureButtons(builder, getActivity());
        addOnCancelListener(builder, getActivity());
        mDialog = builder.show();
        mShowLatch.countDown();
    } else {

    }
}

From source file:com.googlecode.android_scripting.facade.AndroidFacade.java

private String getInputFromAlertDialog(final String title, final String message, final boolean password) {
    final FutureActivityTask<String> task = new FutureActivityTask<String>() {
        @Override//from   w w  w.ja  va 2 s .c  om
        public void onCreate() {
            super.onCreate();
            final EditText input = new EditText(getActivity());
            if (password) {
                input.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
                input.setTransformationMethod(new PasswordTransformationMethod());
            }
            AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
            alert.setTitle(title);
            alert.setMessage(message);
            alert.setView(input);
            alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.dismiss();
                    setResult(input.getText().toString());
                    finish();
                }
            });
            alert.setOnCancelListener(new DialogInterface.OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    dialog.dismiss();
                    setResult(null);
                    finish();
                }
            });
            alert.show();
        }
    };
    mTaskQueue.execute(task);

    try {
        return task.getResult();
    } catch (Exception e) {
        Log.e("Failed to display dialog.", e);
        throw new RuntimeException(e);
    }
}

From source file:org.brandroid.openmanager.activities.OpenExplorer.java

private void handleNetworking() {
    FileManager.DefaultUserInfo = new SimpleUserInfo();
    final Context c = this;
    Preferences.Warn_Networking = getPreferences().getSetting("warn", "networking", false);
    SimpleUserInfo.setInteractionCallback(new UserInfoInteractionCallback() {

        public boolean promptPassword(String message) {
            String mPassword = null;
            View view = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE))
                    .inflate(R.layout.prompt_password, null);
            TextView tv = (TextView) view.findViewById(android.R.id.message);
            tv.setText(message);//  w  w w .  ja v a  2 s  .c om
            final EditText text1 = ((EditText) view.findViewById(android.R.id.text1));
            final CheckBox checkpw = (CheckBox) view.findViewById(android.R.id.checkbox);
            checkpw.setOnCheckedChangeListener(new OnCheckedChangeListener() {
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        text1.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
                        text1.setTransformationMethod(new SingleLineTransformationMethod());
                    } else {
                        text1.setRawInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
                        text1.setTransformationMethod(new PasswordTransformationMethod());
                    }
                }
            });

            AlertDialog dlg = new AlertDialog.Builder(c).setTitle(R.string.s_prompt_password).setView(view)
                    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String mPassword = text1.getText().toString();
                            onPasswordEntered(mPassword);
                            onYesNoAnswered(true);
                        }
                    }).setNegativeButton(android.R.string.no, new OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            onYesNoAnswered(false);
                        }
                    }).create();
            dlg.show();
            return true;
        }

        @Override
        public void onYesNoAnswered(boolean yes) {
        }

        @Override
        public void onPasswordEntered(String password) {
        }

        @Override
        public boolean promptYesNo(final String message) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    AlertDialog dlg = new AlertDialog.Builder(c).setMessage(message)
                            .setPositiveButton(android.R.string.yes, new OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    onYesNoAnswered(true);
                                }
                            }).setNegativeButton(android.R.string.no, new OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    onYesNoAnswered(false);
                                }
                            }).create();
                    dlg.show();
                }
            });
            return true;
        }
    });
    try {
        OpenSFTP.DefaultJSch.setHostKeyRepository(new SimpleHostKeyRepo(OpenSFTP.DefaultJSch,
                FileManager.DefaultUserInfo, Preferences.getPreferences(getApplicationContext(), "hosts")));
        OpenNetworkPath.Timeout = getPreferences().getSetting("global", "server_timeout", 20) * 1000;
    } catch (JSchException e) {
        Logger.LogWarning("Couldn't set Preference-backed Host Key Repository", e);
    }
}

From source file:universe.constellation.orion.viewer.OrionViewerActivity.java

private void askPassword(final Controller controller) {
    if (controller.needPassword()) {
        AlertDialog.Builder buider = createThemedAlertBuilder();
        buider.setTitle("Password");

        final EditText input = new EditText(this);
        input.setInputType(EditorInfo.TYPE_TEXT_VARIATION_PASSWORD);
        input.setTransformationMethod(new PasswordTransformationMethod());
        buider.setView(input);/*w w  w.ja v a2s . c  o m*/

        buider.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (controller.authentificate(input.getText().toString())) {
                    dialog.dismiss();
                } else {
                    askPassword(controller);
                    showWarning("Wrong password!");
                }
            }
        });

        buider.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        buider.create().show();
    }
}