Java Code Examples for android.view.accessibility.AccessibilityManager#isEnabled()

The following examples show how to use android.view.accessibility.AccessibilityManager#isEnabled() . 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: WebViewCompatUtils.java    From rexxar-android with MIT License 6 votes vote down vote up
/**
 * m:lorss
 * 关闭辅助功能,针对4.2.1和4.2.2 崩溃问题
 * java.lang.NullPointerException
 * at android.webkit.AccessibilityInjector$TextToSpeechWrapper$1.onInit(AccessibilityInjector.java:753)
 * ... ...
 * at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:321)
 */
private static void disableAccessibility(Context context) {
    if (Build.VERSION.SDK_INT == 17/*4.2 (Build.VERSION_CODES.JELLY_BEAN_MR1)*/) {
        if (context != null) {
            try {
                AccessibilityManager am = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
                if (!am.isEnabled()) {
                    //Not need to disable accessibility
                    return;
                }

                Method setState = am.getClass().getDeclaredMethod("setState", int.class);
                setState.setAccessible(true);
                setState.invoke(am, 0);/**{@link AccessibilityManager#STATE_FLAG_ACCESSIBILITY_ENABLED}*/
            } catch (Exception ignored) {
                ignored.printStackTrace();
            }
        }
    }
}
 
Example 2
Source File: BaseWebView.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void disableAccessibility(Context context) {
    if (Build.VERSION.SDK_INT == 17/*4.2 (Build.VERSION_CODES.JELLY_BEAN_MR1)*/) {
        if (context != null) {
            try {
                AccessibilityManager am = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
                if (!am.isEnabled()) {
                    //Not need to disable accessibility
                    return;
                }

                Method setState = am.getClass().getDeclaredMethod("setState", int.class);
                setState.setAccessible(true);
                setState.invoke(am, 0);/**{@link AccessibilityManager#STATE_FLAG_ACCESSIBILITY_ENABLED}*/
            } catch (Exception ignored) {
                ignored.printStackTrace();
            }
        }
    }
}
 
Example 3
Source File: AccessibilityUtils.java    From SuperToasts with Apache License 2.0 6 votes vote down vote up
/**
 * Try to send an {@link AccessibilityEvent}
 * for a {@link View}.
 *
 * @param view The View that will dispatch the AccessibilityEvent
 * @return true if the AccessibilityEvent was dispatched
 */
@SuppressWarnings("UnusedReturnValue")
public static boolean sendAccessibilityEvent(View view) {
    final AccessibilityManager accessibilityManager = (AccessibilityManager)
            view.getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);

    if (!accessibilityManager.isEnabled()) return false;

    final AccessibilityEvent accessibilityEvent = AccessibilityEvent
            .obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
    accessibilityEvent.setClassName(view.getClass().getName());
    accessibilityEvent.setPackageName(view.getContext().getPackageName());

    view.dispatchPopulateAccessibilityEvent(accessibilityEvent);
    accessibilityManager.sendAccessibilityEvent(accessibilityEvent);

    return true;
}
 
Example 4
Source File: TalkBackHelper.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
 * 指定したテキストをTalkBackで読み上げる(TalkBackが有効な場合)
 * @param context
 * @param text
 * @throws IllegalStateException
 */
public static void announceText(@NonNull final Context context,
	@Nullable final CharSequence[] text) throws IllegalStateException {

	if ((text == null) || (text.length == 0) || (context == null)) return;
	final AccessibilityManager manager
		= ContextUtils.requireSystemService(context, AccessibilityManager.class);
	if ((manager != null) && manager.isEnabled()) {
		final AccessibilityEvent event = AccessibilityEvent.obtain();
		if (event != null) {
			event.setEventType(AccessibilityEventCompat.TYPE_ANNOUNCEMENT);
			event.setClassName(TalkBackHelper.class.getName());
			event.setPackageName(context.getPackageName());
			for (final CharSequence t: text) {
				event.getText().add(t);
			}
			manager.sendAccessibilityEvent(event);
		} else {
			throw new IllegalStateException("failed to obtain AccessibilityEvent");
		}
	} else {
		throw new IllegalStateException("AccessibilityManager is not available/or disabled");
	}
}
 
Example 5
Source File: Workspace.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
public ValueAnimator createHotseatAlphaAnimator(float finalValue) {
    if (Float.compare(finalValue, mHotseatAlpha[HOTSEAT_STATE_ALPHA_INDEX]) == 0) {
        // Return a dummy animator to avoid null checks.
        return ValueAnimator.ofFloat(0, 0);
    } else {
        ValueAnimator animator = ValueAnimator
                .ofFloat(mHotseatAlpha[HOTSEAT_STATE_ALPHA_INDEX], finalValue);
        animator.addUpdateListener(new AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                float value = (Float) valueAnimator.getAnimatedValue();
                setHotseatAlphaAtIndex(value, HOTSEAT_STATE_ALPHA_INDEX);
            }
        });

        AccessibilityManager am = (AccessibilityManager)
                mLauncher.getSystemService(Context.ACCESSIBILITY_SERVICE);
        final boolean accessibilityEnabled = am.isEnabled();
        animator.addUpdateListener(
                new AlphaUpdateListener(mLauncher.getHotseat(), accessibilityEnabled));
        animator.addUpdateListener(
                new AlphaUpdateListener(mPageIndicator, accessibilityEnabled));
        return animator;
    }
}
 
