1 package com.android.camera.util; 2 3 import android.content.Context; 4 import android.support.v4.view.accessibility.AccessibilityRecordCompat; 5 import android.view.View; 6 import android.view.accessibility.AccessibilityEvent; 7 import android.view.accessibility.AccessibilityManager; 8 9 /** 10 * AccessibilityUtils provides functions needed in accessibility mode. All the functions 11 * in this class are made compatible with gingerbread and later API's 12 */ 13 public class AccessibilityUtils { 14 public static void makeAnnouncement(View view, CharSequence announcement) { 15 if (view == null) 16 return; 17 if (ApiHelper.HAS_ANNOUNCE_FOR_ACCESSIBILITY) { 18 view.announceForAccessibility(announcement); 19 } else { 20 // For API 15 and earlier, we need to construct an accessibility event 21 Context ctx = view.getContext(); 22 AccessibilityManager am = (AccessibilityManager) ctx.getSystemService( 23 Context.ACCESSIBILITY_SERVICE); 24 if (!am.isEnabled()) return; 25 AccessibilityEvent event = AccessibilityEvent.obtain( 26 AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED); 27 AccessibilityRecordCompat arc = new AccessibilityRecordCompat(event); 28 arc.setSource(view); 29 event.setClassName(view.getClass().getName()); 30 event.setPackageName(view.getContext().getPackageName()); 31 event.setEnabled(view.isEnabled()); 32 event.getText().add(announcement); 33 am.sendAccessibilityEvent(event); 34 } 35 } 36 }