|
|
@@ -1,17 +1,24 @@
|
|
|
package com.sheep.gamegroup.view.activity;
|
|
|
|
|
|
import android.app.AppOpsManager;
|
|
|
+import android.app.Notification;
|
|
|
import android.app.NotificationManager;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.content.pm.ApplicationInfo;
|
|
|
+import android.graphics.Color;
|
|
|
import android.net.Uri;
|
|
|
import android.os.Build;
|
|
|
import android.provider.Settings;
|
|
|
+import android.support.v4.app.NotificationCompat;
|
|
|
import android.text.TextUtils;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.widget.TextView;
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.lang.reflect.Method;
|
|
|
+import java.util.LinkedList;
|
|
|
|
|
|
/**
|
|
|
* Created by Administrator on 2017/8/25 0025.
|
|
|
@@ -149,4 +156,54 @@ public class NotificationsUtils {
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
context.startActivity(intent);
|
|
|
}
|
|
|
+
|
|
|
+ public static boolean isDarkNotificationTheme(Context context) {
|
|
|
+ return !isSimilarColor(Color.BLACK, getNotificationColor(context));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int getNotificationColor(Context context) {
|
|
|
+ NotificationCompat.Builder builder=new NotificationCompat.Builder(context);
|
|
|
+ Notification notification=builder.build();
|
|
|
+ int layoutId=notification.contentView.getLayoutId();
|
|
|
+ ViewGroup viewGroup= (ViewGroup) LayoutInflater.from(context).inflate(layoutId, null, false);
|
|
|
+ if (viewGroup.findViewById(android.R.id.title)!=null) {
|
|
|
+ return ((TextView) viewGroup.findViewById(android.R.id.title)).getCurrentTextColor();
|
|
|
+ }
|
|
|
+ return findColor(viewGroup);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static boolean isSimilarColor(int baseColor, int color) {
|
|
|
+ int simpleBaseColor=baseColor|0xff000000;
|
|
|
+ int simpleColor=color|0xff000000;
|
|
|
+ int baseRed=Color.red(simpleBaseColor)-Color.red(simpleColor);
|
|
|
+ int baseGreen=Color.green(simpleBaseColor)-Color.green(simpleColor);
|
|
|
+ int baseBlue=Color.blue(simpleBaseColor)-Color.blue(simpleColor);
|
|
|
+ double value=Math.sqrt(baseRed*baseRed+baseGreen*baseGreen+baseBlue*baseBlue);
|
|
|
+ if (value<180.0) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static int findColor(ViewGroup viewGroupSource) {
|
|
|
+ int color= Color.TRANSPARENT;
|
|
|
+ LinkedList<ViewGroup> viewGroups=new LinkedList<>();
|
|
|
+ viewGroups.add(viewGroupSource);
|
|
|
+ while (viewGroups.size()>0) {
|
|
|
+ ViewGroup viewGroup1=viewGroups.getFirst();
|
|
|
+ for (int i = 0; i < viewGroup1.getChildCount(); i++) {
|
|
|
+ if (viewGroup1.getChildAt(i) instanceof ViewGroup) {
|
|
|
+ viewGroups.add((ViewGroup) viewGroup1.getChildAt(i));
|
|
|
+ }
|
|
|
+ else if (viewGroup1.getChildAt(i) instanceof TextView) {
|
|
|
+ if (((TextView) viewGroup1.getChildAt(i)).getCurrentTextColor()!=-1) {
|
|
|
+ color=((TextView) viewGroup1.getChildAt(i)).getCurrentTextColor();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ viewGroups.remove(viewGroup1);
|
|
|
+ }
|
|
|
+ return color;
|
|
|
+ }
|
|
|
+
|
|
|
}
|