Tadashi G. Takaoka | c206d04 | 2012-04-13 19:53:44 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
Tadashi G. Takaoka | 8aa9963 | 2013-01-21 21:52:57 +0900 | [diff] [blame] | 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 |
Tadashi G. Takaoka | c206d04 | 2012-04-13 19:53:44 +0900 | [diff] [blame] | 7 | * |
Tadashi G. Takaoka | 8aa9963 | 2013-01-21 21:52:57 +0900 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Tadashi G. Takaoka | c206d04 | 2012-04-13 19:53:44 +0900 | [diff] [blame] | 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
Tadashi G. Takaoka | 8aa9963 | 2013-01-21 21:52:57 +0900 | [diff] [blame] | 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. |
Tadashi G. Takaoka | c206d04 | 2012-04-13 19:53:44 +0900 | [diff] [blame] | 15 | */ |
| 16 | |
Ken Wakasa | a7d2fc6 | 2013-07-22 12:43:37 +0900 | [diff] [blame] | 17 | package com.android.inputmethod.latin.settings; |
Tadashi G. Takaoka | c206d04 | 2012-04-13 19:53:44 +0900 | [diff] [blame] | 18 | |
Mohammadinamul Sheik | 6041586 | 2015-07-15 13:32:50 -0700 | [diff] [blame] | 19 | import com.android.inputmethod.latin.permissions.PermissionsManager; |
Satoshi Kataoka | 64f64bd | 2013-10-09 14:19:24 +0900 | [diff] [blame] | 20 | import com.android.inputmethod.latin.utils.FragmentUtils; |
Mohammadinamul Sheik | 93d2ab3 | 2015-03-13 16:12:14 -0700 | [diff] [blame] | 21 | import com.android.inputmethod.latin.utils.StatsUtils; |
| 22 | import com.android.inputmethod.latin.utils.StatsUtilsManager; |
Satoshi Kataoka | 64f64bd | 2013-10-09 14:19:24 +0900 | [diff] [blame] | 23 | |
Tadashi G. Takaoka | 76cffec | 2014-07-23 14:12:27 -0700 | [diff] [blame] | 24 | import android.app.ActionBar; |
Tadashi G. Takaoka | c206d04 | 2012-04-13 19:53:44 +0900 | [diff] [blame] | 25 | import android.content.Intent; |
Tadashi G. Takaoka | 76cffec | 2014-07-23 14:12:27 -0700 | [diff] [blame] | 26 | import android.os.Bundle; |
Tadashi G. Takaoka | c206d04 | 2012-04-13 19:53:44 +0900 | [diff] [blame] | 27 | import android.preference.PreferenceActivity; |
vineel sadineni | d256927 | 2018-05-15 14:55:43 -0700 | [diff] [blame] | 28 | import androidx.core.app.ActivityCompat; |
Tadashi G. Takaoka | 76cffec | 2014-07-23 14:12:27 -0700 | [diff] [blame] | 29 | import android.view.MenuItem; |
Tadashi G. Takaoka | c206d04 | 2012-04-13 19:53:44 +0900 | [diff] [blame] | 30 | |
Mohammadinamul Sheik | 6041586 | 2015-07-15 13:32:50 -0700 | [diff] [blame] | 31 | public final class SettingsActivity extends PreferenceActivity |
| 32 | implements ActivityCompat.OnRequestPermissionsResultCallback { |
Tadashi G. Takaoka | cbee8a3 | 2013-01-08 15:41:46 +0900 | [diff] [blame] | 33 | private static final String DEFAULT_FRAGMENT = SettingsFragment.class.getName(); |
Mohammadinamul Sheik | 93d2ab3 | 2015-03-13 16:12:14 -0700 | [diff] [blame] | 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 | |
Tadashi G. Takaoka | 76cffec | 2014-07-23 14:12:27 -0700 | [diff] [blame] | 42 | private boolean mShowHomeAsUp; |
| 43 | |
| 44 | @Override |
| 45 | protected void onCreate(final Bundle savedState) { |
| 46 | super.onCreate(savedState); |
| 47 | final ActionBar actionBar = getActionBar(); |
Mohammadinamul Sheik | 93d2ab3 | 2015-03-13 16:12:14 -0700 | [diff] [blame] | 48 | final Intent intent = getIntent(); |
Tadashi G. Takaoka | 76cffec | 2014-07-23 14:12:27 -0700 | [diff] [blame] | 49 | if (actionBar != null) { |
Mohammadinamul Sheik | 93d2ab3 | 2015-03-13 16:12:14 -0700 | [diff] [blame] | 50 | mShowHomeAsUp = intent.getBooleanExtra(EXTRA_SHOW_HOME_AS_UP, true); |
Tadashi G. Takaoka | 76cffec | 2014-07-23 14:12:27 -0700 | [diff] [blame] | 51 | actionBar.setDisplayHomeAsUpEnabled(mShowHomeAsUp); |
| 52 | actionBar.setHomeButtonEnabled(mShowHomeAsUp); |
| 53 | } |
Mohammadinamul Sheik | 93d2ab3 | 2015-03-13 16:12:14 -0700 | [diff] [blame] | 54 | StatsUtils.onSettingsActivity( |
| 55 | intent.hasExtra(EXTRA_ENTRY_KEY) ? intent.getStringExtra(EXTRA_ENTRY_KEY) |
Jatin Matani | 2fb8e5e | 2015-03-24 12:20:23 -0700 | [diff] [blame] | 56 | : EXTRA_ENTRY_VALUE_SYSTEM_SETTINGS); |
Tadashi G. Takaoka | 76cffec | 2014-07-23 14:12:27 -0700 | [diff] [blame] | 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 | } |
Tadashi G. Takaoka | c27fe62 | 2012-04-13 16:41:24 +0900 | [diff] [blame] | 67 | |
Tadashi G. Takaoka | c206d04 | 2012-04-13 19:53:44 +0900 | [diff] [blame] | 68 | @Override |
| 69 | public Intent getIntent() { |
Tadashi G. Takaoka | c27fe62 | 2012-04-13 16:41:24 +0900 | [diff] [blame] | 70 | final Intent intent = super.getIntent(); |
Tadashi G. Takaoka | 262d5bd | 2013-04-10 16:21:20 +0900 | [diff] [blame] | 71 | final String fragment = intent.getStringExtra(EXTRA_SHOW_FRAGMENT); |
| 72 | if (fragment == null) { |
| 73 | intent.putExtra(EXTRA_SHOW_FRAGMENT, DEFAULT_FRAGMENT); |
| 74 | } |
Tadashi G. Takaoka | c27fe62 | 2012-04-13 16:41:24 +0900 | [diff] [blame] | 75 | intent.putExtra(EXTRA_NO_HEADERS, true); |
| 76 | return intent; |
Tadashi G. Takaoka | c206d04 | 2012-04-13 19:53:44 +0900 | [diff] [blame] | 77 | } |
Satoshi Kataoka | c5182c9 | 2013-10-02 15:39:25 +0900 | [diff] [blame] | 78 | |
Tadashi G. Takaoka | bfcd98e | 2014-07-23 17:08:18 -0700 | [diff] [blame] | 79 | @Override |
Tadashi G. Takaoka | 76cffec | 2014-07-23 14:12:27 -0700 | [diff] [blame] | 80 | public boolean isValidFragment(final String fragmentName) { |
Satoshi Kataoka | 64f64bd | 2013-10-09 14:19:24 +0900 | [diff] [blame] | 81 | return FragmentUtils.isValidFragment(fragmentName); |
Satoshi Kataoka | c5182c9 | 2013-10-02 15:39:25 +0900 | [diff] [blame] | 82 | } |
Mohammadinamul Sheik | 6041586 | 2015-07-15 13:32:50 -0700 | [diff] [blame] | 83 | |
| 84 | @Override |
| 85 | public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { |
| 86 | PermissionsManager.get(this).onRequestPermissionsResult(requestCode, permissions, grantResults); |
| 87 | } |
Tadashi G. Takaoka | c206d04 | 2012-04-13 19:53:44 +0900 | [diff] [blame] | 88 | } |