diff options
author | 2025-01-30 23:49:23 +0000 | |
---|---|---|
committer | 2025-02-21 00:22:24 +0000 | |
commit | 83d87e4275780db8473e512e82e4ad6330f2a254 (patch) | |
tree | 1f1f2704a7ac854606a96799ac5f1030936c7033 | |
parent | d241c39be611b83d0996baae6955f8255f697010 (diff) |
Change allow button to a downward button to scroll the permission list
1. If the user hasn't scrolled to the bottom of the permission list, display a button with a downward arrow.
2. Each tap of the downward button scrolls the permission list to reveal the next permission.
3. Once the user has scrolled to the very bottom of the permission list, the "Allow" button becomes visible.
Fix: 391252796
Test: cts + manually
Flag: EXEMPT bugfix
Change-Id: Iac25d681edaf3604230c6d2f7ac8133a8a355ca2
-rw-r--r-- | packages/CompanionDeviceManager/res/drawable/btn_positive_button.xml (renamed from packages/CompanionDeviceManager/res/drawable/btn_positive_bottom.xml) | 8 | ||||
-rw-r--r-- | packages/CompanionDeviceManager/res/drawable/btn_positive_button_with_arrow.xml | 32 | ||||
-rw-r--r-- | packages/CompanionDeviceManager/res/drawable/ic_downward_arrow.xml | 25 | ||||
-rw-r--r-- | packages/CompanionDeviceManager/res/values/strings.xml | 6 | ||||
-rw-r--r-- | packages/CompanionDeviceManager/res/values/styles.xml | 2 | ||||
-rw-r--r-- | packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionAssociationActivity.java | 63 |
6 files changed, 119 insertions, 17 deletions
diff --git a/packages/CompanionDeviceManager/res/drawable/btn_positive_bottom.xml b/packages/CompanionDeviceManager/res/drawable/btn_positive_button.xml index 2cff4737cabf..30cf60ae0b5f 100644 --- a/packages/CompanionDeviceManager/res/drawable/btn_positive_bottom.xml +++ b/packages/CompanionDeviceManager/res/drawable/btn_positive_button.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <!-- - ~ Copyright (C) 2022 The Android Open Source Project + ~ Copyright (C) 2025 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. @@ -16,8 +16,8 @@ --> <shape xmlns:android="http://schemas.android.com/apk/res/android" - android:shape="rectangle"> + android:shape="rectangle"> <solid android:color="@android:color/system_accent1_100"/> <corners android:topLeftRadius="12dp" android:topRightRadius="12dp" - android:bottomLeftRadius="4dp" android:bottomRightRadius="4dp"/> -</shape> + android:bottomLeftRadius="4dp" android:bottomRightRadius="4dp"/> +</shape>
\ No newline at end of file diff --git a/packages/CompanionDeviceManager/res/drawable/btn_positive_button_with_arrow.xml b/packages/CompanionDeviceManager/res/drawable/btn_positive_button_with_arrow.xml new file mode 100644 index 000000000000..1fe4af73caa0 --- /dev/null +++ b/packages/CompanionDeviceManager/res/drawable/btn_positive_button_with_arrow.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2025 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. + --> + +<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> + <item> + <shape android:shape="rectangle"> + <solid android:color="@android:color/system_accent1_100" /> + <corners + android:bottomLeftRadius="4dp" + android:bottomRightRadius="4dp" + android:topLeftRadius="12dp" + android:topRightRadius="12dp" /> + </shape> + </item> + <item + android:drawable="@drawable/ic_downward_arrow" + android:gravity="center" /> +</layer-list>
\ No newline at end of file diff --git a/packages/CompanionDeviceManager/res/drawable/ic_downward_arrow.xml b/packages/CompanionDeviceManager/res/drawable/ic_downward_arrow.xml new file mode 100644 index 000000000000..98fd71b4716d --- /dev/null +++ b/packages/CompanionDeviceManager/res/drawable/ic_downward_arrow.xml @@ -0,0 +1,25 @@ +<!-- + ~ Copyright (C) 2025 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. + --> + +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="960" + android:viewportHeight="960" + android:tint="?attr/colorControlNormal"> + <path android:fillColor="@android:color/system_accent1_600" + android:pathData="M480,720L240,480L296,424L440,568L440,200L520,200L520,568L664,424L720,480L480,720Z"/> +</vector>
\ No newline at end of file diff --git a/packages/CompanionDeviceManager/res/values/strings.xml b/packages/CompanionDeviceManager/res/values/strings.xml index 20ede5ff91d3..60f209b47482 100644 --- a/packages/CompanionDeviceManager/res/values/strings.xml +++ b/packages/CompanionDeviceManager/res/values/strings.xml @@ -139,6 +139,12 @@ <!-- Back button for the helper consent dialog [CHAR LIMIT=30] --> <string name="consent_back">Back</string> + <!-- Downward arrow button action for scroll down the permission list [CHAR LIMIT=30] --> + <string name="downward_arrow_action">Scroll down the list</string> + + <!-- Downward arrow button [CHAR LIMIT=30] --> + <string name="downward_arrow">Downward arrow</string> + <!-- Expand permission in the list CHAR LIMIT=30] --> <string name="permission_expand">Expand <xliff:g id="permission_type" example="Notification">%1$s</xliff:g></string> diff --git a/packages/CompanionDeviceManager/res/values/styles.xml b/packages/CompanionDeviceManager/res/values/styles.xml index 30813baa6e4a..814cc4d25c52 100644 --- a/packages/CompanionDeviceManager/res/values/styles.xml +++ b/packages/CompanionDeviceManager/res/values/styles.xml @@ -119,7 +119,7 @@ <item name="android:layout_marginEnd">32dp</item> <item name="android:textColor">@android:color/system_neutral1_900</item> <item name="android:textAppearance">@android:style/TextAppearance.DeviceDefault.Medium</item> - <item name="android:background">@drawable/btn_positive_bottom</item> + <item name="android:background">@drawable/btn_positive_button</item> </style> <style name="NegativeButton" diff --git a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionAssociationActivity.java b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionAssociationActivity.java index ea40e13fdcc9..572fc3661f1c 100644 --- a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionAssociationActivity.java +++ b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionAssociationActivity.java @@ -176,6 +176,8 @@ public class CompanionAssociationActivity extends FragmentActivity implements // an association to CDM. private boolean mApproved; private boolean mCancelled; + // Indicates user has completely scrolled through the permissions list. + private boolean mIsPermissionsListScrolledToBottom; // A reference to the device selected by the user, to be sent back to the application via // onActivityResult() after the association is created. private @Nullable DeviceFilterPair<?> mSelectedDevice; @@ -670,10 +672,30 @@ public class CompanionAssociationActivity extends FragmentActivity implements private void onPositiveButtonClick(View v) { Slog.d(TAG, "onPositiveButtonClick()"); + // Scroll the permission list when a user presses the `Allow` button. + if (mPermissionListRecyclerView != null + && mPermissionListRecyclerView.isVisibleToUser() + && !mIsPermissionsListScrolledToBottom) { + LinearLayoutManager layoutManager = + (LinearLayoutManager) mPermissionListRecyclerView.getLayoutManager(); + if (layoutManager == null) return; + + int lastVisibleItemPosition = layoutManager.findLastCompletelyVisibleItemPosition(); + int firstVisibleItemPosition = layoutManager.findFirstCompletelyVisibleItemPosition(); + int scrollOffset = lastVisibleItemPosition - firstVisibleItemPosition; + int numItems = mPermissionListRecyclerView.getAdapter().getItemCount(); + + // Calculate the next scroll position with the offset + int nextScrollPosition = Math.min( + lastVisibleItemPosition + scrollOffset + 1, numItems - 1); + mPermissionListRecyclerView.smoothScrollToPosition(nextScrollPosition); + return; + } // Disable the button, to prevent more clicks. v.setEnabled(false); + // Approved the association creation if the list is scrolled to the bottom. if (mRequest.isSelfManaged()) { onAssociationApproved(null); } else { @@ -774,31 +796,48 @@ public class CompanionAssociationActivity extends FragmentActivity implements } } - // Disable and grey out the Allow and Don't allow buttons if the last permission in the + // 1. Disable and grey out the Don't allow button if the last permission in the // permission list is not visible to the users. + // 2. Remove the text for Allow button. + // 3. Set the background that includes the downward arrow icon. private void disableButtons() { - mButtonAllow.setEnabled(false); + mButtonAllow.setText(""); + mButtonAllow.setBackgroundResource(R.drawable.btn_positive_button_with_arrow); + mButtonAllow.setContentDescription(""); + mButtonAllow.setAccessibilityDelegate(new View.AccessibilityDelegate() { + public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { + super.onInitializeAccessibilityNodeInfo(host, info); + info.setContentDescription(getString(R.string.downward_arrow)); + info.addAction( + new AccessibilityNodeInfo.AccessibilityAction( + AccessibilityNodeInfo.ACTION_CLICK, + getString(R.string.downward_arrow_action) + ) + ); + } + }); + mButtonNotAllow.setEnabled(false); - mButtonAllow.setTextColor( - getResources().getColor(android.R.color.system_neutral1_400, null)); mButtonNotAllow.setTextColor( getResources().getColor(android.R.color.system_neutral1_400, null)); - mButtonAllow.getBackground().setColorFilter( - (new BlendModeColorFilter(Color.LTGRAY, BlendMode.DARKEN))); mButtonNotAllow.getBackground().setColorFilter( (new BlendModeColorFilter(Color.LTGRAY, BlendMode.DARKEN))); } - // Enable and restore the color for the Allow and Don't allow buttons if the last permission in - // the permission list is visible to the users. + // 1.Enable and restore the color for the Allow and Don't allow buttons if the + // last permission in the permission list is visible to the users. + // 2. Re-set the background for the Allow button which remove the downward arrow icon. private void enableButtons() { - mButtonAllow.setEnabled(true); + mButtonAllow.setText(R.string.consent_yes); + mButtonAllow.setBackgroundResource(R.drawable.btn_positive_button); + mButtonAllow.setContentDescription(getString(R.string.consent_yes)); + mButtonAllow.setAccessibilityDelegate(null); + mButtonNotAllow.setEnabled(true); - mButtonAllow.getBackground().setColorFilter(null); mButtonNotAllow.getBackground().setColorFilter(null); - mButtonAllow.setTextColor( - getResources().getColor(android.R.color.system_neutral1_900, null)); mButtonNotAllow.setTextColor( getResources().getColor(android.R.color.system_neutral1_900, null)); + + mIsPermissionsListScrolledToBottom = true; } private final ResultReceiver mOnAssociationCreatedReceiver = |