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