Advertisement
Guest User

Untitled

a guest
Aug 19th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. package com.amritayalur.mypowerschool;
  2.  
  3.  
  4.  
  5. import android.app.Activity;
  6. import android.content.Intent;
  7. import android.content.SharedPreferences;
  8. import android.content.SharedPreferences.Editor;
  9. import android.os.Bundle;
  10. import android.preference.PreferenceActivity;
  11. import android.preference.PreferenceManager;
  12. import android.view.View;
  13. import android.widget.Button;
  14. import android.widget.EditText;
  15. import android.widget.TextView;
  16.  
  17.  
  18.  
  19. public class MyPowerSchoolActivity extends Activity {
  20. Button buttonSubmit;
  21. TextView textViewTitle;
  22. TextView textViewDesc;
  23. EditText editTextURL, editTextUser, editTextPass;
  24.  
  25.  
  26. String str;
  27. String username;
  28. String password;
  29. String url;
  30.  
  31. /** Called when the activity is first created. */
  32. @Override
  33. public void onCreate(Bundle savedInstanceState) {
  34. super.onCreate(savedInstanceState);
  35. setContentView(R.layout.main);
  36.  
  37.  
  38. buttonSubmit = (Button) findViewById(R.id.buttonSubmit);
  39. textViewTitle = (TextView) findViewById(R.id.textViewTitle);
  40. textViewDesc = (TextView) findViewById(R.id.textViewDesc);
  41.  
  42. editTextURL = (EditText) findViewById(R.id.editTextURL);
  43. editTextUser = (EditText) findViewById(R.id.editTextUser);
  44. editTextPass = (EditText) findViewById(R.id.editTextPass);
  45. //Start TextView
  46. textViewTitle.setText("MyPowerSchool");
  47.  
  48.  
  49. //button listener
  50. buttonSubmit.setOnClickListener(new View.OnClickListener() {
  51.  
  52. @Override
  53. public void onClick(View v)
  54. {
  55. if ( ( !editTextURL.getText().toString().equals("")) && (
  56. !editTextUser.getText().toString().equals("")) && (
  57. !editTextPass.getText().toString().equals("") ) )
  58. {
  59.  
  60. url = editTextURL.getText().toString();
  61. username = editTextUser.getText().toString();
  62. password = editTextPass.getText().toString();
  63.  
  64.  
  65. // TODO Auto-generated method stub
  66. //Intent i = new Intent( MyPowerSchoolActivity.this,
  67. creds.class);
  68.  
  69.  
  70. //startActivity(i);
  71.  
  72.  
  73.  
  74. }
  75. };
  76.  
  77.  
  78.  
  79.  
  80. });}}
  81.  
  82. public static String MY_PREFS = "MY_PREFS";
  83. private SharedPreferences mySharedPreferences;
  84. int prefMode = Activity.MODE_PRIVATE;
  85.  
  86. SharedPreferences.Editor editor = mySharedPreferences.edit();
  87. editor.putString("key1", "value1");
  88. editor.putString("key2", "value2");
  89. editor.putString("key3", "value3");
  90.  
  91. editor.commit(); // persist the values
  92.  
  93. mySharedPreferences = getSharedPreferences(MY_PREFS, prefMode);
  94. String string1 = mySharedPreferences.getString("key1", null);
  95. String string2 = mySharedPreferences.getString("key2", null);
  96.  
  97. public static final String MY_PARAM_1 = "com.amritayalur.mypowerschool.PARAM_1";
  98. public static final String MY_PARAM_2 = "com.amritayalur.mypowerschool.PARAM_2";
  99.  
  100. // "this" is your activity or context
  101. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
  102.  
  103. SharedPreferences.Editor editor = prefs.edit();
  104.  
  105. editor.putString(MY_PARAM_1, "First string");
  106. editor.putString(MY_PARAM_2, "Second string");
  107.  
  108. editor.commit();
  109.  
  110. // specify default value in case if preferences are empty or current key is not set
  111. prefs.getString(MY_PARAM_1, "default value");
  112.  
  113. preferences
  114. .edit()
  115. .putLong(DAYS_LEFT, premiumStatus.getDaysLeft())
  116. .putString(KEY, premiumStatus.getKey())
  117. .putString(ID, premiumStatus.getId())
  118. .apply();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement