Skip to content

Commit 4fe74c1

Browse files
committed
Toy demo of JellyBean's new Dreams feature; displays text-based reminders.
1 parent e580577 commit 4fe74c1

17 files changed

+345
-0
lines changed

DreamsDemo/.classpath

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="src" path="gen"/>
5+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
6+
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
7+
<classpathentry kind="output" path="bin/classes"/>
8+
</classpath>

DreamsDemo/.project

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>DreamsDemo</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.jdt.core.javabuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
</buildSpec>
29+
<natures>
30+
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
31+
<nature>org.eclipse.jdt.core.javanature</nature>
32+
</natures>
33+
</projectDescription>

DreamsDemo/AndroidManifest.xml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.example.dreamsdemo"
4+
android:versionCode="1"
5+
android:versionName="1.0" >
6+
7+
<uses-sdk
8+
android:minSdkVersion="17"
9+
android:targetSdkVersion="18" />
10+
11+
<application
12+
android:allowBackup="true"
13+
android:icon="@drawable/ic_launcher"
14+
android:label="@string/app_name"
15+
android:theme="@style/AppTheme" >
16+
17+
<service
18+
android:name=".DreamsDemo"
19+
android:exported="true"
20+
android:icon="@drawable/ic_launcher"
21+
android:label="@string/dream_label" >
22+
<intent-filter>
23+
<action android:name="android.service.dreams.DreamService" />
24+
25+
<category android:name="android.intent.category.DEFAULT" />
26+
</intent-filter>
27+
28+
<!-- Points to optional metadata for this dream; for now they only implement
29+
*** a Settings button, ours does nothing but there it is...
30+
-->
31+
<meta-data
32+
android:name="android.service.dream"
33+
android:resource="@xml/my_dream" />
34+
</service>
35+
36+
<activity android:name=".SettingsActivity"
37+
android:label="@string/dream_label"/>
38+
</application>
39+
40+
</manifest>

DreamsDemo/ic_launcher-web.png

113 KB
Loading

DreamsDemo/proguard-project.txt

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# To enable ProGuard in your project, edit project.properties
2+
# to define the proguard.config property as described in that file.
3+
#
4+
# Add project specific ProGuard rules here.
5+
# By default, the flags in this file are appended to flags specified
6+
# in ${sdk.dir}/tools/proguard/proguard-android.txt
7+
# You can edit the include path and order by changing the ProGuard
8+
# include property in project.properties.
9+
#
10+
# For more details, see
11+
# http://developer.android.com/guide/developing/tools/proguard.html
12+
13+
# Add any project specific keep options here:
14+
15+
# If your project uses WebView with JS, uncomment the following
16+
# and specify the fully qualified class name to the JavaScript interface
17+
# class:
18+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19+
# public *;
20+
#}

DreamsDemo/project.properties

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This file is automatically generated by Android Tools.
2+
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3+
#
4+
# This file must be checked in Version Control Systems.
5+
#
6+
# To customize properties used by the Ant build system edit
7+
# "ant.properties", and override values to adapt the script to your
8+
# project structure.
9+
#
10+
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11+
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12+
13+
# Project target.
14+
target=android-18
9.04 KB
Loading
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:paddingBottom="@dimen/activity_vertical_margin"
6+
android:paddingLeft="@dimen/activity_horizontal_margin"
7+
android:paddingRight="@dimen/activity_horizontal_margin"
8+
android:paddingTop="@dimen/activity_vertical_margin"
9+
tools:context=".MainActivity" >
10+
11+
<TextView
12+
android:id="@+id/fail"
13+
android:layout_width="match_parent"
14+
android:layout_height="match_parent"
15+
android:textSize="24sp"
16+
android:lineSpacingExtra="12sp"
17+
android:text="Settings not written yet, sorry"
18+
/>
19+
20+
</RelativeLayout>

DreamsDemo/res/layout/dreamscape.xml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:paddingBottom="@dimen/activity_vertical_margin"
6+
android:paddingLeft="@dimen/activity_horizontal_margin"
7+
android:paddingRight="@dimen/activity_horizontal_margin"
8+
android:paddingTop="@dimen/activity_vertical_margin"
9+
tools:context=".MainActivity" >
10+
11+
<TextView
12+
android:id="@+id/textview"
13+
android:layout_width="match_parent"
14+
android:layout_height="match_parent"
15+
android:textSize="24sp"
16+
android:lineSpacingExtra="12sp"
17+
/>
18+
19+
</RelativeLayout>

DreamsDemo/res/menu/main.xml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
2+
3+
<item
4+
android:id="@+id/action_settings"
5+
android:orderInCategory="100"
6+
android:showAsAction="never"
7+
android:title="@string/action_settings"/>
8+
9+
</menu>

DreamsDemo/res/values/dimens.xml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<resources>
2+
3+
<!-- Default screen margins, per the Android Design guidelines. -->
4+
<dimen name="activity_horizontal_margin">16dp</dimen>
5+
<dimen name="activity_vertical_margin">16dp</dimen>
6+
7+
</resources>

