diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2020-06-06 01:11:58 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2020-06-06 01:11:58 +0000 |
commit | 2403faf32e9c3659d79ad3b968eb4fd337195d19 (patch) | |
tree | e84cdb14ee114291c73d916d77e9c55629e7a6ee | |
parent | 40c36dcad3ae7e319716f4c7cc7aa72355f7a551 (diff) | |
parent | 97c16099017c074fc8292c17959966a5e4e26f61 (diff) | |
download | tests-2403faf32e9c3659d79ad3b968eb4fd337195d19.tar.gz |
Snap for 6564423 from 97c16099017c074fc8292c17959966a5e4e26f61 to rvc-release
Change-Id: Ia03c40836dd6910163ae2bdc7a1ac8c7a0a5e7b6
9 files changed, 243 insertions, 78 deletions
diff --git a/RotaryPlayground/res/layout/rotary_menu.xml b/RotaryPlayground/res/layout/rotary_menu.xml index 176d58c..659f119 100644 --- a/RotaryPlayground/res/layout/rotary_menu.xml +++ b/RotaryPlayground/res/layout/rotary_menu.xml @@ -39,11 +39,11 @@ android:layout_weight="1" android:text="Grid" /> <Button - android:id="@+id/menu_item_4" + android:id="@+id/notification" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" - android:text="Menu Item 4" /> + android:text="Notification" /> <Button android:id="@+id/scroll" android:layout_width="match_parent" diff --git a/RotaryPlayground/res/layout/rotary_notification.xml b/RotaryPlayground/res/layout/rotary_notification.xml new file mode 100644 index 0000000..998febe --- /dev/null +++ b/RotaryPlayground/res/layout/rotary_notification.xml @@ -0,0 +1,79 @@ +<?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. + --> + +<RelativeLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <com.android.car.ui.FocusArea + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_alignParentTop="true"> + <TextView + android:layout_width="0dp" + android:layout_height="@dimen/button_height" + android:layout_weight="1" + android:gravity="center" + android:text="Under HUN"/> + <Button + android:id="@+id/add_notification_button1" + android:layout_width="0dp" + android:layout_height="@dimen/button_height" + android:layout_weight="1" + android:layout_margin="5dp" + android:background="@color/button_background_color" + android:text="Add Notification"/> + <Button + android:id="@+id/clear_notification_button1" + android:layout_width="0dp" + android:layout_height="@dimen/button_height" + android:layout_weight="1" + android:layout_margin="5dp" + android:background="@color/button_background_color" + android:text="Clear Notification"/> + </com.android.car.ui.FocusArea> + + <com.android.car.ui.FocusArea + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_alignParentBottom="true"> + <TextView + android:layout_width="0dp" + android:layout_height="@dimen/button_height" + android:layout_weight="1" + android:gravity="center" + android:text="Not Under HUN"/> + <Button + android:id="@+id/add_notification_button2" + android:layout_width="0dp" + android:layout_height="@dimen/button_height" + android:layout_weight="1" + android:layout_margin="5dp" + android:background="@color/button_background_color" + android:text="Add Notification"/> + <Button + android:id="@+id/clear_notification_button2" + android:layout_width="0dp" + android:layout_height="@dimen/button_height" + android:layout_weight="1" + android:layout_margin="5dp" + android:background="@color/button_background_color" + android:text="Clear Notification"/> + </com.android.car.ui.FocusArea> + +</RelativeLayout> diff --git a/RotaryPlayground/res/values/colors.xml b/RotaryPlayground/res/values/colors.xml index b49ea51..87480a0 100644 --- a/RotaryPlayground/res/values/colors.xml +++ b/RotaryPlayground/res/values/colors.xml @@ -18,6 +18,7 @@ <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_background_color">#660000</color> <color name="button_disabled_background_color">#61646b</color> <color name="scroll_text_background_color">#61646b</color> </resources>
\ No newline at end of file diff --git a/RotaryPlayground/res/values/dimens.xml b/RotaryPlayground/res/values/dimens.xml index 77e907f..02a5406 100644 --- a/RotaryPlayground/res/values/dimens.xml +++ b/RotaryPlayground/res/values/dimens.xml @@ -24,4 +24,6 @@ <dimen name="card_width">400dp</dimen> <dimen name="card_padding">20dp</dimen> <dimen name="description_height">200dp</dimen> + <!-- Notification values --> + <dimen name="button_height">70dp</dimen> </resources>
\ No newline at end of file diff --git a/RotaryPlayground/src/com/android/car/rotaryplayground/DirectManipulationHandler.java b/RotaryPlayground/src/com/android/car/rotaryplayground/DirectManipulationHandler.java index 5773b04..8a87467 100644 --- a/RotaryPlayground/src/com/android/car/rotaryplayground/DirectManipulationHandler.java +++ b/RotaryPlayground/src/com/android/car/rotaryplayground/DirectManipulationHandler.java @@ -16,7 +16,6 @@ package com.android.car.rotaryplayground; -import android.graphics.Color; import android.util.Log; import android.view.KeyEvent; import android.view.MotionEvent; @@ -26,8 +25,6 @@ import android.view.ViewGroup; import androidx.annotation.Nullable; import androidx.core.util.Preconditions; -import com.android.car.ui.utils.DirectManipulationHelper; - /** * A {@link View.OnKeyListener} and {@link View.OnGenericMotionListener} that adds a * "Direct Manipulation" mode to any {@link View} that uses it. @@ -57,12 +54,6 @@ import com.android.car.ui.utils.DirectManipulationHelper; public class DirectManipulationHandler implements View.OnKeyListener, View.OnGenericMotionListener { - /** Background color of a view when it's in direct manipulation mode. */ - private static final int BACKGROUND_COLOR_IN_DIRECT_MANIPULATION_MODE = Color.BLUE; - - /** Background color of a view when it's not in direct manipulation mode. */ - private static final int BACKGROUND_COLOR_NOT_IN_DIRECT_MANIPULATION_MODE = Color.TRANSPARENT; - private final DirectManipulationState mDirectManipulationMode; private final View.OnKeyListener mNudgeDelegate; private final View.OnGenericMotionListener mRotationDelegate; @@ -112,51 +103,23 @@ 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 + "\n is handling " + keyCode + Log.d("RotaryPlayGround", "View: " + view + " is handling " + keyCode + " and action " + keyEvent.getAction() - + " having entered direct manipulation mode from " - + mDirectManipulationMode.getStartingView()); + + " direct manipulation mode is " + + (mDirectManipulationMode.isActive() ? "active" : "inactive")); switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: // If not yet in Direct Manipulation mode, switch to that mode. - // We generally want to give some kind of visual indication that this change - // has happened. In this example we change the background color. + if (!mDirectManipulationMode.isActive() && isActionUp) { - mDirectManipulationMode.setStartingView(view); - /* - * A more robust approach would be to fetch the current background color from - * the view object and store it back onto the View itself using the {@link - * View#setTag(int, java.lang.Object)} API. This could then be fetched back - * and used to restore the background color without needing to keep a constant - * reference to the color here which could fall out of sync with the xml files. - */ - view.setBackgroundColor(BACKGROUND_COLOR_IN_DIRECT_MANIPULATION_MODE); - DirectManipulationHelper.enableDirectManipulationMode(view, true); + mDirectManipulationMode.enable(view); } return true; case KeyEvent.KEYCODE_BACK: // If in Direct Manipulation mode, exit, and clean up state. if (mDirectManipulationMode.isActive() && isActionUp) { - // This may or may not be the same as argument v. It is possible - // for us to enter Direct Manipulation mode from view A and exit from - // view B. dmStartingView represents A and v represents B. - View dmStartingView = mDirectManipulationMode.getStartingView(); - // For ViewGroup objects, restore descendant focusability to - // FOCUS_BLOCK_DESCENDANTS so during non-Direct Manipulation mode, aka, - // general rotary navigation, we don't go through the individual inner UI - // elements. - if (dmStartingView instanceof ViewGroup) { - ViewGroup viewGroup = (ViewGroup) dmStartingView; - viewGroup.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); - } - // Restore any visual indicators that the view was in Direct Manipulation. - dmStartingView.setBackgroundColor( - BACKGROUND_COLOR_NOT_IN_DIRECT_MANIPULATION_MODE); - // Actually go ahead and disable Direct Manipulation mode for the view. - DirectManipulationHelper.enableDirectManipulationMode(dmStartingView, false); - // Update mode. - mDirectManipulationMode.setStartingView(null); + mDirectManipulationMode.disable(); } return true; default: @@ -165,9 +128,9 @@ public class DirectManipulationHandler implements View.OnKeyListener, if (!mDirectManipulationMode.isActive()) { return false; } - // If no delegate present, ignore events. + // If no delegate present, silently consume the events. if (mNudgeDelegate == null) { - return false; + return true; } return mNudgeDelegate.onKey(view, keyCode, keyEvent); } @@ -180,9 +143,9 @@ public class DirectManipulationHandler implements View.OnKeyListener, if (!mDirectManipulationMode.isActive()) { return false; } - // If no delegate present, ignore events. + // If no delegate present, silently consume the events. if (mRotationDelegate == null) { - return false; + return true; } return mRotationDelegate.onGenericMotion(v, event); } diff --git a/RotaryPlayground/src/com/android/car/rotaryplayground/DirectManipulationState.java b/RotaryPlayground/src/com/android/car/rotaryplayground/DirectManipulationState.java index 0227643..05d236b 100644 --- a/RotaryPlayground/src/com/android/car/rotaryplayground/DirectManipulationState.java +++ b/RotaryPlayground/src/com/android/car/rotaryplayground/DirectManipulationState.java @@ -16,10 +16,15 @@ package com.android.car.rotaryplayground; +import android.graphics.Color; import android.view.View; +import android.view.ViewGroup; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.android.car.ui.utils.DirectManipulationHelper; + /** * Keeps track of the state of "direct manipulation" Rotary mode for this application window by * tracking a reference to the {@link View} from which the user first enters into "direct @@ -29,25 +34,65 @@ import androidx.annotation.Nullable; */ public class DirectManipulationState { + + /** Background color of a view when it's in direct manipulation mode. */ + private static final int BACKGROUND_COLOR_IN_DIRECT_MANIPULATION_MODE = Color.BLUE; + + /** Background color of a view when it's not in direct manipulation mode. */ + private static final int BACKGROUND_COLOR_NOT_IN_DIRECT_MANIPULATION_MODE = Color.TRANSPARENT; + /** The view that is in direct manipulation mode, or null if none. */ @Nullable private View mViewInDirectManipulationMode; - public void setStartingView(@Nullable View view) { + private void setStartingView(@Nullable View view) { mViewInDirectManipulationMode = view; } /** - * Returns the {@link View} from which we entered into Direct Manipulation mode when that mode - * is active, and null otherwise. + * Returns true if Direct Manipulation mode is active, false otherwise. + */ + public boolean isActive() { + return mViewInDirectManipulationMode != null; + } + + /** + * Enables Direct Manipulation mode, and keeps track of {@code view} as the starting point + * of this transition. + * <p> + * We generally want to give some kind of visual indication that this change has happened. In + * this example we change the background color of {@code view}. + * + * @param view - the {@link View} from which we entered into Direct Manipulation mode. */ - @Nullable public View getStartingView() { - return mViewInDirectManipulationMode; + public void enable(@NonNull View view) { + /* + * A more robust approach would be to fetch the current background color from + * the view object and store it back onto the View itself using the {@link + * View#setTag(int, java.lang.Object)} API. This could then be fetched back + * and used to restore the background color without needing to keep a constant + * reference to the color here which could fall out of sync with the xml files. + */ + view.setBackgroundColor(BACKGROUND_COLOR_IN_DIRECT_MANIPULATION_MODE); + DirectManipulationHelper.enableDirectManipulationMode(view, /* enable= */ true); + setStartingView(view); } /** - * Returns true if Direct Manipulation mode is active, false otherwise. + * Disables Direct Manipulation mode and restores any visual indicators for the {@link View} + * from which we entered into Direct Manipulation mode. */ - public boolean isActive() { - return mViewInDirectManipulationMode != null; + public void disable() { + mViewInDirectManipulationMode.setBackgroundColor( + BACKGROUND_COLOR_NOT_IN_DIRECT_MANIPULATION_MODE); + DirectManipulationHelper.enableDirectManipulationMode( + mViewInDirectManipulationMode, /* enable= */ false); + // For ViewGroup objects, restore descendant focusability to FOCUS_BLOCK_DESCENDANTS so + // during non-Direct Manipulation mode, aka, general rotary navigation, we don't go + // through the individual inner UI elements. + if (mViewInDirectManipulationMode instanceof ViewGroup) { + ViewGroup viewGroup = (ViewGroup) mViewInDirectManipulationMode; + viewGroup.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); + } + setStartingView(null); } } diff --git a/RotaryPlayground/src/com/android/car/rotaryplayground/HeadsUpNotificationFragment.java b/RotaryPlayground/src/com/android/car/rotaryplayground/HeadsUpNotificationFragment.java new file mode 100644 index 0000000..0744ac0 --- /dev/null +++ b/RotaryPlayground/src/com/android/car/rotaryplayground/HeadsUpNotificationFragment.java @@ -0,0 +1,77 @@ +/* + * 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.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Intent; +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; + +public class HeadsUpNotificationFragment extends Fragment { + private static final String NOTIFICATION_CHANNEL_ID = "rotary_notification"; + private static final int NOTIFICATION_ID = 1; + + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.rotary_notification, container, false); + NotificationManager notificationManager = + getContext().getSystemService(NotificationManager.class); + notificationManager.createNotificationChannel( + new NotificationChannel(NOTIFICATION_CHANNEL_ID, "Rotary Playground", + NotificationManager.IMPORTANCE_HIGH)); + view.findViewById(R.id.add_notification_button1).setOnClickListener( + v -> notificationManager.notify(NOTIFICATION_ID, createNotification())); + view.findViewById(R.id.clear_notification_button1).setOnClickListener( + v -> notificationManager.cancel(NOTIFICATION_ID)); + view.findViewById(R.id.add_notification_button2).setOnClickListener( + v -> notificationManager.notify(NOTIFICATION_ID, createNotification())); + view.findViewById(R.id.clear_notification_button2).setOnClickListener( + v -> notificationManager.cancel(NOTIFICATION_ID)); + + return view; + } + + /** + * Creates a notification with CATEGORY_CALL in a channel with IMPORTANCE_HIGH. This will + * produce a heads-up notification even for non-system apps that aren't privileged and aren't + * signed with the platform key. The notification includes three actions which appear as buttons + * in the HUN. + */ + private Notification createNotification() { + Intent intent = new Intent(getContext(), RotaryActivity.class); + PendingIntent pendingIntent = PendingIntent.getActivity(getContext(), 0, intent, 0); + return new Notification.Builder(getContext(), NOTIFICATION_CHANNEL_ID) + .setContentTitle("Example heads-up notification") + .setContentText("Try nudging up to HUN") + .setSmallIcon(R.drawable.ic_launcher) + .addAction(new Notification.Action.Builder(null, "Action1", pendingIntent).build()) + .addAction(new Notification.Action.Builder(null, "Action2", pendingIntent).build()) + .addAction(new Notification.Action.Builder(null, "Action3", pendingIntent).build()) + .setColor(getContext().getColor(android.R.color.holo_red_light)) + .setCategory(Notification.CATEGORY_CALL) + .build(); + } +} diff --git a/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryDirectManipulationWidgets.java b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryDirectManipulationWidgets.java index a4715c3..9184597 100644 --- a/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryDirectManipulationWidgets.java +++ b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryDirectManipulationWidgets.java @@ -16,7 +16,6 @@ package com.android.car.rotaryplayground; -import android.graphics.Color; import android.os.Bundle; import android.view.KeyEvent; import android.view.LayoutInflater; @@ -28,12 +27,9 @@ import android.view.accessibility.AccessibilityNodeInfo; import android.widget.NumberPicker; import android.widget.TimePicker; -import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; -import com.android.car.ui.utils.DirectManipulationHelper; - import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -51,12 +47,6 @@ public class RotaryDirectManipulationWidgets extends Fragment { // TODO(agathaman): refactor a common class that takes in a fragment xml id and inflates it, to // share between this and RotaryCards. - /** Background color of a view when it's in direct manipulation mode. */ - private static final int BACKGROUND_COLOR_IN_DIRECT_MANIPULATION_MODE = Color.BLUE; - - /** Background color of a view when it's not in direct manipulation mode. */ - private static final int BACKGROUND_COLOR_NOT_IN_DIRECT_MANIPULATION_MODE = Color.TRANSPARENT; - private final DirectManipulationState mDirectManipulationMode = new DirectManipulationState(); @Override @@ -133,21 +123,11 @@ public class RotaryDirectManipulationWidgets extends Fragment { if (mDirectManipulationMode.isActive()) { // To ensure that the user doesn't get stuck in direct manipulation mode, disable direct // manipulation mode when the fragment is not interactive (e.g., a dialog shows up). - enableDirectManipulationMode(mDirectManipulationMode.getStartingView(), false); + mDirectManipulationMode.disable(); } super.onPause(); } - private void enableDirectManipulationMode(@NonNull View view, boolean enable) { - view.setBackgroundColor(enable - ? BACKGROUND_COLOR_IN_DIRECT_MANIPULATION_MODE - : BACKGROUND_COLOR_NOT_IN_DIRECT_MANIPULATION_MODE); - view.invalidate(); - DirectManipulationHelper.enableDirectManipulationMode(view, enable); - View currentView = enable ? view : null; - mDirectManipulationMode.setStartingView(currentView); - } - /** * Register the given {@link DirectManipulationHandler} as both the * {@link View.OnKeyListener} and {@link View.OnGenericMotionListener} for the given diff --git a/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java index d28d007..a1ede40 100644 --- a/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java +++ b/RotaryPlayground/src/com/android/car/rotaryplayground/RotaryMenu.java @@ -20,6 +20,7 @@ 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; @@ -33,11 +34,13 @@ public class RotaryMenu extends Fragment { private Fragment mRotaryCards = null; private Fragment mRotaryGrid = null; private Fragment mDirectManipulation = null; + private Fragment mNotificationFragment = null; private Fragment mScrollFragment = null; private Button mCardButton; private Button mGridButton; private Button mDirectManipulationButton; + private Button mNotificationButton; private Button mScrollButton; @Override @@ -59,6 +62,11 @@ public class RotaryMenu extends Fragment { mDirectManipulationButton.setOnClickListener( (v -> showDirectManipulationExamples(/* hasFocus= */ true))); + mNotificationButton = view.findViewById(R.id.notification); + mNotificationButton.setOnFocusChangeListener( + (v, hasFocus) -> showNotificationExample(hasFocus)); + mNotificationButton.setOnClickListener(v -> showNotificationExample(/* hasFocus= */ true)); + mScrollButton = view.findViewById(R.id.scroll); mScrollButton.setOnFocusChangeListener((v, hasFocus) -> showScrollFragment(hasFocus)); mScrollButton.setOnClickListener(v -> showScrollFragment(/* hasFocus= */ true)); @@ -98,6 +106,16 @@ public class RotaryMenu extends Fragment { showFragment(mDirectManipulation); } + private void showNotificationExample(boolean hasFocus) { + if (!hasFocus) { + return; // do nothing if no focus. + } + if (mNotificationFragment == null) { + mNotificationFragment = new HeadsUpNotificationFragment(); + } + showFragment(mNotificationFragment); + } + private void showScrollFragment(boolean hasFocus) { if (!hasFocus) { return; // Do nothing if no focus. |