Search in sources :

Example 21 with AccessibilityManager

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) + "后,便可安全稳定的使用悬浮窗啦~", "去激活", "取消");
    }
}
Also used : AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) AccessibilityManager(android.view.accessibility.AccessibilityManager)

Example 22 with AccessibilityManager

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);
    }
}
Also used : AccessibilityManager(android.view.accessibility.AccessibilityManager) Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 23 with AccessibilityManager

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);
    }
}
Also used : AccessibilityManager(android.view.accessibility.AccessibilityManager) AccessibilityEvent(android.view.accessibility.AccessibilityEvent) AccessibilityManager(android.view.accessibility.AccessibilityManager)

Example 24 with AccessibilityManager

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;
}
Also used : Context(android.content.Context) AccessibilityManager(android.view.accessibility.AccessibilityManager) Time(android.text.format.Time) AccessibilityEvent(android.view.accessibility.AccessibilityEvent)

Example 25 with AccessibilityManager

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);
}
Also used : IAccessibilityManager(android.view.accessibility.IAccessibilityManager) IBinder(android.os.IBinder) AccessibilityManager(android.view.accessibility.AccessibilityManager) IAccessibilityManager(android.view.accessibility.IAccessibilityManager)

Aggregations

AccessibilityManager (android.view.accessibility.AccessibilityManager)118 AccessibilityEvent (android.view.accessibility.AccessibilityEvent)47 IAccessibilityManager (android.view.accessibility.IAccessibilityManager)43 MediumTest (android.test.suitebuilder.annotation.MediumTest)20 AccessibilityServiceInfo (android.accessibilityservice.AccessibilityServiceInfo)18 ArrayList (java.util.ArrayList)12 AccessibilityNodeProvider (android.view.accessibility.AccessibilityNodeProvider)7 ITransientNotification (android.app.ITransientNotification)6 Notification (android.app.Notification)6 UserInfo (android.content.pm.UserInfo)6 StatusBarNotification (android.service.notification.StatusBarNotification)6 ParcelableString (com.android.internal.util.ParcelableString)6 SuppressLint (android.annotation.SuppressLint)5 ServiceInfo (android.content.pm.ServiceInfo)5 LargeTest (android.test.suitebuilder.annotation.LargeTest)5 Context (android.content.Context)4 AttachInfo (android.view.View.AttachInfo)4 IAccessibilityManagerClient (android.view.accessibility.IAccessibilityManagerClient)4 ApplicationInfo (android.content.pm.ApplicationInfo)3 Paint (android.graphics.Paint)3