Example 6
Source File: Utilities.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
public static void sendCustomAccessibilityEvent(View target, int type, String text) {
    AccessibilityManager accessibilityManager = (AccessibilityManager)
            target.getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    if (accessibilityManager.isEnabled()) {
        AccessibilityEvent event = AccessibilityEvent.obtain(type);
        target.onInitializeAccessibilityEvent(event);
        event.getText().add(text);
        accessibilityManager.sendAccessibilityEvent(event);
    }
}
 
Example 7
Source File: AccessibilityUtil.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Checks to see that this device has accessibility and touch exploration enabled.
 * @param context A {@link Context} instance.
 * @return        Whether or not accessibility and touch exploration are enabled.
 */
@CalledByNative
public static boolean isAccessibilityEnabled(Context context) {
    AccessibilityManager manager = (AccessibilityManager)
            context.getSystemService(Context.ACCESSIBILITY_SERVICE);
    return manager != null && manager.isEnabled() && manager.isTouchExplorationEnabled();
}
 
Example 8
Source File: WorkspaceStateTransitionAnimation.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
public AnimatorSet getAnimationToState(Workspace.State fromState, Workspace.State toState,
        int toPage, boolean animated, HashMap<View, Integer> layerViews) {
    AccessibilityManager am = (AccessibilityManager)
            mLauncher.getSystemService(Context.ACCESSIBILITY_SERVICE);
    final boolean accessibilityEnabled = am.isEnabled();
    TransitionStates states = new TransitionStates(fromState, toState);
    int workspaceDuration = getAnimationDuration(states);
    animateWorkspace(states, toPage, animated, workspaceDuration, layerViews,
            accessibilityEnabled);
    animateBackgroundGradient(states, animated, BACKGROUND_FADE_OUT_DURATION);
    return mStateAnimator;
}
 
Example 9
Source File: CheckBoxPreference.java    From MaterialPreference with Apache License 2.0 5 votes vote down vote up
private void syncViewIfAccessibilityEnabled(View view) {
    AccessibilityManager accessibilityManager = (AccessibilityManager)
            getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    if (!accessibilityManager.isEnabled()) {
        return;
    }

    View checkboxView = view.findViewById(android.R.id.checkbox);
    syncCheckboxView(checkboxView);

    View summaryView = view.findViewById(android.R.id.summary);
    syncSummaryView(summaryView);
}
 
