Skip to content

Commit bb419f4

Browse files
author
houjs0807
committed
1、解决tab切换 2、使用lock 3、1秒时候主动触发triggerViewCalculate
1 parent 7b98296 commit bb419f4

File tree

5 files changed

+35
-21
lines changed

5 files changed

+35
-21
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ android {
88

99
defaultConfig {
1010
applicationId "com.richard.datatracker"
11-
minSdkVersion 17
11+
minSdkVersion 24
1212
targetSdkVersion 30
1313
versionCode 1
1414
versionName "1.0"

app/src/main/java/com/richard/datatracker/App.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class App: MultiDexApplication() {
2020
trackerOpen = false,
2121
trackerExposureOpen = true,
2222
logOpen = true,
23-
batchOpen = true,
23+
batchOpen = true,dimThreshold=0.5,timeThreshold=1000,
2424
onCommitListener = object : OnCommitListener {
2525
override fun commitClickData(clickData: MutableMap<String, Any?>?) {
2626
//点击数据

tracker/src/main/java/com/zsmarter/exposuretracker/manager/ExposureManager.kt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ import android.graphics.Rect
44
import android.os.Handler
55
import android.os.HandlerThread
66
import android.util.ArrayMap
7-
import android.view.MotionEvent
8-
import android.view.View
9-
import android.view.ViewGroup
10-
import android.view.ViewTreeObserver
7+
import android.view.*
118
import com.zsmarter.exposuretracker.constant.GlobalConfig
129
import com.zsmarter.exposuretracker.constant.TrackerConstants
1310
import com.zsmarter.exposuretracker.model.ExposureModel
@@ -16,9 +13,7 @@ import com.zsmarter.exposuretracker.util.CommonHelper
1613
import com.zsmarter.exposuretracker.util.DataProcess
1714
import com.zsmarter.exposuretracker.util.TrackerLog
1815
import com.zsmarter.exposuretracker.util.TrackerUtil
19-
import java.lang.IllegalArgumentException
2016
import java.util.*
21-
import kotlin.collections.ArrayList
2217

2318

2419
class ExposureManager {
@@ -36,6 +31,7 @@ class ExposureManager {
3631
private var isVisible = false
3732
private var exposureViewProportion: Float? = null
3833
var motionEvent: MotionEvent? = null
34+
var lock : Any = Object()
3935

4036
init {
4137
val exposureThread = HandlerThread("ViewTracker_exposure")
@@ -69,7 +65,7 @@ class ExposureManager {
6965
}
7066
}
7167
BATCH_COMMIT_EXPOSURE -> {
72-
val lock = this.commitLogs
68+
//val lock = this.commitLogs
7369
synchronized(lock){
7470
// Scene 3 (switch back and forth when press Home button) is excluded.
7571
TrackerUtil.trackExploreData(commitLogs)
@@ -219,14 +215,15 @@ class ExposureManager {
219215
}
220216
val viewTag = view.getTag(TrackerConstants.VIEW_TAG_UNIQUE_NAME) as String?
221217
val checkWindowFocus = checkWindowFocus(view) //检查视图是否拥有焦点,同时检查isShow
222-
223218
val exposureValid = checkExposureViewDimension(view) //是否可见getGlobalVisibleRect
224219
val rootViewVisible = view.rootView.windowVisibility==View.VISIBLE
225-
val needExposureProcess = exposureValid &&rootViewVisible
220+
val needExposureProcess = checkWindowFocus && exposureValid &&rootViewVisible
221+
//TrackerLog.d(view.javaClass.canonicalName+"=="+view.isShown+"view.getParent="+(view.parent as View).visibility+"===exposureValid="+exposureValid+"|"+rootViewVisible)
222+
226223
if (!needExposureProcess) {
227224
return
228225
}
229-
TrackerLog.d(view.toString()+"可见===")
226+
TrackerLog.d(view.javaClass.canonicalName?.toString()+"可见===")
230227

231228
if (viewTag.isNullOrBlank()) {
232229
throw IllegalArgumentException("没有有给曝光的view设置->VIEW_TAG_UNIQUE_NAME")
@@ -291,8 +288,10 @@ class ExposureManager {
291288
}
292289
}
293290

291+
294292
private fun checkWindowFocus(view: View): Boolean {
295-
if(!view.isShown)return false
293+
return view.isShown&& (view.visibility==View.VISIBLE)
294+
/*if(!view.isShown)return false
296295
view.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
297296
override fun onGlobalLayout() {
298297
val visibleRect = Rect()
@@ -302,7 +301,7 @@ class ExposureManager {
302301
view.viewTreeObserver.removeOnGlobalLayoutListener(this)
303302
}
304303
})
305-
return isVisible
304+
return isVisible*/
306305
}
307306
/**
308307
* check the visible width and height of the view, compared with the its original width and height.

tracker/src/main/java/com/zsmarter/exposuretracker/manager/TrackerManager.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ class TrackerManager {
169169
message?.let {
170170
handler?.sendMessage(message)
171171
}
172-
TrackerLog.v("batch report exposure views ")
173172
}
174173

175174

@@ -249,7 +248,7 @@ class TrackerManager {
249248
}
250249

251250
/**
252-
* 页面暂停或切换tab按键的时候调用触发结束计算时间
251+
* 页面结束
253252
*/
254253
public fun onActivityStoped() {
255254
if (GlobalConfig.trackerExposureOpen) {
@@ -263,6 +262,19 @@ class TrackerManager {
263262
}
264263
}
265264

265+
/**
266+
* 页面暂停或切换tab按键的时候调用触发结束计算时间
267+
*/
268+
public fun onActivityPause() {
269+
if (GlobalConfig.trackerExposureOpen) {
270+
detachTrackerFrameLayout(containerView)
271+
TrackerLog.d("onActivityStopped activity")
272+
if (GlobalConfig.batchOpen) {
273+
batchReport()
274+
}
275+
}
276+
}
277+
266278
companion object {
267279
/**
268280
* 单例

tracker/src/main/java/com/zsmarter/exposuretracker/ui/TrackerFrameLayout.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,14 @@ class TrackerFrameLayout @JvmOverloads constructor(
7777
// Scene 1: Scroll beginning
7878
ExposureManager.get().setAbsPosition(ev)
7979
val time = System.currentTimeMillis()
80-
ExposureManager.get().triggerViewCalculate(
81-
TrackerConstants.TRIGGER_VIEW_CHANGED,
82-
this,
83-
lastVisibleViewMap
84-
)
80+
if (time - lastOnLayoutSystemTimeMillis > 1000) {
81+
lastOnLayoutSystemTimeMillis = time
82+
ExposureManager.get().triggerViewCalculate(
83+
TrackerConstants.TRIGGER_VIEW_CHANGED,
84+
this,
85+
lastVisibleViewMap
86+
)
87+
}
8588
//TrackerLog.v("dispatchTouchEvent triggerViewCalculate =")
8689
} else {
8790
//TrackerLog.d("dispatchTouchEvent ACTION_MOVE but not in click limit")

0 commit comments

Comments
 (0)