diff options
| author | Selim Cinek <cinek@google.com> | 2016-06-16 04:25:26 +0000 |
|---|---|---|
| committer | android-build-merger <android-build-merger@google.com> | 2016-06-16 04:25:26 +0000 |
| commit | 447ee9975501aa1fe1ff2cd0c83eadebb0fd66cd (patch) | |
| tree | 63b2d58f93cd7dc282562d393d63154cedca66c2 /core/java | |
| parent | c3e651cb528e9aa779fcbd637ed0f74bcaaa692f (diff) | |
| parent | c1720dce1b01893bf925267381ff4975095a718a (diff) | |
Merge \"Added dismiss, expand, and collapse accessibility actions\" into nyc-dev
am: c1720dce1b
Change-Id: I14674254eb79fef58e4dcb1a8d7ecaab24831691
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/view/NotificationHeaderView.java | 46 | ||||
| -rw-r--r-- | core/java/com/android/internal/widget/NotificationExpandButton.java | 62 |
2 files changed, 94 insertions, 14 deletions
diff --git a/core/java/android/view/NotificationHeaderView.java b/core/java/android/view/NotificationHeaderView.java index 3069e5ade582..c46acae38c2c 100644 --- a/core/java/android/view/NotificationHeaderView.java +++ b/core/java/android/view/NotificationHeaderView.java @@ -22,6 +22,7 @@ import android.graphics.Canvas; import android.graphics.Outline; import android.graphics.Rect; import android.graphics.drawable.Drawable; +import android.os.Bundle; import android.util.AttributeSet; import android.view.accessibility.AccessibilityNodeInfo; import android.widget.ImageView; @@ -63,6 +64,33 @@ public class NotificationHeaderView extends ViewGroup { } } }; + final AccessibilityDelegate mExpandDelegate = new AccessibilityDelegate() { + + @Override + public boolean performAccessibilityAction(View host, int action, Bundle args) { + if (super.performAccessibilityAction(host, action, args)) { + return true; + } + if (action == AccessibilityNodeInfo.ACTION_COLLAPSE + || action == AccessibilityNodeInfo.ACTION_EXPAND) { + mExpandClickListener.onClick(mExpandButton); + return true; + } + return false; + } + + @Override + public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { + super.onInitializeAccessibilityNodeInfo(host, info); + // Avoid that the button description is also spoken + info.setClassName(getClass().getName()); + if (mExpanded) { + info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_COLLAPSE); + } else { + info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_EXPAND); + } + } + }; public NotificationHeaderView(Context context) { this(context, null); @@ -92,6 +120,9 @@ public class NotificationHeaderView extends ViewGroup { mAppName = findViewById(com.android.internal.R.id.app_name_text); mHeaderText = findViewById(com.android.internal.R.id.header_text); mExpandButton = (ImageView) findViewById(com.android.internal.R.id.expand_button); + if (mExpandButton != null) { + mExpandButton.setAccessibilityDelegate(mExpandDelegate); + } mIcon = findViewById(com.android.internal.R.id.icon); mProfileBadge = findViewById(com.android.internal.R.id.profile_badge); } @@ -230,7 +261,7 @@ public class NotificationHeaderView extends ViewGroup { public void setOnClickListener(@Nullable OnClickListener l) { mExpandClickListener = l; setOnTouchListener(mExpandClickListener != null ? mTouchListener : null); - setFocusable(l != null); + mExpandButton.setOnClickListener(mExpandClickListener); updateTouchListener(); } @@ -380,19 +411,6 @@ public class NotificationHeaderView extends ViewGroup { return this; } - @Override - public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { - super.onInitializeAccessibilityNodeInfo(info); - if (mExpandClickListener != null) { - AccessibilityNodeInfo.AccessibilityAction expand - = new AccessibilityNodeInfo.AccessibilityAction( - AccessibilityNodeInfo.ACTION_CLICK, - getContext().getString( - com.android.internal.R.string.expand_action_accessibility)); - info.addAction(expand); - } - } - public ImageView getExpandButton() { return mExpandButton; } diff --git a/core/java/com/android/internal/widget/NotificationExpandButton.java b/core/java/com/android/internal/widget/NotificationExpandButton.java new file mode 100644 index 000000000000..f4f49b1e4ffe --- /dev/null +++ b/core/java/com/android/internal/widget/NotificationExpandButton.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2016 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.internal.widget; + +import android.annotation.Nullable; +import android.content.Context; +import android.graphics.Rect; +import android.util.AttributeSet; +import android.widget.ImageView; +import android.widget.RemoteViews; + +/** + * An expand button in a notification + */ +@RemoteViews.RemoteView +public class NotificationExpandButton extends ImageView { + public NotificationExpandButton(Context context) { + super(context); + } + + public NotificationExpandButton(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + } + + public NotificationExpandButton(Context context, @Nullable AttributeSet attrs, + int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public NotificationExpandButton(Context context, @Nullable AttributeSet attrs, int defStyleAttr, + int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + @Override + public void getBoundsOnScreen(Rect outRect, boolean clipToParent) { + super.getBoundsOnScreen(outRect, clipToParent); + extendRectToMinTouchSize(outRect); + } + + private void extendRectToMinTouchSize(Rect rect) { + int touchTargetSize = (int) (getResources().getDisplayMetrics().density * 48); + rect.left = rect.centerX() - touchTargetSize / 2; + rect.right = rect.left + touchTargetSize; + rect.top = rect.centerY() - touchTargetSize / 2; + rect.bottom = rect.top + touchTargetSize; + } +} |
