Skip to content

Commit

Permalink
Bring back fixed status icons for A13+
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmud0808 committed Sep 15, 2023
1 parent 219be4f commit 1ac8758
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ protected void onCreate(Bundle savedInstanceState) {

// Fixed status icons
if (Build.VERSION.SDK_INT >= 33) {
binding.enableFixedStatusIconsContainer.setVisibility(View.GONE);
((View) binding.statusIconsSideMarginSeekbar.getParent()).setVisibility(View.GONE);
RPrefs.putBoolean(FIXED_STATUS_ICONS_SWITCH, false);
}

binding.enableFixedStatusIcons.setChecked(RPrefs.getBoolean(FIXED_STATUS_ICONS_SWITCH, false));
binding.enableFixedStatusIcons.setOnCheckedChangeListener((buttonView, isChecked) -> {
binding.statusIconsSideMarginSeekbar.setEnabled(isChecked);
binding.statusIconsTopMarginSeekbar.setEnabled(isChecked);

RPrefs.putBoolean(FIXED_STATUS_ICONS_SWITCH, isChecked);
if (!isChecked) FabricatedUtil.disableOverlay("quickQsOffsetHeight");
else if (RPrefs.getInt(FIXED_STATUS_ICONS_TOPMARGIN, 8) > 32)
Expand All @@ -115,7 +116,11 @@ else if (RPrefs.getInt(FIXED_STATUS_ICONS_TOPMARGIN, 8) > 32)
// Status icons top margin
binding.statusIconsTopMarginOutput.setText(getResources().getString(R.string.opt_selected) + ' ' + RPrefs.getInt(FIXED_STATUS_ICONS_TOPMARGIN, 8) + "dp");
binding.statusIconsTopMarginSeekbar.setValue(RPrefs.getInt(FIXED_STATUS_ICONS_TOPMARGIN, 8));
binding.statusIconsTopMarginSeekbar.setEnabled(Build.VERSION.SDK_INT >= 33 ? RPrefs.getBoolean(QSPANEL_STATUSICONSBG_SWITCH, false) : RPrefs.getBoolean(FIXED_STATUS_ICONS_SWITCH, false));
binding.statusIconsTopMarginSeekbar.setEnabled(
Build.VERSION.SDK_INT >= 33 ?
RPrefs.getBoolean(QSPANEL_STATUSICONSBG_SWITCH, false) || RPrefs.getBoolean(FIXED_STATUS_ICONS_SWITCH, false) :
RPrefs.getBoolean(FIXED_STATUS_ICONS_SWITCH, false)
);
if (Build.VERSION.SDK_INT >= 33) binding.statusIconsTopMarginSeekbar.setValueTo(200);
final int[] topMarginStatusIcons = {RPrefs.getInt(FIXED_STATUS_ICONS_TOPMARGIN, 8)};
binding.statusIconsTopMarginSeekbar.addOnSliderTouchListener(new Slider.OnSliderTouchListener() {
Expand All @@ -128,7 +133,10 @@ public void onStopTrackingTouch(@NonNull Slider slider) {
topMarginStatusIcons[0] = (int) slider.getValue();
binding.statusIconsTopMarginOutput.setText(getResources().getString(R.string.opt_selected) + ' ' + topMarginStatusIcons[0] + "dp");
RPrefs.putInt(FIXED_STATUS_ICONS_TOPMARGIN, topMarginStatusIcons[0]);
if (Build.VERSION.SDK_INT >= 33 ? RPrefs.getBoolean(QSPANEL_STATUSICONSBG_SWITCH, false) : RPrefs.getBoolean(FIXED_STATUS_ICONS_SWITCH, false)) {
if (Build.VERSION.SDK_INT >= 33 ?
RPrefs.getBoolean(QSPANEL_STATUSICONSBG_SWITCH, false) || RPrefs.getBoolean(FIXED_STATUS_ICONS_SWITCH, false) :
RPrefs.getBoolean(FIXED_STATUS_ICONS_SWITCH, false)
) {
if (Build.VERSION.SDK_INT < 33) {
FabricatedUtil.buildAndEnableOverlay(FRAMEWORK_PACKAGE, "quickQsOffsetHeight", "dimen", "quick_qs_offset_height", (40 + topMarginStatusIcons[0]) + "dp");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.drdisagree.iconify.R;
import com.drdisagree.iconify.xposed.ModPack;

import java.lang.reflect.Field;
import java.util.Objects;

import de.robv.android.xposed.IXposedHookLoadPackage;
Expand Down Expand Up @@ -203,14 +204,20 @@ protected void afterHookedMethod(MethodHookParam param) {

if (Build.VERSION.SDK_INT >= 33) {
Class<?> QuickStatusBarHeader = findClass(SYSTEMUI_PACKAGE + ".qs.QuickStatusBarHeader", lpparam.classLoader);
Class<?> ShadeHeaderControllerClass = findClassIfExists(SYSTEMUI_PACKAGE + ".shade.ShadeHeaderController", lpparam.classLoader);

try {
getObjectField(QuickStatusBarHeader, "mIconContainer");
boolean correctClass = false;
Field[] fs = QuickStatusBarHeader.getDeclaredFields();
for (Field f : fs) {
if (f.getName().equals("mIconContainer")) {
correctClass = true;
}
}

if (correctClass) {
hookAllMethods(QuickStatusBarHeader, "onFinishInflate", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) {
if (!mShowQSStatusIconsBg || hideStatusIcons) return;
if ((!mShowQSStatusIconsBg && !fixedStatusIcons) || hideStatusIcons) return;

FrameLayout mQuickStatusBarHeader = (FrameLayout) param.thisObject;
LinearLayout mIconContainer = (LinearLayout) getObjectField(param.thisObject, "mIconContainer");
Expand Down Expand Up @@ -251,17 +258,20 @@ protected void afterHookedMethod(MethodHookParam param) {
hookAllMethods(QuickStatusBarHeader, "updateResources", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) {
if ((!mShowQSStatusIconsBg && !fixedStatusIcons) || hideStatusIcons) return;

updateStatusIcons();
}
});
} catch (Throwable ignored) {
} else {
Class<?> ShadeHeaderControllerClass = findClassIfExists(SYSTEMUI_PACKAGE + ".shade.ShadeHeaderController", lpparam.classLoader);
if (ShadeHeaderControllerClass == null)
ShadeHeaderControllerClass = findClass(SYSTEMUI_PACKAGE + ".shade.LargeScreenShadeHeaderController", lpparam.classLoader);

hookAllMethods(ShadeHeaderControllerClass, "onInit", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) {
if (!mShowQSStatusIconsBg || hideStatusIcons) return;
if ((!mShowQSStatusIconsBg && !fixedStatusIcons) || hideStatusIcons) return;

LinearLayout iconContainer = (LinearLayout) getObjectField(param.thisObject, "iconContainer");
LinearLayout batteryIcon = (LinearLayout) getObjectField(param.thisObject, "batteryIcon");
Expand Down Expand Up @@ -305,7 +315,7 @@ protected void afterHookedMethod(MethodHookParam param) {
hookAllMethods(ShadeHeaderControllerClass, "updateResources", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) {
if (!mShowQSStatusIconsBg || hideStatusIcons) return;
if ((!mShowQSStatusIconsBg && !fixedStatusIcons) || hideStatusIcons) return;

updateStatusIcons();
}
Expand All @@ -329,44 +339,49 @@ private void updateStatusBarClock() {
}

private void updateStatusIcons() {
if (!mShowQSStatusIconsBg || mQsStatusIconsContainer.getChildCount() == 0) return;
if (mQsStatusIconsContainer.getChildCount() == 0)
return;

int paddingTopBottom = dp2px(mContext, 4);
int paddingStartEnd = dp2px(mContext, 12);

setStatusIconsBackgroundChip(mQsStatusIconsContainer);
mQsStatusIconsContainer.setPadding(paddingStartEnd, paddingTopBottom, paddingStartEnd, paddingTopBottom);
try {
if (mShowQSStatusIconsBg) {
setStatusIconsBackgroundChip(mQsStatusIconsContainer);
mQsStatusIconsContainer.setPadding(paddingStartEnd, paddingTopBottom, paddingStartEnd, paddingTopBottom);
}

if (mQsStatusIconsContainer.getLayoutParams() instanceof FrameLayout.LayoutParams) {
((FrameLayout.LayoutParams) mQsStatusIconsContainer.getLayoutParams()).setMargins(0, dp2px(mContext, topMarginStatusIcons), 0, 0);
} catch (Throwable ignored) {
if (mLoadPackageParam != null && header != null && constraintLayoutId != -1) {
try {
Class<?> ConstraintSetClass = findClass("androidx.constraintlayout.widget.ConstraintSet", mLoadPackageParam.classLoader);
Object mConstraintSet = ConstraintSetClass.newInstance();

callMethod(mConstraintSet, "clone", header);
callMethod(mConstraintSet,
"connect",
constraintLayoutId,
ConstraintSet.TOP,
ConstraintSet.PARENT_ID,
ConstraintSet.TOP,
0);
callMethod(mConstraintSet,
"connect",
constraintLayoutId,
ConstraintSet.END,
ConstraintSet.PARENT_ID,
ConstraintSet.END,
0);
callMethod(mConstraintSet, "applyTo", header);

callMethod(callMethod(mQsStatusIconsContainer, "getLayoutParams"), "setMargins", 0, dp2px(mContext, topMarginStatusIcons), 0, 0);
} catch (Throwable throwable) {
log(TAG + throwable);
}
} else if (mQsStatusIconsContainer.getLayoutParams() instanceof LinearLayout.LayoutParams) {
((LinearLayout.LayoutParams) mQsStatusIconsContainer.getLayoutParams()).setMargins(0, dp2px(mContext, topMarginStatusIcons), 0, 0);
} else if (mLoadPackageParam != null && header != null && constraintLayoutId != -1) {
try {
Class<?> ConstraintSetClass = findClass("androidx.constraintlayout.widget.ConstraintSet", mLoadPackageParam.classLoader);
Object mConstraintSet = ConstraintSetClass.newInstance();

callMethod(mConstraintSet, "clone", header);
callMethod(mConstraintSet,
"connect",
constraintLayoutId,
ConstraintSet.TOP,
ConstraintSet.PARENT_ID,
ConstraintSet.TOP,
0);
callMethod(mConstraintSet,
"connect",
constraintLayoutId,
ConstraintSet.END,
ConstraintSet.PARENT_ID,
ConstraintSet.END,
0);
callMethod(mConstraintSet, "applyTo", header);

callMethod(callMethod(mQsStatusIconsContainer, "getLayoutParams"), "setMargins", 0, dp2px(mContext, topMarginStatusIcons), 0, 0);
} catch (Throwable throwable) {
log(TAG + throwable);
}
}

mQsStatusIconsContainer.requestLayout();

Configuration config = mContext.getResources().getConfiguration();
Expand All @@ -375,6 +390,7 @@ private void updateStatusIcons() {
} else {
mQsStatusIconsContainer.setVisibility(View.VISIBLE);
}

}

private void setSBClockBackgroundChip(View view) {
Expand Down Expand Up @@ -487,49 +503,45 @@ private void setQSStatusIconsBgA12() {
ourResparam.res.hookLayout(SYSTEMUI_PACKAGE, "layout", "quick_qs_status_icons", new XC_LayoutInflated() {
@Override
public void handleLayoutInflated(XC_LayoutInflated.LayoutInflatedParam liparam) {
if (!mShowQSStatusIconsBg || hideStatusIcons) return;
if (!mShowQSStatusIconsBg || hideStatusIcons || fixedStatusIcons) return;

if (!fixedStatusIcons) {
try {
@SuppressLint("DiscouragedApi") LinearLayout statusIcons = liparam.view.findViewById(liparam.res.getIdentifier("statusIcons", "id", mContext.getPackageName()));
LinearLayout statusIconContainer = (LinearLayout) statusIcons.getParent();
try {
@SuppressLint("DiscouragedApi") LinearLayout statusIcons = liparam.view.findViewById(liparam.res.getIdentifier("statusIcons", "id", mContext.getPackageName()));
LinearLayout statusIconContainer = (LinearLayout) statusIcons.getParent();

((FrameLayout.LayoutParams) statusIconContainer.getLayoutParams()).gravity = Gravity.CENTER_VERTICAL | Gravity.END;
statusIconContainer.getLayoutParams().height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 28, mContext.getResources().getDisplayMetrics());
statusIconContainer.requestLayout();
((FrameLayout.LayoutParams) statusIconContainer.getLayoutParams()).gravity = Gravity.CENTER_VERTICAL | Gravity.END;
statusIconContainer.getLayoutParams().height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 28, mContext.getResources().getDisplayMetrics());
statusIconContainer.requestLayout();

int paddingTopBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, mContext.getResources().getDisplayMetrics());
int paddingStartEnd = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, mContext.getResources().getDisplayMetrics());
statusIconContainer.setPadding(paddingStartEnd, paddingTopBottom, paddingStartEnd, paddingTopBottom);
int paddingTopBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, mContext.getResources().getDisplayMetrics());
int paddingStartEnd = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, mContext.getResources().getDisplayMetrics());
statusIconContainer.setPadding(paddingStartEnd, paddingTopBottom, paddingStartEnd, paddingTopBottom);

setStatusIconsBackgroundChip(statusIconContainer);
} catch (Throwable throwable) {
log(TAG + throwable);
}
setStatusIconsBackgroundChip(statusIconContainer);
} catch (Throwable throwable) {
log(TAG + throwable);
}
}
});

ourResparam.res.hookLayout(SYSTEMUI_PACKAGE, "layout", "quick_status_bar_header_date_privacy", new XC_LayoutInflated() {
@Override
public void handleLayoutInflated(LayoutInflatedParam liparam) {
if (!mShowQSStatusIconsBg || hideStatusIcons) return;
if (!mShowQSStatusIconsBg || hideStatusIcons || !fixedStatusIcons) return;

if (fixedStatusIcons) {
try {
@SuppressLint("DiscouragedApi") LinearLayout statusIcons = liparam.view.findViewById(liparam.res.getIdentifier("statusIcons", "id", mContext.getPackageName()));
if (statusIcons != null) {
LinearLayout statusIconContainer = (LinearLayout) statusIcons.getParent();
try {
@SuppressLint("DiscouragedApi") LinearLayout statusIcons = liparam.view.findViewById(liparam.res.getIdentifier("statusIcons", "id", mContext.getPackageName()));
if (statusIcons != null) {
LinearLayout statusIconContainer = (LinearLayout) statusIcons.getParent();

int paddingTopBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, mContext.getResources().getDisplayMetrics());
int paddingStartEnd = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, mContext.getResources().getDisplayMetrics());
statusIconContainer.setPadding(paddingStartEnd, paddingTopBottom, paddingStartEnd, paddingTopBottom);
int paddingTopBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, mContext.getResources().getDisplayMetrics());
int paddingStartEnd = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, mContext.getResources().getDisplayMetrics());
statusIconContainer.setPadding(paddingStartEnd, paddingTopBottom, paddingStartEnd, paddingTopBottom);

setStatusIconsBackgroundChip(statusIconContainer);
}
} catch (Throwable throwable) {
log(TAG + throwable);
setStatusIconsBackgroundChip(statusIconContainer);
}
} catch (Throwable throwable) {
log(TAG + throwable);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
Expand Down Expand Up @@ -76,7 +77,7 @@ public void updatePrefs(String... Key) {
if (Objects.equals(Key[0], HIDE_STATUS_ICONS_SWITCH)) hideStatusIcons();

if (Objects.equals(Key[0], FIXED_STATUS_ICONS_SWITCH) || Objects.equals(Key[0], HIDE_STATUS_ICONS_SWITCH) || Objects.equals(Key[0], FIXED_STATUS_ICONS_TOPMARGIN) || Objects.equals(Key[0], FIXED_STATUS_ICONS_SIDEMARGIN))
fixedStatusIcons();
fixedStatusIconsA12();

if (Objects.equals(Key[0], HIDE_LOCKSCREEN_CARRIER) || Objects.equals(Key[0], HIDE_LOCKSCREEN_STATUSBAR))
hideLockscreenCarrierOrStatusbar();
Expand Down Expand Up @@ -176,7 +177,7 @@ protected void afterHookedMethod(MethodHookParam param) {

hideQSCarrierGroup();
hideStatusIcons();
fixedStatusIcons();
fixedStatusIconsA12();
hideLockscreenCarrierOrStatusbar();

Class<?> MobileSignalController = findClass(SYSTEMUI_PACKAGE + ".statusbar.connectivity.MobileSignalController", lpparam.classLoader);
Expand Down Expand Up @@ -355,7 +356,9 @@ public void handleLayoutInflated(XC_LayoutInflated.LayoutInflatedParam liparam)
}
}

private void fixedStatusIcons() {
private void fixedStatusIconsA12() {
if (Build.VERSION.SDK_INT >= 33) return;

XC_InitPackageResources.InitPackageResourcesParam ourResparam = resparams.get(SYSTEMUI_PACKAGE);
if (ourResparam == null) return;

Expand Down

0 comments on commit 1ac8758

Please sign in to comment.