Skip to content

Commit

Permalink
Allow Heads up and Ticker to play nice once and for all
Browse files Browse the repository at this point in the history
Until now users could enable both ticker and heads up and while only one
would work at a time, we would get reports of one not working. This was
common sense for most but not for all.

This commit takes care of that issue and protects the user from the user.
You can now only enable one at a time. So if heads up is enabled the ticker
is disabled and if the ticker was enabled, heads is disabled.

- Renamed ticker preference
- Moved ticker under Mulitasking

Change-Id: Ic7b9a509d954b0b0aee331759f85fcf45fb457ea
  • Loading branch information
Alex Cruz authored and nychitman1 committed Nov 10, 2017
1 parent e73cdb7 commit ffc7467
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
2 changes: 1 addition & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
<string name="heads_up_blacklist_dialog_delete_message">Remove selected item?</string>

<!-- Status bar ticker -->
<string name="ticker_mode_title">Statusbar notification ticker</string>
<string name="ticker_mode_title">Allow notification ticker</string>
<string name="ticker_disabled">Disabled</string>
<string name="ticker_enabled">Notification ticker</string>
<string name="ticker_media_enabled">Notification and music ticker</string>
Expand Down
7 changes: 6 additions & 1 deletion res/xml/multitasking.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@
android:fragment="com.dirtyunicorns.tweaks.fragments.Recents"
android:layout="@layout/recents" />

</PreferenceScreen>
<com.android.settings.applications.LayoutPreference
android:key="ticker_category"
android:fragment="com.dirtyunicorns.tweaks.fragments.Ticker"
android:layout="@layout/ticker" />

</PreferenceScreen>
5 changes: 0 additions & 5 deletions res/xml/statusbar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@
android:fragment="com.dirtyunicorns.tweaks.fragments.QuickSettings"
android:layout="@layout/quicksettings" />

<com.android.settings.applications.LayoutPreference
android:key="ticker_category"
android:fragment="com.dirtyunicorns.tweaks.fragments.Ticker"
android:layout="@layout/ticker" />

<com.android.settings.applications.LayoutPreference
android:key="traffic_category"
android:fragment="com.dirtyunicorns.tweaks.fragments.TrafficIndicators"
Expand Down
24 changes: 24 additions & 0 deletions src/com/dirtyunicorns/tweaks/fragments/HeadsUp.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ContentResolver;
import android.content.DialogInterface;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
Expand All @@ -38,6 +39,7 @@
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.dirtyunicorns.tweaks.preferences.GlobalSettingSwitchPreference;
import com.dirtyunicorns.tweaks.preferences.PackageListAdapter;
import com.dirtyunicorns.tweaks.preferences.PackageListAdapter.PackageItem;
import android.provider.Settings;
Expand All @@ -52,6 +54,8 @@ public class HeadsUp extends SettingsPreferenceFragment

private static final int DIALOG_BLACKLIST_APPS = 0;

private static final String KEY_HEADS_UP_NOTIFICATIONS_ENABLED = "heads_up_notifications_enabled";

private PackageListAdapter mPackageAdapter;
private PackageManager mPackageManager;
private PreferenceGroup mBlacklistPrefList;
Expand All @@ -60,6 +64,8 @@ public class HeadsUp extends SettingsPreferenceFragment
private String mBlacklistPackageList;
private Map<String, Package> mBlacklistPackages;

private GlobalSettingSwitchPreference mHeadsUpNotificationsEnabled;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -77,6 +83,9 @@ public void onCreate(Bundle savedInstanceState) {

mAddBlacklistPref = findPreference("add_blacklist_packages");
mAddBlacklistPref.setOnPreferenceClickListener(this);

mHeadsUpNotificationsEnabled = (GlobalSettingSwitchPreference) findPreference(KEY_HEADS_UP_NOTIFICATIONS_ENABLED);
updatePrefs();
}

@Override
Expand Down Expand Up @@ -207,6 +216,7 @@ public void onClick(DialogInterface dialog, int which) {

builder.show();
}
updatePrefs();
return true;
}

Expand Down Expand Up @@ -285,4 +295,18 @@ private void savePackageList(boolean preferencesUpdated) {
Settings.System.putString(getContentResolver(),
Settings.System.HEADS_UP_BLACKLIST_VALUES, value);
}

private void updatePrefs() {
ContentResolver resolver = getActivity().getContentResolver();
boolean enabled = (Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_SHOW_TICKER, 0) == 1) ||
(Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_SHOW_TICKER, 0) == 2);
if (enabled) {
Settings.Global.putInt(resolver,
Settings.Global.HEADS_UP_NOTIFICATIONS_ENABLED, 0);
mBlacklistPrefList.setEnabled(false);
mHeadsUpNotificationsEnabled.setEnabled(false);
}
}
}
15 changes: 14 additions & 1 deletion src/com/dirtyunicorns/tweaks/fragments/Ticker.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public void onCreate(Bundle savedInstanceState) {
mTickerMode.setOnPreferenceChangeListener(this);
int tickerMode = Settings.System.getIntForUser(getContentResolver(),
Settings.System.STATUS_BAR_SHOW_TICKER,
1, UserHandle.USER_CURRENT);
0, UserHandle.USER_CURRENT);
updatePrefs();
mTickerMode.setValue(String.valueOf(tickerMode));
mTickerMode.setSummary(mTickerMode.getEntry());
}
Expand All @@ -61,6 +62,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
int tickerMode = Integer.parseInt(((String) newValue).toString());
Settings.System.putIntForUser(getContentResolver(),
Settings.System.STATUS_BAR_SHOW_TICKER, tickerMode, UserHandle.USER_CURRENT);
updatePrefs();
int index = mTickerMode.findIndexOfValue((String) newValue);
mTickerMode.setSummary(
mTickerMode.getEntries()[index]);
Expand All @@ -69,6 +71,17 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
return false;
}

private void updatePrefs() {
ContentResolver resolver = getActivity().getContentResolver();
boolean enabled = (Settings.Global.getInt(resolver,
Settings.Global.HEADS_UP_NOTIFICATIONS_ENABLED, 0) == 1);
if (enabled) {
Settings.System.putInt(resolver,
Settings.System.STATUS_BAR_SHOW_TICKER, 0);
mTickerMode.setEnabled(false);
}
}

@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.DIRTYTWEAKS;
Expand Down

0 comments on commit ffc7467

Please sign in to comment.