Guest User

Untitled

a guest
Jul 10th, 2015
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. package com.simonic.filmstudio;
  2.  
  3. import android.app.Activity;
  4. import android.content.SharedPreferences;
  5. import android.os.Bundle;
  6. import android.view.*;
  7. import android.widget.*;
  8.  
  9. public class MainActivity extends Activity {
  10.  
  11. SharedPreferences sharedPrefs;
  12. SharedPreferences.Editor editor;
  13. private static final String FILENAME = "PrefFile";
  14. //Buttons
  15. Button startbutton, buttone, buttonm, buttonh;
  16. //EditText
  17. EditText studiname;
  18. EditText edtext;
  19. //Variablen
  20. boolean regstat;
  21. String pname;
  22. int gamedif;
  23. int pmoney;
  24. String studname;
  25.  
  26. /*---------------------------------------------------------------------*/
  27. @Override
  28. protected void onCreate(Bundle savedInstanceState) {
  29. super.onCreate(savedInstanceState);
  30. //Buttons
  31. startbutton = (Button) findViewById(R.id.startbutt);
  32. buttone = (Button)findViewById(R.id.stutRegButtE);
  33. buttonm = (Button)findViewById(R.id.stutRegButtM);
  34. buttonh = (Button)findViewById(R.id.stutRegButtH);
  35. //SpielerDaten
  36. sharedPrefs = getSharedPreferences(FILENAME, MODE_PRIVATE);
  37. editor = sharedPrefs.edit();
  38. //EditText
  39. edtext = (EditText)findViewById(R.id.editText); //SpielerName
  40. studiname = (EditText)findViewById(R.id.stutRegEdt); //StudioName
  41. loadprefs();
  42. if(!regstat){
  43. setContentView(R.layout.activity_login);
  44. }
  45. setContentView(R.layout.activity_main);
  46. }
  47.  
  48. public void OnClickListeners(){
  49. startbutton.setOnClickListener(new View.OnClickListener() { //Register Start Button
  50.  
  51. @Override
  52. public void onClick(View v) {
  53. pname = edtext.getText().toString();
  54. regstat = true;
  55. setContentView(R.layout.activity_studioreg);
  56. }
  57. });
  58. buttone.setOnClickListener(new View.OnClickListener() { //Dif Button Easy
  59.  
  60. @Override
  61. public void onClick(View v) {
  62. if(studiname.getText().toString().trim().isEmpty()){
  63. nostudnametoast();
  64. }else{
  65. gamedif = 0;
  66. studname = studiname.getText().toString();
  67. pmoney = 100000;
  68. setContentView(R.layout.activity_main);
  69. }
  70. }
  71. });
  72. buttonm.setOnClickListener(new View.OnClickListener() { //Dif Button Medium
  73.  
  74. @Override
  75. public void onClick(View v) {
  76. if(studiname.getText().toString().trim().isEmpty()){
  77. nostudnametoast();
  78. }else{
  79. gamedif = 1;
  80. studname = studiname.getText().toString();
  81. pmoney = 75000;
  82. setContentView(R.layout.activity_main);
  83. }
  84. }
  85. });
  86. buttonh.setOnClickListener(new View.OnClickListener() { //Dif Button Hard
  87.  
  88. @Override
  89. public void onClick(View v) {
  90. if(studiname.getText().toString().trim().isEmpty()){
  91. nostudnametoast();
  92. }else{
  93. gamedif = 2;
  94. studname = studiname.getText().toString();
  95. pmoney = 40000;
  96. setContentView(R.layout.activity_main);
  97. }
  98. }
  99. });
  100. }
  101. public void nostudnametoast(){
  102. Toast toast = new Toast(getApplicationContext());
  103. toast.setGravity(100, 100, 100);
  104. Toast.makeText(MainActivity.this,"@string/nostudname", Toast.LENGTH_SHORT).show();
  105. }
  106.  
  107. @Override
  108. protected void onStop(){
  109. super.onStop();
  110. saveprefs();
  111. }
  112. @Override
  113. protected void onDestroy(){
  114. super.onDestroy();
  115. saveprefs();
  116. }
  117.  
  118. @Override
  119. protected void onPause(){
  120. super.onPause();
  121. saveprefs();
  122. }
  123.  
  124. @Override
  125. protected void onResume(){
  126. super.onResume();
  127. loadprefs();
  128. }
  129.  
  130. public void loadprefs() {
  131. sharedPrefs.getBoolean("regstat", false);
  132. sharedPrefs.getString("pname", "Leer");
  133. sharedPrefs.getString("studname", "Leer");
  134. sharedPrefs.getInt("money", 0);
  135. sharedPrefs.getInt("dif", 0);
  136. }
  137.  
  138. public void saveprefs() {
  139. editor.putBoolean("regstat", regstat);
  140. editor.putString("pname", pname);
  141. editor.putString("studname", studname);
  142. editor.putInt("money", pmoney);
  143. editor.putInt("dif", gamedif);
  144. editor.apply();
  145. }
  146.  
  147. @Override
  148. public boolean onCreateOptionsMenu(Menu menu) {
  149. // Inflate the menu; this adds items to the action bar if it is present.
  150. getMenuInflater().inflate(R.menu.menu_main, menu);
  151. return true;
  152. }
  153.  
  154. @Override
  155. public boolean onOptionsItemSelected(MenuItem item) {
  156. // Handle action bar item clicks here. The action bar will
  157. // automatically handle clicks on the Home/Up button, so long
  158. // as you specify a parent activity in AndroidManifest.xml.
  159. int id = item.getItemId();
  160.  
  161. //noinspection SimplifiableIfStatement
  162. if (id == R.id.action_settings) {
  163. return true;
  164. }
  165.  
  166. return super.onOptionsItemSelected(item);
  167. }
  168. }
Advertisement
Add Comment
Please, Sign In to add comment