/talkback_preics/src/com/google/android/marvin/talkback/StatusProvider.java
Java | 113 lines | 60 code | 15 blank | 38 comment | 2 complexity | 3fe58e762695a2897ced13c01c88ee21 MD5 | raw file
1/* 2 * Copyright (C) 2010 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.google.android.marvin.talkback; 18 19import android.content.ContentProvider; 20import android.content.ContentValues; 21import android.database.Cursor; 22import android.database.MatrixCursor; 23import android.net.Uri; 24 25/* 26 * This content provider enables TalkBack to provide its status (running or not) 27 * to other applications. 28 * 29 * Applications can check if any screen readers are running by doing the 30 * following: 31 * 32 * 1. Detect all installed screen readers by using Intents. 33 * Screen reader services are expected to respond to intent filters for 34 * action = "android.accessibilityservice.AccessibilityService" and 35 * category = "android.accessibilityservice.category.FEEDBACK_SPOKEN". 36 * 37 * 2. For the list of screen readers installed, check their status provider. 38 * Screen readers are expected to implement: 39 * <packagename>.providers.StatusProvider. 40 * For example, in TalkBack, the status provider is: 41 * com.google.android.marvin.talkback.providers.StatusProvider 42 * 43 * 3. The status provider returns 0 for inactive, and 44 * 1 for active. 45 * 46 * @author clchen@google.com (Charles L. Chen) 47 */ 48 49public class StatusProvider extends ContentProvider { 50 private class StatusCursor extends MatrixCursor { 51 private int status; 52 53 public StatusCursor() { 54 super(new String[] {""}); 55 } 56 57 public void setStatus(int status) { 58 this.status = status; 59 } 60 61 @Override 62 public int getCount() { 63 return 1; 64 } 65 66 @Override 67 public String getString(int column) { 68 return String.valueOf(status); 69 } 70 71 @Override 72 public int getInt(int column) { 73 return status; 74 } 75 } 76 77 @Override 78 public int delete(Uri uri, String selection, String[] selectionArgs) { 79 return 0; 80 } 81 82 @Override 83 public String getType(Uri uri) { 84 return null; 85 } 86 87 @Override 88 public Uri insert(Uri uri, ContentValues values) { 89 return null; 90 } 91 92 @Override 93 public boolean onCreate() { 94 return true; 95 } 96 97 @Override 98 public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, 99 String sortOrder) { 100 StatusCursor cursor = new StatusCursor(); 101 if (TalkBackService.isServiceInitialized()) { 102 cursor.setStatus(TalkBackService.RESULT_TALKBACK_ENABLED); 103 } else { 104 cursor.setStatus(TalkBackService.RESULT_TALKBACK_DISABLED); 105 } 106 return cursor; 107 } 108 109 @Override 110 public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { 111 return 0; 112 } 113}