Kaynağa Gözat

download notification bug

billyyoyo 6 yıl önce
ebeveyn
işleme
9b137a2415

+ 3 - 1
app/src/main/java/com/sheep/gamegroup/util/ViewUtil.java

@@ -1717,6 +1717,7 @@ public class ViewUtil {
             ImageView ad_iv = view.findViewById(R.id.ad_iv);
             VideoView ad_video_view = view.findViewById(R.id.ad_video_view);
             TextView ad_msg = view.findViewById(R.id.ad_msg);
+            TextView ad_flag = view.findViewById(R.id.ad_flag);
 //            final TextView ad_skip = view.findViewById(R.id.ad_skip);
             View dialog_rl = view.findViewById(R.id.dialog_rl);
 
@@ -1792,6 +1793,7 @@ public class ViewUtil {
                     EventBus.getDefault().post(BigEvent.get().setEventTypes(EventTypes.GUIDE_NEXT));
                 }
             });
+            setVisibility(ad_flag, advertising.getUser_type() == 2);
             if (TextUtils.isEmpty(advertising.getName())) {
                 ViewUtil.setVisibility(ad_msg, false);
                 //3.4.7添加 -- 不显示标题栏,不显示背景 start
@@ -2010,7 +2012,7 @@ public class ViewUtil {
         }
     }
 
-    public static void setGif(ImageView imageView, int resId){
+    public static void setGif(ImageView imageView, int resId) {
         GlideApp.with(imageView)
                 .asGif()
                 .load(resId)

+ 49 - 23
app/src/main/java/com/sheep/gamegroup/view/activity/NotificationsUtils.java

@@ -14,8 +14,11 @@ import android.support.v4.app.NotificationCompat;
 import android.text.TextUtils;
 import android.view.LayoutInflater;
 import android.view.ViewGroup;
+import android.widget.RemoteViews;
 import android.widget.TextView;
 
+import com.sheep.jiuyan.samllsheep.R;
+
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.util.LinkedList;
@@ -27,8 +30,10 @@ import java.util.LinkedList;
 public class NotificationsUtils {
     private static final String CHECK_OP_NO_THROW = "checkOpNoThrow";
     private static final String OP_POST_NOTIFICATION = "OP_POST_NOTIFICATION";
+
     /**
      * 8.0以上获取t通知栏状态
+     *
      * @param context
      * @return
      */
@@ -49,6 +54,7 @@ public class NotificationsUtils {
             return true;
         }
     }
+
     public static boolean isNotificationEnabled(Context context) {
         boolean Enabled;
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@@ -58,7 +64,7 @@ public class NotificationsUtils {
                 return true;
             }
         }
-        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
             AppOpsManager mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
             ApplicationInfo appInfo = context.getApplicationInfo();
             String pkg = context.getApplicationContext().getPackageName();
@@ -78,7 +84,7 @@ public class NotificationsUtils {
                 e.printStackTrace();
                 Enabled = false;
             }
-        }else{
+        } else {
             Enabled = true;
         }
 
@@ -91,7 +97,7 @@ public class NotificationsUtils {
     public static void goToNotificationSetting(Context context) {
         Intent intent = new Intent();
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
-            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 && TextUtils.equals(android.os.Build.BRAND, "360")){// 360 8.1.0 不能跳转成功,直接跳转应用详情设置界面
+            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 && TextUtils.equals(android.os.Build.BRAND, "360")) {// 360 8.1.0 不能跳转成功,直接跳转应用详情设置界面
                 intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                 intent.setData(Uri.fromParts("package", context.getPackageName(), null));
             } else {
@@ -112,6 +118,7 @@ public class NotificationsUtils {
         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         context.startActivity(intent);
     }
+
     /**
      * 打开允许通知的设置页
      */
@@ -122,6 +129,7 @@ public class NotificationsUtils {
         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         context.startActivity(intent);
     }
+
     /**
      * 打开允许通知的设置页
      */
@@ -133,6 +141,7 @@ public class NotificationsUtils {
         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         context.startActivity(intent);
     }
+
     /**
      * 打开允许通知的设置页
      */
@@ -145,6 +154,7 @@ public class NotificationsUtils {
         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         context.startActivity(intent);
     }
+
     /**
      * 打开允许通知的设置页
      */
@@ -162,42 +172,58 @@ public class NotificationsUtils {
     }
 
     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) {
+        RemoteViews view = buildFakeRemoteViews(context);
+        int layoutId = view.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 RemoteViews buildFakeRemoteViews(Context context) {
+        Notification.Builder builder;
+        builder = new Notification.Builder(context);
+        builder.setContentTitle("1")
+                .setContentText("1")
+                .setTicker("fackTicker");
+        RemoteViews remoteViews = null;
+        if (builder != null) {
+            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+                remoteViews = builder.createContentView();
+            } else {
+                Notification notification = builder.getNotification();
+                remoteViews = notification.contentView;
+            }
+        }
+        return remoteViews;
+    }
+
     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) {
+        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<>();
+        int color = Color.TRANSPARENT;
+        LinkedList<ViewGroup> viewGroups = new LinkedList<>();
         viewGroups.add(viewGroupSource);
-        while (viewGroups.size()>0) {
-            ViewGroup viewGroup1=viewGroups.getFirst();
+        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();
+                } else if (viewGroup1.getChildAt(i) instanceof TextView) {
+                    if (((TextView) viewGroup1.getChildAt(i)).getCurrentTextColor() != -1) {
+                        color = ((TextView) viewGroup1.getChildAt(i)).getCurrentTextColor();
                     }
                 }
             }

+ 18 - 9
app/src/main/java/com/sheep/gamegroup/view/fragment/BaseListFragment5.java

@@ -30,6 +30,7 @@ import java.util.List;
 import butterknife.BindView;
 import io.reactivex.Observable;
 import io.reactivex.android.schedulers.AndroidSchedulers;
+import io.reactivex.functions.Action;
 import io.reactivex.schedulers.Schedulers;
 import rx.functions.Action1;
 
@@ -173,15 +174,20 @@ public abstract class BaseListFragment5<T> extends BaseFragment implements IRefr
                     @Override
                     public void onNext(BaseMessage baseMessage) {
                         lastMessage = baseMessage;
-                        boolean isNewData = DataUtil.getInstance().isNewData(urlKey);
-                        if (isNewData || !isFirstGetACache()) {
-                            if (isFirstGetACache())
-                                ListUtil.removeAll(list, lastCacheList);
-                            List<T> newList = baseMessage.getDatas(getTClass());
-                            loadList(newList);
-                        } else {
-                            notifyDataSetChanged();
-                        }
+                        pluginLoadData(new Action1() {
+                            @Override
+                            public void call(Object o) {
+                                boolean isNewData = DataUtil.getInstance().isNewData(urlKey);
+                                if (isNewData || !isFirstGetACache()) {
+                                    if (isFirstGetACache())
+                                        ListUtil.removeAll(list, lastCacheList);
+                                    List<T> newList = baseMessage.getDatas(getTClass());
+                                    loadList(newList);
+                                } else {
+                                    notifyDataSetChanged();
+                                }
+                            }
+                        });
                     }
 
                     @Override
@@ -282,6 +288,9 @@ public abstract class BaseListFragment5<T> extends BaseFragment implements IRefr
         }
     }
 
