-
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
deleted file mode 100644
index 860d833..0000000
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ /dev/null
@@ -1,77 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/migrations.xml b/.idea/migrations.xml
new file mode 100644
index 0000000..f8051a6
--- /dev/null
+++ b/.idea/migrations.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 72f0d47..824785d 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,11 +1,5 @@
+
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/StatusBarUtil/.gitignore b/StatusBarUtil/.gitignore
new file mode 100644
index 0000000..796b96d
--- /dev/null
+++ b/StatusBarUtil/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/StatusBarUtil/build.gradle b/StatusBarUtil/build.gradle
new file mode 100644
index 0000000..8053f10
--- /dev/null
+++ b/StatusBarUtil/build.gradle
@@ -0,0 +1,25 @@
+apply plugin: 'com.android.library'
+version = "1.5.1"
+android {
+ namespace 'com.jaeger.library'
+ compileSdk 34
+ resourcePrefix "statusbarutil_"
+ defaultConfig {
+ minSdkVersion 14
+ //noinspection ExpiredTargetSdkVersion
+ targetSdk 31
+ versionCode 1
+ versionName "1.0"
+ }
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+ }
+ }
+}
+
+dependencies {
+ implementation 'androidx.appcompat:appcompat:1.6.1'
+ implementation 'com.google.android.material:material:1.9.0'
+}
\ No newline at end of file
diff --git a/StatusBarUtil/proguard-rules.pro b/StatusBarUtil/proguard-rules.pro
new file mode 100644
index 0000000..d738ad8
--- /dev/null
+++ b/StatusBarUtil/proguard-rules.pro
@@ -0,0 +1,17 @@
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in /Users/Jaeger/Develop/android/sdk/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the proguardFiles
+# directive in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
diff --git a/StatusBarUtil/src/main/AndroidManifest.xml b/StatusBarUtil/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..758b0af
--- /dev/null
+++ b/StatusBarUtil/src/main/AndroidManifest.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
diff --git a/StatusBarUtil/src/main/java/com/jaeger/library/StatusBarUtil.java b/StatusBarUtil/src/main/java/com/jaeger/library/StatusBarUtil.java
new file mode 100644
index 0000000..aa0fe40
--- /dev/null
+++ b/StatusBarUtil/src/main/java/com/jaeger/library/StatusBarUtil.java
@@ -0,0 +1,726 @@
+package com.jaeger.library;
+
+import android.annotation.TargetApi;
+import android.app.Activity;
+import android.content.Context;
+import android.graphics.Color;
+import android.os.Build;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.Window;
+import android.view.WindowManager;
+import android.widget.LinearLayout;
+
+import androidx.annotation.ColorInt;
+import androidx.annotation.IntRange;
+import androidx.annotation.NonNull;
+import androidx.coordinatorlayout.widget.CoordinatorLayout;
+import androidx.drawerlayout.widget.DrawerLayout;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+/**
+ * Created by Jaeger on 16/2/14.
+ *
+ * Email: chjie.jaeger@gmail.com
+ * GitHub: ...
+ */
+public class StatusBarUtil {
+
+ public static final int DEFAULT_STATUS_BAR_ALPHA = 112;
+ private static final int FAKE_STATUS_BAR_VIEW_ID = R.id.statusbarutil_fake_status_bar_view;
+ private static final int FAKE_TRANSLUCENT_VIEW_ID = R.id.statusbarutil_translucent_view;
+ private static final int TAG_KEY_HAVE_SET_OFFSET = -123;
+
+ /**
+ * 设置状态栏颜色
+ *
+ * @param activity 需要设置的 activity
+ * @param color 状态栏颜色值
+ */
+ public static void setColor(Activity activity, @ColorInt int color) {
+ setColor(activity, color, DEFAULT_STATUS_BAR_ALPHA);
+ }
+
+ /**
+ * 设置状态栏颜色
+ *
+ * @param activity 需要设置的activity
+ * @param color 状态栏颜色值
+ * @param statusBarAlpha 状态栏透明度
+ */
+
+ public static void setColor(Activity activity, @ColorInt int color, @IntRange(from = 0, to = 255) int statusBarAlpha) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
+ activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
+ activity.getWindow().setStatusBarColor(calculateStatusColor(color, statusBarAlpha));
+ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
+ ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
+ View fakeStatusBarView = decorView.findViewById(FAKE_STATUS_BAR_VIEW_ID);
+ if (fakeStatusBarView != null) {
+ if (fakeStatusBarView.getVisibility() == View.GONE) {
+ fakeStatusBarView.setVisibility(View.VISIBLE);
+ }
+ fakeStatusBarView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
+ } else {
+ decorView.addView(createStatusBarView(activity, color, statusBarAlpha));
+ }
+ setRootView(activity);
+ }
+ }
+
+ /**
+ * 为滑动返回界面设置状态栏颜色
+ *
+ * @param activity 需要设置的activity
+ * @param color 状态栏颜色值
+ */
+ public static void setColorForSwipeBack(Activity activity, int color) {
+ setColorForSwipeBack(activity, color, DEFAULT_STATUS_BAR_ALPHA);
+ }
+
+ /**
+ * 为滑动返回界面设置状态栏颜色
+ *
+ * @param activity 需要设置的activity
+ * @param color 状态栏颜色值
+ * @param statusBarAlpha 状态栏透明度
+ */
+ public static void setColorForSwipeBack(Activity activity, @ColorInt int color,
+ @IntRange(from = 0, to = 255) int statusBarAlpha) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+
+ ViewGroup contentView = ((ViewGroup) activity.findViewById(android.R.id.content));
+ View rootView = contentView.getChildAt(0);
+ int statusBarHeight = getStatusBarHeight(activity);
+ if (rootView instanceof CoordinatorLayout) {
+ final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) rootView;
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
+ coordinatorLayout.setFitsSystemWindows(false);
+ contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
+ boolean isNeedRequestLayout = contentView.getPaddingTop() < statusBarHeight;
+ if (isNeedRequestLayout) {
+ contentView.setPadding(0, statusBarHeight, 0, 0);
+ coordinatorLayout.post(coordinatorLayout::requestLayout);
+ }
+ } else {
+ coordinatorLayout.setStatusBarBackgroundColor(calculateStatusColor(color, statusBarAlpha));
+ }
+ } else {
+ contentView.setPadding(0, statusBarHeight, 0, 0);
+ contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
+ }
+ setTransparentForWindow(activity);
+ }
+ }
+
+ /**
+ * 设置状态栏纯色 不加半透明效果
+ *
+ * @param activity 需要设置的 activity
+ * @param color 状态栏颜色值
+ */
+ public static void setColorNoTranslucent(Activity activity, @ColorInt int color) {
+ setColor(activity, color, 0);
+ }
+
+ /**
+ * 设置状态栏颜色(5.0以下无半透明效果,不建议使用)
+ *
+ * @param activity 需要设置的 activity
+ * @param color 状态栏颜色值
+ */
+ @Deprecated
+ public static void setColorDiff(Activity activity, @ColorInt int color) {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
+ return;
+ }
+ transparentStatusBar(activity);
+ ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
+ // 移除半透明矩形,以免叠加
+ View fakeStatusBarView = contentView.findViewById(FAKE_STATUS_BAR_VIEW_ID);
+ if (fakeStatusBarView != null) {
+ if (fakeStatusBarView.getVisibility() == View.GONE) {
+ fakeStatusBarView.setVisibility(View.VISIBLE);
+ }
+ fakeStatusBarView.setBackgroundColor(color);
+ } else {
+ contentView.addView(createStatusBarView(activity, color));
+ }
+ setRootView(activity);
+ }
+
+ /**
+ * 使状态栏半透明
+ *
+ * 适用于图片作为背景的界面,此时需要图片填充到状态栏
+ *
+ * @param activity 需要设置的activity
+ */
+ public static void setTranslucent(Activity activity) {
+ setTranslucent(activity, DEFAULT_STATUS_BAR_ALPHA);
+ }
+
+ /**
+ * 使状态栏半透明
+ *
+ * 适用于图片作为背景的界面,此时需要图片填充到状态栏
+ *
+ * @param activity 需要设置的activity
+ * @param statusBarAlpha 状态栏透明度
+ */
+ public static void setTranslucent(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha) {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
+ return;
+ }
+ setTransparent(activity);
+ addTranslucentView(activity, statusBarAlpha);
+ }
+
+ /**
+ * 针对根布局是 CoordinatorLayout, 使状态栏半透明
+ *
+ * 适用于图片作为背景的界面,此时需要图片填充到状态栏
+ *
+ * @param activity 需要设置的activity
+ * @param statusBarAlpha 状态栏透明度
+ */
+ public static void setTranslucentForCoordinatorLayout(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha) {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
+ return;
+ }
+ transparentStatusBar(activity);
+ addTranslucentView(activity, statusBarAlpha);
+ }
+
+ /**
+ * 设置状态栏全透明
+ *
+ * @param activity 需要设置的activity
+ */
+ public static void setTransparent(Activity activity) {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
+ return;
+ }
+ transparentStatusBar(activity);
+ setRootView(activity);
+ }
+
+ /**
+ * 使状态栏透明(5.0以上半透明效果,不建议使用)
+ *
+ * 适用于图片作为背景的界面,此时需要图片填充到状态栏
+ *
+ * @param activity 需要设置的activity
+ */
+ @Deprecated
+ public static void setTranslucentDiff(Activity activity) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ // 设置状态栏透明
+ activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
+ setRootView(activity);
+ }
+ }
+
+ /**
+ * 为DrawerLayout 布局设置状态栏变色
+ *
+ * @param activity 需要设置的activity
+ * @param drawerLayout DrawerLayout
+ * @param color 状态栏颜色值
+ */
+ public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) {
+ setColorForDrawerLayout(activity, drawerLayout, color, DEFAULT_STATUS_BAR_ALPHA);
+ }
+
+ /**
+ * 为DrawerLayout 布局设置状态栏颜色,纯色
+ *
+ * @param activity 需要设置的activity
+ * @param drawerLayout DrawerLayout
+ * @param color 状态栏颜色值
+ */
+ public static void setColorNoTranslucentForDrawerLayout(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) {
+ setColorForDrawerLayout(activity, drawerLayout, color, 0);
+ }
+
+ /**
+ * 为DrawerLayout 布局设置状态栏变色
+ *
+ * @param activity 需要设置的activity
+ * @param drawerLayout DrawerLayout
+ * @param color 状态栏颜色值
+ * @param statusBarAlpha 状态栏透明度
+ */
+ public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, @ColorInt int color,
+ @IntRange(from = 0, to = 255) int statusBarAlpha) {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
+ return;
+ }
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
+ activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
+ activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
+ } else {
+ activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
+ }
+ // 生成一个状态栏大小的矩形
+ // 添加 statusBarView 到布局中
+ ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
+ View fakeStatusBarView = contentLayout.findViewById(FAKE_STATUS_BAR_VIEW_ID);
+ if (fakeStatusBarView != null) {
+ if (fakeStatusBarView.getVisibility() == View.GONE) {
+ fakeStatusBarView.setVisibility(View.VISIBLE);
+ }
+ fakeStatusBarView.setBackgroundColor(color);
+ } else {
+ contentLayout.addView(createStatusBarView(activity, color), 0);
+ }
+ // 内容布局不是 LinearLayout 时,设置padding top
+ if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
+ contentLayout.getChildAt(1)
+ .setPadding(contentLayout.getPaddingLeft(), getStatusBarHeight(activity) + contentLayout.getPaddingTop(),
+ contentLayout.getPaddingRight(), contentLayout.getPaddingBottom());
+ }
+ // 设置属性
+ setDrawerLayoutProperty(drawerLayout, contentLayout);
+ addTranslucentView(activity, statusBarAlpha);
+ }
+
+ /**
+ * 设置 DrawerLayout 属性
+ *
+ * @param drawerLayout DrawerLayout
+ * @param drawerLayoutContentLayout DrawerLayout 的内容布局
+ */
+ private static void setDrawerLayoutProperty(DrawerLayout drawerLayout, ViewGroup drawerLayoutContentLayout) {
+ ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
+ drawerLayout.setFitsSystemWindows(false);
+ drawerLayoutContentLayout.setFitsSystemWindows(false);
+ drawerLayoutContentLayout.setClipToPadding(true);
+ drawer.setFitsSystemWindows(false);
+ }
+
+ /**
+ * 为DrawerLayout 布局设置状态栏变色(5.0以下无半透明效果,不建议使用)
+ *
+ * @param activity 需要设置的activity
+ * @param drawerLayout DrawerLayout
+ * @param color 状态栏颜色值
+ */
+ @Deprecated
+ public static void setColorForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
+ // 生成一个状态栏大小的矩形
+ ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
+ View fakeStatusBarView = contentLayout.findViewById(FAKE_STATUS_BAR_VIEW_ID);
+ if (fakeStatusBarView != null) {
+ if (fakeStatusBarView.getVisibility() == View.GONE) {
+ fakeStatusBarView.setVisibility(View.VISIBLE);
+ }
+ fakeStatusBarView.setBackgroundColor(calculateStatusColor(color, DEFAULT_STATUS_BAR_ALPHA));
+ } else {
+ // 添加 statusBarView 到布局中
+ contentLayout.addView(createStatusBarView(activity, color), 0);
+ }
+ // 内容布局不是 LinearLayout 时,设置padding top
+ if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
+ contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
+ }
+ // 设置属性
+ setDrawerLayoutProperty(drawerLayout, contentLayout);
+ }
+ }
+
+ /**
+ * 为 DrawerLayout 布局设置状态栏透明
+ *
+ * @param activity 需要设置的activity
+ * @param drawerLayout DrawerLayout
+ */
+ public static void setTranslucentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) {
+ setTranslucentForDrawerLayout(activity, drawerLayout, DEFAULT_STATUS_BAR_ALPHA);
+ }
+
+ /**
+ * 为 DrawerLayout 布局设置状态栏透明
+ *
+ * @param activity 需要设置的activity
+ * @param drawerLayout DrawerLayout
+ */
+ public static void setTranslucentForDrawerLayout(Activity activity, DrawerLayout drawerLayout,
+ @IntRange(from = 0, to = 255) int statusBarAlpha) {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
+ return;
+ }
+ setTransparentForDrawerLayout(activity, drawerLayout);
+ addTranslucentView(activity, statusBarAlpha);
+ }
+
+ /**
+ * 为 DrawerLayout 布局设置状态栏透明
+ *
+ * @param activity 需要设置的activity
+ * @param drawerLayout DrawerLayout
+ */
+ public static void setTransparentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
+ return;
+ }
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
+ activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
+ activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
+ } else {
+ activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
+ }
+
+ ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
+ // 内容布局不是 LinearLayout 时,设置padding top
+ if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
+ contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
+ }
+
+ // 设置属性
+ setDrawerLayoutProperty(drawerLayout, contentLayout);
+ }
+
+ /**
+ * 为 DrawerLayout 布局设置状态栏透明(5.0以上半透明效果,不建议使用)
+ *
+ * @param activity 需要设置的activity
+ * @param drawerLayout DrawerLayout
+ */
+ @Deprecated
+ public static void setTranslucentForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ // 设置状态栏透明
+ activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
+ // 设置内容布局属性
+ ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
+ contentLayout.setFitsSystemWindows(true);
+ contentLayout.setClipToPadding(true);
+ // 设置抽屉布局属性
+ ViewGroup vg = (ViewGroup) drawerLayout.getChildAt(1);
+ vg.setFitsSystemWindows(false);
+ // 设置 DrawerLayout 属性
+ drawerLayout.setFitsSystemWindows(false);
+ }
+ }
+
+ /**
+ * 为头部是 ImageView 的界面设置状态栏全透明
+ *
+ * @param activity 需要设置的activity
+ * @param needOffsetView 需要向下偏移的 View
+ */
+ public static void setTransparentForImageView(Activity activity, View needOffsetView) {
+ setTranslucentForImageView(activity, 0, needOffsetView);
+ }
+
+ /**
+ * 为头部是 ImageView 的界面设置状态栏透明(使用默认透明度)
+ *
+ * @param activity 需要设置的activity
+ * @param needOffsetView 需要向下偏移的 View
+ */
+ public static void setTranslucentForImageView(Activity activity, View needOffsetView) {
+ setTranslucentForImageView(activity, DEFAULT_STATUS_BAR_ALPHA, needOffsetView);
+ }
+
+ /**
+ * 为头部是 ImageView 的界面设置状态栏透明
+ *
+ * @param activity 需要设置的activity
+ * @param statusBarAlpha 状态栏透明度
+ * @param needOffsetView 需要向下偏移的 View
+ */
+ public static void setTranslucentForImageView(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha,
+ View needOffsetView) {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
+ return;
+ }
+ setTransparentForWindow(activity);
+ addTranslucentView(activity, statusBarAlpha);
+ if (needOffsetView != null) {
+ Object haveSetOffset = needOffsetView.getTag(TAG_KEY_HAVE_SET_OFFSET);
+ if (haveSetOffset != null && (Boolean) haveSetOffset) {
+ return;
+ }
+ ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) needOffsetView.getLayoutParams();
+ layoutParams.setMargins(layoutParams.leftMargin, layoutParams.topMargin + getStatusBarHeight(activity),
+ layoutParams.rightMargin, layoutParams.bottomMargin);
+ needOffsetView.setTag(TAG_KEY_HAVE_SET_OFFSET, true);
+ }
+ }
+
+ /**
+ * 为 fragment 头部是 ImageView 的设置状态栏透明
+ *
+ * @param activity fragment 对应的 activity
+ * @param needOffsetView 需要向下偏移的 View
+ */
+ public static void setTranslucentForImageViewInFragment(Activity activity, View needOffsetView) {
+ setTranslucentForImageViewInFragment(activity, DEFAULT_STATUS_BAR_ALPHA, needOffsetView);
+ }
+
+ /**
+ * 为 fragment 头部是 ImageView 的设置状态栏透明
+ *
+ * @param activity fragment 对应的 activity
+ * @param needOffsetView 需要向下偏移的 View
+ */
+ public static void setTransparentForImageViewInFragment(Activity activity, View needOffsetView) {
+ setTranslucentForImageViewInFragment(activity, 0, needOffsetView);
+ }
+
+ /**
+ * 为 fragment 头部是 ImageView 的设置状态栏透明
+ *
+ * @param activity fragment 对应的 activity
+ * @param statusBarAlpha 状态栏透明度
+ * @param needOffsetView 需要向下偏移的 View
+ */
+ public static void setTranslucentForImageViewInFragment(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha,
+ View needOffsetView) {
+ setTranslucentForImageView(activity, statusBarAlpha, needOffsetView);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
+ clearPreviousSetting(activity);
+ }
+ }
+
+ /**
+ * 隐藏伪状态栏 View
+ *
+ * @param activity 调用的 Activity
+ */
+ public static void hideFakeStatusBarView(Activity activity) {
+ ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
+ View fakeStatusBarView = decorView.findViewById(FAKE_STATUS_BAR_VIEW_ID);
+ if (fakeStatusBarView != null) {
+ fakeStatusBarView.setVisibility(View.GONE);
+ }
+ View fakeTranslucentView = decorView.findViewById(FAKE_TRANSLUCENT_VIEW_ID);
+ if (fakeTranslucentView != null) {
+ fakeTranslucentView.setVisibility(View.GONE);
+ }
+ }
+
+ @TargetApi(Build.VERSION_CODES.M)
+ public static void setLightMode(Activity activity) {
+ setMIUIStatusBarDarkIcon(activity, true);
+ setMeizuStatusBarDarkIcon(activity, true);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
+ }
+ }
+
+ @TargetApi(Build.VERSION_CODES.M)
+ public static void setDarkMode(Activity activity) {
+ setMIUIStatusBarDarkIcon(activity, false);
+ setMeizuStatusBarDarkIcon(activity, false);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
+ }
+ }
+
+ /**
+ * 修改 MIUI V6 以上状态栏颜色
+ */
+ private static void setMIUIStatusBarDarkIcon(@NonNull Activity activity, boolean darkIcon) {
+ Class extends Window> clazz = activity.getWindow().getClass();
+ try {
+ Class> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
+ Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
+ int darkModeFlag = field.getInt(layoutParams);
+ Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
+ extraFlagField.invoke(activity.getWindow(), darkIcon ? darkModeFlag : 0, darkModeFlag);
+ } catch (Exception e) {
+ //e.printStackTrace();
+ }
+ }
+
+ /**
+ * 修改魅族状态栏字体颜色 Flyme 4.0
+ */
+ private static void setMeizuStatusBarDarkIcon(@NonNull Activity activity, boolean darkIcon) {
+ try {
+ WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
+ Field darkFlag = WindowManager.LayoutParams.class.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
+ Field meizuFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags");
+ darkFlag.setAccessible(true);
+ meizuFlags.setAccessible(true);
+ int bit = darkFlag.getInt(null);
+ int value = meizuFlags.getInt(lp);
+ if (darkIcon) {
+ value |= bit;
+ } else {
+ value &= ~bit;
+ }
+ meizuFlags.setInt(lp, value);
+ activity.getWindow().setAttributes(lp);
+ } catch (Exception e) {
+ //e.printStackTrace();
+ }
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////
+
+ @TargetApi(Build.VERSION_CODES.KITKAT)
+ private static void clearPreviousSetting(Activity activity) {
+ ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
+ View fakeStatusBarView = decorView.findViewById(FAKE_STATUS_BAR_VIEW_ID);
+ if (fakeStatusBarView != null) {
+ decorView.removeView(fakeStatusBarView);
+ ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
+ rootView.setPadding(0, 0, 0, 0);
+ }
+ }
+
+ /**
+ * 添加半透明矩形条
+ *
+ * @param activity 需要设置的 activity
+ * @param statusBarAlpha 透明值
+ */
+ private static void addTranslucentView(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha) {
+ ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
+ View fakeTranslucentView = contentView.findViewById(FAKE_TRANSLUCENT_VIEW_ID);
+ if (fakeTranslucentView != null) {
+ if (fakeTranslucentView.getVisibility() == View.GONE) {
+ fakeTranslucentView.setVisibility(View.VISIBLE);
+ }
+ fakeTranslucentView.setBackgroundColor(Color.argb(statusBarAlpha, 0, 0, 0));
+ } else {
+ contentView.addView(createTranslucentStatusBarView(activity, statusBarAlpha));
+ }
+ }
+
+ /**
+ * 生成一个和状态栏大小相同的彩色矩形条
+ *
+ * @param activity 需要设置的 activity
+ * @param color 状态栏颜色值
+ * @return 状态栏矩形条
+ */
+ private static View createStatusBarView(Activity activity, @ColorInt int color) {
+ return createStatusBarView(activity, color, 0);
+ }
+
+ /**
+ * 生成一个和状态栏大小相同的半透明矩形条
+ *
+ * @param activity 需要设置的activity
+ * @param color 状态栏颜色值
+ * @param alpha 透明值
+ * @return 状态栏矩形条
+ */
+ private static View createStatusBarView(Activity activity, @ColorInt int color, int alpha) {
+ // 绘制一个和状态栏一样高的矩形
+ View statusBarView = new View(activity);
+ LinearLayout.LayoutParams params =
+ new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity));
+ statusBarView.setLayoutParams(params);
+ statusBarView.setBackgroundColor(calculateStatusColor(color, alpha));
+ statusBarView.setId(FAKE_STATUS_BAR_VIEW_ID);
+ return statusBarView;
+ }
+
+ /**
+ * 设置根布局参数
+ */
+ private static void setRootView(Activity activity) {
+ ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content);
+ for (int i = 0, count = parent.getChildCount(); i < count; i++) {
+ View childView = parent.getChildAt(i);
+ if (childView instanceof ViewGroup) {
+ childView.setFitsSystemWindows(true);
+ ((ViewGroup) childView).setClipToPadding(true);
+ }
+ }
+ }
+
+ /**
+ * 设置透明
+ */
+ private static void setTransparentForWindow(Activity activity) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
+ activity.getWindow()
+ .getDecorView()
+ .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
+ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ activity.getWindow()
+ .setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
+ }
+ }
+
+ /**
+ * 使状态栏透明
+ */
+ @TargetApi(Build.VERSION_CODES.KITKAT)
+ private static void transparentStatusBar(Activity activity) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
+ activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
+ activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
+ activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
+ } else {
+ activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
+ }
+ }
+
+ /**
+ * 创建半透明矩形 View
+ *
+ * @param alpha 透明值
+ * @return 半透明 View
+ */
+ private static View createTranslucentStatusBarView(Activity activity, int alpha) {
+ // 绘制一个和状态栏一样高的矩形
+ View statusBarView = new View(activity);
+ LinearLayout.LayoutParams params =
+ new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity));
+ statusBarView.setLayoutParams(params);
+ statusBarView.setBackgroundColor(Color.argb(alpha, 0, 0, 0));
+ statusBarView.setId(FAKE_TRANSLUCENT_VIEW_ID);
+ return statusBarView;
+ }
+
+ /**
+ * 获取状态栏高度
+ *
+ * @param context context
+ * @return 状态栏高度
+ */
+ private static int getStatusBarHeight(Context context) {
+ // 获得状态栏高度
+ int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
+ return context.getResources().getDimensionPixelSize(resourceId);
+ }
+
+ /**
+ * 计算状态栏颜色
+ *
+ * @param color color值
+ * @param alpha alpha值
+ * @return 最终的状态栏颜色
+ */
+ private static int calculateStatusColor(@ColorInt int color, int alpha) {
+ if (alpha == 0) {
+ return color;
+ }
+ float a = 1 - alpha / 255f;
+ int red = color >> 16 & 0xff;
+ int green = color >> 8 & 0xff;
+ int blue = color & 0xff;
+ red = (int) (red * a + 0.5);
+ green = (int) (green * a + 0.5);
+ blue = (int) (blue * a + 0.5);
+ return 0xff << 24 | red << 16 | green << 8 | blue;
+ }
+}
diff --git a/StatusBarUtil/src/main/res/values/ids.xml b/StatusBarUtil/src/main/res/values/ids.xml
new file mode 100644
index 0000000..faad20c
--- /dev/null
+++ b/StatusBarUtil/src/main/res/values/ids.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 992a53d..69d54b8 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -4,7 +4,7 @@ plugins {
android {
signingConfigs {
debug {
- storeFile file('F:\\muqing.jks')
+ storeFile file('../muqing.jks')
storePassword 'muqing153'
keyAlias 'muqing'
keyPassword 'muqing153'
@@ -44,8 +44,8 @@ android {
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
-
implementation 'com.google.android.material:material:1.9.0'
+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.code.gson:gson:2.9.1'
@@ -61,5 +61,6 @@ dependencies {
//修改音乐标签库
implementation 'com.mpatric:mp3agic:0.9.1'
-// implementation 'com.github.QuadFlask:colorpicker:0.0.15'
+// 沉浸式状态栏
+ api project(path: ':StatusBarUtil')
}
\ No newline at end of file
diff --git a/app/debug/Cloud_music-debug-v1.9.5.apk b/app/debug/Cloud_music-debug-v1.9.5.apk
deleted file mode 100644
index 5fdccd1..0000000
Binary files a/app/debug/Cloud_music-debug-v1.9.5.apk and /dev/null differ
diff --git a/app/debug/output-metadata.json b/app/debug/output-metadata.json
deleted file mode 100644
index 6d112db..0000000
--- a/app/debug/output-metadata.json
+++ /dev/null
@@ -1,20 +0,0 @@
-{
- "version": 3,
- "artifactType": {
- "type": "APK",
- "kind": "Directory"
- },
- "applicationId": "com.muqingbfq",
- "variantName": "debug",
- "elements": [
- {
- "type": "SINGLE",
- "filters": [],
- "attributes": [],
- "versionCode": 1,
- "versionName": "1.9.5",
- "outputFile": "Cloud_music-debug-v1.9.5.apk"
- }
- ],
- "elementType": "File"
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/muqingbfq/activity_search.java b/app/src/main/java/com/muqingbfq/activity_search.java
index 7dd9f0b..b1b1ef2 100644
--- a/app/src/main/java/com/muqingbfq/activity_search.java
+++ b/app/src/main/java/com/muqingbfq/activity_search.java
@@ -1,10 +1,12 @@
package com.muqingbfq;
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
+import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
-import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -16,6 +18,7 @@ import android.widget.ListView;
import android.widget.TextView;
import androidx.annotation.NonNull;
+import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.flexbox.AlignItems;
@@ -31,6 +34,7 @@ import com.muqingbfq.mq.FragmentActivity;
import com.muqingbfq.mq.gj;
import com.muqingbfq.mq.wj;
import com.muqingbfq.mq.wl;
+import com.muqingbfq.view.Edit;
import org.json.JSONArray;
import org.json.JSONObject;
@@ -101,13 +105,14 @@ public class activity_search extends FragmentActivity {
});
Object o = new Object();
- binding.editview.addTextChangedListener(new TextWatcher() {
+ binding.editview.addTextChangedListener(new Edit.TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
+ binding.editview.iskong();
if (TextUtils.isEmpty(s)) {
listPopupWindow.setVisibility(View.GONE);
return;
@@ -143,13 +148,13 @@ public class activity_search extends FragmentActivity {
public void afterTextChanged(Editable s) {
}
});
- gj.tcjp(binding.editview);
+ gj.tcjp(binding.editview.editText);
}
public void dismiss() {
binding.editview.clearFocus();
listPopupWindow.setVisibility(View.GONE);
- gj.ycjp(binding.editview);
+ gj.ycjp(binding.editview.editText);
}
@SuppressLint("NotifyDataSetChanged")
@@ -169,7 +174,8 @@ public class activity_search extends FragmentActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.home, menu);
+ MenuItem sousuo = menu.add("搜索");
+ sousuo.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
return super.onCreateOptionsMenu(menu);
}
@@ -178,7 +184,7 @@ public class activity_search extends FragmentActivity {
int itemId = item.getItemId();
if (itemId == android.R.id.home) {
finish();
- } else if (itemId == R.id.menu_search) {
+ } else if (itemId == 0) {
start(binding.editview.getText().toString());
}
return super.onOptionsItemSelected(item);
@@ -213,6 +219,23 @@ public class activity_search extends FragmentActivity {
if (json_list.isEmpty()) {
binding.xxbj1.setVisibility(View.INVISIBLE);
}
+ RecyclerView.ItemAnimator animator = new DefaultItemAnimator(){
+ @Override
+ public boolean animateRemove(RecyclerView.ViewHolder holder) {
+ ObjectAnimator fadeAnimator = ObjectAnimator.ofFloat(holder.itemView, "alpha", 1f, 0f);
+ fadeAnimator.setDuration(getRemoveDuration());
+ fadeAnimator.addListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ dispatchRemoveFinished(holder);
+ holder.itemView.setAlpha(1f);
+ }
+ });
+ fadeAnimator.start();
+ return false;
+ }
+ };
+ binding.listRecycler.setItemAnimator(animator);
}
@NonNull
@@ -236,7 +259,7 @@ public class activity_search extends FragmentActivity {
.setPositiveButton("确定", (dialogInterface, i) -> {
json_list.remove(keyword);
wj.xrwb(wj.filesdri + wj.lishi_json, new Gson().toJson(json_list));
- notifyItemChanged(position);
+ notifyItemRemoved(position);
})
.setNegativeButton("取消", null)
.show();
diff --git a/app/src/main/java/com/muqingbfq/api/resource.java b/app/src/main/java/com/muqingbfq/api/resource.java
index 1699d3d..7addc82 100644
--- a/app/src/main/java/com/muqingbfq/api/resource.java
+++ b/app/src/main/java/com/muqingbfq/api/resource.java
@@ -62,7 +62,8 @@ public class resource {
return new XM(id, name, coverImgUrl);
}
- public static void 排行榜(List list) {
+// 排行榜
+ public static void leaderboard(List list) {
String hq;
try {
if (wj.cz(wj.gd_phb)) {
diff --git a/app/src/main/java/com/muqingbfq/fragment/gd.java b/app/src/main/java/com/muqingbfq/fragment/gd.java
index 11184f4..488f12d 100644
--- a/app/src/main/java/com/muqingbfq/fragment/gd.java
+++ b/app/src/main/java/com/muqingbfq/fragment/gd.java
@@ -5,7 +5,9 @@ import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
+import android.view.GestureDetector;
import android.view.LayoutInflater;
+import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
@@ -53,6 +55,7 @@ public class gd extends com.muqingbfq.mq.FragmentActivity {
super.onCreate(savedInstanceState);
FragmentMp3Binding binding = FragmentMp3Binding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
+
Intent intent = getIntent();
binding.title.setText(intent.getStringExtra("name"));
adapter = new baseadapter(this, list);
@@ -79,7 +82,7 @@ public class gd extends com.muqingbfq.mq.FragmentActivity {
public void run() {
super.run();
if (id.equals("排行榜")) {
- resource.排行榜(list);
+ resource.leaderboard(list);
} else {
String hq = wl.hq("/search?keywords=" + id + "&limit=" + (k * 3) + "&type=1000");
try {
@@ -103,7 +106,7 @@ public class gd extends com.muqingbfq.mq.FragmentActivity {
public static class baseadapter extends RecyclerView.Adapter {
Context context;
- List list;
+ public List list;
public baseadapter(Context context, List list) {
this.context = context;
@@ -112,10 +115,108 @@ public class gd extends com.muqingbfq.mq.FragmentActivity {
boolean bool = false;
- public baseadapter(Context context, List list, boolean bool) {
+ public baseadapter(Context context, List list, boolean bool, RecyclerView recyclerView) {
this.context = context;
this.list = list;
this.bool = bool;
+ setrecycle(recyclerView);
+ }
+
+ public void setrecycle(RecyclerView recyclerView) {
+
+ recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
+ final GestureDetector gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
+ @Override
+ public void onLongPress(@NonNull MotionEvent motionEvent) {
+ View childView = recyclerView.findChildViewUnder(motionEvent.getX(), motionEvent.getY());
+ if (childView != null) {
+ int position = recyclerView.getChildAdapterPosition(childView);
+ setonlong(position);
+ // 处理长按事件,使用正确的位置position
+ // ...
+
+ }
+ }
+ });
+
+ @Override
+ public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) {
+ return gestureDetector.onTouchEvent(e);
+ }
+
+ @Override
+ public void onTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) {
+
+ }
+
+ @Override
+ public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
+
+ }
+
+ });
+ }
+
+ @SuppressLint("NotifyDataSetChanged")
+ public void setonlong(int position) {
+ XM xm = list.get(position);
+ gj.sc(xm.name);
+ String[] stringArray = context.getResources()
+ .getStringArray(R.array.gd_list);
+ if (!wj.cz(wj.gd + xm.id)) {
+ stringArray = new String[]{"下载歌单"};
+ }
+ String[] finalStringArray = stringArray;
+ new MaterialAlertDialogBuilder(context).
+ setItems(stringArray, (dialog, id) -> {
+ switch (finalStringArray[id]) {
+ case "下载歌单":
+ new Thread() {
+ @SuppressLint("NotifyDataSetChanged")
+ @Override
+ public void run() {
+ super.run();
+ String hq = playlist.gethq(xm.id);
+ if (hq != null) {
+ wj.xrwb(wj.gd + xm.id, hq);
+ try {
+ JSONObject jsonObject = new JSONObject();
+ if (wj.cz(wj.gd_xz)) {
+ jsonObject = new JSONObject(Objects.requireNonNull(wj.dqwb(wj.gd_xz)));
+ }
+ XM fh = resource.Playlist_content(xm.id);
+ JSONObject json = new JSONObject();
+ json.put("name", fh.name);
+ json.put("picUrl", fh.picurl);
+ jsonObject.put(fh.id, json);
+ wj.xrwb(wj.gd_xz, jsonObject.toString());
+ main.handler.post(() -> {
+ notifyItemChanged(position);
+ wode.addlist(xm);
+ });
+ } catch (JSONException e) {
+ gj.sc("list gd onclick thear " + e);
+ }
+ }
+ }
+ }.start();
+ break;
+ case "删除歌单":
+// 删除项目
+ try {
+ wj.sc(wj.gd + xm.id);
+ JSONObject jsonObject = new JSONObject(Objects.requireNonNull(wj.dqwb(wj.gd_xz)));
+ jsonObject.remove(xm.id);
+ list.remove(xm);
+ wj.xrwb(wj.gd_xz, jsonObject.toString());
+ wode.removelist(xm);
+ } catch (JSONException e) {
+ gj.sc(e);
+ }
+ break;
+ }
+ // 在这里处理菜单项的点击事件
+ }).show();
}
@NonNull
@@ -140,10 +241,12 @@ public class gd extends com.muqingbfq.mq.FragmentActivity {
if (bool) {
holder.itemView.setOnClickListener(card);
holder.bindingB.text2.setText(xm.message);
- holder.itemView.setOnLongClickListener(card);
} else {
holder.binding.image.setOnClickListener(card);
- holder.binding.image.setOnLongClickListener(card);
+ holder.binding.image.setOnLongClickListener(v -> {
+ setonlong(position);
+ return false;
+ });
}
holder.title.setText(xm.name);
holder.kg.setOnClickListener(view1 -> {
@@ -182,8 +285,7 @@ public class gd extends com.muqingbfq.mq.FragmentActivity {
return list.size();
}
- class CARD implements View.OnClickListener
- , View.OnLongClickListener {
+ class CARD implements View.OnClickListener {
int position;
public CARD(int position) {
@@ -199,60 +301,6 @@ public class gd extends com.muqingbfq.mq.FragmentActivity {
intent.putExtra("name", xm.name);
context.startActivity(intent);
}
-
- @Override
- public boolean onLongClick(View view) {
- XM xm = list.get(position);
- String[] stringArray = view.getResources()
- .getStringArray(R.array.gd_list);
- if (!wj.cz(wj.gd + xm.id)) {
- stringArray = new String[]{"下载歌单"};
- }
- new MaterialAlertDialogBuilder(view.getContext()).
- setItems(stringArray, (dialog, id) -> {
- new Thread() {
- @Override
- public void run() {
- if (id == 0) {
- String hq = playlist.gethq(xm.id);
- if (hq != null) {
- wj.xrwb(wj.gd + xm.id, hq);
- try {
- JSONObject jsonObject = new JSONObject();
- if (wj.cz(wj.gd_xz)) {
- jsonObject = new JSONObject(Objects.requireNonNull(wj.dqwb(wj.gd_xz)));
- }
- XM fh = resource.Playlist_content(xm.id);
- JSONObject json = new JSONObject();
- json.put("name", fh.name);
- json.put("picUrl", fh.picurl);
- jsonObject.put(fh.id, json);
- wj.xrwb(wj.gd_xz, jsonObject.toString());
- main.handler.post(() -> notifyItemChanged(position));
- } catch (JSONException e) {
- gj.sc("list gd onclick thear " + e);
- }
- }
-
- } else if (id == 2) {
- wj.sc(wj.gd + xm.id);
- try {
- JSONObject jsonObject = new JSONObject(Objects.requireNonNull(wj.dqwb(wj.gd_xz)));
- jsonObject.remove(xm.id);
- list.remove(xm);
- wj.xrwb(wj.gd_xz, jsonObject.toString());
- main.handler.post(() -> notifyItemChanged(position));
- } catch (JSONException e) {
- gj.sc(e);
- }
- }
- }
- }.start();
- // 在这里处理菜单项的点击事件
- }).show();
- return false;
- }
-
}
}
@@ -262,6 +310,7 @@ public class gd extends com.muqingbfq.mq.FragmentActivity {
public ImageView kg;
public CardImage image;
public TextView title;
+
public VH(@NonNull ListGdBinding itemView) {
super(itemView.getRoot());
binding = itemView;
@@ -288,4 +337,6 @@ public class gd extends com.muqingbfq.mq.FragmentActivity {
adapter.notifyDataSetChanged();
}
}
+
+
}
\ No newline at end of file
diff --git a/app/src/main/java/com/muqingbfq/fragment/gd_adapter.java b/app/src/main/java/com/muqingbfq/fragment/gd_adapter.java
index d283880..8ede88b 100644
--- a/app/src/main/java/com/muqingbfq/fragment/gd_adapter.java
+++ b/app/src/main/java/com/muqingbfq/fragment/gd_adapter.java
@@ -1,13 +1,20 @@
package com.muqingbfq.fragment;
import android.annotation.SuppressLint;
+import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import androidx.appcompat.app.ActionBarDrawerToggle;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@@ -17,11 +24,13 @@ import com.bumptech.glide.request.RequestOptions;
import com.muqingbfq.MP3;
import com.muqingbfq.R;
import com.muqingbfq.XM;
+import com.muqingbfq.activity_search;
import com.muqingbfq.api.resource;
import com.muqingbfq.api.url;
import com.muqingbfq.bfqkz;
import com.muqingbfq.databinding.FragmentGdBinding;
import com.muqingbfq.databinding.ListMp3ImageBinding;
+import com.muqingbfq.home;
import com.muqingbfq.main;
import com.muqingbfq.mq.gj;
import com.muqingbfq.mq.wj;
@@ -38,12 +47,27 @@ public class gd_adapter extends Fragment {
List listmp3 = new ArrayList<>();
FragmentGdBinding binding;
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ setHasOptionsMenu(true);
+ // 其他初始化代码...
+ }
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = FragmentGdBinding.inflate(getLayoutInflater(), container, false);
+ //初始化工具栏
+ ((AppCompatActivity) requireActivity()).setSupportActionBar(binding.toolbar);
+ DrawerLayout drawerLayout = home.appCompatActivity.findViewById(R.id.chct);
+ ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
+ getActivity(), drawerLayout, binding.toolbar, R.string.app_name, R.string.app_name);
+ drawerLayout.addDrawerListener(toggle);
+ toggle.syncState();
+
+ binding.toolbar.setPadding(0, gj.getztl(getContext()), 0, 0);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
binding.recyclerview1.setHasFixedSize(true);
@@ -131,6 +155,21 @@ public class gd_adapter extends Fragment {
}
}
+ @Override
+ public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater inflater) {
+ inflater.inflate(R.menu.home, menu);
+ super.onCreateOptionsMenu(menu, inflater);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == R.id.menu_search) {
+ Intent intent = new Intent(getContext(), activity_search.class);
+ startActivity(intent);
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
public void mp3list() {
new Thread(){
@SuppressLint("NotifyDataSetChanged")
diff --git a/app/src/main/java/com/muqingbfq/fragment/search.java b/app/src/main/java/com/muqingbfq/fragment/search.java
index 7247bc3..8745142 100644
--- a/app/src/main/java/com/muqingbfq/fragment/search.java
+++ b/app/src/main/java/com/muqingbfq/fragment/search.java
@@ -92,7 +92,9 @@ public class search extends Fragment {
} else if (i == 1) {
k = (int) (main.k / getResources().getDisplayMetrics().density + 0.5f) / 120;
inflate.recyclerview.setLayoutManager(new LinearLayoutManager(getContext()));
- inflate.recyclerview.setAdapter(new gd.baseadapter(getContext(), xmList, true));
+ inflate.recyclerview.setAdapter(new gd.baseadapter(getContext(),
+ xmList, true, inflate.recyclerview));
+
}
new start(name);
}
diff --git a/app/src/main/java/com/muqingbfq/fragment/sz.java b/app/src/main/java/com/muqingbfq/fragment/sz.java
index f549a37..ba53d59 100644
--- a/app/src/main/java/com/muqingbfq/fragment/sz.java
+++ b/app/src/main/java/com/muqingbfq/fragment/sz.java
@@ -9,7 +9,6 @@ import android.widget.Toast;
import com.muqingbfq.R;
import com.muqingbfq.activity_about_software;
import com.muqingbfq.clean.fragment_clean;
-import com.muqingbfq.login.cookie;
import com.muqingbfq.mq.gj;
public class sz {
diff --git a/app/src/main/java/com/muqingbfq/fragment/wode.java b/app/src/main/java/com/muqingbfq/fragment/wode.java
index 506a017..28ae1a4 100644
--- a/app/src/main/java/com/muqingbfq/fragment/wode.java
+++ b/app/src/main/java/com/muqingbfq/fragment/wode.java
@@ -2,8 +2,12 @@ package com.muqingbfq.fragment;
import android.annotation.SuppressLint;
import android.content.Intent;
+import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
@@ -11,19 +15,28 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import androidx.appcompat.app.ActionBarDrawerToggle;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.content.ContextCompat;
+import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
+import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.gson.Gson;
import com.muqingbfq.R;
import com.muqingbfq.XM;
+import com.muqingbfq.activity_search;
import com.muqingbfq.api.playlist;
import com.muqingbfq.api.resource;
+import com.muqingbfq.bfqkz;
import com.muqingbfq.databinding.FragmentWdBinding;
+import com.muqingbfq.databinding.ListGdBBinding;
+import com.muqingbfq.home;
import com.muqingbfq.login.user_logs;
import com.muqingbfq.login.visitor;
import com.muqingbfq.main;
@@ -36,6 +49,7 @@ import org.json.JSONObject;
import java.io.File;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
@@ -59,14 +73,55 @@ public class wode extends Fragment {
{R.drawable.paihangbang, "排行榜", "排行榜"},
{R.drawable.icon, "开发中", ""}
};
- private final List list = new ArrayList<>();
+ @SuppressLint("StaticFieldLeak")
+ public static baseadapter adaper;
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ setHasOptionsMenu(true);
+ // 其他初始化代码...
+ }
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
binding = FragmentWdBinding.inflate(inflater, container, false);
+ //初始化工具栏
+ ((AppCompatActivity) requireActivity()).setSupportActionBar(binding.toolbar);
+ DrawerLayout drawerLayout = home.appCompatActivity.findViewById(R.id.chct);
+ ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
+ getActivity(), drawerLayout, binding.toolbar, R.string.app_name, R.string.app_name);
+ drawerLayout.addDrawerListener(toggle);
+ toggle.syncState();
+
+ binding.appbar.setPadding(0, gj.getztl(getContext()), 0, 0);
name = binding.text1;
+ binding.toolbar.setTitle("");
+ binding.appbar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
+ boolean isCollapsed = false; // 标记是否处于折叠状态
+
+ @Override
+ public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
+ if (Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange()) {
+ // 完全折叠时的逻辑
+ if (!isCollapsed) {
+ // 处理完全折叠时的操作
+ isCollapsed = true;
+ binding.aaa.setVisibility(View.VISIBLE);
+ binding.aaa.setText(name.getText());
+ }
+ } else {
+ // 非折叠状态的逻辑
+ if (isCollapsed) {
+ // 处理非折叠状态的操作
+ isCollapsed = false;
+ binding.aaa.setVisibility(View.GONE);
+ }
+ }
+ }
+ });
jieshao = binding.text2;
imageView = binding.imageView;
binding.cardview.setOnClickListener(v -> {
@@ -157,7 +212,7 @@ public class wode extends Fragment {
}
String finalStr = str;
gj.ts(getContext(), "导入中");
- new Thread(){
+ new Thread() {
@Override
public void run() {
super.run();
@@ -204,12 +259,14 @@ public class wode extends Fragment {
}
});
binding.recyclerview2.setFocusable(false);
- binding.recyclerview2.setAdapter(new gd.baseadapter(getContext(), list, true));
+ adaper = new baseadapter();
+ binding.recyclerview2.setAdapter(adaper);
sx();
denglu();
return binding.getRoot();
}
+
class VH extends RecyclerView.ViewHolder {
public ImageView imageView;
public TextView textView;
@@ -224,14 +281,14 @@ public class wode extends Fragment {
@SuppressLint("NotifyDataSetChanged")
public void sx() {
try {
- list.clear();
+ adaper.list.clear();
JSONObject date = new JSONObject(wj.dqwb(wj.gd_xz));
for (Iterator it = date.keys(); it.hasNext(); ) {
String id = it.next();
JSONObject jsonObject = date.getJSONObject(id);
String name = jsonObject.getString("name");
String picUrl = jsonObject.getString("picUrl");
- list.add(new XM(id, name, picUrl));
+ adaper.list.add(new XM(id, name, picUrl));
}
main.handler.post(() -> binding.recyclerview2.getAdapter().notifyDataSetChanged());
} catch (Exception e) {
@@ -239,6 +296,22 @@ public class wode extends Fragment {
}
}
+ @SuppressLint("NotifyDataSetChanged")
+ public static void addlist(XM xm) {
+ if (adaper != null&&!adaper.list.contains(xm)) {
+ adaper.list.add(xm);
+ adaper.notifyDataSetChanged();
+ }
+ }
+
+ @SuppressLint("NotifyDataSetChanged")
+ public static void removelist(XM xm) {
+ if (adaper != null) {
+ adaper.list.remove(xm);
+ adaper.notifyDataSetChanged();
+ }
+ }
+
public static void setname(String string) {
main.handler.post(() -> name.setText(string));
}
@@ -266,4 +339,135 @@ public class wode extends Fragment {
.error(R.drawable.ic_launcher_foreground)
.into(binding.imageView);
}
+
+
+ @Override
+ public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater inflater) {
+ inflater.inflate(R.menu.home, menu);
+ super.onCreateOptionsMenu(menu, inflater);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == R.id.menu_search) {
+ Intent intent = new Intent(getContext(), activity_search.class);
+ startActivity(intent);
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ class baseadapter extends RecyclerView.Adapter {
+ public List list = new ArrayList<>();
+ @NonNull
+ @Override
+ public gd.VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+ return new gd.VH(ListGdBBinding.bind(LayoutInflater.from(getContext())
+ .inflate(R.layout.list_gd_b, parent, false)));
+ }
+
+ public void setList(List list) {
+ this.list = list;
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull gd.VH holder, @SuppressLint("RecyclerView") int position) {
+ XM xm = list.get(position);
+ holder.itemView.setOnClickListener(v -> {
+ XM xm1 = list.get(position);
+ Intent intent = new Intent(getContext(), mp3.class);
+ intent.putExtra("id", xm1.id);
+ intent.putExtra("name", xm1.name);
+ getContext().startActivity(intent);
+ });
+ holder.itemView.setOnLongClickListener(v -> {
+ String[] stringArray = {"下载歌单", "删除歌单"};
+ new MaterialAlertDialogBuilder(getContext()).
+ setItems(stringArray, (dialog, id) -> {
+ switch (stringArray[id]) {
+ case "下载歌单":
+ new Thread() {
+ @SuppressLint("NotifyDataSetChanged")
+ @Override
+ public void run() {
+ super.run();
+ String hq = playlist.gethq(xm.id);
+ if (hq != null) {
+ wj.xrwb(wj.gd + xm.id, hq);
+ try {
+ JSONObject jsonObject = new JSONObject();
+ if (wj.cz(wj.gd_xz)) {
+ jsonObject = new JSONObject(Objects.requireNonNull(wj.dqwb(wj.gd_xz)));
+ }
+ XM fh = resource.Playlist_content(xm.id);
+ JSONObject json = new JSONObject();
+ json.put("name", fh.name);
+ json.put("picUrl", fh.picurl);
+ jsonObject.put(fh.id, json);
+ wj.xrwb(wj.gd_xz, jsonObject.toString());
+ main.handler.post(() -> notifyItemChanged(position));
+ } catch (JSONException e) {
+ gj.sc("list gd onclick thear " + e);
+ }
+ }
+ }
+ }.start();
+ break;
+ case "删除歌单":
+// 删除项目
+ try {
+ wj.sc(wj.gd + xm.id);
+ JSONObject jsonObject = new JSONObject(Objects.requireNonNull(wj.dqwb(wj.gd_xz)));
+ jsonObject.remove(xm.id);
+ list.remove(xm);
+ wj.xrwb(wj.gd_xz, jsonObject.toString());
+ notifyItemRemoved(position);
+ } catch (JSONException e) {
+ gj.sc(e);
+ }
+ break;
+ }
+ // 在这里处理菜单项的点击事件
+ }).show();
+ return false;
+ });
+
+ holder.bindingB.text2.setText(xm.message);
+ holder.title.setText(xm.name);
+ holder.kg.setOnClickListener(view1 -> {
+ ImageView tx = (ImageView) view1;
+ new Thread() {
+ @SuppressLint("NotifyDataSetChanged")
+ @Override
+ public void run() {
+ super.run();
+ boolean an = playlist.hq(bfqkz.list, xm.id);
+ if (bfqkz.ms == 2) {
+ Collections.shuffle(bfqkz.list);
+ }
+ main.handler.post(() -> {
+ if (an) {
+ com.muqingbfq.bfq_an.xyq();
+ tx.setImageResource(R.drawable.bf);
+ com.muqingbfq.fragment.gd.gdid = xm.id;
+ }
+ notifyDataSetChanged();
+ });
+ }
+ }.start();
+ });
+ Drawable color_kg = ContextCompat.getDrawable(getContext(), R.drawable.zt);
+ if (xm.id.equals(com.muqingbfq.fragment.gd.gdid)) {
+ color_kg = ContextCompat.getDrawable(getContext(), R.drawable.bf);
+ }
+ holder.kg.setImageDrawable(color_kg);
+// xm.picurl
+ holder.image.setImageapply(xm.picurl);
+ }
+
+ @Override
+ public int getItemCount() {
+ return list.size();
+ }
+ }
+
}
diff --git a/app/src/main/java/com/muqingbfq/home.java b/app/src/main/java/com/muqingbfq/home.java
index 268e4ca..2d361ec 100644
--- a/app/src/main/java/com/muqingbfq/home.java
+++ b/app/src/main/java/com/muqingbfq/home.java
@@ -6,16 +6,13 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
-import android.os.Process;
import android.support.v4.media.MediaBrowserCompat;
import android.util.DisplayMetrics;
import android.view.Menu;
import android.view.MenuItem;
import androidx.annotation.NonNull;
-import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
-import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;
@@ -44,17 +41,11 @@ public class home extends AppCompatActivity {
super.onCreate(savedInstanceState);
binding = ActivityHomeBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
+// binding.toolbar.setPadding(0, gj.getztl(this), 0, 0);
DisplayMetrics dm = getResources().getDisplayMetrics();
main.k = dm.widthPixels;
main.g = dm.heightPixels;
try {
- //初始化工具栏
- setSupportActionBar(binding.toolbar);
- DrawerLayout drawerLayout = findViewById(R.id.chct);
- ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
- this, drawerLayout, binding.toolbar, R.string.app_name, R.string.app_name);
- drawerLayout.addDrawerListener(toggle);
- toggle.syncState();
//初始化侧滑
binding.chb.setNavigationItemSelectedListener(item -> {
com.muqingbfq.fragment.sz.switch_sz(home.this, item.getItemId());
@@ -75,8 +66,6 @@ public class home extends AppCompatActivity {
}
//检测更新
new gj.jianchagengxin(this);
- binding.editView.setOnClickListener(view ->
- startActivity(new Intent(this, activity_search.class)));
UI();
// startService(new Intent(this, FloatingLyricsService.class));
} catch (Exception e) {
@@ -122,6 +111,7 @@ public class home extends AppCompatActivity {
}
return true;
});
+ Object o = new Object();
binding.viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
@Override
public void onPageSelected(int position) {
@@ -131,19 +121,15 @@ public class home extends AppCompatActivity {
break;
case 1:
binding.tablayout.setSelectedItemId(R.id.c);
- new Thread() {
+/* new Thread() {
@Override
public void run() {
- super.run();
- try {
- sleep(1000);
- } catch (InterruptedException e) {
- e.toString();
+ synchronized (o) {
+ wode fragment = (wode) adapter.createFragment(position);
+ fragment.sx();
}
- wode fragment = (wode) adapter.createFragment(position);
- fragment.sx();
}
- }.start();
+ }.start();*/
break;
}
}
@@ -169,25 +155,12 @@ public class home extends AppCompatActivity {
.replace(R.id.bfq_db, new bfq_db())
.commit();
}
+
@Override
public void onBackPressed() {
moveTaskToBack(true);
}
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.home, menu);
- return super.onCreateOptionsMenu(menu);
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if (item.getItemId() == R.id.menu_search) {
- Intent intent = new Intent(this, activity_search.class);
- startActivity(intent);
- }
- return super.onOptionsItemSelected(item);
- }
/**
* 连接状态的回调接口,连接成功时会调用onConnected()方法
*/
diff --git a/app/src/main/java/com/muqingbfq/login/cookie.java b/app/src/main/java/com/muqingbfq/login/cookie.java
deleted file mode 100644
index 346afd7..0000000
--- a/app/src/main/java/com/muqingbfq/login/cookie.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.muqingbfq.login;
-
-import android.os.Bundle;
-import android.view.View;
-import android.widget.ImageView;
-import android.widget.TextView;
-
-import androidx.annotation.Nullable;
-
-import com.muqingbfq.R;
-import com.muqingbfq.main;
-import com.muqingbfq.mq.FragmentActivity;
-import com.muqingbfq.mq.gj;
-import com.muqingbfq.mq.wl;
-
-import org.json.JSONObject;
-
-import java.util.Objects;
-
-public class cookie extends FragmentActivity {
-
- View view_a, view_b;
- TextView textView;
- ImageView imageView;
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_cookie);
- view_a = findViewById(R.id.view1);
- view_b = findViewById(R.id.view2);
- view_a.setVisibility(View.GONE);
-
- //view2 里面的控件
- textView = findViewById(R.id.textView);
- imageView = findViewById(R.id.imageView);
-// new erweima();
- }
-
-
-}
diff --git a/app/src/main/java/com/muqingbfq/mq/gj.java b/app/src/main/java/com/muqingbfq/mq/gj.java
index 14045a0..97ae831 100644
--- a/app/src/main/java/com/muqingbfq/mq/gj.java
+++ b/app/src/main/java/com/muqingbfq/mq/gj.java
@@ -1,9 +1,8 @@
package com.muqingbfq.mq;
+import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.Service;
-import android.app.usage.UsageStats;
-import android.app.usage.UsageStatsManager;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
@@ -83,7 +82,6 @@ public class gj {
/**
* 复制文字到剪切板
*
- * @param text
*/
public static void fz(Context context, String text) {
ClipboardManager systemService =
@@ -173,4 +171,12 @@ public class gj {
imm.hideSoftInputFromWindow(editText.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
+
+ public static int getztl(Context context) {
+ // 获得状态栏高度
+ @SuppressLint({"InternalInsetResource", "DiscouragedApi"}) int resourceId =
+ context.getResources().
+ getIdentifier("status_bar_height", "dimen", "android");
+ return context.getResources().getDimensionPixelSize(resourceId);
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/muqingbfq/view/Edit.java b/app/src/main/java/com/muqingbfq/view/Edit.java
new file mode 100644
index 0000000..f3dd018
--- /dev/null
+++ b/app/src/main/java/com/muqingbfq/view/Edit.java
@@ -0,0 +1,173 @@
+package com.muqingbfq.view;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.RippleDrawable;
+import android.text.Editable;
+import android.text.NoCopySpan;
+import android.util.AttributeSet;
+import android.util.TypedValue;
+import android.view.Gravity;
+import android.view.ViewGroup;
+import android.view.inputmethod.EditorInfo;
+import android.widget.EditText;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.core.content.ContextCompat;
+
+import com.muqingbfq.R;
+import com.muqingbfq.activity_search;
+
+public class Edit extends LinearLayout {
+ public Edit(@NonNull Context context) {
+ super(context);
+ initView();
+ }
+
+ AttributeSet attrs;
+ public Edit(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ this.attrs=attrs;
+ initView();
+ }
+
+ public Edit(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ this.attrs=attrs;
+ initView();
+ }
+
+ ImageView chahao;
+ public EditText editText;
+
+ private void initView() {
+ setGravity(Gravity.CENTER_VERTICAL);
+ setBackgroundResource(R.drawable.ui_editview);
+ setPadding(30, 10, 30, 10);
+ //构建编辑框
+ editText = new EditText(getContext());
+ editText.setHint("搜索");
+ editText.setSingleLine(true);
+ editText.setBackground(null);
+ editText.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
+ addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence var1, int var2, int var3, int var4) {
+
+ }
+
+ @Override
+ public void onTextChanged(CharSequence var1, int var2, int var3, int var4) {
+ iskong();
+ }
+
+ @Override
+ public void afterTextChanged(Editable var1) {
+
+ }
+ });
+
+ ImageView imageView = new ImageView(getContext());
+ imageView.setImageResource(R.drawable.sousuo);
+ addView(imageView, (int) TypedValue.applyDimension(TypedValue.
+ COMPLEX_UNIT_DIP, 26, getResources().getDisplayMetrics())
+ , (int) TypedValue.applyDimension(TypedValue.
+ COMPLEX_UNIT_DIP, 26, getResources().getDisplayMetrics()));
+
+ LayoutParams layoutParams = new LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.WRAP_CONTENT);
+ layoutParams.weight = 1;
+ layoutParams.gravity = Gravity.CENTER;
+ addView(editText, layoutParams);
+
+ chahao = new ImageView(getContext());
+ chahao.setImageResource(R.drawable.chahao);
+ Drawable rippleDrawable = new RippleDrawable(
+ ContextCompat.getColorStateList(getContext(),R.color.bj),
+ chahao.getBackground(),
+ null
+ );
+ chahao.setBackground(rippleDrawable);
+ chahao.setOnClickListener(view -> {
+ editText.setText("");
+ view.setVisibility(GONE);
+ });
+ addView(chahao, (int) TypedValue.applyDimension(TypedValue.
+ COMPLEX_UNIT_DIP, 26, getResources().getDisplayMetrics())
+ , (int) TypedValue.applyDimension(TypedValue.
+ COMPLEX_UNIT_DIP, 26, getResources().getDisplayMetrics()));
+ iskong();
+ if (attrs != null) {
+ TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Edit);
+ boolean isEnabled = a.getBoolean(R.styleable.Edit_Enabled, true);
+ if (!isEnabled) {
+ removeView(editText);
+ removeView(imageView);
+ removeView(chahao);
+ TextView textView = new TextView(getContext());
+ textView.setTextColor(editText.getHintTextColors());
+ textView.setText("搜索");
+
+ // 将 px 值转换为 sp
+ float v = TypedValue.applyDimension(
+ TypedValue.COMPLEX_UNIT_PX,
+ editText.getTextSize(),
+ getResources().getDisplayMetrics()
+ ) / getResources().getDisplayMetrics().scaledDensity;
+ textView.setTextSize(v);
+ setGravity(Gravity.CENTER);
+ addView(textView);
+ textView.setPadding(26, 26, 26, 26);
+ setOnClickListener(view ->
+ getContext().startActivity(new Intent(getContext(), activity_search.class)));
+ }
+ a.recycle();
+ }
+ }
+
+ public void addTextChangedListener(TextWatcher textWatcher) {
+ editText.addTextChangedListener(textWatcher);
+ }
+
+ public void iskong() {
+ if (editText.getText().toString().isEmpty()) {
+ chahao.setVisibility(GONE);
+ } else {
+ chahao.setVisibility(VISIBLE);
+ }
+ }
+
+ @Override
+ public void setLayoutParams(ViewGroup.LayoutParams params) {
+// params.width = ViewGroup.LayoutParams.MATCH_PARENT;
+ params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ super.setLayoutParams(params);
+// setGravity(Gravity.CENTER_VERTICAL);
+ }
+
+ public void setOnEditorActionListener(TextView.OnEditorActionListener a) {
+ editText.setOnEditorActionListener(a);
+ }
+
+ public void setText(String s) {
+ editText.setText(s);
+ }
+
+ public Editable getText() {
+ return editText.getText();
+ }
+
+ public interface TextWatcher extends NoCopySpan, android.text.TextWatcher {
+ void beforeTextChanged(CharSequence var1, int var2, int var3, int var4);
+
+ void onTextChanged(CharSequence var1, int var2, int var3, int var4);
+
+ void afterTextChanged(Editable var1);
+ }
+}
diff --git a/app/src/main/res/drawable/chahao.xml b/app/src/main/res/drawable/chahao.xml
new file mode 100644
index 0000000..72992ed
--- /dev/null
+++ b/app/src/main/res/drawable/chahao.xml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/app/src/main/res/drawable/sousuo.xml b/app/src/main/res/drawable/sousuo.xml
index 40c0dc2..5a0f98b 100644
--- a/app/src/main/res/drawable/sousuo.xml
+++ b/app/src/main/res/drawable/sousuo.xml
@@ -1,7 +1,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_gd.xml b/app/src/main/res/layout/activity_gd.xml
index 959eb9a..9b57c88 100644
--- a/app/src/main/res/layout/activity_gd.xml
+++ b/app/src/main/res/layout/activity_gd.xml
@@ -3,6 +3,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
+ android:fitsSystemWindows="true"
android:orientation="vertical">
@@ -19,31 +18,6 @@
android:layout_height="match_parent"
android:orientation="vertical">
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_llq.xml b/app/src/main/res/layout/activity_llq.xml
index a6f2800..013f54e 100644
--- a/app/src/main/res/layout/activity_llq.xml
+++ b/app/src/main/res/layout/activity_llq.xml
@@ -2,6 +2,7 @@
-
+ android:enabled="false"/>
-
+ android:layout_height="match_parent"
+ android:orientation="vertical">
-
+ android:layout_height="wrap_content">
-
-
-
+ android:minHeight="?attr/actionBarSize">
-
-
+ android:layout_margin="10dp"
+ app:Enabled="false"
+ app:layout_constraintTop_toTopOf="parent" />
+
+
-
+
-
+ android:layout_height="match_parent"
+ android:orientation="vertical">
-
+
+
-
-
+ android:layout_height="wrap_content"
+ app:cardUseCompatPadding="true"
+ app:contentPadding="6dp">
-
\ No newline at end of file
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_mp3.xml b/app/src/main/res/layout/fragment_mp3.xml
index aee763e..64df140 100644
--- a/app/src/main/res/layout/fragment_mp3.xml
+++ b/app/src/main/res/layout/fragment_mp3.xml
@@ -3,7 +3,8 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:orientation="vertical">
+ android:orientation="vertical"
+ android:fitsSystemWindows="true">
-
-
-
+
+
+ android:layout_height="wrap_content">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
+ app:cardUseCompatPadding="true"
+ app:layout_constraintTop_toTopOf="parent">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml
index 8a159a9..9dbbab9 100644
--- a/app/src/main/res/values-night/colors.xml
+++ b/app/src/main/res/values-night/colors.xml
@@ -1,5 +1,6 @@
+ #1C1B1F
@color/white
#CCC2DC
#2A2831
diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml
index 904ba51..c421c6d 100644
--- a/app/src/main/res/values-night/themes.xml
+++ b/app/src/main/res/values-night/themes.xml
@@ -7,5 +7,6 @@
<!– Secondary brand color. –>
- @color/text
-->
- false
+
\ No newline at end of file
diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml
index 6950329..3953429 100644
--- a/app/src/main/res/values/attrs.xml
+++ b/app/src/main/res/values/attrs.xml
@@ -28,4 +28,9 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index 769bca6..1d3f369 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -1,5 +1,6 @@
+ #FFFBFE
#0088FF
#FF6200EE
#FF3700B3
diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml
index 87da36e..7e27007 100644
--- a/app/src/main/res/values/themes.xml
+++ b/app/src/main/res/values/themes.xml
@@ -4,22 +4,28 @@
- true
-