diff options
author | Romain Guy <romainguy@google.com> | 2013-02-28 13:08:34 -0800 |
---|---|---|
committer | Romain Guy <romainguy@google.com> | 2013-02-28 13:08:34 -0800 |
commit | 29ce8c98ff1cd2fdf6ccc5127aab466d52367b61 (patch) | |
tree | c876567e7ed63c3a9b54da9108c3538c6c7ac449 /tests/HwAccelerationTest/src | |
parent | 19886f8b5109218191908d2ce5faf0293f85cf31 (diff) | |
download | frameworks_base-29ce8c98ff1cd2fdf6ccc5127aab466d52367b61.zip frameworks_base-29ce8c98ff1cd2fdf6ccc5127aab466d52367b61.tar.gz frameworks_base-29ce8c98ff1cd2fdf6ccc5127aab466d52367b61.tar.bz2 |
Reorganize OpenGL renderer tests
The new UI works just like ApiDemos. The label of the activities
declared in the manifest defines where they go in the UI.
For instance Draw/Circles will create an entry called Draw in the
first screen of the test app. Click the "Draw" item will launch
a new activity containing an item called "Circles".
Change-Id: I98a4442ee3d992598af440b2078ae1925214da20
Diffstat (limited to 'tests/HwAccelerationTest/src')
-rw-r--r-- | tests/HwAccelerationTest/src/com/android/test/hwui/HwTests.java | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/HwTests.java b/tests/HwAccelerationTest/src/com/android/test/hwui/HwTests.java new file mode 100644 index 0000000..b1c32a8 --- /dev/null +++ b/tests/HwAccelerationTest/src/com/android/test/hwui/HwTests.java @@ -0,0 +1,153 @@ +/* + * 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.test.hwui; + +import android.app.*; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.os.Bundle; +import android.view.View; +import android.widget.ListView; +import android.widget.SimpleAdapter; + +import java.text.Collator; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@SuppressWarnings("UnusedDeclaration") +public class HwTests extends android.app.ListActivity { + private static final String EXTRA_PATH = "com.android.test.hwui.Path"; + private static final String CATEGORY_HWUI_TEST = "com.android.test.hwui.TEST"; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + Intent intent = getIntent(); + String path = intent.getStringExtra("com.android.test.hwui.Path"); + + if (path == null) { + path = ""; + } + + setListAdapter(new SimpleAdapter(this, getData(path), + android.R.layout.simple_list_item_1, new String[] { "title" }, + new int[] { android.R.id.text1 })); + getListView().setTextFilterEnabled(true); + } + + protected List<Map<String, Object>> getData(String prefix) { + List<Map<String, Object>> myData = new ArrayList<Map<String, Object>>(); + + Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); + mainIntent.addCategory(CATEGORY_HWUI_TEST); + + PackageManager pm = getPackageManager(); + List<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0); + + if (null == list) + return myData; + + String[] prefixPath; + String prefixWithSlash = prefix; + + if (prefix.equals("")) { + prefixPath = null; + } else { + prefixPath = prefix.split("/"); + prefixWithSlash = prefix + "/"; + } + + int len = list.size(); + + Map<String, Boolean> entries = new HashMap<String, Boolean>(); + + for (int i = 0; i < len; i++) { + ResolveInfo info = list.get(i); + CharSequence labelSeq = info.loadLabel(pm); + String label = labelSeq != null + ? labelSeq.toString() + : info.activityInfo.name; + + if (prefixWithSlash.length() == 0 || label.startsWith(prefixWithSlash)) { + + String[] labelPath = label.split("/"); + + String nextLabel = prefixPath == null ? labelPath[0] : labelPath[prefixPath.length]; + + if ((prefixPath != null ? prefixPath.length : 0) == labelPath.length - 1) { + addItem(myData, nextLabel, activityIntent( + info.activityInfo.applicationInfo.packageName, + info.activityInfo.name)); + } else { + if (entries.get(nextLabel) == null) { + addItem(myData, nextLabel, browseIntent(prefix.equals("") ? + nextLabel : prefix + "/" + nextLabel)); + entries.put(nextLabel, true); + } + } + } + } + + Collections.sort(myData, sDisplayNameComparator); + + return myData; + } + + private final static Comparator<Map<String, Object>> sDisplayNameComparator = + new Comparator<Map<String, Object>>() { + private final Collator collator = Collator.getInstance(); + + public int compare(Map<String, Object> map1, Map<String, Object> map2) { + return collator.compare(map1.get("title"), map2.get("title")); + } + }; + + protected Intent activityIntent(String pkg, String componentName) { + Intent result = new Intent(); + result.setClassName(pkg, componentName); + return result; + } + + protected Intent browseIntent(String path) { + Intent result = new Intent(); + result.setClass(this, HwTests.class); + result.putExtra(EXTRA_PATH, path); + return result; + } + + protected void addItem(List<Map<String, Object>> data, String name, Intent intent) { + Map<String, Object> temp = new HashMap<String, Object>(); + temp.put("title", name); + temp.put("intent", intent); + data.add(temp); + } + + @Override + @SuppressWarnings({ "unchecked", "UnusedParameters" }) + protected void onListItemClick(ListView l, View v, int position, long id) { + Map<String, Object> map = (Map<String, Object>)l.getItemAtPosition(position); + + Intent intent = (Intent) map.get("intent"); + startActivity(intent); + } +} |