Commit b799da99 authored by 王韦's avatar 王韦

[new] 修复 touchoutside

parent 02d8aefd
...@@ -17,8 +17,8 @@ class GridDividerActivity : AppCompatActivity() { ...@@ -17,8 +17,8 @@ class GridDividerActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_grid_divider) setContentView(R.layout.activity_grid_divider)
val gridLayoutManager = GridLayoutManager(this, 5) val gridLayoutManager = GridLayoutManager(this, 3)
val datas = mutableListOf<String>("1", "2","1", "2","1", "2") val datas = mutableListOf<String>("1", "2")
val adapter = GridAdatper(datas) val adapter = GridAdatper(datas)
grid.layoutManager =gridLayoutManager grid.layoutManager =gridLayoutManager
......
...@@ -26,8 +26,8 @@ class MainActivity : AppCompatActivity() { ...@@ -26,8 +26,8 @@ class MainActivity : AppCompatActivity() {
// loding.isCancelable =false // loding.isCancelable =false
// loding.show(supportFragmentManager, "loading") // loding.show(supportFragmentManager, "loading")
// TestWindow(this, findViewById<Button>(R.id.commonPop)).build().show() TestWindow(this, findViewById<Button>(R.id.commonPop)).build().show()
CustomToastUtils.getInstance().success() // CustomToastUtils.getInstance().success()
} }
......
package com.qimai.android.widget
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.view.ViewGroup
/**
* created by wangwei ON 4/17/20 email:wangwei_5521@163.com
* @version 1.1.1
* @Description
**/
class StoreLocalLayout : ViewGroup {
constructor(context: Context?) : this(context, null)
constructor(context: Context?, attrs: AttributeSet?) : this(context, attrs, 0)
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
) {
}
private val mAllView = mutableListOf<List<View>>()
private val mLineHeight = mutableListOf<Int>()
override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
if (childCount == 0) return
var left = 0
var top = 0
mAllView.clear()
mLineHeight.clear()
var lineHeight = 0
var lineViews = arrayListOf<View>()
if (childCount == 1){
val child = getChildAt(0)
val lc = left
val tc = top
val rc = measuredWidth
val bc = tc + child.measuredHeight
child.layout(lc, tc, rc, bc)
return
}
for (index in 0 until childCount) {
val child = getChildAt(index)
lineHeight = Math.max(child.measuredHeight, lineHeight)
lineViews.add(child)
if ((index + 1) % 2 == 0) {
mLineHeight.add(lineHeight)
mAllView.add(lineViews)
lineViews = arrayListOf<View>()
}
}
mLineHeight.add(lineHeight)
mAllView.add(lineViews)
mAllView.forEachIndexed { index, list ->
val mLineHeight = mLineHeight[index]
list.forEachIndexed { index, view ->
val child = view
val lc = left
val tc = top
val rc = lc + measuredWidth/2
val bc = tc + child.measuredHeight
child.layout(lc, tc, rc, bc)
left += measuredWidth/2
}
left = 0
top += mLineHeight
}
}
override fun measureChild(
child: View?,
parentWidthMeasureSpec: Int,
parentHeightMeasureSpec: Int
) {
super.measureChild(child, parentWidthMeasureSpec, parentHeightMeasureSpec)
}
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
if (childCount == 0) return
val heightSize = MeasureSpec.getSize(heightMeasureSpec)
val widthSize = MeasureSpec.getSize(widthMeasureSpec)
for (i in 0 until childCount ) {
if (i == 0 && childCount == 1) {
val widthSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.AT_MOST)
val heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)
measureChild(getChildAt(i), widthSpec, heightSpec)
}
if (childCount > 1) {
val widthSpec = MeasureSpec.makeMeasureSpec(widthSize / 2, MeasureSpec.EXACTLY)
val heightSpec = MeasureSpec.makeMeasureSpec(300, MeasureSpec.EXACTLY)
measureChild(getChildAt(i), widthSpec, heightSpec)
}
}
setMeasuredDimension(widthSize, heightSize)
}
}
\ No newline at end of file
...@@ -22,13 +22,14 @@ class TestWindow constructor(var ctx: Context, var anchor: View) : AbsQMBasePopu ...@@ -22,13 +22,14 @@ class TestWindow constructor(var ctx: Context, var anchor: View) : AbsQMBasePopu
override fun config(): WindowConfig { override fun config(): WindowConfig {
val content = LayoutInflater.from(ctx).inflate(R.layout.qm_alert_content, null)
val content = LayoutInflater.from(ctx).inflate(R.layout.qm_alert_content, null)
return AbsQMBasePopup.WindowConfig().apply { return AbsQMBasePopup.WindowConfig().apply {
mContentView = content mContentView = content
mAnchorView = anchor mAnchorView = anchor
mWindowWidth = getScreenWidth(ctx) - ctx.dpTopx(30.0f) mWindowWidth = getScreenWidth(ctx) - ctx.dpTopx(30.0f)
mGravity = Gravity.CENTER mGravity = Gravity.CENTER
isOutsideTouchable = false
} }
} }
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
tools:context=".GridDividerActivity"> tools:context=".GridDividerActivity">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/grid" android:id="@+id/grid"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />
......
...@@ -34,6 +34,23 @@ ...@@ -34,6 +34,23 @@
android:text="griddivider" android:text="griddivider"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="50dp" /> android:layout_height="50dp" />
<TextView
android:layout_width="match_parent"
android:text="测试111111 "
android:gravity="center"
android:textColor="@color/colorAccent"
android:layout_height="20dp" />
<com.qimai.android.widget.StoreLocalLayout
android:layout_width="match_parent"
android:layout_height="100dp">
<TextView
android:layout_width="wrap_content"
android:text="测试111111 "
android:textColor="@color/colorAccent"
android:layout_height="20dp" />
</com.qimai.android.widget.StoreLocalLayout>
</LinearLayout> </LinearLayout>
......
...@@ -4,6 +4,12 @@ ...@@ -4,6 +4,12 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="测试测试测试"
android:textColor="#C02F14"
android:textSize="10sp" />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
...@@ -11,4 +17,10 @@ ...@@ -11,4 +17,10 @@
android:textColor="#C02F14" android:textColor="#C02F14"
android:textSize="10sp" /> android:textSize="10sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="测试测试测试"
android:textColor="#C02F14"
android:textSize="10sp" />
</LinearLayout> </LinearLayout>
\ No newline at end of file
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
buildscript { buildscript {
ext.kotlin_version = '1.3.60' ext.kotlin_version = '1.3.60'
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.3.41'
repositories { repositories {
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }// 阿里云镜像 maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }// 阿里云镜像
maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' } maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
......
...@@ -47,7 +47,7 @@ repositories { ...@@ -47,7 +47,7 @@ repositories {
group 'com.qmai.android.sdk' group 'com.qmai.android.sdk'
version '1.1.29-SNAPSHOT' version '1.1.30-SNAPSHOT'
gradlePublish { gradlePublish {
......
...@@ -28,7 +28,7 @@ abstract class AbsQMBasePopup(open var context: Context) { ...@@ -28,7 +28,7 @@ abstract class AbsQMBasePopup(open var context: Context) {
abstract fun config(): WindowConfig abstract fun config(): WindowConfig
var touchOutside = true var touchOutside = false
set(value) { set(value) {
field = value field = value
mWindow.isOutsideTouchable = value mWindow.isOutsideTouchable = value
...@@ -57,7 +57,7 @@ abstract class AbsQMBasePopup(open var context: Context) { ...@@ -57,7 +57,7 @@ abstract class AbsQMBasePopup(open var context: Context) {
} }
mWindow.isTouchable = true mWindow.isTouchable = true
mWindow.isFocusable = true mWindow.isFocusable = config().isOutsideTouchable
mWindow.isOutsideTouchable = config().isOutsideTouchable mWindow.isOutsideTouchable = config().isOutsideTouchable
// 在相关的View被移除时,window也自动移除。避免当Fragment退出后,Fragment中弹出的PopupWindow还存在于界面上。 // 在相关的View被移除时,window也自动移除。避免当Fragment退出后,Fragment中弹出的PopupWindow还存在于界面上。
...@@ -119,7 +119,7 @@ abstract class AbsQMBasePopup(open var context: Context) { ...@@ -119,7 +119,7 @@ abstract class AbsQMBasePopup(open var context: Context) {
mRootViewWrapper.addView(contentView) mRootViewWrapper.addView(contentView)
mWindow.contentView = mRootViewWrapper mWindow.contentView = mRootViewWrapper
mWindow.setTouchInterceptor(View.OnTouchListener { v, event -> mWindow.setTouchInterceptor(View.OnTouchListener { v, event ->
if (event.action == MotionEvent.ACTION_OUTSIDE) { if (event.action == MotionEvent.ACTION_OUTSIDE && config().isOutsideTouchable) {
mWindow.dismiss() mWindow.dismiss()
return@OnTouchListener false return@OnTouchListener false
} }
......
...@@ -21,7 +21,7 @@ public class GridItemDivider extends RecyclerView.ItemDecoration { ...@@ -21,7 +21,7 @@ public class GridItemDivider extends RecyclerView.ItemDecoration {
private Drawable mDivider; private Drawable mDivider;
private final Rect mBounds = new Rect(); private final Rect mBounds = new Rect();
private int mode = OPEN; private int mode = CLOSE;
public final static int CLOSE = 1; public final static int CLOSE = 1;
public final static int OPEN = 2; public final static int OPEN = 2;
......
package com.qimai.android.widgetlib.shapeview;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.FrameLayout;
/**
* created by wangwei ON 4/13/20 email:wangwei_5521@163.com
*
* @version 1.1.1
* @Description
**/
public class ShapeView extends FrameLayout {
public ShapeView(Context context) {
this(context, null);
}
public ShapeView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public ShapeView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
}
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/color_222222" /> <solid android:color="#f2f2f2" />
<size android:width="0.5dp" android:height="0.5dp"/> <size android:width="1dp" android:height="1dp"/>
</shape> </shape>
\ No newline at end of file
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