Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. package com.example.ali.ColorMatch2;
  2.  
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.content.SharedPreferences;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.os.Process;
  11. import android.widget.TextView;
  12.  
  13. /**
  14. * Created by Ali on 10/17/2016.
  15. */
  16.  
  17. public class LoseScreen extends AppCompatActivity {
  18.  
  19. @Override
  20. protected void onCreate(Bundle savedInstanceState) {
  21. super.onCreate(savedInstanceState);
  22. setContentView(R.layout.lose_screen);
  23. TextView textView7 = (TextView) findViewById(R.id.textView7);
  24. textView7.setText("Well you tried. Click anywhere to play again");
  25.  
  26.  
  27. /*Button quitButton = (Button) findViewById(R.id.quitButton);
  28.  
  29. quitButton.setOnClickListener(new View.OnClickListener() {
  30. @Override
  31. public void onClick(View v) {
  32. Process.killProcess(Process.myPid());
  33. //finish();
  34. System.exit(0);
  35. }
  36. });*/
  37.  
  38. Bundle b = getIntent().getExtras();
  39. int newScore = b.getInt("newScore");
  40.  
  41. TextView textView6 = (TextView) findViewById(R.id.textView6);
  42. textView6.setText("Score: " + newScore);
  43.  
  44. SharedPreferences prefs = this.getSharedPreferences("myPrefsKey", Context.MODE_PRIVATE);
  45. int highScore = prefs.getInt("highScore", 0); //0 is the default value
  46.  
  47. if (newScore > highScore) {
  48. prefs = this.getSharedPreferences("myPrefsKey", Context.MODE_PRIVATE);
  49. SharedPreferences.Editor editor = prefs.edit();
  50. editor.putInt("highScore", newScore);
  51. editor.commit();
  52. highScore = newScore;
  53. }
  54.  
  55.  
  56. TextView textView8 = (TextView) findViewById(R.id.textView8);
  57. textView8.setText("High Score: " + highScore);
  58.  
  59.  
  60.  
  61.  
  62. }
  63.  
  64. /* protected void onDestroy(){
  65. super.onDestroy();
  66. Process.killProcess(Process.myPid());
  67. }*/
  68.  
  69. public void onQuitClick(View view){
  70. finish();
  71. Process.killProcess(Process.myPid());
  72. //System.exit(0);
  73. }
  74.  
  75. public void onLoseScreenClick (View view){
  76. Intent intent = new Intent(LoseScreen.this, ColorMatch2.class);
  77. startActivity(intent);
  78. overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
  79.  
  80. }
  81.  
  82. <?xml version="1.0" encoding="utf-8"?>
  83. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  84. xmlns:tools="http://schemas.android.com/tools"
  85. android:layout_width="match_parent" android:layout_height="match_parent"
  86. android:background="@drawable/bkg_7"
  87. android:onClick="onLoseScreenClick"
  88. >
  89.  
  90. <Button
  91. android:layout_width="35dp"
  92. android:layout_height="35dp"
  93. android:id="@+id/quitButton"
  94. android:background="@android:drawable/btn_dialog"
  95. android:onClick="onQuitClick"
  96. android:clickable="true"
  97. android:layout_marginTop="16dp"
  98. android:layout_marginLeft="24dp"
  99. android:layout_marginStart="24dp"
  100. android:layout_alignParentTop="true"
  101. android:layout_alignParentLeft="true"
  102. android:layout_alignParentStart="true" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement