Skip to content

Commit

Permalink
CHANGELOG: Added Volume Panel Slider background color (New Volume Pan…
Browse files Browse the repository at this point in the history
…el UI)
  • Loading branch information
DHD2280 committed May 15, 2024
1 parent 81f277f commit 08e22a1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.view.View;
import android.view.Gravity;
Expand All @@ -24,6 +27,7 @@
import android.view.WindowManager;
import android.widget.ImageView;

import androidx.appcompat.widget.AppCompatImageView;
import androidx.core.graphics.ColorUtils;

import java.util.List;
Expand All @@ -40,9 +44,9 @@ public class VolumePanel extends XposedMods {
private int mTimeOut;
private int mDesiredTimeout;
private boolean mDisableVolumeWarning;
private boolean customizeVolumeProgress, customizeVolumeIcon;
private boolean volumeProgressPrimary, volumeIconPrimary;
private int volumeProgressColor, volumeIconColor;
private boolean customizeVolumeProgress, customizeVolumeBg;
private boolean volumeProgressPrimary;
private int volumeProgressColor, volumeBgColor;
private Object OVDI;
private boolean sliderCustomizable = false;

Expand All @@ -58,19 +62,17 @@ public void updatePrefs(String... Key) {
mTimeOut = mDesiredTimeout * 1000;
mDisableVolumeWarning = Xprefs.getBoolean("disable_volume_warning", false);
customizeVolumeProgress = Xprefs.getBoolean("volume_panel_seekbar_color_enabled", false);
customizeVolumeIcon = Xprefs.getBoolean("volume_panel_icon_color_enabled", false);
customizeVolumeBg = Xprefs.getBoolean("volume_panel_seekbar_bg_color_enabled", false);
volumeProgressPrimary = Xprefs.getBoolean("volume_panel_seekbar_link_primary", false);
volumeIconPrimary = Xprefs.getBoolean("volume_panel_icon_accent", false);
volumeProgressColor = Xprefs.getInt("volume_panel_seekbar_color", 0);
volumeIconColor = Xprefs.getInt("volume_panel_icon_color", 0);
volumeBgColor = Xprefs.getInt("volume_panel_seekbar_bg_color", Color.GRAY);

if (Key.length > 0) {
if (Key[0].equals("volume_panel_seekbar_color_enabled") ||
Key[0].equals("volume_panel_seekbar_link_primary") ||
Key[0].equals("volume_panel_seekbar_color") ||
Key[0].equals("volume_panel_icon_color_enabled") ||
Key[0].equals("volume_panel_icon_accent") ||
Key[0].equals("volume_panel_icon_color")) {
Key[0].equals("volume_panel_seekbar_bg_color_enabled") ||
Key[0].equals("volume_panel_seekbar_bg_color")) {
updateVolumePanel();
}
}
Expand Down Expand Up @@ -116,7 +118,15 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
}
});


Class<?> VolumeDialogImpl = findClass("com.android.systemui.volume.VolumeDialogImpl", lpparam.classLoader);
hookAllMethods(VolumeDialogImpl, "showSafetyWarningH", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (mDisableVolumeWarning) {
param.setResult(null);
}
}
});

hookAllConstructors(OplusVolumeDialogImpl, new XC_MethodHook() {
@Override
Expand All @@ -138,87 +148,10 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
else
callMethod(slider, "setProgressColor", ColorStateList.valueOf(volumeProgressColor));
}

if (customizeVolumeIcon) {
ImageView icon = (ImageView) getObjectField(VolumeRow, "icon");
int colorToApply = -1;
if (volumeIconPrimary)
colorToApply = getPrimaryColor(mContext);
else
colorToApply = volumeIconColor;

if (colorToApply != -1) {
int fadeFilter = ColorUtils.blendARGB(Color.TRANSPARENT, colorToApply, 1.0f);
icon.setColorFilter(fadeFilter, PorterDuff.Mode.SRC_ATOP);
}
callMethod(icon, "setSupportImageTintList", ColorStateList.valueOf(colorToApply));
callMethod(slider, "setIcon", icon);
}

}
});

final XC_MethodHook volumeIconHook = new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Object VolumeRow = param.args[0];
Object slider = getObjectField(VolumeRow, "slider");

if (customizeVolumeIcon) {
ImageView icon = (ImageView) getObjectField(VolumeRow, "icon");
int colorToApply = -1;
if (volumeIconPrimary)
colorToApply = getPrimaryColor(mContext);
else
colorToApply = volumeIconColor;

if (colorToApply != -1) {
int fadeFilter = ColorUtils.blendARGB(Color.TRANSPARENT, colorToApply, 1.0f);
icon.setColorFilter(fadeFilter, PorterDuff.Mode.SRC_ATOP);
}
callMethod(icon, "setSupportImageTintList", ColorStateList.valueOf(colorToApply));
callMethod(slider, "setIcon", icon);
if (customizeVolumeBg) {
callMethod(slider, "setSeekBarBackgroundColor", ColorStateList.valueOf(volumeBgColor));
}
}
};

