SettingsFragment.java revision a715d7f6fd3b29e660d78f83815ebe75837f1436
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    private static final int NO_MENU_GROUP = Menu.NONE; // We don't care about menu grouping.
33    private static final int MENU_FEEDBACK = Menu.FIRST; // The first menu item id and order.
34    private static final int MENU_ABOUT = Menu.FIRST + 1; // The second menu item id and order.
35
36    @Override
37    public void onCreate(final Bundle icicle) {
38        super.onCreate(icicle);
39        setHasOptionsMenu(true);
40        setInputMethodSettingsCategoryTitle(R.string.language_selection_title);
41        setSubtypeEnablerTitle(R.string.select_language);
42        addPreferencesFromResource(R.xml.prefs);
43        final PreferenceScreen preferenceScreen = getPreferenceScreen();
44        preferenceScreen.setTitle(
45                ApplicationUtils.getActivityTitleResId(getActivity(), SettingsActivity.class));
46    }
47
48    @Override
49    public void onResume() {
50        super.onResume();
51        ThemeSettingsFragment.updateKeyboardThemeSummary(findPreference(Settings.SCREEN_THEME));
52    }
53
54    @Override
55    public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
56        if (FeedbackUtils.isFeedbackFormSupported()) {
57            menu.add(NO_MENU_GROUP, MENU_FEEDBACK /* itemId */, MENU_FEEDBACK /* order */,
58                    R.string.send_feedback);
59        }
60        final int aboutResId = FeedbackUtils.getAboutKeyboardTitleResId();
61        if (aboutResId != 0) {
62            menu.add(NO_MENU_GROUP, MENU_ABOUT /* itemId */, MENU_ABOUT /* order */, aboutResId);
63        }
64    }
65
66    @Override
67    public boolean onOptionsItemSelected(final MenuItem item) {
68        final int itemId = item.getItemId();
69        if (itemId == MENU_FEEDBACK) {
70            FeedbackUtils.showFeedbackForm(getActivity());
71            return true;
72        }
73        if (itemId == MENU_ABOUT) {
74            final Intent aboutIntent = FeedbackUtils.getAboutKeyboardIntent(getActivity());
75            if (aboutIntent != null) {
76                startActivity(aboutIntent);
77                return true;
78            }
79        }
80        return super.onOptionsItemSelected(item);
81    }
82}
83