Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:支持compose #166

Merged
merged 4 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@ android {
keyPassword '19980920.'
}
}
compileSdk compilesdk_version
compileSdk 33

composeOptions {
kotlinCompilerExtensionVersion = '1.5.3'
}
buildFeatures {
compose = true
}

defaultConfig {
applicationId "com.petterp.floatingx.app"
minSdk minsdk_version
targetSdk targetsdk_version
minSdk 21
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -31,11 +38,11 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = "11"
}
packagingOptions {
resources {
Expand All @@ -47,12 +54,20 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(path: ':floatingx')
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.10"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.10"
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation "androidx.lifecycle:lifecycle-common-java8:2.3.1"
implementation project(':floatingx_compose')
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.10'
implementation platform("androidx.compose:compose-bom:2023.06.01")
implementation "androidx.compose.ui:ui:1.3.3"
implementation "androidx.compose.ui:ui-graphics"
implementation "androidx.compose.ui:ui-tooling-preview"
implementation "androidx.compose.material3:material3"
debugImplementation 'androidx.compose.ui:ui-tooling'
// debugImplementation 'com.squareup.leakcanary:leakcanary-object-watcher-android-startup:2.10'
implementation isDev ? project(path: ':floatingx') : "io.github.petterpx:floatingx:$version_name"
debugImplementation "com.bytedance.tools.codelocator:codelocator-core:2.0.3"
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
<activity
android:name=".test.SimpleRvActivity"
android:configChanges="keyboard|orientation|keyboardHidden|screenSize|smallestScreenSize|screenLayout|locale|navigation|fontScale|mcc|mnc|uiMode"
android:exported="true" />
android:exported="true" >

</activity>
</application>

</manifest>
81 changes: 7 additions & 74 deletions app/src/main/java/com/petterp/floatingx/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ class MainActivity : AppCompatActivity() {
}
}.show()
}
addItemView("开启半贴边"){
FloatingX.control(MultipleFxActivity.TAG_1).configControl.setEnableHalfHide(true)
}
addItemView("隐藏半贴边"){
FloatingX.control(MultipleFxActivity.TAG_1).configControl.setEnableHalfHide(false)
}
addItemView("隐藏全局悬浮窗") {
FloatingX.control(MultipleFxActivity.TAG_1).hide()
}
Expand All @@ -62,7 +68,6 @@ class MainActivity : AppCompatActivity() {
this.updateViewContent {
it.setText(R.id.tvItemFx, "App")
}
gravity=
}.show()
}
addItemView("更新当前[全局浮窗]内容-(传递view方式)") {
Expand Down Expand Up @@ -95,51 +100,12 @@ class MainActivity : AppCompatActivity() {
.setCardBackgroundColor(Color.GREEN)
}
}
addItemView("显示windows级别悬浮窗") {
// val config =
// FxAppHelper.builder().setLayout(R.layout.item_floating)
// .setEnableLog(true, "windows")
// .setContext(applicationContext).build()
// val layoutParam = WindowManager.LayoutParams().apply {
// // 设置大小 自适应
// width = WindowManager.LayoutParams.WRAP_CONTENT
// height = WindowManager.LayoutParams.WRAP_CONTENT
// format = PixelFormat.TRANSPARENT
// /**
// * 注意,flag的值可以为:
// * 下面的flags属性的效果形同“锁定”。
// * 悬浮窗不可触摸,不接受任何事件,同时不影响后面的事件响应。
// * LayoutParams.FLAG_NOT_TOUCH_MODAL 不影响后面的事件
// * LayoutParams.FLAG_NOT_FOCUSABLE 不可聚焦
// * LayoutParams.FLAG_NOT_TOUCHABLE 不可触摸
// */
// flags =
// WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
// type = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
// } else {
// WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
// }
// }
// val fx = FxManagerView(applicationContext).init(config)
// fx.windowManager = windowManager
// windowManager.addView(fx, layoutParam)
windowManager
}
addItemView("进入测试页面") {
TestActivity::class.java.start(this@MainActivity)
}
addItemView("进入system浮窗测试页面") {
SystemActivity::class.java.start(this@MainActivity)
}

