Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PasswordKeeperActivity extends Activity implements AdapterView.OnItemSelectedListener {
- // initialise
- EditText username, password, note;
- Button save, reset;
- public String savedata = "";
- String[] countryNames={"Google", "Yahoo", "Facebook", "Twitter", "Instagram", "BBM", "Skype", "Other"};
- 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};
- // for inflating the menu
- public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.menu, menu);
- return true;
- }
- // on selection of the menu
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle item selection
- switch (item.getItemId()) {
- case R.id.view_passwords:
- Intent intent = new Intent(this, PasswordView.class);
- startActivity(intent);
- return true;
- default:
- return super.onOptionsItemSelected(item);
- }
- }
- public void onItemSelected(AdapterView<?> parent, View view,
- int pos, long id) {
- // An item was selected. You can retrieve the selected item using
- // parent.getItemAtPosition(pos)
- }
- public void onNothingSelected(AdapterView<?> parent) {
- // Another interface callback
- }
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_home);
- initialise();
- //Getting the instance of Spinner and applying OnItemSelectedListener on it
- Spinner spin = (Spinner) findViewById(R.id.planets_spinner);
- spin.setOnItemSelectedListener(this);
- CustomAdapter customAdapter = new CustomAdapter(getApplicationContext(), flags, countryNames);
- spin.setAdapter(customAdapter);
- //to set the site Edit Text to get the focus
- // save the data to the textfile
- save.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- // creates hidden directory if not existing
- File dir = new File(Environment
- .getExternalStorageDirectory().getAbsolutePath()
- + "/.sk/");
- if (!dir.exists()) {
- dir.mkdirs();
- }
- // saving data part
- String sFileName = Environment.getExternalStorageDirectory()
- .getAbsolutePath() + "/.sk/" + "logp.csv";
- try {
- FileWriter writer = new FileWriter(sFileName, true);
- String countryNames, sUser, sPass, sAdd;
- sUser = username.getText().toString();
- sPass = password.getText().toString();
- sAdd = note.getText().toString();
- if ((sUser.equals("")) && (sPass.equals("")) && (sAdd.equals(""))) {
- Toast.makeText(getBaseContext(), "Please Enter At least one Field",
- Toast.LENGTH_SHORT).show();
- } else {
- if (sUser.equals(""))
- sUser = "null";
- if (sPass.equals(""))
- sPass = "null";
- if (sAdd.equals(""))
- sAdd = "null";
- // encrypting the passwords before saving
- SimpleCrypto mcrypt = new SimpleCrypto();
- sPass = SimpleCrypto.bytesToHex( mcrypt.encrypt(sPass) );
- //sPass = SimpleCrypto.encrypt("fugly", sPass);
- writer.append(sUser);
- writer.append(',');
- writer.append(sPass);
- writer.append(',');
- writer.append(sAdd);
- writer.append('\n');
- // generate whatever data you want
- writer.flush();
- writer.close();
- Toast.makeText(getBaseContext(), "Password Saved!",
- Toast.LENGTH_SHORT).show();
- Intent intent = new Intent(PasswordKeeperActivity.this, PasswordView.class);
- String[] myStrings = new String[] {"Google", "Yahoo", "Facebook", "Twitter", "Instagram", "BBM", "Skype", "Other"};
- 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};
- intent.putExtra("strings", myStrings);
- intent.putExtra("logos", logo);
- startActivity(intent);
- }
- } catch (Exception e) {
- Toast.makeText(getBaseContext(), e.getMessage(),
- Toast.LENGTH_SHORT).show();
- }
- }
- });
- // Reset
- reset.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- countryNames.equals("Google");
- note.setText("");
- username.setText("");
- password.setText("");
- Toast.makeText(getBaseContext(), "Field(s) Cleared!",
- Toast.LENGTH_SHORT).show();
- }
- });
- }
- public void initialise() {
- username = (EditText) findViewById(R.id.input_name);
- password = (EditText) findViewById(R.id.input_email);
- note = (EditText) findViewById(R.id.input_password);
- save = (Button) findViewById(R.id.buttonSave);
- reset = (Button) findViewById(R.id.ButtonReset);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement