src/jpm/dg/TextHideScreen.java
/**
	 * Displays and controls a dialog for saving with a password and a security
	 * level.
	 */
Displays and controls a dialog for saving with a password and a security
level.
Displays and controls a dialog for saving with a password and a security level .
public void displaySaveDialog() {
		LayoutInflater inflater = getLayoutInflater();
		View alertLayout = inflater.inflate(R.layout.encode_dialog, null);
		final EditText fileNameField = (EditText) alertLayout
				.findViewById(R.id.fileNameField);
		final EditText passwordField = (EditText) alertLayout
				.findViewById(R.id.passField);
		final TextView passLabel = (TextView) alertLayout
				.findViewById(R.id.passLabel);
		final CheckBox cbShowPassword = (CheckBox) alertLayout
				.findViewById(R.id.cb_ShowPassword);
		final SeekBar seekBar = (SeekBar) alertLayout
				.findViewById(R.id.seekbar);
		final TextView securityLabel = (TextView) alertLayout
				.findViewById(R.id.securityLabel);
		seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
			public void onProgressChanged(SeekBar seekBar, int progress,
					boolean fromUser) {
				currentSecurity = progress;
				securityLabel
						.setText("Security Level: " + SEC_LEVELS[progress]);
			}
			public void onStartTrackingTouch(SeekBar seekBar) {
			}
			public void onStopTrackingTouch(SeekBar seekBar) {
			}
		});
		cbShowPassword.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				isEncrypted = cbShowPassword.isChecked();
				if (isEncrypted) {
					passwordField.setEnabled(true);
					passLabel.setVisibility(View.VISIBLE);
					passwordField.setVisibility(View.VISIBLE);
				} else {
					passwordField.setEnabled(false);
					passLabel.setVisibility(View.INVISIBLE);
					passwordField.setVisibility(View.INVISIBLE);
				}
			}
		});
		cbShowPassword.setChecked(!isEncrypted);
		cbShowPassword.performClick();
		fileNameField.setText(currentFileName);
		fileNameField.setSelection(fileNameField.getText().length());
		passwordField.setText(currentPassword);
		seekBar.setProgress(currentSecurity);
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setTitle("Encode Text:");
		builder.setView(alertLayout);
		builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				currentFileName = fileNameField.getText().toString()
						.replace(" ", "_").trim();
				String error = Util.isValidFileName(currentFileName);
				boolean isBelowCapacity = true;
				currentPassword = null;
				if (cbShowPassword.isChecked()
						&& !passwordField.getText().toString().isEmpty()) {
					currentPassword = passwordField.getText().toString();
					isBelowCapacity = Crypto.isBelowCapacity(editText.getText()
							.toString(), (bitmap.getWidth() * bitmap
							.getHeight()));
				}
				if (error.equals("") && isBelowCapacity) {
					new HideTextTask(TextHideScreen.this).execute();
				} else {
					if (!isBelowCapacity) {
						error = "This data will exceed the image capacity if encrypted";
					}
					Toast.makeText(getApplicationContext(), error,
							Toast.LENGTH_LONG).show();
					displaySaveDialog();
				}
			}
		});
		builder.setNegativeButton("Cancel",
				new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						currentFileName = fileNameField.getText().toString()
								.replace(" ", "_").trim();
						currentPassword = passwordField.getText().toString();
						dialog.cancel();
						return;
					}
				});
		builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
			@Override
			public void onCancel(DialogInterface dialog) {
				currentFileName = fileNameField.getText().toString()
						.replace(" ", "_").trim();
				currentPassword = passwordField.getText().toString();
			}
		});
		builder.show();
	}
