blob: b0c494098ed0906dc5668df788b57cbc04f89b5f [file] [log] [blame]
Tadashi G. Takaokac206d042012-04-13 19:53:44 +09001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
Tadashi G. Takaoka8aa99632013-01-21 21:52:57 +09004 * 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. Takaokac206d042012-04-13 19:53:44 +09007 *
Tadashi G. Takaoka8aa99632013-01-21 21:52:57 +09008 * http://www.apache.org/licenses/LICENSE-2.0
Tadashi G. Takaokac206d042012-04-13 19:53:44 +09009 *
10 * Unless required by applicable law or agreed to in writing, software
Tadashi G. Takaoka8aa99632013-01-21 21:52:57 +090011 * 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. Takaokac206d042012-04-13 19:53:44 +090015 */
16
Ken Wakasaa7d2fc62013-07-22 12:43:37 +090017package com.android.inputmethod.latin.settings;
Tadashi G. Takaokac206d042012-04-13 19:53:44 +090018
Satoshi Kataoka64f64bd2013-10-09 14:19:24 +090019import com.android.inputmethod.latin.utils.FragmentUtils;
20
Tadashi G. Takaoka76cffec2014-07-23 14:12:27 -070021import android.app.ActionBar;
Tadashi G. Takaokac206d042012-04-13 19:53:44 +090022import android.content.Intent;
Tadashi G. Takaoka76cffec2014-07-23 14:12:27 -070023import android.os.Bundle;
Tadashi G. Takaokac206d042012-04-13 19:53:44 +090024import android.preference.PreferenceActivity;
Tadashi G. Takaoka76cffec2014-07-23 14:12:27 -070025import android.view.MenuItem;
Tadashi G. Takaokac206d042012-04-13 19:53:44 +090026
Tadashi G. Takaokaa28a05e2012-09-27 18:16:16 +090027public final class SettingsActivity extends PreferenceActivity {
Tadashi G. Takaoka76cffec2014-07-23 14:12:27 -070028 public static final String EXTRA_SHOW_HOME_AS_UP = "show_home_as_up";
Tadashi G. Takaokacbee8a32013-01-08 15:41:46 +090029 private static final String DEFAULT_FRAGMENT = SettingsFragment.class.getName();
Tadashi G. Takaoka76cffec2014-07-23 14:12:27 -070030 private boolean mShowHomeAsUp;
31
32 @Override
33 protected void onCreate(final Bundle savedState) {
34 super.onCreate(savedState);
35 final ActionBar actionBar = getActionBar();
36 if (actionBar != null) {
37 mShowHomeAsUp = getIntent().getBooleanExtra(EXTRA_SHOW_HOME_AS_UP, true);
38 actionBar.setDisplayHomeAsUpEnabled(mShowHomeAsUp);
39 actionBar.setHomeButtonEnabled(mShowHomeAsUp);
40 }
41 }
42
43 @Override
44 public boolean onOptionsItemSelected(final MenuItem item) {
45 if (mShowHomeAsUp && item.getItemId() == android.R.id.home) {
46 finish();
47 return true;
48 }
49 return super.onOptionsItemSelected(item);
50 }
Tadashi G. Takaokac27fe622012-04-13 16:41:24 +090051
Tadashi G. Takaokac206d042012-04-13 19:53:44 +090052 @Override
53 public Intent getIntent() {
Tadashi G. Takaokac27fe622012-04-13 16:41:24 +090054 final Intent intent = super.getIntent();
Tadashi G. Takaoka262d5bd2013-04-10 16:21:20 +090055 final String fragment = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
56 if (fragment == null) {
57 intent.putExtra(EXTRA_SHOW_FRAGMENT, DEFAULT_FRAGMENT);
58 }
Tadashi G. Takaokac27fe622012-04-13 16:41:24 +090059 intent.putExtra(EXTRA_NO_HEADERS, true);
60 return intent;
Tadashi G. Takaokac206d042012-04-13 19:53:44 +090061 }
Satoshi Kataokac5182c92013-10-02 15:39:25 +090062
Tadashi G. Takaokabfcd98e2014-07-23 17:08:18 -070063 @Override
Tadashi G. Takaoka76cffec2014-07-23 14:12:27 -070064 public boolean isValidFragment(final String fragmentName) {
Satoshi Kataoka64f64bd2013-10-09 14:19:24 +090065 return FragmentUtils.isValidFragment(fragmentName);
Satoshi Kataokac5182c92013-10-02 15:39:25 +090066 }
Tadashi G. Takaokac206d042012-04-13 19:53:44 +090067}