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