android.support.v4.view.accessibility.AccessibilityManagerCompat Java Examples

The following examples show how to use android.support.v4.view.accessibility.AccessibilityManagerCompat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExploreByTouchHelper.java    From letv with Apache License 2.0 6 votes vote down vote up
public boolean dispatchHoverEvent(MotionEvent event) {
    boolean z = true;
    if (!this.mManager.isEnabled() || !AccessibilityManagerCompat.isTouchExplorationEnabled(this.mManager)) {
        return false;
    }
    switch (event.getAction()) {
        case 7:
        case 9:
            int virtualViewId = getVirtualViewAt(event.getX(), event.getY());
            updateHoveredVirtualView(virtualViewId);
            if (virtualViewId == Integer.MIN_VALUE) {
                z = false;
            }
            return z;
        case 10:
            if (this.mFocusedVirtualViewId == Integer.MIN_VALUE) {
                return false;
            }
            updateHoveredVirtualView(Integer.MIN_VALUE);
            return true;
        default:
            return false;
    }
}
 
Example #2
Source File: MainActivity.java    From Float-Bar with Eclipse Public License 1.0 6 votes vote down vote up
@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)
				+ "后,便可安全稳定的使用悬浮窗啦~", "去激活", "取消");
	}
}
 
Example #3
Source File: ExploreByTouchHelper.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
/**
 * Dispatches hover {@link MotionEvent}s to the virtual view hierarchy when
 * the Explore by Touch feature is enabled.
 * <p>
 * This method should be called by overriding
 * {@link View#dispatchHoverEvent}:
 *
 * <pre>&#64;Override
 * public boolean dispatchHoverEvent(MotionEvent event) {
 *   if (mHelper.dispatchHoverEvent(this, event) {
 *     return true;
 *   }
 *   return super.dispatchHoverEvent(event);
 * }
 * </pre>
 *
 * @param event The hover event to dispatch to the virtual view hierarchy.
 * @return Whether the hover event was handled.
 */
public boolean dispatchHoverEvent(MotionEvent event) {
    if (!mManager.isEnabled()
            || !AccessibilityManagerCompat.isTouchExplorationEnabled(mManager)) {
        return false;
    }

    switch (event.getAction()) {
        case MotionEventCompat.ACTION_HOVER_MOVE:
        case MotionEventCompat.ACTION_HOVER_ENTER:
            final int virtualViewId = getVirtualViewAt(event.getX(), event.getY());
            updateHoveredVirtualView(virtualViewId);
            return (virtualViewId != INVALID_ID);
        case MotionEventCompat.ACTION_HOVER_EXIT:
            if (mFocusedVirtualViewId != INVALID_ID) {
                updateHoveredVirtualView(INVALID_ID);
                return true;
            }
            return false;
        default:
            return false;
    }
}
 
Example #4
Source File: ExploreByTouchHelper.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
/**
 * Attempts to give accessibility focus to a virtual view.
 * <p>
 * A virtual view will not actually take focus if
 * {@link AccessibilityManager#isEnabled()} returns false,
 * {@link AccessibilityManager#isTouchExplorationEnabled()} returns false,
 * or the view already has accessibility focus.
 *
 * @param virtualViewId The id of the virtual view on which to place
 *            accessibility focus.
 * @return Whether this virtual view actually took accessibility focus.
 */
