summaryrefslogtreecommitdiffstats
path: root/tests/RenderThreadTest/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/RenderThreadTest/src')
-rw-r--r--tests/RenderThreadTest/src/com/example/renderthread/MainActivity.java95
-rw-r--r--tests/RenderThreadTest/src/com/example/renderthread/SubActivity.java60
2 files changed, 155 insertions, 0 deletions
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..1d209dd
--- /dev/null
+++ b/tests/RenderThreadTest/src/com/example/renderthread/MainActivity.java
@@ -0,0 +1,95 @@
+
+package com.example.renderthread;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+import android.view.HardwareRenderer;
+import android.view.RenderNodeAnimator;
+import android.view.View;
+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 TRANSLATION_Y = 1;
+ static final int DELTA_TYPE_DELTA = 1;
+ 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);
+ }
+ }
+
+ @Override
+ public void onItemClick(final AdapterView<?> adapterView, View clickedView,
+ int clickedPosition, long clickedId) {
+ int topPosition = adapterView.getFirstVisiblePosition();
+ int dy = adapterView.getHeight();
+ 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;
+ RenderNodeAnimator animator = new RenderNodeAnimator(
+ TRANSLATION_Y, DELTA_TYPE_DELTA, dy * delta);
+ animator.setDuration(DURATION);
+ animator.start(child);
+ }
+ //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);
+ }
+}