下面列出了android.view.View#announceForAccessibility ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Try to speak the specified text, for accessibility. Only available on JB or later.
*
* @param text Text to announce.
*/
@SuppressLint("NewApi")
public static void tryAccessibilityAnnounce(View view, CharSequence text) {
if (view != null && text != null) {
view.announceForAccessibility(text);
}
}
/**
* uZooms camera in when in accessibility mode.
*
* @param view is the current view
* @param maxZoom is the maximum zoom value on the given device
* @return float representing the current zoom value
*/
public float zoomIn(View view, float maxZoom)
{
mCurrA11yZoomLevel++;
mMaxZoom = maxZoom;
mCurrA11yZoom = getZoomAtLevel(mCurrA11yZoomLevel);
mZoomListener.onZoomValueChanged(mCurrA11yZoom);
view.announceForAccessibility(String.format(
view.getResources().
getString(R.string.accessibility_zoom_announcement), mCurrA11yZoom));
return mCurrA11yZoom;
}
/**
* Zooms camera out when in accessibility mode.
*
* @param view is the current view
* @param maxZoom is the maximum zoom value on the given device
* @return float representing the current zoom value
*/
public float zoomOut(View view, float maxZoom)
{
mCurrA11yZoomLevel--;
mMaxZoom = maxZoom;
mCurrA11yZoom = getZoomAtLevel(mCurrA11yZoomLevel);
mZoomListener.onZoomValueChanged(mCurrA11yZoom);
view.announceForAccessibility(String.format(
view.getResources().
getString(R.string.accessibility_zoom_announcement), mCurrA11yZoom));
return mCurrA11yZoom;
}
/**
* Try to speak the specified text, for accessibility. Only available on JB or later.
* @param text Text to announce.
*/
@SuppressLint("NewApi")
public static void tryAccessibilityAnnounce(View view, CharSequence text) {
if (isJellybeanOrLater() && view != null && text != null) {
view.announceForAccessibility(text);
}
}
/**
* Try to speak the specified text, for accessibility. Only available on JB or later.
* @param text Text to announce.
*/
@SuppressLint("NewApi")
public static void tryAccessibilityAnnounce(View view, CharSequence text) {
if (isJellybeanOrLater() && view != null && text != null) {
view.announceForAccessibility(text);
}
}
/**
* Try to speak the specified text, for accessibility. Only available on JB or later.
* @param text Text to announce.
*/
@SuppressLint("NewApi")
public static void tryAccessibilityAnnounce(View view, CharSequence text) {
if (isJellybeanOrLater() && view != null && text != null) {
view.announceForAccessibility(text);
}
}
/**
* Try to speak the specified text, for accessibility. Only available on JB or later.
* @param text Text to announce.
*/
@SuppressLint("NewApi")
public static void tryAccessibilityAnnounce(View view, CharSequence text) {
if (isJellybeanOrLater() && view != null && text != null) {
view.announceForAccessibility(text);
}
}
/**
* Try to speak the specified text, for accessibility. Only available on JB or later.
* @param text Text to announce.
*/
@SuppressLint("NewApi")
public static void tryAccessibilityAnnounce(View view, CharSequence text) {
if (Build.VERSION.SDK_INT >= 16 && view != null && text != null) {
view.announceForAccessibility(text);
}
}
/**
* Try to speak the specified text, for accessibility. Only available on JB or later.
* @param text Text to announce.
*/
@SuppressLint("NewApi")
public static void tryAccessibilityAnnounce(View view, CharSequence text) {
if (isJellybeanOrLater() && view != null && text != null) {
view.announceForAccessibility(text);
}
}
@Thunk void selectTile(View v) {
if (mSelectedTile != null) {
mSelectedTile.setSelected(false);
mSelectedTile = null;
}
mSelectedTile = v;
v.setSelected(true);
mSelectedIndex = mWallpapersView.indexOfChild(v);
// TODO: Remove this once the accessibility framework and
// services have better support for selection state.
v.announceForAccessibility(
getContext().getString(R.string.announce_selection, v.getContentDescription()));
}
/**
* Try to speak the specified text, for accessibility. Only available on JB or later.
* @param text Text to announce.
*/
@SuppressLint("NewApi")
public static void tryAccessibilityAnnounce(View view, CharSequence text) {
if (isJellybeanOrLater() && view != null && text != null) {
view.announceForAccessibility(text);
}
}
private void selectTile(View v) {
if (mSelectedTile != null) {
mSelectedTile.setSelected(false);
mSelectedTile = null;
}
mSelectedTile = v;
v.setSelected(true);
mSelectedIndex = mWallpapersView.indexOfChild(v);
// TODO: Remove this once the accessibility framework and
// services have better support for selection state.
v.announceForAccessibility(
getString(R.string.announce_selection, v.getContentDescription()));
}
/**
* Try to speak the specified text, for accessibility. Only available on JB or later.
* @param text Text to announce.
*/
@SuppressLint("NewApi")
public static void tryAccessibilityAnnounce(View view, CharSequence text) {
if (isJellybeanOrLater() && view != null && text != null) {
view.announceForAccessibility(text);
}
}
/**
* @param view the View to trigger the accessibility event
* @param msg text that will be read aloud (if accessibility enabled)
*/
public static void announceForAccessibility(View view, String msg)
{
if (view != null && msg != null)
{
if (Build.VERSION.SDK_INT >= 16)
{
view.announceForAccessibility(msg);
} else {
Context context = view.getContext();
if (context != null)
{
AccessibilityManager accesibility = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
if (accesibility != null && accesibility.isEnabled())
{
AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_FOCUSED);
event.getText().add(msg);
event.setEnabled(view.isEnabled());
event.setClassName(view.getClass().getName());
event.setPackageName(context.getPackageName());
ViewParent parent = view.getParent();
if (Build.VERSION.SDK_INT >= 14 && parent != null)
{
parent.requestSendAccessibilityEvent(view, event);
} else {
accesibility.sendAccessibilityEvent(event);
}
}
}
}
}
}
/**
* Try to speak the specified text, for accessibility. Only available on JB or later.
* @param text Text to announce.
*/
@SuppressLint("NewApi")
public static void tryAccessibilityAnnounce(View view, CharSequence text) {
if (isJellybeanOrLater() && view != null && text != null) {
view.announceForAccessibility(text);
}
}
/**
* Try to speak the specified text, for accessibility. Only available on JB or later.
* @param text Text to announce.
*/
@SuppressLint("NewApi")
public static void tryAccessibilityAnnounce(View view, CharSequence text) {
if (isJellybeanOrLater() && view != null && text != null) {
view.announceForAccessibility(text);
}
}
/**
* Try to speak the specified text, for accessibility. Only available on JB or later.
* @param text Text to announce.
*/
@SuppressLint("NewApi")
public static void tryAccessibilityAnnounce(View view, CharSequence text) {
if (isJellybeanOrLater() && view != null && text != null) {
view.announceForAccessibility(text);
}
}
public static void announceForAccessibility(View view, CharSequence text) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.announceForAccessibility(text);
} // No-op on versions prior to Jellybean
}
/**
* Try to speak the specified text, for accessibility. Only available on JB or later.
* @param text Text to announce.
*/
public static void tryAccessibilityAnnounce(View view, CharSequence text) {
if (view != null && text != null) {
view.announceForAccessibility(text);
}
}
/**
* Wrapper for {@link View#announceForAccessibility(CharSequence)}.
*
* @param view
* a view.
* @param text
* The announcement text.
* @see View#announceForAccessibility(CharSequence)
*/
public static void announceForAccessibility(View view, CharSequence text) {
view.announceForAccessibility(text);
}