Commit 7a380a6c authored by jyx's avatar jyx

添加应用外弹出开关

parent 0b3c1526
......@@ -28,9 +28,11 @@ import com.mints.flowbox.keepalive.ScreenWatch;
import com.mints.flowbox.keepalive.WifiStateWatch;
import com.mints.flowbox.manager.CsjGroMoreManager;
import com.mints.flowbox.manager.MiitHelper;
import com.mints.flowbox.manager.TrackManager;
import com.mints.flowbox.manager.ad.OwManager;
import com.mints.flowbox.manager.ad.TzManager;
import com.mints.flowbox.manager.ad.WnManager;
import com.mints.flowbox.manager.wifi.WifiDataManager;
import com.mints.flowbox.net.LoanService;
import com.mints.flowbox.ui.activitys.keepalive.ApkActivity;
import com.mints.flowbox.ui.activitys.keepalive.BoostActivity;
......@@ -193,30 +195,32 @@ public class MintsApplication extends BaseApp {
// Toast.makeText(this, "测试:主进程重启成功", Toast.LENGTH_LONG).show();
// }
// 获取应用外开关
TrackManager.getInstance().getOuterAdConfig();
WifiStateWatch.getInstance(this).begin(new WifiStateWatch.WifiStateListener() {
@Override
public void onWifiOpen() {
// ToastUtils.show("--> 开启wifi <--");
// 应用在前台,则不展示
if (ForegroundOrBackground.isForeground2()) {
return;
}
// if (WifiDataManager.INSTANCE.getWifiOn()) {
showBoost();
// }
if (WifiDataManager.INSTANCE.getWifiOn()) {
// 跳转去wifi加速
showTimingActivity(TimingActivity.TIMING_TYPE_WIFI_BOOST);
}
}
@Override
public void onWifiClose() {
// ToastUtils.show("--> 关闭wifi <--");
// 应用在前台,则不展示
if (ForegroundOrBackground.isForeground2()) {
return;
}
// if (WifiDataManager.INSTANCE.getWifiOff()) {
showTimingActivity(TimingActivity.TIMING_TYPE_SPEED_TEST);
// }
if (WifiDataManager.INSTANCE.getWifiOff()) {
// 跳转网络测速
showTimingActivity(TimingActivity.TIMING_TYPE_SPEED_TEST);
}
}
});
......@@ -224,22 +228,12 @@ public class MintsApplication extends BaseApp {
ScreenWatch.getInstance(this).begin(new ScreenWatch.ScreenStateListener() {
@Override
public void onScreenOn() {
// ToastUtils.show("--> 亮屏 <--");
// if (ForegroundOrBackground.isForeground2() & !ScreenLockerUtils.INSTANCE.isOV()) {
// return;
// }
//
// LogUtil.d("亮屏");
//
// showScreen();
}
@Override
public void onScreenOff() {
// ToastUtils.show("--> 息屏 <--");
// 检测是否在前台及是否是oppo或vivo
// 检测应用是否在前台
if (ForegroundOrBackground.isForeground2()) {
return;
}
......@@ -259,26 +253,13 @@ public class MintsApplication extends BaseApp {
return;
}
showScreen();
if (WifiDataManager.INSTANCE.getLockOn()) {
showScreen();
}
}
@Override
public void onUserPresent() {
// ToastUtils.show("--> 解锁屏幕 <--");
if (ForegroundOrBackground.isForeground2() & !ScreenLockerUtils.INSTANCE.isOV()) {
return;
}
if (PhoneBrandUtils.isOppo() & ScreenLockerUtils.INSTANCE.isOppoScreenLockOpen(MintsApplication.getContext())) {
return;
}
if (PhoneBrandUtils.isVivo() & ScreenLockerUtils.INSTANCE.isVivoScreenLockOpen(MintsApplication.getContext())) {
return;
}
showScreen();
}
});
......@@ -286,8 +267,6 @@ public class MintsApplication extends BaseApp {
// HomeKeyWatch.getInstance(this).begin(new HomeKeyWatch.HomeKeyStateListener() {
// @Override
// public void onHOME_KEY() {
//// ToastUtils.show("--> 点击HOME键 <--");
//
// if (ForegroundOrBackground.isForeground2()) {
// return;
// }
......@@ -299,8 +278,6 @@ public class MintsApplication extends BaseApp {
//
// @Override
// public void onRECENT_APPS() {
//// ToastUtils.show("--> 最近任务列表 <--");
//
// if (ForegroundOrBackground.isForeground2()) {
// return;
// }
......@@ -312,11 +289,10 @@ public class MintsApplication extends BaseApp {
// });
// 监听电话状态
PhoneWatch.getInstance(this).begin(new PhoneWatch.PhoneStateListener() {
@Override
public void onIdle() {
// ToastUtils.show("--> 电话挂断 <--");
}
});
......@@ -324,26 +300,23 @@ public class MintsApplication extends BaseApp {
BatteryWatch.getInstance(this).begin(new BatteryWatch.BatteryStateListener() {
@Override
public void onCharging() {
// ToastUtils.show("--> 正在充电 <--");
if (ForegroundOrBackground.isForeground2()) {
return;
}
// if (WifiDataManager.INSTANCE.getBatteryOn()) {
showScreen();
// }
if (WifiDataManager.INSTANCE.getBatteryOn()) {
showScreen();
}
}
@Override
public void onUnCharging() {
// ToastUtils.show("--> 停止充电 <--");
if (ForegroundOrBackground.isForeground2()) {
return;
}
// if (WifiDataManager.INSTANCE.getBatteryOff()) {
showBoost();
// }
if (WifiDataManager.INSTANCE.getBatteryOff()) {
// 跳转省电
showTimingActivity(TimingActivity.TIMING_TYPE_SAVE_ELE);
}
}
});
......@@ -351,23 +324,32 @@ public class MintsApplication extends BaseApp {
PackageWatch.getInstance(this).begin(new PackageWatch.InstallStateListener() {
@Override
public void onAdded(String pkgName) {
showApk(0, pkgName);
// ToastUtils.show("--> APK安装 <--");
if (ForegroundOrBackground.isForeground2()) {
return;
}
if (WifiDataManager.INSTANCE.getInstallApk()) {
showApk(0, pkgName);
}
}
@Override
public void onReplaced(String pkgName) {
showApk(1, pkgName);
// ToastUtils.show("--> APK卸载 <--");
if (ForegroundOrBackground.isForeground2()) {
return;
}
if (WifiDataManager.INSTANCE.getUpdateApk()) {
showApk(0, pkgName);
}
}
@Override
public void onRemoved(String pkgName) {
showApk(2, pkgName);
// ToastUtils.show("--> APK移除 <--");
if (ForegroundOrBackground.isForeground2()) {
return;
}
if (WifiDataManager.INSTANCE.getUnInstallApk()) {
showApk(2, pkgName);
}
}
});
}
......
package com.mints.flowbox.keepalive;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import com.bytedance.msdk.adapter.util.WeakHandler;
......@@ -9,10 +8,9 @@ import com.mints.flowbox.MintsApplication;
import com.mints.flowbox.ad.express.ExpressManager;
import com.mints.flowbox.common.AppConfig;
import com.mints.flowbox.manager.TrackManager;
import com.mints.flowbox.ui.activitys.keepalive.BoostActivity;
import com.mints.flowbox.manager.wifi.WifiDataManager;
import com.mints.flowbox.ui.activitys.keepalive.TimingActivity;
import com.mints.flowbox.utils.ForegroundOrBackground;
import com.mints.flowbox.utils.LogUtil;
import com.mints.flowbox.utils.keepalive.IntentUtils;
/**
......@@ -24,9 +22,9 @@ public class AlarmManager implements WeakHandler.IHandler {
private static volatile AlarmManager _inst;
public static final int WIFI_MINTER = 3;//单位-分钟,wifi页重置
public static final int USER_ACTIVE_MINTER = 10;//单位-分钟,用户激活接口
public static final int APP_OUT_CLEAR_MINTER = 1;//单位-分钟,应用外清理
private static final int WIFI_MINTER = 3;//单位-分钟,wifi页重置
private static final int USER_ACTIVE_MINTER = 10;//单位-分钟,用户激活接口
private static int APP_OUT_TIMING_MINTER = 10;//单位-分钟,应用外清理
public static final long ONE_MINTER_Interval = 60 * 1000;//60秒
public static final long TEN_SECOND_Interval = 10 * 1000;//10秒
......@@ -74,8 +72,6 @@ public class AlarmManager implements WeakHandler.IHandler {
// 防止userTime超出Integer范围
if (userTime < 20) userTime++;
LogUtil.d("AAAAAAAAAA");
// 固定时间增长
exeActionForTime(curTime);
// 用户操作按时间增长
......@@ -93,15 +89,18 @@ public class AlarmManager implements WeakHandler.IHandler {
* @param userTime
*/
private void userActionForTime(int userTime) {
if (userTime % APP_OUT_CLEAR_MINTER == 0) {
if (userTime % APP_OUT_TIMING_MINTER == 0) {
// 应用在前台时,不弹出应用外广告
if (ForegroundOrBackground.isForeground2()) {
return;
}
if (WifiDataManager.INSTANCE.getTiming()) {
showTimingActivity();
}
this.resetUserActionTime();
showTimingActivity();
// // 预加载信息流
// ExpressManager.INSTANCE.loadAppOutExpress();
// //用户关闭界面后10分钟调用
......@@ -132,6 +131,7 @@ public class AlarmManager implements WeakHandler.IHandler {
} else if (curTime % USER_ACTIVE_MINTER == 0) {
//每10分钟调用 用户激活接口
TrackManager.getInstance().setMinsActive();
TrackManager.getInstance().getOuterAdConfig();
}
}
......@@ -139,6 +139,7 @@ public class AlarmManager implements WeakHandler.IHandler {
* 展示定时页面
*/
private void showTimingActivity() {
// 预加载信息流
ExpressManager.INSTANCE.loadAppOutExpress();
......@@ -153,6 +154,11 @@ public class AlarmManager implements WeakHandler.IHandler {
IntentUtils.startActivity(ForegroundOrBackground.getMain_activity(), intent);
}
public void setAppOutTimingMinter(int timingMinter) {
APP_OUT_TIMING_MINTER = timingMinter;
resetUserActionTime();
}
/**
* 重置用户操作时长
*/
......
......@@ -171,4 +171,10 @@ public class TrackManager {
trackPresenter.setMinsActive(vo);
}
}
public void getOuterAdConfig() {
if (trackPresenter != null) {
trackPresenter.getOuterAdConfig();
}
}
}
......@@ -2,7 +2,9 @@ package com.mints.flowbox.mvp.model
import java.io.Serializable
data class WifiActiveBean(val ouTofApplicationAdCount: Int = 10,
val time: Long = 0,
val ouTofApplicationAdMins: Int = 10
data class WifiActiveBean(
val ouTofApplicationAdCount: Int = 10,
val time: Long = 0,
val ouTofApplicationAdMins: Int = 10,
val outerConfigs: OutAppConfig? = null
) : Serializable
\ No newline at end of file
......@@ -16,6 +16,7 @@ import com.mints.flowbox.manager.UserWeight;
import com.mints.flowbox.manager.wifi.WifiDataManager;
import com.mints.flowbox.mvp.model.BaseResponse;
import com.mints.flowbox.mvp.model.CommonParamBean;
import com.mints.flowbox.mvp.model.OutAppConfig;
import com.mints.flowbox.mvp.model.ServerAdBean;
import com.mints.flowbox.mvp.model.WifiActiveBean;
import com.mints.library.net.neterror.BaseSubscriber;
......@@ -88,9 +89,9 @@ public class TrackPresenter extends BaseTrackPresenter {
try {
if (baseResponse.getStatus() == 200) {
WifiActiveBean data = baseResponse.getData();
if (data != null) {
if (data != null && data.getOuterConfigs() != null) {
// 本地标记未赋值时
WifiDataManager.INSTANCE.getNewDay(data.getTime());
WifiDataManager.INSTANCE.getNewDay(data.getTime(), data.getOuterConfigs());
}
}
} catch (Exception e) {
......@@ -525,4 +526,30 @@ public class TrackPresenter extends BaseTrackPresenter {
});
}
public void getOuterAdConfig() {
AppHttpManager.getInstance(loanApplication)
.call(loanService.getOuterAdConfig(),
new BaseSubscriber<BaseResponse<OutAppConfig>>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(BaseResponse<OutAppConfig> baseResponse) {
try {
if (baseResponse.getStatus() == 200) {
OutAppConfig data = baseResponse.getData();
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
......@@ -20,6 +20,7 @@ import com.mints.flowbox.mvp.model.MainVideoMsgBean;
import com.mints.flowbox.mvp.model.MealBean;
import com.mints.flowbox.mvp.model.MorningClockBean;
import com.mints.flowbox.mvp.model.MyInfo;
import com.mints.flowbox.mvp.model.OutAppConfig;
import com.mints.flowbox.mvp.model.ServerAdBean;
import com.mints.flowbox.mvp.model.SignRedbagsBean;
import com.mints.flowbox.mvp.model.TaskCpdBean;
......@@ -467,11 +468,17 @@ public interface LoanService {
Observable<BaseResponse<JsonObject>> getRankMsg();
/**
* 提现排名
* 保活间隔上送后台
*/
@POST("na/setMinsActive")
Observable<BaseResponse<WifiActiveBean>> setMinsActive(@Body Map<String, Object> vo);
/**
* 获取应用外广告配置
*/
@POST("common/getOuterAdConfig")
Observable<BaseResponse<OutAppConfig>> getOuterAdConfig();
/**
* 默认http工厂
*/
......
......@@ -283,13 +283,13 @@ class CleanActivity : BaseActivity(), View.OnClickListener {
val bundle = Bundle()
if (scanMax == 1) {
// AppConfig.isCanBoost = false
AppConfig.isCanBoost = false
bundle.putString(
IncreasespeedActivity.INCREASE_TYPE,
IncreasespeedActivity.INCREASE_BOOST
)
} else {
// AppConfig.isCanClean = false
AppConfig.isCanClean = false
bundle.putString(
IncreasespeedActivity.INCREASE_TYPE,
IncreasespeedActivity.INCREASE_CLEAN
......
......@@ -95,17 +95,17 @@ class IncreasespeedActivity : BaseActivity(), View.OnClickListener {
}
})
// if (mIncreaseType == INCREASE_BOOST && AppConfig.isCanBoost) {
if (mIncreaseType == INCREASE_BOOST) {
startTimer()
// } else if (mIncreaseType == INCREASE_SAVE_ELECTRICITY && AppConfig.isCanSaveBattery) {
} else if (mIncreaseType == INCREASE_SAVE_ELECTRICITY) {
if (mIncreaseType == INCREASE_BOOST && AppConfig.isCanBoost) {
// if (mIncreaseType == INCREASE_BOOST) {
startTimer()
} else if (mIncreaseType == INCREASE_SAVE_ELECTRICITY && AppConfig.isCanSaveBattery) {
// } else if (mIncreaseType == INCREASE_SAVE_ELECTRICITY) {
mTimerMax = 11
// } else if (mIncreaseType == INCREASE_CLEAN && AppConfig.isCanClean) {
} else if (mIncreaseType == INCREASE_CLEAN) {
startTimer()
} else if (mIncreaseType == INCREASE_CLEAN && AppConfig.isCanClean) {
// } else if (mIncreaseType == INCREASE_CLEAN) {
mTimerMax = 14
startTimer()
} else {
initView()
......
package com.mints.flowbox.ui.activitys.base
import android.app.KeyguardManager
import android.content.Context
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.util.AttributeSet
import android.view.View
import android.view.WindowManager
import com.mints.flowbox.R
import com.mints.flowbox.utils.keepalive.ScreenLockerUtils
import com.mints.library.base.BaseSwipeBackCompatActivity
import com.mints.library.net.netstatus.NetUtils
......@@ -24,17 +18,18 @@ abstract class OutAppActivity : BaseSwipeBackCompatActivity() {
setShowWhenLocked(true)
// 强制亮屏
// setTurnScreenOn(true)
val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
keyguardManager.requestDismissKeyguard(this, null)
// val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
// keyguardManager.requestDismissKeyguard(this, null)
} else {
this.window.addFlags(
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD or
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
)
}
ScreenLockerUtils.updateWindowFlags(this.window.decorView)
this.window.addFlags(
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD or
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
)
// 设置锁屏页全屏
ScreenLockerUtils.makeLockWindowFullScreen(this, this.window.attributes, true)
ScreenLockerUtils.updateWindowFlags(this.window.decorView)
ScreenLockerUtils.makeLockWindowFullScreen(this, this.window.attributes, false)
super.onCreate(savedInstanceState)
}
......
......@@ -20,7 +20,6 @@ import kotlinx.android.synthetic.main.activity_apk.btnClean
import kotlinx.android.synthetic.main.activity_apk.fl_ad
import kotlinx.android.synthetic.main.activity_apk.tvInfo
import kotlinx.android.synthetic.main.activity_boost.iv_close
import kotlinx.android.synthetic.main.activity_timing.*
import kotlin.random.Random
/**
......@@ -113,7 +112,7 @@ class ApkActivity : BaseActivity() {
initExpress()
btnClean.postDelayed({
rope = YoYo.with(Techniques.Pulse).duration(1000).repeat(6).playOn(btnClean)
rope = YoYo.with(Techniques.Pulse).duration(1000).repeat(10).playOn(btnClean)
}, 200)
}
......
......@@ -3,7 +3,9 @@ package com.mints.flowbox.ui.activitys.keepalive
import android.app.WallpaperManager
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.os.*
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.View
import com.mints.flowbox.R
import com.mints.flowbox.ad.express.ExpressManager
......@@ -11,10 +13,12 @@ import com.mints.flowbox.common.Constant
import com.mints.flowbox.ui.activitys.CleanActivity
import com.mints.flowbox.ui.activitys.IncreasespeedActivity
import com.mints.flowbox.ui.activitys.base.OutAppActivity
import com.mints.flowbox.utils.TimeThread
import com.mints.flowbox.utils.TimeRender
import com.mints.flowbox.utils.ToolUtil
import com.mints.flowbox.utils.keepalive.ScreenLockerUtils
import com.mints.library.utils.nodoubleclick.AntiShake
import kotlinx.android.synthetic.main.activity_screen.*
import java.util.*
class ScreenActivity : OutAppActivity(), View.OnClickListener {
......@@ -38,8 +42,8 @@ class ScreenActivity : OutAppActivity(), View.OnClickListener {
)
}, 500)
val thread = TimeThread(tvDate, tvTime)
thread.start()
// val thread = TimeThread(tvDate, tvTime)
// thread.start()
tvBoost.setOnClickListener(this)
tvClean.setOnClickListener(this)
......@@ -48,9 +52,20 @@ class ScreenActivity : OutAppActivity(), View.OnClickListener {
override fun onResume() {
super.onResume()
resetTime()
initExpress()
}
private fun resetTime() {
val date = Date()
val monthDay = TimeRender.formatDate(date, TimeRender.DEFAULT_FORMAT_MONTH_DAY)
val time = TimeRender.formatDate(date, TimeRender.DEFAULT_FORMAT_MINTER)
tvDate.text = TimeRender.getWeek() + " " + monthDay
tvTime.text = time
}
override fun onClick(v: View?) {
if (AntiShake.check(v?.id)) return
......
......@@ -78,9 +78,7 @@ class TimingActivity : BaseActivity() {
btnClean.text = "立即清理"
}
TIMING_TYPE_SAVE_ELE -> { // 省电
if (AppConfig.fakeSaveBatteryCount == 0) {
AppConfig.fakeSaveBatteryCount = 1 + Random.nextInt(8)
}
AppConfig.fakeSaveBatteryCount = 1 + Random.nextInt(8)
tvInfo.text = SpanUtils()
.append("检测到")
......@@ -173,7 +171,7 @@ class TimingActivity : BaseActivity() {
initExpress()
btnClean.postDelayed({
rope = YoYo.with(Techniques.Pulse).duration(1000).repeat(6).playOn(btnClean)
rope = YoYo.with(Techniques.Pulse).duration(1000).repeat(10).playOn(btnClean)
}, 200)
}
......
......@@ -30,6 +30,7 @@ import com.mints.flowbox.ui.activitys.*
import com.mints.flowbox.ui.adapter.MainWifiAdapter
import com.mints.flowbox.ui.adapter.listener.OnItemClickListener
import com.mints.flowbox.ui.fragment.base.BaseFragment
import com.mints.flowbox.ui.widgets.RecyItemDecoration
import com.mints.flowbox.ui.widgets.dialog.DialogListener
import com.mints.flowbox.ui.widgets.dialog.DialogUtils
import com.mints.flowbox.ui.widgets.dialog.WifiConnectDialog
......@@ -239,12 +240,11 @@ class WifiFragment : BaseFragment(), View.OnClickListener, OnItemClickListener,
.setForegroundColor(ContextCompat.getColor(mContext, R.color.color_4BB93F))
.setFontSize(BubbleUtils.sp2px(10))
.create()
AppConfig.isCanBoost = true
}
if (AppConfig.isCanSaveBattery) {
if (AppConfig.fakeSaveBatteryCount == 0) {
AppConfig.fakeSaveBatteryCount = 1 + Random.nextInt(8)
}
AppConfig.fakeSaveBatteryCount = 1 + Random.nextInt(8)
tv_save_battery.text = SpanUtils()
.append("超强省电\n")
.append("${AppConfig.fakeSaveBatteryCount}个")
......@@ -264,6 +264,7 @@ class WifiFragment : BaseFragment(), View.OnClickListener, OnItemClickListener,
.setForegroundColor(ContextCompat.getColor(mContext, R.color.color_4BB93F))
.setFontSize(BubbleUtils.sp2px(10))
.create()
AppConfig.isCanSaveBattery = true
}
if (AppConfig.isCanClean) {
......@@ -286,6 +287,7 @@ class WifiFragment : BaseFragment(), View.OnClickListener, OnItemClickListener,
.setForegroundColor(ContextCompat.getColor(mContext, R.color.color_4BB93F))
.setFontSize(BubbleUtils.sp2px(10))
.create()
AppConfig.isCanSaveBattery = true
}
}
......@@ -296,7 +298,7 @@ class WifiFragment : BaseFragment(), View.OnClickListener, OnItemClickListener,
}
private fun initRecy() {
recy_wifi.addItemDecoration(DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL))
recy_wifi.addItemDecoration(RecyItemDecoration(mContext, DividerItemDecoration.VERTICAL))
mMainWifiAdapter = MainWifiAdapter(mContext, mWifiList)
recy_wifi.adapter = mMainWifiAdapter
mMainWifiAdapter?.setOnItemClickListener(this)
......
package com.mints.flowbox.ui.widgets;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.View;
import androidx.recyclerview.widget.RecyclerView;
public class RecyItemDecoration extends RecyclerView.ItemDecoration {
public static final int HORIZONTAL = 0;
public static final int VERTICAL = 1;
private static final String TAG = "DividerItem";
private static final int[] ATTRS = new int[]{16843284};
private Drawable mDivider;
private int mOrientation;
private final Rect mBounds = new Rect();
public RecyItemDecoration(Context context, int orientation) {
TypedArray a = context.obtainStyledAttributes(ATTRS);
this.mDivider = a.getDrawable(0);
if (this.mDivider == null) {
Log.w("DividerItem", "@android:attr/listDivider was not set in the theme used for this DividerItemDecoration. Please set that attribute all call setDrawable()");
}
a.recycle();
this.setOrientation(orientation);
}
public void setOrientation(int orientation) {
if (orientation != 0 && orientation != 1) {
throw new IllegalArgumentException("Invalid orientation. It should be either HORIZONTAL or VERTICAL");
} else {
this.mOrientation = orientation;
}
}
public void setDrawable(Drawable drawable) {
if (drawable == null) {
throw new IllegalArgumentException("Drawable cannot be null.");
} else {
this.mDivider = drawable;
}
}
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
if (parent.getLayoutManager() != null && this.mDivider != null) {
if (this.mOrientation == 1) {
this.drawVertical(c, parent);
} else {
this.drawHorizontal(c, parent);
}
}
}
private void drawVertical(Canvas canvas, RecyclerView parent) {
canvas.save();
int left;
int right;
if (parent.getClipToPadding()) {
left = parent.getPaddingLeft();
right = parent.getWidth() - parent.getPaddingRight();
canvas.clipRect(left, parent.getPaddingTop(), right, parent.getHeight() - parent.getPaddingBottom());
} else {
left = 0;
right = parent.getWidth();
}
int childCount = parent.getChildCount();
//当最后一个子项的时候去除下划线
for (int i = 0; i < childCount - 1; ++i) {
View child = parent.getChildAt(i);
parent.getDecoratedBoundsWithMargins(child, this.mBounds);
int bottom = this.mBounds.bottom + Math.round(child.getTranslationY());
int top = bottom - this.mDivider.getIntrinsicHeight();
this.mDivider.setBounds(left, top, right, bottom);
this.mDivider.draw(canvas);
}
canvas.restore();
}
private void drawHorizontal(Canvas canvas, RecyclerView parent) {
canvas.save();
int top;
int bottom;
if (parent.getClipToPadding()) {
top = parent.getPaddingTop();
bottom = parent.getHeight() - parent.getPaddingBottom();
canvas.clipRect(parent.getPaddingLeft(), top, parent.getWidth() - parent.getPaddingRight(), bottom);
} else {
top = 0;
bottom = parent.getHeight();
}
int childCount = parent.getChildCount();
for (int i = 0; i < childCount; ++i) {
View child = parent.getChildAt(i);
parent.getLayoutManager().getDecoratedBoundsWithMargins(child, this.mBounds);
int right = this.mBounds.right + Math.round(child.getTranslationX());
int left = right - this.mDivider.getIntrinsicWidth();
this.mDivider.setBounds(left, top, right, bottom);
this.mDivider.draw(canvas);
}
canvas.restore();
}
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
if (this.mDivider == null) {
outRect.set(0, 0, 0, 0);
} else {
if (this.mOrientation == 1) {
outRect.set(0, 0, 0, this.mDivider.getIntrinsicHeight());
} else {
outRect.set(0, 0, this.mDivider.getIntrinsicWidth(), 0);
}
}
}
}
......@@ -23,6 +23,7 @@ public class TimeRender {
public static String DEFAULT_FORMAT_MONTH_DAY = "MM月dd日";
public static String DEFAULT_FORMAT_LINE = "yyyy/MM/dd";
public static String DEFAULT_FORMAT_TIME = "HH:mm:ss";
public static String DEFAULT_FORMAT_MINTER = "HH:mm";
/**
* 年月日时分秒加横杠
......
......@@ -20,6 +20,7 @@ private const val TAG = "screenlocker.utils"
@Suppress("DEPRECATION")
object ScreenLockerUtils {
fun canShowScreenLocker(context: Context): Boolean {
try {
val pm = context.getSystemService(Context.POWER_SERVICE) as PowerManager
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment