Micha Kops avatar Micha Kops committed 024a601

Configuration menu for the dream added.

Comments (0)

Files changed (8)

AndroidManifest.xml

 
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
+
+            <meta-data
+                android:name="android.service.dream"
+                android:resource="@xml/hascode_dream" />
         </service>
+        <activity android:name="CustomDreamSettingsActivity"></activity>
     </application>
 
 </manifest>

res/layout/dream_settings.xml

+<?xml version="1.0" encoding="utf-8"?>
+    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent"
+        android:gravity="center_horizontal" >
+
+        <TextView
+            android:id="@+id/config_text"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/toggle_animation"
+            android:textAppearance="?android:attr/textAppearanceLarge" />
+
+        <ToggleButton
+            android:id="@+id/toggle_animate_button"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:checked="true"
+            android:minHeight="32dp"
+            android:minWidth="32dp" />
+
+    </LinearLayout>

res/values/strings.xml

     <string name="app_name">hasCode Dream App</string>
     <string name="custom_dream_label">hasCode Dream</string>
     <string name="demo_text">Dreaming of hasCode.com..</string>
+    <string name="toggle_animation">Animate Dream</string>
 
 </resources>

res/xml/hascode_dream.xml

+<dream xmlns:android="http://schemas.android.com/apk/res/android"
+    android:settingsActivity="com.hascode.android.dream_app/.CustomDreamSettingsActivity" />

res/xml/sample_dream.xml

-<dream xmlns:android="http://schemas.android.com/apk/res/android"
-    android:settingsActivity="com.example.app/.MyDreamSettingsActivity" />

src/com/hascode/android/dream/SampleDream.java

-package com.hascode.android.dream;
-
-import android.service.dreams.DreamService;
-
-import com.hascode.dream_app.R;
-
-public class SampleDream extends DreamService {
-
-	@Override
-	public void onAttachedToWindow() {
-		super.onAttachedToWindow();
-		setInteractive(false);
-		setFullscreen(true);
-		setContentView(R.layout.dream);
-	}
-}

src/com/hascode/android/dream_app/CustomDreamSettingsActivity.java

+package com.hascode.android.dream_app;
+
+import android.app.Activity;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.widget.CompoundButton;
+import android.widget.CompoundButton.OnCheckedChangeListener;
+import android.widget.ToggleButton;
+
+public class CustomDreamSettingsActivity extends Activity {
+	public static final String PREFS_KEY = "SampleDreamPrefs";
+
+	@Override
+	protected void onCreate(final Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.dream_settings);
+		final SharedPreferences settings = getSharedPreferences(PREFS_KEY, 0);
+		boolean animate = settings.getBoolean("animateDream", true);
+
+		final ToggleButton toggle = (ToggleButton) findViewById(R.id.toggle_animate_button);
+		toggle.setChecked(animate);
+		toggle.setOnCheckedChangeListener(new OnCheckedChangeListener() {
+
+			@Override
+			public void onCheckedChanged(final CompoundButton buttonView,
+					final boolean isChecked) {
+				SharedPreferences.Editor prefEditor = settings.edit();
+				prefEditor.putBoolean("animateDream", isChecked);
+				prefEditor.commit();
+			}
+		});
+	}
+}

src/com/hascode/android/dream_app/SampleDream.java

 package com.hascode.android.dream_app;
 
+import android.content.SharedPreferences;
 import android.service.dreams.DreamService;
 import android.view.animation.Animation;
 import android.view.animation.AnimationUtils;
 		setFullscreen(true);
 		setContentView(R.layout.dream);
 		TextView animatedText = (TextView) findViewById(R.id.animatedText);
-		Animation animation = AnimationUtils.loadAnimation(this,
-				R.anim.dream_animation);
-		animation.reset();
-		animatedText.startAnimation(animation);
+		final SharedPreferences settings = getSharedPreferences(
+				CustomDreamSettingsActivity.PREFS_KEY, 0);
+		boolean animate = settings.getBoolean("animateDream", true);
+		if (animate) {
+			Animation animation = AnimationUtils.loadAnimation(this,
+					R.anim.dream_animation);
+			animation.reset();
+			animatedText.startAnimation(animation);
+		}
 	}
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.