diff options
author | John Reck <jreck@google.com> | 2013-11-05 13:27:50 -0800 |
---|---|---|
committer | John Reck <jreck@google.com> | 2013-12-09 15:57:09 -0800 |
commit | cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fc (patch) | |
tree | 9b2287a705b0634197262c13433f5c32aa848bdc /tests | |
parent | 4598ea4e5e6b2accce5165a76f5e2d04ce46c74c (diff) | |
download | frameworks_base-cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fc.zip frameworks_base-cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fc.tar.gz frameworks_base-cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fc.tar.bz2 |
RenderThread work
Hacky prototype needs a private API to enable
Change-Id: I21e0ddf3cdbd38a4036354b5d6012449e1a34849
Diffstat (limited to 'tests')
-rw-r--r-- | tests/RenderThreadTest/Android.mk | 18 | ||||
-rw-r--r-- | tests/RenderThreadTest/AndroidManifest.xml | 29 | ||||
-rw-r--r-- | tests/RenderThreadTest/res/drawable-hdpi/ic_launcher.png | bin | 0 -> 9397 bytes | |||
-rw-r--r-- | tests/RenderThreadTest/res/drawable-mdpi/ic_launcher.png | bin | 0 -> 5237 bytes | |||
-rw-r--r-- | tests/RenderThreadTest/res/drawable-xhdpi/ic_launcher.png | bin | 0 -> 14383 bytes | |||
-rw-r--r-- | tests/RenderThreadTest/res/drawable-xhdpi/starry_night_bg.jpg | bin | 0 -> 561519 bytes | |||
-rw-r--r-- | tests/RenderThreadTest/res/layout/activity_main.xml | 12 | ||||
-rw-r--r-- | tests/RenderThreadTest/res/layout/activity_sub.xml | 39 | ||||
-rw-r--r-- | tests/RenderThreadTest/res/layout/item_layout.xml | 12 | ||||
-rw-r--r-- | tests/RenderThreadTest/res/values/strings.xml | 8 | ||||
-rw-r--r-- | tests/RenderThreadTest/res/values/styles.xml | 11 | ||||
-rw-r--r-- | tests/RenderThreadTest/src/com/example/renderthread/MainActivity.java | 158 | ||||
-rw-r--r-- | tests/RenderThreadTest/src/com/example/renderthread/SubActivity.java | 60 |
13 files changed, 347 insertions, 0 deletions
diff --git a/tests/RenderThreadTest/Android.mk b/tests/RenderThreadTest/Android.mk new file mode 100644 index 0000000..bdcba2e --- /dev/null +++ b/tests/RenderThreadTest/Android.mk @@ -0,0 +1,18 @@ +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 := RenderThreadTest + +LOCAL_STATIC_JAVA_LIBRARIES += android-common + +LOCAL_PROGUARD_ENABLED := disabled + +include $(BUILD_PACKAGE) + +# Use the following include to make our test apk. +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/tests/RenderThreadTest/AndroidManifest.xml b/tests/RenderThreadTest/AndroidManifest.xml new file mode 100644 index 0000000..c76cfce --- /dev/null +++ b/tests/RenderThreadTest/AndroidManifest.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.example.renderthread" + android:versionCode="1" + android:versionName="1.0" > + + <uses-sdk + android:minSdkVersion="18" + android:targetSdkVersion="18" /> + + <application + android:allowBackup="true" + android:icon="@drawable/ic_launcher" + android:label="@string/app_name" + android:theme="@style/AppTheme" > + <activity + android:name=".MainActivity" + android:label="@string/app_name" > + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + <activity android:name=".SubActivity" + android:theme="@style/AppTheme.Transparent" /> + </application> + +</manifest> diff --git a/tests/RenderThreadTest/res/drawable-hdpi/ic_launcher.png b/tests/RenderThreadTest/res/drawable-hdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..96a442e --- /dev/null +++ b/tests/RenderThreadTest/res/drawable-hdpi/ic_launcher.png diff --git a/tests/RenderThreadTest/res/drawable-mdpi/ic_launcher.png b/tests/RenderThreadTest/res/drawable-mdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..359047d --- /dev/null +++ b/tests/RenderThreadTest/res/drawable-mdpi/ic_launcher.png diff --git a/tests/RenderThreadTest/res/drawable-xhdpi/ic_launcher.png b/tests/RenderThreadTest/res/drawable-xhdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..71c6d76 --- /dev/null +++ b/tests/RenderThreadTest/res/drawable-xhdpi/ic_launcher.png diff --git a/tests/RenderThreadTest/res/drawable-xhdpi/starry_night_bg.jpg b/tests/RenderThreadTest/res/drawable-xhdpi/starry_night_bg.jpg Binary files differnew file mode 100644 index 0000000..755232d --- /dev/null +++ b/tests/RenderThreadTest/res/drawable-xhdpi/starry_night_bg.jpg diff --git a/tests/RenderThreadTest/res/layout/activity_main.xml b/tests/RenderThreadTest/res/layout/activity_main.xml new file mode 100644 index 0000000..1fd5459 --- /dev/null +++ b/tests/RenderThreadTest/res/layout/activity_main.xml @@ -0,0 +1,12 @@ +<FrameLayout 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" + tools:context=".MainActivity" > + + <ListView android:id="@android:id/list" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:divider="@null" /> + +</FrameLayout> diff --git a/tests/RenderThreadTest/res/layout/activity_sub.xml b/tests/RenderThreadTest/res/layout/activity_sub.xml new file mode 100644 index 0000000..713cee4 --- /dev/null +++ b/tests/RenderThreadTest/res/layout/activity_sub.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="utf-8"?> +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" > + + <View + android:id="@+id/bg_container" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@drawable/starry_night_bg" /> + + <LinearLayout + android:id="@+id/my_container" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" > + + <View + android:id="@+id/from_left" + android:layout_width="match_parent" + android:layout_height="48dip" + android:background="#7000FF00" /> + + <View + android:id="@+id/from_right" + android:layout_width="match_parent" + android:layout_height="0dip" + android:layout_margin="80dip" + android:layout_weight="1" + android:background="#90FF0000" /> + + <View + android:id="@+id/from_left" + android:layout_width="match_parent" + android:layout_height="48dip" + android:background="#7000FF00" /> + </LinearLayout> + +</FrameLayout>
\ No newline at end of file diff --git a/tests/RenderThreadTest/res/layout/item_layout.xml b/tests/RenderThreadTest/res/layout/item_layout.xml new file mode 100644 index 0000000..5bdb1ac --- /dev/null +++ b/tests/RenderThreadTest/res/layout/item_layout.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8"?> +<TextView xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@android:id/text1" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textAppearance="?android:attr/textAppearanceListItemSmall" + android:gravity="center_vertical" + android:paddingStart="?android:attr/listPreferredItemPaddingStart" + android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" + android:minHeight="?android:attr/listPreferredItemHeightSmall" + android:background="#33b5e5" +/>
\ No newline at end of file diff --git a/tests/RenderThreadTest/res/values/strings.xml b/tests/RenderThreadTest/res/values/strings.xml new file mode 100644 index 0000000..f782e98 --- /dev/null +++ b/tests/RenderThreadTest/res/values/strings.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + + <string name="app_name">Render Thread</string> + <string name="action_settings">Settings</string> + <string name="hello_world">Hello world!</string> + +</resources> diff --git a/tests/RenderThreadTest/res/values/styles.xml b/tests/RenderThreadTest/res/values/styles.xml new file mode 100644 index 0000000..f6b5d6a --- /dev/null +++ b/tests/RenderThreadTest/res/values/styles.xml @@ -0,0 +1,11 @@ +<resources> + <!-- Application theme. --> + <style name="AppTheme" parent="android:Theme.Holo.Light"> + </style> + + <style name="AppTheme.Transparent"> + <item name="android:windowIsTranslucent">true</item> + <item name="android:windowBackground">@android:color/transparent</item> + </style> + +</resources> diff --git a/tests/RenderThreadTest/src/com/example/renderthread/MainActivity.java b/tests/RenderThreadTest/src/com/example/renderthread/MainActivity.java new file mode 100644 index 0000000..a39aba8 --- /dev/null +++ b/tests/RenderThreadTest/src/com/example/renderthread/MainActivity.java @@ -0,0 +1,158 @@ + +package com.example.renderthread; + +import android.animation.TimeInterpolator; +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; +import android.os.SystemClock; +import android.view.DisplayList; +import android.view.HardwareRenderer; +import android.view.ThreadedRenderer; +import android.view.View; +import android.view.animation.AccelerateDecelerateInterpolator; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; +import android.widget.ListView; +import android.widget.SimpleAdapter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +public class MainActivity extends Activity implements OnItemClickListener { + + static final int DURATION = 400; + + static final String KEY_NAME = "name"; + static final String KEY_CLASS = "clazz"; + + static Map<String,?> make(String name) { + Map<String,Object> ret = new HashMap<String,Object>(); + ret.put(KEY_NAME, name); + return ret; + } + + @SuppressWarnings("serial") + static final ArrayList<Map<String,?>> SAMPLES = new ArrayList<Map<String,?>>() {{ + for (int i = 1; i < 25; i++) { + add(make("List Item: " + i)); + } + }}; + + Handler mHandler = new Handler(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + HardwareRenderer.sUseRenderThread = true; + setContentView(R.layout.activity_main); + ListView lv = (ListView) findViewById(android.R.id.list); + lv.setDrawSelectorOnTop(true); + lv.setAdapter(new SimpleAdapter(this, SAMPLES, + R.layout.item_layout, new String[] { KEY_NAME }, + new int[] { android.R.id.text1 })); + lv.setOnItemClickListener(this); + getActionBar().setTitle("MainActivity"); + } + + @Override + protected void onResume() { + super.onResume(); + ListView lv = (ListView) findViewById(android.R.id.list); + for (int i = 0; i < lv.getChildCount(); i++) { + lv.getChildAt(i).animate().translationY(0).setDuration(DURATION); + } + } + + private static class DisplayListAnimator { + private static final TimeInterpolator sDefaultInterpolator = + new AccelerateDecelerateInterpolator(); + + DisplayList mDisplayList; + float mFromValue; + float mDelta; + long mDuration = DURATION * 2; + long mStartTime; + + DisplayListAnimator(View view, float translateXBy) { + mDelta = translateXBy; + mFromValue = view.getTranslationY(); + mDisplayList = view.getDisplayList(); + } + + boolean animate(long currentTime) { + if (mStartTime == 0) mStartTime = currentTime; + + float fraction = (float)(currentTime - mStartTime) / mDuration; + if (fraction > 1) { + return false; + } + fraction = sDefaultInterpolator.getInterpolation(fraction); + float translation = mFromValue + (mDelta * fraction); + mDisplayList.setTranslationY(translation); + return fraction < 1f; + } + } + + private static class AnimationExecutor implements Runnable { + DisplayListAnimator[] mAnimations; + ThreadedRenderer mRenderer; + + AnimationExecutor(ThreadedRenderer renderer, DisplayListAnimator[] animations) { + mRenderer = renderer; + mAnimations = animations; + ThreadedRenderer.postToRenderThread(this); + } + + @Override + public void run() { + boolean hasMore = false; + long now = SystemClock.uptimeMillis(); + for (DisplayListAnimator animator : mAnimations) { + hasMore |= animator.animate(now); + } + mRenderer.repeatLastDraw(); + if (hasMore) { + ThreadedRenderer.postToRenderThread(this); + } + } + + } + + @Override + public void onItemClick(final AdapterView<?> adapterView, View clickedView, + int clickedPosition, long clickedId) { + int topPosition = adapterView.getFirstVisiblePosition(); + int dy = adapterView.getHeight(); + final DisplayListAnimator[] animators = new DisplayListAnimator[adapterView.getChildCount()]; + for (int i = 0; i < adapterView.getChildCount(); i++) { + int pos = topPosition + i; + View child = adapterView.getChildAt(i); + float delta = (pos - clickedPosition) * 1.1f; + if (delta == 0) delta = -1; + animators[i] = new DisplayListAnimator(child, dy * delta); + } + adapterView.invalidate(); + adapterView.post(new Runnable() { + + @Override + public void run() { + new AnimationExecutor((ThreadedRenderer) adapterView.getHardwareRenderer(), animators); + } + }); + //mHandler.postDelayed(mLaunchActivity, (long) (DURATION * .4)); + mLaunchActivity.run(); + } + + private Runnable mLaunchActivity = new Runnable() { + + @Override + public void run() { + startActivity(new Intent(MainActivity.this, SubActivity.class)); + overridePendingTransition(0, 0); + } + }; + +} diff --git a/tests/RenderThreadTest/src/com/example/renderthread/SubActivity.java b/tests/RenderThreadTest/src/com/example/renderthread/SubActivity.java new file mode 100644 index 0000000..892cbae --- /dev/null +++ b/tests/RenderThreadTest/src/com/example/renderthread/SubActivity.java @@ -0,0 +1,60 @@ +/* + * 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.renderthread; + +import android.app.Activity; +import android.os.Bundle; +import android.os.Process; +import android.os.SystemClock; +import android.view.View; +import android.view.ViewGroup; + +public class SubActivity extends Activity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + long before = SystemClock.currentThreadTimeMillis(); + setContentView(R.layout.activity_sub); + getActionBar().setTitle("SubActivity"); + // Simulate being a real app! + while (SystemClock.currentThreadTimeMillis() - before < 100) { + View v = new View(this, null); + } + } + + @Override + protected void onResume() { + super.onResume(); + ViewGroup container = (ViewGroup) findViewById(R.id.my_container); + int dx = getWindowManager().getDefaultDisplay().getWidth(); + for (int i = 0; i < container.getChildCount(); i++) { + View child = container.getChildAt(i); + int dir = child.getId() == R.id.from_left ? 1 : -1; + child.setTranslationX(dx * dir); + child.animate().translationX(0).setDuration(MainActivity.DURATION); + } + View bg = findViewById(R.id.bg_container); + bg.setAlpha(0f); + bg.animate().alpha(1f).setDuration(MainActivity.DURATION); + } + + @Override + public void onBackPressed() { + super.onBackPressed(); + overridePendingTransition(0, 0); + } +} |