PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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