Home | History | Annotate | Download | only in settings
      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.utils.FragmentUtils;
     20 
     21 import android.app.ActionBar;
     22 import android.content.Intent;
     23 import android.os.Bundle;
     24 import android.preference.PreferenceActivity;
     25 import android.view.MenuItem;
     26 
     27 public final class SettingsActivity extends PreferenceActivity {
     28     public static final String EXTRA_SHOW_HOME_AS_UP = "show_home_as_up";
     29     private static final String DEFAULT_FRAGMENT = SettingsFragment.class.getName();
     30     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     }
     51 
     52     @Override
     53     public Intent getIntent() {
     54         final Intent intent = super.getIntent();
     55         final String fragment = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
     56         if (fragment == null) {
     57             intent.putExtra(EXTRA_SHOW_FRAGMENT, DEFAULT_FRAGMENT);
     58         }
     59         intent.putExtra(EXTRA_NO_HEADERS, true);
     60         return intent;
     61     }
     62 
     63     @Override
     64     public boolean isValidFragment(final String fragmentName) {
     65         return FragmentUtils.isValidFragment(fragmentName);
     66     }
     67 }
     68