summaryrefslogtreecommitdiffstats
path: root/samples/devbytes/animation/LayoutTransChanging
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/LayoutTransChanging
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/LayoutTransChanging')
-rw-r--r--samples/devbytes/animation/LayoutTransChanging/AndroidManifest.xml36
-rw-r--r--samples/devbytes/animation/LayoutTransChanging/res/drawable-hdpi/icon.pngbin0 -> 4147 bytes
-rw-r--r--samples/devbytes/animation/LayoutTransChanging/res/drawable-ldpi/icon.pngbin0 -> 1723 bytes
-rw-r--r--samples/devbytes/animation/LayoutTransChanging/res/drawable-mdpi/icon.pngbin0 -> 2574 bytes
-rw-r--r--samples/devbytes/animation/LayoutTransChanging/res/layout/main.xml41
-rw-r--r--samples/devbytes/animation/LayoutTransChanging/res/values/strings.xml20
-rw-r--r--samples/devbytes/animation/LayoutTransChanging/src/com/example/android/layouttranschanging/LayoutTransChanging.java120
7 files changed, 217 insertions, 0 deletions
diff --git a/samples/devbytes/animation/LayoutTransChanging/AndroidManifest.xml b/samples/devbytes/animation/LayoutTransChanging/AndroidManifest.xml
new file mode 100644
index 000000000..d9b55f5ae
--- /dev/null
+++ b/samples/devbytes/animation/LayoutTransChanging/AndroidManifest.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.layouttranschanging"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <uses-sdk android:minSdkVersion="16"/>
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <application
+ android:icon="@drawable/icon"
+ android:label="@string/app_name"
+ android:hardwareAccelerated="true">
+ <activity android:label="@string/app_name"
+ android:name="com.example.android.layouttranschanging.LayoutTransChanging">
+ <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/LayoutTransChanging/res/drawable-hdpi/icon.png b/samples/devbytes/animation/LayoutTransChanging/res/drawable-hdpi/icon.png
new file mode 100644
index 000000000..8074c4c57
--- /dev/null
+++ b/samples/devbytes/animation/LayoutTransChanging/res/drawable-hdpi/icon.png
Binary files differ
diff --git a/samples/devbytes/animation/LayoutTransChanging/res/drawable-ldpi/icon.png b/samples/devbytes/animation/LayoutTransChanging/res/drawable-ldpi/icon.png
new file mode 100644
index 000000000..1095584ec
--- /dev/null
+++ b/samples/devbytes/animation/LayoutTransChanging/res/drawable-ldpi/icon.png
Binary files differ
diff --git a/samples/devbytes/animation/LayoutTransChanging/res/drawable-mdpi/icon.png b/samples/devbytes/animation/LayoutTransChanging/res/drawable-mdpi/icon.png
new file mode 100644
index 000000000..a07c69fa5
--- /dev/null
+++ b/samples/devbytes/animation/LayoutTransChanging/res/drawable-mdpi/icon.png
Binary files differ
diff --git a/samples/devbytes/animation/LayoutTransChanging/res/layout/main.xml b/samples/devbytes/animation/LayoutTransChanging/res/layout/main.xml
new file mode 100644
index 000000000..3b5dd0df4
--- /dev/null
+++ b/samples/devbytes/animation/LayoutTransChanging/res/layout/main.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+ <LinearLayout
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+ <Button
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/addButton"
+ android:id="@+id/addButton"/>
+ <Button
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/removeButton"
+ android:id="@+id/removeButton"/>
+ </LinearLayout>
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:animateLayoutChanges="true"
+ android:id="@+id/container"/>
+</LinearLayout>
diff --git a/samples/devbytes/animation/LayoutTransChanging/res/values/strings.xml b/samples/devbytes/animation/LayoutTransChanging/res/values/strings.xml
new file mode 100644
index 000000000..d50ad1167
--- /dev/null
+++ b/samples/devbytes/animation/LayoutTransChanging/res/values/strings.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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">LayoutTransChanging</string>
+ <string name="addButton">Add Item</string>
+ <string name="removeButton">Remove Item</string>
+</resources>
diff --git a/samples/devbytes/animation/LayoutTransChanging/src/com/example/android/layouttranschanging/LayoutTransChanging.java b/samples/devbytes/animation/LayoutTransChanging/src/com/example/android/layouttranschanging/LayoutTransChanging.java
new file mode 100644
index 000000000..e24033032
--- /dev/null
+++ b/samples/devbytes/animation/LayoutTransChanging/src/com/example/android/layouttranschanging/LayoutTransChanging.java
@@ -0,0 +1,120 @@
+/*
+ * 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.layouttranschanging;
+
+import android.animation.LayoutTransition;
+import android.app.Activity;
+import android.content.Context;
+import android.os.Bundle;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.LinearLayout;
+import android.widget.LinearLayout.LayoutParams;
+
+/**
+ * This example shows how to use LayoutTransition to animate simple changes in a layout
+ * container.
+ *
+ * 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=55wLsaWpQ4g.
+ */
+public class LayoutTransChanging extends Activity {
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+
+ final Button addButton =
+ (Button) findViewById(R.id.addButton);
+ final Button removeButton =
+ (Button) findViewById(R.id.removeButton);
+ final LinearLayout container =
+ (LinearLayout) findViewById(R.id.container);
+ final Context context = this;
+
+ // Start with two views
+ for (int i = 0; i < 2; ++i) {
+ container.addView(new ColoredView(this));
+ }
+
+ addButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ // Adding a view will cause a LayoutTransition animation
+ container.addView(new ColoredView(context), 1);
+ }
+ });
+
+ removeButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (container.getChildCount() > 0) {
+ // Removing a view will cause a LayoutTransition animation
+ container.removeViewAt(Math.min(1, container.getChildCount() - 1));
+ }
+ }
+ });
+
+ // Note that this assumes a LayoutTransition is set on the container, which is the
+ // case here because the container has the attribute "animateLayoutChanges" set to true
+ // in the layout file. You can also call setLayoutTransition(new LayoutTransition()) in
+ // code to set a LayoutTransition on any container.
+ LayoutTransition transition = container.getLayoutTransition();
+
+ // New capability as of Jellybean; monitor the container for *all* layout changes
+ // (not just add/remove/visibility changes) and animate these changes as well.
+ transition.enableTransitionType(LayoutTransition.CHANGING);
+ }
+
+ /**
+ * Custom view painted with a random background color and two different sizes which are
+ * toggled between due to user interaction.
+ */
+ private static class ColoredView extends View {
+
+ private boolean mExpanded = false;
+
+ private LayoutParams mCompressedParams = new LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT, 50);
+
+ private LayoutParams mExpandedParams = new LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT, 200);
+
+ private ColoredView(Context context) {
+ super(context);
+ int red = (int)(Math.random() * 128 + 127);
+ int green = (int)(Math.random() * 128 + 127);
+ int blue = (int)(Math.random() * 128 + 127);
+ int color = 0xff << 24 | (red << 16) |
+ (green << 8) | blue;
+ setBackgroundColor(color);
+ setLayoutParams(mCompressedParams);
+ setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ // Size changes will cause a LayoutTransition animation if the CHANGING
+ // transition is enabled
+ setLayoutParams(mExpanded ? mCompressedParams : mExpandedParams);
+ mExpanded = !mExpanded;
+ requestLayout();
+ }
+ });
+ }
+ }
+}