Advertisement
Guest User

Untitled

a guest
Aug 15th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.82 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 = Environment.getExternalStorageDirectory().toString();
  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. private static final int REQUEST_EXTERNAL_STORAGE = 1;
  12. private static String[] PERMISSIONS_STORAGE = {
  13. Manifest.permission.READ_EXTERNAL_STORAGE,
  14. Manifest.permission.WRITE_EXTERNAL_STORAGE
  15. };
  16. // for inflating the menu
  17. public boolean onCreateOptionsMenu(Menu menu) {
  18. MenuInflater inflater = getMenuInflater();
  19. inflater.inflate(R.menu.menu, menu);
  20. return true;
  21. }
  22.  
  23. // on selection of the menu
  24. @Override
  25. public boolean onOptionsItemSelected(MenuItem item) {
  26. // Handle item selection
  27. switch (item.getItemId()) {
  28. case R.id.view_passwords:
  29. Intent intent = new Intent(this, PasswordView.class);
  30. startActivity(intent);
  31. return true;
  32.  
  33. default:
  34. return super.onOptionsItemSelected(item);
  35. }
  36. }
  37.  
  38. public void onItemSelected(AdapterView<?> parent, View view,
  39. int pos, long id) {
  40. // An item was selected. You can retrieve the selected item using
  41. // parent.getItemAtPosition(pos)
  42.  
  43. }
  44.  
  45. public void onNothingSelected(AdapterView<?> parent) {
  46. // Another interface callback
  47. }
  48.  
  49. public void onCreate(Bundle savedInstanceState) {
  50. super.onCreate(savedInstanceState);
  51. setContentView(R.layout.activity_home);
  52.  
  53. initialise();
  54.  
  55. //Getting the instance of Spinner and applying OnItemSelectedListener on
  56. it
  57. Spinner spin = (Spinner) findViewById(R.id.planets_spinner);
  58. spin.setOnItemSelectedListener(this);
  59.  
  60. CustomAdapter customAdapter = new CustomAdapter(getApplicationContext(),
  61. flags, countryNames);
  62. spin.setAdapter(customAdapter);
  63.  
  64. //to set the site Edit Text to get the focus
  65.  
  66.  
  67.  
  68.  
  69. // save the data to the textfile
  70. save.setOnClickListener(new OnClickListener() {
  71. public void onClick(View v) {
  72.  
  73. // creates hidden directory if not existing
  74. File dir = new File(getCacheDir(), "/sk/");
  75. if (!dir.exists()) {
  76. dir.mkdirs();
  77. }
  78.  
  79. // saving data part
  80. String sFileName = getCacheDir() + "/sk/logp.csv";
  81. try {
  82. FileWriter writer = new FileWriter(sFileName, true);
  83.  
  84. String countryNames, sUser, sPass, sAdd;
  85.  
  86. countryNames =
  87. sUser = username.getText().toString();
  88. sPass = password.getText().toString();
  89. sAdd = note.getText().toString();
  90.  
  91.  
  92.  
  93. if ((sUser.equals("")) && (sPass.equals("")) &&
  94. (sAdd.equals(""))) {
  95. Toast.makeText(getBaseContext(), "Please Enter At least
  96. one Field",
  97. Toast.LENGTH_SHORT).show();
  98.  
  99. } else {
  100. if (sUser.equals(""))
  101. sUser = "null";
  102. if (sPass.equals(""))
  103. sPass = "null";
  104. if (sAdd.equals(""))
  105. sAdd = "null";
  106.  
  107.  
  108. // encrypting the passwords before saving
  109. SimpleCrypto mcrypt = new SimpleCrypto();
  110. sPass = SimpleCrypto.bytesToHex( mcrypt.encrypt(sPass) );
  111. //sPass = SimpleCrypto.encrypt("fugly", sPass);
  112.  
  113.  
  114.  
  115.  
  116. writer.append(sUser);
  117. writer.append(',');
  118.  
  119. writer.append(sPass);
  120. writer.append(',');
  121. writer.append(sAdd);
  122.  
  123. writer.append('n');
  124.  
  125. // generate whatever data you want
  126.  
  127. writer.flush();
  128. writer.close();
  129.  
  130. Toast.makeText(getBaseContext(), "Password Saved!",
  131. Toast.LENGTH_SHORT).show();
  132.  
  133. Intent intent = new Intent(PasswordKeeperActivity.this,
  134. PasswordView.class);
  135. String[] myStrings = new String[] {"Google", "Yahoo",
  136. "Facebook", "Twitter", "Instagram", "BBM", "Skype", "Other"};
  137. int logo[] = new int[] {R.drawable.google,
  138. R.drawable.yahoo, R.drawable.facebook, R.drawable.twitter,
  139. R.drawable.instagram,
  140. R.drawable.bbm, R.drawable.skype, R.drawable.other};
  141. intent.putExtra("strings", myStrings);
  142. intent.putExtra("logos", logo);
  143. startActivity(intent);
  144. }
  145.  
  146. } catch (Exception e) {
  147. Toast.makeText(getBaseContext(), e.getMessage(),
  148. Toast.LENGTH_SHORT).show();
  149. }
  150.  
  151. }
  152. });
  153.  
  154. // Reset
  155. reset.setOnClickListener(new OnClickListener() {
  156. public void onClick(View v) {
  157.  
  158. countryNames.equals("Google");
  159. note.setText("");
  160. username.setText("");
  161. password.setText("");
  162. Toast.makeText(getBaseContext(), "Field(s) Cleared!",
  163. Toast.LENGTH_SHORT).show();
  164. }
  165. });
  166.  
  167. }
  168.  
  169.  
  170.  
  171. public void initialise() {
  172.  
  173.  
  174. username = (EditText) findViewById(R.id.input_name);
  175. password = (EditText) findViewById(R.id.input_email);
  176. note = (EditText) findViewById(R.id.input_password);
  177.  
  178. save = (Button) findViewById(R.id.buttonSave);
  179. reset = (Button) findViewById(R.id.ButtonReset);
  180. }
  181.  
  182. /**
  183. * Checks if the app has permission to write to device storage
  184. *
  185. * If the app does not has permission then the user will be prompted to
  186. grant permissions
  187. *
  188. * @param activity
  189. */
  190. public static void verifyStoragePermissions(Activity activity) {
  191. // Check if we have write permission
  192. int permission = ActivityCompat.checkSelfPermission(activity,
  193. Manifest.permission.WRITE_EXTERNAL_STORAGE);
  194.  
  195. if (permission != PackageManager.PERMISSION_GRANTED) {
  196. // We don't have permission so prompt the user
  197. ActivityCompat.requestPermissions(
  198. activity,
  199. PERMISSIONS_STORAGE,
  200. REQUEST_EXTERNAL_STORAGE
  201. );
  202. }
  203. }
  204. }
  205.  
  206. 08-15 10:02:44.353 5961-5961/com.com.dreacot.dreacot.fingerprint E/AndroidRuntime: FATAL EXCEPTION: main
  207. Process: com.com.dreacot.dreacot.fingerprint, PID: 5961
  208. java.lang.NullPointerException: Attempt to read from null array
  209. at com.dreacot.fortpasswordkeeper.CustomListAdapter.getView(CustomListAdapter.java:35)
  210. at android.widget.AbsListView.obtainView(AbsListView.java:2929)
  211. at android.widget.ListView.measureHeightOfChildren(ListView.java:1305)
  212. at android.widget.ListView.onMeasure(ListView.java:1212)
  213. at android.view.View.measure(View.java:20151)
  214. at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:716)
  215. at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:462)
  216. at android.view.View.measure(View.java:20151)
  217. at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6330)
  218. at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:714)
  219. at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:90)
  220. at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1391)
  221. at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:784)
  222. at android.view.View.measure(View.java:20151)
  223. at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6330)
  224. at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
  225. at android.view.View.measure(View.java:20151)
  226. at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6330)
  227. at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
  228. at android.widget.LinearLayout.measureVertical(LinearLayout.java:747)
  229. at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)
  230. at android.view.View.measure(View.java:20151)
  231. at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6330)
  232. at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
  233. at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:3158)
  234. at android.view.View.measure(View.java:20151)
  235. at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2594)
  236. at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1549)
  237. at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1841)
  238. at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1437)
  239. at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7397)
  240. at android.view.Choreographer$CallbackRecord.run(Choreographer.java:920)
  241. at android.view.Choreographer.doCallbacks(Choreographer.java:695)
  242. at android.view.Choreographer.doFrame(Choreographer.java:631)
  243. at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:906)
  244. at android.os.Handler.handleCallback(Handler.java:739)
  245. at android.os.Handler.dispatchMessage(Handler.java:95)
  246. at android.os.Looper.loop(Looper.java:158)
  247. at android.app.ActivityThread.main(ActivityThread.java:7224)
  248. at java.lang.reflect.Method.invoke(Native Method)
  249. at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
  250. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
  251.  
  252. public class CustomListAdapter extends ArrayAdapter<String> {
  253.  
  254. private final Activity context;
  255. private final String[] countryNames;
  256. private final int flags[];
  257.  
  258. public CustomListAdapter(Activity context, String[] countryNames, int flags[]) {
  259. super(context, R.layout.mylist, countryNames);
  260. // TODO Auto-generated constructor stub
  261.  
  262. this.context=context;
  263. this.countryNames=countryNames;
  264. this.flags=flags;
  265. }
  266.  
  267. public View getView(int position,View view,ViewGroup parent) {
  268. LayoutInflater inflater=context.getLayoutInflater();
  269. View rowView=inflater.inflate(R.layout.mylist, null,true);
  270.  
  271. TextView txtTitle = (TextView) rowView.findViewById(R.id.item);
  272. ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
  273. TextView extratxt = (TextView) rowView.findViewById(R.id.textView1);
  274.  
  275. txtTitle.setText(countryNames[position]);
  276. imageView.setImageResource(flags[position]);
  277. extratxt.setText("Description "+countryNames[position]);
  278. return rowView;
  279.  
  280. }
  281. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement