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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 几种常见卷积神经网络结构

    几种常见卷积神经网络结构卷积神经网络图像特征的提取与分类一直是计算机视觉领域的一个基础而重要的研究方向。卷积神经网络(ConvolutionalNeuralNetwork,CNN)提供了一种端到端的学习模型,模型中的参数可以通过传统的梯度下降方法进行训练,经过训练的卷积神经网络能够学习到图像中的特征,并且完成对图像特征的提取和分类。作为神经网络领域的一个重要研究分支,卷积神经网络的特点在于其每一层的特征都由上一层的局部区域通过共享权值的卷积核激励得到。这一特点使得卷积神经网络相比于其他神经网络方法更适合应用于图像特征的.

    2022年6月16日
    20
  • 深度图像基础知识(一)[通俗易懂]

    深度图像基础知识(一)[通俗易懂]深度图像(depthimage)也被称为距离影像(rangeimage),是指将从图像采集器到场景中各点的距离(深度)作为像素值的图像,它直接反映了景物可见表面的几何形状。深度图像经过坐标转换可以计算为点云数据,有规则及必要信息的点云数据也可以反算为深度图像数据。深度数据流所提供的图像帧中,每一个像素点代表的是在深度感应器的视野中,该特定的(x,y)坐标处物体到离摄像头平面最近的

    2022年4月25日
    46
  • vue分页组件动态页码_怎样分页设置页码

    vue分页组件动态页码_怎样分页设置页码效果如下:HTML:<ulclass=”pagef16tcmt30″><li><spanv-if=”page>1″><b@click=”page–,pageClick()”>上一页</b></span><spanv-if=”page==1″>上一页</span><spanv-for=”indexinpagesAll”:key=”index”.

    2022年9月13日
    0
  • (二)Sql Server的基本配置以及使用Navicat连接Sql Server

    (二)Sql Server的基本配置以及使用Navicat连接Sql Server一:sqlserver连接的验证方式分为两种:Windows身份认证:使用windows的用户名密码验证SQLServer身份认证:使用sqlserver的用户名+密码的方式登录()二:sqlserver的环境配置实际生产环境服务器肯定是需要远程连接的,所以我们需要对本机的sqlserver进行一下的基本配置:配置支持tcp连接(否则无法使用连接工具进行远程连接)配置支持SQLServer身份认证(一般情况下都会使用这种验证方式而不是windows验证)配置

    2022年8月30日
    0
  • PyPDF2的使用「建议收藏」

    PyPDF2的使用「建议收藏」pdf使用Adobe公司开发,现在由国际标准化组织ISO进行维护。PDF合成包含链接和按钮,表单字段,音频,视频和业务逻辑在这篇文章中,我们将学习如何做一些pdf的操作:从PDF中提取文字旋转pdf页合并pdf分割pdf向pdf页中添加水印使用简单的python脚本1、安装我们将使用第三方的模块PyPDF2PyPDF2是作为PDF…

    2022年6月23日
    27
  • 奇怪的print progname “:\n”日志

    奇怪的print progname “:\n”日志

    2022年2月24日
    34

发表回复

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

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