SettingsFragment.java revision 83a96fe5c748926d53a3771d2913a0a1012753c2
1/*
2 * Copyright (C) 2008 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
17package com.android.inputmethod.latin.settings;
18
19import android.content.Intent;
20import android.os.Bundle;
21import android.preference.PreferenceScreen;
22import android.view.Menu;
23import android.view.MenuInflater;
24import android.view.MenuItem;
25
26import com.android.inputmethod.latin.R;
27import com.android.inputmethod.latin.utils.ApplicationUtils;
28import com.android.inputmethod.latin.utils.FeedbackUtils;
29import com.android.inputmethodcommon.InputMethodSettingsFragment;
30
31public final class SettingsFragment extends InputMethodSettingsFragment {
32    // We don't care about menu grouping.
33    private static final int NO_MENU_GROUP = Menu.NONE;
34    // The first menu item id and order.
35    private static final int MENU_HELP_AND_FEEDBACK = Menu.FIRST;
36    // The second menu item id and order.
37    private static final int MENU_ABOUT = Menu.FIRST + 1;
38
39    @Override
40    public void onCreate(final Bundle icicle) {
41        super.onCreate(icicle);
42        setHasOptionsMenu(true);
43        setInputMethodSettingsCategoryTitle(R.string.language_selection_title);
44        setSubtypeEnablerTitle(R.string.select_language);
45        addPreferencesFromResource(R.xml.prefs);
46        final PreferenceScreen preferenceScreen = getPreferenceScreen();
47        preferenceScreen.setTitle(
48                ApplicationUtils.getActivityTitleResId(getActivity(), SettingsActivity.class));
49    }
50
51    @Override
52    public void onResume() {
53        super.onResume();
54        ThemeSettingsFragment.updateKeyboardThemeSummary(findPreference(Settings.SCREEN_THEME));
55    }
56
57    @Override
58    public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
59        if (FeedbackUtils.isHelpAndFeedbackFormSupported()) {
60            menu.add(NO_MENU_GROUP, MENU_HELP_AND_FEEDBACK /* itemId */,
61                    MENU_HELP_AND_FEEDBACK /* order */, R.string.help_and_feedback);
62        }
63        final int aboutResId = FeedbackUtils.getAboutKeyboardTitleResId();
64        if (aboutResId != 0) {
65            menu.add(NO_MENU_GROUP, MENU_ABOUT /* itemId */, MENU_ABOUT /* order */, aboutResId);
66        }
67    }
68
69    @Override
70    public boolean onOptionsItemSelected(final MenuItem item) {
71        final int itemId = item.getItemId();
72        if (itemId == MENU_HELP_AND_FEEDBACK) {
73            FeedbackUtils.showHelpAndFeedbackForm(getActivity());
74            return true;
75        }
76        if (itemId == MENU_ABOUT) {
77            final Intent aboutIntent = FeedbackUtils.getAboutKeyboardIntent(getActivity());
78            if (aboutIntent != null) {
79                startActivity(aboutIntent);
80                return true;
81            }
82        }
83        return super.onOptionsItemSelected(item);
84    }
85}
86