var halfHide = false
addItemView("切换半隐状态") {
FloatingX.control(MultipleFxActivity.TAG_1).apply {
halfHide = !halfHide
configControl.setEnableHalfHide(halfHide)
}
}
}
}
}
Expand All @@ -161,37 +127,4 @@ class MainActivity : AppCompatActivity() {
addView(viewGroup)
return viewGroup
}
}

// class ItemViewTouchListener(val wl: WindowManager.LayoutParams, val windowManager: WindowManager) :
// View.OnTouchListener {
// private var x = 0
// private var y = 0
// override fun onTouch(view: View, motionEvent: MotionEvent): Boolean {
// when (motionEvent.action) {
// MotionEvent.ACTION_DOWN -> {
// x = motionEvent.rawX.toInt()
// y = motionEvent.rawY.toInt()
// }
//
// MotionEvent.ACTION_MOVE -> {
// val nowX = motionEvent.rawX.toInt()
// val nowY = motionEvent.rawY.toInt()
// val movedX = nowX - x
// val movedY = nowY - y
// x = nowX
// y = nowY
// wl.apply {
// x += movedX
// y += movedY
// }
// // 更新悬浮球控件位置
// windowManager?.updateViewLayout(view, wl)
// }
//
// else -> {
// }
// }
// return false
// }
// }
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
package com.petterp.floatingx.app.kotlin

import android.app.AlertDialog
import android.app.Application
import android.graphics.Color
import android.view.Gravity
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import android.widget.Toast
import androidx.cardview.widget.CardView
import com.petterp.floatingx.FloatingX
import com.petterp.floatingx.app.*
import com.petterp.floatingx.app.simple.FxAnimationImpl
import com.petterp.floatingx.app.test.BlackActivity
import com.petterp.floatingx.app.test.ImmersedActivity
import com.petterp.floatingx.app.test.MultipleFxActivity
import com.petterp.floatingx.app.test.ScopeActivity
import com.petterp.floatingx.assist.FxDisplayMode
import com.petterp.floatingx.assist.FxGravity
import com.petterp.floatingx.assist.FxScopeType
import com.petterp.floatingx.listener.IFxProxyTagActivityLifecycle
import com.petterp.floatingx.listener.IFxTouchListener
import com.petterp.floatingx.listener.IFxViewLifecycle
import com.petterp.floatingx.util.FxScrollImpl
import com.petterp.floatingx.view.IFxInternalHelper

/** Kotlin-Application */
Expand All @@ -45,169 +35,8 @@ class CustomKtApplication : Application() {
// setTag(MultipleFxActivity.TAG_1)
// }

installTag1(this)
installTag2(this)
}