private boolean requestAccessibilityFocus(int virtualViewId) {
    if (!mManager.isEnabled()
            || !AccessibilityManagerCompat.isTouchExplorationEnabled(mManager)) {
        return false;
    }
    // TODO: Check virtual view visibility.
    if (!isAccessibilityFocused(virtualViewId)) {
        mFocusedVirtualViewId = virtualViewId;
        // TODO: Only invalidate virtual view bounds.
        mView.invalidate();
        sendEventForVirtualView(virtualViewId,
                AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
        return true;
    }
    return false;
}
 
Example #5
Source File: ExploreByTouchHelper.java    From android-recipes-app with Apache License 2.0 6 votes vote down vote up
/**
 * Dispatches hover {@link MotionEvent}s to the virtual view hierarchy when
 * the Explore by Touch feature is enabled.
 * <p>
 * This method should be called by overriding
 * {@link View#dispatchHoverEvent}:
 *
 * <pre>&#64;Override
 * public boolean dispatchHoverEvent(MotionEvent event) {
 *   if (mHelper.dispatchHoverEvent(this, event) {
 *     return true;
 *   }
 *   return super.dispatchHoverEvent(event);
 * }
 * </pre>
 *
 * @param event The hover event to dispatch to the virtual view hierarchy.
 * @return Whether the hover event was handled.
 */
public boolean dispatchHoverEvent(MotionEvent event) {
    if (!mManager.isEnabled()
            || !AccessibilityManagerCompat.isTouchExplorationEnabled(mManager)) {
        return false;
    }

    switch (event.getAction()) {
        case MotionEventCompat.ACTION_HOVER_MOVE:
        case MotionEventCompat.ACTION_HOVER_ENTER:
            final int virtualViewId = getVirtualViewAt(event.getX(), event.getY());
            updateHoveredVirtualView(virtualViewId);
            return (virtualViewId != INVALID_ID);
        case MotionEventCompat.ACTION_HOVER_EXIT:
            if (mFocusedVirtualViewId != INVALID_ID) {
                updateHoveredVirtualView(INVALID_ID);
                return true;
            }
            return false;
        default:
            return false;
    }
}
 
Example #6
Source File: ExploreByTouchHelper.java    From android-recipes-app with Apache License 2.0 6 votes vote down vote up
/**
 * Attempts to give accessibility focus to a virtual view.
 * <p>
 * A virtual view will not actually take focus if
 * {@link AccessibilityManager#isEnabled()} returns false,
 * {@link AccessibilityManager#isTouchExplorationEnabled()} returns false,
 * or the view already has accessibility focus.
 *
 * @param virtualViewId The id of the virtual view on which to place
 *            accessibility focus.
 * @return Whether this virtual view actually took accessibility focus.
 */
private boolean requestAccessibilityFocus(int virtualViewId) {
    if (!mManager.isEnabled()
            || !AccessibilityManagerCompat.isTouchExplorationEnabled(mManager)) {
        return false;
    }
    // TODO: Check virtual view visibility.
    if (!isAccessibilityFocused(virtualViewId)) {
        mFocusedVirtualViewId = virtualViewId;
        // TODO: Only invalidate virtual view bounds.
        mView.invalidate();
        sendEventForVirtualView(virtualViewId,
                AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
        return true;
    }
    return false;
}
 
Example #7
Source File: ExploreByTouchHelper.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
/**
 * Dispatches hover {@link MotionEvent}s to the virtual view hierarchy when
 * the Explore by Touch feature is enabled.
 * <p>
 * This method should be called by overriding
 * {@link View#dispatchHoverEvent}:
 *
 * <pre>&#64;Override
 * public boolean dispatchHoverEvent(MotionEvent event) {
 *   if (mHelper.dispatchHoverEvent(this, event) {
 *     return true;
 *   }
 *   return super.dispatchHoverEvent(event);
 * }
 * </pre>
 *
 * @param event The hover event to dispatch to the virtual view hierarchy.
 * @return Whether the hover event was handled.
 */
public boolean dispatchHoverEvent(MotionEvent event) {
    if (!mManager.isEnabled()
            || !AccessibilityManagerCompat.isTouchExplorationEnabled(mManager)) {
        return false;
    }

    switch (event.getAction()) {
        case MotionEventCompat.ACTION_HOVER_MOVE:
        case MotionEventCompat.ACTION_HOVER_ENTER:
            final int virtualViewId = getVirtualViewAt(event.getX(), event.getY());
            updateHoveredVirtualView(virtualViewId);
            return (virtualViewId != INVALID_ID);
        case MotionEventCompat.ACTION_HOVER_EXIT:
            if (mFocusedVirtualViewId != INVALID_ID) {
                updateHoveredVirtualView(INVALID_ID);
                return true;
            }
            return false;
        default:
            return false;
    }
}
 
Example #8
Source File: ExploreByTouchHelper.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
/**
 * Attempts to give accessibility focus to a virtual view.
 * <p>
 * A virtual view will not actually take focus if
 * {@link AccessibilityManager#isEnabled()} returns false,
 * {@link AccessibilityManager#isTouchExplorationEnabled()} returns false,
 * or the view already has accessibility focus.
 *
 * @param virtualViewId The id of the virtual view on which to place
 *            accessibility focus.
 * @return Whether this virtual view actually took accessibility focus.
 */
private boolean requestAccessibilityFocus(int virtualViewId) {
    if (!mManager.isEnabled()
            || !AccessibilityManagerCompat.isTouchExplorationEnabled(mManager)) {
        return false;
    }
    // TODO: Check virtual view visibility.
    if (!isAccessibilityFocused(virtualViewId)) {
        mFocusedVirtualViewId = virtualViewId;
        // TODO: Only invalidate virtual view bounds.
        mView.invalidate();
        sendEventForVirtualView(virtualViewId,
                AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
        return true;
    }
    return false;
}
 
Example #9
Source File: AccessibilityManagerSupportActivity.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
/**
 * Registers an AccessibilityStateChangeListener that show a Toast
 * when the global accessibility state on the device changes.
 */
private void registerAccessibilityStateChangeListener() {
    // The AccessibilityStateChange listener APIs were added in ICS. Therefore to be
    // backwards compatible we use the APIs in the support library. Note that if the
    // platform API version is lower and the called API is not available no listener
    // is added and you will not receive a call of onAccessibilityStateChanged.
    AccessibilityManagerCompat.addAccessibilityStateChangeListener(mAccessibilityManager,
            new AccessibilityStateChangeListenerCompat() {
        @Override
        public void onAccessibilityStateChanged(boolean enabled) {
            Toast.makeText(AccessibilityManagerSupportActivity.this,
                    getString(R.string.accessibility_manager_accessibility_state, enabled),
                    Toast.LENGTH_SHORT).show();
        }
    });
}
 
Example #10
Source File: MainActivity.java    From Float-Bar with Eclipse Public License 1.0 6 votes vote down vote up
@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)
				+ "后,便可安全稳定的使用悬浮窗啦~", "去激活", "取消");
	}
}
 
