Advertisement
am_dot_com

DDM 20211102

Nov 2nd, 2021 (edited)
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.50 KB | None | 0 0
  1. package com.joythis.android.passwordgenerator;
  2.  
  3. import android.app.Activity;
  4. import android.view.Gravity;
  5. import android.widget.Toast;
  6.  
  7. import java.util.ArrayList;
  8. import java.util.Random;
  9.  
  10. public class AmUtil {
  11. private Activity mA;
  12.  
  13. public AmUtil(Activity pA){
  14. this.mA = pA;
  15. }//AmUtil
  16.  
  17. public void fb (String pStrMsg){
  18. Toast t = Toast.makeText(
  19. this.mA,
  20. pStrMsg,
  21. Toast.LENGTH_SHORT
  22. );
  23.  
  24. t.setGravity(Gravity.CENTER, 0, 0);
  25.  
  26. t.show();
  27. }//fb
  28.  
  29. //tools related to randomness
  30. public static int randomInt(int pMin, int pMax){
  31. Random r = new Random();
  32. int iAmplitude = pMax-pMin+1;
  33. int iJump = r.nextInt(iAmplitude);
  34. int iDestination = pMin + iJump;
  35. return iDestination;
  36. }//randomInt
  37.  
  38. public static char random_az(){
  39. int code_a = (int)'a';
  40. int code_z = (int)'z';
  41. int codeRandom = randomInt(code_a, code_z);
  42. char letterRandom = (char)codeRandom;
  43. return letterRandom;
  44. }//random_az
  45.  
  46. public static char random_AZ(){
  47. int code_A = (int)'A';
  48. int code_Z = (int)'Z';
  49. int codeRandom = randomInt(code_A, code_Z);
  50. char letterRandom = (char)codeRandom;
  51. return letterRandom;
  52. }//random_AZ
  53.  
  54. public static char random_09(){
  55. int code_0 = (int)'0';
  56. int code_9 = (int)'9';
  57. int codeRandom = randomInt(code_0, code_9);
  58. char letterRandom = (char)codeRandom;
  59. return letterRandom;
  60. }//random_09
  61.  
  62. public static char randomSymbol(char pS1, char pS2){
  63. int code_s1 = (int)pS1;
  64. int code_s2 = (int)pS2;
  65. int codeRandom = randomInt(code_s1, code_s2);
  66. char letterRandom = (char)codeRandom;
  67. return letterRandom;
  68. }//randomSymbol
  69.  
  70. public static char rAZ(){return randomSymbol('A', 'Z');}
  71. public static char raz(){return randomSymbol('a', 'z');}
  72. public static char r09(){return randomSymbol('0', '9');}
  73.  
  74. /*
  75. ["*", "?", ":"]
  76. */
  77. public static char randomSpecialSymbol(
  78. ArrayList<String> pAlAcceptableSpecialSymbols
  79. ){
  80. int iHowMany = pAlAcceptableSpecialSymbols.size();
  81. int iRandomAddress = randomInt(0, iHowMany-1);
  82. String strRandomSymbol =
  83. pAlAcceptableSpecialSymbols.get(iRandomAddress);
  84. return strRandomSymbol.charAt(0);
  85. }//randomSpecialSymbol
  86. }//AmUtil
  87.  
  88. ********************
  89.  
  90.  
  91. package com.joythis.android.passwordgenerator;
  92.  
  93. import androidx.appcompat.app.AppCompatActivity;
  94.  
  95. import android.content.Context;
  96. import android.os.Bundle;
  97. import android.view.View;
  98. import android.widget.ArrayAdapter;
  99. import android.widget.Button;
  100. import android.widget.CheckBox;
  101. import android.widget.EditText;
  102. import android.widget.ListView;
  103. import android.widget.SeekBar;
  104.  
  105. import java.util.ArrayList;
  106.  
  107. public class MainActivity extends AppCompatActivity {
  108. //data members
  109. CheckBox mCbAZ, mCbaz, mCbDigits;
  110. EditText mEtSS; //for the Special Symbols
  111. SeekBar mSbLength; //for the password length / size
  112. Button mBtnGenPass;
  113. ListView mLvPasswords;
  114. ArrayList<String> mAlPasswords;
  115. ArrayAdapter<String> mAd;
  116.  
  117. Context mContext;
  118.  
  119. View.OnClickListener mClickHandler = new View.OnClickListener() {
  120. @Override
  121. public void onClick(View v) {
  122.  
  123. }//onClick
  124. };//mClickHandler
  125.  
  126. @Override
  127. protected void onCreate(Bundle savedInstanceState) {
  128. super.onCreate(savedInstanceState);
  129. setContentView(R.layout.rl_pass_gen_v1);
  130.  
  131. init(savedInstanceState);
  132. }//onCreate
  133.  
  134. void init (Bundle pB){
  135. //bindings
  136. mContext = this;
  137. //mContext = MainActivity.this;
  138.  
  139. mCbaz = findViewById(R.id.idCbaz);
  140. mCbAZ = findViewById(R.id.idCbAZ);
  141. mCbDigits = findViewById(R.id.idCbDigits);
  142. mEtSS = findViewById(R.id.idEtSS);
  143. mSbLength = findViewById(R.id.idSbLength);
  144. mBtnGenPass = findViewById(R.id.idBtnGenPass);
  145. mLvPasswords = findViewById(R.id.idLvPasswords);
  146.  
  147. if (mLvPasswords!=null){
  148. //data source + adapter
  149. mAlPasswords = new ArrayList<>();
  150. mAd = new ArrayAdapter<>(
  151. mContext,
  152. android.R.layout.simple_list_item_1,
  153. mAlPasswords
  154. );
  155. mLvPasswords.setAdapter(mAd);
  156. }//if (ListView pattern)
  157.  
  158. //behaviors
  159. }//init
  160.  
  161.  
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement