Commit 228085c2 authored by mengcuiguang's avatar mengcuiguang

删除体外

parent 6dd0e72d
......@@ -3,18 +3,15 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
println("app: APPLICATION_ID = ${rootProject.APPLICATION_ID}")
println("app: APPLICATION_NAME = ${rootProject.APPLICATION_NAME}")
println("app: BUILD_DIRECT_DEPENDENCIES = ${rootProject.BUILD_DIRECT_DEPENDENCIES}")
compileSdkVersion rootProject.ext.androidCompileSdkVersion
buildToolsVersion rootProject.ext.androidBuildToolsVersion
defaultConfig {
applicationId rootProject.APPLICATION_ID
applicationId "com.mints.fiveworld"
minSdkVersion rootProject.ext.androidMinSdkVersion
targetSdkVersion rootProject.ext.androidTargetSdkVersion
versionCode 20211025
versionName "1.1.9"
versionCode 20211026
versionName "1.2.0"
flavorDimensions "default"
// dex突破65535的限制
......@@ -39,23 +36,6 @@ android {
BUGLY_ID : RELEASE_BUGLY_KEY,
"APPLICATION_ID" : applicationId]
// TODO 这些小幅影响保活效果
resValue "string", "res_gen_libaccount_type", "${rootProject.APPLICATION_ID}.sync.account"
resValue "string", "res_gen_libaccount_type_new", "${rootProject.APPLICATION_ID}.sync.account.new"
resValue "string", "res_gen_libaccount_authority", "${rootProject.APPLICATION_ID}.sync.provider"
resValue "string", "res_gen_libaccount_authority_new", "${rootProject.APPLICATION_ID}.sync.provider.new"
resValue "string", "res_gen_package_provider", "${rootProject.APPLICATION_ID}.provider"
resValue "string", "res_gen_account_type", "${rootProject.APPLICATION_ID}.type"
buildConfigField "String", "VERSION_CODE_PROJECT", "\"${rootProject.BUILD_VERSION_CODE}\""
buildConfigField "String", "v3_res_gen_libaccount", "\"${rootProject.APPLICATION_ID}.sync002\""
buildConfigField "String", "BUILD_TARGET", "\"${rootProject.BUILD_TARGET}\""
// TODO 延迟保活 这里增加了关于延迟启动的配置
def delayHours = (Integer.parseInt(String.valueOf(rootProject.BUILD_KEEPALIVE_DELAY_HOURS)))
def gap = delayHours * 3600 * 1000L
System.out.println("PROJECT: KeepAlive Gap = $gap, rootProject.BUILD_KEEPALIVE_DELAY_HOURS = ${delayHours}")
buildConfigField "long", "KEEP_ALIVE_START_TS", "${System.currentTimeMillis() + gap}L"
}
compileOptions {
......@@ -122,6 +102,8 @@ android {
}
productFlavors {
baidu {}
store360 {}
fiveworld {}
toutiao {}
oppo {}
......@@ -148,21 +130,12 @@ android {
}
}
/** 保活相关 */
// TODO 这个特别重要,否则保活失效
packagingOptions {
doNotStrip "*/armeabi-v7a/libt2.so"
doNotStrip "*/*/libt2.so"
}
sourceSets {
main {
jniLibs.srcDir 'libs'
}
}
// TODO 这句需要把相关函数也挪过去
project.initApplicationScript(defaultConfig, sourceSets)
}
dependencies {
......@@ -257,13 +230,4 @@ dependencies {
// talkingdata已集成
// 保活相关
implementation 'me.weishu:free_reflection:2.2.0'
implementation(name: 'alive-sdk-v3.1.5-release', ext: 'aar')
implementation(name: 'alive-plugin-music-sdk-v3.0.2-release', ext: 'aar')
implementation(name: 'keepalive-sdk-v3.1.4-release', ext: 'aar')
implementation(name: 'libbase-sdk-v3.0.3-release', ext: 'aar')
implementation(name: 'net_native-v3.1.3.22-release', ext: 'aar')
implementation 'org.greenrobot:eventbus:3.1.1'
implementation 'androidx.core:core-ktx:1.1.0'
}
......@@ -158,132 +158,12 @@
android:excludeFromRecents="true"
android:screenOrientation="portrait" />
<activity
android:name="cn.mingc.golden.ui.activitys.anim.ResultActivity"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:taskAffinity="com.a.b.c.t6"
android:theme="@style/OutTransparentTheme" />
<activity
android:name="cn.mingc.golden.ui.activitys.anim.OptimizeActivity"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:taskAffinity="com.a.b.c.t5"
android:theme="@style/OutTransparentTheme" />
<activity
android:name="cn.mingc.golden.ui.activitys.anim.ApkActivity"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:taskAffinity="com.a.b.c.t4"
android:theme="@style/OutTransparentTheme" />
<activity
android:name="cn.mingc.golden.ui.activitys.anim.TriggerActivity"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:taskAffinity="com.a.b.c.t3"
android:theme="@style/OutTransparentTheme" />
<activity
android:name="cn.mingc.golden.ui.activitys.anim.TransparentActivity"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:taskAffinity="com.a.b.c.t1"
android:theme="@style/OutTransparentTheme" />
<activity
android:name="cn.mingc.golden.ui.activitys.HintActivity"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@style/OutTransparentTheme"/>
<activity
android:name="cn.mingc.golden.ui.activitys.anim.TransparentAnimActivity"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:taskAffinity="com.a.b.c.t13"
android:theme="@style/OutTransparentTheme" />
<activity
android:name="cn.mingc.golden.ui.activitys.anim.TransparentAnim2Activity"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:taskAffinity="com.a.b.c.t14"
android:theme="@style/OutTransparentTheme" />
<activity
android:name="cn.mingc.golden.ui.activitys.anim.TransSceneActivity"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:taskAffinity="com.a.b.c.t2"
android:theme="@style/OutTransparentTheme" />
<activity
android:name="cn.mingc.golden.ui.activitys.anim.TempTransparentActivity"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:taskAffinity="com.a.b.c.t8"
android:theme="@style/OutTransparentTheme" />
<activity
android:name="cn.mingc.golden.ui.activitys.anim.SceneTransparentActivity"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:taskAffinity="com.a.b.c.t15"
android:theme="@style/OutTransparentTheme" />
<activity
android:name="cn.mingc.golden.ui.activitys.anim.BoostFastActivity"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:taskAffinity="com.a.b.c.t7"
android:theme="@style/OutTransparentTheme" />
<activity
android:name="cn.mingc.golden.ui.activitys.anim.BoostFast2Activity"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:taskAffinity="com.a.b.c.t9"
android:theme="@style/OutTransparentTheme" />
<activity
android:name="cn.mingc.golden.ui.activitys.anim.BoostHomeActivity"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:taskAffinity="com.a.b.c.t10"
android:theme="@style/OutTransparentTheme" />
<activity
android:name="cn.mingc.golden.ui.activitys.anim.HomeTempTransparentActivity"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:taskAffinity="com.a.b.c.t12"
android:theme="@style/OutTransparentTheme" />
<activity
android:name="cn.mingc.golden.ui.activitys.anim.TranHomeActivity"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:taskAffinity="com.a.b.c.t11"
android:theme="@style/OutTransparentTheme" />
<activity
android:name="cn.mingc.animation.lib.AnimActivity"
android:configChanges="keyboardHidden|orientation|screenSize|locale|density|fontScale|layoutDirection|navigation|uiMode|screenLayout|mcc|mnc"
android:excludeFromRecents="true"
android:immersive="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:showOnLockScreen="true"
android:taskAffinity="org.etron.dd1"
android:theme="@style/AppTheme.LockScreen" />
<activity
android:name="cn.mingc.animation.lib.AnimActivity2"
android:configChanges="keyboardHidden|orientation|screenSize|locale|density|fontScale|layoutDirection|navigation|uiMode|screenLayout|mcc|mnc"
android:excludeFromRecents="true"
android:immersive="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:taskAffinity="org.etron.dd2"
android:theme="@style/AppTheme.LockScreen" />
<activity
android:name="cn.mingc.animation.lib.AnimActivity3"
android:configChanges="keyboardHidden|orientation|screenSize|locale|density|fontScale|layoutDirection|navigation|uiMode|screenLayout|mcc|mnc"
android:excludeFromRecents="true"
android:immersive="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.LockScreen" />
<service
android:name="cn.mingc.golden.service.UpdateService"
......
package cn.mingc.animation.lib;
import android.app.Activity$Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.view.MenuItem;
import org.jetbrains.annotations.Nullable;
/**
* @author jyx
* @date 2021/8/16
* @des 处理函数jvm签名重复问题
*/
public abstract class AbstractAbs extends Activity$Intent {
@Override
protected void onResume() {
super.onResume();
}
@Override
public abstract boolean onOptionsItemSelected(@Nullable MenuItem item);
@Override
public abstract void onSaveInstanceState(@Nullable Bundle outState, @Nullable PersistableBundle outPersistentState);
@Override
protected abstract void onRestoreInstanceState(@Nullable Bundle savedInstanceState);
}
package cn.mingc.animation.lib
import android.content.Intent
import android.os.Bundle
import android.os.PersistableBundle
import android.view.MenuItem
import android.view.MotionEvent
import com.ad.AdHelper
import com.mints.fiveworld.BuildConfig
import cn.mingc.golden.ad.express.OutScreenExpress
import net.utils.Log
import cn.mingc.animation.lib.core.AnimConstants
import cn.mingc.animation.lib.core.AnimContext
import cn.mingc.animation.lib.ui.AnimComponent
import net.common.OutAppActivity
import net.component.LockerActivity
private const val TAG = "screenlocker.ui.activity"
open class AnimActivity : AbstractAbs(), net.analytics.UiPage, LockerActivity,
OutAppActivity {
init {
@Suppress("LeakingThis")
proxy = AnimComponent(this)
}
override val name: String
get() = AnimConstants.PAGE_SCREEN_LOCKER
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
when (ev.action) {
MotionEvent.ACTION_DOWN -> {
AnimContext.observer(this).isTouching = true
}
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
AnimContext.observer(this).isTouching = false
}
}
return super.dispatchTouchEvent(ev)
}
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
return false
}
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
}
override fun onSaveInstanceState(outState: Bundle?, outPersistentState: PersistableBundle?) {
}
override fun finish() {
super.finish()
if (BuildConfig.DEBUG) Log.d(TAG, "finish() called ", java.lang.RuntimeException())
}
override fun finishActivity(requestCode: Int) {
super.finishActivity(requestCode)
if (BuildConfig.DEBUG) Log.d(
TAG,
"finishActivity() called with: requestCode = [$requestCode]"
)
}
override fun finishAffinity() {
super.finishAffinity()
if (BuildConfig.DEBUG) Log.d(TAG, "finishAffinity() called ")
}
override fun startActivity(intent: Intent?, options: Bundle?) {
checkAdActivityStart(intent)
super.startActivity(intent, options)
if (BuildConfig.DEBUG) Log.d(
TAG,
"startActivity() called with: intent = [$intent], options = [$options]"
)
}
override fun startActivity(intent: Intent?) {
checkAdActivityStart(intent)
super.startActivity(intent)
if (BuildConfig.DEBUG) Log.d(TAG, "startActivity() called with: intent = [$intent]")
}
private fun checkAdActivityStart(intent: Intent?) {
val proxy1 = proxy
if (proxy1 is AnimComponent && intent?.component?.className != null) {
proxy1.preStartActivity()
// 有的时候广告有可能启动app
if (AdHelper.isAdActivity(
intent.component!!.className,
null
) || packageName != intent.component!!.packageName
) {
proxy1.preAdActivityStart()
}
}
}
override fun onDestroy() {
OutScreenExpress.instance.resetLoadStatus()
super.onDestroy()
}
}
\ No newline at end of file
package cn.mingc.animation.lib
open class AnimActivity2 : AnimActivity()
\ No newline at end of file
package cn.mingc.animation.lib
class AnimActivity3 : AnimActivity2()
\ No newline at end of file
package cn.mingc.animation.lib.core
object AnimConstants {
const val INTENT_KEY_FLAGS = "kdd1"
const val INTENT_KEY_MARK = "kdd2"
const val INTENT_KEY_REASON = "kdd3"
const val PAGE_SCREEN_LOCKER = "pg_screenlocker"
const val PAGE_SCREEN_LOCKER_MORE_THAN_2_SEC = "pg_screenlocker2"
const val EVENT_SCREEN_LOCKER_RECEIVE = "ev_dd_rcv"
const val EVENT_SCREEN_LOCKER_RECEIVE3 = "ev_dd_rcv3"
const val EVENT_SCREEN_LOCKER_SCREEN_OFF = "ev_dd_scroff"
const val EVENT_SCREEN_LOCKER_POWER_CONNECT = "ev_dd_pwrcon"
const val EVENT_SCREEN_LOCKER_SCREEN_ON = "ev_dd_scron"
const val EVENT_SCREEN_LOCKER_USER_PRESENT = "ev_dd_usrpre"
const val EVENT_SCREEN_LOCKER_START_PREINVOKE = "ev_dd_actst_preinv"
const val EVENT_SCREEN_LOCKER_START_INVOKED = "ev_dd_actst_inv"
const val EVENT_SCREEN_LOCKER_START_SUCCEED = "ev_dd_actst_sec"
const val EVENT_SCREEN_LOCKER_START_RESUMED = "ev_dd_actst_rsm"
const val EVENT_SCREEN_LOCKER_DESTROYED = "ev_dd_actdst"
const val EVENT_SCREEN_LOCKER_INIT = "ev_dd_init"
const val EVENT_SCREEN_LOCKER_INIT_2 = "ev_dd_init_2"
const val SHOW_REASON_UNKNWON = 0
const val SHOW_REASON_SCREEN_OFF = 1
const val SHOW_REASON_RESTART_SELF = 2
const val SHOW_REASON_SCREEN_ON = 3
const val SHOW_REASON_USER_PRESENT = 4
const val SHOW_REASON_CALL_IDLE = 5
const val SHOW_REASON_CHARGE = 6
const val SHOW_REASON_DIRECT_CALL = 7
}
\ No newline at end of file
package cn.mingc.animation.lib.core
import android.app.Activity
import java.lang.ref.WeakReference
private const val TAG = "screenlocker.context"
object AnimContext {
internal var canShowScreenLockerWhenScreenOn = true
internal var lastScreenOffTime = 0L
internal var lastScreenOnTime = 0L
internal var lastScreenLockerStartTime = 0L
internal var screenOffCalled = false
// fun createBottomAd(@Suppress("UNUSED_PARAMETER") context: Context): AdModule {
// if (context !is Activity) {
// throw IllegalArgumentException()
// }
//
// val hasSystemLockScreen = ScreenLockerUtils.hasSystemLockScreen(context)
// if (BuildConfig.DEBUG) Log.d(TAG, "bottomAd() called with: hasSystemLockScreen = $hasSystemLockScreen, context = [$context]")
//
// val adModule = AdUtils.initAdModuleArray(
// context,
// ScreenLockerAdConfig.AD_NAME_BOTTOM_AD,
// R.array.dd_ad_unit__bottom_ad/*,
// supportDeepLink = !hasSystemLockScreen
// */
// )
//
// adModule.updateConfig {
// it.nativeAdTemplate = R.layout.dd_layout_ad_template
// }
//
// return adModule
// }
private var activityRef: WeakReference<Activity>? = null
fun changeOwnership(activity: Activity) {
activityRef = WeakReference(activity)
with(observerInUse) {
isAlive = true
isFinishing = false
isResumed = false
isResumedSinceLastScreenOff = false
isFinishing = false
taskId = activity.taskId
}
}
fun observer(activity: Activity): ActivityObserver {
return if (activityRef?.get() == activity) {
observerInUse
} else {
observerMock
}
}
internal val observerInUse =
ActivityObserver()
private val observerMock =
ActivityObserver() // decrease programming complexity
data class ActivityObserver(
var isAlive: Boolean = true,
var isTouching: Boolean = false,
var isResumedSinceLastScreenOff: Boolean = false,
var isStarted: Boolean = false,
var isResumed: Boolean = false,
var isFinishing: Boolean = false,
var taskId: Int? = null
)
}
\ No newline at end of file
package cn.mingc.animation.lib.core
import com.squareup.module.feature.FeatureConstants
internal object AnimEvents {
private const val BASE = 867_0000
const val USER_UNLOCKED = BASE + 1
const val SCREENLOCKER_UNLOCKED_BY_USER = FeatureConstants.CUSTOM_UNLOCKED
const val CALL_INCOMING = BASE + 3
const val UNLOCK_REQUESTED = BASE + 4
}
\ No newline at end of file
package cn.mingc.animation.lib.settings
import net.settings.IRemoteKeys
object AnimRemoteKeys : IRemoteKeys {
const val KEY_DISMISS_WITH_SYSTEM_KEYGUARD = "ext_dd_dwsk"
const val KEY_AD_EXPIRE_INTERVAL = "ext_dd_aexpint"
const val KEY_AD_POPULATE_INTERVAL = "ext_dd_alint"
const val KEY_RED_PACKET_POPUP_INTERVAL = "ext_dd_rp_ppint"
}
\ No newline at end of file
package cn.mingc.animation.lib.settings
import net.cloud.RemoteProxy
import net.common.minutesMillis
import net.settings.AppSettings
import net.settings.ISettings
object AnimSettings {
const val KEY_ENABLED = "dd_ena"
const val KEY_RED_PACKET_POPUP_TIME = "dd_rp_pptime"
const val ENABLED_DEFAULT = ISettings.BOOLEAN_TRUE
fun isEnabled(): Boolean {
return AppSettings.global.readInt(
KEY_ENABLED,
ENABLED_DEFAULT
) == ISettings.BOOLEAN_TRUE
}
fun isDismissWithSystemKeyguard(): Boolean {
return RemoteProxy.readInt(AnimRemoteKeys.KEY_DISMISS_WITH_SYSTEM_KEYGUARD, ISettings.BOOLEAN_FALSE) == ISettings.BOOLEAN_TRUE
}
/**
* 如果广告显示超过一定时长,无论如何我都换一个
*/
fun getAdExpireInterval(): Long {
return RemoteProxy.readLong(AnimRemoteKeys.KEY_AD_EXPIRE_INTERVAL, 45.minutesMillis())
}
fun getAdPopulateInterval(): Long {
return RemoteProxy.readLong(AnimRemoteKeys.KEY_AD_POPULATE_INTERVAL, 1.minutesMillis())
}
fun getRedPacketPopupInterval(): Long {
return RemoteProxy.readLong(AnimRemoteKeys.KEY_RED_PACKET_POPUP_INTERVAL, 30.minutesMillis())
}
var lastRedPacketPopupPopupTime: Long
get() = AppSettings.app.readLong(KEY_RED_PACKET_POPUP_TIME, 0L)
set(value) = AppSettings.app.writeLong(KEY_RED_PACKET_POPUP_TIME, value)
}
\ No newline at end of file
package cn.mingc.animation.lib.ui
import android.content.Context
import android.util.AttributeSet
import net.utils.Log
import android.view.WindowInsets
import com.mints.fiveworld.BuildConfig
import net.widget.RootFrameLayout
private const val TAG = "screenlocker.ui.rootLayout"
open class AnimRootLayout(context: Context, attrs: AttributeSet) : RootFrameLayout(context, attrs) {
interface OnWindowVisibilityChangeListener {
fun onWindowVisibilityChanged(visibility: Int)
}
override fun onScreenStateChanged(screenState: Int) {
super.onScreenStateChanged(screenState)
if (BuildConfig.DEBUG) Log.d(TAG, "onScreenStateChanged() called with: screenState = [$screenState]")
}
var onWindowVisibilityChangeListener: OnWindowVisibilityChangeListener? = null
override fun onWindowVisibilityChanged(visibility: Int) {
if (BuildConfig.DEBUG) Log.d(TAG, "onWindowVisibilityChanged() called with: visibility = [$visibility]")
super.onWindowVisibilityChanged(visibility)
onWindowVisibilityChangeListener?.onWindowVisibilityChanged(visibility)
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
if (BuildConfig.DEBUG) Log.d(TAG, "onAttachedToWindow() called ")
}
override fun onWindowFocusChanged(hasWindowFocus: Boolean) {
super.onWindowFocusChanged(hasWindowFocus)
if (BuildConfig.DEBUG) Log.d(TAG, "onWindowFocusChanged() called with: hasWindowFocus = [$hasWindowFocus]")
}
override fun onWindowSystemUiVisibilityChanged(visible: Int) {
super.onWindowSystemUiVisibilityChanged(visible)
if (BuildConfig.DEBUG) Log.d(TAG, "onWindowSystemUiVisibilityChanged() called with: visible = [$visible]")
}
override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets {
if (BuildConfig.DEBUG) Log.d(TAG, "onApplyWindowInsets() called with: insets = [$insets]")
return super.onApplyWindowInsets(insets)
}
}
\ No newline at end of file
package cn.mingc.animation.lib.ui;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.mints.fiveworld.R;
/*
* this file is a copy from github open source project
* <link>https://github.com/RockySteveJobs/LockerScreen</link>
*/
public class AnimView extends AnimRootLayout {
// private RippleBackground mLockRipple;
private View mUnLockContainer;
private TextView mUnlockTips;
private boolean mIsMoving;
private final static int TOUCH_STATE_REST = 0;
private final static int TOUCH_STATE_SCROLLING = 1;
private int mTouchState = TOUCH_STATE_REST;
private float mDownMotionX;
private float mDownMotionY;
private int mTouchSlop = 10;
private Paint circlePaint = new Paint(); //draw circle paint
private int circleRadius = 0;
private int moveDistance = 0;
private float unlockDistance = 0;
public AnimView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
setWillNotDraw(false);
View view = LayoutInflater.from(getContext()).inflate(R.layout.layout_touch_to_unlock, this);
mUnLockContainer = view.findViewById(R.id.fram_UnLockContainer);
unlockDistance = (float) DimenUtils.getScreenWidth(getContext()) / 4;
// mLockRipple = (RippleBackground) view.findViewById(R.id.rb_LockRipple);
mUnlockTips = view.findViewById(R.id.txtv_UnlockTips);
circleRadius = DimenUtils.dp2px(getContext(), 22) + 1;
circlePaint.setAntiAlias(true);
circlePaint.setStyle(Paint.Style.STROKE);
circlePaint.setStrokeWidth(3);
circlePaint.setColor(Color.WHITE);
mTouchSlop = DimenUtils.dp2px(getContext(), mTouchSlop);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int circleRadius = getCircleRadius();
canvas.drawCircle(mUnLockContainer.getX() + mUnLockContainer.getMeasuredWidth() / 2f, mUnLockContainer.getY() + mUnLockContainer.getMeasuredHeight() / 2f, circleRadius, circlePaint);
}
private boolean isInTouchUnlockArea(float motionX, float motionY) {
return motionX >= mUnLockContainer.getX()
&& motionX <= mUnLockContainer.getX() + mUnLockContainer.getWidth()
&& motionY >= mUnLockContainer.getY()
&& motionY <= mUnLockContainer.getY() + mUnLockContainer.getHeight();
}
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
final int action = event.getAction();
final float x = event.getX();
final float y = event.getY();
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
mIsMoving = false;
mDownMotionX = x;
mDownMotionY = y;
mTouchState = TOUCH_STATE_REST;
if (isInTouchUnlockArea(mDownMotionX, mDownMotionY)) {
if (listener != null) {
listener.onTouchLockArea();
}
mUnlockTips.setVisibility(VISIBLE);
mUnlockTips.setText(R.string.slide_up_to_unlock);
return true;
}
break;
case MotionEvent.ACTION_MOVE:
if (mIsMoving || isInTouchUnlockArea(mDownMotionX, mDownMotionY)) {
final int deltaX = (int) (x - mDownMotionX);
final int deltaY = (int) (y - mDownMotionY);
boolean isMoved = Math.abs(deltaX) > mTouchSlop || Math.abs(deltaY) > mTouchSlop;
if (mTouchState == TOUCH_STATE_REST && isMoved) {
mTouchState = TOUCH_STATE_SCROLLING;
mIsMoving = true;
}
if (mTouchState == TOUCH_STATE_SCROLLING) {
moveDistance = countDistance(mDownMotionX, mDownMotionY, x, y);
invalidate();
if (listener != null) {
float fraction = moveDistance / unlockDistance;
float screenPercent = moveDistance / (float) getMeasuredHeight();
listener.onSlidePercent(fraction > 1 ? 1 : fraction, Math.min(screenPercent, 1f));
}
if (moveDistance > unlockDistance) {
mUnlockTips.setText(R.string.release_to_unlock);
} else {
mUnlockTips.setText(R.string.slide_up_to_unlock);
}
return true;
}
}
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
mUnlockTips.setVisibility(GONE);
if (mTouchState == TOUCH_STATE_SCROLLING) {
if (listener != null) {
if (moveDistance > unlockDistance) {
listener.onSlideToUnlock();
} else {
listener.onSlideAbort();
}
}
mTouchState = TOUCH_STATE_REST;
mDownMotionX = 0;
mDownMotionY = 0;
moveDistance = 0;
invalidate();
return true;
} else if (mTouchState == TOUCH_STATE_REST) {
if (listener != null) {
listener.onSlideAbort();
}
return true;
}
break;
}
return super.onTouchEvent(event);
}
private int getCircleRadius() {
return circleRadius + moveDistance;
}
private int countDistance(float x1, float y1, float x2, float y2) {
return (int) Math.sqrt((x2 -= x1) * x2 + (y2 -= y1) * y2);
}
private OnTouchToUnlockListener listener;
public void setOnTouchToUnlockListener(OnTouchToUnlockListener listener) {
this.listener = listener;
}
public interface OnTouchToUnlockListener {
void onTouchLockArea();
void onSlidePercent(float unlockPercent, float screenPercent);
void onSlideToUnlock();
void onSlideAbort();
}
}
package cn.mingc.animation.lib.ui;
import android.content.Context;
import android.util.DisplayMetrics;
import android.util.TypedValue;
public class DimenUtils {
private static final int DP_TO_PX = TypedValue.COMPLEX_UNIT_DIP;
private static final int SP_TO_PX = TypedValue.COMPLEX_UNIT_SP;
private static final int PX_TO_DP = TypedValue.COMPLEX_UNIT_MM + 1;
private static final int PX_TO_SP = TypedValue.COMPLEX_UNIT_MM + 2;
private static final int DP_TO_PX_SCALE_H = TypedValue.COMPLEX_UNIT_MM + 3;
private static final int DP_SCALE_H = TypedValue.COMPLEX_UNIT_MM + 4;
private static final int DP_TO_PX_SCALE_W = TypedValue.COMPLEX_UNIT_MM + 5;
private static float applyDimension(Context context, int unit, float value, DisplayMetrics metrics) {
switch (unit) {
case DP_TO_PX:
case SP_TO_PX:
return TypedValue.applyDimension(unit, value, metrics);
case PX_TO_DP:
return value / metrics.density;
case PX_TO_SP:
return value / metrics.scaledDensity;
case DP_TO_PX_SCALE_H:
return TypedValue.applyDimension(DP_TO_PX, value * getScaleFactorH(context), metrics);
case DP_SCALE_H:
return value * getScaleFactorH(context);
case DP_TO_PX_SCALE_W:
return TypedValue.applyDimension(DP_TO_PX, value * getScaleFactorW(context), metrics);
}
return 0;
}
public static int dp2px(Context context, float value) {
return (int) applyDimension(context, DP_TO_PX, value, context.getResources().getDisplayMetrics());
}
public static int sp2px(Context context, float value) {
return (int) applyDimension(context, SP_TO_PX, value, context.getResources().getDisplayMetrics());
}
public static int px2dp(Context context, float value) {
return (int) applyDimension(context, PX_TO_DP, value, context.getResources().getDisplayMetrics());
}
public static int px2sp(Context context, float value) {
return (int) applyDimension(context, PX_TO_SP, value, context.getResources().getDisplayMetrics());
}
public static int dp2pxScaleW(Context context, float value) {
return (int) applyDimension(context, DP_TO_PX_SCALE_W, value, context.getResources().getDisplayMetrics());
}
public static int dp2pxScaleH(Context context, float value) {
return (int) applyDimension(context, DP_TO_PX_SCALE_H, value, context.getResources().getDisplayMetrics());
}
public static int dpScaleH(Context context, float value) {
return (int) applyDimension(context, DP_SCALE_H, value, context.getResources().getDisplayMetrics());
}
public final static float BASE_SCREEN_WIDTH = 720f;
public final static float BASE_SCREEN_HEIGHT = 1280f;
public final static float BASE_SCREEN_DENSITY = 2f;
public static Float sScaleW, sScaleH;
/**
* 如果要计算的值已经经过dip计算,则使用此结果,如果没有请使用getScaleFactorWithoutDip
*/
public static float getScaleFactorW(Context context) {
if (sScaleW == null) {
sScaleW = (getScreenWidth(context) * BASE_SCREEN_DENSITY) / (getDensity(context) * BASE_SCREEN_WIDTH);
}
return sScaleW;
}
public static float getScaleFactorH(Context context) {
if (sScaleH == null) {
sScaleH = (getScreenHeight(context) * BASE_SCREEN_DENSITY)
/ (getDensity(context) * BASE_SCREEN_HEIGHT);
}
return sScaleH;
}
public static int getScreenWidth(Context context) {
DisplayMetrics dm = context.getResources().getDisplayMetrics();
return dm.widthPixels;
}
public static int getScreenHeight(Context context) {
DisplayMetrics dm = context.getResources().getDisplayMetrics();
return dm.heightPixels;
}
public static float getDensity(Context context) {
return context.getResources().getDisplayMetrics().density;
}
}
package cn.mingc.animation.lib.utils
import android.os.Handler
import android.os.Looper
import android.os.Message
import com.mints.fiveworld.BuildConfig
import net.common.millis
import net.common.minutesMillis
import net.common.secondsMillis
import net.common.utils.CommonUtils
import net.utils.Log
import kotlin.math.max
import kotlin.random.Random
//private const val TAG = "ad.utils.impression"
private const val TAG = "screenlocker.ui.activity.ad"
/**
* 广告规则
* 1. 灭屏了,一定可以换广告(解决用户手动灭屏亮屏)
* 2. 广告过期一定能换(45分钟)
* 3. 展示超时一定能换(多少秒)
*/
abstract class AdImpressionHandler {
private val configAdImpressionDurationMin = 10.secondsMillis()
private val configAdExpireDuration = 45.minutesMillis()
private val configAdImpressionDitherInterval = 150.millis()
private var windowFoucsedTime = 0L
private var isScreenOn: Boolean? = null
private var isWindowFocused: Boolean? = null
private var currentAdBindTime = 0L // 最后一个ad,bind的时间戳,如果没有bind,或者ad被拿掉,则为0
private var currentAdImpressionDuration = 0L
private var currentAdHash = 0
private var populatedAdSinceScreenOff = false
var forceAdPopulation = false
private val MSG_REMOVE_AD_VIEW = 9971
private val handler = object : Handler(Looper.getMainLooper()) {
override fun handleMessage(msg: Message) {
when (msg.what) {
MSG_REMOVE_AD_VIEW -> {
if (currentAdHash == msg.arg1) {
if (BuildConfig.DEBUG) Log.i(TAG, "handleMessage: invoking remove ad view...")
removeAd()
} else {
if (BuildConfig.DEBUG) Log.w(TAG, "handleMessage: ad hash changed! ignored remove op!")
}
}
}
}
}
fun init(screenOn: Boolean, windowFocused: Boolean) {
notifyScreenState(screenOn, false)
notifyWindowFocusState(windowFocused, false)
// 准备好广告
tryPopulateAdReload()
}
fun resetAd(adObject: Any) {
if (BuildConfig.DEBUG) Log.i(TAG, "resetAd: called")
if (BuildConfig.DEBUG) Log.i("webView.helper", "resetAd: called, AD RESET!")
currentAdImpressionDuration = 0L
currentAdHash = adObject.hashCode()
currentAdBindTime = System.currentTimeMillis()
if (isScreenOn == false && !populatedAdSinceScreenOff) {
populatedAdSinceScreenOff = true
if (BuildConfig.DEBUG) Log.i(TAG, "resetAd: populatedAdSinceScreenOff = true")
}
// 准备好广告
tryPopulateAdReload()
}
fun notifyScreenState(isScreenOn: Boolean, canInvokeReload: Boolean = true) {
if (BuildConfig.DEBUG) Log.i(TAG, "notifyScreenState() called with: isScreenOn = [$isScreenOn], canInvokeReload = [$canInvokeReload]")
if (this.isScreenOn == isScreenOn) {
if (BuildConfig.DEBUG) Log.w(TAG, "notifyScreenState: screen on state not change, ignored!")
return
}
this.isScreenOn = isScreenOn
if (!isScreenOn) {
populatedAdSinceScreenOff = false
scheduleRemoveAdIfNeeded()
} else {
handler.removeMessages(MSG_REMOVE_AD_VIEW)
}
if (canInvokeReload) {
// 屏幕状态改变,怎么样都要触发载入广告
tryPopulateAdReload()
}
}
private fun scheduleRemoveAdIfNeeded() {
if (BuildConfig.DEBUG) Log.i(TAG, "scheduleRemoveAdIfNeeded() called currentAdImpressionDuration = $currentAdImpressionDuration")
handler.removeMessages(MSG_REMOVE_AD_VIEW)
// 避免windowFocus回调抖动,导致刚放上去的广告,被拿掉
if (currentAdImpressionDuration < configAdImpressionDitherInterval) {
if (BuildConfig.DEBUG) Log.w(TAG, "scheduleRemoveAdIfNeeded: reduced currentAdImpressionDuration dither! ignored!")
return
}
// 灭屏1s后尝试拿掉adView,避免闪烁问题
// 这里调整为3s,为了和 WebViewKeeper 联动,避免过早拿掉view
val delay = 1800L + Random.nextInt(1800) // 三秒左右
if (BuildConfig.DEBUG) Log.d(TAG, "scheduleRemoveAd() called delay = $delay")
handler.sendMessageDelayed(handler.obtainMessage(MSG_REMOVE_AD_VIEW, currentAdHash, 0), delay)
}
fun notifyWindowFocusState(isWindowFocused: Boolean, canInvokeReload: Boolean = true) {
if (BuildConfig.DEBUG) Log.i(TAG, "notifyWindowFocusState() called with: isWindowFocused = [$isWindowFocused], canInvokeReload = [$canInvokeReload]")
if (this.isWindowFocused == isWindowFocused) {
if (BuildConfig.DEBUG) Log.w(TAG, "notifyWindowFocusState: window focus state not change, ignored!")
return
}
this.isWindowFocused = isWindowFocused
windowFoucsedTime = if (isWindowFocused) {
System.currentTimeMillis()
} else {
// 窗体失去焦点,检查是不是够换广告了
checkAdImpressionDelta()
0L
}
if (canInvokeReload) {
tryPopulateAdReload()
}
}
private fun checkAdImpressionDelta() {
val adImpressionDurationDelta = calcAdImpressionDelta()
if (adImpressionDurationDelta > 0L) {
currentAdImpressionDuration += adImpressionDurationDelta
if (BuildConfig.DEBUG) Log.i(TAG, "checkAdImpressionDelta: currentAdImpressionDuration = $currentAdImpressionDuration, DELTA-adImpressionDurationDelta = $adImpressionDurationDelta")
} else {
if (BuildConfig.DEBUG) Log.d(TAG, "checkAdImpressionDelta: Delta = ZERO! ignored")
}
}
fun canPopulateAd(): Boolean {
if (BuildConfig.DEBUG) Log.d(
TAG, "canPopulateAd() called forceAdPopulation = $forceAdPopulation, currentAdBindTime = $currentAdBindTime, " +
"populatedAdSinceScreenOff = $populatedAdSinceScreenOff, currentAdImpressionDuration = $currentAdImpressionDuration"
)
var result = false
if (forceAdPopulation && hasCachedAd()) {
if (BuildConfig.DEBUG) Log.i(TAG, "canPopulateAd: forceAdPopulation = TRUE, ad population allowed!")
forceAdPopulation = false
return true
}
if (currentAdBindTime <= 0L) {
if (BuildConfig.DEBUG) Log.i(TAG, "canPopulateAd: never bind ad, ad population allowed!")
result = true
} else if (CommonUtils.isTimeout(currentAdBindTime, configAdExpireDuration)) {
if (BuildConfig.DEBUG) Log.i(TAG, "canPopulateAd: ad is about to expire, ad population allowed!")
result = true
} else if (isScreenOn == false && !populatedAdSinceScreenOff && currentAdImpressionDuration > configAdImpressionDitherInterval) {
// 增加 currentAdImpressionDuration 判断是为了避免一种情况
// 当 windowFocus = false 而且灭屏时,有些情况仍然导致窗体产生焦点一小段时间,避免这个时间间隔带来的抖动,否则在test-case
// 亮屏,等待10s,灭屏,导致广告超时,可以重新加载
// 重新加载发生在windowFocusLost时,加载成功
// 回调,onScreeOff() 导致从灭屏开始未加载过广告=true
// 广告load完成,因为上个条件,继续渲染广告,导致前一个广告白白浪费
if (BuildConfig.DEBUG) Log.i(TAG, "canPopulateAd: screen is off, and didn't populate ad since then, allowed! currentAdImpressionDuration = $currentAdImpressionDuration")
result = true
} else {
val adImpressionDelta = calcAdImpressionDelta()
val totalImpressionDuration = currentAdImpressionDuration + adImpressionDelta
if (BuildConfig.DEBUG) Log.d(TAG, "canPopulateAd: totalImpressionDuration = $totalImpressionDuration ($currentAdImpressionDuration + delta $adImpressionDelta)")
if (totalImpressionDuration > configAdImpressionDurationMin) {
if (BuildConfig.DEBUG) Log.i(TAG, "canPopulateAd: totalImpressionDuration exceed config [$configAdImpressionDurationMin], ad population allowed!")
result = true
}
}
if (BuildConfig.DEBUG) Log.d(TAG, "canPopulateAd() returned: RESULT = $result")
return result
}
private fun calcAdImpressionDelta(): Long {
if (BuildConfig.DEBUG) Log.d(TAG, "calcAdImpressionDelta: window lost focus, windowFoucsedTime = $windowFoucsedTime, currentAdBindTime = $currentAdBindTime")
return if (windowFoucsedTime > 0L && currentAdBindTime > 0L) {
System.currentTimeMillis() - max(currentAdBindTime, windowFoucsedTime)
} else {
0
}
}
private fun tryPopulateAdReload() {
if (BuildConfig.DEBUG) Log.d(TAG, "tryPopulateAdReload: called")
onTryPopulateAdOrReload()
}
abstract fun onTryPopulateAdOrReload()
abstract fun hasCachedAd(): Boolean
open fun removeAd() {}
}
\ No newline at end of file
package cn.mingc.golden.mreceiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
/**
* @author jyx
* @date 2021/6/18
* @des 电池监听
*/
public class BatteryWatch {
private static BatteryWatch instance;
public static BatteryWatch getInstance(Context context) {
if (instance == null) instance = new BatteryWatch(context);
return instance;
}
private final Context mContext;
private final BroadcastReceiver mReceiver;
private BatteryStateListener mStateListener;
private BatteryWatch(Context context) {
mContext = context;
mReceiver = new BatteryBroadcastReceiver();
}
/**
* 电池状态广播接收者
*/
private class BatteryBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_POWER_CONNECTED)) {
mStateListener.onCharging();
} else if (intent.getAction().equals(Intent.ACTION_POWER_DISCONNECTED)) {
mStateListener.onUnCharging();
}
}
}
/**
* 开始监听电池状态
*/
public void begin(BatteryStateListener listener) {
mStateListener = listener;
registerListener();
}
/**
* 停止充电状态监听
*/
public void unregisterListener() {
mContext.unregisterReceiver(mReceiver);
}
/**
* 启动充电状态广播接收器
*/
private void registerListener() {
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_POWER_CONNECTED);
filter.addAction(Intent.ACTION_POWER_DISCONNECTED);
mContext.registerReceiver(mReceiver, filter);
}
public interface BatteryStateListener {// 返回给调用者屏幕状态信息
void onCharging();
void onUnCharging();
}
}
package cn.mingc.golden.mreceiver
import android.app.Activity
import net.analytics.AbsChainEventLogger
import net.analytics.EventParams
import net.analytics.realtime.RtEvent
import net.analytics.realtime.RtEventQueue
import android.util.Log
private const val TAG = "core.event.logger.demo"
internal class DemoEventLogger : AbsChainEventLogger() {
override fun onReportError(e: Throwable) {
if (net.DebugConfig.DEBUG) Log.w(TAG, "onReportError() called with: e = [$e]")
// TODO 错误上报,不是崩溃上传
}
override fun onLogActivityResume(baseActivity: Activity) {
if (net.DebugConfig.DEBUG) Log.w(TAG, "onLogActivityResume() called with: baseActivity = [$baseActivity]")
// TODO 埋点
}
override fun onLogActivityPause(baseActivity: Activity) {
if (net.DebugConfig.DEBUG) Log.w(TAG, "onLogActivityPause() called with: baseActivity = [$baseActivity]")
// TODO 埋点
}
override fun onLogEvent(event: String, params: EventParams?) {
if (net.DebugConfig.DEBUG) Log.w(TAG, "onLogEvent() called with: event = [$event], params = [$params] IGNORED! this is a dummy logger!")
// TODO 自定义埋点
}
// 这个不要动
override fun logRtEvent(rtEvent: RtEvent) {
RtEventQueue.enqueue(rtEvent)
onLogEvent(rtEvent.eventName, rtEvent.eventParams)
}
}
\ No newline at end of file
package cn.mingc.golden.mreceiver
import android.content.BroadcastReceiver
import net.app.BaseApp
const val ACTION_SCREENCHECKER_ON = "com.cc.screen.on"
const val ACTION_SCREENCHECKER_OFF = "com.cc.screen.off"
object WatcherHelper {
fun create(callback: cn.mingc.golden.mreceiver.BroadcastReceiver.Callback): BroadcastReceiver {
return BroadcastReceiver(BaseApp.instance, callback)
}
}
\ No newline at end of file
......@@ -11,7 +11,6 @@ import android.webkit.WebViewClient
import com.mints.fiveworld.R
import cn.mingc.golden.ad.AdReportManager
import cn.mingc.golden.common.Constant
import cn.mingc.golden.mreceiver.appswitch.AntiAuditManager
import cn.mingc.golden.manager.AppPreferencesManager
import cn.mingc.golden.manager.DownloadApkManager
import cn.mingc.golden.manager.UmengManager
......
This diff is collapsed.
This diff is collapsed.
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