1 /* 2 * Copyright (C) 2013 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.documentsui; 18 19 import android.app.ActionBar; 20 import android.app.Activity; 21 import android.content.Context; 22 import android.os.Bundle; 23 import android.preference.PreferenceFragment; 24 import android.preference.PreferenceManager; 25 import android.view.MenuItem; 26 27 public class SettingsActivity extends Activity { 28 private static final String KEY_ADVANCED_DEVICES = "advancedDevices"; 29 private static final String KEY_FILE_SIZE = "fileSize"; 30 31 public static boolean getDisplayAdvancedDevices(Context context) { 32 return PreferenceManager.getDefaultSharedPreferences(context) 33 .getBoolean(KEY_ADVANCED_DEVICES, false); 34 } 35 36 public static boolean getDisplayFileSize(Context context) { 37 return PreferenceManager.getDefaultSharedPreferences(context) 38 .getBoolean(KEY_FILE_SIZE, false); 39 } 40 41 @Override 42 protected void onCreate(Bundle savedInstanceState) { 43 super.onCreate(savedInstanceState); 44 45 getFragmentManager() 46 .beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit(); 47 48 final ActionBar bar = getActionBar(); 49 if (bar != null) { 50 bar.setDisplayShowHomeEnabled(false); 51 bar.setDisplayHomeAsUpEnabled(true); 52 } 53 } 54 55 @Override 56 public boolean onOptionsItemSelected(MenuItem item) { 57 if (item.getItemId() == android.R.id.home) { 58 finish(); 59 return true; 60 } 61 return super.onOptionsItemSelected(item); 62 } 63 64 public static class SettingsFragment extends PreferenceFragment { 65 @Override 66 public void onCreate(Bundle savedInstanceState) { 67 super.onCreate(savedInstanceState); 68 addPreferencesFromResource(R.xml.preferences); 69 } 70 } 71 } 72