Jelajahi Sumber

Initial commit for PersistenDataSharedPreferences project.

Cristian Tanas 11 tahun lalu
induk
melakukan
79f9f3f662

+ 27 - 0
PersistentDataSharedPreferences/AndroidManifest.xml

@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="org.uab.android.persistentdata.sharedpreferences"
+    android:versionCode="1"
+    android:versionName="1.0" >
+
+    <uses-sdk
+        android:minSdkVersion="14"
+        android:targetSdkVersion="19" />
+
+    <application
+        android:allowBackup="true"
+        android:icon="@drawable/ic_launcher"
+        android:label="@string/app_name"
+        android:theme="@style/AppTheme" >
+        <activity
+            android:name=".MainActivity"
+            android:label="@string/app_name" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+    </application>
+
+</manifest>

TEMPAT SAMPAH
PersistentDataSharedPreferences/ic_launcher-web.png


TEMPAT SAMPAH
PersistentDataSharedPreferences/libs/android-support-v4.jar


TEMPAT SAMPAH
PersistentDataSharedPreferences/res/drawable-hdpi/ic_launcher.png


TEMPAT SAMPAH
PersistentDataSharedPreferences/res/drawable-mdpi/ic_launcher.png


TEMPAT SAMPAH
PersistentDataSharedPreferences/res/drawable-xhdpi/ic_launcher.png


TEMPAT SAMPAH
PersistentDataSharedPreferences/res/drawable-xxhdpi/ic_launcher.png


+ 49 - 0
PersistentDataSharedPreferences/res/layout/activity_main.xml

@@ -0,0 +1,49 @@
+<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"
+    tools:context="${relativePackage}.${activityClass}" >
+
+    <TextView
+        android:id="@+id/textView2"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/highScore" />
+
+    <TextView
+        android:id="@+id/highScoreTv"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentTop="true"
+        android:layout_marginLeft="14dp"
+        android:layout_toRightOf="@+id/textView2"
+        android:text="@string/initialHighScore" />
+
+    <TextView
+        android:id="@+id/currentScoreTv"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_centerHorizontal="true"
+        android:layout_centerVertical="true"
+        android:text="@string/initialHighScore"
+        android:textSize="36sp" />
+
+    <Button
+        android:id="@+id/resetBtn"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentBottom="true"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentRight="true"
+        android:text="@string/reset" />
+
+    <Button
+        android:id="@+id/playBtn"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_above="@+id/resetBtn"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentRight="true"
+        android:text="@string/play" />
+
+</RelativeLayout>

+ 11 - 0
PersistentDataSharedPreferences/res/values-v11/styles.xml

@@ -0,0 +1,11 @@
+<resources>
+
+    <!--
+        Base application theme for API 11+. This theme completely replaces
+        AppBaseTheme from res/values/styles.xml on API 11+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
+        <!-- API 11 theme customizations can go here. -->
+    </style>
+
+</resources>

+ 12 - 0
PersistentDataSharedPreferences/res/values-v14/styles.xml

@@ -0,0 +1,12 @@
+<resources>
+
+    <!--
+        Base application theme for API 14+. This theme completely replaces
+        AppBaseTheme from BOTH res/values/styles.xml and
+        res/values-v11/styles.xml on API 14+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+        <!-- API 14 theme customizations can go here. -->
+    </style>
+
+</resources>

+ 11 - 0
PersistentDataSharedPreferences/res/values/strings.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    <string name="app_name">PersistentDataSharedPreferences</string>
+    <string name="hello_world">Hello world!</string>
+    <string name="highScore">High Score:</string>
+    <string name="initialHighScore">0</string>
+    <string name="play">Play</string>
+    <string name="reset">Reset</string>
+
+</resources>

+ 20 - 0
PersistentDataSharedPreferences/res/values/styles.xml

@@ -0,0 +1,20 @@
+<resources>
+
+    <!--
+        Base application theme, dependent on API level. This theme is replaced
+        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Light">
+        <!--
+            Theme customizations available in newer API levels can go in
+            res/values-vXX/styles.xml, while customizations related to
+            backward-compatibility can go here.
+        -->
+    </style>
+
+    <!-- Application theme. -->
+    <style name="AppTheme" parent="AppBaseTheme">
+        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
+    </style>
+
+</resources>

+ 63 - 0
PersistentDataSharedPreferences/src/org/uab/android/persistentdata/sharedpreferences/MainActivity.java

@@ -0,0 +1,63 @@
+package org.uab.android.persistentdata.sharedpreferences;
+
+import java.util.Random;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.TextView;
+
+public class MainActivity extends Activity {
+	
+	private static final int 		MAX_RANGE = 1000;
+	private static final String		HIGH_SCORE_KEY = "HIGH_SCORE";
+	
+	TextView		highScoreTextView;
+	TextView		currentScoreTextView;
+	Button			playButton;
+	Button			resetButton;
+
+	@Override
+	protected void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.activity_main);
+		
+		// Get a reference to the high score TextView
+		highScoreTextView = (TextView) findViewById(R.id.highScoreTv);
+		
+		//TODO Update the high score based on the saved high score
+		
+		// Get a reference to the current game score TextView
+		currentScoreTextView = (TextView) findViewById(R.id.currentScoreTv);
+		
+		playButton = (Button) findViewById(R.id.playBtn);
+		playButton.setOnClickListener(new OnClickListener() {
+			
+			@Override
+			public void onClick(View v) {
+				
+				// Play a game where we get and display a random number
+				Random randomGenerator = new Random();
+				int value = randomGenerator.nextInt(MAX_RANGE);
+				
+				// Update the current game score
+				currentScoreTextView.setText(String.valueOf(value));
+				
+				//TODO Check whether the current score is greater than the high score
+				//		and update the high score accordingly
+			}
+		});
+		
+		resetButton = (Button) findViewById(R.id.resetBtn);
+		resetButton.setOnClickListener(new OnClickListener() {
+			
+			@Override
+			public void onClick(View v) {
+				
+				// TODO Set current game and high score to 0
+			}
+		});
+	}
+}