diff options
author | Agatha Man <agathaman@google.com> | 2020-05-07 23:25:47 -0700 |
---|---|---|
committer | Agatha Man <agathaman@google.com> | 2020-05-11 10:30:54 -0700 |
commit | 66a5959ddd1b97833926effe3fcd3cbfb56cfb0f (patch) | |
tree | 8aeebf158961393714eb7d181b119b1069c9d4c3 /RotaryPlayground | |
parent | faa8227fdef9dd7e5d1439c53b6810c953441439 (diff) | |
download | tests-66a5959ddd1b97833926effe3fcd3cbfb56cfb0f.tar.gz |
Add Grid RecyclerView to Rotary Playground
Added a screen with a Grid CarRecyclerView to test z-pattern rotating
navigation and vertical scrolling.
Bug: 154957299
Bug: 154971276
Test: manual
Change-Id: I685637db07d89a3a43dd2321c1af359ad5e6f277
Diffstat (limited to 'RotaryPlayground')
10 files changed, 222 insertions, 2 deletions
diff --git a/RotaryPlayground/Android.bp b/RotaryPlayground/Android.bp index 002feae..2371831 100644 --- a/RotaryPlayground/Android.bp +++ b/RotaryPlayground/Android.bp @@ -24,6 +24,7 @@ android_app { static_libs: [ "car-apps-common", + "car-ui-lib", ], owner: "google", diff --git a/RotaryPlayground/res/layout/rotary_activity.xml b/RotaryPlayground/res/layout/rotary_activity.xml index bbe970c..2e63d6b 100644 --- a/RotaryPlayground/res/layout/rotary_activity.xml +++ b/RotaryPlayground/res/layout/rotary_activity.xml @@ -1,3 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> <!-- ~ Copyright (C) 2020 The Android Open Source Project ~ diff --git a/RotaryPlayground/res/layout/rotary_cards.xml b/RotaryPlayground/res/layout/rotary_cards.xml index ce798bc..7774918 100644 --- a/RotaryPlayground/res/layout/rotary_cards.xml +++ b/RotaryPlayground/res/layout/rotary_cards.xml @@ -1,3 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> <!-- ~ Copyright (C) 2020 The Android Open Source Project ~ diff --git a/RotaryPlayground/res/layout/rotary_grid.xml b/RotaryPlayground/res/layout/rotary_grid.xml new file mode 100644 index 0000000..7e9998d --- /dev/null +++ b/RotaryPlayground/res/layout/rotary_grid.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2020 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. +--> + +<com.android.car.ui.FocusArea + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <com.android.car.ui.recyclerview.CarUiRecyclerView + android:id="@+id/rotary_grid_view" + app:layoutStyle="grid" + app:numOfColumns="3" + android:layout_width="match_parent" + android:layout_height="match_parent"/> +</com.android.car.ui.FocusArea> diff --git a/RotaryPlayground/res/layout/rotary_grid_item.xml b/RotaryPlayground/res/layout/rotary_grid_item.xml new file mode 100644 index 0000000..e532ec5 --- /dev/null +++ b/RotaryPlayground/res/layout/rotary_grid_item.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2020 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. +--> + +<!-- This is the item layout for the rotary_grid.xml. The attribute, + android:focusable="true" is to allow the items to be focusable. + Alternatively, android:clickable="true" will also make the items + focusable automatically, but would mean the user could tap on the items. --> +<FrameLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/rotary_grid_item" + android:background="@color/grid_item_background_color" + android:focusable="true" + android:layout_width="match_parent" + android:layout_height="100dp" + android:layout_margin="10dp"> + + <TextView + android:id="@+id/rotary_grid_item_text" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:ellipsize="end" + android:maxLines="1"/> +</FrameLayout>
\ No newline at end of file diff --git a/RotaryPlayground/res/layout/rotary_menu.xml b/RotaryPlayground/res/layout/rotary_menu.xml index debe3ed..b8b43d2 100644 --- a/RotaryPlayground/res/layout/rotary_menu.xml +++ b/RotaryPlayground/res/layout/rotary_menu.xml @@ -33,11 +33,11 @@ android:layout_marginTop="32dp" android:text="Menu Item 2" /> <Button - android:id="@+id/menu_item_3" + android:id="@+id/grid_example" android:layout_width="match_parent" android:layout_height="50dp" android:layout_marginTop="32dp" - android:text="Menu Item 3" /> + android:text="Grid Example" /> <Button android:id="@+id/menu_item_4" android:layout_width="match_parent" diff --git a/RotaryPlayground/res/values/colors.xml b/RotaryPlayground/res/values/colors.xml index c52fa47..05e030c 100644 --- a/RotaryPlayground/res/values/colors.xml +++ b/RotaryPlayground/res/values/colors.xml @@ -17,5 +17,6 @@ <resources> <color name="card_background_color">#37393d</color> <color name="card_disabled_background_color">#61646b</color> + <color name="grid_item_background_color">#006666</color> <color name="button_disabled_background_color">#61646b</color> </resources>
\ No newline at end of file diff --git a/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryGrid.java b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryGrid.java new file mode 100644 index 0000000..ceb0673 --- /dev/null +++ b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryGrid.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2020 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.car.rotaryplayground; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +/** + * Fragment with a RecyclerView Grid to demo and test z-pattern rotating navigation and + * vertical scroll. + */ +public class RotaryGrid extends Fragment { + + private static final int NUMBER_OF_COLUMNS = 3; + + private static final String[] DATA = { + "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", + "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", + "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", + "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", + "41", "42", "43", "44", "45", "46", "47", "48", "49", "50"}; + + private RotaryGridAdapter mGridAdapter; + + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.rotary_grid, container, false); + populateGridItems(view); + return view; + } + + private void populateGridItems(View view) { + RecyclerView gridView = view.findViewById(R.id.rotary_grid_view); + gridView.setLayoutManager(new GridLayoutManager(getActivity(), NUMBER_OF_COLUMNS)); + mGridAdapter = new RotaryGridAdapter(getActivity(), DATA); + gridView.setAdapter(mGridAdapter); + } +} diff --git a/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryGridAdapter.java b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryGridAdapter.java new file mode 100644 index 0000000..8c5492c --- /dev/null +++ b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryGridAdapter.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2020 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.car.rotaryplayground; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.recyclerview.widget.RecyclerView; + +import java.util.Collections; +import java.util.List; + +/** + * The adapter that populates the example rotary grid view with strings. + */ +final class RotaryGridAdapter extends RecyclerView.Adapter<RotaryGridAdapter.ItemViewHolder> { + + private final String[] mData; + private final Context mContext; + private final LayoutInflater mInflater; + + RotaryGridAdapter(Context context, String[] data) { + this.mContext = context; + this.mInflater = LayoutInflater.from(context); + this.mData = data; + } + + @Override + public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View view = mInflater.inflate( + R.layout.rotary_grid_item, parent, /* attachToRoot= */ false); + return new ItemViewHolder(view); + } + + @Override + public void onBindViewHolder(ItemViewHolder holder, int position) { + holder.setText(mData[position]); + } + + @Override + public int getItemCount() { + return mData.length; + } + + /** The viewholder class that contains the grid item data. */ + static class ItemViewHolder extends RecyclerView.ViewHolder { + private TextView mItemText; + + ItemViewHolder(View view) { + super(view); + mItemText = itemView.findViewById(R.id.rotary_grid_item_text); + } + + void setText(String text) { + this.mItemText.setText(text); + } + } +}
\ No newline at end of file diff --git a/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java index 272317d..29f446d 100644 --- a/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java +++ b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java @@ -31,8 +31,10 @@ import androidx.fragment.app.Fragment; public class RotaryMenu extends Fragment { private Fragment mRotaryCards = null; + private Fragment mRotaryGrid = null; private Button mCardExamplesButton; + private Button mGridExampleButton; @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @@ -43,6 +45,10 @@ public class RotaryMenu extends Fragment { mCardExamplesButton.setOnFocusChangeListener((v, hasFocus) -> showRotaryCards(hasFocus)); mCardExamplesButton.setOnClickListener(v -> showRotaryCards(/* hasFocus= */ true)); + mGridExampleButton = view.findViewById(R.id.grid_example); + mGridExampleButton.setOnFocusChangeListener((v, hasFocus) -> showGridExample(hasFocus)); + mGridExampleButton.setOnClickListener(v -> showGridExample(/* hasFocus= */ true)); + return view; } @@ -56,6 +62,16 @@ public class RotaryMenu extends Fragment { showContent(mRotaryCards); } + private void showGridExample(boolean hasFocus) { + if (!hasFocus) { + return; // do nothing if no focus. + } + if (mRotaryGrid == null) { + mRotaryGrid = new RotaryGrid(); + } + showContent(mRotaryGrid); + } + private void showContent(Fragment fragment) { getFragmentManager().beginTransaction() .replace(R.id.rotary_content, fragment) |