aboutsummaryrefslogtreecommitdiff
path: root/RotaryPlayground/src/com/android
diff options
context:
space:
mode:
authorPardis Beikzadeh <pardis@google.com>2020-06-02 14:05:15 -0700
committerPardis Beikzadeh <pardis@google.com>2020-06-11 19:54:25 -0700
commitb4d094e1c6c5b9bdbf0f2476ba47f865b91e3c13 (patch)
tree9bf852e0743cb4c93377bdead211609c76f992a7 /RotaryPlayground/src/com/android
parent97c16099017c074fc8292c17959966a5e4e26f61 (diff)
downloadtests-b4d094e1c6c5b9bdbf0f2476ba47f865b91e3c13.tar.gz
Add direct manipulation sys window widgets.
In particular, adding 2 SeekBars and 2 RadialTimePickerViews. 2 because in a system window, a given View can be marked as "supports direct manipulation mode" or not. So we add 1 of each thing that supports DM mode and one that doesn't. For the ones that support, entering DM mode allows rotary controls to be used to manipulate the value. For the ones that don't, the event that would have entered DM mode instead triggers an ACTION_CLICK which in our implementation changes the background color on every other invocation. Test: manual, build, install, run the app BUG: 153888753 Change-Id: If1d4de9def33c8bf062e6f0ce202b99797e2d014
Diffstat (limited to 'RotaryPlayground/src/com/android')
-rw-r--r--RotaryPlayground/src/com/android/car/rotaryplayground/DirectManipulationHandler.java2
-rw-r--r--RotaryPlayground/src/com/android/car/rotaryplayground/L.java24
-rw-r--r--RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java18
-rw-r--r--RotaryPlayground/src/com/android/car/rotaryplayground/RotarySysUiDirectManipulationWidgets.java95
4 files changed, 138 insertions, 1 deletions
diff --git a/RotaryPlayground/src/com/android/car/rotaryplayground/DirectManipulationHandler.java b/RotaryPlayground/src/com/android/car/rotaryplayground/DirectManipulationHandler.java
index 8a87467..fc06754 100644
--- a/RotaryPlayground/src/com/android/car/rotaryplayground/DirectManipulationHandler.java
+++ b/RotaryPlayground/src/com/android/car/rotaryplayground/DirectManipulationHandler.java
@@ -103,7 +103,7 @@ public class DirectManipulationHandler implements View.OnKeyListener,
@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
boolean isActionUp = keyEvent.getAction() == KeyEvent.ACTION_UP;
- Log.d("RotaryPlayGround", "View: " + view + " is handling " + keyCode
+ Log.d(L.TAG, "View: " + view + " is handling " + keyCode
+ " and action " + keyEvent.getAction()
+ " direct manipulation mode is "
+ (mDirectManipulationMode.isActive() ? "active" : "inactive"));
diff --git a/RotaryPlayground/src/com/android/car/rotaryplayground/L.java b/RotaryPlayground/src/com/android/car/rotaryplayground/L.java
new file mode 100644
index 0000000..d970f6d
--- /dev/null
+++ b/RotaryPlayground/src/com/android/car/rotaryplayground/L.java
@@ -0,0 +1,24 @@
+/*
+ * 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;
+
+/**
+ * A class to facilitate app-wide logging.
+ */
+public class L {
+ public static final String TAG = "RotaryPlayground";
+}
diff --git a/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java
index a1ede40..c87fe1b 100644
--- a/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java
+++ b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java
@@ -34,12 +34,14 @@ public class RotaryMenu extends Fragment {
private Fragment mRotaryCards = null;
private Fragment mRotaryGrid = null;
private Fragment mDirectManipulation = null;
+ private Fragment mSysUiDirectManipulation = null;
private Fragment mNotificationFragment = null;
private Fragment mScrollFragment = null;
private Button mCardButton;
private Button mGridButton;
private Button mDirectManipulationButton;
+ private Button mSysUiDirectManipulationButton;
private Button mNotificationButton;
private Button mScrollButton;
@@ -62,6 +64,12 @@ public class RotaryMenu extends Fragment {
mDirectManipulationButton.setOnClickListener(
(v -> showDirectManipulationExamples(/* hasFocus= */ true)));
+ mSysUiDirectManipulationButton = view.findViewById(R.id.sys_ui_direct_manipulation);
+ mSysUiDirectManipulationButton.setOnFocusChangeListener(
+ (v, hasFocus) -> showSysUiDirectManipulationExamples(hasFocus));
+ mSysUiDirectManipulationButton.setOnClickListener(
+ (v -> showSysUiDirectManipulationExamples(/* hasFocus= */ true)));
+
mNotificationButton = view.findViewById(R.id.notification);
mNotificationButton.setOnFocusChangeListener(
(v, hasFocus) -> showNotificationExample(hasFocus));
@@ -106,6 +114,16 @@ public class RotaryMenu extends Fragment {
showFragment(mDirectManipulation);
}
+ private void showSysUiDirectManipulationExamples(boolean hasFocus) {
+ if (!hasFocus) {
+ return; // Do nothing if no focus.
+ }
+ if (mSysUiDirectManipulation == null) {
+ mSysUiDirectManipulation = new RotarySysUiDirectManipulationWidgets();
+ }
+ showFragment(mSysUiDirectManipulation);
+ }
+
private void showNotificationExample(boolean hasFocus) {
if (!hasFocus) {
return; // do nothing if no focus.
diff --git a/RotaryPlayground/src/com/android/car/rotaryplayground/RotarySysUiDirectManipulationWidgets.java b/RotaryPlayground/src/com/android/car/rotaryplayground/RotarySysUiDirectManipulationWidgets.java
new file mode 100644
index 0000000..85fce89
--- /dev/null
+++ b/RotaryPlayground/src/com/android/car/rotaryplayground/RotarySysUiDirectManipulationWidgets.java
@@ -0,0 +1,95 @@
+/*
+ * 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.graphics.Color;
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import androidx.annotation.Nullable;
+import androidx.fragment.app.Fragment;
+
+import com.android.car.ui.utils.DirectManipulationHelper;
+
+public class RotarySysUiDirectManipulationWidgets extends Fragment {
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
+ @Nullable Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.rotary_sys_ui_direct_manipulation, container, false);
+
+ View directManipulationSupportedSeekBar = view.findViewById(
+ R.id.direct_manipulation_supported_seek_bar);
+ DirectManipulationHelper.setSupportsDirectManipulation(
+ directManipulationSupportedSeekBar, true);
+
+ View directManipulationUnsupportedSeekBar = view.findViewById(
+ R.id.direct_manipulation_unsupported_seek_bar);
+ directManipulationUnsupportedSeekBar.setOnClickListener(
+ new ChangeBackgroundColorOnClickListener());
+
+ View directManipulationSupportedRadialTimePickerView = view.findViewById(
+ R.id.direct_manipulation_supported_radial_time_picker);
+ DirectManipulationHelper.setSupportsDirectManipulation(
+ directManipulationSupportedRadialTimePickerView, true);
+
+ View directManipulationUnsupportedRadialTimePickerView = view.findViewById(
+ R.id.direct_manipulation_unsupported_radial_time_picker);
+ directManipulationUnsupportedRadialTimePickerView.setOnClickListener(
+ new ChangeBackgroundColorOnClickListener());
+
+ return view;
+ }
+
+ /**
+ * An {@link android.view.View.OnClickListener} object that changes the background of the
+ * view it is registered on to {@link Color#BLUE} and back to whatever it was before on
+ * subsequent calls. This is just to demo doing something visually obvious in the UI.
+ */
+ private static class ChangeBackgroundColorOnClickListener implements View.OnClickListener {
+
+ /** Just some random color to switch the background to for demo purposes. */
+ private static final int ALTERNATIVE_BACKGROUND_COLOR = Color.BLUE;
+
+ /**
+ * The purpose of this boolean is to change color every other time {@link #onClick} is
+ * called.
+ */
+ private boolean mFlipFlop = true;
+
+ @Override
+ public void onClick(View v) {
+ Log.d(L.TAG,
+ "Handling onClick for " + v + " and going " + (mFlipFlop ? "flip" : "flop"));
+ if (mFlipFlop) {
+ Log.d(L.TAG, "Background about to be overwritten: " + v.getBackground());
+ v.setTag(R.id.saved_background_tag, v.getBackground());
+ v.setBackgroundColor(ALTERNATIVE_BACKGROUND_COLOR);
+ } else {
+ Object savedBackground = v.getTag(R.id.saved_background_tag);
+ Log.d(L.TAG, "Restoring background: " + savedBackground);
+ v.setBackground((Drawable) savedBackground);
+ }
+ // Flip mode bit.
+ mFlipFlop = !mFlipFlop;
+ }
+ }
+} \ No newline at end of file