Skip to content

Commit

Permalink
[hapjs-platform#631]【1300联盟版本】无障碍新增组件属性方法(rfc:hapjs-platform#2)
Browse files Browse the repository at this point in the history
Change-Id: Id0fbb4c35a47e84152b57ea1c5440ede7e89984a
  • Loading branch information
mingcan-mc committed Dec 13, 2023
1 parent 41bbd82 commit bff75ee
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.ProgressBar;
import java.util.Map;
import org.hapjs.bridge.annotation.TypeAnnotation;
Expand All @@ -26,6 +27,7 @@
import org.hapjs.component.view.gesture.IGesture;
import org.hapjs.component.view.keyevent.KeyEventDelegate;
import org.hapjs.runtime.HapEngine;
import org.hapjs.widgets.R;

@WidgetAnnotation(
name = Progress.WIDGET_NAME,
Expand Down Expand Up @@ -157,5 +159,19 @@ private boolean onKey(int keyAction, int keyCode, KeyEvent event, boolean result
result |= mKeyEventDelegate.onKey(keyAction, keyCode, event);
return result;
}

@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
info.setClassName("");
info.setClickable(false);
info.removeAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK);
if (getProgress() >= 0) {
info.setText(mContext.getResources().getString(R.string.talkback_progress_percent)
+ getProgress()
+ " "
+ mContext.getResources().getString(R.string.talkback_progress));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Build;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.FrameLayout;
import android.widget.ProgressBar;

import androidx.annotation.RequiresApi;

import java.util.Map;
import org.hapjs.bridge.annotation.TypeAnnotation;
import org.hapjs.bridge.annotation.WidgetAnnotation;
Expand All @@ -25,6 +31,7 @@
import org.hapjs.component.constants.Attributes;
import org.hapjs.component.view.GestureFrameLayout;
import org.hapjs.runtime.HapEngine;
import org.hapjs.widgets.R;

@WidgetAnnotation(
name = Progress.WIDGET_NAME,
Expand Down Expand Up @@ -81,6 +88,7 @@ protected FrameLayout createViewImpl() {
layer.setId(1, android.R.id.progress);

mProgressBar = new ProgressBar(mContext, null, android.R.attr.progressBarStyleHorizontal);
initTalkBack();
mProgressBar.setProgressDrawable(layer);
FrameLayout.LayoutParams lp =
new FrameLayout.LayoutParams(
Expand All @@ -93,6 +101,41 @@ protected FrameLayout createViewImpl() {
return frameLayout;
}

private void initTalkBack() {
if (isEnableTalkBack() && null != mProgressBar) {
mProgressBar.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(View v) {
mProgressBar.setAccessibilityDelegate(new View.AccessibilityDelegate() {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(host, info);
info.setClassName("");
info.setClickable(false);
info.removeAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK);
if (null != mProgressBar && mProgressBar.getProgress() >= 0 && null != mContext) {
info.setText(mContext.getResources().getString(R.string.talkback_progress_percent)
+ mProgressBar.getProgress()
+ " "
+ mContext.getResources().getString(R.string.talkback_progress_percent));
}

}
});
}

@Override
public void onViewDetachedFromWindow(View v) {
if (null != mProgressBar) {
mProgressBar.setAccessibilityDelegate(null);
mProgressBar.removeOnAttachStateChangeListener(this);
}
}
});
}
}

@Override
protected boolean setAttribute(String key, Object attribute) {
switch (key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public void setValue(String value) {
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
initTallkback(info);
initTalkBack(info);
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void initTallkback(AccessibilityNodeInfo info) {
private void initTalkBack(AccessibilityNodeInfo info) {
if (mIsEnableTalkBack && null != info) {
info.removeAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK);
info.setClassName("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public FlexEditText(Context context, boolean isEnableTalkBack) {
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void initTallkback(AccessibilityNodeInfo info) {
private void initTalkBack(AccessibilityNodeInfo info) {
if (mIsEnableTalkBack && null != info) {
info.removeAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK);
info.removeAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_LONG_CLICK);
Expand Down Expand Up @@ -89,7 +89,7 @@ private void initTallkback(AccessibilityNodeInfo info) {
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
initTallkback(info);
initTalkBack(info);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void setValue(String value) {
this.mValue = value;
}

private void initTallkback(AccessibilityNodeInfo info) {
private void initTalkBack(AccessibilityNodeInfo info) {
if (mIsEnableTalkBack && null != info) {
info.removeAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK);
info.setClassName("");
Expand Down Expand Up @@ -70,7 +70,7 @@ private void initTallkback(AccessibilityNodeInfo info) {
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
initTallkback(info);
initTalkBack(info);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,12 @@
<string name="popup_window_default_title">弹出式窗口</string>
<string name="talkback_close">关闭-按钮</string>
<string name="talkback_common_button">按钮</string>
<!--progress-->
<string name="talkback_progress_percent">百分之</string>
<string name="talkback_progress">进度条</string>
<!--video 无障碍-->
<string name="talkback_video_controller_play">播放</string>
<string name="talkback_video_controller_pause">暂停</string>
<string name="talkback_video_controller_full_screen">全屏</string>
<string name="talkback_video_controller_exit_full_screen">退出全屏</string>
</resources>
9 changes: 8 additions & 1 deletion core/runtime/android/widgets/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@
<string name="shortcut_add_shortcut_mini">Add to desktop</string>
<string name="shortcut_add_shortcut_desktop">Add to desktop</string>
<string name="shortcut_add_shortcut_long">Add to desktop</string>

<!--progress-->
<string name="talkback_progress_percent">Percent</string>
<string name="talkback_progress">Progress bar</string>
<!--video 无障碍-->
<string name="talkback_video_controller_play">play</string>
<string name="talkback_video_controller_pause">pause</string>
<string name="talkback_video_controller_full_screen">full screen</string>
<string name="talkback_video_controller_exit_full_screen">exit full screen</string>
<!--menubar 无障碍-->
<string name="talkback_titlebar_left_menu_iv">more-button</string>
<string name="popup_window_default_title">pop-up window</string>
Expand Down

0 comments on commit bff75ee

Please sign in to comment.