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