/* * Copyright (C) 2014 TeamEos * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.du; import java.util.ArrayList; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.os.Bundle; import android.os.UserHandle; import android.support.v7.preference.ListPreference; import android.support.v14.preference.SwitchPreference; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceCategory; import android.support.v7.preference.PreferenceScreen; import android.support.v7.preference.Preference.OnPreferenceChangeListener; import android.provider.Settings; import com.android.settings.SettingsPreferenceFragment; import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.MetricsProto.MetricsEvent; import com.android.internal.utils.du.ActionConstants; import com.android.internal.utils.du.Config; import com.android.internal.utils.du.DUActionUtils; import com.android.internal.utils.du.Config.ButtonConfig; import com.android.settings.du.preference.CustomSeekBarPreference; import com.android.settings.dashboard.SummaryLoader; import com.android.settings.R; public class NavbarSettings extends SettingsPreferenceFragment implements OnPreferenceChangeListener { private static final String NAVBAR_VISIBILITY = "navbar_visibility"; private static final String KEY_NAVBAR_MODE = "navbar_mode"; private static final String KEY_FLING_NAVBAR_SETTINGS = "fling_settings"; private static final String KEY_CATEGORY_NAVIGATION_INTERFACE = "category_navbar_interface"; private static final String KEY_CATEGORY_NAVIGATION_GENERAL = "category_navbar_general"; private static final String KEY_NAVIGATION_BAR_LEFT = "navigation_bar_left"; private static final String KEY_SMARTBAR_SETTINGS = "smartbar_settings"; private static final String KEY_NAVIGATION_HEIGHT_PORT = "navbar_height_portrait"; private static final String KEY_NAVIGATION_HEIGHT_LAND = "navbar_height_landscape"; private static final String KEY_NAVIGATION_WIDTH = "navbar_width"; private SwitchPreference mNavbarVisibility; private ListPreference mNavbarMode; private PreferenceScreen mFlingSettings; private PreferenceCategory mNavInterface; private PreferenceCategory mNavGeneral; private PreferenceScreen mSmartbarSettings; private CustomSeekBarPreference mBarHeightPort; private CustomSeekBarPreference mBarHeightLand; private CustomSeekBarPreference mBarWidth; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.navbar_settings); mNavInterface = (PreferenceCategory) findPreference(KEY_CATEGORY_NAVIGATION_INTERFACE); mNavGeneral = (PreferenceCategory) findPreference(KEY_CATEGORY_NAVIGATION_GENERAL); mNavbarVisibility = (SwitchPreference) findPreference(NAVBAR_VISIBILITY); mNavbarMode = (ListPreference) findPreference(KEY_NAVBAR_MODE); mFlingSettings = (PreferenceScreen) findPreference(KEY_FLING_NAVBAR_SETTINGS); mSmartbarSettings = (PreferenceScreen) findPreference(KEY_SMARTBAR_SETTINGS); boolean showing = Settings.Secure.getInt(getContentResolver(), Settings.Secure.NAVIGATION_BAR_VISIBLE, DUActionUtils.hasNavbarByDefault(getActivity()) ? 1 : 0) != 0; updateBarVisibleAndUpdatePrefs(showing); mNavbarVisibility.setOnPreferenceChangeListener(this); int mode = Settings.Secure.getInt(getContentResolver(), Settings.Secure.NAVIGATION_BAR_MODE, 0); updateBarModeSettings(mode); mNavbarMode.setOnPreferenceChangeListener(this); int size = Settings.Secure.getIntForUser(getContentResolver(), Settings.Secure.NAVIGATION_BAR_HEIGHT, 100, UserHandle.USER_CURRENT); mBarHeightPort = (CustomSeekBarPreference) findPreference(KEY_NAVIGATION_HEIGHT_PORT); mBarHeightPort.setValue(size); mBarHeightPort.setOnPreferenceChangeListener(this); final boolean canMove = DUActionUtils.navigationBarCanMove(); if (canMove) { mNavGeneral.removePreference(findPreference(KEY_NAVIGATION_HEIGHT_LAND)); size = Settings.Secure.getIntForUser(getContentResolver(), Settings.Secure.NAVIGATION_BAR_WIDTH, 100, UserHandle.USER_CURRENT); mBarWidth = (CustomSeekBarPreference) findPreference(KEY_NAVIGATION_WIDTH); mBarWidth.setValue(size); mBarWidth.setOnPreferenceChangeListener(this); } else { mNavGeneral.removePreference(findPreference(KEY_NAVIGATION_WIDTH)); size = Settings.Secure.getIntForUser(getContentResolver(), Settings.Secure.NAVIGATION_BAR_HEIGHT_LANDSCAPE, 100, UserHandle.USER_CURRENT); mBarHeightLand = (CustomSeekBarPreference) findPreference(KEY_NAVIGATION_HEIGHT_LAND); mBarHeightLand.setValue(size); mBarHeightLand.setOnPreferenceChangeListener(this); } } private void updateBarModeSettings(int mode) { mNavbarMode.setValue(String.valueOf(mode)); mSmartbarSettings.setEnabled(mode == 0); mSmartbarSettings.setSelectable(mode == 0); mFlingSettings.setEnabled(mode == 1); mFlingSettings.setSelectable(mode == 1); } private void updateBarVisibleAndUpdatePrefs(boolean showing) { mNavbarVisibility.setChecked(showing); mNavInterface.setEnabled(mNavbarVisibility.isChecked()); mNavGeneral.setEnabled(mNavbarVisibility.isChecked()); } @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (preference.equals(mNavbarMode)) { int mode = Integer.parseInt(((String) newValue).toString()); Settings.Secure.putInt(getContentResolver(), Settings.Secure.NAVIGATION_BAR_MODE, mode); updateBarModeSettings(mode); return true; } else if (preference.equals(mNavbarVisibility)) { boolean showing = ((Boolean)newValue); Settings.Secure.putInt(getContentResolver(), Settings.Secure.NAVIGATION_BAR_VISIBLE, showing ? 1 : 0); updateBarVisibleAndUpdatePrefs(showing); return true; } else if (preference == mBarHeightPort) { int val = (Integer) newValue; Settings.Secure.putIntForUser(getContentResolver(), Settings.Secure.NAVIGATION_BAR_HEIGHT, val, UserHandle.USER_CURRENT); return true; } else if (preference == mBarHeightLand) { int val = (Integer) newValue; Settings.Secure.putIntForUser(getContentResolver(), Settings.Secure.NAVIGATION_BAR_HEIGHT_LANDSCAPE, val, UserHandle.USER_CURRENT); return true; } else if (preference == mBarWidth) { int val = (Integer) newValue; Settings.Secure.putIntForUser(getContentResolver(), Settings.Secure.NAVIGATION_BAR_WIDTH, val, UserHandle.USER_CURRENT); return true; } return false; } @Override protected int getMetricsCategory() { return MetricsEvent.APPLICATION; } private static class SummaryProvider implements SummaryLoader.SummaryProvider { private final Context mContext; private final SummaryLoader mSummaryLoader; public SummaryProvider(Context context, SummaryLoader summaryLoader) { mContext = context; mSummaryLoader = summaryLoader; } @Override public void setListening(boolean listening) { if (listening) { mSummaryLoader.setSummary(this, mContext.getString(R.string.summary_navbar)); } } } public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY = new SummaryLoader.SummaryProviderFactory() { @Override public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity, SummaryLoader summaryLoader) { return new SummaryProvider(activity, summaryLoader); } }; }