1 /*
2  * Copyright (C) 2011 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 /**
18  * This is a part of the inputmethod-common static Java library.
19  * The original source code can be found at frameworks/opt/inputmethodcommon of Android Open Source
20  * Project.
21  */
22 
23 package com.android.inputmethodcommon;
24 
25 import android.content.Context;
26 import android.graphics.drawable.Drawable;
27 import android.os.Bundle;
28 import android.preference.PreferenceFragment;
29 
30 /**
31  * This is a helper class for an IME's settings preference fragment. It's recommended for every
32  * IME to have its own settings preference fragment which inherits this class.
33  */
34 public abstract class InputMethodSettingsFragment extends PreferenceFragment
35         implements InputMethodSettingsInterface {
36     private final InputMethodSettingsImpl mSettings = new InputMethodSettingsImpl();
37     @Override
onCreate(Bundle savedInstanceState)38     public void onCreate(Bundle savedInstanceState) {
39         super.onCreate(savedInstanceState);
40         final Context context = getActivity();
41         setPreferenceScreen(getPreferenceManager().createPreferenceScreen(context));
42         mSettings.init(context, getPreferenceScreen());
43     }
44 
45     /**
46      * {@inheritDoc}
47      */
48     @Override
setInputMethodSettingsCategoryTitle(int resId)49     public void setInputMethodSettingsCategoryTitle(int resId) {
50         mSettings.setInputMethodSettingsCategoryTitle(resId);
51     }
52 
53     /**
54      * {@inheritDoc}
55      */
56     @Override
setInputMethodSettingsCategoryTitle(CharSequence title)57     public void setInputMethodSettingsCategoryTitle(CharSequence title) {
58         mSettings.setInputMethodSettingsCategoryTitle(title);
59     }
60 
61     /**
62      * {@inheritDoc}
63      */
64     @Override
setSubtypeEnablerTitle(int resId)65     public void setSubtypeEnablerTitle(int resId) {
66         mSettings.setSubtypeEnablerTitle(resId);
67     }
68 
69     /**
70      * {@inheritDoc}
71      */
72     @Override
setSubtypeEnablerTitle(CharSequence title)73     public void setSubtypeEnablerTitle(CharSequence title) {
74         mSettings.setSubtypeEnablerTitle(title);
75     }
76 
77     /**
78      * {@inheritDoc}
79      */
80     @Override
setSubtypeEnablerIcon(int resId)81     public void setSubtypeEnablerIcon(int resId) {
82         mSettings.setSubtypeEnablerIcon(resId);
83     }
84 
85     /**
86      * {@inheritDoc}
87      */
88     @Override
setSubtypeEnablerIcon(Drawable drawable)89     public void setSubtypeEnablerIcon(Drawable drawable) {
90         mSettings.setSubtypeEnablerIcon(drawable);
91     }
92 
93     /**
94      * {@inheritDoc}
95      */
96     @Override
onResume()97     public void onResume() {
98         super.onResume();
99         mSettings.updateSubtypeEnabler();
100     }
101 }
102