Android Dialog implementation mechanism with Password Input Interface, androiddialog

Source: Internet
Author: User

Android Dialog implementation mechanism with Password Input Interface, androiddialog

1. layout implementation:

<?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. Code implementation:

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.addprivate 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(){@Overridepublic void onClick(View source){mFactRstPwsCheckDialog.dismiss();//finish();}});okButton.setOnClickListener(new View.OnClickListener(){@Overridepublic 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 activitymFactRstPwsCheckDialog.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}




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.