Android 带password输入界面的Dialog实现机制

Android 带password输入界面的Dialog实现机制

大家好,又见面了,我是全栈君。

1.布局实现:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:orientation="vertical">
    <EditText
        android:id="@+id/FactRstDialogPsw"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:password="true"
        android:singleLine="true"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_weight="2">
        <Button
            android:id="@+id/FactRstDialogCancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="@string/cancel"
            android:layout_weight="1"/>
        <Button
            android:id="@+id/FactRstDialogCertain"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="@string/user_dict_settings_add_dialog_confirm"
            android:layout_weight="1"/>
	</LinearLayout>
</LinearLayout>

2.代码实现:

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.mediatek.common.featureoption.FeatureOption; 
public class MasterClearConfirm extends Fragment {
	//cbk.add
	private Dialog mFactRstPwsCheckDialog;
	private Button cancelButton;
	private Button okButton;
	private EditText pswEdit;
	//cbk.add
    private Button.OnClickListener mFinalClickListener = new Button.OnClickListener() {

        public void onClick(View v) {
            if (Utils.isMonkeyRunning()) {
                return;
            }
            /// M:For CT feature resetPhone with mEraseInternalData: data | app | media 

			//cbk.add
            //mExt.onResetPhone(getActivity(), mEraseInternalData, mEraseSdCard);
			createFactoryResetPwdDialog();	
			//cbk.add			
        }
    };
//cbk.add
    private void createFactoryResetPwdDialog() {

		if (mFactRstPwsCheckDialog == null) {
			mFactRstPwsCheckDialog = new Dialog(getActivity());
			//mFactRstPwsCheckDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
			mFactRstPwsCheckDialog.setContentView(R.layout.factory_rst_pwd_dialog);
			mFactRstPwsCheckDialog.setTitle("please input password:");
		
			pswEdit = (EditText)mFactRstPwsCheckDialog.findViewById(R.id.FactRstDialogPsw);
			cancelButton = (Button)mFactRstPwsCheckDialog.findViewById(R.id.FactRstDialogCancel);
			okButton = (Button)mFactRstPwsCheckDialog.findViewById(R.id.FactRstDialogCertain);

			cancelButton.setOnClickListener(new View.OnClickListener()
			{
				@Override
				public void onClick(View source)
				{
					mFactRstPwsCheckDialog.dismiss();//finish();
				}
			});
			
			okButton.setOnClickListener(new View.OnClickListener()
			{
				@Override
				public void onClick(View source)
				{
					onPairPassword(pswEdit.getText().toString());
					pswEdit.setText(null);
				}
			});

		}

		if (mFactRstPwsCheckDialog != null) {
			mFactRstPwsCheckDialog.show();
		}	

    }

    private boolean onPairPassword(String value){	
		//Log.d(TAG, "onPairPassword()  pwd value=" +value);
		boolean pwdvalid=false; 

		if(value ==null ){
			//Log.d(TAG, "onPairPassword()  value ==null");
			Toast.makeText(getActivity(), getString(R.string.settings_pwd_empty_str), Toast.LENGTH_SHORT).show();
			
			return false;
		}

		if(value.length()<=0 ){
			//Log.d(TAG, "onPairPassword()  value ==null");
			Toast.makeText(getActivity(), getString(R.string.settings_pwd_empty_str), Toast.LENGTH_SHORT).show();
			
			return false;
		}

		String def_pwd_value =getString(R.string.settings_pwd_def);

		//if(value.length() !=6 || isNumeric(value) ==false){
		if(value.length() < def_pwd_value.length()){
			//add the item into the Locked list.
			//Log.d(TAG, "onPairPassword()  value ==valid");
			Toast.makeText(getActivity(), getString(R.string.settings_pwd_wrong_str), Toast.LENGTH_SHORT).show();
			return false;
		}	

		//Log.d(TAG, "onPairPassword()  pwd_length =" +value.length() );

		if (value.equals(def_pwd_value)) {
			//add the item into the Locked list.
			//Log.d(TAG, "onPairPassword()  mPref.contains(PWD_PREF_NAME) ==true");
			//no store the pwd activity
			mFactRstPwsCheckDialog.dismiss();//finish();
			mExt.onResetPhone(getActivity(), mEraseInternalData, mEraseSdCard);
			return true;
		}

		Toast.makeText(getActivity(), getString(R.string.settings_pwd_wrong_str), Toast.LENGTH_SHORT).show();
		return false;
    }	
//cbk.add
	
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/116040.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • python 之免费ip代理池[通俗易懂]

    python 之免费ip代理池[通俗易懂]基于proxy_pool,部署了一个开放的免费ip代理池,提供出来供大家使用。数据有效性每2分钟更新一次。地址:http://proxy.linuxdba.ltd/all/开源项目地址:https://github.com/jhao104/proxy_pool

    2022年5月29日
    63
  • mac mysql改密码_mac系统重置密码

    mac mysql改密码_mac系统重置密码MAC重置MySql密码步骤:1.关闭mysql服务2.打开终端按步骤输入:输入1:cd/usr/local/mysql/bin/输入2:sudo./mysqld_safe–skip-grant-tables3.打开另外一个终端窗口:第一步输入:cd/usr/local/mysql/bin/第二步输入:./mysql第三步输入:FLUSHPRIVILEGES;第四步输入:ALTERUSER‘root’@‘localhost’IDENTIFIEDBY‘1

    2022年10月11日
    5
  • 射频RC522一些知识「建议收藏」

    射频RC522一些知识「建议收藏」我的测试为RC522的读写模块和S50的射频卡:一.S50的射频卡有如下特点:1. 分为16个扇区,每个扇区为4块,每块16个字节,以块为存取单位2. 每个扇区有独立的一组密码及访问控制3. 每张卡有唯一序列号,为32位 二.射频卡的介绍1、M1卡分为16个扇区,每个扇区由4块(块0、块1、块2、块3)组成,(我们也将16个扇区的64个块按绝对地址编号为0~63,

    2022年7月26日
    19
  • media type的类型汇总

    media type的类型汇总用的比较多的是screen和print:区分打印和屏幕显示(Android,iPhone都不是手持设备handheld,都是screen设备)转载于:https://www.cnblogs.com/hulaoxi/p/6140054.html

    2022年5月25日
    87
  • 稀疏数组(最详解)「建议收藏」

    稀疏数组(最详解)「建议收藏」概念当一个数组中大部分元素为0,或者为同一值的数组时,可以使用稀疏数组来保存该数组。 稀疏数组的处理方式是:记录数组一共有几行几列,有多少个不同值;把具有不同值的元素和行列及值记录在一个小规模的数组中,从而缩小程序的规模 如下图:左边是原始数组,右边是稀疏数组代码实现publicclassSparseArray{publicstaticvoidmain(String[]args){//创建一个二维数组11*110:没有棋子,1:黑..

    2025年7月17日
    4
  • phpstorm激活码[最新免费获取]

    (phpstorm激活码)最近有小伙伴私信我,问我这边有没有免费的intellijIdea的激活码,然后我将全栈君台教程分享给他了。激活成功之后他一直表示感谢,哈哈~IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html…

    2022年3月26日
    44

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号