SettingsActivity.java revision 2fb8e5eecf0b472c00c40ab01d7bae81bdd4459f
1/* 2 * Copyright (C) 2012 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 com.android.inputmethod.latin.utils.FragmentUtils; 20import com.android.inputmethod.latin.utils.StatsUtils; 21import com.android.inputmethod.latin.utils.StatsUtilsManager; 22 23import android.app.ActionBar; 24import android.content.Intent; 25import android.os.Bundle; 26import android.preference.PreferenceActivity; 27import android.view.MenuItem; 28 29public final class SettingsActivity extends PreferenceActivity { 30 private static final String DEFAULT_FRAGMENT = SettingsFragment.class.getName(); 31 32 public static final String EXTRA_SHOW_HOME_AS_UP = "show_home_as_up"; 33 public static final String EXTRA_ENTRY_KEY = "entry"; 34 public static final String EXTRA_ENTRY_VALUE_LONG_PRESS_COMMA = "long_press_comma"; 35 public static final String EXTRA_ENTRY_VALUE_APP_ICON = "app_icon"; 36 public static final String EXTRA_ENTRY_VALUE_NOTICE_DIALOG = "important_notice"; 37 public static final String EXTRA_ENTRY_VALUE_SYSTEM_SETTINGS = "system_settings"; 38 39 private boolean mShowHomeAsUp; 40 41 @Override 42 protected void onCreate(final Bundle savedState) { 43 super.onCreate(savedState); 44 final ActionBar actionBar = getActionBar(); 45 final Intent intent = getIntent(); 46 if (actionBar != null) { 47 mShowHomeAsUp = intent.getBooleanExtra(EXTRA_SHOW_HOME_AS_UP, true); 48 actionBar.setDisplayHomeAsUpEnabled(mShowHomeAsUp); 49 actionBar.setHomeButtonEnabled(mShowHomeAsUp); 50 } 51 StatsUtils.onSettingsActivity( 52 intent.hasExtra(EXTRA_ENTRY_KEY) ? intent.getStringExtra(EXTRA_ENTRY_KEY) 53 : EXTRA_ENTRY_VALUE_SYSTEM_SETTINGS); 54 } 55 56 @Override 57 public boolean onOptionsItemSelected(final MenuItem item) { 58 if (mShowHomeAsUp && item.getItemId() == android.R.id.home) { 59 finish(); 60 return true; 61 } 62 return super.onOptionsItemSelected(item); 63 } 64 65 @Override 66 public Intent getIntent() { 67 final Intent intent = super.getIntent(); 68 final String fragment = intent.getStringExtra(EXTRA_SHOW_FRAGMENT); 69 if (fragment == null) { 70 intent.putExtra(EXTRA_SHOW_FRAGMENT, DEFAULT_FRAGMENT); 71 } 72 intent.putExtra(EXTRA_NO_HEADERS, true); 73 return intent; 74 } 75 76 @Override 77 public boolean isValidFragment(final String fragmentName) { 78 return FragmentUtils.isValidFragment(fragmentName); 79 } 80} 81