DreamsDemo/res/values/reminders.xml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string-array name="reminders">
4+
<item>Don\'t worry, be happy!</item>
5+
<item>Remain hydrated, but not too much.</item>
6+
<item>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do.</item>
7+
<item>Eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim.</item>
8+
<item>Ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.</item>
9+
<item>Aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit.</item>
10+
<item>in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</item>
11+
<item>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui.</item>
12+
<item>Officia deserunt mollit anim id est laborum.</item>
13+
</string-array>
14+
</resources>

DreamsDemo/res/values/strings.xml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<string name="app_name">DreamsDemo</string>
5+
<string name="action_settings">Settings</string>
6+
<string name="dream_label">California Dreamin?</string>
7+
8+
</resources>

DreamsDemo/res/values/styles.xml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme, dependent on API level. This theme is replaced
5+
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
6+
-->
7+
<style name="AppBaseTheme" parent="android:Theme.Light">
8+
<!--
9+
Theme customizations available in newer API levels can go in
10+
res/values-vXX/styles.xml, while customizations related to
11+
backward-compatibility can go here.
12+
-->
13+
</style>
14+
15+
<!-- Application theme. -->
16+
<style name="AppTheme" parent="AppBaseTheme">
17+
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
18+
</style>
19+
20+
</resources>

DreamsDemo/res/xml/my_dream.xml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<dream xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:settingsActivity=".SettingsActivity" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package com.example.dreamsdemo;
2+
3+
import java.util.Random;
4+
5+
import android.animation.TimeAnimator;
6+
import android.content.Context;
7+
import android.service.dreams.DreamService;
8+
import android.util.AttributeSet;
9+
import android.util.Log;
10+
import android.widget.FrameLayout;
11+
import android.widget.TextView;
12+
13+
/**
14+
* Androids Do Dream of Electric Sleep, But Only While Charging
15+
*/
16+
public class DreamsDemo extends DreamService {
17+
static final String TAG = "MyDream";
18+
19+
final static int YINCR = 2;
20+
final static int POINT_SIZE = 18;
21+
private static final Random RANDOM = new Random();
22+
String[] data;
23+
24+
@Override
25+
public void onCreate() {
26+
Log.d(TAG, "MyDream.onCreate()");
27+
super.onCreate();
28+
data = getResources().getStringArray(R.array.reminders);
29+
}
30+
31+
@Override
32+
public void onAttachedToWindow() {
33+
Log.d(TAG, "MyDream.onAttachedToWindow()");
34+
super.onAttachedToWindow();
35+
36+
// ready the Runner
37+
final Runner runner = new Runner(this);
38+
setContentView(runner);
39+
40+
// Exit dream upon user touch
41+
setInteractive(false);
42+
// Don't hide system UI - leaves time and battery etc showing.
43+
setFullscreen(false);
44+
45+
}
46+
47+
48+
/**
49+
* A little animator.
50+
*/
51+
class Runner extends FrameLayout implements TimeAnimator.TimeListener {
52+
53+
private TextView ta;
54+
private final TimeAnimator mAnimator;
55+
56+
public Runner(Context context) {
57+
this(context, null);
58+
}
59+
60+
public Runner(Context context, AttributeSet attrs) {
61+
this(context, attrs, 0);
62+
}
63+
64+
public Runner(Context context, AttributeSet attrs, int flags) {
65+
super(context, attrs, flags);
66+
mAnimator = new TimeAnimator();
67+
mAnimator.setTimeListener(this);
68+
ta = new TextView(context, attrs);
69+
ta.setTextSize(POINT_SIZE);
70+
final FrameLayout.LayoutParams params =
71+
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
72+
addView(ta, params);
73+
}
74+
75+
@Override
76+
public void onAttachedToWindow() {
77+
Log.d(TAG, "MyDream.Runner.onAttachedToWindow()");
78+
super.onAttachedToWindow();
79+
mAnimator.start();
80+
}
81+
82+
@Override
83+
public void onDetachedFromWindow() {
84+
Log.d(TAG, "MyDream.Runner.onDetachedFromWindow()");
85+
mAnimator.cancel();
86+
super.onDetachedFromWindow();
87+
}
88+
89+
/** Tick! */
90+
@Override
91+
public void onTimeUpdate(TimeAnimator animation, long elapsed, long dt_ms) {
92+
93+
// At the top of screen, pick a new reminder
94+
if (ta.getY() < YINCR) {
95+
int ix = RANDOM.nextInt(data.length);
96+
ta.setText(data[ix]);
97+
}
98+
// move that baby along!
99+
int y = (int)(ta.getY() + YINCR);
100+
if (getHeight() > 0) {
101+
y %= getHeight();
102+
}
103+
// If we've gone off the bottom, give up; next call or few will reset it
104+
if (y > getHeight()) {
105+
return;
106+
}
107+
ta.setY(y);
108+
}
109+
110+
}
111+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.example.dreamsdemo;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
import android.util.Log;
6+
7+
/**
8+
* Placeholder for a Settings Activity; see ../PreferencesDemo for real how-to.
9+
*/
10+
public class SettingsActivity extends Activity {
11+
12+
private static final String TAG = DreamsDemo.TAG;
13+
14+
@Override
15+
protected void onCreate(Bundle savedInstanceState) {
16+
Log.d(TAG, "SettingsActivity.onCreate()");
17+
super.onCreate(savedInstanceState);
18+
setContentView(R.layout.dream_settings);
19+
}
20+
}

0 commit comments

Comments
 (0)