You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by cx...@apache.org on 2017/03/29 06:49:02 UTC
[10/18] incubator-weex git commit: * [android] add support for
aria-label and aria-hidden
* [android] add support for aria-label and aria-hidden
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/c15a7183
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/c15a7183
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/c15a7183
Branch: refs/heads/0.12-dev
Commit: c15a718317bd8e5f6ebbfdfa264e4fbce43565ae
Parents: 213a2a3
Author: sospartan <so...@apache.org>
Authored: Thu Mar 23 16:11:18 2017 +0800
Committer: sospartan <so...@apache.org>
Committed: Thu Mar 23 16:11:18 2017 +0800
----------------------------------------------------------------------
.../java/com/taobao/weex/common/Constants.java | 3 ++-
.../com/taobao/weex/ui/component/WXComponent.java | 16 +++++++++++++++-
.../java/com/taobao/weex/ui/component/WXText.java | 8 ++++++++
.../java/com/taobao/weex/ui/view/WXTextView.java | 18 +++++++++++++++++-
4 files changed, 42 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/c15a7183/android/sdk/src/main/java/com/taobao/weex/common/Constants.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/common/Constants.java b/android/sdk/src/main/java/com/taobao/weex/common/Constants.java
index c3d1190..57f6386 100755
--- a/android/sdk/src/main/java/com/taobao/weex/common/Constants.java
+++ b/android/sdk/src/main/java/com/taobao/weex/common/Constants.java
@@ -358,7 +358,8 @@ public class Constants {
String DELETE_CELL_ANIMATION = "deleteAnimation";
String AUTO = "auto";
String NORMAL = "normal";
- String ARIA_LABEL = "aria-label";
+ String ARIA_LABEL = "ariaLabel";
+ String ARIA_HIDDEN = "ariaHidden";
}
public interface Value {
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/c15a7183/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java
index e4da406..8c1a622 100755
--- a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java
+++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java
@@ -127,6 +127,7 @@
*/
package com.taobao.weex.ui.component;
+import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
@@ -135,6 +136,7 @@ import android.graphics.Rect;
import android.graphics.Shader;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
+import android.os.Build;
import android.os.Message;
import android.support.annotation.CallSuper;
import android.support.annotation.CheckResult;
@@ -767,6 +769,10 @@ public abstract class WXComponent<T extends View> implements IWXObject, IWXActi
String label = WXUtils.getString(param,"");
setAriaLabel(label);
return true;
+ case Constants.Name.ARIA_HIDDEN:
+ boolean isHidden = WXUtils.getBoolean(param,false);
+ setAriaHidden(isHidden);
+ return true;
case Constants.Name.WIDTH:
case Constants.Name.MIN_WIDTH:
case Constants.Name.MAX_WIDTH:
@@ -799,7 +805,15 @@ public abstract class WXComponent<T extends View> implements IWXObject, IWXActi
}
}
- private void setAriaLabel(String label) {
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
+ protected void setAriaHidden(boolean isHidden) {
+ View host = getHostView();
+ if(host != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){
+ host.setImportantForAccessibility(isHidden?View.IMPORTANT_FOR_ACCESSIBILITY_NO:View.IMPORTANT_FOR_ACCESSIBILITY_YES);
+ }
+ }
+
+ protected void setAriaLabel(String label) {
View host = getHostView();
if(host != null){
host.setContentDescription(label);
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/c15a7183/android/sdk/src/main/java/com/taobao/weex/ui/component/WXText.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXText.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXText.java
index a85c644..f1b3e0e 100755
--- a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXText.java
+++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXText.java
@@ -264,6 +264,14 @@ public class WXText extends WXComponent<WXTextView> {
}
@Override
+ protected void setAriaLabel(String label) {
+ WXTextView text = getHostView();
+ if(text != null){
+ text.setAriaLabel(label);
+ }
+ }
+
+ @Override
public void refreshData(WXComponent component) {
super.refreshData(component);
if (component instanceof WXText) {
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/c15a7183/android/sdk/src/main/java/com/taobao/weex/ui/view/WXTextView.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/view/WXTextView.java b/android/sdk/src/main/java/com/taobao/weex/ui/view/WXTextView.java
index d56b196..763328b 100755
--- a/android/sdk/src/main/java/com/taobao/weex/ui/view/WXTextView.java
+++ b/android/sdk/src/main/java/com/taobao/weex/ui/view/WXTextView.java
@@ -207,6 +207,7 @@ package com.taobao.weex.ui.view;
import android.content.Context;
import android.graphics.Canvas;
import android.text.Layout;
+import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
@@ -225,6 +226,8 @@ public class WXTextView extends View implements WXGestureObservable, IWXTextView
private WeakReference<WXText> mWeakReference;
private WXGesture wxGesture;
private Layout textLayout;
+ private boolean mIsLabelSet = false;
+
public WXTextView(Context context) {
super(context);
}
@@ -266,7 +269,7 @@ public class WXTextView extends View implements WXGestureObservable, IWXTextView
public void setTextLayout(Layout layout) {
this.textLayout = layout;
- if(layout!=null){
+ if(layout!=null && !mIsLabelSet){
setContentDescription(layout.getText());
}
if (mWeakReference != null) {
@@ -277,6 +280,19 @@ public class WXTextView extends View implements WXGestureObservable, IWXTextView
}
}
+ public void setAriaLabel(String label){
+ if(!TextUtils.isEmpty(label)){
+ mIsLabelSet = true;
+ setContentDescription(label);
+ }else{
+ mIsLabelSet = false;
+ if(textLayout != null){
+ setContentDescription(textLayout.getText());
+ }
+ }
+
+ }
+
@Override
public void holdComponent(WXText component) {
mWeakReference = new WeakReference<>(component);