Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. public class PasswordKeeperActivity extends Activity implements AdapterView.OnItemSelectedListener {
  2.  
  3. // initialise
  4. EditText username, password, note;
  5. Button save, reset;
  6. public String savedata = "";
  7.  
  8. String[] countryNames={"Google", "Yahoo", "Facebook", "Twitter", "Instagram", "BBM", "Skype", "Other"};
  9. int flags[] = {R.drawable.google, R.drawable.yahoo, R.drawable.facebook, R.drawable.twitter, R.drawable.instagram, R.drawable.bbm, R.drawable.skype, R.drawable.other};
  10.  
  11.  
  12. // for inflating the menu
  13. public boolean onCreateOptionsMenu(Menu menu) {
  14. MenuInflater inflater = getMenuInflater();
  15. inflater.inflate(R.menu.menu, menu);
  16. return true;
  17. }
  18.  
  19. // on selection of the menu
  20. @Override
  21. public boolean onOptionsItemSelected(MenuItem item) {
  22. // Handle item selection
  23. switch (item.getItemId()) {
  24. case R.id.view_passwords:
  25. Intent intent = new Intent(this, PasswordView.class);
  26. startActivity(intent);
  27. return true;
  28.  
  29. default:
  30. return super.onOptionsItemSelected(item);
  31. }
  32. }
  33.  
  34. public void onItemSelected(AdapterView<?> parent, View view,
  35. int pos, long id) {
  36. // An item was selected. You can retrieve the selected item using
  37. // parent.getItemAtPosition(pos)
  38.  
  39. }
  40.  
  41. public void onNothingSelected(AdapterView<?> parent) {
  42. // Another interface callback
  43. }
  44.  
  45. public void onCreate(Bundle savedInstanceState) {
  46. super.onCreate(savedInstanceState);
  47. setContentView(R.layout.activity_home);
  48.  
  49. initialise();
  50.  
  51. //Getting the instance of Spinner and applying OnItemSelectedListener on it
  52. Spinner spin = (Spinner) findViewById(R.id.planets_spinner);
  53. spin.setOnItemSelectedListener(this);
  54.  
  55. CustomAdapter customAdapter = new CustomAdapter(getApplicationContext(), flags, countryNames);
  56. spin.setAdapter(customAdapter);
  57.  
  58. //to set the site Edit Text to get the focus
  59.  
  60.  
  61.  
  62.  
  63. // save the data to the textfile
  64. save.setOnClickListener(new OnClickListener() {
  65. public void onClick(View v) {
  66.  
  67. // creates hidden directory if not existing
  68. File dir = new File(Environment
  69. .getExternalStorageDirectory().getAbsolutePath()
  70. + "/.sk/");
  71. if (!dir.exists()) {
  72. dir.mkdirs();
  73. }
  74.  
  75. // saving data part
  76. String sFileName = Environment.getExternalStorageDirectory()
  77. .getAbsolutePath() + "/.sk/" + "logp.csv";
  78. try {
  79. FileWriter writer = new FileWriter(sFileName, true);
  80.  
  81. String countryNames, sUser, sPass, sAdd;
  82.  
  83.  
  84. sUser = username.getText().toString();
  85. sPass = password.getText().toString();
  86. sAdd = note.getText().toString();
  87.  
  88.  
  89.  
  90. if ((sUser.equals("")) && (sPass.equals("")) && (sAdd.equals(""))) {
  91. Toast.makeText(getBaseContext(), "Please Enter At least one Field",
  92. Toast.LENGTH_SHORT).show();
  93.  
  94. } else {
  95. if (sUser.equals(""))
  96. sUser = "null";
  97. if (sPass.equals(""))
  98. sPass = "null";
  99. if (sAdd.equals(""))
  100. sAdd = "null";
  101.  
  102.  
  103. // encrypting the passwords before saving
  104. SimpleCrypto mcrypt = new SimpleCrypto();
  105. sPass = SimpleCrypto.bytesToHex( mcrypt.encrypt(sPass) );
  106. //sPass = SimpleCrypto.encrypt("fugly", sPass);
  107.  
  108.  
  109.  
  110.  
  111. writer.append(sUser);
  112. writer.append(',');
  113.  
  114. writer.append(sPass);
  115. writer.append(',');
  116. writer.append(sAdd);
  117.  
  118. writer.append('\n');
  119.  
  120. // generate whatever data you want
  121.  
  122. writer.flush();
  123. writer.close();
  124.  
  125. Toast.makeText(getBaseContext(), "Password Saved!",
  126. Toast.LENGTH_SHORT).show();
  127.  
  128. Intent intent = new Intent(PasswordKeeperActivity.this, PasswordView.class);
  129. String[] myStrings = new String[] {"Google", "Yahoo", "Facebook", "Twitter", "Instagram", "BBM", "Skype", "Other"};
  130. int logo[] = new int[] {R.drawable.google, R.drawable.yahoo, R.drawable.facebook, R.drawable.twitter, R.drawable.instagram, R.drawable.bbm, R.drawable.skype, R.drawable.other};
  131. intent.putExtra("strings", myStrings);
  132. intent.putExtra("logos", logo);
  133. startActivity(intent);
  134. }
  135.  
  136. } catch (Exception e) {
  137. Toast.makeText(getBaseContext(), e.getMessage(),
  138. Toast.LENGTH_SHORT).show();
  139. }
  140.  
  141. }
  142. });
  143.  
  144. // Reset
  145. reset.setOnClickListener(new OnClickListener() {
  146. public void onClick(View v) {
  147.  
  148. countryNames.equals("Google");
  149. note.setText("");
  150. username.setText("");
  151. password.setText("");
  152. Toast.makeText(getBaseContext(), "Field(s) Cleared!",
  153. Toast.LENGTH_SHORT).show();
  154. }
  155. });
  156.  
  157. }
  158.  
  159.  
  160.  
  161. public void initialise() {
  162.  
  163.  
  164. username = (EditText) findViewById(R.id.input_name);
  165. password = (EditText) findViewById(R.id.input_email);
  166. note = (EditText) findViewById(R.id.input_password);
  167.  
  168. save = (Button) findViewById(R.id.buttonSave);
  169. reset = (Button) findViewById(R.id.ButtonReset);
  170. }
  171.  
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement