Skip to content

Commit

Permalink
## 3.44.21
Browse files Browse the repository at this point in the history
- 添加 歌词左右位置 功能
- 修改 功能描述
- 修改 描述
- 升级 gradle为7.0.0
- 耦合 感谢名单
- 优化 代码

- Added lyrics left and right position function
- Modify the function description
- Modify the description
- Upgrade gradle to 7.0.0
- Coupling thank you list
- Optimize the code
  • Loading branch information
xiaowine authored Dec 25, 2021
2 parents 839848d + 3472dd9 commit 7d59552
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 124 deletions.
9 changes: 3 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ android {
minSdkVersion 26
//noinspection OldTargetApi
targetSdkVersion 29
versionCode 73
versionName "3.43.19"
versionCode 74
versionName "3.44.21"
aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false
}

buildTypes {debug {
buildConfigField 'boolean', 'PREPROD', 'true'
buildConfigField 'boolean', 'STAGING', 'false'
}
buildTypes {
release {
minifyEnabled true
zipAlignEnabled true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ protected void onCreate(Bundle savedInstanceState) {
config = new Config(ConfigUtils.getSP(activity, "Lyric_Config"));
setTitle(String.format("%s (%s)", getString(R.string.AppName), getString(R.string.SPConfigMode)));
init();
AppCenter.start(getApplication(), "1a36c976-87ea-4f22-a8d8-4aba01ad973d",
Analytics.class, Crashes.class);
} catch (SecurityException ignored) {
new AlertDialog.Builder(activity)
.setTitle(getString(R.string.Tips))
Expand All @@ -85,7 +83,10 @@ public void init() {
.setTitle(getString(R.string.Tips))
.setIcon(R.mipmap.ic_launcher)
.setMessage(getString(R.string.AppTips))
.setNegativeButton(getString(R.string.TipsIDone), (dialog, which) -> preferences.edit().putBoolean(tips, true).apply())
.setNegativeButton(getString(R.string.TipsIDone), (dialog, which) -> {
preferences.edit().putBoolean(tips, true).apply();
ActivityUtils.getNotice(activity);
})
.setPositiveButton(getString(R.string.Quit), (dialog, which) -> activity.finish())
.setNeutralButton(getString(R.string.PrivacyPolicy), (dialog, which) -> {
Uri uri = Uri.parse("https://github.com/577fkj/MIUIStatusBarLyric/blob/main/EUAL.md");
Expand All @@ -96,7 +97,11 @@ public void init() {
.setCancelable(false)
.create()
.show();
} else {
ActivityUtils.getNotice(activity);
}
AppCenter.start(getApplication(), "1a36c976-87ea-4f22-a8d8-4aba01ad973d",
Analytics.class, Crashes.class);

//使用说明
Preference verExplain = findPreference("ver_explain");
Expand Down
66 changes: 5 additions & 61 deletions app/src/main/java/miui/statusbar/lyric/hook/MainHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import miui.statusbar.lyric.config.ApiListConfig;
import miui.statusbar.lyric.hook.app.SystemUI;
import miui.statusbar.lyric.hook.app.Kugou;
import miui.statusbar.lyric.hook.app.Kuwo;
import miui.statusbar.lyric.hook.app.Myplayer;
import miui.statusbar.lyric.hook.app.Netease;
import miui.statusbar.lyric.hook.app.NeteaseLite;
import miui.statusbar.lyric.hook.app.SystemUI;
import miui.statusbar.lyric.utils.Utils;

import java.util.HashMap;


public class MainHook implements IXposedHookLoadPackage {
Context context = null;
Expand Down Expand Up @@ -56,68 +56,12 @@ protected void afterHookedMethod(MethodHookParam param) {
break;
case "com.kugou.android":
Utils.log("正在hook酷狗音乐");
XposedHelpers.findAndHookMethod("android.media.AudioManager", lpparam.classLoader, "isBluetoothA2dpOn", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
}

@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
param.setResult(true);
}
});
XposedHelpers.findAndHookMethod("com.kugou.framework.player.c", lpparam.classLoader, "a", HashMap.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
}

@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
Utils.log("酷狗音乐:" + ((HashMap) param.args[0]).values().toArray()[0]);
Utils.sendLyric(context, "" + ((HashMap) param.args[0]).values().toArray()[0], "kugou");
}
});
new Kugou.Hook(lpparam, context);
Utils.log("hook酷狗音乐结束");
break;
case "cn.kuwo.player":
Utils.log("正在hook酷我音乐");
XposedHelpers.findAndHookMethod("android.bluetooth.BluetoothAdapter", lpparam.classLoader, "isEnabled", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
}

@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
param.setResult(true);
}
});
XposedHelpers.findAndHookMethod("cn.kuwo.mod.playcontrol.RemoteControlLyricMgr", lpparam.classLoader, "updateLyricText", Class.forName("java.lang.String"), new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
String str = (String) param.args[0];
Utils.log("酷我音乐:" + str);
if (param.args[0] != null && !str.equals("") && !str.contains(" - ")) {
Utils.sendLyric(context, "" + str, "kuwo");
}
param.setResult(replaceHookedMethod());
}

