Home | History | Annotate | Download | only in inputmethod
      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 
     17 package com.android.settings.inputmethod;
     18 
     19 import android.content.Intent;
     20 import android.os.Bundle;
     21 import android.support.v7.preference.PreferenceScreen;
     22 import android.text.TextUtils;
     23 
     24 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
     25 import com.android.settings.SettingsPreferenceFragment;
     26 import com.android.settingslib.inputmethod.InputMethodAndSubtypeEnablerManager;
     27 
     28 public class InputMethodAndSubtypeEnabler extends SettingsPreferenceFragment {
     29     private InputMethodAndSubtypeEnablerManager mManager;
     30 
     31     @Override
     32     public int getMetricsCategory() {
     33         return MetricsEvent.INPUTMETHOD_SUBTYPE_ENABLER;
     34     }
     35 
     36     @Override
     37     public void onCreate(final Bundle icicle) {
     38         super.onCreate(icicle);
     39 
     40         // Input method id should be available from an Intent when this preference is launched as a
     41         // single Activity (see InputMethodAndSubtypeEnablerActivity). It should be available
     42         // from a preference argument when the preference is launched as a part of the other
     43         // Activity (like a right pane of 2-pane Settings app)
     44         final String targetImi = getStringExtraFromIntentOrArguments(
     45                 android.provider.Settings.EXTRA_INPUT_METHOD_ID);
     46 
     47         final PreferenceScreen root =
     48                 getPreferenceManager().createPreferenceScreen(getPrefContext());
     49         mManager = new InputMethodAndSubtypeEnablerManager(this);
     50         mManager.init(this, targetImi, root);
     51         setPreferenceScreen(root);
     52     }
     53 
     54     private String getStringExtraFromIntentOrArguments(final String name) {
     55         final Intent intent = getActivity().getIntent();
     56         final String fromIntent = intent.getStringExtra(name);
     57         if (fromIntent != null) {
     58             return fromIntent;
     59         }
     60         final Bundle arguments = getArguments();
     61         return (arguments == null) ? null : arguments.getString(name);
     62     }
     63 
     64     @Override
     65     public void onActivityCreated(final Bundle icicle) {
     66         super.onActivityCreated(icicle);
     67         final String title = getStringExtraFromIntentOrArguments(Intent.EXTRA_TITLE);
     68         if (!TextUtils.isEmpty(title)) {
     69             getActivity().setTitle(title);
     70         }
     71     }
     72 
     73     @Override
     74     public void onResume() {
     75         super.onResume();
     76         mManager.refresh(getContext(), this);
     77     }
     78 
     79     @Override
     80     public void onPause() {
     81         super.onPause();
     82         mManager.save(getContext(), this);
     83     }
     84 }
     85