Adding recyclerview and activity transition to UiBench

Change-Id: Ief31c6ed7f6b798893256f79b41e8a6ccbc3f3c7
This commit is contained in:
Md Haque
2015-09-01 12:00:34 -07:00
committed by Chris Craik
parent a05ee0435e
commit d68e8cb51b
25 changed files with 547 additions and 7 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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'
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

View File

@@ -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>

View File

@@ -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>

View File

@@ -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"/>

View File

@@ -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());
}
}

View File

@@ -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());
}
}

View File

@@ -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() {

View File

@@ -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() {

View File

@@ -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() {

View File

@@ -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() {

View File

@@ -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());
}
}

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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();
}