private void beautyView() { beautyEditText(this.mInputAccount, L10NString.getString("umgr_please_input_username"), this.mAccountTextWatcher); beautyCleanButton(this.mClearInputAccount, this); this.mInputAccountLayout.setOnClickListener(this); beautyCleanButton(this.mClearInputPassword, this); this.mInputPassword.setOnClickListener(this); beautyEditText(this.mInputPassword, L10NString.getString("umgr_please_input_password"), this.mPasswordTextWatcher); beautyColorTextView(this.mRegister, "#007dc4", false, L10NString.getString("umgr_whether_register_ornot"), this); beautyColorTextView(this.mFindpwd, "#007dc4", false, L10NString.getString("umgr_whether_forget_password"), this); beautyColorTextView(this.mSwitchAccount, "#007dc4", false, L10NString.getString("umgr_third_login_qihoo_tip"), this); beautyButtonGreen(this.mLogin, L10NString.getString("umgr_login"), this); beautyTextView(this.mAgreeClause1, L10NString.getString("umgr_login_agree_clause_1")); beautyTextView(this.mAgreeClauseUser, L10NString.getString("umgr_agree_clause_2_user")); beautyColorTextView(this.mAgreement, "#0099e5", true, L10NString.getString("umgr_agree_clause_2_agreement"), this); beautyTextView(this.mAnd, L10NString.getString("umgr_agree_clause_2_and")); beautyColorTextView(this.mPrivacy, "#0099e5", true, L10NString.getString("umgr_agree_clause_2_privacy"), this); beautyCheckButton(this.mShowPwd, new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { LoginActivity.this.mInputPassword.setTransformationMethod(LoginActivity.this.mShowPwd.isChecked() ? HideReturnsTransformationMethod.getInstance() : PasswordTransformationMethod.getInstance()); } }); loadPrivateConfig(); }
private void updatePasswordVisibility() { if (mPasswordVisible) { setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } else { setTransformationMethod(PasswordTransformationMethod.getInstance()); } Drawable drawable = ContextCompat.getDrawable(getContext(),R.drawable.ic_remove_red_eye_black_18dp); Drawable wrap = DrawableCompat.wrap(drawable); if (mPasswordVisible) { DrawableCompat.setTint(wrap, ContextCompat.getColor(getContext(), R.color.colorPrimary)); DrawableCompat.setTintMode(wrap, PorterDuff.Mode.SRC_IN); wrap = wrap.mutate(); } else { DrawableCompat.setTint(wrap, Color.BLACK); DrawableCompat.setTintMode(wrap, PorterDuff.Mode.SRC_IN); wrap = wrap.mutate(); } setCompoundDrawablesWithIntrinsicBounds(null, null, wrap, null); setCompoundDrawablePadding(10); }
/** * 初始化视图 */ private void initViews() { accountEdit = (CleanEditText) this.findViewById(R.id.et_email_phone); accountEdit.setImeOptions(EditorInfo.IME_ACTION_NEXT); accountEdit.setTransformationMethod(HideReturnsTransformationMethod .getInstance()); passwordEdit = (CleanEditText) this.findViewById(R.id.et_password); passwordEdit.setImeOptions(EditorInfo.IME_ACTION_DONE); passwordEdit.setImeOptions(EditorInfo.IME_ACTION_GO); passwordEdit.setTransformationMethod(PasswordTransformationMethod .getInstance()); passwordEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_GO) { clickLogin(); } return false; } }); }
public void setText(String name, String text) { if (!mConformanceMode) { if (null == mScrollText) { mScrollText = new ScrollView(mContext); mScrollText.setScrollBarStyle(SCROLLBARS_OUTSIDE_INSET); addView(mScrollText, new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0, 0)); if (DEBUG) { mScrollText.setBackgroundColor(0xFF00FF00); } } if (null == mTextView) { mTextView = new TextView(mContext); mTextView.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); mScrollText.addView(mTextView); } mScrollText.requestFocus(); } mTextView.setVisibility(View.VISIBLE); mTextView.setText(text); // Let the text in Mms can be selected. mTextView.setTextIsSelectable(true); }
@Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { boolean touchable = ( getWidth() - mWidth - Interval < event.getX() ) && (event.getX() < getWidth() - Interval); if (touchable) { isVisible = !isVisible; if (isVisible){ //设置EditText文本为可见的 setTransformationMethod(HideReturnsTransformationMethod.getInstance()); }else{ //设置EditText文本为隐藏的 setTransformationMethod(PasswordTransformationMethod.getInstance()); } } } return super.onTouchEvent(event); }
@Override public boolean onTouchEvent(MotionEvent event) { final int lens = this.getText().toString().length(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: { boolean isClean = (event.getX() > (getWidth() - getTotalPaddingRight())) && (event.getX() < (getWidth() - getPaddingRight())); if (isClean) { this.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); setSelection(lens); } } break; case MotionEvent.ACTION_UP: { this.setTransformationMethod(PasswordTransformationMethod.getInstance()); setSelection(lens); } break; default: break; } return super.onTouchEvent(event); }
@Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { switch (buttonView.getId()) { case R.id.ap_button: if (isChecked) { //Turn on AP enableAP(); } else { //Turn off AP disableAP(); } break; case R.id.checkBox: if (!isChecked) { passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance()); } else { passwordEditText.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } } }
@AfterViews protected void init() { setTitle(R.string.regist3); // phone="11112345685"; passwdCheck.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(isChecked){ // mEditTextPw.setInputType(InputType.TYPE_TEXT_VARIATION_NORMAL); mEditTextPw.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); mEditTextPw.setSelection(mEditTextPw.getText().length()); }else{ mEditTextPw.setTransformationMethod(PasswordTransformationMethod.getInstance()); mEditTextPw.setSelection(mEditTextPw.getText().length()); // mEditTextPw.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); } } }); }
public void setText(String name, String text) { if (!mConformanceMode) { if (null == mScrollText) { mScrollText = new ScrollView(mContext); mScrollText.setScrollBarStyle(SCROLLBARS_OUTSIDE_INSET); addView(mScrollText, new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0, 0)); if (DEBUG) { mScrollText.setBackgroundColor(0xFF00FF00); } } if (null == mTextView) { mTextView = new TextView(mContext); mTextView.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); mScrollText.addView(mTextView); } mScrollText.requestFocus(); } mTextView.setVisibility(View.VISIBLE); mTextView.setText(text); }
/** * 因为我们不能直接给EditText设置点击事件,所以我们用记住我们按下的位置来模拟点击事件 * 当我们按下的位置在 EditText的宽度 - 图标到控件右侧的间距 - 图标的宽度 和 * EditText的宽度 - 图标到控件右侧的间距 之间我们就算点击了图标,竖直方向没有考虑 * @param event * @return */ @Override public boolean onTouchEvent(MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_UP){ if(getCompoundDrawables()[2] != null){ boolean isTouched = event.getX() > (getWidth() - getTotalPaddingRight()) && (event.getX() < (getWidth() - getPaddingLeft())); if(isTouched){ if(mRightClickListener == null){ if(funcType == TYPE_CAN_CLEAR){ this.setText(""); }else if(funcType == TYPE_CAN_WATCH_PWD){ if(eyeOpen){ //变为密文,TYPE_CLASS_TEXT 和 TYPE_TEXT_VARIATION_PASSWORD 必须一起使用 this.setTransformationMethod(PasswordTransformationMethod.getInstance()); eyeOpen = false; }else{ //变为明文 this.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); eyeOpen = true; } switchWatchPwdIcon(); } }else { //如果没有则回调 mRightClickListener.onClick(this); } } } } return super.onTouchEvent(event); }
private void setPwdVisible(boolean b) { if (!b){ ivEye.setBackgroundResource(R.drawable.eye_close); ivEye.setTag(false); etPwd.setTransformationMethod(PasswordTransformationMethod.getInstance()); }else{ ivEye.setBackgroundResource(R.drawable.eye_open); ivEye.setTag(true); etPwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } etPwd.invalidate(); }
@OnClick(R.id.iv_pwd) public void showPwd() { // 明文显示 if (isShow) { etPwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); ivPwd.setImageResource(R.drawable.ic_visibility_blue_500_24dp); } else { // 密码显示 etPwd.setTransformationMethod(PasswordTransformationMethod.getInstance()); ivPwd.setImageResource(R.drawable.ic_visibility_off_grey_500_24dp); } isShow = !isShow; }
private void togglePassword() { showPassword = !showPassword; if (showPassword) { imageValidfy.setImageResource(R.drawable.ic_password_show); editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } else { imageValidfy.setImageResource(R.drawable.ic_password_normal); editText.setTransformationMethod(PasswordTransformationMethod.getInstance()); } editText.setSelection(editText.length()); }
private void initListener() { mainLayout.setOnSoftKeyboardVisibilityChangeListener( new SoftKeyboardHandledLinearLayout.SoftKeyboardVisibilityChangeListener() { @Override public void onSoftKeyboardShow() { avatarLayout.setVisibility(View.GONE); listenerSoftInput(); } @Override public void onSoftKeyboardHide() { avatarLayout.setVisibility(View.VISIBLE); listenerSoftInput(); } }); mShow.setOnToggleChanged(new SwitchButton.OnToggleChanged() { @Override public void onToggle(boolean isChecked) { if (isChecked) { //如果选中,显示密码 mPasswordEditText.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } else { //否则隐藏密码 mPasswordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance()); } } }); }
private void initListener() { mainLayout.setOnSoftKeyboardVisibilityChangeListener( new SoftKeyboardHandledLinearLayout.SoftKeyboardVisibilityChangeListener() { @Override public void onSoftKeyboardShow() { avatarLayout.setVisibility(View.GONE); bottomLayout.setVisibility(View.VISIBLE); listenerSoftInput(); } @Override public void onSoftKeyboardHide() { avatarLayout.setVisibility(View.VISIBLE); bottomLayout.setVisibility(View.VISIBLE); listenerSoftInput(); } }); mShow.setOnToggleChanged(new SwitchButton.OnToggleChanged() { @Override public void onToggle(boolean isChecked) { if (isChecked) { //如果选中,显示密码 mPasswordEditText.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } else { //否则隐藏密码 mPasswordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance()); } } }); }
/** * 是否显示明文 * @param showPwd */ public void setShowPwd(boolean showPwd) { int length = textViews.length; for(int i = 0; i < length; i++) { if (showPwd) { textViews[i].setTransformationMethod(PasswordTransformationMethod.getInstance()); } else { textViews[i].setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } } }
public void showkey() { //get object TextView keybox = (TextView) findViewById(R.id.editText2); //Set InputType keybox.setTransformationMethod(HideReturnsTransformationMethod.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)); }
private void setInputStyle(Context context, ConfigBean bean) { if (TextUtils.isEmpty(bean.hint1)) { et1.setVisibility(View.GONE); } else { bean.setNeedSoftKeyboard(true); et1.setVisibility(View.VISIBLE); et1.setHint(bean.hint1); et1.setTextColor(Tool.getColor(et1.getContext(), bean.inputTxtColor)); et1.setTextSize(bean.inputTxtSize); } if (TextUtils.isEmpty(bean.hint2)) { et2.setVisibility(View.GONE); } else { bean.setNeedSoftKeyboard(true); et2.setVisibility(View.VISIBLE); et2.setHint(bean.hint2); et2.setTextColor(Tool.getColor(et2.getContext(), bean.inputTxtColor)); et2.setTextSize(bean.inputTxtSize); if (bean.isInput2HideAsPassword) { //设置EditText文本为可见的 et2.setTransformationMethod(PasswordTransformationMethod.getInstance()); } else { //设置EditText文本为隐藏的 et2.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } } }
private void setInputStyle(Context context, ConfigBean bean) { if (TextUtils.isEmpty(bean.hint1)) { et1.setVisibility(View.GONE); } else { bean.setNeedSoftKeyboard(true); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) sv.getLayoutParams(); params.height = LinearLayout.LayoutParams.WRAP_CONTENT; params.weight = 0; sv.setLayoutParams(params); et1.setVisibility(View.VISIBLE); et1.setHint(bean.hint1); et1.setTextColor(Tool.getColor(et1.getContext(),bean.inputTxtColor)); et1.setTextSize(bean.inputTxtSize); } if (TextUtils.isEmpty(bean.hint2)) { et2.setVisibility(View.GONE); } else { bean.setNeedSoftKeyboard(true); et2.setVisibility(View.VISIBLE); et2.setHint(bean.hint2); et2.setTextColor(Tool.getColor(et2.getContext(),bean.inputTxtColor)); et2.setTextSize(bean.inputTxtSize); if (bean.isInput2HideAsPassword) { //设置EditText文本为可见的 et2.setTransformationMethod(PasswordTransformationMethod.getInstance()); } else { //设置EditText文本为隐藏的 et2.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } } }
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); showActionBar(R.string.ct_modify_pass); setContentView(R.layout.ct_modify_password); mOnce = (TextView) findViewById(R.id.ct_passwd_one); mTwice = (TextView) findViewById(R.id.ct_passwd_twice); mTwice.setImeOptions(EditorInfo.IME_ACTION_DONE); mTwice.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { tryModify(); return true; } }); ((CheckBox) findViewById(R.id.toggle_pw)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { if (checked) { mOnce.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); mTwice.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } else { mOnce.setTransformationMethod(PasswordTransformationMethod.getInstance()); mTwice.setTransformationMethod(PasswordTransformationMethod.getInstance()); } } }); }
@Override protected View onCreateDialogView() { View view = super.onCreateDialogView(); mUsername = (EditText) view.findViewById(R.id.txt_login_username); mPassword = (EditText) view.findViewById(R.id.txt_login_remotekey); CheckBox mShowRKey = (CheckBox) view.findViewById(R.id.chk_login_showremkey); mShowRKey.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { mPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } else { mPassword.setTransformationMethod(PasswordTransformationMethod.getInstance()); } } }); Button mGoToRKey = (Button) view.findViewById(R.id.btn_login_gotoremkey); mGoToRKey.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse("http://friendfeed.com/remotekey")); v.getContext().startActivity(browse); } }); return view; }
private void passwordShownState() { isPasswordVisible = true; showPasswordButton.setVisibility(View.VISIBLE); showPasswordButton.setText(hideText); passwordField.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); passwordField.setSelection(passwordField.getText().length()); }
/** * Takes care if checked/unchecked box for showing/not showing password */ private void show_password() { if (mChbShowPwd.isChecked()) { mTextboxPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); return; } mTextboxPassword.setTransformationMethod(PasswordTransformationMethod.getInstance()); }
@Override protected void onFinishInflate() { mTextPreview = (TextView) findViewById(R.id.text_preview); mTextPreview.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); mImagePreview = (ImageView) findViewById(R.id.image_preview); mAttachmentName = (TextView) findViewById(R.id.attachment_name); mAttachmentIcon = (ImageView) findViewById(R.id.attachment_icon); }
@BindingAdapter(value = {"app:passwordChangeVisibility"}) public static void passwordChangeVisibility(TextInputEditText inputEditText, boolean isVisible) { inputEditText.setTransformationMethod(isVisible ? HideReturnsTransformationMethod.getInstance() : PasswordTransformationMethod.getInstance()); inputEditText.setSelection(inputEditText.getText().length()); }
@Override public void initListener() { mEtNick.addTextChangedListener(watcher); mEtPwd.addTextChangedListener(watcher); mEtPhone.addTextChangedListener(watcher); mEtVerifyCode.addTextChangedListener(watcher); mEtNick.setOnFocusChangeListener((v, hasFocus) -> { if (hasFocus) { mVLineNick.setBackgroundColor(UIUtils.getColor(R.color.green0)); } else { mVLineNick.setBackgroundColor(UIUtils.getColor(R.color.line)); } }); mEtPwd.setOnFocusChangeListener((v, hasFocus) -> { if (hasFocus) { mVLinePwd.setBackgroundColor(UIUtils.getColor(R.color.green0)); } else { mVLinePwd.setBackgroundColor(UIUtils.getColor(R.color.line)); } }); mEtPhone.setOnFocusChangeListener((v, hasFocus) -> { if (hasFocus) { mVLinePhone.setBackgroundColor(UIUtils.getColor(R.color.green0)); } else { mVLinePhone.setBackgroundColor(UIUtils.getColor(R.color.line)); } }); mEtVerifyCode.setOnFocusChangeListener((v, hasFocus) -> { if (hasFocus) { mVLineVertifyCode.setBackgroundColor(UIUtils.getColor(R.color.green0)); } else { mVLineVertifyCode.setBackgroundColor(UIUtils.getColor(R.color.line)); } }); mIvSeePwd.setOnClickListener(v -> { if (mEtPwd.getTransformationMethod() == HideReturnsTransformationMethod.getInstance()) { mEtPwd.setTransformationMethod(PasswordTransformationMethod.getInstance()); } else { mEtPwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } mEtPwd.setSelection(mEtPwd.getText().toString().trim().length()); }); mBtnSendCode.setOnClickListener(v -> { if (mBtnSendCode.isEnabled()) { mPresenter.sendCode(); } }); mBtnRegister.setOnClickListener(v -> { mPresenter.register(); }); }
@Override public void initListener() { mEtNick.addTextChangedListener(watcher); mEtPwd.addTextChangedListener(watcher); mEtPhone.addTextChangedListener(watcher); mEtVerifyCode.addTextChangedListener(watcher); /** * 通过监听事件判断EditText下面的基线颜色 */ mEtNick.setOnFocusChangeListener((v, hasFocus) -> { if (hasFocus) { mVLineNick.setBackgroundColor(UIUtils.getColor(R.color.green0)); } else { mVLineNick.setBackgroundColor(UIUtils.getColor(R.color.line)); } }); mEtPwd.setOnFocusChangeListener((v, hasFocus) -> { if (hasFocus) { mVLinePwd.setBackgroundColor(UIUtils.getColor(R.color.green0)); } else { mVLinePwd.setBackgroundColor(UIUtils.getColor(R.color.line)); } }); mEtPhone.setOnFocusChangeListener((v, hasFocus) -> { if (hasFocus) { mVLinePhone.setBackgroundColor(UIUtils.getColor(R.color.green0)); } else { mVLinePhone.setBackgroundColor(UIUtils.getColor(R.color.line)); } }); mEtVerifyCode.setOnFocusChangeListener((v, hasFocus) -> { if (hasFocus) { mVLineVertifyCode.setBackgroundColor(UIUtils.getColor(R.color.green0)); } else { mVLineVertifyCode.setBackgroundColor(UIUtils.getColor(R.color.line)); } }); /** * 查看密码点击事件 */ mIvSeePwd.setOnClickListener(v -> { if (mEtPwd.getTransformationMethod() == HideReturnsTransformationMethod.getInstance()) { mEtPwd.setTransformationMethod(PasswordTransformationMethod.getInstance()); } else { mEtPwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } mEtPwd.setSelection(mEtPwd.getText().toString().trim().length()); }); /** * 发送验证的事件 MVP实现 */ mBtnSendCode.setOnClickListener(v -> { if (mBtnSendCode.isEnabled()) { mPresenter.sendCode(); } }); /** * 注册的事件 MVP实现 */ mBtnRegister.setOnClickListener(v -> { mPresenter.register(); }); }
private void showWindow(){ windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE); WindowManager.LayoutParams params = new WindowManager.LayoutParams(); params.width = WindowManager.LayoutParams.MATCH_PARENT; params.height = WindowManager.LayoutParams.MATCH_PARENT; params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; params.format = PixelFormat.TRANSPARENT; params.gravity = Gravity.CENTER; params.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN; LayoutInflater inflater = LayoutInflater.from(this); v = (RelativeLayoutWithKeyDetect) inflater.inflate(R.layout.window, null); v.setCallback(new RelativeLayoutWithKeyDetect.IKeyCodeBackCallback() { @Override public void backCallback() { if (v!=null && v.isAttachedToWindow()) L.e("remove view "); windowManager.removeViewImmediate(v); } }); btn_sure = (Button) v.findViewById(R.id.btn_sure); btn_cancel = (Button) v.findViewById(R.id.btn_cancel); et_account = (EditText) v.findViewById(R.id.et_account); et_pwd = (EditText) v.findViewById(R.id.et_pwd); cb_showpwd = (CheckBox) v.findViewById(R.id.cb_showpwd); cb_showpwd.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { et_pwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } else { et_pwd.setTransformationMethod(PasswordTransformationMethod.getInstance()); } et_pwd.setSelection(TextUtils.isEmpty(et_pwd.getText()) ? 0 : et_pwd.getText().length()); } }); //useless // v.setOnKeyListener(new View.OnKeyListener() { // @Override // public boolean onKey(View v, int keyCode, KeyEvent event) { // Log.e("zhao", keyCode+""); // if (keyCode == KeyEvent.KEYCODE_BACK) { // windowManager.removeViewImmediate(v); // return true; // } // return false; // } // }); //点击外部消失 v.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { Rect temp = new Rect(); view.getGlobalVisibleRect(temp); L.e("remove view "); if (temp.contains((int)(event.getX()), (int)(event.getY()))){ windowManager.removeViewImmediate(v); return true; } return false; } }); btn_sure.setOnClickListener(this); btn_cancel.setOnClickListener(this); L.e("add view "); windowManager.addView(v, params); }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { act = getActivity(); rootView = inflater.inflate(R.layout.fragment_login, container, false); setHasOptionsMenu(true); final BootstrapEditText email = (BootstrapEditText) rootView.findViewById(R.id.email); final BootstrapEditText password = (BootstrapEditText) rootView.findViewById(R.id.password); final BootstrapButton btnLogin = (BootstrapButton) rootView.findViewById(R.id.btnLogin); CheckBox checkBox = (CheckBox) rootView.findViewById(R.id.showPass); InputFilter filter = new InputFilter() { public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { for (int i = start; i < end; i++) { if (Character.isSpaceChar(source.charAt(i))) { return ""; } } return null; } }; email.setFilters(new InputFilter[]{filter}); password.setFilters(new InputFilter[]{filter}); if(!act.getSharedPreferences("EroadPrefs", 0).getString("user_name", "").equals("")){ email.setText(act.getSharedPreferences("EroadPrefs", 0).getString("user_email", "")); } checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (!isChecked) { password.setTransformationMethod(PasswordTransformationMethod.getInstance()); } else { password.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } } }); btnLogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String string_email = email.getText().toString(); String string_password = password.getText().toString(); if (!string_password.trim().equals("")) { new CheckIfUserExists(string_email, encryptPassword(string_password)).execute(); }else { Toast.makeText(act, "The password can not be empty", Toast.LENGTH_SHORT).show(); } } }); return rootView; }