1/* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.gallery3d.util; 18 19import android.content.Context; 20import android.support.v4.view.accessibility.AccessibilityRecordCompat; 21import android.view.View; 22import android.view.accessibility.AccessibilityEvent; 23import android.view.accessibility.AccessibilityManager; 24 25import com.android.gallery3d.common.ApiHelper; 26 27/** 28 * AccessibilityUtils provides functions needed in accessibility mode. All the functions 29 * in this class are made compatible with gingerbread and later API's 30*/ 31public class AccessibilityUtils { 32 public static void makeAnnouncement(View view, CharSequence announcement) { 33 if (view == null) 34 return; 35 if (ApiHelper.HAS_ANNOUNCE_FOR_ACCESSIBILITY) { 36 view.announceForAccessibility(announcement); 37 } else { 38 // For API 15 and earlier, we need to construct an accessibility event 39 Context ctx = view.getContext(); 40 AccessibilityManager am = (AccessibilityManager) ctx.getSystemService( 41 Context.ACCESSIBILITY_SERVICE); 42 if (!am.isEnabled()) return; 43 AccessibilityEvent event = AccessibilityEvent.obtain( 44 AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED); 45 AccessibilityRecordCompat arc = new AccessibilityRecordCompat(event); 46 arc.setSource(view); 47 event.setClassName(view.getClass().getName()); 48 event.setPackageName(view.getContext().getPackageName()); 49 event.setEnabled(view.isEnabled()); 50 event.getText().add(announcement); 51 am.sendAccessibilityEvent(event); 52 } 53 } 54}