Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.ali.ColorMatch2;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.os.Process;
- import android.widget.TextView;
- /**
- * Created by Ali on 10/17/2016.
- */
- public class LoseScreen extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.lose_screen);
- TextView textView7 = (TextView) findViewById(R.id.textView7);
- textView7.setText("Well you tried. Click anywhere to play again");
- /*Button quitButton = (Button) findViewById(R.id.quitButton);
- quitButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Process.killProcess(Process.myPid());
- //finish();
- System.exit(0);
- }
- });*/
- Bundle b = getIntent().getExtras();
- int newScore = b.getInt("newScore");
- TextView textView6 = (TextView) findViewById(R.id.textView6);
- textView6.setText("Score: " + newScore);
- SharedPreferences prefs = this.getSharedPreferences("myPrefsKey", Context.MODE_PRIVATE);
- int highScore = prefs.getInt("highScore", 0); //0 is the default value
- if (newScore > highScore) {
- prefs = this.getSharedPreferences("myPrefsKey", Context.MODE_PRIVATE);
- SharedPreferences.Editor editor = prefs.edit();
- editor.putInt("highScore", newScore);
- editor.commit();
- highScore = newScore;
- }
- TextView textView8 = (TextView) findViewById(R.id.textView8);
- textView8.setText("High Score: " + highScore);
- }
- /* protected void onDestroy(){
- super.onDestroy();
- Process.killProcess(Process.myPid());
- }*/
- public void onQuitClick(View view){
- finish();
- Process.killProcess(Process.myPid());
- //System.exit(0);
- }
- public void onLoseScreenClick (View view){
- Intent intent = new Intent(LoseScreen.this, ColorMatch2.class);
- startActivity(intent);
- overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
- }
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent" android:layout_height="match_parent"
- android:background="@drawable/bkg_7"
- android:onClick="onLoseScreenClick"
- >
- <Button
- android:layout_width="35dp"
- android:layout_height="35dp"
- android:id="@+id/quitButton"
- android:background="@android:drawable/btn_dialog"
- android:onClick="onQuitClick"
- android:clickable="true"
- android:layout_marginTop="16dp"
- android:layout_marginLeft="24dp"
- android:layout_marginStart="24dp"
- android:layout_alignParentTop="true"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement