Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:tools="http://schemas.android.com/tools"
  4. android:id="@+id/activity_main"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. android:paddingBottom="@dimen/activity_vertical_margin"
  8. android:paddingLeft="@dimen/activity_horizontal_margin"
  9. android:paddingRight="@dimen/activity_horizontal_margin"
  10. android:paddingTop="@dimen/activity_vertical_margin"
  11. tools:context="ru.hashmap.myapplol.MainActivity">
  12.  
  13. <EditText
  14. android:layout_width="wrap_content"
  15. android:layout_height="wrap_content"
  16. android:inputType="textPersonName"
  17. android:text="Your password should be here"
  18. android:ems="10"
  19. android:layout_alignParentTop="true"
  20. android:layout_alignParentLeft="true"
  21. android:layout_alignParentStart="true"
  22. android:layout_marginTop="16dp"
  23. android:id="@+id/editText"
  24. android:layout_alignParentRight="true"
  25. android:layout_alignParentEnd="true"
  26. android:singleLine="true" />
  27.  
  28. <ProgressBar
  29. style="?android:attr/progressBarStyleHorizontal"
  30. android:layout_width="wrap_content"
  31. android:layout_height="wrap_content"
  32. android:layout_below="@+id/editText"
  33. android:layout_alignParentLeft="true"
  34. android:layout_alignParentStart="true"
  35. android:id="@+id/progressBar"
  36. android:layout_alignParentRight="true"
  37. android:layout_alignParentEnd="true"
  38. android:indeterminate="true" />
  39.  
  40. <Button
  41. android:text="generate!"
  42. android:layout_width="wrap_content"
  43. android:layout_height="wrap_content"
  44. android:layout_marginTop="62dp"
  45. android:id="@+id/button"
  46. android:layout_below="@+id/progressBar"
  47. android:layout_alignParentLeft="true"
  48. android:layout_alignParentStart="true"
  49. android:layout_alignParentRight="true"
  50. android:layout_alignParentEnd="true"
  51. android:onClick="genPass"/>
  52.  
  53. <SeekBar
  54. style="@style/Widget.AppCompat.SeekBar.Discrete"
  55. android:layout_width="wrap_content"
  56. android:layout_height="wrap_content"
  57. android:max="15"
  58. android:progress="6"
  59. android:layout_marginTop="27dp"
  60. android:id="@+id/seekBar"
  61. android:layout_below="@+id/progressBar"
  62. android:layout_alignParentLeft="true"
  63. android:layout_alignParentStart="true"
  64. android:layout_alignParentRight="true"
  65. android:layout_alignParentEnd="true" />
  66. </RelativeLayout>
  67.  
  68. package ru.hashmap.myapplol;
  69.  
  70. import android.support.v7.app.AppCompatActivity;
  71. import android.os.Bundle;
  72. import android.util.Log;
  73. import android.view.View;
  74. import android.widget.SeekBar;
  75. import android.widget.TextView;
  76.  
  77. import java.util.Random;
  78.  
  79. public class MainActivity extends AppCompatActivity {
  80.  
  81. protected void onCreate(Bundle savedInstanceState) {
  82. super.onCreate(savedInstanceState);
  83. setContentView(R.layout.activity_main);
  84. }
  85. public void genPass(View view)
  86. {
  87. SeekBar seek = (SeekBar) findViewById(R.id.seekBar);
  88. int seekValue = seek.getProgress()+1;
  89. Log.d("seekValue", seekValue+"");
  90. String[] dict = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
  91. String[] pass = new String[seekValue];
  92. Random rnd = new Random();
  93. for(int i = 0; i < seekValue; i++) {
  94. pass[i] = dict[rnd.nextInt(dict.toString().length())];
  95. }
  96. ((TextView) findViewById(R.id.editText)).setText(pass.toString());
  97. Log.d("pass", pass+"");
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement