use of android.view.accessibility.AccessibilityManager in project Float-Bar by tianzhijiexian.
the class MainActivity method onResume.
@Override
protected void onResume() {
super.onResume();
AccessibilityManager manager = (AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE);
List<AccessibilityServiceInfo> list = AccessibilityManagerCompat.getEnabledAccessibilityServiceList(manager, AccessibilityServiceInfo.FEEDBACK_ALL_MASK);
System.out.println("list.size = " + list.size());
for (int i = 0; i < list.size(); i++) {
System.out.println("已经可用的服务列表 = " + list.get(i).getId());
if ("com.kale.floatbar/.service.FloatService".equals(list.get(i).getId())) {
System.out.println("已启用");
isEnabled = true;
break;
}
}
if (!isEnabled) {
showDialog(this, "激活悬浮窗", "您还没有激活悬浮窗。" + "在设置中:系统 → 辅助功能 → 服务 中激活" + getResources().getString(R.string.app_name) + "后,便可安全稳定的使用悬浮窗啦~", "去激活", "取消");
}
}
use of android.view.accessibility.AccessibilityManager in project XobotOS by xamarin.
the class WebView method injectAccessibilityForUrl.
/**
* This method injects accessibility in the loaded document if accessibility
* is enabled. If JavaScript is enabled we try to inject a URL specific script.
* If no URL specific script is found or JavaScript is disabled we fallback to
* the default {@link AccessibilityInjector} implementation.
* </p>
* If the URL has the "axs" paramter set to 1 it has already done the
* script injection so we do nothing. If the parameter is set to 0
* the URL opts out accessibility script injection so we fall back to
* the default {@link AccessibilityInjector}.
* </p>
* Note: If the user has not opted-in the accessibility script injection no scripts
* are injected rather the default {@link AccessibilityInjector} implementation
* is used.
*
* @param url The URL loaded by this {@link WebView}.
*/
private void injectAccessibilityForUrl(String url) {
if (mWebViewCore == null) {
return;
}
AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(mContext);
if (!accessibilityManager.isEnabled()) {
// it is possible that accessibility was turned off between reloads
ensureAccessibilityScriptInjectorInstance(false);
return;
}
if (!getSettings().getJavaScriptEnabled()) {
// no JS so we fallback to the basic buil-in support
ensureAccessibilityScriptInjectorInstance(true);
return;
}
// check the URL "axs" parameter to choose appropriate action
int axsParameterValue = getAxsUrlParameterValue(url);
if (axsParameterValue == ACCESSIBILITY_SCRIPT_INJECTION_UNDEFINED) {
boolean onDeviceScriptInjectionEnabled = (Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION, 0) == 1);
if (onDeviceScriptInjectionEnabled) {
ensureAccessibilityScriptInjectorInstance(false);
// neither script injected nor script injection opted out => we inject
loadUrl(ACCESSIBILITY_SCRIPT_CHOOSER_JAVASCRIPT);
// TODO: Set this flag after successfull script injection. Maybe upon injection
// the chooser should update the meta tag and we check it to declare success
mAccessibilityScriptInjected = true;
} else {
// injection disabled so we fallback to the basic built-in support
ensureAccessibilityScriptInjectorInstance(true);
}
} else if (axsParameterValue == ACCESSIBILITY_SCRIPT_INJECTION_OPTED_OUT) {
// injection opted out so we fallback to the basic buil-in support
ensureAccessibilityScriptInjectorInstance(true);
} else if (axsParameterValue == ACCESSIBILITY_SCRIPT_INJECTION_PROVIDED) {
ensureAccessibilityScriptInjectorInstance(false);
// the URL provides accessibility but we still need to add our generic script
loadUrl(ACCESSIBILITY_SCRIPT_CHOOSER_JAVASCRIPT);
} else {
Log.e(LOGTAG, "Unknown URL value for the \"axs\" URL parameter: " + axsParameterValue);
}
}
use of android.view.accessibility.AccessibilityManager in project ZI by yixia.
the class Manager method announceForAccessibilityCompat.
/**
* Generates and dispatches an SDK-specific spoken announcement.
* <p>
* For backwards compatibility, we're constructing an event from scratch
* using the appropriate event type. If your application only targets SDK
* 16+, you can just call View.announceForAccessibility(CharSequence).
* </p>
* <p/>
* note: AccessibilityManager is only available from API lvl 4.
* <p/>
* Adapted from https://http://eyes-free.googlecode.com/files/accessibility_codelab_demos_v2_src.zip
* via https://github.com/coreform/android-formidable-validation
*
* @param context
* Used to get {@link AccessibilityManager}
* @param text
* The text to announce.
*/
public static void announceForAccessibilityCompat(Context context, CharSequence text) {
if (Build.VERSION.SDK_INT >= 4) {
AccessibilityManager accessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
if (!accessibilityManager.isEnabled()) {
return;
}
// Prior to SDK 16, announcements could only be made through FOCUSED
// events. Jelly Bean (SDK 16) added support for speaking text verbatim
// using the ANNOUNCEMENT event type.
final int eventType;
if (Build.VERSION.SDK_INT < 16) {
eventType = AccessibilityEvent.TYPE_VIEW_FOCUSED;
} else {
eventType = AccessibilityEventCompat.TYPE_ANNOUNCEMENT;
}
// Construct an accessibility event with the minimum recommended
// attributes. An event without a class name or package may be dropped.
final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
event.getText().add(text);
event.setClassName(Manager.class.getName());
event.setPackageName(context.getPackageName());
// Sends the event directly through the accessibility manager. If your
// application only targets SDK 14+, you should just call
// getParent().requestSendAccessibilityEvent(this, event);
accessibilityManager.sendAccessibilityEvent(event);
}
}
use of android.view.accessibility.AccessibilityManager in project Etar-Calendar by Etar-Group.
the class SimpleWeekView method onHoverEvent.
@Override
public boolean onHoverEvent(MotionEvent event) {
Context context = getContext();
// only send accessibility events if accessibility and exploration are
// on.
AccessibilityManager am = (AccessibilityManager) context.getSystemService(Service.ACCESSIBILITY_SERVICE);
if (!am.isEnabled() || !am.isTouchExplorationEnabled()) {
return super.onHoverEvent(event);
}
if (event.getAction() != MotionEvent.ACTION_HOVER_EXIT) {
Time hover = getDayFromLocation(event.getX());
if (hover != null && (mLastHoverTime == null || Time.compare(hover, mLastHoverTime) != 0)) {
Long millis = hover.toMillis(true);
String date = Utils.formatDateRange(context, millis, millis, DateUtils.FORMAT_SHOW_DATE);
AccessibilityEvent accessEvent = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
accessEvent.getText().add(date);
sendAccessibilityEventUnchecked(accessEvent);
mLastHoverTime = hover;
}
}
return true;
}
use of android.view.accessibility.AccessibilityManager in project android_frameworks_base by DirtyUnicorns.
the class DevicePolicyManagerService method getAccessibilityManagerForUser.
private AccessibilityManager getAccessibilityManagerForUser(int userId) {
// Not using AccessibilityManager.getInstance because that guesses
// at the user you require based on callingUid and caches for a given
// process.
IBinder iBinder = ServiceManager.getService(Context.ACCESSIBILITY_SERVICE);
IAccessibilityManager service = iBinder == null ? null : IAccessibilityManager.Stub.asInterface(iBinder);
return new AccessibilityManager(mContext, service, userId);
}
Aggregations