Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.grawl.passgen;
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.content.DialogInterface;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.Toast;
- public class PassGenActivity extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- // Interface -- Default
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- // Interface -- Custom
- final Button button_generate = (Button) findViewById(R.id.button_generate);
- final EditText text_pass = (EditText) findViewById(R.id.textPassWord);
- final EditText edit_length = (EditText) findViewById(R.id.editLength);
- // Set up Arrays
- final String[] lowerCase;
- final String[] upperCase;
- final String[] numbers;
- final String[] symbols;
- // Fill Arrays
- createArray characters = new createArray();
- lowerCase = characters.getArrayLower();
- upperCase = characters.getArrayUpper();
- numbers = characters.getArrayNumbers();
- symbols = characters.getArraySymbols();
- // Pressing the button WOOOSH!
- button_generate.setOnClickListener(new View.OnClickListener() {
- // Set up parameters
- boolean lowerCaseEnabled = true; // needs interface option
- boolean upperCaseEnabled = true; // needs interface option
- boolean numbersEnabled = true; // needs interface option
- boolean symbolsEnabled = true; // needs interface option
- int length;
- public void onClick(View v) {
- // Set up length based on input from EditText
- length = 0;
- try {
- length = Integer.parseInt(edit_length.getText().toString());
- } catch(NumberFormatException nfe) {
- Toast.makeText(PassGenActivity.this, "Can't parse " + nfe, Toast.LENGTH_LONG).show();
- }
- // If password is 0 (or negative), set length to 1
- if (length < 1) {
- length = 1;
- edit_length.setText("1");
- Toast.makeText(PassGenActivity.this, "Password length can't be less than 1, set it to 1.", Toast.LENGTH_LONG).show();
- };
- // Problem: Need a way to call the "generate password" feature
- if (length < 100) {
- Password password = new Password();
- password.fillPassword(lowerCase, upperCase, numbers, symbols);
- // Generate password
- password.setPassword(lowerCaseEnabled, upperCaseEnabled, numbersEnabled, symbolsEnabled, length);
- text_pass.setText(password.getPassword());
- }
- // Create a dialog to confirm user wants to create big password. Currently not working.
- // Problem: Password is generated only after the dialog has been agreed upon once. <-- FIXED
- // Problem: Need a way to call the "generate password" feature
- if (length > 99) {
- AlertDialog.Builder alert = new AlertDialog.Builder(PassGenActivity.this);
- alert.setTitle("Warning");
- alert.setMessage("You are trying to create quite a long password, are you sure?");
- alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- // Toast.makeText(PassGenActivity.this, "ignoreLength is now: " + ignoreLength, Toast.LENGTH_LONG).show();
- Password password = new Password();
- password.fillPassword(lowerCase, upperCase, numbers, symbols);
- // Generate password
- password.setPassword(lowerCaseEnabled, upperCaseEnabled, numbersEnabled, symbolsEnabled, length);
- text_pass.setText(password.getPassword());
- }
- });
- alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- // Toast.makeText(PassGenActivity.this, "ignoreLength is now: " + ignoreLength, Toast.LENGTH_LONG).show();
- }
- });
- alert.show();
- }
- }
- });
- }
- }
Add Comment
Please, Sign In to add comment