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 }
时间: 2024-09-30 16:01:16