GrayManager.java
4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package com.wd.common.utils;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.text.TextUtils;
import android.view.View;
import com.wd.foundation.bean.response.MourningModelBean;
import java.util.List;
/**
* 国殇模式下的工具
*
* @version 1.0.0
* @description:
* @author: liyubing
* @date :2023/3/28 9:41
*/
public class GrayManager {
private static GrayManager mInstance;
// 添加灰色蒙层
private Paint mGrayPaint;
private ColorMatrix mGrayMatrix;
// 清理灰色蒙层
private Paint cGrayPaint;
// 国殇总开关
public boolean switchOpen;
// 所有频道都开启国殇
public boolean selectAll = false;
// tab 新闻中国殇 频道id
public List<String> newsChannelList;
// tab 视频中国殇 频道id
public List<String> videoChannelList;
// tab 人民号 中国殇 频道id
public List<String> rmhList;
// tab 服务中国殇 频道id
public List<String> serverList;
public static GrayManager getInstance() {
if (mInstance == null) {
synchronized (GrayManager.class) {
if (mInstance == null) {
mInstance = new GrayManager();
}
}
}
return mInstance;
}
//灰色蒙层初始化
public void init() {
mGrayMatrix = new ColorMatrix();
mGrayPaint = new Paint();
mGrayMatrix.setSaturation(0);
mGrayPaint.setColorFilter(new ColorMatrixColorFilter(mGrayMatrix));
}
//硬件加速置灰方
public void setLayerGrayType(View view) {
if (mGrayMatrix == null && mGrayPaint == null) {
init();
}
view.setLayerType(View.LAYER_TYPE_HARDWARE, mGrayPaint);
}
/**
* 清理蒙层
*
* @param view
*/
public void clearLayerGray(View view) {
if(cGrayPaint == null){
ColorMatrix cGrayMatrix = new ColorMatrix();
cGrayPaint = new Paint();
cGrayPaint.setColorFilter(new ColorMatrixColorFilter(cGrayMatrix));
}
view.setLayerType(View.LAYER_TYPE_HARDWARE, cGrayPaint);
}
/**
* 记录底部导航栏需要处理频道
*
* @param modelBean
*/
public void saveChannelList(MourningModelBean modelBean) {
// 新闻 频道
List<String> navNewslList = modelBean.getNewsList();
if (navNewslList != null && navNewslList.size() > 0) {
newsChannelList = navNewslList;
} else {
newsChannelList = null;
}
// 视频 频道
List<String> navVideoList = modelBean.getVideoList();
if (navVideoList != null && navVideoList.size() > 0) {
videoChannelList = navVideoList;
} else {
videoChannelList = null;
}
// 人民号 频道
List<String> navBrannList = modelBean.getRmhList();
if (navBrannList != null && navBrannList.size() > 0) {
rmhList = navBrannList;
} else {
rmhList = null;
}
// 服务 频道
List<String> navSectionList = modelBean.getServerList();
if (navSectionList != null && navSectionList.size() > 0) {
serverList = navSectionList;
} else {
serverList = null;
}
}
/**
* 清理数据
*/
public void clearData() {
newsChannelList = null;
videoChannelList = null;
rmhList = null;
serverList = null;
}
/**
* 检测当前页面所在频道是否需要开启国殇模式
*
* @param channelId
* @param channelList
* @return
*/
public boolean checkChannelHaveGrayView(String channelId, List<String> channelList) {
if(selectAll){
return true;
}
boolean open = false;
if (switchOpen && channelList != null && channelList.size() > 0 && !TextUtils.isEmpty(channelId)) {
for (String a : channelList) {
if (channelId.equals(a)) {
open = true;
break;
}
}
}
return open;
}
}