Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.joythis.android.passwordgenerator;
- import android.app.Activity;
- import android.view.Gravity;
- import android.widget.Toast;
- import java.util.ArrayList;
- import java.util.Random;
- public class AmUtil {
- private Activity mA;
- public AmUtil(Activity pA){
- this.mA = pA;
- }//AmUtil
- public void fb (String pStrMsg){
- Toast t = Toast.makeText(
- this.mA,
- pStrMsg,
- Toast.LENGTH_SHORT
- );
- t.setGravity(Gravity.CENTER, 0, 0);
- t.show();
- }//fb
- //tools related to randomness
- public static int randomInt(int pMin, int pMax){
- Random r = new Random();
- int iAmplitude = pMax-pMin+1;
- int iJump = r.nextInt(iAmplitude);
- int iDestination = pMin + iJump;
- return iDestination;
- }//randomInt
- public static char random_az(){
- int code_a = (int)'a';
- int code_z = (int)'z';
- int codeRandom = randomInt(code_a, code_z);
- char letterRandom = (char)codeRandom;
- return letterRandom;
- }//random_az
- public static char random_AZ(){
- int code_A = (int)'A';
- int code_Z = (int)'Z';
- int codeRandom = randomInt(code_A, code_Z);
- char letterRandom = (char)codeRandom;
- return letterRandom;
- }//random_AZ
- public static char random_09(){
- int code_0 = (int)'0';
- int code_9 = (int)'9';
- int codeRandom = randomInt(code_0, code_9);
- char letterRandom = (char)codeRandom;
- return letterRandom;
- }//random_09
- public static char randomSymbol(char pS1, char pS2){
- int code_s1 = (int)pS1;
- int code_s2 = (int)pS2;
- int codeRandom = randomInt(code_s1, code_s2);
- char letterRandom = (char)codeRandom;
- return letterRandom;
- }//randomSymbol
- public static char rAZ(){return randomSymbol('A', 'Z');}
- public static char raz(){return randomSymbol('a', 'z');}
- public static char r09(){return randomSymbol('0', '9');}
- /*
- ["*", "?", ":"]
- */
- public static char randomSpecialSymbol(
- ArrayList<String> pAlAcceptableSpecialSymbols
- ){
- int iHowMany = pAlAcceptableSpecialSymbols.size();
- int iRandomAddress = randomInt(0, iHowMany-1);
- String strRandomSymbol =
- pAlAcceptableSpecialSymbols.get(iRandomAddress);
- return strRandomSymbol.charAt(0);
- }//randomSpecialSymbol
- }//AmUtil
- ********************
- package com.joythis.android.passwordgenerator;
- import androidx.appcompat.app.AppCompatActivity;
- import android.content.Context;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.ArrayAdapter;
- import android.widget.Button;
- import android.widget.CheckBox;
- import android.widget.EditText;
- import android.widget.ListView;
- import android.widget.SeekBar;
- import java.util.ArrayList;
- public class MainActivity extends AppCompatActivity {
- //data members
- CheckBox mCbAZ, mCbaz, mCbDigits;
- EditText mEtSS; //for the Special Symbols
- SeekBar mSbLength; //for the password length / size
- Button mBtnGenPass;
- ListView mLvPasswords;
- ArrayList<String> mAlPasswords;
- ArrayAdapter<String> mAd;
- Context mContext;
- View.OnClickListener mClickHandler = new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- }//onClick
- };//mClickHandler
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.rl_pass_gen_v1);
- init(savedInstanceState);
- }//onCreate
- void init (Bundle pB){
- //bindings
- mContext = this;
- //mContext = MainActivity.this;
- mCbaz = findViewById(R.id.idCbaz);
- mCbAZ = findViewById(R.id.idCbAZ);
- mCbDigits = findViewById(R.id.idCbDigits);
- mEtSS = findViewById(R.id.idEtSS);
- mSbLength = findViewById(R.id.idSbLength);
- mBtnGenPass = findViewById(R.id.idBtnGenPass);
- mLvPasswords = findViewById(R.id.idLvPasswords);
- if (mLvPasswords!=null){
- //data source + adapter
- mAlPasswords = new ArrayList<>();
- mAd = new ArrayAdapter<>(
- mContext,
- android.R.layout.simple_list_item_1,
- mAlPasswords
- );
- mLvPasswords.setAdapter(mAd);
- }//if (ListView pattern)
- //behaviors
- }//init
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement