summaryrefslogtreecommitdiffstats
path: root/samples/devbytes/animation/KeyframeAnimation
diff options
context:
space:
mode:
authorChet Haase <chet@google.com>2013-01-10 16:19:38 -0800
committerChet Haase <chet@google.com>2013-01-14 15:21:15 -0800
commit74497f33361e3e9f0cb33d3111b5198444af5794 (patch)
treefdd5424398128a61c1c1bf0c150c76fd89919b3c /samples/devbytes/animation/KeyframeAnimation
parent7ca2ee364e57d481a212042cb50da48f8c3db374 (diff)
downloadandroid_development-74497f33361e3e9f0cb33d3111b5198444af5794.tar.gz
android_development-74497f33361e3e9f0cb33d3111b5198444af5794.tar.bz2
android_development-74497f33361e3e9f0cb33d3111b5198444af5794.zip
First set of demo apps for DevBytes videos
Change-Id: I4ae984cf776604cede32b98db6b1eb3cb6c59c7e
Diffstat (limited to 'samples/devbytes/animation/KeyframeAnimation')
-rw-r--r--samples/devbytes/animation/KeyframeAnimation/AndroidManifest.xml39
-rw-r--r--samples/devbytes/animation/KeyframeAnimation/res/drawable-hdpi/ic_launcher.pngbin0 -> 9397 bytes
-rw-r--r--samples/devbytes/animation/KeyframeAnimation/res/drawable-mdpi/ic_launcher.pngbin0 -> 5237 bytes
-rw-r--r--samples/devbytes/animation/KeyframeAnimation/res/drawable-xhdpi/ic_launcher.pngbin0 -> 14383 bytes
-rw-r--r--samples/devbytes/animation/KeyframeAnimation/res/layout/activity_keyframe_animation.xml28
-rw-r--r--samples/devbytes/animation/KeyframeAnimation/res/values-v11/styles.xml19
-rw-r--r--samples/devbytes/animation/KeyframeAnimation/res/values-v14/styles.xml19
-rw-r--r--samples/devbytes/animation/KeyframeAnimation/res/values/strings.xml20
-rw-r--r--samples/devbytes/animation/KeyframeAnimation/res/values/styles.xml19
-rw-r--r--samples/devbytes/animation/KeyframeAnimation/src/com/example/android/keyframeanimation/KeyframeAnimation.java85
10 files changed, 229 insertions, 0 deletions
diff --git a/samples/devbytes/animation/KeyframeAnimation/AndroidManifest.xml b/samples/devbytes/animation/KeyframeAnimation/AndroidManifest.xml
new file mode 100644
index 000000000..2406281ae
--- /dev/null
+++ b/samples/devbytes/animation/KeyframeAnimation/AndroidManifest.xml
@@ -0,0 +1,39 @@
+<!-- Copyright (C) 2013 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.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.keyframeanimation"
+ android:versionCode="1"
+ android:versionName="1.0" >
+
+ <uses-sdk
+ android:minSdkVersion="8"
+ android:targetSdkVersion="15" />
+
+ <application
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@style/AppTheme" >
+ <activity
+ android:name="com.example.android.keyframeanimation.KeyframeAnimation"
+ android:label="@string/title_activity_keyframe_animation" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
diff --git a/samples/devbytes/animation/KeyframeAnimation/res/drawable-hdpi/ic_launcher.png b/samples/devbytes/animation/KeyframeAnimation/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 000000000..96a442e5b
--- /dev/null
+++ b/samples/devbytes/animation/KeyframeAnimation/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/devbytes/animation/KeyframeAnimation/res/drawable-mdpi/ic_launcher.png b/samples/devbytes/animation/KeyframeAnimation/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 000000000..359047dfa
--- /dev/null
+++ b/samples/devbytes/animation/KeyframeAnimation/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/devbytes/animation/KeyframeAnimation/res/drawable-xhdpi/ic_launcher.png b/samples/devbytes/animation/KeyframeAnimation/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 000000000..71c6d760f
--- /dev/null
+++ b/samples/devbytes/animation/KeyframeAnimation/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/devbytes/animation/KeyframeAnimation/res/layout/activity_keyframe_animation.xml b/samples/devbytes/animation/KeyframeAnimation/res/layout/activity_keyframe_animation.xml
new file mode 100644
index 000000000..4da3948b8
--- /dev/null
+++ b/samples/devbytes/animation/KeyframeAnimation/res/layout/activity_keyframe_animation.xml
@@ -0,0 +1,28 @@
+<!-- Copyright (C) 2013 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.
+-->
+<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" >
+
+ <ImageView
+ android:id="@+id/imageview"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerHorizontal="true"
+ android:layout_centerVertical="true"
+ tools:context=".KeyframeAnimation" />
+
+</RelativeLayout>
diff --git a/samples/devbytes/animation/KeyframeAnimation/res/values-v11/styles.xml b/samples/devbytes/animation/KeyframeAnimation/res/values-v11/styles.xml
new file mode 100644
index 000000000..c16b77bf8
--- /dev/null
+++ b/samples/devbytes/animation/KeyframeAnimation/res/values-v11/styles.xml
@@ -0,0 +1,19 @@
+<!-- Copyright (C) 2013 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.
+-->
+<resources>
+
+ <style name="AppTheme" parent="android:Theme.Holo.Light" />
+
+</resources>
diff --git a/samples/devbytes/animation/KeyframeAnimation/res/values-v14/styles.xml b/samples/devbytes/animation/KeyframeAnimation/res/values-v14/styles.xml
new file mode 100644
index 000000000..0f1a1ef9c
--- /dev/null
+++ b/samples/devbytes/animation/KeyframeAnimation/res/values-v14/styles.xml
@@ -0,0 +1,19 @@
+<!-- Copyright (C) 2013 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.
+-->
+<resources>
+
+ <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar" />
+
+</resources>
diff --git a/samples/devbytes/animation/KeyframeAnimation/res/values/strings.xml b/samples/devbytes/animation/KeyframeAnimation/res/values/strings.xml
new file mode 100644
index 000000000..330dae2ba
--- /dev/null
+++ b/samples/devbytes/animation/KeyframeAnimation/res/values/strings.xml
@@ -0,0 +1,20 @@
+<!-- Copyright (C) 2013 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.
+-->
+<resources>
+
+ <string name="app_name">KeyframeAnimation</string>
+ <string name="title_activity_keyframe_animation">KeyframeAnimation</string>
+
+</resources>
diff --git a/samples/devbytes/animation/KeyframeAnimation/res/values/styles.xml b/samples/devbytes/animation/KeyframeAnimation/res/values/styles.xml
new file mode 100644
index 000000000..de01fbd2f
--- /dev/null
+++ b/samples/devbytes/animation/KeyframeAnimation/res/values/styles.xml
@@ -0,0 +1,19 @@
+<!-- Copyright (C) 2013 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.
+-->
+<resources>
+
+ <style name="AppTheme" parent="android:Theme.Light" />
+
+</resources>
diff --git a/samples/devbytes/animation/KeyframeAnimation/src/com/example/android/keyframeanimation/KeyframeAnimation.java b/samples/devbytes/animation/KeyframeAnimation/src/com/example/android/keyframeanimation/KeyframeAnimation.java
new file mode 100644
index 000000000..9a6bbd017
--- /dev/null
+++ b/samples/devbytes/animation/KeyframeAnimation/src/com/example/android/keyframeanimation/KeyframeAnimation.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2013 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.example.android.keyframeanimation;
+
+import android.app.Activity;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.drawable.AnimationDrawable;
+import android.graphics.drawable.BitmapDrawable;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.ImageView;
+
+/**
+ * This example shows how to use AnimationDrawable to construct a keyframe animation where each
+ * frame is shown for a specified duration.
+ *
+ * Watch the associated video for this demo on the DevBytes channel of developer.android.com
+ * or on YouTube at https://www.youtube.com/watch?v=V3ksidLf7vA.
+ */
+public class KeyframeAnimation extends Activity {
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_keyframe_animation);
+
+ ImageView imageview = (ImageView) findViewById(R.id.imageview);
+
+ // Create the AnimationDrawable in which we will store all frames of the animation
+ final AnimationDrawable animationDrawable = new AnimationDrawable();
+ for (int i = 0; i < 10; ++i) {
+ animationDrawable.addFrame(getDrawableForFrameNumber(i), 300);
+ }
+ // Run until we say stop
+ animationDrawable.setOneShot(false);
+
+ imageview.setImageDrawable(animationDrawable);
+
+ // When the user clicks on the image, toggle the animation on/off
+ imageview.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ if (animationDrawable.isRunning()) {
+ animationDrawable.stop();
+ } else {
+ animationDrawable.start();
+ }
+ }
+ });
+ }
+
+ /**
+ * The 'frames' in this app are nothing more than a gray background with text indicating
+ * the number of the frame.
+ */
+ private BitmapDrawable getDrawableForFrameNumber(int frameNumber) {
+ Bitmap bitmap = Bitmap.createBitmap(400, 400, Bitmap.Config.ARGB_8888);
+ Canvas canvas = new Canvas(bitmap);
+ canvas.drawColor(Color.GRAY);
+ Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
+ paint.setTextSize(80);
+ paint.setColor(Color.BLACK);
+ canvas.drawText("Frame " + frameNumber, 40, 220, paint);
+ return new BitmapDrawable(getResources(), bitmap);
+ }
+
+}