Home | History | Annotate | Download | only in setup
      1 /*
      2  * Copyright (C) 2013 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 
     17 package com.android.inputmethod.latin.setup;
     18 
     19 import android.app.Activity;
     20 import android.content.Context;
     21 import android.content.Intent;
     22 import android.os.Bundle;
     23 import android.provider.Settings;
     24 import android.view.inputmethod.InputMethodInfo;
     25 import android.view.inputmethod.InputMethodManager;
     26 
     27 public final class SetupActivity extends Activity {
     28     @Override
     29     protected void onCreate(final Bundle savedInstanceState) {
     30         super.onCreate(savedInstanceState);
     31         final Intent intent = new Intent();
     32         intent.setClass(this, SetupWizardActivity.class);
     33         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
     34                 | Intent.FLAG_ACTIVITY_NEW_TASK);
     35         startActivity(intent);
     36         if (!isFinishing()) {
     37             finish();
     38         }
     39     }
     40 
     41     /*
     42      * We may not be able to get our own {@link InputMethodInfo} just after this IME is installed
     43      * because {@link InputMethodManagerService} may not be aware of this IME yet.
     44      * Note: {@link RichInputMethodManager} has similar methods. Here in setup wizard, we can't
     45      * use it for the reason above.
     46      */
     47 
     48     /**
     49      * Check if the IME specified by the context is enabled.
     50      * CAVEAT: This may cause a round trip IPC.
     51      *
     52      * @param context package context of the IME to be checked.
     53      * @param imm the {@link InputMethodManager}.
     54      * @return true if this IME is enabled.
     55      */
     56     /* package */ static boolean isThisImeEnabled(final Context context,
     57             final InputMethodManager imm) {
     58         final String packageName = context.getPackageName();
     59         for (final InputMethodInfo imi : imm.getEnabledInputMethodList()) {
     60             if (packageName.equals(imi.getPackageName())) {
     61                 return true;
     62             }
     63         }
     64         return false;
     65     }
     66 
     67     /**
     68      * Check if the IME specified by the context is the current IME.
     69      * CAVEAT: This may cause a round trip IPC.
     70      *
     71      * @param context package context of the IME to be checked.
     72      * @param imm the {@link InputMethodManager}.
     73      * @return true if this IME is the current IME.
     74      */
     75     /* package */ static boolean isThisImeCurrent(final Context context,
     76             final InputMethodManager imm) {
     77         final InputMethodInfo imi = getInputMethodInfoOf(context.getPackageName(), imm);
     78         final String currentImeId = Settings.Secure.getString(
     79                 context.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
     80         return imi != null && imi.getId().equals(currentImeId);
     81     }
     82 
     83     /**
     84      * Get {@link InputMethodInfo} of the IME specified by the package name.
     85      * CAVEAT: This may cause a round trip IPC.
     86      *
     87      * @param packageName package name of the IME.
     88      * @param imm the {@link InputMethodManager}.
     89      * @return the {@link InputMethodInfo} of the IME specified by the <code>packageName</code>,
     90      * or null if not found.
     91      */
     92     /* package */ static InputMethodInfo getInputMethodInfoOf(final String packageName,
     93             final InputMethodManager imm) {
     94         for (final InputMethodInfo imi : imm.getInputMethodList()) {
     95             if (packageName.equals(imi.getPackageName())) {
     96                 return imi;
     97             }
     98         }
     99         return null;
    100     }
    101 }
    102