Skip to content

Commit

Permalink
优化模块入口加载 && 简化部分代码的逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
lingqiqi5211 committed Dec 2, 2024
1 parent 73d9475 commit 5123b3e
Show file tree
Hide file tree
Showing 14 changed files with 345 additions and 400 deletions.
31 changes: 17 additions & 14 deletions app/src/main/java/com/sevtinge/hyperceiler/XposedInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,39 @@
import de.robv.android.xposed.callbacks.XC_LoadPackage;

public class XposedInit extends BaseXposedInit implements IXposedHookZygoteInit, IXposedHookLoadPackage {
private final String TAG = "HyperCeiler";
private static final String TAG = "HyperCeiler";

@Override
public void initZygote(IXposedHookZygoteInit.StartupParam startupParam) throws Throwable {
public void initZygote(StartupParam startupParam) throws Throwable {
super.initZygote(startupParam);
EzXHelper.initZygote(startupParam);
EzXHelper.setLogTag(TAG);
EzXHelper.setToastTag(TAG);
HCInit.initStartupParam(startupParam);
if (mPrefsMap.getBoolean("system_framework_allow_uninstall"))
new AllowUninstall().initZygote(startupParam);
loadZygoteHook(startupParam);
}

private static void loadZygoteHook(StartupParam startupParam) throws Throwable {
if (mPrefsMap.getBoolean("system_framework_screen_all_rotations")) ScreenRotation.initRes();
if (mPrefsMap.getBoolean("system_framework_clean_share_menu")) CleanShareMenu.initRes();
if (mPrefsMap.getBoolean("system_framework_clean_open_menu")) CleanOpenMenu.initRes();
if (mPrefsMap.getBoolean("system_framework_volume_separate_control"))
VolumeSeparateControlForSettings.initRes();
if (mPrefsMap.getBoolean("system_framework_allow_manage_all_notifications"))
new AllowManageAllNotifications().initZygote(startupParam);

if (startupParam != null) {
new BackgroundBlurDrawable().initZygote(startupParam);
new SystemFrameworkForCorePatch().initZygote(startupParam);

if (mPrefsMap.getBoolean("system_framework_allow_uninstall"))
new AllowUninstall().initZygote(startupParam);
if (mPrefsMap.getBoolean("system_framework_allow_manage_all_notifications"))
new AllowManageAllNotifications().initZygote(startupParam);
if (mPrefsMap.getBoolean("system_framework_background_blur_toast"))
new ToastBlur().initZygote(startupParam);
if (mPrefsMap.getBoolean("aod_unlock_always_on_display_hyper"))
new UnlockAlwaysOnDisplay().initZygote(startupParam);
}
if (mPrefsMap.getBoolean("system_framework_background_blur_toast"))
new ToastBlur().initZygote(startupParam);
if (mPrefsMap.getBoolean("aod_unlock_always_on_display_hyper"))
new UnlockAlwaysOnDisplay().initZygote(startupParam);

}

@Override
Expand All @@ -74,10 +81,6 @@ public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Th
// load CorePatch
new SystemFrameworkForCorePatch().handleLoadPackage(lpparam);

if ("com.miui.contentcatcher".equals(lpparam.packageName) ||
"com.miui.catcherpatch".equals(lpparam.packageName)) {
return;
}
// load Module hook apps
init(lpparam);
if (mPrefsMap.getBoolean("system_framework_network_flightmode_hotspot"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

public class LogoAnimationController {

private static final float MAX_SCROLL_FACTOR = 1.0f;
private static final float MIN_SCROLL_FACTOR = 0.0f;
private static final float SCALE_FACTOR = 0.1f;
private static final float ALPHA_FACTOR = 0.1f;

private int startY = 0;
private int logoHeight = 0;
private int logoPadding = 0;
Expand All @@ -25,17 +30,26 @@ public LogoAnimationController(Context context, boolean needUpdate) {

public void iniData(Context context, boolean needUpdate) {
mContext = context;
actionBarPadding = context.getResources().getDimensionPixelSize(R.dimen.logo_area_height);
btnPadding = context.getResources().getDimensionPixelSize(R.dimen.update_btn_margin_bottom);
startY = context.getResources().getDimensionPixelSize(R.dimen.screen_effect_actionbar_height);
logoHeight = context.getResources().getDimensionPixelSize(R.dimen.logo_height);
actionBarPadding = getDimensionPixelSize(R.dimen.logo_area_height);
btnPadding = getDimensionPixelSize(R.dimen.update_btn_margin_bottom);
startY = getDimensionPixelSize(R.dimen.screen_effect_actionbar_height);
logoHeight = getDimensionPixelSize(R.dimen.logo_height);
isNeedUpdate = needUpdate;
logoPadding = calculateLogoPadding(context, needUpdate);
}

private int getDimensionPixelSize(int dimenResId) {
return mContext.getResources().getDimensionPixelSize(dimenResId);
}

private int calculateLogoPadding(Context context, boolean needUpdate) {
int basePadding = getDimensionPixelSize(R.dimen.logo_bottom) - btnPadding;
if (needUpdate) {
logoPadding = context.getResources().getDimensionPixelSize(R.dimen.logo_bottom) - btnPadding;
return basePadding;
} else if (SettingsFeatures.isSplitTabletDevice()) {
logoPadding = (context.getResources().getDimensionPixelSize(R.dimen.logo_bottom) - btnPadding) - DisplayUtils.dp2px(context, 27.0f);
return basePadding - DisplayUtils.dp2px(context, 27.0f);
} else {
logoPadding = (context.getResources().getDimensionPixelSize(R.dimen.logo_bottom) - btnPadding) - DisplayUtils.dp2px(context, 30.0f);
return basePadding - DisplayUtils.dp2px(context, 30.0f);
}
}

Expand All @@ -44,112 +58,76 @@ public void setActionBarAlpha(View view) {
}

public void startAnimation(int scrollY, View iconLogoView, View textLogoView, View iconLogoViewShade, View textLogoViewShade, HyperCardView updateTextView, View versionLayout, View bgEffectView) {
float scroll = Math.min(1.0f, Math.max(0.0f, Math.abs(scrollY) * 1.0f / actionBarPadding));
float scale = 1.0f - scroll * 0.1f;
if (scrollY == 0) {
iconLogoView.setAlpha(1.0f);
iconLogoView.setScaleX(1.0f);
iconLogoView.setScaleY(1.0f);

textLogoView.setAlpha(1.0f);
textLogoView.setScaleX(1.0f);
textLogoView.setScaleY(1.0f);

iconLogoViewShade.setAlpha(1.0f);
iconLogoViewShade.setScaleX(1.0f);
iconLogoViewShade.setScaleY(1.0f);

textLogoViewShade.setAlpha(1.0f);
textLogoViewShade.setScaleX(1.0f);
textLogoViewShade.setScaleY(1.0f);

versionLayout.setAlpha(1.0f);
versionLayout.setScaleX(1.0f);
versionLayout.setScaleY(1.0f);
bgEffectView.setAlpha(1.0f);
if (isNeedUpdate) {
updateTextView.setAlpha(1.0f);
updateTextView.setScaleX(1.0f);
updateTextView.setScaleY(1.0f);
updateTextView.setClickable(true);
} else {
updateTextView.setClickable(false);
}
float scroll = calculateScrollFactor(scrollY, actionBarPadding);
float scale = 1.0f - scroll * SCALE_FACTOR;

resetViewsAlphaAndScale(iconLogoView, textLogoView, iconLogoViewShade, textLogoViewShade);

applyAnimation(scroll, iconLogoView, textLogoView, iconLogoViewShade, textLogoViewShade, updateTextView, versionLayout, bgEffectView, scale, scrollY);
}

private void resetViewsAlphaAndScale(View... views) {
for (View view : views) {
view.setAlpha(1.0f);
view.setScaleX(1.0f);
view.setScaleY(1.0f);
}
}

private void applyAnimation(float scroll, View iconLogoView, View textLogoView, View iconLogoViewShade, View textLogoViewShade, HyperCardView updateTextView, View versionLayout, View bgEffectView, float scale, int scrollY) {
if (scrollY >= logoPadding) {
float scroll2 = calculateScrollFactor(scrollY - logoPadding, logoHeight);
float scale2 = 1.0f - SCALE_FACTOR * scroll2;
setViewAlphaAndScale(iconLogoView, 1.0f - scroll2, scale2);
setViewAlphaAndScale(textLogoView, 1.0f - scroll2, scale2);
setViewAlphaAndScale(iconLogoViewShade, 1.0f - scroll2, scale2);
setViewAlphaAndScale(textLogoViewShade, 1.0f - scroll2, scale2);
} else {
if (scrollY >= logoPadding) {
float scroll2 = Math.min(1.0f, Math.max(0.0f, Math.abs(scrollY - logoPadding) * 1.0f / this.logoHeight));
float scale2 = 1.0f - 0.1f * scroll2;
iconLogoView.setAlpha(1.0f - scroll2);
iconLogoView.setScaleX(scale2);
iconLogoView.setScaleY(scale2);
iconLogoView.setPivotX((float) (iconLogoView.getMeasuredWidth() / 2));
iconLogoView.setPivotY((float) (iconLogoView.getMeasuredHeight() / 2));

textLogoView.setAlpha(1.0f - scroll2);
textLogoView.setScaleX(scale2);
textLogoView.setScaleY(scale2);
textLogoView.setPivotX((float) (textLogoView.getMeasuredWidth() / 2));
textLogoView.setPivotY((float) (textLogoView.getMeasuredHeight() / 2));

iconLogoViewShade.setAlpha(1.0f - scroll2);
iconLogoViewShade.setScaleX(scale2);
iconLogoViewShade.setScaleY(scale2);
iconLogoViewShade.setPivotX((float) (iconLogoViewShade.getMeasuredWidth() / 2));
iconLogoViewShade.setPivotY((float) (iconLogoViewShade.getMeasuredHeight() / 2));

textLogoViewShade.setAlpha(1.0f - scroll2);
textLogoViewShade.setScaleX(scale2);
textLogoViewShade.setScaleY(scale2);
textLogoViewShade.setPivotX((float) (textLogoViewShade.getMeasuredWidth() / 2));
textLogoViewShade.setPivotY((float) (textLogoViewShade.getMeasuredHeight() / 2));
} else {
iconLogoViewShade.setAlpha(1.0f);
iconLogoViewShade.setScaleX(1.0f);
iconLogoViewShade.setScaleY(1.0f);

textLogoViewShade.setAlpha(1.0f);
textLogoViewShade.setScaleX(1.0f);
textLogoViewShade.setScaleY(1.0f);
}
versionLayout.setAlpha(1.0f - actionBarPadding * 1.0f / logoPadding * scroll);
versionLayout.setScaleX(scale);
versionLayout.setScaleY(scale);
versionLayout.setPivotX(((float) (versionLayout.getMeasuredWidth()) / 2));
versionLayout.setPivotY(((float) (versionLayout.getMeasuredHeight()) / 2));
bgEffectView.setAlpha(1.0f - scroll);
if (isNeedUpdate) {
updateTextView.setAlpha(1.0f - scroll * (actionBarPadding * 1.0f / btnPadding));
updateTextView.setScaleX(scale);
updateTextView.setScaleY(scale);
updateTextView.setClickable(updateTextView.getAlpha() > 0.0f);
} else {
updateTextView.setClickable(false);
}
resetViewsAlphaAndScale(iconLogoViewShade, textLogoViewShade);
}

versionLayout.setAlpha(1.0f - scroll * (actionBarPadding / (float) logoPadding));
versionLayout.setScaleX(scale);
versionLayout.setScaleY(scale);
setPivotXY(versionLayout);

bgEffectView.setAlpha(1.0f - scroll);
updateTextView.setAlpha(isNeedUpdate ? 1.0f - scroll * (actionBarPadding / (float) btnPadding) : 0.0f);
updateTextView.setScaleX(scale);
updateTextView.setScaleY(scale);
updateTextView.setClickable(updateTextView.getAlpha() > 0.0f);
}

private void setViewAlphaAndScale(View view, float alpha, float scale) {
view.setAlpha(alpha);
view.setScaleX(scale);
view.setScaleY(scale);
setPivotXY(view);
}

private void setPivotXY(View view) {
view.setPivotX((float) (view.getMeasuredWidth() / 2));
view.setPivotY((float) (view.getMeasuredHeight() / 2));
}

private float calculateScrollFactor(int scrollY, int padding) {
return Math.min(MAX_SCROLL_FACTOR, Math.max(MIN_SCROLL_FACTOR, Math.abs(scrollY) / (float) padding));
}

public void startButtonAnimation(int scrollValue, HyperCardView updateTextView) {
float scroll = Math.min(1.0f, Math.max(0.0f, (Math.abs(scrollValue) * 1.0f) / actionBarPadding));
float scale = 1.0f - (0.1f * scroll);
float scroll = calculateScrollFactor(scrollValue, actionBarPadding);
float scale = 1.0f - SCALE_FACTOR * scroll;

if (scrollValue == 0) {
if (isNeedUpdate) {
updateTextView.setAlpha(1.0f);
updateTextView.setScaleX(1.0f);
updateTextView.setScaleY(1.0f);
updateTextView.setClickable(true);
} else {
updateTextView.setClickable(false);
}
updateTextView.setAlpha(isNeedUpdate ? 1.0f : 0.0f);
updateTextView.setScaleX(1.0f);
updateTextView.setScaleY(1.0f);
updateTextView.setClickable(isNeedUpdate);
} else {
if (isNeedUpdate) {
updateTextView.setAlpha(1.0f - (scroll * ((actionBarPadding * 1.0f) / btnPadding)));
updateTextView.setScaleX(scale);
updateTextView.setScaleY(scale);
updateTextView.setClickable(updateTextView.getAlpha() > 0.0f);
} else {
updateTextView.setClickable(false);
}
updateTextView.setAlpha(isNeedUpdate ? 1.0f - scroll * (actionBarPadding / (float) btnPadding) : 0.0f);
updateTextView.setScaleX(scale);
updateTextView.setScaleY(scale);
updateTextView.setClickable(updateTextView.getAlpha() > 0.0f);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,30 @@ public abstract class BaseHook extends HookTool {
// public static final XmlTool mXmlTool = BaseXposedInit.mXmlTool;
public static final String ACTION_PREFIX = "com.sevtinge.hyperceiler.module.action.";

public boolean isLoad() {
return false;
}

public abstract void init() throws NoSuchMethodException;

public void onCreate(LoadPackageParam lpparam) {
try {
setLoadPackageParam(lpparam);
init();
if (logLevel >= 3) {
logI(TAG, lpparam.packageName, "Hook Success.");
}
logHookSuccess(lpparam);
} catch (Throwable t) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
t.printStackTrace(printWriter);
if (logLevel >= 1) logE(TAG, lpparam.packageName, "Hook Failed: " + stringWriter);
logHookFailure(t, lpparam);
}
}

private void logHookSuccess(LoadPackageParam lpparam) {
if (logLevel >= 3) {
logI(TAG, lpparam.packageName, "Hook Success.");
}
}

private void logHookFailure(Throwable t, LoadPackageParam lpparam) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
t.printStackTrace(printWriter);
if (logLevel >= 1) {
logE(TAG, lpparam.packageName, "Hook Failed: " + stringWriter);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package com.sevtinge.hyperceiler.module.base;

import com.github.kyuubiran.ezxhelper.EzXHelper;
import com.hchen.hooktool.HCInit;
import com.sevtinge.hyperceiler.BuildConfig;
import com.sevtinge.hyperceiler.XposedInit;
Expand All @@ -43,14 +42,15 @@ public abstract class BaseModule implements IXposedHook {
private static HashMap<String, String> swappedMap = CrashData.swappedData();

public void init(LoadPackageParam lpparam) {
if (swappedMap.isEmpty()) swappedMap = CrashData.swappedData();
if (swappedMap.isEmpty()) {
swappedMap = CrashData.swappedData();
}

if (CrashData.toPkgList(lpparam.packageName)) {
XposedLogUtils.logI(TAG, "Entry safe mode: " + lpparam.packageName);
return;
}
EzXHelper.initHandleLoadPackage(lpparam);
EzXHelper.setLogTag(TAG);
EzXHelper.setToastTag(TAG);

HCInit.initBasicData(new HCInit.BasicData()
.setModulePackageName(BuildConfig.APPLICATION_ID)
.setLogLevel(LogManager.getLogLevel())
Expand All @@ -69,10 +69,13 @@ public void init(LoadPackageParam lpparam) {
} catch (Throwable e) {
XposedLogUtils.logE(TAG, "get context failed!" + e);
}

mLoadPackageParam = lpparam;

DexKit dexKit = new DexKit(lpparam, TAG);
initZygote();
handleLoadPackage();

if (dexKit.isInit) {
dexKit.close();
}
Expand Down
Loading

0 comments on commit 5123b3e

Please sign in to comment.