diff options
author | ztenghui <ztenghui@google.com> | 2014-04-02 16:35:24 -0700 |
---|---|---|
committer | ztenghui <ztenghui@google.com> | 2014-04-02 17:31:08 -0700 |
commit | fba3bad3870d607ecaed4f147788885c841c2ab3 (patch) | |
tree | 467f9a781557d1fd25f5a5acb8e281dd7db689a0 /tests/VectorDrawableTest/src | |
parent | 1970f570714a4746bf592e26731ea0ee8933d363 (diff) | |
download | frameworks_base-fba3bad3870d607ecaed4f147788885c841c2ab3.zip frameworks_base-fba3bad3870d607ecaed4f147788885c841c2ab3.tar.gz frameworks_base-fba3bad3870d607ecaed4f147788885c841c2ab3.tar.bz2 |
Clean up on VectorDrawable.
Rename the test from DynamicDrawableTest to VectorDrawableTest.
Remove duplicate function calls in the test.
Fix comments in VectorDrawable
Change-Id: I1ef87137088ccc10b1abdb40ca368345d9dbadab
Diffstat (limited to 'tests/VectorDrawableTest/src')
7 files changed, 506 insertions, 0 deletions
diff --git a/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorCheckbox.java b/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorCheckbox.java new file mode 100644 index 0000000..0b3ea4d --- /dev/null +++ b/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorCheckbox.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2014 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.dynamic; + +import android.app.Activity; +import android.graphics.drawable.VectorDrawable; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.GridLayout; + +@SuppressWarnings({"UnusedDeclaration"}) +public class VectorCheckbox extends Activity { + private static final String LOGCAT = "VectorDrawable1"; + int[] icon = { + R.drawable.vector_drawable01, + R.drawable.vector_drawable02, + R.drawable.vector_drawable03, + R.drawable.vector_drawable04, + R.drawable.vector_drawable05, + R.drawable.vector_drawable06, + R.drawable.vector_drawable07, + R.drawable.vector_drawable08, + R.drawable.vector_drawable09, + R.drawable.vector_drawable10, + R.drawable.vector_drawable11, + R.drawable.vector_drawable12, + R.drawable.vector_drawable13, + R.drawable.vector_drawable14, + R.drawable.vector_drawable15, + R.drawable.vector_drawable16, + R.drawable.vector_drawable17, + R.drawable.vector_drawable18, + R.drawable.vector_drawable19, + R.drawable.vector_drawable20 + }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + GridLayout container = new GridLayout(this); + container.setColumnCount(5); + container.setBackgroundColor(0xFF888888); + final Button []bArray = new Button[icon.length]; + + for (int i = 0; i < icon.length; i++) { + CheckBox checkBox = new CheckBox(this); + bArray[i] = checkBox; + checkBox.setWidth(200); + checkBox.setButtonDrawable(icon[i]); + container.addView(checkBox); + } + setContentView(container); + } +} diff --git a/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawable01.java b/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawable01.java new file mode 100644 index 0000000..88ae398 --- /dev/null +++ b/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawable01.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2014 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.dynamic; + +import android.app.Activity; +import android.graphics.drawable.VectorDrawable; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.GridLayout; + +@SuppressWarnings({"UnusedDeclaration"}) +public class VectorDrawable01 extends Activity implements View.OnClickListener { + private static final String LOGCAT = "VectorDrawable1"; + int[] icon = { + R.drawable.vector_drawable01, + R.drawable.vector_drawable02, + R.drawable.vector_drawable03, + R.drawable.vector_drawable04, + R.drawable.vector_drawable05, + R.drawable.vector_drawable06, + R.drawable.vector_drawable07, + R.drawable.vector_drawable08, + R.drawable.vector_drawable09, + R.drawable.vector_drawable10, + R.drawable.vector_drawable11, + R.drawable.vector_drawable12, + R.drawable.vector_drawable13, + R.drawable.vector_drawable14, + R.drawable.vector_drawable15, + R.drawable.vector_drawable16, + R.drawable.vector_drawable17, + R.drawable.vector_drawable18, + R.drawable.vector_drawable19, + R.drawable.vector_drawable20 + }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + GridLayout container = new GridLayout(this); + container.setColumnCount(5); + container.setBackgroundColor(0xFF888888); + final Button []bArray = new Button[icon.length]; + + for (int i = 0; i < icon.length; i++) { + Button button = new Button(this); + bArray[i] = button; + button.setWidth(200); + button.setBackgroundResource(icon[i]); + container.addView(button); + button.setOnClickListener(this); + } + Button b = new Button(this); + b.setText("Run All"); + b.setOnClickListener(new View.OnClickListener(){ + + @Override + public void onClick(View v) { + for (int i = 0; i < bArray.length; i++) { + VectorDrawable d = (VectorDrawable) bArray[i].getBackground(); + d.start(); + } + }}); + container.addView(b); + setContentView(container); + + } + + @Override + public void onClick(View v) { + VectorDrawable d = (VectorDrawable) v.getBackground(); + d.start(); + } + +} diff --git a/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawableDupPerf.java b/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawableDupPerf.java new file mode 100644 index 0000000..a00bc5e --- /dev/null +++ b/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawableDupPerf.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2014 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.dynamic; + + +@SuppressWarnings({"UnusedDeclaration"}) +public class VectorDrawableDupPerf extends VectorDrawablePerformance { + { + icon = new int[]{ + R.drawable.vector_drawable04, + R.drawable.vector_drawable04, + R.drawable.vector_drawable04, + R.drawable.vector_drawable04, + R.drawable.vector_drawable04, + R.drawable.vector_drawable04, + R.drawable.vector_drawable04, + R.drawable.vector_drawable04, + R.drawable.vector_drawable04, + R.drawable.vector_drawable04, + R.drawable.vector_drawable04, + R.drawable.vector_drawable04, + R.drawable.vector_drawable04, + R.drawable.vector_drawable04, + R.drawable.vector_drawable04, + R.drawable.vector_drawable04, + R.drawable.vector_drawable04, + R.drawable.vector_drawable04, + R.drawable.vector_drawable04, + R.drawable.vector_drawable04, + }; + } +} diff --git a/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawablePerformance.java b/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawablePerformance.java new file mode 100644 index 0000000..3929298 --- /dev/null +++ b/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawablePerformance.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2014 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.dynamic; + +import android.app.Activity; +import android.content.res.Resources; +import android.graphics.drawable.VectorDrawable; +import android.os.Bundle; +import android.view.View; +import android.widget.TextView; +import android.widget.Button; +import android.widget.GridLayout; +import android.widget.ScrollView; +import java.text.DecimalFormat; + +@SuppressWarnings({"UnusedDeclaration"}) +public class VectorDrawablePerformance extends Activity implements View.OnClickListener { + private static final String LOGCAT = "VectorDrawable1"; + protected int[] icon = { + R.drawable.vector_drawable01, + R.drawable.vector_drawable02, + R.drawable.vector_drawable03, + R.drawable.vector_drawable04, + R.drawable.vector_drawable05, + R.drawable.vector_drawable06, + R.drawable.vector_drawable07, + R.drawable.vector_drawable08, + R.drawable.vector_drawable09, + R.drawable.vector_drawable10, + R.drawable.vector_drawable11, + R.drawable.vector_drawable12, + R.drawable.vector_drawable13, + R.drawable.vector_drawable14, + R.drawable.vector_drawable15, + R.drawable.vector_drawable16, + R.drawable.vector_drawable17, + R.drawable.vector_drawable18, + R.drawable.vector_drawable19, + R.drawable.vector_drawable20 + }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + ScrollView scrollView = new ScrollView(this); + GridLayout container = new GridLayout(this); + scrollView.addView(container); + container.setColumnCount(5); + Resources res = this.getResources(); + container.setBackgroundColor(0xFF888888); + VectorDrawable []d = new VectorDrawable[icon.length]; + long time = android.os.SystemClock.elapsedRealtimeNanos(); + for (int i = 0; i < icon.length; i++) { + d[i] = VectorDrawable.create(res,icon[i]); + } + time = android.os.SystemClock.elapsedRealtimeNanos()-time; + TextView t = new TextView(this); + DecimalFormat df = new DecimalFormat("#.##"); + t.setText("avgL=" + df.format(time / (icon.length * 1000000.)) + " ms"); + t.setBackgroundColor(0xFF000000); + container.addView(t); + time = android.os.SystemClock.elapsedRealtimeNanos(); + for (int i = 0; i < icon.length; i++) { + Button button = new Button(this); + button.setWidth(200); + button.setBackgroundResource(icon[i]); + container.addView(button); + button.setOnClickListener(this); + } + setContentView(scrollView); + time = android.os.SystemClock.elapsedRealtimeNanos()-time; + t = new TextView(this); + t.setText("avgS=" + df.format(time / (icon.length * 1000000.)) + " ms"); + t.setBackgroundColor(0xFF000000); + container.addView(t); + } + + @Override + public void onClick(View v) { + VectorDrawable d = (VectorDrawable) v.getBackground(); + d.start(); + } +} diff --git a/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawableStaticPerf.java b/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawableStaticPerf.java new file mode 100644 index 0000000..9d3eded --- /dev/null +++ b/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawableStaticPerf.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 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.dynamic; + +import android.app.Activity; +import android.content.res.Resources; +import android.graphics.drawable.VectorDrawable; +import android.os.Bundle; +import android.view.View; +import android.widget.TextView; +import android.widget.Button; +import android.widget.GridLayout; + +@SuppressWarnings({"UnusedDeclaration"}) +public class VectorDrawableStaticPerf extends VectorDrawablePerformance { + { + icon = new int[]{ + R.drawable.vector_icon_create, + R.drawable.vector_icon_delete, + R.drawable.vector_icon_heart, + R.drawable.vector_icon_schedule, + R.drawable.vector_icon_settings, + }; + } +} diff --git a/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawableTest.java b/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawableTest.java new file mode 100644 index 0000000..704d3d7 --- /dev/null +++ b/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorDrawableTest.java @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2014 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.dynamic; + +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 VectorDrawableTest extends android.app.ListActivity { + private static final String EXTRA_PATH = "com.android.test.dynamic.Path"; + private static final String CATEGORY_HWUI_TEST = "com.android.test.dynamic.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, VectorDrawableTest.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); + } +} diff --git a/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorPathChecking.java b/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorPathChecking.java new file mode 100644 index 0000000..3430192 --- /dev/null +++ b/tests/VectorDrawableTest/src/com/android/test/dynamic/VectorPathChecking.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2014 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.dynamic; + + +@SuppressWarnings({"UnusedDeclaration"}) +public class VectorPathChecking extends VectorDrawablePerformance { + { + icon = new int[]{ + R.drawable.vector_test01, + R.drawable.vector_test02 + }; + } +} |