/ime/latinime/src/com/googlecode/eyesfree/inputmethod/latin/BootReceiver.java

http://eyes-free.googlecode.com/ · Java · 57 lines · 29 code · 7 blank · 21 comment · 5 complexity · b81625d9caad323dc7a583634e0d870f MD5 · raw file

  1. /*
  2. * Copyright (C) 2011 Google Inc.
  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.googlecode.eyesfree.inputmethod.latin;
  17. import android.content.BroadcastReceiver;
  18. import android.content.Context;
  19. import android.content.Intent;
  20. import android.provider.Settings;
  21. import android.util.Log;
  22. import com.googlecode.eyesfree.inputmethod.latin.tutorial.LatinTutorialLogger;
  23. /**
  24. * This class receives the boot completed broadcast and opens the IME
  25. * automatically (assuming it is enabled and set as default).
  26. *
  27. * @author alanv@google.com (Alan Viverette)
  28. */
  29. public class BootReceiver extends BroadcastReceiver {
  30. private static final Class<?> TARGET_IME = LatinIME.class;
  31. @Override
  32. public void onReceive(Context context, Intent intent) {
  33. if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
  34. if (AccessibilityUtils.isAccessibilityEnabled(context)) {
  35. if (AccessibilityUtils.isInputMethodDefault(context, TARGET_IME)) {
  36. LatinTutorialLogger.log(Log.DEBUG, "Starting IME");
  37. context.startActivity(new Intent(context, BootActivity.class).setFlags(
  38. Intent.FLAG_ACTIVITY_NEW_TASK));
  39. } else {
  40. final String defaultImeId = Settings.Secure.getString(
  41. context.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
  42. LatinTutorialLogger.log(
  43. Log.INFO, "Cannot start IME, current default IME is %s", defaultImeId);
  44. }
  45. } else {
  46. LatinTutorialLogger.log(Log.INFO, "Cannot start IME, accessibility is disabled");
  47. }
  48. }
  49. }
  50. }