下面列出了android.widget.EditText#setTransformationMethod ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static $ pwd(boolean option){
try{
if(mView instanceof TextView){
TextView textView = (TextView) mView;
if(option)
textView.setTransformationMethod(new PasswordTransformationMethod());
else
textView.setTransformationMethod(null);
}
else if(mView instanceof EditText){
EditText editText = (EditText) mView;
if(option)
editText.setTransformationMethod(new PasswordTransformationMethod());
else
editText.setTransformationMethod(null);
}
}catch (Exception e){
Log.d(TAG, e.getMessage());
}
return $.getInstance();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
setContentView(R.layout.addnetwork);
server = (EditText) findViewById(R.id.server);
domain = (EditText) findViewById(R.id.domain);
username = (EditText) findViewById(R.id.username);
password = (EditText) findViewById(R.id.password);
password.setTypeface(Typeface.DEFAULT);
password.setTransformationMethod(new PasswordTransformationMethod());
anonymous = (CheckBox) findViewById(R.id.checkBox);
guest = (CheckBox) findViewById(R.id.checkBox2);
guest.setOnCheckedChangeListener(changeListener);
anonymous.setOnCheckedChangeListener(changeListener);
isMovie = getIntent().getExtras().getString("type").equals("movie");
LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter("mizuu-network-search"));
}
private void setPwdState(ImageView imageView,
EditText editText,
boolean isHidePwd) {
int start = editText.getSelectionStart();
if (isHidePwd) {
imageView.setImageDrawable(hidePwdDrawable);
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
} else {
imageView.setImageDrawable(showPwdDrawable);
editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
}
editText.setSelection(start);
}
@Override
public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
final EditText editText = new EditText(activity);
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
AlertDialog.Builder inputDialog =
new AlertDialog.Builder(activity);
inputDialog.setTitle("验证主密码").setView(editText);
inputDialog.setPositiveButton("确定",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String s = editText.getText().toString();
DailyMindMain data = adapter.getItem(i - 1);
try {
String value = AESTools.decodeFromBase64(s, data.content);
if (TextUtils.isEmpty(value)) {
toast("主密码不正确,请重新输入!");
} else {
Intent intent = new Intent(activity, DailyPasswordBoxSubActivity.class);
intent.putExtra("data", data);
intent.putExtra("main_password", s);
startActivity(intent);
}
} catch (Exception e) {
e.printStackTrace();
toast("解密失败!");
}
}
}).show();
}
protected void setupEditText(EditText editText) {
editText.setInputType(InputType.TYPE_NULL);
editText.setFilters(filters);
editText.setOnTouchListener(touchListener);
editText.setTransformationMethod(PasswordTransformationMethod
.getInstance());
}
protected void setupEditText(EditText editText) {
editText.setInputType(InputType.TYPE_NULL);
editText.setFilters(filters);
editText.setOnTouchListener(touchListener);
editText.setTransformationMethod(PasswordTransformationMethod
.getInstance());
}
/**
* Set a PinBox with all attributes
*
* @param editText to set attributes
*/
private void setStylePinBox(EditText editText) {
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(mNumberCharacters)});
if (mMaskPassword) {
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
else{
editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
}
if (mNativePinBox) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
//noinspection deprecation
editText.setBackgroundDrawable(new EditText(getContext()).getBackground());
} else {
editText.setBackground(new EditText(getContext()).getBackground());
}
} else {
editText.setBackgroundResource(mCustomDrawablePinBox);
}
if (mColorTextPinBoxes != PinViewSettings.DEFAULT_TEXT_COLOR_PIN_BOX) {
editText.setTextColor(mColorTextPinBoxes);
}
editText.setTextSize(PinViewUtils.convertPixelToDp(getContext(), mTextSizePinBoxes));
}
/**
* Set a PinBox with all attributes
*
* @param editText to set attributes
*/
private void setStylePinBox(EditText editText) {
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(mNumberCharacters)});
if (mMaskPassword) {
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
else{
editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
}
if (mNativePinBox) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
//noinspection deprecation
editText.setBackgroundDrawable(new EditText(getContext()).getBackground());
} else {
editText.setBackground(new EditText(getContext()).getBackground());
}
} else {
editText.setBackgroundResource(mCustomDrawablePinBox);
}
if (mColorTextPinBoxes != PinViewSettings.DEFAULT_TEXT_COLOR_PIN_BOX) {
editText.setTextColor(mColorTextPinBoxes);
}
editText.setTextSize(PinViewUtils.convertPixelToDp(getContext(), mTextSizePinBoxes));
}
private void setPINCode(){
evInput = new EditText(PinCodeActivity.this);
alertDialog =
CommonDialogUtils
.getAlertDialogWithTwoButtonAndEditView(PinCodeActivity.this,
getResources().getString(R.string.title_head_confirm_pin),
getResources().getString(R.string.button_ok),
getResources().getString(R.string.button_cancel),
dialogClickListener,
dialogClickListener,
evInput);
final AlertDialog dialog = alertDialog.create();
dialog.show();
// Overriding default positive button behavior to keep the
// dialog open, if PINS don't match.
dialog.getButton(AlertDialog.BUTTON_POSITIVE)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (evPin.getText().toString()
.equals(evInput.getText().toString())) {
savePin();
dialog.dismiss();
} else {
evInput.setError(getResources().getString(
R.string.validation_pin_confirm));
}
}
});
evInput.setInputType(InputType.TYPE_CLASS_NUMBER);
evInput.setTransformationMethod(new PasswordTransformationMethod());
}
@Override
protected void init() {
super.init();
EditText editView = getEditView();
editView.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
editView.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
@Override
protected void setTextInputType(EditText mAnswer) {
if (secret) {
mAnswer.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
mAnswer.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
}
protected void setTextInputType(EditText mAnswer) {
if (secret) {
mAnswer.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
mAnswer.setTransformationMethod(PasswordTransformationMethod.getInstance());
} else {
mAnswer.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER);
}
}
protected void setupPinItem(EditText item){
item.setInputType(InputType.TYPE_NULL);
item.setFilters(filters);
item.setOnTouchListener(otl);
item.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
protected void setupPinItem(EditText item){
item.setInputType(InputType.TYPE_NULL);
item.setFilters(filters);
item.setOnTouchListener(otl);
item.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
@Override
final protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gitty_reporter_layout);
// Get Device info and print them in EditText
deviceInfoEditText = (EditText) findViewById(R.id.gittyreporter_device_info);
getDeviceInfo();
deviceInfoEditText.setText(deviceInfo);
init(savedInstanceState);
final View nextFab = findViewById(R.id.gittyreporter_fab_next);
final View sendFab = findViewById(R.id.gittyreporter_fab_send);
if (!enableGitHubLogin){
nextFab.setVisibility(View.INVISIBLE);
sendFab.setVisibility(View.VISIBLE);
}
AppCompatCheckBox githubCheckbox = (AppCompatCheckBox) findViewById(R.id.gittyreporter_github_checkbox);
AppCompatButton registerButton = (AppCompatButton) findViewById(R.id.gittyreporter_github_register);
final EditText userName = (EditText) findViewById(R.id.gittyreporter_login_username);
final EditText userPassword = (EditText) findViewById(R.id.gittyreporter_login_password);
userPassword.setTypeface(Typeface.DEFAULT);
userPassword.setTransformationMethod(new PasswordTransformationMethod());
if (!enableGuestGitHubLogin){
githubCheckbox.setChecked(false);
githubCheckbox.setVisibility(View.GONE);
registerButton.setVisibility(View.VISIBLE);
}
githubCheckbox.setOnCheckedChangeListener(
new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked){
userName.setEnabled(false);
userName.setText("");
userPassword.setEnabled(false);
userPassword.setText("");
} else {
userName.setEnabled(true);
userPassword.setEnabled(true);
}
}
}
);
}
@Override
public void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
setContentView( R.layout.login );
progressDialog = UIFactory.getDefaultProgressDialog( this );
//Initializing Backendless API
Backendless.initApp( this, Defaults.APPLICATION_ID, Defaults.APPLICATION_API_KEY, Defaults.APPLICATION_VERSION );
//Binding UI elements
emailField = (EditText) findViewById( R.id.emailField );
passwordField = (EditText) findViewById( R.id.passwordField );
passwordField.setTypeface( Typeface.DEFAULT );
passwordField.setTransformationMethod( new PasswordTransformationMethod() );
//Checking for a login intent (it can be send from a Registration activity)
Intent intent = getIntent();
userEmail = intent.getStringExtra( BackendlessUser.EMAIL_KEY );
String userPassword = intent.getStringExtra( BackendlessUser.PASSWORD_KEY );
//Checking if user is already logged in and was saved in Backendless.UserService.CurrentUser
if( (userEmail == null || userPassword == null) && Backendless.UserService.CurrentUser() != null )
{
userEmail = Backendless.UserService.CurrentUser().getEmail();
userPassword = Backendless.UserService.CurrentUser().getPassword();
}
if( userEmail != null )
emailField.setText( userEmail );
if( userEmail != null && userPassword != null )
{
//Sending login request asynchronously from the intent credentials
Backendless.UserService.login( userEmail, userPassword, loginCallback );
}
else
{
Button loginButton = (Button) findViewById( R.id.loginButton );
loginButton.setOnClickListener( loginListener );
findViewById( R.id.registerButton ).setOnClickListener( registerListener );
progressDialog.cancel();
}
Button loginFacebookButton = (Button) findViewById( R.id.loginFacebookButton );
loginFacebookButton.setVisibility( View.INVISIBLE );
TextView loginFacebookText = (TextView) findViewById( R.id.loginWith );
loginFacebookText.setVisibility( View.INVISIBLE );
}
protected void setupPinItem(EditText item){
item.setInputType(InputType.TYPE_NULL);
item.setFilters(filters);
item.setOnTouchListener(otl);
item.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
/*
* 检测用户登陆状态
*
* 如果SharedPreferences中存在用户信息,
* 则说明用户已经登陆,此时直接跳转到MainActivity即可;
* 否则进入登陆界面
*/
sharedPreferences = getSharedPreferences(getString(R.string.login_sp), MODE_PRIVATE);
String oAuth = sharedPreferences.getString(getString(R.string.login_sp_oauth), null);
if (oAuth != null) {
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
intent.putExtra(getString(R.string.login_intent), false);
startActivity(intent);
finish();
}
getActionBar().setDisplayShowHomeEnabled(false);
final EditText userText = (EditText) findViewById(R.id.login_username);
final EditText passText = (EditText) findViewById(R.id.login_password);
/* 保持EditText字体的一致性 */
passText.setTypeface(Typeface.DEFAULT);
passText.setTransformationMethod(new PasswordTransformationMethod());
Button button = (Button) findViewById(R.id.login_button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
username = userText.getText().toString();
password = passText.getText().toString();
/* 给出相应的错误提示 */
if (username.length() == 0 && password.length() == 0) {
SuperToast.create(
LoginActivity.this,
getString(R.string.login_message_miss_both),
SuperToast.Duration.SHORT,
Style.getStyle(Style.RED)
).show();
} else if (username.length() != 0 && password.length() == 0) {
SuperToast.create(
LoginActivity.this,
getString(R.string.login_message_miss_password),
SuperToast.Duration.SHORT,
Style.getStyle(Style.RED)
).show();
} else if (username.length() == 0 && password.length() != 0) {
SuperToast.create(
LoginActivity.this,
getString(R.string.login_message_miss_username),
SuperToast.Duration.SHORT,
Style.getStyle(Style.RED)
).show();
} else {
/* ProgressDialog显示当前正在运行的状态 */
progressDialog = new ProgressDialog(LoginActivity.this);
progressDialog.setMessage(getString(R.string.login_message_authoring));
progressDialog.setCancelable(false);
progressDialog.show();
/* 开启新的线程用于认证 */
HandlerThread handlerThread = new HandlerThread(getString(R.string.login_thread));
handlerThread.start();
Handler handler = new Handler(handlerThread.getLooper());
handler.post(authorizationThread);
}
}
});
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
// getActionBar().setIcon(R.drawable.ic_launcher_black);
/*
* 检测用户登陆状态
*
* 如果SharedPreferences中存在用户信息,
* 则说明用户已经登陆,此时直接跳转到MainActivity即可;
* 否则进入登陆界面
*/
sharedPreferences = getSharedPreferences(getString(R.string.login_sp), MODE_PRIVATE);
String oAuth = sharedPreferences.getString(getString(R.string.login_sp_oauth), null);
if (oAuth != null) {
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
intent.putExtra(getString(R.string.login_intent), false);
startActivity(intent);
finish();
}
final EditText userText = (EditText) findViewById(R.id.login_username);
final EditText passText = (EditText) findViewById(R.id.login_password);
/* 保持EditText字体的一致性 */
passText.setTypeface(Typeface.DEFAULT);
passText.setTransformationMethod(new PasswordTransformationMethod());
Button button = (Button) findViewById(R.id.login_button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
username = userText.getText().toString();
password = passText.getText().toString();
/* 给出相应的错误提示 */
if (username.length() == 0 && password.length() == 0) {
Toast.makeText(
LoginActivity.this,
R.string.login_message_miss_username_and_password,
Toast.LENGTH_SHORT
).show();
} else if (username.length() != 0 && password.length() == 0) {
Toast.makeText(
LoginActivity.this,
R.string.login_message_miss_password,
Toast.LENGTH_SHORT
).show();
} else if (username.length() == 0 && password.length() != 0) {
Toast.makeText(
LoginActivity.this,
R.string.login_message_miss_username,
Toast.LENGTH_SHORT
).show();
} else {
/* ProgressDialog显示当前正在运行的状态 */
progressDialog = new ProgressDialog(LoginActivity.this);
progressDialog.setMessage(getString(R.string.login_message_authoring));
progressDialog.setCancelable(false);
progressDialog.show();
/* 开启新的线程用于认证 */
HandlerThread handlerThread = new HandlerThread(getString(R.string.login_thread));
handlerThread.start();
Handler handler = new Handler(handlerThread.getLooper());
handler.post(authorizationThread);
}
}
});
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
/*
* 检测用户登陆状态
*
* 如果SharedPreferences中存在用户信息,
* 则说明用户已经登陆,此时直接跳转到MainActivity即可;
* 否则进入登陆界面
*/
sharedPreferences = getSharedPreferences(getString(R.string.login_sp), MODE_PRIVATE);
String oAuth = sharedPreferences.getString(getString(R.string.login_sp_oauth), null);
if (oAuth != null) {
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
intent.putExtra(getString(R.string.login_intent), false);
startActivity(intent);
finish();
}
getActionBar().setDisplayShowHomeEnabled(false);
final EditText userText = (EditText) findViewById(R.id.login_username);
final EditText passText = (EditText) findViewById(R.id.login_password);
/* 保持EditText字体的一致性 */
passText.setTypeface(Typeface.DEFAULT);
passText.setTransformationMethod(new PasswordTransformationMethod());
Button button = (Button) findViewById(R.id.login_button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
username = userText.getText().toString();
password = passText.getText().toString();
/* 给出相应的错误提示 */
if (username.length() == 0 && password.length() == 0) {
SuperToast.create(
LoginActivity.this,
getString(R.string.login_message_miss_both),
SuperToast.Duration.SHORT,
Style.getStyle(Style.RED)
).show();
} else if (username.length() != 0 && password.length() == 0) {
SuperToast.create(
LoginActivity.this,
getString(R.string.login_message_miss_password),
SuperToast.Duration.SHORT,
Style.getStyle(Style.RED)
).show();
} else if (username.length() == 0 && password.length() != 0) {
SuperToast.create(
LoginActivity.this,
getString(R.string.login_message_miss_username),
SuperToast.Duration.SHORT,
Style.getStyle(Style.RED)
).show();
} else {
/* ProgressDialog显示当前正在运行的状态 */
progressDialog = new ProgressDialog(LoginActivity.this);
progressDialog.setMessage(getString(R.string.login_message_authoring));
progressDialog.setCancelable(false);
progressDialog.show();
/* 开启新的线程用于认证 */
HandlerThread handlerThread = new HandlerThread(getString(R.string.login_thread));
handlerThread.start();
Handler handler = new Handler(handlerThread.getLooper());
handler.post(authorizationThread);
}
}
});
}