Accessibility of clear-all button

Making it visible to accessibility even when it’s completely hidden
behind a task. I had to mark it visible as a view. Now it’s invisible
only when there are no tasks in RecensView, to hide it from
accessibility.

Focusing on the button completely reveals it.

Bug: 72222505
Test: Manual
Change-Id: Ia31a1136e07faed93b4a44d5be69483d3b88364d
This commit is contained in:
Vadim Tryshev
2018-04-30 13:52:13 -07:00
parent 1e0b98fa6e
commit 4e3e54a45a
4 changed files with 91 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView
<com.android.quickstep.views.ClearAllButton
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/clear_all_button"
style="@android:style/Widget.DeviceDefault.Button.Borderless"
@@ -10,5 +10,6 @@
android:fontFamily="sans-serif-medium"
android:text="@string/recents_clear_all"
android:textColor="?attr/workspaceTextColor"
android:visibility="invisible"
android:textSize="14sp"
/>

View File

@@ -0,0 +1,55 @@
/*
* Copyright (C) 2018 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.quickstep.views;
import static android.view.accessibility.AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.TextView;
public class ClearAllButton extends TextView {
RecentsView mRecentsView;
public ClearAllButton(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public void setRecentsView(RecentsView recentsView) {
mRecentsView = recentsView;
}
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
// Should be visible to accessibility even when completely covered by the task.
// Otherwise, we won't be able to scroll to it.
info.setVisibleToUser(true);
}
@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
final boolean res = super.performAccessibilityAction(action, arguments);
if (action == ACTION_ACCESSIBILITY_FOCUS) {
mRecentsView.revealClearAllButton();
}
return res;
}
}

View File

@@ -264,6 +264,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
loader.unloadTaskData(task);
loader.getHighResThumbnailLoader().onTaskInvisible(task);
}
onChildViewsChanged();
}
public boolean isTaskViewVisible(TaskView tv) {
@@ -358,7 +359,6 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
if (mClearAllButton != null) {
final float alpha = calculateClearAllButtonAlpha();
mClearAllButton.setAlpha(alpha * mContentAlpha);
mClearAllButton.setVisibility(alpha == 0 ? INVISIBLE : VISIBLE);
}
}
@@ -371,7 +371,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN && mTouchState == TOUCH_STATE_REST
&& mScroller.isFinished() && mClearAllButton.getVisibility() == View.VISIBLE) {
&& mScroller.isFinished() && mClearAllButton.getAlpha() > 0) {
mClearAllButton.getHitRect(mTempRect);
mTempRect.offset(-getLeft(), -getTop());
if (mTempRect.contains((int) ev.getX(), (int) ev.getY())) {
@@ -1011,6 +1011,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
super.onViewAdded(child);
child.setAlpha(mContentAlpha);
setAdjacentScale(mAdjacentScale);
onChildViewsChanged();
}
@Override
@@ -1243,4 +1244,15 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
mClearAllButton = clearAllButton;
updateClearAllButtonAlpha();
}
private void onChildViewsChanged() {
final int childCount = getChildCount();
mClearAllButton.setAccessibilityTraversalAfter(
childCount == 0 ? NO_ID : getChildAt(childCount - 1).getId());
mClearAllButton.setVisibility(childCount == 0 ? INVISIBLE : VISIBLE);
}
public void revealClearAllButton() {
scrollTo(mIsRtl ? 0 : computeMaxScrollX(), 0);
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright (C) 2018 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.quickstep.views;
import static com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch.TAP;
@@ -9,7 +25,6 @@ import android.util.AttributeSet;
import android.util.FloatProperty;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import com.android.launcher3.InsettableFrameLayout;
import com.android.launcher3.R;
@@ -31,7 +46,7 @@ public class RecentsViewContainer extends InsettableFrameLayout {
private final Rect mTempRect = new Rect();
private RecentsView mRecentsView;
private View mClearAllButton;
private ClearAllButton mClearAllButton;
public RecentsViewContainer(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -48,13 +63,15 @@ public class RecentsViewContainer extends InsettableFrameLayout {
mRecentsView.dismissAllTasks();
});
mRecentsView = (RecentsView) findViewById(R.id.overview_panel);
mRecentsView = findViewById(R.id.overview_panel);
final InsettableFrameLayout.LayoutParams params =
(InsettableFrameLayout.LayoutParams) mClearAllButton.getLayoutParams();
params.gravity = Gravity.TOP | (RecentsView.FLIP_RECENTS ? Gravity.START : Gravity.END);
mClearAllButton.setLayoutParams(params);
mClearAllButton.forceHasOverlappingRendering(false);
mRecentsView.setClearAllButton(mClearAllButton);
mClearAllButton.setRecentsView(mRecentsView);
}
@Override