public void displaySaveDialog ( ) { LayoutInflater inflater = getLayoutInflater ( ) ; View alertLayout = inflater . inflate ( R . layout . encode_dialog , null ) ; final EditText fileNameField = ( EditText ) alertLayout . findViewById ( R . id . fileNameField ) ; final EditText passwordField = ( EditText ) alertLayout . findViewById ( R . id . passField ) ; final TextView passLabel = ( TextView ) alertLayout . findViewById ( R . id . passLabel ) ; final CheckBox cbShowPassword = ( CheckBox ) alertLayout . findViewById ( R . id . cb_ShowPassword ) ; final SeekBar seekBar = ( SeekBar ) alertLayout . findViewById ( R . id . seekbar ) ; final TextView securityLabel = ( TextView ) alertLayout . findViewById ( R . id . securityLabel ) ; seekBar . setOnSeekBarChangeListener ( new OnSeekBarChangeListener ( ) { public void onProgressChanged ( SeekBar seekBar , int progress , boolean fromUser ) { currentSecurity = progress ; securityLabel . setText ( "Security Level: " + SEC_LEVELS [ progress ] ) ; } public void onStartTrackingTouch ( SeekBar seekBar ) { } public void onStopTrackingTouch ( SeekBar seekBar ) { } } ) ; cbShowPassword . setOnClickListener ( new OnClickListener ( ) { @ Override public void onClick ( View v ) { isEncrypted = cbShowPassword . isChecked ( ) ; if ( isEncrypted ) { passwordField . setEnabled ( true ) ; passLabel . setVisibility ( View . VISIBLE ) ; passwordField . setVisibility ( View . VISIBLE ) ; } else { passwordField . setEnabled ( false ) ; passLabel . setVisibility ( View . INVISIBLE ) ; passwordField . setVisibility ( View . INVISIBLE ) ; } } } ) ; cbShowPassword . setChecked ( ! isEncrypted ) ; cbShowPassword . performClick ( ) ; fileNameField . setText ( currentFileName ) ; fileNameField . setSelection ( fileNameField . getText ( ) . length ( ) ) ; passwordField . setText ( currentPassword ) ; seekBar . setProgress ( currentSecurity ) ; AlertDialog . Builder builder = new AlertDialog . Builder ( this ) ; builder . setTitle ( "Encode Text:" ) ; builder . setView ( alertLayout ) ; builder . setPositiveButton ( "OK" , new DialogInterface . OnClickListener ( ) { @ Override public void onClick ( DialogInterface dialog , int which ) { currentFileName = fileNameField . getText ( ) . toString ( ) . replace ( " " , "_" ) . trim ( ) ; String error = Util . isValidFileName ( currentFileName ) ; boolean isBelowCapacity = true ; currentPassword = null ; if ( cbShowPassword . isChecked ( ) && ! passwordField . getText ( ) . toString ( ) . isEmpty ( ) ) { currentPassword = passwordField . getText ( ) . toString ( ) ; isBelowCapacity = Crypto . isBelowCapacity ( editText . getText ( ) . toString ( ) , ( bitmap . getWidth ( ) * bitmap . getHeight ( ) ) ) ; } if ( error . equals ( "" ) && isBelowCapacity ) { new HideTextTask ( TextHideScreen . this ) . execute ( ) ; } else { if ( ! isBelowCapacity ) { error = "This data will exceed the image capacity if encrypted" ; } Toast . makeText ( getApplicationContext ( ) , error , Toast . LENGTH_LONG ) . show ( ) ; displaySaveDialog ( ) ; } } } ) ; builder . setNegativeButton ( "Cancel" , new DialogInterface . OnClickListener ( ) { @ Override public void onClick ( DialogInterface dialog , int which ) { currentFileName = fileNameField . getText ( ) . toString ( ) . replace ( " " , "_" ) . trim ( ) ; currentPassword = passwordField . getText ( ) . toString ( ) ; dialog . cancel ( ) ; return ; } } ) ; builder . setOnCancelListener ( new DialogInterface . OnCancelListener ( ) { @ Override public void onCancel ( DialogInterface dialog ) { currentFileName = fileNameField . getText ( ) . toString ( ) . replace ( " " , "_" ) . trim ( ) ; currentPassword = passwordField . getText ( ) . toString ( ) ; } } ) ; builder . show ( ) ; }
Displays and controls a dialog for saving with a password and a security
 level.
Displays and controls a dialog for saving with a password and a security level .
// Set up the buttons
