Skip to content

Commit

Permalink
FB: Volume panel background color && transparency [2/2]
Browse files Browse the repository at this point in the history
Allow user to specify background color and transparency level
    for volume panel.

PS: color now applies instantaneously after setting the preference.
Change-Id: I23a09d302fe090fe4aed6dd9024c73056d14fba1
  • Loading branch information
dankoman30 authored and Gerrit Code Review committed Aug 25, 2014
1 parent 4819f6f commit 4551ceb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
7 changes: 7 additions & 0 deletions core/java/android/provider/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -2047,6 +2047,13 @@ public static void setShowGTalkServiceStatusForUser(ContentResolver cr, boolean
/** @hide */
public static final int VOLUME_OVERLAY_NONE = 3;

/**
* Volume panel background color
*
* @hide
*/
public static final String VOLUME_PANEL_BG_COLOR = "volume_panel_bg_color";

/**
* Whether the torch will pulse on incoming call
* @hide
Expand Down
32 changes: 30 additions & 2 deletions core/java/android/view/VolumePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.content.IntentFilter;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.media.AudioService;
import android.media.AudioSystem;
Expand Down Expand Up @@ -118,6 +119,8 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
private boolean mVoiceCapable;
private boolean mVolumeLinkNotification;
private int mCurrentOverlayStyle = -1;
private Drawable defaultBackground;
private int mPanelColor;

// True if we want to play tones on the system stream when the master stream is specified.
private final boolean mPlayMasterStreamTones;
Expand Down Expand Up @@ -236,6 +239,7 @@ public void onChange(boolean selfChange) {
Settings.System.MODE_VOLUME_OVERLAY, VOLUME_OVERLAY_EXPANDABLE,
UserHandle.USER_CURRENT);
changeOverlayStyle(overlayStyle);
setColor();
}
};

Expand Down Expand Up @@ -359,14 +363,17 @@ public void onDismiss(DialogInterface dialog) {
context.getContentResolver().registerContentObserver(
Settings.System.getUriFor(Settings.System.MODE_VOLUME_OVERLAY), false,
mSettingsObserver, UserHandle.USER_ALL);

context.getContentResolver().registerContentObserver(
Settings.System.getUriFor(Settings.System.VOLUME_PANEL_BG_COLOR), false,
mSettingsObserver, UserHandle.USER_ALL);
boolean masterVolumeKeySounds = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_useVolumeKeySounds);

mPlayMasterStreamTones = useMasterVolume && masterVolumeKeySounds;

mMoreButton.setOnClickListener(this);
listenToRingerMode();
setColor();
}

private void changeOverlayStyle(int newStyle) {
Expand Down Expand Up @@ -417,10 +424,31 @@ public void setTheme() {
// Force reload the background (to do not get the old cached one)
// and update the states.
mPanel.setBackgroundResource(R.color.transparent);
mPanel.setBackgroundResource(R.drawable.dialog_full_holo_dark);
setColor();
updateStates();
}

private void setColor() {
ContentResolver resolver = mContext.getContentResolver();

defaultBackground = mContext.getResources().getDrawable(
R.drawable.dialog_full_holo_dark).getCurrent();
mPanelColor = Settings.System.getIntForUser(resolver,
Settings.System.VOLUME_PANEL_BG_COLOR, -2, UserHandle.USER_CURRENT);

if (mPanelColor == Integer.MIN_VALUE
|| mPanelColor == -2) {
// Flag to reset volume panel background color
mPanel.setBackground(defaultBackground);
} else {
if (mPanelColor != 0x00ffffff) {
mPanel.setBackgroundColor(mPanelColor);
} else {
mPanel.setBackgroundResource(R.drawable.dialog_full_holo_dark);
}
}
}

private void listenToRingerMode() {
final IntentFilter filter = new IntentFilter();
filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
Expand Down

0 comments on commit 4551ceb

Please sign in to comment.