diff options
author | Yabin Huang <yabinh@google.com> | 2020-09-14 19:17:27 -0700 |
---|---|---|
committer | Yabin Huang <yabinh@google.com> | 2020-09-18 13:08:12 -0700 |
commit | c47a2d9e139ef599d81fbfe3223b459e877e8f95 (patch) | |
tree | e16b59fc8fc956e015b3c1e806a41c38fff7763f | |
parent | 62f7efaaf88420486373f48001726ae1344465f5 (diff) | |
download | tests-c47a2d9e139ef599d81fbfe3223b459e877e8f95.tar.gz |
Add an example to demo custom FocusArea
Bug: 155698037
Test: manual
Change-Id: I4bf0648d66da4804e9d67c8f98accd92f65cbd41
5 files changed, 271 insertions, 4 deletions
diff --git a/RotaryPlayground/res/layout/custom_focus_areas_fragment.xml b/RotaryPlayground/res/layout/custom_focus_areas_fragment.xml new file mode 100644 index 0000000..ea6a0b0 --- /dev/null +++ b/RotaryPlayground/res/layout/custom_focus_areas_fragment.xml @@ -0,0 +1,214 @@ +<?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. + --> +<LinearLayout + 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"> + + <LinearLayout + android:layout_width="0dp" + android:layout_height="match_parent" + android:layout_weight="1" + android:orientation="vertical"> + + <com.android.car.ui.FocusArea + android:id="@+id/top_left" + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_weight="1" + android:layout_margin="@dimen/margin" + android:gravity="center" + android:orientation="vertical" + android:background="@color/card_background_color"> + <Button + android:layout_width="wrap_content" + android:layout_height="@dimen/button_height" + android:paddingHorizontal="@dimen/padding" + android:text="Button"/> + <Button + android:layout_width="wrap_content" + android:layout_height="@dimen/button_height" + android:paddingHorizontal="@dimen/padding" + android:focusedByDefault="true" + android:text="android:focusedByDefault"/> + <Button + android:id="@+id/default_focus1" + android:layout_width="wrap_content" + android:layout_height="@dimen/button_height" + android:paddingHorizontal="@dimen/padding" + android:text="Button"/> + </com.android.car.ui.FocusArea> + + <com.android.car.ui.FocusArea + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_weight="1" + android:layout_margin="@dimen/margin" + android:gravity="center" + android:orientation="vertical" + android:background="@color/card_background_color" + app:defaultFocus="@+id/default_focus"> + <Button + android:layout_width="wrap_content" + android:layout_height="@dimen/button_height" + android:paddingHorizontal="@dimen/padding" + android:text="Button"/> + <Button + android:layout_width="wrap_content" + android:layout_height="@dimen/button_height" + android:paddingHorizontal="@dimen/padding" + android:focusedByDefault="true" + android:text="android:focusedByDefault"/> + <Button + android:id="@+id/default_focus" + android:layout_width="wrap_content" + android:layout_height="@dimen/button_height" + android:paddingHorizontal="@dimen/padding" + android:text="app:defaultFocus"/> + </com.android.car.ui.FocusArea> + + </LinearLayout> + + <LinearLayout + android:layout_width="0dp" + android:layout_height="match_parent" + android:layout_weight="1" + android:orientation="vertical"> + + <com.android.car.ui.FocusArea + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_weight="1" + android:layout_margin="@dimen/margin" + android:gravity="center" + android:orientation="vertical" + android:background="@color/card_background_color" + app:defaultFocus="@+id/default_focus2"> + <Button + android:layout_width="wrap_content" + android:layout_height="@dimen/button_height" + android:paddingHorizontal="@dimen/padding" + android:text="Button"/> + <Button + android:id="@+id/default_focus2" + android:layout_width="wrap_content" + android:layout_height="@dimen/button_height" + android:paddingHorizontal="@dimen/padding" + android:text="app:defaultFocus"/> + <Button + android:layout_width="wrap_content" + android:layout_height="@dimen/button_height" + android:paddingHorizontal="@dimen/padding" + android:text="Button"/> + </com.android.car.ui.FocusArea> + + <com.android.car.ui.FocusArea + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_weight="1" + android:layout_margin="@dimen/margin" + android:gravity="center" + android:orientation="vertical" + android:background="@color/card_background_color" + app:nudgeLeft="@+id/top_left"> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Nudging to left goes to top left"/> + <Button + android:layout_width="wrap_content" + android:layout_height="@dimen/button_height" + android:paddingHorizontal="@dimen/padding" + android:text="Button"/> + <Button + android:layout_width="wrap_content" + android:layout_height="@dimen/button_height" + android:paddingHorizontal="@dimen/padding" + android:text="Button"/> + <Button + android:layout_width="wrap_content" + android:layout_height="@dimen/button_height" + android:paddingHorizontal="@dimen/padding" + android:text="Button"/> + </com.android.car.ui.FocusArea> + + </LinearLayout> + + <LinearLayout + android:layout_width="0dp" + android:layout_height="match_parent" + android:layout_weight="1" + android:orientation="vertical"> + + <com.android.car.ui.FocusArea + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_weight="1" + android:layout_margin="@dimen/margin" + android:gravity="center" + android:orientation="vertical" + android:background="@color/card_background_color" + app:nudgeShortcut="@+id/nudge_shortcut" + app:nudgeShortcutDirection="up"> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Nudging up goes to the first Button"/> + <Button + android:id="@+id/nudge_shortcut" + android:layout_width="wrap_content" + android:layout_height="@dimen/button_height" + android:paddingHorizontal="@dimen/padding" + android:text="Button"/> + <Button + android:layout_width="wrap_content" + android:layout_height="@dimen/button_height" + android:paddingHorizontal="@dimen/padding" + android:text="Button"/> + <Button + android:layout_width="wrap_content" + android:layout_height="@dimen/button_height" + android:paddingHorizontal="@dimen/padding" + android:text="Button"/> + </com.android.car.ui.FocusArea> + + <com.android.car.ui.FocusArea + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_weight="1" + android:layout_margin="@dimen/margin" + android:gravity="center" + android:orientation="vertical" + android:background="@color/card_disabled_background_color"> + <Button + android:layout_width="wrap_content" + android:layout_height="@dimen/button_height" + android:paddingHorizontal="@dimen/padding" + android:focusable="false" + android:text="non-focusable Button"/> + <Button + android:layout_width="wrap_content" + android:layout_height="@dimen/button_height" + android:paddingHorizontal="@dimen/padding" + android:enabled="false" + android:text="disabled Button"/> + </com.android.car.ui.FocusArea> + + </LinearLayout> + +</LinearLayout> diff --git a/RotaryPlayground/res/layout/rotary_cards.xml b/RotaryPlayground/res/layout/rotary_cards.xml index b197058..e3d9e87 100644 --- a/RotaryPlayground/res/layout/rotary_cards.xml +++ b/RotaryPlayground/res/layout/rotary_cards.xml @@ -52,15 +52,12 @@ android:layout_width="@dimen/card_width" android:layout_height="match_parent" android:padding="@dimen/card_padding" - android:orientation="vertical" - app:nudgeShortcut="@+id/button1" - app:nudgeShortcutDirection="up"> + android:orientation="vertical"> <TextView android:layout_height="@dimen/description_height" android:layout_width="match_parent" android:text="@string/card_normal_text" /> <Button - android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="50dp" android:onClick="onRotaryButtonClick" diff --git a/RotaryPlayground/res/layout/rotary_menu.xml b/RotaryPlayground/res/layout/rotary_menu.xml index 452fdc1..f72d6ec 100644 --- a/RotaryPlayground/res/layout/rotary_menu.xml +++ b/RotaryPlayground/res/layout/rotary_menu.xml @@ -69,4 +69,11 @@ android:layout_weight="1" android:text="WebView" style="@style/tab" /> + <Button + android:id="@+id/custom_focus_areas" + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_weight="1" + android:text="Custom FocusAreas" + style="@style/tab" /> </com.android.car.ui.FocusArea> diff --git a/RotaryPlayground/src/com/android/car/rotaryplayground/CustomFocusAreasFragment.java b/RotaryPlayground/src/com/android/car/rotaryplayground/CustomFocusAreasFragment.java new file mode 100644 index 0000000..b8b1c71 --- /dev/null +++ b/RotaryPlayground/src/com/android/car/rotaryplayground/CustomFocusAreasFragment.java @@ -0,0 +1,35 @@ +/* + * 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; + +/** Fragment to demo custom attributes in {@link com.android.car.ui.FocusArea}. */ +public class CustomFocusAreasFragment extends Fragment { + + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { + return inflater.inflate(R.layout.custom_focus_areas_fragment, container, false); + } +} diff --git a/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java index 048686e..0e417b4 100644 --- a/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java +++ b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java @@ -38,6 +38,7 @@ public class RotaryMenu extends Fragment { private Fragment mNotificationFragment = null; private Fragment mScrollFragment = null; private Fragment mWebViewFragment = null; + private Fragment mCustomFocusAreasFragment = null; @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @@ -86,6 +87,12 @@ public class RotaryMenu extends Fragment { showWebViewFragment(); }); + Button customFocusAreasButton = view.findViewById(R.id.custom_focus_areas); + customFocusAreasButton.setOnClickListener(v -> { + selectTab(v); + showCustomFocusAreasFragment(); + }); + return view; } @@ -148,6 +155,13 @@ public class RotaryMenu extends Fragment { showFragment(mWebViewFragment); } + private void showCustomFocusAreasFragment() { + if (mCustomFocusAreasFragment == null) { + mCustomFocusAreasFragment = new CustomFocusAreasFragment(); + } + showFragment(mCustomFocusAreasFragment); + } + private void showFragment(Fragment fragment) { getFragmentManager().beginTransaction() .replace(R.id.rotary_content, fragment) |