aboutsummaryrefslogtreecommitdiff
path: root/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryCards.java
diff options
context:
space:
mode:
Diffstat (limited to 'RotaryPlayground/src/com/android/car/rotaryplayground/RotaryCards.java')
-rw-r--r--RotaryPlayground/src/com/android/car/rotaryplayground/RotaryCards.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryCards.java b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryCards.java
index 28f34a1..730c7c5 100644
--- a/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryCards.java
+++ b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryCards.java
@@ -16,13 +16,18 @@
package com.android.car.rotaryplayground;
+import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.Button;
+
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
+import com.android.car.ui.FocusArea;
+
/** Fragment to demo a layout with cards that are FocusArea containers. */
public class RotaryCards extends Fragment {
@@ -30,6 +35,62 @@ public class RotaryCards extends Fragment {
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.rotary_cards, container, false);
+
+ // This button will be removed and immediately added back after click. So the focus
+ // highlight will jump to another view after rotary click.
+ FocusArea focusArea5 = view.findViewById(R.id.focus_area5);
+ Button button5a = view.findViewById(R.id.button_5a);
+ button5a.setOnClickListener(v -> {
+ int index = focusArea5.indexOfChild(button5a);
+ focusArea5.removeView(button5a);
+ focusArea5.addView(button5a, index);
+ });
+
+ // The background of this button will be changed after click. The focus highlight will stay
+ // on this Button after click.
+ Button button5b = view.findViewById(R.id.button_5b);
+ boolean[] stopped = {false};
+ button5b.setOnClickListener(v -> {
+ stopped[0] = !stopped[0];
+ Drawable drawable = view.getContext().getDrawable(
+ stopped[0] ? R.drawable.ic_stop : R.drawable.ic_play_arrow);
+ button5b.setBackground(drawable);
+ });
+
+ // This button will be removed and immediately added back after click. It's not focusable
+ // but its container is focusable. The focus highlight will stay on the container after
+ // click.
+ ViewGroup button5cContainer = view.findViewById(R.id.button_5c_container);
+ Button button5c = view.findViewById(R.id.button_5c);
+ button5c.setFocusable(false);
+ button5cContainer.setOnClickListener(v -> {
+ button5cContainer.removeView(button5c);
+ button5cContainer.addView(button5c, 0);
+ });
+
+ // This button will be removed then added back and request focus explicitly after click.
+ // So the focus highlight will jump to another view then jump back after rotary click.
+ Button button5d = view.findViewById(R.id.button_5d);
+ button5d.setOnClickListener(v -> {
+ boolean needRestoreFocus = button5d.isFocused();
+ int index = focusArea5.indexOfChild(button5d);
+ focusArea5.removeView(button5d);
+ focusArea5.addView(button5d, index);
+ if (needRestoreFocus) {
+ button5d.requestFocus();
+ }
+ });
+
+ // This button will be disabled after click. So the focus highlight will jump to another
+ // view after rotary click.
+ Button button5e = view.findViewById(R.id.button_5e);
+ button5e.setOnClickListener(v -> button5e.setEnabled(!button5e.isEnabled()));
+
+ // This button will appear disabled but is not disabled after click. So the focus
+ // highlight will stay after rotary click.
+ CustomButton button5f = view.findViewById(R.id.button_5f);
+ button5f.setOnClickListener(v -> button5f.setRotaryEnabled(!button5f.isRotaryEnabled()));
+
return view;
}
}