Guest User

Untitled

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