companion object {

fun installTag1(context: Application) {
FloatingX.install {
setContext(context)
setScopeType(FxScopeType.APP)
// 设置浮窗展示类型,默认可移动可点击,无需配置
setDisplayMode(FxDisplayMode.Normal)
setLayout(R.layout.item_floating)
// 设置权限拦截器
setPermissionInterceptor { activity, controller ->
AlertDialog.Builder(activity).setTitle("提示").setMessage("需要允许悬浮窗权限")
.setPositiveButton("去开启") { _, _ ->
Toast.makeText(
activity.applicationContext,
"去申请权限中~",
Toast.LENGTH_SHORT,
).show()
controller.requestPermission(
activity,
isAutoShow = true,
canUseAppScope = true,
) {
Toast.makeText(
activity.applicationContext,
"申请权限结果: $it",
Toast.LENGTH_SHORT,
).show()
}
}.setNegativeButton("取消") { _, _ ->
Toast.makeText(
activity.applicationContext,
"降级为App浮窗~",
Toast.LENGTH_SHORT,
).show()
controller.downgradeToAppScope()
}.show()
}
// 设置悬浮窗默认方向
setGravity(FxGravity.TOP_OR_CENTER)
// 设置偏移位置
setOffsetXY(100f, 100f)
// 设置启用边缘吸附,默认启用
setEnableEdgeAdsorption(true)
// 设置边缘偏移量
setEdgeOffset(10f)
// 设置启用悬浮窗可屏幕外回弹
setEnableScrollOutsideScreen(true)
// 开启历史位置缓存
// setSaveDirectionImpl(FxConfigStorageToSpImpl(context))
// 设置启用动画
setEnableAnimation(true)
// 设置启用动画实现
setAnimationImpl(FxAnimationImpl())
// 设置移动边框
setBorderMargin(50f, 50f, 50f, 50f)

//支持半隐
setEnableHalfHide(true)
setHalfHidePercent(0.3f)

/** 指定浮窗可显示的activity方式 */
// 1.设置是否允许所有activity都进行显示,默认true
setEnableAllInstall(true)
// 2.禁止插入Activity的页面, setEnableAllBlackClass(true)时,此方法生效
addInstallBlackClass(BlackActivity::class.java)
// 3.允许插入Activity的页面, setEnableAllBlackClass(false)时,此方法生效
addInstallWhiteClass(
MainActivity::class.java,
ImmersedActivity::class.java,
ScopeActivity::class.java,
)
// 设置点击事件
setOnClickListener {
Toast.makeText(context, "浮窗被点击", Toast.LENGTH_SHORT).show()
}
setOnLongClickListener {
Toast.makeText(context, "浮窗被长按", Toast.LENGTH_SHORT).show()
true
}
// 设置tag-Activity生命周期回调时的触发
setTagActivityLifecycle(object : IFxProxyTagActivityLifecycle {
})
// 增加生命周期监听
setViewLifecycle(object : IFxViewLifecycle {
override fun initView(view: View) {
view.findViewById<View>(R.id.tvItemFx).setOnClickListener {
Toast.makeText(context, "子view点击", Toast.LENGTH_SHORT).show()
}
}

override fun attach() {
}

override fun detached() {
}
})
// 设置滑动监听
setTouchListener(object : FxScrollImpl() {
override fun down() {
// 按下
}

override fun up() {
// 释放
}

override fun dragIng(event: MotionEvent, x: Float, y: Float) {
// 正在拖动
}

override fun eventIng(event: MotionEvent) {
// 接收所有事件传递
}
})
// 设置是否启用日志
setEnableLog(BuildConfig.DEBUG)
// 设置浮窗tag
setTag(MultipleFxActivity.TAG_1)
}.show()
}

fun installTag2(context: Application) {
FloatingX.install {
setContext(context)
setScopeType(FxScopeType.APP)
setGravity(FxGravity.LEFT_OR_BOTTOM)
setOffsetXY(10f, 10f)
setLayoutView(
CardView(context).apply {
setCardBackgroundColor(Color.GRAY)
radius = 30.dpF
addView(
TextView(this.context).apply {
layoutParams = ViewGroup.LayoutParams(
-2,
60.dp,
)
gravity = Gravity.CENTER
text = "浮窗2-act"
setTextColor(Color.WHITE)
textSize = 15f
},
)
},
)
setTouchListener(object : IFxTouchListener {
override fun onTouch(event: MotionEvent, control: IFxInternalHelper?): Boolean {
return false
}
})
setOnClickListener {
Toast.makeText(context, "浮窗2被点击", Toast.LENGTH_SHORT).show()
}
setTag(MultipleFxActivity.TAG_2)
setEnableLog(true)
setEdgeOffset(20f)
setEnableEdgeAdsorption(false)
}.show()
}
FxSystemSimple.install(this)
FxAppSimple.install(this)
FxComposeSimple.install(this)
}
}
Loading
Loading