Example 10
Source File: Toast.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void trySendAccessibilityEvent() {
    AccessibilityManager accessibilityManager =
            AccessibilityManager.getInstance(mView.getContext());
    if (!accessibilityManager.isEnabled()) {
        return;
    }
    // treat toasts as notifications since they are used to
    // announce a transient piece of information to the user
    AccessibilityEvent event = AccessibilityEvent.obtain(
            AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
    event.setClassName(getClass().getName());
    event.setPackageName(mView.getContext().getPackageName());
    mView.dispatchPopulateAccessibilityEvent(event);
    accessibilityManager.sendAccessibilityEvent(event);
}
 
Example 11
Source File: TalkBackKeyboardShortcutPreferencesActivity.java    From talkback with Apache License 2.0 5 votes vote down vote up
/** Utility method for announcing text via accessibility event. */
public static void announceText(String text, Context context) {
  AccessibilityManager accessibilityManager =
      (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
  if (accessibilityManager.isEnabled()) {
    AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_ANNOUNCEMENT);
    event.setContentDescription(text);
    accessibilityManager.sendAccessibilityEvent(event);
  }
}
 
Example 12
Source File: AndroidUtilities.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public static void makeAccessibilityAnnouncement(CharSequence what) {
    AccessibilityManager am = (AccessibilityManager) ApplicationLoader.applicationContext.getSystemService(Context.ACCESSIBILITY_SERVICE);
    if (am.isEnabled()) {
        AccessibilityEvent ev = AccessibilityEvent.obtain();
        ev.setEventType(AccessibilityEvent.TYPE_ANNOUNCEMENT);
        ev.getText().add(what);
        am.sendAccessibilityEvent(ev);
    }
}
 
Example 13
Source File: NumberPicker.java    From NewXmPluginSDK with Apache License 2.0 5 votes vote down vote up
private void sendAccessibilityEventForVirtualButton(int virtualViewId, int eventType, String text) {
    AccessibilityManager acm = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    if (acm.isEnabled()) {
        AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
        event.setClassName(Button.class.getName());
        event.setPackageName(getContext().getPackageName());
        event.getText().add(text);
        event.setEnabled(NumberPicker.this.isEnabled());
        event.setSource(NumberPicker.this, virtualViewId);
        requestSendAccessibilityEvent(NumberPicker.this, event);
    }
}
 
Example 14
Source File: DragLayer.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
private void sendTapOutsideFolderAccessibilityEvent(boolean isEditingName) {
    AccessibilityManager accessibilityManager = (AccessibilityManager)
            getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    if (accessibilityManager.isEnabled()) {
        int stringId = isEditingName ? R.string.folder_tap_to_rename : R.string.folder_tap_to_close;
        AccessibilityEvent event = AccessibilityEvent.obtain(
                AccessibilityEvent.TYPE_VIEW_FOCUSED);
        onInitializeAccessibilityEvent(event);
        event.getText().add(getContext().getString(stringId));
        accessibilityManager.sendAccessibilityEvent(event);
    }
}
 
Example 15
Source File: Utils.java    From Noyze with Apache License 2.0 5 votes vote down vote up
/**
 * @return True if system-wide Accessibility is enabled.
 */
public static boolean isAccessibilityEnabled(Context context) {
    // Also see Settings.Secure.ACCESSIBILITY_ENABLED, alternative method.
    AccessibilityManager aManager = (AccessibilityManager)
            context.getSystemService(Context.ACCESSIBILITY_SERVICE);
    return (null != aManager && aManager.isEnabled());
}
 
Example 16
Source File: JsWindow.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
private void trySendAccessibilityEvent() {
	AccessibilityManager accessibilityManager = AccessibilityManager
			.getInstance(mView.getContext());
	if (!accessibilityManager.isEnabled()) {
		return;
	}
	// treat toasts as notifications since they are used to
	// announce a transient piece of information to the user
	AccessibilityEvent event = AccessibilityEvent
			.obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
	event.setClassName(getClass().getName());
	event.setPackageName(mView.getContext().getPackageName());
	mView.dispatchPopulateAccessibilityEvent(event);
	accessibilityManager.sendAccessibilityEvent(event);
}
 
Example 17
Source File: AgentWebView.java    From AgentWeb with Apache License 2.0 4 votes vote down vote up
private boolean isAccessibilityEnabled() {
    AccessibilityManager am = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    return am.isEnabled();
}
 
Example 18
Source File: AppsCustomizePagedView.java    From TurboLauncher with Apache License 2.0 4 votes vote down vote up
protected void onResume() {
    AccessibilityManager am = (AccessibilityManager)
            getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    sAccessibilityEnabled = am.isEnabled();
}
 
Example 19
Source File: TalkBackHelper.java    From libcommon with Apache License 2.0 4 votes vote down vote up
/**
 * Accessibilityが有効になっているかどうかを取得
 * @param context
 * @return
 */
public static boolean isEnabled(@NonNull final Context context) {
	final AccessibilityManager manager
		= ContextUtils.requireSystemService(context, AccessibilityManager.class);
	return manager.isEnabled();
}
 
Example 20
Source File: PagedView.java    From LB-Launcher with Apache License 2.0 4 votes vote down vote up
protected boolean computeScrollHelper() {
    if (mScroller.computeScrollOffset()) {
        // Don't bother scrolling if the page does not need to be moved
        if (getScrollX() != mScroller.getCurrX()
            || getScrollY() != mScroller.getCurrY()
            || mOverScrollX != mScroller.getCurrX()) {
            float scaleX = mFreeScroll ? getScaleX() : 1f;
            int scrollX = (int) (mScroller.getCurrX() * (1 / scaleX));
            scrollTo(scrollX, mScroller.getCurrY());
        }
        invalidate();
        return true;
    } else if (mNextPage != INVALID_PAGE) {
        sendScrollAccessibilityEvent();

        mCurrentPage = validateNewPage(mNextPage);
        mNextPage = INVALID_PAGE;
        notifyPageSwitchListener();

        // Load the associated pages if necessary
        if (mDeferLoadAssociatedPagesUntilScrollCompletes) {
            loadAssociatedPages(mCurrentPage);
            mDeferLoadAssociatedPagesUntilScrollCompletes = false;
        }

        // We don't want to trigger a page end moving unless the page has settled
        // and the user has stopped scrolling
        if (mTouchState == TOUCH_STATE_REST) {
            pageEndMoving();
        }

        onPostReorderingAnimationCompleted();
        AccessibilityManager am = (AccessibilityManager)
                getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
        if (am.isEnabled()) {
            // Notify the user when the page changes
            announceForAccessibility(getCurrentPageDescription());
        }
        return true;
    }
    return false;
}