Class<?> VolumeSeekBarChangeListener = findClass("com.oplus.systemui.volume.OplusVolumeDialogImpl$VolumeSeekBarChangeListener", lpparam.classLoader);
hookAllConstructors(VolumeSeekBarChangeListener, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Object VolumeRow = getObjectField(param.thisObject, "mRow");

if (customizeVolumeIcon) {
ImageView icon = (ImageView) getObjectField(VolumeRow, "icon");
if (icon == null) return;
int colorToApply = -1;
if (volumeIconPrimary)
colorToApply = getPrimaryColor(mContext);
else
colorToApply = volumeIconColor;

if (colorToApply != -1) {
int fadeFilter = ColorUtils.blendARGB(Color.TRANSPARENT, colorToApply, 1.0f);
icon.setColorFilter(fadeFilter, PorterDuff.Mode.SRC_ATOP);
}
callMethod(icon, "setSupportImageTintList", ColorStateList.valueOf(colorToApply));
} }
});

hookAllMethods(OplusVolumeDialogImpl, "updateVolumeRowH", volumeIconHook);

hookAllMethods(OplusVolumeDialogImpl, "updateVolumeRowSliderH", volumeIconHook);
hookAllMethods(OplusVolumeDialogImpl, "updateVolumeRowTintH", volumeIconHook);
hookAllMethods(OplusVolumeDialogImpl, "refreshVisibleRow", volumeIconHook);


Class<?> VolumeDialogImpl = findClass("com.android.systemui.volume.VolumeDialogImpl", lpparam.classLoader);
hookAllMethods(VolumeDialogImpl, "showSafetyWarningH", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (mDisableVolumeWarning) {
param.setResult(null);
}
}
});

Expand All @@ -238,20 +171,8 @@ private void updateVolumePanel() {
else
callMethod(slider, "setProgressColor", ColorStateList.valueOf(volumeProgressColor));
}

if (customizeVolumeIcon) {
ImageView icon = (ImageView) getObjectField(VolumeRow, "icon");
int colorToApply = -1;
if (volumeIconPrimary)
colorToApply = getPrimaryColor(mContext);
else
colorToApply = volumeIconColor;

if (colorToApply != -1) {
int fadeFilter = ColorUtils.blendARGB(Color.TRANSPARENT, colorToApply, 1.0f);
icon.setColorFilter(fadeFilter, PorterDuff.Mode.SRC_ATOP);
}
callMethod(slider, "setIcon", icon);
if (customizeVolumeBg) {
callMethod(slider, "setSeekBarBackgroundColor", ColorStateList.valueOf(volumeBgColor));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@
<string name="volume_panel_seekbar_link_primary">Link Progress to primary color</string>
<string name="volume_panel_icon_color">Customize Icon Color</string>
<string name="volume_panel_icon_accent">Link Icon to primary color</string>
<string name="volume_panel_bg_color">Custom Background Color</string>

<!-- Volume Styles -->
<string name="volume_style_title">Volume panel styles</string>
Expand Down
18 changes: 5 additions & 13 deletions app/src/main/res/xml/volume_panel_customizations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,19 @@
app:iconSpaceReserved="false"
android:defaultValue="0xffffffff" />

<!-- Not Ready Yet <SwitchPreference
android:key="volume_panel_icon_color_enabled"
android:title="@string/volume_panel_icon_color"
android:summaryOff="@string/general_off"
android:summaryOn="@string/general_on"
app:iconSpaceReserved="false"
android:defaultValue="false" />
<SwitchPreference
android:key="volume_panel_icon_accent"
android:title="@string/volume_panel_icon_accent"
<SwitchPreferenceCompat
android:key="volume_panel_seekbar_bg_color_enabled"
android:title="@string/volume_panel_bg_color"
android:summaryOff="@string/general_off"
android:summaryOn="@string/general_on"
app:iconSpaceReserved="false"
android:defaultValue="false" />

<it.dhd.oxygencustomizer.customprefs.MaterialColorPreference
android:key="volume_panel_icon_color"
android:key="volume_panel_seekbar_bg_color"
android:title="@string/custom_color"
app:iconSpaceReserved="false"
android:defaultValue="0xff000000" /> -->
android:defaultValue="-7829368" />

</PreferenceCategory>

Expand Down

0 comments on commit 08e22a1

Please sign in to comment.