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 /tests/UiBench/src | |
parent | a05ee0435e541f8c9ae89485d1c6a22e38da6a04 (diff) |
Adding recyclerview and activity transition to UiBench
Change-Id: Ief31c6ed7f6b798893256f79b41e8a6ccbc3f3c7
Diffstat (limited to 'tests/UiBench/src')
-rw-r--r-- | tests/UiBench/src/com/android/test/uibench/ActivityTransition.java | 118 | ||||
-rw-r--r-- | tests/UiBench/src/com/android/test/uibench/ActivityTransitionDetails.java | 63 | ||||
-rw-r--r-- | tests/UiBench/src/com/android/test/uibench/InflatingListActivity.java | 2 | ||||
-rw-r--r-- | tests/UiBench/src/com/android/test/uibench/TextCacheHighHitrateActivity.java | 2 | ||||
-rw-r--r-- | tests/UiBench/src/com/android/test/uibench/TextCacheLowHitrateActivity.java | 2 | ||||
-rw-r--r-- | tests/UiBench/src/com/android/test/uibench/TrivialListActivity.java | 2 | ||||
-rw-r--r-- | tests/UiBench/src/com/android/test/uibench/TrivialRecyclerViewActivity.java | 28 | ||||
-rw-r--r-- | tests/UiBench/src/com/android/test/uibench/listview/CompatListActivity.java (renamed from tests/UiBench/src/com/android/test/uibench/CompatListActivity.java) | 2 | ||||
-rw-r--r-- | tests/UiBench/src/com/android/test/uibench/recyclerview/RvArrayAdapter.java | 64 | ||||
-rw-r--r-- | tests/UiBench/src/com/android/test/uibench/recyclerview/RvCompatListActivity.java | 68 |
10 files changed, 350 insertions, 1 deletions
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(); +} |