private Object replaceHookedMethod() {
return null;
}

@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
}
});
new Kuwo.Hook(lpparam, context);
Utils.log("hook酷我音乐结束");
break;
case "com.tencent.qqmusic":
Expand Down
29 changes: 8 additions & 21 deletions app/src/main/java/miui/statusbar/lyric/hook/app/Kugou.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,22 @@

public class Kugou {
public static class Hook {
public Hook(XC_LoadPackage.LoadPackageParam lpparam) {
public Hook(XC_LoadPackage.LoadPackageParam lpparam, Context context) {
XposedHelpers.findAndHookMethod("android.media.AudioManager", lpparam.classLoader, "isBluetoothA2dpOn", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
param.setResult(true);
}

});
XposedHelpers.findAndHookMethod("com.kugou.framework.player.c", lpparam.classLoader, "a", HashMap.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
param.setResult(true);
Utils.log("酷狗音乐:" + ((HashMap) param.args[0]).values().toArray()[0]);
Utils.sendLyric(context, "" + ((HashMap) param.args[0]).values().toArray()[0], "kugou");
}
});
XposedHelpers.findAndHookMethod("com.kugou.framework.player.c", lpparam.classLoader, "a", HashMap.class, new

XC_MethodHook() {
@Override
protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
}

@Override
protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
Context context = (Context) param.thisObject;
Utils.log("酷狗音乐:" + ((HashMap) param.args[0]).values().toArray()[0]);
Utils.sendLyric(context, "" + ((HashMap) param.args[0]).values().toArray()[0], "kugou");
}
});

}
}
Expand Down
18 changes: 4 additions & 14 deletions app/src/main/java/miui/statusbar/lyric/hook/app/Kuwo.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@

public class Kuwo {
public static class Hook {
public Hook(XC_LoadPackage.LoadPackageParam lpparam) throws ClassNotFoundException {
public Hook(XC_LoadPackage.LoadPackageParam lpparam, Context context) throws ClassNotFoundException {
XposedHelpers.findAndHookMethod("android.bluetooth.BluetoothAdapter", lpparam.classLoader, "isEnabled", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
}

@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
Expand All @@ -25,10 +20,9 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
Context context = (Context) param.thisObject;
String str = (String) param.args[0];
Utils.log("酷我音乐:" + str);
if (param.args[0] != null && !str.equals("") && !str.equals("好音质 用酷我") && !str.equals("正在搜索歌词...") && !str.contains(" - ")) {
if (param.args[0] != null && !str.equals("")) {
Utils.sendLyric(context, "" + str, "kuwo");
}
param.setResult(replaceHookedMethod());
Expand All @@ -37,11 +31,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
private Object replaceHookedMethod() {
return null;
}

@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
}
});
}}
}
}
}
67 changes: 48 additions & 19 deletions app/src/main/java/miui/statusbar/lyric/utils/ActivityUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static void initIcon(Activity activity, Config config) {
}
}

