Nick0703

Untitled

Feb 12th, 2014
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.01 KB | None | 0 0
  1. /*
  2.  * Copyright (C) 2012 The CyanogenMod 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.settings.cyanogenmod;
  18.  
  19. import android.content.ContentResolver;
  20. import android.content.res.Resources;
  21. import android.os.Bundle;
  22. import android.os.RemoteException;
  23. import android.preference.CheckBoxPreference;
  24. import android.preference.ListPreference;
  25. import android.preference.Preference;
  26. import android.preference.PreferenceCategory;
  27. import android.preference.PreferenceScreen;
  28. import android.provider.Settings;
  29. import android.util.Log;
  30. import android.view.WindowManagerGlobal;
  31.  
  32. import com.android.settings.R;
  33. import com.android.settings.SettingsPreferenceFragment;
  34. import com.android.settings.Utils;
  35.  
  36. public class SystemUiSettings extends SettingsPreferenceFragment  implements
  37.         Preference.OnPreferenceChangeListener {
  38.     private static final String TAG = "SystemSettings";
  39.  
  40.     private static final String KEY_EXPANDED_DESKTOP = "expanded_desktop";
  41.     private static final String KEY_EXPANDED_DESKTOP_NO_NAVBAR = "expanded_desktop_no_navbar";
  42.     private static final String CATEGORY_NAVBAR = "navigation_bar";
  43.     private static final String KEY_SCREEN_GESTURE_SETTINGS = "touch_screen_gesture_settings";
  44.     private static final String ENABLE_NAVIGATION_BAR = "enable_nav_bar"; // Enable/disable nav bar
  45.     private static final String KEY_NAVIGATION_BAR_LEFT = "navigation_bar_left";
  46.  
  47.     private ListPreference mExpandedDesktopPref;
  48.     private CheckBoxPreference mExpandedDesktopNoNavbarPref;
  49.     private CheckBoxPreference mEnableNavigationBar; // Enable/disable nav bar
  50.     private CheckBoxPreference mNavigationBarLeftPref;
  51.  
  52.     @Override
  53.     public void onCreate(Bundle savedInstanceState) {
  54.         super.onCreate(savedInstanceState);
  55.  
  56.         addPreferencesFromResource(R.xml.system_ui_settings);
  57.         PreferenceScreen prefScreen = getPreferenceScreen();
  58.  
  59.         // Expanded desktop
  60.         mExpandedDesktopPref = (ListPreference) findPreference(KEY_EXPANDED_DESKTOP);
  61.         mExpandedDesktopNoNavbarPref =
  62.                 (CheckBoxPreference) findPreference(KEY_EXPANDED_DESKTOP_NO_NAVBAR);
  63.  
  64.         // Navigation bar left
  65.         mNavigationBarLeftPref = (CheckBoxPreference) findPreference(KEY_NAVIGATION_BAR_LEFT);
  66.  
  67.         Utils.updatePreferenceToSpecificActivityFromMetaDataOrRemove(getActivity(),
  68.                 getPreferenceScreen(), KEY_SCREEN_GESTURE_SETTINGS);
  69.  
  70.         int expandedDesktopValue = Settings.System.getInt(getContentResolver(),
  71.                 Settings.System.EXPANDED_DESKTOP_STYLE, 0);
  72.  
  73.         try {
  74.             boolean hasNavBar = WindowManagerGlobal.getWindowManagerService().hasNavigationBar();
  75.  
  76.             if (hasNavBar) {
  77.                 mExpandedDesktopPref.setOnPreferenceChangeListener(this);
  78.                 mExpandedDesktopPref.setValue(String.valueOf(expandedDesktopValue));
  79.                 updateExpandedDesktop(expandedDesktopValue);
  80.                 prefScreen.removePreference(mExpandedDesktopNoNavbarPref);
  81.  
  82.                 if (!Utils.isPhone(getActivity())) {
  83.                     PreferenceCategory navCategory =
  84.                             (PreferenceCategory) findPreference(CATEGORY_NAVBAR);
  85.                     navCategory.removePreference(mNavigationBarLeftPref);
  86.                 } else {
  87.                 }
  88.             } else {
  89.                 // Hide no-op "Status bar visible" expanded desktop mode
  90.                 mExpandedDesktopNoNavbarPref.setOnPreferenceChangeListener(this);
  91.                 mExpandedDesktopNoNavbarPref.setChecked(expandedDesktopValue > 0);
  92.                 prefScreen.removePreference(mExpandedDesktopPref);
  93.             }
  94.         } catch (RemoteException e) {
  95.             Log.e(TAG, "Error getting navigation bar status");
  96.         }
  97.  
  98.         // Booleans to enable/disable nav bar
  99.         // overriding overlays
  100.         boolean hasNavBarByDefault = getResources().getBoolean(
  101.                 com.android.internal.R.bool.config_showNavigationBar);
  102.         boolean enableNavigationBar = Settings.System.getInt(getContentResolver(),
  103.                 Settings.System.NAVIGATION_BAR_SHOW, hasNavBarByDefault ? 1 : 0) == 1;
  104.         mEnableNavigationBar = (CheckBoxPreference) findPreference(ENABLE_NAVIGATION_BAR);
  105.         mEnableNavigationBar.setChecked(enableNavigationBar);
  106.         mEnableNavigationBar.setOnPreferenceChangeListener(this);
  107.  
  108.         updateNavbarPreferences(enableNavigationBar);
  109.     }
  110.  
  111.     // Enable/disbale nav bar
  112.     private void updateNavbarPreferences(boolean show) {}
  113.  
  114.     public boolean onPreferenceChange(Preference preference, Object objValue) {
  115.         if (preference == mExpandedDesktopPref) {
  116.             int expandedDesktopValue = Integer.valueOf((String) objValue);
  117.             updateExpandedDesktop(expandedDesktopValue);
  118.             return true;
  119.         } else if (preference == mExpandedDesktopNoNavbarPref) {
  120.             boolean value = (Boolean) objValue;
  121.             updateExpandedDesktop(value ? 2 : 0);
  122.             return true;
  123.         } else if (preference == mEnableNavigationBar) { // Enable/disbale nav bar (used in custom nav bar dimensions)
  124.             Settings.System.putInt(getActivity().getContentResolver(),
  125.                     Settings.System.NAVIGATION_BAR_SHOW,
  126.                     ((Boolean) objValue) ? 1 : 0);
  127.             updateNavbarPreferences((Boolean) objValue);
  128.             return true;
  129.         }
  130.  
  131.         return false;
  132.     }
  133.  
  134.     private void updateExpandedDesktop(int value) {
  135.         ContentResolver cr = getContentResolver();
  136.         Resources res = getResources();
  137.         int summary = -1;
  138.  
  139.         Settings.System.putInt(cr, Settings.System.EXPANDED_DESKTOP_STYLE, value);
  140.  
  141.         if (value == 0) {
  142.             // Expanded desktop deactivated
  143.             Settings.System.putInt(cr, Settings.System.POWER_MENU_EXPANDED_DESKTOP_ENABLED, 0);
  144.             Settings.System.putInt(cr, Settings.System.EXPANDED_DESKTOP_STATE, 0);
  145.             summary = R.string.expanded_desktop_disabled;
  146.         } else if (value == 1) {
  147.             Settings.System.putInt(cr, Settings.System.POWER_MENU_EXPANDED_DESKTOP_ENABLED, 1);
  148.             summary = R.string.expanded_desktop_status_bar;
  149.         } else if (value == 2) {
  150.             Settings.System.putInt(cr, Settings.System.POWER_MENU_EXPANDED_DESKTOP_ENABLED, 1);
  151.             summary = R.string.expanded_desktop_no_status_bar;
  152.         }
  153.  
  154.         if (mExpandedDesktopPref != null && summary != -1) {
  155.             mExpandedDesktopPref.setSummary(res.getString(summary));
  156.         }
  157.     }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment