Commit 2d294d30 authored by 王韦's avatar 王韦

[new] popwindow

parent 8e9ee0dd
...@@ -24,7 +24,7 @@ android { ...@@ -24,7 +24,7 @@ android {
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2' implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.qimai.android.widget"> package="com.qimai.android.widget">
<application <application
android:allowBackup="true" android:allowBackup="true"
...@@ -9,11 +9,13 @@ ...@@ -9,11 +9,13 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity android:name=".CommomPopActivity"></activity>
<activity android:name=".TopBarActivity" />
<activity android:name=".MainActivity"> <activity android:name=".MainActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
</application> </application>
......
package com.qimai.android.widget
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import com.qimai.android.widgetlib.popup.CommonPopWindow
class CommomPopActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_commom_pop)
findViewById<Button>(R.id.center).setOnClickListener {
// val commonPopWindow = CommonPopWindow(CommomPopActivity@ this)
val contentView =
LayoutInflater.from(CommomPopActivity@ this).inflate(R.layout.popitem, null)
// commonPopWindow.setContentView(contentView)
// commonPopWindow.show(findViewById(R.id.root))
// commonPopWindow.dimBehind(0.5f)
val commonPopWindow = CommonPopWindow.Builder()
.configContentView(contentView = contentView)
.configGravity(Gravity.CENTER)
.build().showWindow(findViewById(R.id.root))
commonPopWindow.dimBehind(0.5f)
}
}
}
package com.qimai.android.widget package com.qimai.android.widget
import android.graphics.Color import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.widget.Button import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.qimai.android.widgetlib.topbar.QmTopBar
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
val toolbar = findViewById<QmTopBar>(R.id.toolbar) findViewById<Button>(R.id.commonPop).setOnClickListener {
setSupportActionBar(toolbar) startActivity(Intent(MainActivity@ this, CommomPopActivity::class.java))
supportActionBar?.setDisplayShowCustomEnabled(false)
toolbar.registerViewClickListener {
backImgClick {
finish()
}
rightImgClick {
Toast.makeText(this@MainActivity, "rightImg", Toast.LENGTH_SHORT).show()
}
rightTextClick {
Toast.makeText(this@MainActivity, "rightText", Toast.LENGTH_SHORT).show()
}
}
findViewById<Button>(R.id.line).setOnClickListener {
toolbar.qmTopBarNeedSeparator = !toolbar.qmTopBarNeedSeparator
}
findViewById<Button>(R.id.leftTextview).setOnClickListener {
toolbar.rightTextProperty = toolbar.rightTextProperty.apply {
text = "确定"
textColor = ContextCompat.getColor(this@MainActivity, R.color.abc_btn_colored_borderless_text_material)
textBackground = ContextCompat.getDrawable(this@MainActivity, R.drawable.btn_shape)
}
}
findViewById<Button>(R.id.center).setOnClickListener {
toolbar.centerTextProperty = toolbar.centerTextProperty.apply {
text = "修改"
textColor = ContextCompat.getColor(this@MainActivity, R.color.abc_btn_colored_borderless_text_material)
}
}
findViewById<Button>(R.id.customleft).setOnClickListener {
var text = TextView(this)
text.text = "取消"
text.setTextColor(Color.RED)
text.textSize = 16f
toolbar.customLeftView(text, null)
} }
findViewById<Button>(R.id.customright).setOnClickListener {
var text = TextView(this)
text.text = "确定"
text.setTextColor(Color.RED)
text.textSize = 16f
toolbar.customRightView(text, null)
}
} }
} }
package com.qimai.android.widget
import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import androidx.core.content.ContextCompat
import com.qimai.android.widgetlib.topbar.QmTopBar
class TopBarActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_top_bar)
val toolbar = findViewById<QmTopBar>(R.id.toolbar)
setSupportActionBar(toolbar)
supportActionBar?.setDisplayShowCustomEnabled(false)
toolbar.registerViewClickListener {
backImgClick {
finish()
}
rightImgClick {
Toast.makeText(this@TopBarActivity, "rightImg", Toast.LENGTH_SHORT).show()
}
rightTextClick {
Toast.makeText(this@TopBarActivity, "rightText", Toast.LENGTH_SHORT).show()
}
}
findViewById<Button>(R.id.line).setOnClickListener {
toolbar.qmTopBarNeedSeparator = !toolbar.qmTopBarNeedSeparator
}
findViewById<Button>(R.id.leftTextview).setOnClickListener {
toolbar.rightTextProperty = toolbar.rightTextProperty.apply {
text = "确定"
textColor = ContextCompat.getColor(this@TopBarActivity, R.color.abc_btn_colored_borderless_text_material)
textBackground = ContextCompat.getDrawable(this@TopBarActivity, R.drawable.btn_shape)
}
}
findViewById<Button>(R.id.center).setOnClickListener {
toolbar.centerTextProperty = toolbar.centerTextProperty.apply {
text = "修改"
textColor = ContextCompat.getColor(this@TopBarActivity, R.color.abc_btn_colored_borderless_text_material)
}
}
findViewById<Button>(R.id.customleft).setOnClickListener {
var text = TextView(this)
text.text = "取消"
text.setTextColor(Color.RED)
text.textSize = 16f
toolbar.customLeftView(text, null)
}
findViewById<Button>(R.id.customright).setOnClickListener {
var text = TextView(this)
text.text = "确定"
text.setTextColor(Color.RED)
text.textSize = 16f
toolbar.customRightView(text, null)
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="@+id/root"
android:orientation="vertical"
android:layout_height="match_parent"
tools:context=".CommomPopActivity">
<Button
android:id="@+id/center"
android:text="center"
android:layout_width="match_parent"
android:layout_height="50dp" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <ScrollView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
...@@ -8,59 +8,23 @@ ...@@ -8,59 +8,23 @@
android:orientation="vertical" android:orientation="vertical"
tools:context=".MainActivity"> tools:context=".MainActivity">
<com.qimai.android.widgetlib.topbar.QmTopBar
android:id="@+id/toolbar"
android:layout_width="match_parent"
app:title_color="@color/colorPrimary"
app:title_text_size="@dimen/QmTopBar_dp_18"
app:right_drawable_id="@drawable/more"
app:right_text="确定"
app:need_separator="true"
app:right_text_color="@color/colorAccent"
app:title_text="详情"
android:layout_height="45dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="45dp">
<Button
android:id="@+id/line"
android:layout_width="wrap_content"
android:text="line"
android:layout_height="45dp"/>
<Button
android:id="@+id/leftTextview"
android:layout_width="wrap_content"
android:text="右边text"
android:layout_height="45dp"/>
<Button
android:id="@+id/center"
android:layout_width="wrap_content"
android:text="center"
android:layout_height="45dp"/>
<Button
android:id="@+id/customleft"
android:layout_width="wrap_content"
android:text="自定义左边"
android:layout_height="45dp"/>
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:orientation="vertical" android:orientation="vertical"
android:layout_height="wrap_content"> android:layout_height="match_parent">
<Button <Button
android:id="@+id/customright" android:id="@+id/topbar"
android:layout_width="wrap_content" android:text="topbar"
android:text="自定义右边" android:layout_width="match_parent"
android:layout_height="45dp"/> android:layout_height="50dp" />
<Button
android:id="@+id/commonPop"
android:text="commonPop"
android:layout_width="match_parent"
android:layout_height="50dp" />
</LinearLayout> </LinearLayout>
</LinearLayout> </ScrollView>
\ No newline at end of file \ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<com.qimai.android.widgetlib.topbar.QmTopBar
android:id="@+id/toolbar"
android:layout_width="match_parent"
app:title_color="@color/colorPrimary"
app:title_text_size="@dimen/QmTopBar_dp_18"
app:right_drawable_id="@drawable/more"
app:right_text="确定"
app:need_separator="true"
app:right_text_color="@color/colorAccent"
app:title_text="详情"
android:layout_height="45dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="45dp">
<Button
android:id="@+id/line"
android:layout_width="wrap_content"
android:text="line"
android:layout_height="45dp"/>
<Button
android:id="@+id/leftTextview"
android:layout_width="wrap_content"
android:text="右边text"
android:layout_height="45dp"/>
<Button
android:id="@+id/center"
android:layout_width="wrap_content"
android:text="center"
android:layout_height="45dp"/>
<Button
android:id="@+id/customleft"
android:layout_width="wrap_content"
android:text="自定义左边"
android:layout_height="45dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<Button
android:id="@+id/customright"
android:layout_width="wrap_content"
android:text="自定义右边"
android:layout_height="45dp"/>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="20dp"
android:background="@color/QmTopBar_color_999999" />
</LinearLayout>
\ No newline at end of file
...@@ -17,7 +17,7 @@ buildscript { ...@@ -17,7 +17,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.4.2' classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
......
#Mon Aug 05 11:06:05 CST 2019 #Wed Aug 28 09:07:20 CST 2019
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
-------
#### 怎么上传maven #### 怎么上传maven
项目的根build.gradle 项目的根build.gradle
...@@ -51,7 +58,7 @@ last, execute `./gradlew publish` or `./gradlew :library:publish` task to publis ...@@ -51,7 +58,7 @@ last, execute `./gradlew publish` or `./gradlew :library:publish` task to publis
-----
#### 常用组件和工具库 #### 常用组件和工具库
[TopBar](https://git.zmcms.cn/wangwei/widget/blob/master/widgetlib/TopBarReadMe.MD) [TopBar](https://git.zmcms.cn/wangwei/widget/blob/master/widgetlib/TopBarReadMe.MD)
......
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android-extensions'
apply plugin: "com.whl.gradle-publish-plugin"
android { android {
compileSdkVersion 29 compileSdkVersion 29
...@@ -39,3 +39,28 @@ dependencies { ...@@ -39,3 +39,28 @@ dependencies {
repositories { repositories {
mavenCentral() mavenCentral()
} }
group 'com.qmai.android.tools'
version '1.1.3'
gradlePublish {
sourceJarEnabled = true
javaDocEnabled = false
signEnabled = false
releaseRepository {
url = "https://hub.zmcms.cn/repository/maven-releases/"
userName = "wangwei"
password = "caihong520"
}
snapshotRepository {
url = "https://hub.zmcms.cn/repository/maven-snapshots/"
userName = "wangwei"
password = "caihong520"
}
}
\ No newline at end of file
package com.qimai.android.tools
import android.content.Context
import android.content.SharedPreferences
import android.util.DisplayMetrics
/**
* created by wangwei ON 2019-08-22 email:wangwei_5521@163.com
* @version 1.1.1
* @Description
**/
fun getDisplayMetrics(context: Context): DisplayMetrics {
return context.resources.displayMetrics
}
/**
* 获取屏幕宽度
*
* @return
*/
fun getScreenWidth(context: Context): Int {
return getDisplayMetrics(context).widthPixels
}
/**
* 获取屏幕高度
*
* @return
*/
fun getScreenHeight(context: Context): Int {
var screenHeight = getDisplayMetrics(context).heightPixels
// if (QMUIDeviceHelper.isXiaomi() && xiaomiNavigationGestureEnabled(context)) {
// screenHeight += getResourceNavHeight(context)
// }
return screenHeight
}
package com.qimai.android.tools
import android.content.Context
import android.content.SharedPreferences
import java.util.concurrent.ConcurrentHashMap
/**
* created by wangwei ON 2019-08-27 email:wangwei_5521@163.com
* @version 1.1.1
* @Description
**/
class SharedPreferencesTools {
private var sp: SharedPreferences? = null
// applicationContext
private lateinit var context: Context
private val defaultKey = "sp_tools_default_key"
companion object {
val instance: SharedPreferencesTools by lazy {
SharedPreferencesTools()
}
}
private val spCache = ConcurrentHashMap<String, SharedPreferences>()
fun initSp(context: Context) {
this.context = context
sp = context.getSharedPreferences(defaultKey, Context.MODE_PRIVATE)
}
fun getSpByKey(key: String): SharedPreferences {
if (spCache[key] == null) {
spCache[key] = context.getSharedPreferences(key, Context.MODE_PRIVATE)
}
return spCache[key]!!
}
fun putString(key: String, value: String) {
check()
sp!!.edit().putString(key, value).apply()
}
fun putInt(key: String, value: Int) {
check()
sp!!.edit().putInt(key, value).apply()
}
fun putBoolean(key: String, value: Boolean) {
check()
sp!!.edit().putBoolean(key, value).apply()
}
fun remove(key: String) {
check()
sp!!.edit().remove(key).apply()
}
fun clear() {
check()
sp!!.edit().clear().apply()
}
private fun check() {
checkNotNull(sp) { "mull be invoke initSp" }
}
}
\ No newline at end of file
package com.qimai.android.tools
/**
* @author wangwei
* @version 1.1.1
* @date 2019-08-13
* @Description
* @email wangwei_5521@163.com
**/
open class SingletonHolder<out T : Any, in A>(creator: (A) -> T) {
private var creator: ((A) -> T)? = creator
@Volatile
private var instance: T? = null
fun getInstance(arg: A): T {
var i = instance
if (i != null) {
return i
}
return synchronized(this) {
val temp = instance
if (temp != null) {
return temp
} else {
val created = creator!!(arg)
instance = created
creator = null
created
}
}
}
}
\ No newline at end of file
...@@ -3,12 +3,12 @@ apply plugin: 'kotlin-android' ...@@ -3,12 +3,12 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android-extensions'
apply plugin: "com.whl.gradle-publish-plugin" apply plugin: "com.whl.gradle-publish-plugin"
android { android {
compileSdkVersion 29 compileSdkVersion 27
defaultConfig { defaultConfig {
minSdkVersion 19 minSdkVersion 19
targetSdkVersion 29 targetSdkVersion 27
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
...@@ -36,6 +36,7 @@ dependencies { ...@@ -36,6 +36,7 @@ dependencies {
implementation "androidx.core:core-ktx:1.0.2" implementation "androidx.core:core-ktx:1.0.2"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation project(path: ':tools') implementation project(path: ':tools')
// implementation 'com.qmai.android.tools:tools:1.1.1-SNAPSHOT'
} }
repositories { repositories {
mavenCentral() mavenCentral()
...@@ -43,7 +44,7 @@ repositories { ...@@ -43,7 +44,7 @@ repositories {
group 'com.qmai.android.sdk' group 'com.qmai.android.sdk'
version '1.1.2-SNAPSHOT' version '1.1.4-SNAPSHOT'
gradlePublish { gradlePublish {
...@@ -52,7 +53,7 @@ gradlePublish { ...@@ -52,7 +53,7 @@ gradlePublish {
signEnabled = false signEnabled = false
releaseRepository { releaseRepository {
url = "https://hub.zmcms.cn/repository/maven-public/" url = "https://hub.zmcms.cn/repository/maven-releases/"
userName = "wangwei" userName = "wangwei"
password = "caihong520" password = "caihong520"
} }
......
package com.qimai.android.widgetlib.popup
import android.content.Context
import android.graphics.Point
import android.view.Gravity
import android.view.View
/**
* created by wangwei ON 2019-08-28 email:wangwei_5521@163.com
* @version 1.1.1
* @Description
**/
class CommonPopWindow(context: Context) : QMBasePopup(context) {
fun showWindow(parent: View): CommonPopWindow {
super.show(parent)
return this
}
class Builder {
private var mContentView: View? = null
private var gravity = Gravity.NO_GRAVITY
private var animationStyle = -1
fun configContentView(contentView: View) = apply {
this.mContentView = contentView
}
fun configGravity(gravity: Int) = apply {
this.gravity = gravity
}
fun configAnimationStyle(style: Int) {
this.animationStyle = style
}
fun build(): CommonPopWindow {
val commonPopWindow = CommonPopWindow(mContentView!!.context)
commonPopWindow.gravity = gravity
commonPopWindow.setAnimatonStyle(style = animationStyle)
return commonPopWindow
}
}
override fun onShowBegin(parent: View, attachedView: View?): Point {
return Point(0, 0)
}
}
\ No newline at end of file
package com.qimai.android.widgetlib.popup
import android.content.Context
import android.graphics.Color
import android.graphics.Point
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.os.Build
import android.view.*
import android.widget.FrameLayout
import android.widget.PopupWindow
import androidx.core.view.ViewCompat
/**
* created by wangwei ON 2019-08-22 email:wangwei_5521@163.com
* @version 1.1.1
* @Description
**/
abstract class QMBasePopup(var context: Context) {
private var mWindow = PopupWindow()
lateinit var mRootViewWrapper: FrameLayout
var mBackground: Drawable? = null
var mWindowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
var mWindowWidth = 0
var mWindowHeight = 0
var gravity = Gravity.NO_GRAVITY
protected var mDismissListener: PopupWindow.OnDismissListener? = null
fun setAnimatonStyle(style: Int) {
mWindow.animationStyle = style
}
fun isShowing(): Boolean {
return mWindow.isShowing
}
fun dimBehind(dim: Float) {
if (!isShowing()) {
throw RuntimeException("should call after method show() or in onShowEnd()")
}
val decorView = getDecorView()
if (decorView != null) {
val p = decorView.layoutParams as WindowManager.LayoutParams
p.flags = p.flags or WindowManager.LayoutParams.FLAG_DIM_BEHIND
p.dimAmount = dim
mWindowManager.updateViewLayout(decorView, p)
}
}
protected abstract fun onShowBegin(parent: View, attachedView: View?): Point
protected fun onShowEnd() {}
fun dismiss() {
mWindow.dismiss()
}
protected fun show(parent: View) {
show(parent, null)
}
fun show(parent: View, anchorView: View?) {
if (anchorView != null && !ViewCompat.isAttachedToWindow(anchorView!!)) {
return
}
if (mWindowWidth == 0 || mWindowHeight == 0) {
mWindowWidth = ViewGroup.LayoutParams.MATCH_PARENT
mWindowHeight = ViewGroup.LayoutParams.WRAP_CONTENT
}
mWindow.width = mWindowWidth
mWindow.height = mWindowHeight
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
mWindow.isAttachedInDecor = false
}
val point = onShowBegin(parent, anchorView)
mWindow.showAtLocation(parent, gravity, point.x, point.y)
onShowEnd()
// 在相关的View被移除时,window也自动移除。避免当Fragment退出后,Fragment中弹出的PopupWindow还存在于界面上。
parent.addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
override fun onViewAttachedToWindow(v: View) {
}
override fun onViewDetachedFromWindow(v: View) {
if (isShowing()) {
dismiss()
}
}
})
}
protected fun onShowConfig() {
if (mBackground == null) {
mWindow.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
} else {
mWindow.setBackgroundDrawable(mBackground)
}
mWindow.isTouchable = true
mWindow.isFocusable = true
mWindow.isOutsideTouchable = true
}
fun setContentView(root: View) {
mRootViewWrapper = FrameLayout(context)
mRootViewWrapper.layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
mRootViewWrapper.addView(root)
onShowConfig()
mWindow.setTouchInterceptor(View.OnTouchListener { v, event ->
if (event.action == MotionEvent.ACTION_OUTSIDE) {
mWindow.dismiss()
return@OnTouchListener false
}
false
})
mWindow.setOnDismissListener {
this@QMBasePopup.onDismiss()
if (mDismissListener != null) {
mDismissListener!!.onDismiss()
}
}
}
protected fun onDismiss() {}
private fun getDecorView(): View? {
var decorView: View? = null
try {
decorView = if (mWindow.background == null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mWindow.contentView.parent as View
} else {
mWindow.contentView
}
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mWindow.contentView.parent.parent as View
} else {
mWindow.contentView.parent as View
}
}
} catch (ignore: Exception) {
}
return decorView
}
}
\ No newline at end of file
...@@ -293,7 +293,7 @@ class QmTopBar : Toolbar { ...@@ -293,7 +293,7 @@ class QmTopBar : Toolbar {
} }
private fun registerRightImgListener() { private fun registerRightImgListener() {
if (mRightImg != null) { if (mRightImg != null &&::mListenerViewClick.isInitialized ) {
mRightImg?.setOnClickListener { mRightImg?.setOnClickListener {
mListenerViewClick.rightImgClick?.invoke(it) mListenerViewClick.rightImgClick?.invoke(it)
} }
...@@ -301,11 +301,11 @@ class QmTopBar : Toolbar { ...@@ -301,11 +301,11 @@ class QmTopBar : Toolbar {
} }
private fun registerRightTextListener() { private fun registerRightTextListener() {
if (::mRightTextView.isInitialized) { if (!::mListenerViewClick.isInitialized) return
mRightTextView.setOnClickListener { mRightTextView.setOnClickListener {
mListenerViewClick.rightTextClick?.invoke(it) mListenerViewClick.rightTextClick?.invoke(it)
}
} }
} }
......
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