+    public void pluginLoadData(Action1 action){
+        action.call(null);
+    }
 
     private boolean noMore = false;
 

+ 13 - 2
app/src/main/java/com/sheep/gamegroup/view/fragment/FgtFindChild.java

@@ -50,6 +50,7 @@ import java.util.Locale;
 import java.util.Map;
 
 import io.reactivex.Observable;
+import rx.functions.Action1;
 
 import static android.content.Intent.ACTION_PACKAGE_ADDED;
 import static android.content.Intent.ACTION_PACKAGE_REMOVED;
@@ -242,6 +243,16 @@ public class FgtFindChild extends BaseListFragment5<Article> {
     }
 
     @Override
+    public void pluginLoadData(Action1 action){
+        CommonUtil.getInstance().refreshAds(SheepAd.FORM_NEWS, (ret, list) -> {
+            if (ret) {
+                ads = list;
+            }
+            action.call(null);
+        });
+    }
+
+    @Override
     public void onCreate(@Nullable Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         Bundle bundle = getArguments();
@@ -449,8 +460,8 @@ public class FgtFindChild extends BaseListFragment5<Article> {
         @Override
         public void convert(final ViewHolder holder, final Article item) {
             View rootConvertView = holder.itemView;
-            TextView find_item_name = (TextView) rootConvertView.findViewById(R.id.find_item_name);
-            ImageView find_item_iv = (ImageView) rootConvertView.findViewById(R.id.find_item_iv);
+            TextView find_item_name = rootConvertView.findViewById(R.id.find_item_name);
+            ImageView find_item_iv = rootConvertView.findViewById(R.id.find_item_iv);
             View find_item_placement = rootConvertView.findViewById(R.id.find_item_placement);
             ViewUtil.setVisibility(find_item_placement, item.getType() == -2);
             ViewUtil.setText(find_item_name, item.getTitle());

+ 3 - 3
app/src/main/java/com/sheep/gamegroup/view/fragment/FgtPersonalCenter.java

@@ -525,9 +525,9 @@ public class FgtPersonalCenter extends BaseFragment {
             R.id.account_task_layout, R.id.proxy_service_layout, R.id.feedbook_layout,
             R.id.recommend_friend_layout, R.id.faq_layout, R.id.fgt_pc_item_gift_ll,
             R.id.version_layout, R.id.order_layout, R.id.proxy_game_account_layout,
-            R.id.audit_activity_cl, R.id.audit_success_cl, R.id.audit_failed_cl,R.id.fgt_person_center_cart,
+            R.id.audit_activity_cl, R.id.audit_success_cl, R.id.audit_failed_cl, R.id.fgt_person_center_cart,
             R.id.iv_redpackage, R.id.fgt_person_center_my_focus, R.id.fgt_pc_item_vip_ll,
-            R.id.voucher_layout, R.id.my_pet_layout, R.id.my_card_layout, R.id.be_vip_btn,
+            R.id.voucher_layout, R.id.my_pet_layout, R.id.my_card_layout, R.id.vip_layout,
             R.id.login_name_tv, R.id.edit_nickname_view, R.id.my_game_layout, R.id.shop_assist_layout
     })
     public void onViewClicked(View view) {
@@ -569,7 +569,7 @@ public class FgtPersonalCenter extends BaseFragment {
                 Jump2View.getInstance().goWeb(activity, Config.getUrlByPath(Config.PATH_MY_CARD), "我的卡包");
                 break;
             case R.id.fgt_pc_item_vip_ll://VIP
-            case R.id.be_vip_btn://VIP
+            case R.id.vip_layout://VIP
                 Jump2View.getInstance().gotoVip(activity);
                 break;
             case R.id.personalcenter_item_price_ic://我的资产

+ 7 - 2
app/src/main/java/com/sheep/jiuyan/samllsheep/service/DownloadService.java

@@ -284,14 +284,14 @@ public class DownloadService extends Service {
                 if (serverMd5.length() != 32) {
                     return;
                 }
-//                if (!clientMd5.equals(serverMd5)) {
+                if (!clientMd5.equals(serverMd5)) {
                     CommonUtil.getInstance().statGameDownloadError(
                             info.getMGameID() + "",
                             task.getRedirectLocation(),
                             getCdbIp(task.getRedirectLocation()),
                             clientMd5,
                             serverMd5);
-//                }
+                }
             } catch (Exception e) {
                 e.printStackTrace();
             } catch (OutOfMemoryError e) {
@@ -546,6 +546,8 @@ public class DownloadService extends Service {
                 NotificationChannel mChannel = new NotificationChannel(channelId, name, NotificationManager.IMPORTANCE_HIGH);
                 mChannel.enableVibration(false);
                 mChannel.enableLights(false);
+                mChannel.setVibrationPattern(new long[]{0});
+                mChannel.setSound(null, null);
                 notificationManager.createNotificationChannel(mChannel);
                 notification = new NotificationCompat.Builder(SheepApp.getInstance(), channelId)
                         .setCustomContentView(view)
@@ -560,6 +562,9 @@ public class DownloadService extends Service {
                         .setContentTitle(SheepApp.getInstance().getString(R.string.app_name))
                         .setContentText("下载中")
                         .setSmallIcon(R.mipmap.ic_launcher)
+                        .setDefaults(NotificationCompat.FLAG_ONLY_ALERT_ONCE)
+                        .setVibrate(new long[]{0})
+                        .setSound(null)
                         .setOngoing(true);
                 notification = notificationBuilder.build();
             }

+ 6 - 6
app/src/main/res/layout/dialog_half_screen_ad.xml

@@ -22,21 +22,21 @@
             android:id="@+id/ad_video_view"
             android:layout_width="match_parent"
             android:layout_height="300dp" />
+
         <TextView
+            android:id="@+id/ad_flag"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_alignParentEnd="true"
-            android:layout_alignParentTop="true"
             android:layout_margin="@dimen/content_padding_10"
-            android:background="@drawable/shape_ash_solid_rectangle_small"
+            android:background="#50000000"
             android:paddingBottom="2dp"
             android:paddingEnd="@dimen/content_padding_15"
             android:paddingStart="@dimen/content_padding_15"
             android:paddingTop="2dp"
-            android:text="跳过"
-            android:textColor="#918F8F"
-            android:visibility="gone"
-            android:textSize="14sp" />
+            android:text="广告"
+            android:textColor="#ffffff"
+            android:textSize="12sp" />
     </RelativeLayout>
 
     <TextView

+ 2 - 1
app/src/main/res/layout/find_item_ad.xml

@@ -51,6 +51,7 @@
         android:layout_height="120dp"
         android:layout_marginLeft="16dp"
         android:layout_marginTop="4dp"
+        android:layout_marginBottom="4dp"
         android:layout_marginRight="16dp"
         android:adjustViewBounds="true"
         android:scaleType="centerCrop"
@@ -58,6 +59,6 @@
 
     <View
         android:layout_width="match_parent"
-        android:layout_height="8dp"
+        android:layout_height="0.5dp"
         android:background="@color/gray_F0F0F0" />
 </LinearLayout>