Example #11
Source File: ExploreByTouchHelper.java    From guideshow with MIT License 6 votes vote down vote up
/**
 * Dispatches hover {@link MotionEvent}s to the virtual view hierarchy when
 * the Explore by Touch feature is enabled.
 * <p>
 * This method should be called by overriding
 * {@link View#dispatchHoverEvent}:
 *
 * <pre>&#64;Override
 * public boolean dispatchHoverEvent(MotionEvent event) {
 *   if (mHelper.dispatchHoverEvent(this, event) {
 *     return true;
 *   }
 *   return super.dispatchHoverEvent(event);
 * }
 * </pre>
 *
 * @param event The hover event to dispatch to the virtual view hierarchy.
 * @return Whether the hover event was handled.
 */
public boolean dispatchHoverEvent(MotionEvent event) {
    if (!mManager.isEnabled()
            || !AccessibilityManagerCompat.isTouchExplorationEnabled(mManager)) {
        return false;
    }

    switch (event.getAction()) {
        case MotionEventCompat.ACTION_HOVER_MOVE:
        case MotionEventCompat.ACTION_HOVER_ENTER:
            final int virtualViewId = getVirtualViewAt(event.getX(), event.getY());
            updateHoveredVirtualView(virtualViewId);
            return (virtualViewId != INVALID_ID);
        case MotionEventCompat.ACTION_HOVER_EXIT:
            if (mFocusedVirtualViewId != INVALID_ID) {
                updateHoveredVirtualView(INVALID_ID);
                return true;
            }
            return false;
        default:
            return false;
    }
}
 
Example #12
Source File: ExploreByTouchHelper.java    From guideshow with MIT License 6 votes vote down vote up
/**
 * Attempts to give accessibility focus to a virtual view.
 * <p>
 * A virtual view will not actually take focus if
 * {@link AccessibilityManager#isEnabled()} returns false,
 * {@link AccessibilityManager#isTouchExplorationEnabled()} returns false,
 * or the view already has accessibility focus.
 *
 * @param virtualViewId The id of the virtual view on which to place
 *            accessibility focus.
 * @return Whether this virtual view actually took accessibility focus.
 */
