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.app.settings.SettingsEnums; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.os.Bundle; 23 import android.text.TextUtils; 24 25 import com.android.settings.R; 26 import com.android.settings.dashboard.DashboardFragment; 27 28 public class InputMethodAndSubtypeEnabler extends DashboardFragment { 29 30 private static final String TAG = "InputMethodAndSubtypeEnabler"; 31 32 @Override getMetricsCategory()33 public int getMetricsCategory() { 34 return SettingsEnums.INPUTMETHOD_SUBTYPE_ENABLER; 35 } 36 37 @Override getPreferenceScreenResId()38 protected int getPreferenceScreenResId() { 39 return R.xml.input_methods_subtype; 40 } 41 42 @Override getLogTag()43 protected String getLogTag() { 44 return TAG; 45 } 46 47 @Override onAttach(Context context)48 public void onAttach(Context context) { 49 super.onAttach(context); 50 51 // Input method id should be available from an Intent when this preference is launched as a 52 // single Activity (see InputMethodAndSubtypeEnablerActivity). It should be available 53 // from a preference argument when the preference is launched as a part of the other 54 // Activity (like a right pane of 2-pane Settings app) 55 final String targetImi = getStringExtraFromIntentOrArguments( 56 android.provider.Settings.EXTRA_INPUT_METHOD_ID); 57 58 use(InputMethodAndSubtypePreferenceController.class).initialize(this /* fragment */, 59 targetImi); 60 } 61 getStringExtraFromIntentOrArguments(final String name)62 private String getStringExtraFromIntentOrArguments(final String name) { 63 final Intent intent = getActivity().getIntent(); 64 final String fromIntent = intent.getStringExtra(name); 65 if (fromIntent != null) { 66 return fromIntent; 67 } 68 final Bundle arguments = getArguments(); 69 return (arguments == null) ? null : arguments.getString(name); 70 } 71 72 @Override onActivityCreated(final Bundle icicle)73 public void onActivityCreated(final Bundle icicle) { 74 super.onActivityCreated(icicle); 75 final String title = getStringExtraFromIntentOrArguments(Intent.EXTRA_TITLE); 76 if (!TextUtils.isEmpty(title)) { 77 getActivity().setTitle(title); 78 } 79 } 80 } 81