User:Android242/sandbox

=
======================================================================

=
====================================================================== public class PasswordDialogFragment extends DialogFragment implements OnClickListener{

//create instance of PasswordDialogFragment public static PasswordDialogFragment newInstance { PasswordDialogFragment frag = new PasswordDialogFragment; return frag; }	public Dialog onCreateDialog(Bundle savedInstanceState) { final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity); // Get the layout inflater LayoutInflater inflater = getActivity.getLayoutInflater; // Inflate and set the layout for the dialog // Pass null as the parent view because its going in the dialog layout final View dialog = inflater.inflate(R.layout.admin_pswd_dialog,null); alert.setView(dialog);

//use an edit text view to get input for admin pop up		TextView tv_Password= (TextView)dialog.findViewById(R.id.lblEnterPswd); EditText et_Password= (EditText)dialog.findViewById(R.id.txtPassword); String password = et_Password.getText.toString; Button btnSubmit = (Button) dialog.findViewById(R.id.btnSubmit); Button btnCancel = (Button) dialog.findViewById(R.id.btnCancel); btnSubmit.setOnClickListener(this); btnCancel.setOnClickListener(this); // if Cancel button is clicked, close the custom dialog btnCancel.setOnClickListener(new OnClickListener {			@Override			public void onClick(View v) {			getDialog.cancel;			}		}); alert.setCancelable(false); Dialog d = alert.create; return d;		btnSubmit.setOnClickListener(new OnClickListener {			@Override			public void onClick(View arg0) {				// TODO Auto-generated method stub			}		};	}	//create an instance of main activity	PasswordDialog pd=new PasswordDialog;	@Override 	public void onClick(View v) {		// TODO Auto-generated method stub		switch(v.getId){		case R.id.btnSubmit:	       Logger.getInstance.log(getTag, Logger.INFO, ".........SUBMIT.......");			// Get the password entered by user    	        if(password == null)				return;			if(password.equals(pd.autogenPwd)) 			{				// if password is correct, show admin screen				Intent myIntent = new Intent(super.getActivity, AdminActivity.class); 	            startActivityForResult(myIntent, 0);	            //don't finish now			//	setResult(RESULT_OK, returnIntent);			//	this.finish; 			}			else {				//if password is incorrect, reset password field.				Logger.getInstance.log(getTag, Logger.INFO, "Password incorrect."); et_Password.setText(""); }			break; case R.id.btnCancel: // To cancel the dialog getDialog.cancel; break; }	}

}

=
======================================================================

=
====================================================================== public class PasswordDialog extends FragmentActivity{ private final SimpleDateFormat _sdfPassword = new SimpleDateFormat("ddMMyyyy", Locale.US); private final String TAG = "PasswordDialog";

// Variable to store the auto-generated password for the day public String autogenPwd = null;

// Mapping of numbers 0-9 to characters final String[] charMapping = {"-", "A", "B", "C", "D", "E", "F", "G", "H", "I"};

// Mapping of numbers 0-9 to symbols final String[] symbolMapping = {")", "!", "@", "#", "$", "%", "^", "&", "*", "("}; @Override public void onStart {			 super.onStart; Logger.getInstance.log(TAG, Logger.INFO, "Password Dialog - onStart"); // Auto generate password try { autogenPwd = generatePassword; DialogFragment newFragment = PasswordDialogFragment.newInstance; newFragment.show(getSupportFragmentManager,"passwordDialog"); }			 catch (Exception e) { Logger.getInstance.log(TAG, Logger.ERROR, "Error in generatePassword - " + e.getMessage); Logger.getInstance.log(TAG, Logger.ERROR, Log.getStackTraceString(e)); }		  // note: any arithmetic error will be caught by the try/catch block, but autogenPwd will be null System.out.println("*** password *** " + autogenPwd); }       private String generatePassword {   		//Do not log password logic Date today = new Date; String strToday = _sdfPassword.format(today);

Calendar calendar = Calendar.getInstance; int Day  = calendar.get(Calendar.DATE); int Month = calendar.get(Calendar.MONTH) + 1; int date = Integer.parseInt(strToday); int A = date + (Day * Month); int B = A * (Day + Month); long C = B/Day; String strC = String.valueOf(Math.abs(C)); //first digit int n1 = strC.charAt(0) - '0'; String firstChar = charMapping[n1]; // second digit int n2 = strC.charAt(1) - '0'; String secondChar = charMapping[n2]; // Third digit int n3 = strC.charAt(2) - '0'; String thirdChar = symbolMapping[n3]; String password = firstChar + secondChar + thirdChar + strC.substring(3); return password; } }