private boolean requestAccessibilityFocus(int virtualViewId) {
    if (!mManager.isEnabled()
            || !AccessibilityManagerCompat.isTouchExplorationEnabled(mManager)) {
        return false;
    }
    // TODO: Check virtual view visibility.
    if (!isAccessibilityFocused(virtualViewId)) {
        mFocusedVirtualViewId = virtualViewId;
        // TODO: Only invalidate virtual view bounds.
        mView.invalidate();
        sendEventForVirtualView(virtualViewId,
                AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
        return true;
    }
    return false;
}
 
Example #13
Source File: ExploreByTouchHelper.java    From letv with Apache License 2.0 5 votes vote down vote up
private boolean requestAccessibilityFocus(int virtualViewId) {
    if (!this.mManager.isEnabled() || !AccessibilityManagerCompat.isTouchExplorationEnabled(this.mManager) || isAccessibilityFocused(virtualViewId)) {
        return false;
    }
    if (this.mFocusedVirtualViewId != Integer.MIN_VALUE) {
        sendEventForVirtualView(this.mFocusedVirtualViewId, 65536);
    }
    this.mFocusedVirtualViewId = virtualViewId;
    this.mView.invalidate();
    sendEventForVirtualView(virtualViewId, 32768);
    return true;
}
 
Example #14
Source File: ExploreByTouchHelper.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
private boolean f(int l)
{
    while (!g.isEnabled() || !AccessibilityManagerCompat.isTouchExplorationEnabled(g) || e(l)) 
    {
        return false;
    }
    j = l;
    h.invalidate();
    sendEventForVirtualView(l, 32768);
    return true;
}
 
Example #15
Source File: ExploreByTouchHelper.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public boolean dispatchHoverEvent(MotionEvent motionevent)
{
    boolean flag = true;
    if (g.isEnabled() && AccessibilityManagerCompat.isTouchExplorationEnabled(g))
    {
        switch (motionevent.getAction())
        {
        case 8: // '\b'
        default:
            return false;

        case 7: // '\007'
        case 9: // '\t'
            int l = getVirtualViewAt(motionevent.getX(), motionevent.getY());
            a(l);
            if (l == 0x80000000)
            {
                flag = false;
            }
            return flag;

        case 10: // '\n'
            break;
        }
        if (j != 0x80000000)
        {
            a(0x80000000);
            return flag;
        }
    }
    return false;
}
 
Example #16
Source File: AccessibilityManagerSupportActivity.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
/**
 * Updates the content of a TextView with description of the enabled
 * accessibility services.
 */
private void updateAccessibilityStateView() {
    // The API for getting the enabled accessibility services based on feedback
    // type was added in ICS. Therefore to be backwards compatible we use the
    // APIs in the support library. Note that if the platform API version is lower
    // and the called API is not available an empty list of services is returned.
    List<AccessibilityServiceInfo> enabledServices =
        AccessibilityManagerCompat.getEnabledAccessibilityServiceList(mAccessibilityManager,
                AccessibilityServiceInfo.FEEDBACK_SPOKEN);
    if (!enabledServices.isEmpty()) {
        StringBuilder builder = new StringBuilder();
        final int enabledServiceCount = enabledServices.size();
        for (int i = 0; i < enabledServiceCount; i++) {
            AccessibilityServiceInfo service = enabledServices.get(i);
            // Some new APIs were added in ICS for getting more information about
            // an accessibility service. Again accessed them via the support library.
            ResolveInfo resolveInfo = AccessibilityServiceInfoCompat.getResolveInfo(service);
            String serviceDescription = getString(
                    R.string.accessibility_manager_enabled_service,
                    resolveInfo.loadLabel(getPackageManager()),
                    AccessibilityServiceInfoCompat.feedbackTypeToString(service.feedbackType),
                    AccessibilityServiceInfoCompat.getDescription(service),
                    AccessibilityServiceInfoCompat.getSettingsActivityName(service));
            builder.append(serviceDescription);
        }
        mAccessibilityStateView.setText(builder);
    } else {
        // Either no services or the platform API version is not high enough.
        mAccessibilityStateView.setText(getString(
                R.string.accessibility_manager_no_enabled_services));
    }
}