diff options
author | Daniel Sandler <dsandler@android.com> | 2012-09-20 13:15:31 -0400 |
---|---|---|
committer | Daniel Sandler <dsandler@android.com> | 2012-09-20 13:15:31 -0400 |
commit | 728f13b267698668f5d3349cda8035c1a1d4a820 (patch) | |
tree | d31c0da5e3bd3543a5ac457f1e7c8ad85bcb5b93 | |
parent | 5d2e654245d7cfec9aee71ff7923dfa7566dde01 (diff) | |
download | experimental-728f13b267698668f5d3349cda8035c1a1d4a820.tar.gz |
Sample Dream showing an error message.
Change-Id: I56df7392ec5cd1c2b56cac61ffacc5df5ad6244b
-rw-r--r-- | Bummer/Android.mk | 14 | ||||
-rw-r--r-- | Bummer/AndroidManifest.xml | 19 | ||||
-rw-r--r-- | Bummer/src/com/android/dreams/bummer/Bummer.java | 64 | ||||
-rw-r--r-- | Bummer/src/com/android/dreams/bummer/BummerView.java | 106 |
4 files changed, 203 insertions, 0 deletions
diff --git a/Bummer/Android.mk b/Bummer/Android.mk new file mode 100644 index 0000000..221d322 --- /dev/null +++ b/Bummer/Android.mk @@ -0,0 +1,14 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := optional + +# Only compile source java files in this apk. +LOCAL_SRC_FILES := $(call all-java-files-under, src) + +LOCAL_PACKAGE_NAME := Bummer + +include $(BUILD_PACKAGE) + +# Use the following include to make our test apk. +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/Bummer/AndroidManifest.xml b/Bummer/AndroidManifest.xml new file mode 100644 index 0000000..7572bb3 --- /dev/null +++ b/Bummer/AndroidManifest.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.dreams.bummer" + android:versionCode="1" + android:versionName="1.0"> + + <application android:label="Bummer"> + <service + android:name=".Bummer" + android:exported="true" + android:label="Bummer"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.DEFAULT" /> + <category android:name="android.intent.category.DREAM" /> + </intent-filter> + </service> + </application> +</manifest> diff --git a/Bummer/src/com/android/dreams/bummer/Bummer.java b/Bummer/src/com/android/dreams/bummer/Bummer.java new file mode 100644 index 0000000..8cfa138 --- /dev/null +++ b/Bummer/src/com/android/dreams/bummer/Bummer.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.dreams.bummer; + +import android.graphics.Color; +import android.service.dreams.Dream; +import android.view.View; +import android.view.ViewGroup; +import android.widget.FrameLayout; + +public class Bummer extends Dream { + public static final int MOVE = 1; + + public static final int DELAY = 1000; // ms + + public String message = "Bummer!"; + public int color = Color.WHITE; + public float size = 20.0f; + + private FrameLayout mFrame; + private BummerView mApology; + + @Override + public void onStart() { + mFrame = new FrameLayout(this); + mFrame.setLayoutParams(new ViewGroup.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT + )); + + mApology = new BummerView(this); + mApology.setText(message); + mApology.setTextColor(color); + mApology.setTextSize(size); + mApology.setCompoundDrawablesWithIntrinsicBounds(android.R.drawable.stat_sys_warning, 0, 0, + 0); + mApology.setCompoundDrawablePadding(8); + mApology.setAlpha(0.5f); + + final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams( + ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ); + mApology.setVisibility(View.INVISIBLE); + mFrame.addView(mApology, lp); + + setContentView(mFrame); + } + +} diff --git a/Bummer/src/com/android/dreams/bummer/BummerView.java b/Bummer/src/com/android/dreams/bummer/BummerView.java new file mode 100644 index 0000000..dc2a89d --- /dev/null +++ b/Bummer/src/com/android/dreams/bummer/BummerView.java @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.dreams.bummer; + +import android.content.Context; +import android.os.Handler; +import android.os.Message; +import android.util.AttributeSet; +import android.view.View; +import android.widget.TextView; + +public class BummerView extends TextView { + public static final int START = 1; + public static final int MOVE = 2; + + private int mDelay = 10000; // ms + private int mAnimTime = 2000; // ms + private boolean mAnimate = true; + + private Handler mHandler = new Handler() { + @Override + public void handleMessage(Message m) { + boolean animate = false; + switch (m.what) { + case MOVE: + animate = mAnimate; + // fall through + case START: + final View parent = (View) BummerView.this.getParent(); + if (parent == null) + return; + + final float framew = parent.getMeasuredWidth(); + final float frameh = parent.getMeasuredHeight(); + final float textw = getMeasuredWidth(); + final float texth = getMeasuredHeight(); + + final float newx = (float) (Math.random() * (framew - textw)); + final float newy = (float) (Math.random() * (frameh - texth)); + if (animate) { + animate().x(newx) + .y(newy) + .setDuration(mAnimTime) + .start(); + } else { + setX(newx); + setY(newy); + } + setVisibility(View.VISIBLE); + + removeMessages(MOVE); + sendEmptyMessageDelayed(MOVE, mDelay); + break; + } + } + }; + + public BummerView(Context context) { + super(context); + } + + public BummerView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public BummerView(Context context, AttributeSet attrs, int flags) { + super(context, attrs, flags); + } + + public void setAnimationParams(boolean animate, int delay, int animTime) { + mAnimate = animate; + mDelay = delay; + mAnimTime = animTime; + } + + @Override + public void onAttachedToWindow() { + final View parent = (View) this.getParent(); + parent.addOnLayoutChangeListener(new OnLayoutChangeListener() { + public void onLayoutChange(View v, int left, int top, int right, int bottom, + int oldLeft, int oldTop, int oldRight, int oldBottom) { + if (v == parent && right != oldRight) { + mHandler.removeMessages(MOVE); + mHandler.sendEmptyMessage(START); + } + } + }); + + mHandler.sendEmptyMessage(START); + } + +} |