diff options
author | 2025-01-30 23:49:23 +0000 | |
---|---|---|
committer | 2025-02-21 00:22:24 +0000 | |
commit | 83d87e4275780db8473e512e82e4ad6330f2a254 (patch) | |
tree | 1f1f2704a7ac854606a96799ac5f1030936c7033 /packages/CompanionDeviceManager/src | |
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
Diffstat (limited to 'packages/CompanionDeviceManager/src')
-rw-r--r-- | packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionAssociationActivity.java | 63 |
1 files changed, 51 insertions, 12 deletions
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 = |