MarouaneTheViper

Untitled

Sep 7th, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. package com.example.saferou;
  2.  
  3. import androidx.appcompat.app.ActionBar;
  4. import androidx.appcompat.app.AppCompatActivity;
  5.  
  6. import androidx.fragment.app.Fragment;
  7. import androidx.fragment.app.FragmentTransaction;
  8.  
  9. import android.os.Bundle;
  10. import android.view.View;
  11. import android.widget.Button;
  12. import android.widget.EditText;
  13. import android.widget.RadioButton;
  14. import android.widget.RadioGroup;
  15.  
  16. import java.util.ArrayList;
  17. import java.util.Arrays;
  18. import java.util.Collections;
  19. import java.util.List;
  20. import java.util.Random;
  21.  
  22. import static androidx.appcompat.app.ActionBar.*;
  23.  
  24. public class MainActivity extends AppCompatActivity {
  25.  
  26. private ActionBar actionbar;
  27. private Tab tabOne;
  28. private Tab tabTwo;
  29. private Fragment register = new RegisterFragment();
  30. private Fragment browse = new BrowseFragment();
  31. private Button saveButton, randButton;
  32. private EditText editTitle,editUser,editPass;
  33. private RadioGroup radioGroup;
  34. private RadioButton radioButton;
  35.  
  36.  
  37. private void link()
  38. {
  39. saveButton = findViewById(R.id.buttonSave);
  40. randButton = findViewById(R.id.buttonRand);
  41. editTitle = findViewById(R.id.acc_title);
  42. editUser = findViewById(R.id.acc_username);
  43. editPass = findViewById(R.id.password);
  44. radioGroup = findViewById(R.id.rGroup);
  45. }
  46.  
  47. @Override
  48. protected void onCreate(Bundle savedInstanceState) {
  49. super.onCreate(savedInstanceState);
  50. setContentView(R.layout.activity_main);
  51. link();
  52.  
  53. actionbar = getSupportActionBar();
  54. actionbar.show();
  55. actionbar.setNavigationMode(NAVIGATION_MODE_TABS);
  56.  
  57. tabOne = actionbar.newTab().setText(R.string.new_account);
  58. tabTwo = actionbar.newTab().setText(R.string.browse);
  59.  
  60. tabOne.setTabListener(new TabAction(register));
  61. tabTwo.setTabListener(new TabAction(browse));
  62.  
  63. actionbar.addTab(tabOne);
  64. actionbar.addTab(tabTwo);
  65.  
  66. saveButtonHandler();
  67. randomButtonHandler();
  68.  
  69. }
  70.  
  71. private void saveButtonHandler()
  72. {
  73. saveButton.setOnClickListener(new View.OnClickListener() {
  74. @Override
  75. public void onClick(View view) {
  76.  
  77. }
  78. });
  79. }
  80.  
  81. private void randomButtonHandler()
  82. {
  83. randButton.setOnClickListener(new View.OnClickListener() {
  84. @Override
  85. public void onClick(View view) {
  86.  
  87. }
  88. });
  89. }
  90.  
  91. private String randomPassword()
  92. {
  93. Character[] characters = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
  94. 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
  95. '!','@','#','$','%','^','&','*','(',')','_','+','1','2','3','4','5','6','7','8','9','0'};
  96.  
  97. List<Character> characterList = new ArrayList<>(Arrays.asList(characters));
  98. Collections.shuffle(characterList);
  99. Random rand = new Random();
  100. String result ="";
  101. for(int i = 0;i<9;i++)
  102. {
  103. int count = rand.nextInt(characterList.size());
  104. result = result + characterList.get(count).toString();
  105. }
  106.  
  107. return result;
  108. }
  109.  
  110. class TabAction implements ActionBar.TabListener {
  111.  
  112. Fragment f;
  113.  
  114. public TabAction(Fragment f) {
  115. this.f = f;
  116. }
  117.  
  118. @Override
  119. public void onTabSelected(Tab tab, FragmentTransaction ft) {
  120. ft.replace(R.id.frame, f);
  121. }
  122.  
  123. @Override
  124. public void onTabUnselected(Tab tab, FragmentTransaction ft) {
  125. ft.remove(f);
  126. }
  127.  
  128. @Override
  129. public void onTabReselected(Tab tab, FragmentTransaction ft) {
  130.  
  131. }
  132. }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment