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: Ia81638db5794c25e3f24cafb3e0fe6f2b5e21569
  • Loading branch information
mingcan-mc committed Dec 13, 2023
1 parent d196ac0 commit 497e6a5
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,78 @@
package org.hapjs.widgets.view.text;

import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.accessibility.AccessibilityNodeInfo;

import androidx.annotation.RequiresApi;
import androidx.appcompat.widget.AppCompatCheckBox;
import org.hapjs.component.Component;
import org.hapjs.component.view.ComponentHost;
import org.hapjs.component.view.gesture.GestureHost;
import org.hapjs.component.view.gesture.IGesture;
import org.hapjs.component.view.helper.StateHelper;
import org.hapjs.component.view.keyevent.KeyEventDelegate;
import org.hapjs.widgets.R;

public class FlexCheckBox extends AppCompatCheckBox implements ComponentHost, GestureHost {
private Component mComponent;
private KeyEventDelegate mKeyEventDelegate;

private IGesture mGesture;
private boolean mIsEnableTalkBack;
private String mValue;

public FlexCheckBox(Context context) {
super(context);
}

public FlexCheckBox(Context context, boolean isEnableTalkBack) {
super(context);
mIsEnableTalkBack = isEnableTalkBack;
}

public void setValue(String value) {
this.mValue = value;
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
initTallkback(info);
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void initTallkback(AccessibilityNodeInfo info) {
if (mIsEnableTalkBack && null != info) {
info.removeAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK);
info.setClassName("");
info.setCheckable(false);
info.setClickable(false);
String realTextStr = "";
if (!TextUtils.isEmpty(mValue)) {
realTextStr = mValue;
}
if (TextUtils.isEmpty(realTextStr)) {
info.setText((isChecked() ? getResources().getString(R.string.talkback_selected) : getResources().getString(R.string.talkback_unselected))
+ " "
+ getResources().getString(R.string.talkback_checkbox)
+ " "
+ getResources().getString(R.string.talkback_no_use));
} else {
info.setText((isChecked() ? getResources().getString(R.string.talkback_selected) : getResources().getString(R.string.talkback_unselected))
+ " "
+ realTextStr
+ " "
+ getResources().getString(R.string.talkback_press_active_min)
+ (isChecked() ? getResources().getString(R.string.talkback_cancel_select) : getResources().getString(R.string.talkback_select)));
}
}
}

@Override
protected void drawableStateChanged() {
super.drawableStateChanged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
package org.hapjs.widgets.view.text;

import android.content.Context;
import android.os.Build;
import android.text.Editable;
import android.text.Spannable;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputConnectionWrapper;
import android.view.inputmethod.InputMethodManager;

import androidx.annotation.RequiresApi;
import androidx.appcompat.widget.AppCompatAutoCompleteTextView;
import org.hapjs.common.compat.BuildPlatform;
import org.hapjs.component.Component;
Expand All @@ -23,6 +27,7 @@
import org.hapjs.component.view.gesture.IGesture;
import org.hapjs.component.view.helper.StateHelper;
import org.hapjs.component.view.keyevent.KeyEventDelegate;
import org.hapjs.widgets.R;
import org.hapjs.widgets.input.Edit;

public class FlexEditText extends AppCompatAutoCompleteTextView
Expand All @@ -35,12 +40,58 @@ public class FlexEditText extends AppCompatAutoCompleteTextView
private IGesture mGesture;
private boolean mAutoCompleted = true;
private boolean mLastWindowFocus = false;
private boolean mIsEnableTalkBack;

public FlexEditText(Context context) {
super(context);
setThreshold(0);
}

public FlexEditText(Context context, boolean isEnableTalkBack) {
super(context);
setThreshold(0);
mIsEnableTalkBack = isEnableTalkBack;
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void initTallkback(AccessibilityNodeInfo info) {
if (mIsEnableTalkBack && null != info) {
info.removeAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK);
info.removeAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_LONG_CLICK);
info.setClickable(false);
info.setLongClickable(false);
info.setClassName("");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
info.setHintText("");
}
Editable curTextStr = getText();
String realTextStr = "";
if (null != curTextStr && !TextUtils.isEmpty(curTextStr.toString())) {
realTextStr = curTextStr.toString();
}
if (TextUtils.isEmpty(realTextStr)) {
info.setText(getResources().getString(R.string.talkback_edit_input)
+ " "
+ getResources().getString(R.string.talkback_press_active));
} else {
info.setText((!TextUtils.isEmpty(getHint()) ? getHint() : "")
+ " "
+ getResources().getString(R.string.talkback_edit)
+ " "
+ (!TextUtils.isEmpty(realTextStr) ? realTextStr : "")
+ " "
+ getResources().getString(R.string.talkback_press_active_more));
}
}
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
initTallkback(info);
}

@Override
protected void drawableStateChanged() {
super.drawableStateChanged();
Expand Down

0 comments on commit 497e6a5

Please sign in to comment.