Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.simonic.filmstudio;
- import android.app.Activity;
- import android.content.SharedPreferences;
- import android.os.Bundle;
- import android.view.*;
- import android.widget.*;
- public class MainActivity extends Activity {
- private static final String FILENAME = "PrefFile";
- //SpielerDaten
- SharedPreferences sharedPrefs = getSharedPreferences(FILENAME, 0);
- SharedPreferences.Editor editor = sharedPrefs.edit();
- //Variablen
- boolean regstat;
- String pname;
- int gamedif;
- int pmoney;
- String studname;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- loadprefs();
- if(!regstat){
- setContentView(R.layout.activity_login);
- //Buttons
- Button startbutton = (Button) findViewById(R.id.startbutt);
- Button buttone = (Button)findViewById(R.id.stutRegButtE);
- Button buttonm = (Button)findViewById(R.id.stutRegButtM);
- Button buttonh = (Button)findViewById(R.id.stutRegButtH);
- //EditText
- final EditText studiname = (EditText)findViewById(R.id.stutRegEdt); //StudioName
- final EditText edtext = (EditText)findViewById(R.id.editText); //SpielerName
- startbutton.setOnClickListener(new View.OnClickListener() { //Register Start Button
- @Override
- public void onClick(View v) {
- pname = edtext.getText().toString();
- regstat = true;
- setContentView(R.layout.activity_studioreg);
- }
- });
- buttone.setOnClickListener(new View.OnClickListener() { //Dif Button Easy
- @Override
- public void onClick(View v) {
- if(studiname.getText().toString().trim().isEmpty()){
- nostudnametoast();
- }else{
- gamedif = 0;
- studname = studiname.getText().toString();
- pmoney = 100000;
- setContentView(R.layout.activity_main);
- }
- }
- });
- buttonm.setOnClickListener(new View.OnClickListener() { //Dif Button Medium
- @Override
- public void onClick(View v) {
- if(studiname.getText().toString().trim().isEmpty()){
- nostudnametoast();
- }else{
- gamedif = 1;
- studname = studiname.getText().toString();
- pmoney = 75000;
- setContentView(R.layout.activity_main);
- }
- }
- });
- buttonh.setOnClickListener(new View.OnClickListener() { //Dif Button Hard
- @Override
- public void onClick(View v) {
- if(studiname.getText().toString().trim().isEmpty()){
- nostudnametoast();
- }else{
- gamedif = 2;
- studname = studiname.getText().toString();
- pmoney = 40000;
- setContentView(R.layout.activity_main);
- }
- }
- });
- }
- setContentView(R.layout.activity_main);
- }
- public void nostudnametoast(){
- Toast toast = new Toast(getApplicationContext());
- toast.setGravity(100, 100, 100);
- Toast.makeText(MainActivity.this,"@string/nostudname", Toast.LENGTH_SHORT).show();
- }
- protected void onDestroy(){
- saveprefs();
- }
- protected void onPause(){
- saveprefs();
- }
- protected void onResume(){
- loadprefs();
- }
- public void loadprefs() {
- sharedPrefs.getBoolean("regstat", false);
- sharedPrefs.getString("pname", "Leer");
- sharedPrefs.getString("studname", "Leer");
- sharedPrefs.getInt("money", 0);
- sharedPrefs.getInt("dif", 0);
- }
- public void saveprefs() {
- editor.putBoolean("regstat", regstat);
- editor.putString("pname", pname);
- editor.putString("studname", studname);
- editor.putInt("money", pmoney);
- editor.putInt("dif", gamedif);
- editor.commit();
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_main, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment