Merge "[2/2] OmniGears: Smart pulldown" into android-4.4
diff --git a/res/values/custom_arrays.xml b/res/values/custom_arrays.xml
index d632f6a..dd68836 100644
--- a/res/values/custom_arrays.xml
+++ b/res/values/custom_arrays.xml
@@ -289,6 +289,19 @@
<item>3</item>
</string-array>
+ <!-- Smart pulldown -->
+ <string-array name="smart_pulldown_entries" translatable="false">
+ <item>@string/smart_pulldown_off</item>
+ <item>@string/smart_pulldown_dismissable</item>
+ <item>@string/smart_pulldown_persistent</item>
+ </string-array>
+
+ <string-array name="smart_pulldown_values" translatable="false">
+ <item>0</item>
+ <item>1</item>
+ <item>2</item>
+ </string-array>
+
<!--- Volume key cursor control -->
<string-array name="volume_key_cursor_control_entries" translatable="false">
<item>@string/disabled</item>
diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml
index a576cd1..807589d 100644
--- a/res/values/custom_strings.xml
+++ b/res/values/custom_strings.xml
@@ -386,6 +386,13 @@
<string name="quick_pulldown_left">Left</string>
<string name="quick_pulldown_right">Right</string>
+ <!-- QuickSettings: Smart Pulldown -->
+ <string name="smart_pulldown_title">Smart pulldown</string>
+ <string name="smart_pulldown_summary">Open Quick Settings when there are no notifications present</string>
+ <string name="smart_pulldown_off">Off</string>
+ <string name="smart_pulldown_dismissable">Pulldown if there are no cleareable notifications</string>
+ <string name="smart_pulldown_persistent">Pulldown if there are no notifications</string>
+
<!-- Cursor control -->
<string name="volume_key_cursor_control_title">Cursor control</string>
<string name="volume_key_cursor_control_on">Left/right</string>
diff --git a/res/xml/bars_settings.xml b/res/xml/bars_settings.xml
index 06e6c56..9bd2a18 100644
--- a/res/xml/bars_settings.xml
+++ b/res/xml/bars_settings.xml
@@ -57,6 +57,14 @@
android:entryValues="@array/quick_pulldown_values"
android:persistent="false" />
+ <ListPreference
+ android:key="smart_pulldown"
+ android:title="@string/smart_pulldown_title"
+ android:summary="@string/smart_pulldown_summary"
+ android:entries="@array/smart_pulldown_entries"
+ android:entryValues="@array/smart_pulldown_values"
+ android:persistent="false" />
+
<CheckBoxPreference
android:key="quicksettings_dynamic_row"
android:title="@string/qs_configurable_title"
diff --git a/src/org/omnirom/omnigears/interfacesettings/BarsSettings.java b/src/org/omnirom/omnigears/interfacesettings/BarsSettings.java
index bdb8bd0..1bf48a5 100644
--- a/src/org/omnirom/omnigears/interfacesettings/BarsSettings.java
+++ b/src/org/omnirom/omnigears/interfacesettings/BarsSettings.java
@@ -33,7 +33,10 @@
import android.preference.PreferenceScreen;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
+import android.util.DisplayMetrics;
import android.util.Log;
+import android.view.DisplayInfo;
+import android.view.WindowManager;
import android.view.WindowManagerGlobal;
public class BarsSettings extends SettingsPreferenceFragment implements
@@ -45,16 +48,23 @@
private static final String STATUS_BAR_TRAFFIC = "status_bar_traffic";
private static final String STATUS_BAR_NETWORK_ACTIVITY = "status_bar_network_activity";
private static final String QUICK_PULLDOWN = "quick_pulldown";
+ private static final String SMART_PULLDOWN = "smart_pulldown";
private static final String QUICKSETTINGS_DYNAMIC = "quicksettings_dynamic_row";
private static final String CATEGORY_NAVBAR = "category_navigation_bar";
private static final String SOFT_BACK_KILL_APP = "soft_back_kill_app";
+ // Device types
+ private static final int DEVICE_PHONE = 0;
+ private static final int DEVICE_HYBRID = 1;
+ private static final int DEVICE_TABLET = 2;
+
private CheckBoxPreference mStatusBarBrightnessControl;
private CheckBoxPreference mStatusBarNotifCount;
private CheckBoxPreference mStatusBarTraffic;
private CheckBoxPreference mStatusBarNetworkActivity;
private CheckBoxPreference mQuickSettingsDynamic;
private ListPreference mQuickPulldown;
+ private ListPreference mSmartPulldown;
private CheckBoxPreference mSoftBackKillApp;
@Override
@@ -98,10 +108,24 @@
mStatusBarNetworkActivity.setOnPreferenceChangeListener(this);
mQuickPulldown = (ListPreference) findPreference(QUICK_PULLDOWN);
- mQuickPulldown.setOnPreferenceChangeListener(this);
- int statusQuickPulldown =
- Settings.System.getInt(resolver, Settings.System.QS_QUICK_PULLDOWN,0);
- mQuickPulldown.setValue(String.valueOf(statusQuickPulldown));
+ mSmartPulldown = (ListPreference) findPreference(SMART_PULLDOWN);
+
+ if (isPhone(getActivity())) {
+ int quickPulldown = Settings.System.getInt(resolver,
+ Settings.System.QS_QUICK_PULLDOWN, 0);
+ mQuickPulldown.setValue(String.valueOf(quickPulldown));
+ updateQuickPulldownSummary(quickPulldown);
+ mQuickPulldown.setOnPreferenceChangeListener(this);
+
+ int smartPulldown = Settings.System.getInt(resolver,
+ Settings.System.QS_SMART_PULLDOWN, 0);
+ mSmartPulldown.setValue(String.valueOf(smartPulldown));
+ updateSmartPulldownSummary(smartPulldown);
+ mSmartPulldown.setOnPreferenceChangeListener(this);
+ } else {
+ prefSet.removePreference(mQuickPulldown);
+ prefSet.removePreference(mSmartPulldown);
+ }
mQuickSettingsDynamic = (CheckBoxPreference) prefSet.findPreference(QUICKSETTINGS_DYNAMIC);
mQuickSettingsDynamic.setChecked(Settings.System.getInt(resolver,
@@ -157,9 +181,15 @@
Settings.System.putInt(resolver,
Settings.System.QUICK_SETTINGS_TILES_ROW, value ? 1 : 0);
} else if (preference == mQuickPulldown) {
- int statusQuickPulldown = Integer.valueOf((String) objValue);
+ int quickPulldown = Integer.valueOf((String) objValue);
Settings.System.putInt(resolver, Settings.System.QS_QUICK_PULLDOWN,
- statusQuickPulldown);
+ quickPulldown);
+ updateQuickPulldownSummary(quickPulldown);
+ } else if (preference == mSmartPulldown) {
+ int smartPulldown = Integer.valueOf((String) objValue);
+ Settings.System.putInt(resolver, Settings.System.QS_SMART_PULLDOWN,
+ smartPulldown);
+ updateSmartPulldownSummary(smartPulldown);
} else if (preference == mSoftBackKillApp) {
boolean value = (Boolean) objValue;
Settings.System.putInt(resolver,
@@ -182,4 +212,46 @@
}
return intState;
}
+
+ private void updateQuickPulldownSummary(int i) {
+ if (i == 0) {
+ mQuickPulldown.setSummary(R.string.quick_pulldown_off);
+ } else if (i == 1) {
+ mQuickPulldown.setSummary(R.string.quick_pulldown_right);
+ } else if (i == 2) {
+ mQuickPulldown.setSummary(R.string.quick_pulldown_left);
+ } else if (i == 3) {
+ mQuickPulldown.setSummary(R.string.quick_pulldown_centre);
+ }
+ }
+
+ private void updateSmartPulldownSummary(int i) {
+ if (i == 0) {
+ mSmartPulldown.setSummary(R.string.smart_pulldown_off);
+ } else if (i == 1) {
+ mSmartPulldown.setSummary(R.string.smart_pulldown_dismissable);
+ } else if (i == 2) {
+ mSmartPulldown.setSummary(R.string.smart_pulldown_persistent);
+ }
+ }
+
+ private static int getScreenType(Context con) {
+ WindowManager wm = (WindowManager) con.getSystemService(Context.WINDOW_SERVICE);
+ DisplayInfo outDisplayInfo = new DisplayInfo();
+ wm.getDefaultDisplay().getDisplayInfo(outDisplayInfo);
+ int shortSize = Math.min(outDisplayInfo.logicalHeight, outDisplayInfo.logicalWidth);
+ int shortSizeDp =
+ shortSize * DisplayMetrics.DENSITY_DEFAULT / outDisplayInfo.logicalDensityDpi;
+ if (shortSizeDp < 600) {
+ return DEVICE_PHONE;
+ } else if (shortSizeDp < 720) {
+ return DEVICE_HYBRID;
+ } else {
+ return DEVICE_TABLET;
+ }
+ }
+
+ public static boolean isPhone(Context con) {
+ return getScreenType(con) == DEVICE_PHONE;
+ }
}