diff options
author | Md Haque <haque@google.com> | 2015-09-01 12:00:34 -0700 |
---|---|---|
committer | Chris Craik <ccraik@google.com> | 2015-09-14 11:28:15 -0700 |
commit | d68e8cb51bc41bdc7567ddcee92fb80d9b47204e (patch) | |
tree | 772452423bc7f69182bb0f95b37e5ed59ac995ee | |
parent | a05ee0435e541f8c9ae89485d1c6a22e38da6a04 (diff) |
Adding recyclerview and activity transition to UiBench
Change-Id: Ief31c6ed7f6b798893256f79b41e8a6ccbc3f3c7
25 files changed, 547 insertions, 7 deletions
diff --git a/tests/UiBench/Android.mk b/tests/UiBench/Android.mk index 24df85b1841f..0e678cde9c70 100644 --- a/tests/UiBench/Android.mk +++ b/tests/UiBench/Android.mk @@ -11,17 +11,20 @@ LOCAL_SRC_FILES := $(call all-java-files-under,src) LOCAL_RESOURCE_DIR := \ $(LOCAL_PATH)/res \ frameworks/support/v7/appcompat/res \ - frameworks/support/v7/cardview/res + frameworks/support/v7/cardview/res \ + frameworks/support/v7/recyclerview/res LOCAL_AAPT_FLAGS := \ --auto-add-overlay \ --extra-packages android.support.v7.appcompat \ - --extra-packages android.support.v7.cardview + --extra-packages android.support.v7.cardview \ + --extra-packages android.support.v7.recyclerview LOCAL_STATIC_JAVA_LIBRARIES := \ android-support-v4 \ android-support-v7-appcompat \ - android-support-v7-cardview + android-support-v7-cardview \ + android-support-v7-recyclerview LOCAL_PACKAGE_NAME := UiBench diff --git a/tests/UiBench/AndroidManifest.xml b/tests/UiBench/AndroidManifest.xml index 9b3d18668aa9..7b4f01cad849 100644 --- a/tests/UiBench/AndroidManifest.xml +++ b/tests/UiBench/AndroidManifest.xml @@ -83,6 +83,30 @@ <category android:name="com.android.test.uibench.TEST" /> </intent-filter> </activity> + <activity + android:name=".TrivialRecyclerViewActivity" + android:label="General/Trivial Recycler ListView" > + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="com.android.test.uibench.TEST" /> + </intent-filter> + </activity> + <activity + android:name=".ActivityTransition" + android:label="Transitions/Activity Transition" > + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="com.android.test.uibench.TEST" /> + </intent-filter> + </activity> + <activity + android:name=".ActivityTransitionDetails" + android:label="Transitions/Activity Transition " > + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <!-- Part of ActivityTransition test above, so not in TEST category --> + </intent-filter> + </activity> <!-- Rendering --> <activity diff --git a/tests/UiBench/build.gradle b/tests/UiBench/build.gradle index deecbb6392d1..0756a8aac878 100644 --- a/tests/UiBench/build.gradle +++ b/tests/UiBench/build.gradle @@ -32,7 +32,8 @@ android { dependencies { // Dependencies enumerated specifically for platform-independent / reproducible builds. - compile 'com.android.support:support-v4:23.0.0' - compile 'com.android.support:appcompat-v7:23.0.0' - compile 'com.android.support:cardview-v7:23.0.0' + compile 'com.android.support:support-v4:23.0.1' + compile 'com.android.support:appcompat-v7:23.0.1' + compile 'com.android.support:cardview-v7:23.0.1' + compile 'com.android.support:recyclerview-v7:23.0.1' } diff --git a/tests/UiBench/res/drawable-nodpi/ball.jpg b/tests/UiBench/res/drawable-nodpi/ball.jpg Binary files differnew file mode 100644 index 000000000000..2960b7309f6e --- /dev/null +++ b/tests/UiBench/res/drawable-nodpi/ball.jpg diff --git a/tests/UiBench/res/drawable-nodpi/block.jpg b/tests/UiBench/res/drawable-nodpi/block.jpg Binary files differnew file mode 100644 index 000000000000..04c22a0cf5b4 --- /dev/null +++ b/tests/UiBench/res/drawable-nodpi/block.jpg diff --git a/tests/UiBench/res/drawable-nodpi/ducky.jpg b/tests/UiBench/res/drawable-nodpi/ducky.jpg Binary files differnew file mode 100644 index 000000000000..830bbe347e47 --- /dev/null +++ b/tests/UiBench/res/drawable-nodpi/ducky.jpg diff --git a/tests/UiBench/res/drawable-nodpi/frantic.jpg b/tests/UiBench/res/drawable-nodpi/frantic.jpg Binary files differnew file mode 100644 index 000000000000..4c623336e15b --- /dev/null +++ b/tests/UiBench/res/drawable-nodpi/frantic.jpg diff --git a/tests/UiBench/res/drawable-nodpi/jellies.jpg b/tests/UiBench/res/drawable-nodpi/jellies.jpg Binary files differnew file mode 100644 index 000000000000..ee2b5c68c43b --- /dev/null +++ b/tests/UiBench/res/drawable-nodpi/jellies.jpg diff --git a/tests/UiBench/res/drawable-nodpi/mug.jpg b/tests/UiBench/res/drawable-nodpi/mug.jpg Binary files differnew file mode 100644 index 000000000000..e149e198a9cd --- /dev/null +++ b/tests/UiBench/res/drawable-nodpi/mug.jpg diff --git a/tests/UiBench/res/drawable-nodpi/pencil.jpg b/tests/UiBench/res/drawable-nodpi/pencil.jpg Binary files differnew file mode 100644 index 000000000000..e348311bf4d0 --- /dev/null +++ b/tests/UiBench/res/drawable-nodpi/pencil.jpg diff --git a/tests/UiBench/res/drawable-nodpi/scissors.jpg b/tests/UiBench/res/drawable-nodpi/scissors.jpg Binary files differnew file mode 100644 index 000000000000..caf0ce8e2f4b --- /dev/null +++ b/tests/UiBench/res/drawable-nodpi/scissors.jpg diff --git a/tests/UiBench/res/drawable-nodpi/woot.jpg b/tests/UiBench/res/drawable-nodpi/woot.jpg Binary files differnew file mode 100644 index 000000000000..ccaef674b1a5 --- /dev/null +++ b/tests/UiBench/res/drawable-nodpi/woot.jpg diff --git a/tests/UiBench/res/layout/activity_transition.xml b/tests/UiBench/res/layout/activity_transition.xml new file mode 100644 index 000000000000..d4c661027a35 --- /dev/null +++ b/tests/UiBench/res/layout/activity_transition.xml @@ -0,0 +1,103 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2015 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 + --> +<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:clipChildren="true" + android:columnCount="2" + android:rowCount="4"> + <ImageView + android:id="@+id/ducky" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:scaleType="centerCrop" + android:layout_column="0" + android:layout_row="0" + android:src="@drawable/ducky" + android:onClick="clicked" + android:transitionName="ducky"/> + <ImageView + android:id="@+id/woot" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:scaleType="centerCrop" + android:src="@drawable/woot" + android:layout_column="1" + android:layout_row="0" + android:onClick="clicked" + android:transitionName="woot"/> + <ImageView + android:id="@+id/ball" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:scaleType="centerCrop" + android:src="@drawable/ball" + android:layout_column="0" + android:layout_row="1" + android:onClick="clicked" + android:transitionName="ball"/> + <ImageView + android:id="@+id/block" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:scaleType="centerCrop" + android:src="@drawable/block" + android:layout_column="1" + android:layout_row="1" + android:onClick="clicked" + android:transitionName="block"/> + <ImageView + android:id="@+id/jellies" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:scaleType="centerCrop" + android:src="@drawable/jellies" + android:layout_column="0" + android:layout_row="2" + android:onClick="clicked" + android:transitionName="jellies"/> + <ImageView + android:id="@+id/mug" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:scaleType="centerCrop" + android:src="@drawable/mug" + android:layout_column="1" + android:layout_row="2" + android:onClick="clicked" + android:transitionName="mug"/> + <ImageView + android:id="@+id/pencil" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:scaleType="centerCrop" + android:src="@drawable/pencil" + android:layout_column="0" + android:layout_row="3" + android:onClick="clicked" + android:transitionName="pencil"/> + <ImageView + android:id="@+id/scissors" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:scaleType="centerCrop" + android:src="@drawable/scissors" + android:layout_column="1" + android:layout_row="3" + android:onClick="clicked" + android:transitionName="scissors"/> +</GridLayout>
\ No newline at end of file diff --git a/tests/UiBench/res/layout/activity_transition_details.xml b/tests/UiBench/res/layout/activity_transition_details.xml new file mode 100644 index 000000000000..1022d2fc2a40 --- /dev/null +++ b/tests/UiBench/res/layout/activity_transition_details.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2015 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:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + <ImageView + android:id="@+id/titleImage" + android:layout_height="0px" + android:layout_weight="1" + android:layout_width="match_parent" + android:scaleType="centerCrop" + android:transitionName="hero" + android:onClick="clicked"/> + <View + android:layout_width="match_parent" + android:layout_height="2dp" + android:background="#808080"/> + <TextView + android:layout_height="wrap_content" + android:layout_width="match_parent" + android:text="Sample Picture" + android:textSize="30sp" + android:textColor="#FFF"/> +</LinearLayout>
\ No newline at end of file diff --git a/tests/UiBench/res/layout/recycler_view.xml b/tests/UiBench/res/layout/recycler_view.xml new file mode 100644 index 000000000000..54c5b5845ae2 --- /dev/null +++ b/tests/UiBench/res/layout/recycler_view.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Copyright (C) 2015 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 + --> +<android.support.v7.widget.RecyclerView + xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/recyclerView" + android:layout_width="match_parent" + android:layout_height="match_parent"/> diff --git a/tests/UiBench/src/com/android/test/uibench/ActivityTransition.java b/tests/UiBench/src/com/android/test/uibench/ActivityTransition.java new file mode 100644 index 000000000000..1106a13bfc2a --- /dev/null +++ b/tests/UiBench/src/com/android/test/uibench/ActivityTransition.java @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2015 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.uibench; + +import android.app.ActivityOptions; +import android.app.SharedElementCallback; +import android.content.Intent; +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.ImageView; + +import java.util.List; +import java.util.Map; + +public class ActivityTransition extends AppCompatActivity { + private static final String KEY_ID = "ViewTransitionValues:id"; + + private ImageView mHero; + + public static final int[] DRAWABLES = { + R.drawable.ball, + R.drawable.block, + R.drawable.ducky, + R.drawable.jellies, + R.drawable.mug, + R.drawable.pencil, + R.drawable.scissors, + R.drawable.woot, + }; + + public static final int[] IDS = { + R.id.ball, + R.id.block, + R.id.ducky, + R.id.jellies, + R.id.mug, + R.id.pencil, + R.id.scissors, + R.id.woot, + }; + + public static final String[] NAMES = { + "ball", + "block", + "ducky", + "jellies", + "mug", + "pencil", + "scissors", + "woot", + }; + + public static int getIdForKey(String id) { + return IDS[getIndexForKey(id)]; + } + + public static int getDrawableIdForKey(String id) { + return DRAWABLES[getIndexForKey(id)]; + } + + public static int getIndexForKey(String id) { + for (int i = 0; i < NAMES.length; i++) { + String name = NAMES[i]; + if (name.equals(id)) { + return i; + } + } + return 2; + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK)); + setContentView(R.layout.activity_transition); + setupHero(); + } + + private void setupHero() { + String name = getIntent().getStringExtra(KEY_ID); + mHero = null; + if (name != null) { + mHero = (ImageView) findViewById(getIdForKey(name)); + setEnterSharedElementCallback(new SharedElementCallback() { + @Override + public void onMapSharedElements(List<String> names, + Map<String, View> sharedElements) { + sharedElements.put("hero", mHero); + } + }); + } + } + + public void clicked(View v) { + mHero = (ImageView) v; + Intent intent = new Intent(this, ActivityTransitionDetails.class); + intent.putExtra(KEY_ID, v.getTransitionName()); + ActivityOptions activityOptions + = ActivityOptions.makeSceneTransitionAnimation(this, mHero, "hero"); + startActivity(intent, activityOptions.toBundle()); + } +} diff --git a/tests/UiBench/src/com/android/test/uibench/ActivityTransitionDetails.java b/tests/UiBench/src/com/android/test/uibench/ActivityTransitionDetails.java new file mode 100644 index 000000000000..a654c6107134 --- /dev/null +++ b/tests/UiBench/src/com/android/test/uibench/ActivityTransitionDetails.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2015 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.uibench; + +import android.app.ActivityOptions; +import android.content.Intent; +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.ImageView; + +import com.android.test.uibench.ActivityTransition; +import com.android.test.uibench.R; + + +public class ActivityTransitionDetails extends AppCompatActivity { + private static final String KEY_ID = "ViewTransitionValues:id"; + private int mImageResourceId = R.drawable.ducky; + private String mName = "ducky"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + getWindow().setBackgroundDrawable(new ColorDrawable(Color.DKGRAY)); + setContentView(R.layout.activity_transition_details); + ImageView titleImage = (ImageView) findViewById(R.id.titleImage); + titleImage.setImageDrawable(getHeroDrawable()); + } + + private Drawable getHeroDrawable() { + String name = getIntent().getStringExtra(KEY_ID); + if (name != null) { + mName = name; + mImageResourceId = ActivityTransition.getDrawableIdForKey(name); + } + + return getResources().getDrawable(mImageResourceId); + } + + public void clicked(View v) { + Intent intent = new Intent(this, ActivityTransition.class); + intent.putExtra(KEY_ID, mName); + ActivityOptions activityOptions = ActivityOptions.makeSceneTransitionAnimation( + this, v, "hero"); + startActivity(intent, activityOptions.toBundle()); + } +} diff --git a/tests/UiBench/src/com/android/test/uibench/InflatingListActivity.java b/tests/UiBench/src/com/android/test/uibench/InflatingListActivity.java index 84383ec9d911..603244eb2a43 100644 --- a/tests/UiBench/src/com/android/test/uibench/InflatingListActivity.java +++ b/tests/UiBench/src/com/android/test/uibench/InflatingListActivity.java @@ -20,6 +20,8 @@ import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ListAdapter; +import com.android.test.uibench.listview.CompatListActivity; + public class InflatingListActivity extends CompatListActivity { @Override protected ListAdapter createListAdapter() { diff --git a/tests/UiBench/src/com/android/test/uibench/TextCacheHighHitrateActivity.java b/tests/UiBench/src/com/android/test/uibench/TextCacheHighHitrateActivity.java index 91d74ac580ca..fc5be35be4a3 100644 --- a/tests/UiBench/src/com/android/test/uibench/TextCacheHighHitrateActivity.java +++ b/tests/UiBench/src/com/android/test/uibench/TextCacheHighHitrateActivity.java @@ -18,6 +18,8 @@ package com.android.test.uibench; import android.widget.ArrayAdapter; import android.widget.ListAdapter; +import com.android.test.uibench.listview.CompatListActivity; + public class TextCacheHighHitrateActivity extends CompatListActivity { @Override protected ListAdapter createListAdapter() { diff --git a/tests/UiBench/src/com/android/test/uibench/TextCacheLowHitrateActivity.java b/tests/UiBench/src/com/android/test/uibench/TextCacheLowHitrateActivity.java index b526cde9d3b2..14dc437d052b 100644 --- a/tests/UiBench/src/com/android/test/uibench/TextCacheLowHitrateActivity.java +++ b/tests/UiBench/src/com/android/test/uibench/TextCacheLowHitrateActivity.java @@ -18,6 +18,8 @@ package com.android.test.uibench; import android.widget.ArrayAdapter; import android.widget.ListAdapter; +import com.android.test.uibench.listview.CompatListActivity; + public class TextCacheLowHitrateActivity extends CompatListActivity { @Override protected ListAdapter createListAdapter() { diff --git a/tests/UiBench/src/com/android/test/uibench/TrivialListActivity.java b/tests/UiBench/src/com/android/test/uibench/TrivialListActivity.java index 339ac80615ee..2625a99f3c82 100644 --- a/tests/UiBench/src/com/android/test/uibench/TrivialListActivity.java +++ b/tests/UiBench/src/com/android/test/uibench/TrivialListActivity.java @@ -18,6 +18,8 @@ package com.android.test.uibench; import android.widget.ArrayAdapter; import android.widget.ListAdapter; +import com.android.test.uibench.listview.CompatListActivity; + public class TrivialListActivity extends CompatListActivity { @Override protected ListAdapter createListAdapter() { diff --git a/tests/UiBench/src/com/android/test/uibench/TrivialRecyclerViewActivity.java b/tests/UiBench/src/com/android/test/uibench/TrivialRecyclerViewActivity.java new file mode 100644 index 000000000000..4647ba774b2e --- /dev/null +++ b/tests/UiBench/src/com/android/test/uibench/TrivialRecyclerViewActivity.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2015 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.uibench; + +import android.support.v7.widget.RecyclerView; + +import com.android.test.uibench.recyclerview.RvArrayAdapter; +import com.android.test.uibench.recyclerview.RvCompatListActivity; + +public class TrivialRecyclerViewActivity extends RvCompatListActivity { + @Override + protected RecyclerView.Adapter createAdapter() { + return new RvArrayAdapter(TextUtils.buildSimpleStringList()); + } +} diff --git a/tests/UiBench/src/com/android/test/uibench/CompatListActivity.java b/tests/UiBench/src/com/android/test/uibench/listview/CompatListActivity.java index 40ec4530fbc4..214c07463fd7 100644 --- a/tests/UiBench/src/com/android/test/uibench/CompatListActivity.java +++ b/tests/UiBench/src/com/android/test/uibench/listview/CompatListActivity.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.test.uibench; +package com.android.test.uibench.listview; import android.os.Bundle; import android.support.v4.app.FragmentManager; diff --git a/tests/UiBench/src/com/android/test/uibench/recyclerview/RvArrayAdapter.java b/tests/UiBench/src/com/android/test/uibench/recyclerview/RvArrayAdapter.java new file mode 100644 index 000000000000..e5a3a49cf228 --- /dev/null +++ b/tests/UiBench/src/com/android/test/uibench/recyclerview/RvArrayAdapter.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2015 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.uibench.recyclerview; + +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +public class RvArrayAdapter extends RecyclerView.Adapter<RvArrayAdapter.ViewHolder> { + private String[] mDataSet; + private LayoutInflater mLayoutInflater; + + public static class ViewHolder extends RecyclerView.ViewHolder { + private final TextView mTextView; + + public ViewHolder(View v) { + super(v); + mTextView = (TextView) v.findViewById(android.R.id.text1); + } + + public TextView getTextView() { + return mTextView; + } + } + + public RvArrayAdapter(String[] dataSet) { + mDataSet = dataSet; + } + + @Override + public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { + if (mLayoutInflater == null) { + mLayoutInflater = LayoutInflater.from(viewGroup.getContext()); + } + View v = mLayoutInflater.inflate(android.R.layout.simple_list_item_1, viewGroup, false); + + return new ViewHolder(v); + } + + @Override + public void onBindViewHolder(ViewHolder viewHolder, final int position) { + viewHolder.getTextView().setText(mDataSet[position]); + } + + @Override + public int getItemCount() { + return mDataSet.length; + } +} diff --git a/tests/UiBench/src/com/android/test/uibench/recyclerview/RvCompatListActivity.java b/tests/UiBench/src/com/android/test/uibench/recyclerview/RvCompatListActivity.java new file mode 100644 index 000000000000..e08dbc66e7f2 --- /dev/null +++ b/tests/UiBench/src/com/android/test/uibench/recyclerview/RvCompatListActivity.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2015 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.uibench.recyclerview; + +import android.content.Context; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; + +import com.android.test.uibench.R; + +public abstract class RvCompatListActivity extends AppCompatActivity { + public static class RecyclerViewFragment extends Fragment { + RecyclerView.LayoutManager layoutManager; + RecyclerView.Adapter adapter; + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + RecyclerView recyclerView = (RecyclerView) inflater.inflate( + R.layout.recycler_view, container, false); + recyclerView.setLayoutManager(layoutManager); + recyclerView.setAdapter(adapter); + return recyclerView; + } + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + FragmentManager fm = getSupportFragmentManager(); + if (fm.findFragmentById(android.R.id.content) == null) { + RecyclerViewFragment fragment = new RecyclerViewFragment(); + fragment.layoutManager = createLayoutManager(this); + fragment.adapter = createAdapter(); + fm.beginTransaction().add(android.R.id.content, fragment).commit(); + } + } + + protected RecyclerView.LayoutManager createLayoutManager(Context context) { + return new LinearLayoutManager(context); + } + + protected abstract RecyclerView.Adapter createAdapter(); +} |