/talkback_preics/src/com/google/android/marvin/talkback/StatusProvider.java

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