Commit d48b9df8 authored by mengcuiguang's avatar mengcuiguang

代码优化

parent 2d3ab50a
......@@ -220,6 +220,8 @@ dependencies {
implementation 'com.airbnb.android:lottie:3.4.0'
// 跑马灯
implementation 'com.sunfusheng:MarqueeView:1.4.1'
// 悬浮窗
implementation 'com.github.princekin-f:EasyFloat:1.3.4'
// 工具类
// BASE64Decoder接入
// 兼容奔溃问题-Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
......
......@@ -5,6 +5,7 @@ import android.content.Intent
import android.media.AudioManager
import android.net.Uri
import android.os.Bundle
import android.view.Gravity
import android.view.KeyEvent
import android.view.View
import android.widget.TextView
......@@ -22,6 +23,10 @@ import com.duben.happyplaylet.ui.fragment.RecommendFragment
import com.duben.happyplaylet.ui.widgets.DialogListener
import com.duben.happyplaylet.ui.widgets.PhoneDialog
import com.duben.happyplaylet.video.csj.DPHolderManager
import com.lzf.easyfloat.EasyFloat
import com.lzf.easyfloat.anim.AppFloatDefaultAnimator
import com.lzf.easyfloat.anim.DefaultAnimator
import com.lzf.easyfloat.enums.SidePattern
import kotlinx.android.synthetic.main.activity_main.*
/**
......@@ -79,7 +84,7 @@ class MainActivity : BaseActivity(), View.OnClickListener {
initEditView()
initEasyFloat()
}
override fun isApplyKitKatTranslucency(): Boolean {
......@@ -286,4 +291,52 @@ class MainActivity : BaseActivity(), View.OnClickListener {
ll_bottom_tab.background = ContextCompat.getDrawable(context, R.color.white)
}
}
private fun initEasyFloat() {
EasyFloat.with(this)
// 设置浮窗xml布局文件,并可设置详细信息
.setLayout(R.layout.float_app) {
it.findViewById<TextView>(R.id.tv_float).setOnClickListener { backPhoneDialog() }
}
// 设置吸附方式,共15种模式,详情参考SidePattern
.setSidePattern(SidePattern.RESULT_HORIZONTAL)
// 设置浮窗是否可拖拽,默认可拖拽
.setDragEnable(false)
// 系统浮窗是否包含EditText,仅针对系统浮窗,默认不包含
.hasEditText(false)
// 设置浮窗的对齐方式和坐标偏移量
.setGravity( Gravity.CENTER_VERTICAL, 0, 200)
// 设置宽高是否充满父布局,直接在xml设置match_parent属性无效
.setMatchParent(widthMatch = false, heightMatch = false)
// 设置Activity浮窗的出入动画,可自定义,实现相应接口即可(策略模式),无需动画直接设置为null
.setAnimator(DefaultAnimator())
// 设置系统浮窗的出入动画,使用同上
.setAppFloatAnimator(AppFloatDefaultAnimator())
// 设置系统浮窗的不需要显示的页面
// 浮窗的一些状态回调,如:创建结果、显示、隐藏、销毁、touchEvent、拖拽过程、拖拽结束。
// ps:通过Kotlin DSL实现的回调,可以按需复写方法,用到哪个写哪个
.registerCallback {
createResult { isCreated, msg, view -> }
show { }
hide { }
dismiss { }
touchEvent { view, motionEvent -> }
// drag { view, motionEvent ->
// view.findViewById<TextView>(R.id.tv_float).apply {
// text = "我被拖拽..."
// setBackgroundResource(R.drawable.shape_banner_write)
// }
// }
dragEnd {
it.findViewById<TextView>(R.id.tv_float).apply {
text = "联系\n客服"
val location = IntArray(2)
getLocationOnScreen(location)
setBackgroundResource(if (location[0] > 10) R.drawable.shape_phone_left else R.drawable.shape_phone_right)
}
}
}
.show()
}
}
\ No newline at end of file
......@@ -5,7 +5,6 @@
<solid android:color="@color/my_color_gray" />
<!-- 设置按钮的四个角为弧形 -->
<!-- android:radius 弧形的半径 -->
<corners android:bottomLeftRadius="30dp"
android:topLeftRadius="30dp"/>
<corners android:radius="5dp"/>
</shape>
\ No newline at end of file
......@@ -4,15 +4,15 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/shape_phone_left"
android:drawableLeft="@mipmap/ic_kefu"
android:drawablePadding="4dp"
android:drawableTop="@mipmap/ic_kefu"
android:drawablePadding="8dp"
android:gravity="center"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:paddingLeft="10dp"
android:paddingLeft="4dp"
android:paddingTop="10dp"
android:paddingRight="4dp"
android:paddingBottom="10dp"
android:text="联\n系\n客\n服"
android:textColor="@color/black"
android:paddingRight="10dp"
android:textSize="11sp"
android:text="联系\n客服">
android:textSize="11sp">
</TextView>
\ 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