public static void copyAssets(Activity activity, String str, String str2) {
private static void copyAssets(Activity activity, String str, String str2) {
try {
File file = new File(str2);
InputStream open = activity.getAssets().open(str);
Expand All @@ -106,6 +106,7 @@ public static void copyAssets(Activity activity, String str, String str2) {
}
}

//检查更新
public static void checkUpdate(Activity activity) {
Handler handler = new Handler(Looper.getMainLooper(), message -> {
String data = message.getData().getString("value");
Expand All @@ -114,38 +115,32 @@ public static void checkUpdate(Activity activity) {
if (!getLocalVersion(activity).equals("")) {
if (Integer.parseInt(jsonObject.getString("tag_name").split("v")[1])
> Utils.getLocalVersionCode(activity)) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(activity.getString(R.string.NewVer) + " [" + jsonObject.getString("name") + "]")

new AlertDialog.Builder(activity)
.setTitle(String.format("%s [%s]", activity.getString(R.string.NewVer), jsonObject.getString("name")))
.setIcon(R.mipmap.ic_launcher)
.setMessage(jsonObject.getString("body").replace("#", ""))
.setPositiveButton(activity.getString(R.string.Update), (dialog, which) -> {
try {
Uri uri = Uri.parse(jsonObject.getJSONArray("assets").getJSONObject(0).getString("browser_download_url"));
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
intent.setData(uri);
Intent intent = new Intent(
Intent.ACTION_VIEW, uri);
activity.startActivity(intent);
} catch (JSONException e) {
Toast.makeText(activity, activity.getString(R.string.GetNewVerError) + e, Toast.LENGTH_LONG).show();
showToastOnLooper(activity, activity.getString(R.string.GetNewVerError) + e);
}

}).setNegativeButton(activity.getString(R.string.Cancel), null).create().show();
} else {
Toast.makeText(activity, activity.getString(R.string.NoVerUpdate), Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(activity, activity.getString(R.string.CheckUpdateError), Toast.LENGTH_LONG).show();

return true;
}
} catch (JSONException e) {
e.printStackTrace();
} catch (JSONException ignored) {
}
Looper.loop();
showToastOnLooper(activity, activity.getString(R.string.CheckUpdateError));
return true;
});

new Thread(() -> {
Looper.prepare();
String value = HttpUtils.Get("https://api.github.com/repos/577fkj/MIUIStatusBarLyric/releases/latest");
if (!value.equals("")) {
Message message = handler.obtainMessage();
Expand All @@ -154,12 +149,12 @@ public static void checkUpdate(Activity activity) {
message.setData(bundle);
handler.sendMessage(message);
} else {
Toast.makeText(activity, activity.getString(R.string.CheckUpdateFailed), Toast.LENGTH_LONG).show();
Looper.loop();
showToastOnLooper(activity, activity.getString(R.string.CheckUpdateFailed));
}
}).start();
}

//清除配置
public static void cleanConfig(Activity activity, Config config, ApiListConfig config2) {
activity.getSharedPreferences("miui.statusbar.lyric_preferences", 0).edit().clear().apply();
PackageManager packageManager = Objects.requireNonNull(activity).getPackageManager();
Expand Down Expand Up @@ -200,4 +195,38 @@ public static void showToastOnLooper(final Context context, final String message
e.printStackTrace();
}
}
}

public static void getNotice(Activity activity) {
Handler handler = new Handler(Looper.getMainLooper(), message -> {
String data = message.getData().getString("value");
try {
JSONObject jsonObject = new JSONObject(data);
if (jsonObject.getString("versionCode").equals(String.valueOf(Utils.getLocalVersionCode(activity)))) {
if (Boolean.parseBoolean(jsonObject.getString("forcibly"))) {
new AlertDialog.Builder(activity)
.setTitle(activity.getString(R.string.NewNotice))
.setIcon(R.mipmap.ic_launcher)
.setMessage(jsonObject.getString("data"))
.setNegativeButton(activity.getString(R.string.Done), null).create().show();
}
}
return true;
} catch (JSONException ignored) {
}
showToastOnLooper(activity, activity.getString(R.string.GetNewNoticeError));
return true;
});
new Thread(() -> {
String value = HttpUtils.Get("https://app.xiaowine.cc/app/notice.json");
if (!value.equals("")) {
Message message = handler.obtainMessage();
Bundle bundle = new Bundle();
bundle.putString("value", value);
message.setData(bundle);
handler.sendMessage(message);
} else {
// showToastOnLooper(activity, activity.getString(R.string.GetNewNoticeError));
}
}).start();
}
}
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,6 @@
<string name="LyricSettings">歌词设置</string>
<string name="IconSettings">图标设置</string>
<string name="LyricPos">* 歌词左右位置(重启界面后1min后生效)</string>
<string name="NewNotice">新通知</string>
<string name="GetNewNoticeError">获取新通知错误</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,6 @@
<string name="LyricSettings">歌詞設置</string>
<string name="IconSettings">圖標設置</string>
<string name="LyricPos">* 歌詞左右位置(重啟界面後1min後生效)</string>
<string name="NewNotice">新通知</string>
<string name="GetNewNoticeError">獲取新通知錯誤</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,6 @@
</string>
<string name="LyricSettings">Lyrics settings</string>
<string name="IconSettings">Icon settings</string>
<string name="NewNotice">NewNotice</string>
<string name="GetNewNoticeError">Get NewNotice Error</string>
</resources>

0 comments on commit 7d59552

Please sign in to comment.