1+ /*
2+ * Copyright (C) 2024 Christians Martínez Alvarado
3+ *
4+ * Licensed under the GNU General Public License v3
5+ *
6+ * This is free software: you can redistribute it and/or modify it under
7+ * the terms of the GNU General Public License as published by
8+ * the Free Software Foundation either version 3 of the License, or (at your option) any later version.
9+ *
10+ * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+ * See the GNU General Public License for more details.
13+ */
14+ package com.simplified.wsstatussaver.views
15+
16+ import android.content.Context
17+ import android.util.AttributeSet
18+ import android.view.MotionEvent
19+ import android.widget.FrameLayout
20+
21+ /* *
22+ * https://github.com/Baseflow/PhotoView/issues/708#issuecomment-1116960531
23+ */
24+ class PhotoViewWrapper @JvmOverloads constructor(context : Context , attrs : AttributeSet ? = null ) :
25+ FrameLayout (context, attrs) {
26+
27+ private var isParentInterceptionDisallowed = false
28+
29+ override fun requestDisallowInterceptTouchEvent (disallowIntercept : Boolean ) {
30+ isParentInterceptionDisallowed = disallowIntercept
31+ if (disallowIntercept) {
32+ // PhotoView wants to disallow parent interception, let it be.
33+ parent.requestDisallowInterceptTouchEvent(true ) // don't ban wrapper itself
34+ } else {
35+ // PhotoView wants to allow parent interception, we need to re-check it.
36+ }
37+ }
38+
39+ override fun onInterceptTouchEvent (ev : MotionEvent ): Boolean {
40+ // always false when up or cancel event,
41+ // which will allow parent interception normally.
42+ val isMultiTouch = ev.pointerCount > 1
43+
44+ // re-check if it's multi touch
45+ parent.requestDisallowInterceptTouchEvent(isParentInterceptionDisallowed || isMultiTouch)
46+ return false
47+ }
48+ }
0 commit comments