Commit 37323969 by 范玉宾

Manage floating window state

parent 94352583
......@@ -53,10 +53,13 @@ class MainActivity : BaseLceActivity<DemoContract.View, DemoContract.Presenter>(
DemoContract.View {
private var secretDescriptionDialog: SecretDescriptionDialog? = null
private var serviceConnection: ServiceConnection? = null
private var meditationServiceConnection:ServiceConnection? = null
private var secretDialog: SecretDialog? = null
protected var playService: PlayService? = null
private var meditationIntent:Intent?=null
protected var meditationService:MeditationWindowService?=null
override fun getContentViewId(): Int {
return R.id.lce_content_view
......@@ -89,9 +92,7 @@ class MainActivity : BaseLceActivity<DemoContract.View, DemoContract.Presenter>(
// 初始化一键登录sdk
OneKeyLoginHelp.sdkInit(this, OneKeyLoginHelp.YDL_USER_APP, PhoneNumberAuthHelper.SERVICE_TYPE_LOGIN)
bindService()
meditationIntent = Intent(this,MeditationWindowService::class.java)
startService(meditationIntent)
bindMeditationService()
reLoadData()
requestPermission()
......@@ -264,6 +265,13 @@ class MainActivity : BaseLceActivity<DemoContract.View, DemoContract.Presenter>(
bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE)
}
private fun bindMeditationService(){
val intent = Intent()
intent.setClass(this,MeditationWindowService::class.java)
meditationServiceConnection = MeditationServiceConnection()
bindService(intent,meditationServiceConnection,Context.BIND_AUTO_CREATE)
}
override fun onResume() {
super.onResume()
MobclickAgent.onResume(this)
......@@ -287,10 +295,10 @@ class MainActivity : BaseLceActivity<DemoContract.View, DemoContract.Presenter>(
if (serviceConnection != null) {
unbindService(serviceConnection)
}
if(meditationIntent!=null){
if(meditationServiceConnection!=null){
EventBus.getDefault().post(MeditationFloatEvent(false))
MediaPlayerManager.getInstance(this)?.stop()
stopService(meditationIntent)
unbindService(meditationServiceConnection)
}
if(EventBus.getDefault().isRegistered(this)){
EventBus.getDefault().unregister(this)
......@@ -308,6 +316,17 @@ class MainActivity : BaseLceActivity<DemoContract.View, DemoContract.Presenter>(
}
}
private inner class MeditationServiceConnection:ServiceConnection {
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
meditationService = (service as MeditationWindowService.MeditationBinder).service
}
override fun onServiceDisconnected(name: ComponentName?) {
}
}
private fun showEnsureDialog() {
secretDialog = SecretDialog(this, object : OnSecretDialogListener {
override fun onCancel() {
......
......@@ -28,7 +28,6 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.Objects;
import de.greenrobot.event.EventBus;
/**
* Created by haorui on 2019-10-28 .
......@@ -64,12 +63,8 @@ public class PlayFragment extends Fragment implements View.OnClickListener,
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
EventBus.getDefault().register(this);
initPlayMode();
MeditationFloatEvent event = new MeditationFloatEvent(false,true,null,null,null);
EventBus.getDefault().post(event);
onChangeImpl(AudioPlayer.Companion.get().getPlayMusic());
AudioPlayer.Companion.get().addOnPlayEventListener(this);
}
......@@ -269,9 +264,6 @@ public class PlayFragment extends Fragment implements View.OnClickListener,
public void onDestroy() {
AudioPlayer.Companion.get().removeOnPlayEventListener(this);
PlayerFloatHelper.Companion.onDestroy();
if(EventBus.getDefault().isRegistered(this)){
EventBus.getDefault().unregister(this);
}
super.onDestroy();
}
......@@ -302,8 +294,5 @@ public class PlayFragment extends Fragment implements View.OnClickListener,
ivCover = bindSource.findViewById(R.id.iv_cover);
}
public void onEventMainThread(MeditationFloatEvent event){
}
}
......@@ -10,11 +10,11 @@ ext {
"m-fm" : "0.0.30.08",
"m-user" : "0.0.62.24",
"m-home" : "0.0.23.78",
"m-im" : "0.0.21.44",
"m-im" : "0.0.21.50",
"m-dynamic" : "0.0.7.73",
"m-article" : "0.0.0.10",
"m-muse" : "0.0.28.61",
"m-muse" : "0.0.28.62",
"m-tests" : "0.0.24.18",
"m-course" : "0.0.43.37",
......@@ -35,11 +35,11 @@ ext {
//mdt 组件
"ydl-tuicore" : "0.0.23",
//第一步
"ydl-platform" : "0.0.41.20",
"ydl-platform" : "0.0.41.24",
//第二步 若干
"ydl-webview" : "0.0.38.86",
"ydl-media" : "0.0.21.44",
"ydl-media" : "0.0.21.46",
"ydl-pay" : "0.0.18.19",
"m-audioim" : "0.0.49.29.94",
"ydl-flutter-base": "0.0.14.38",
......@@ -95,11 +95,11 @@ ext {
"m-fm" : "0.0.30.08",
"m-user" : "0.0.62.24",
"m-home" : "0.0.23.78",
"m-im" : "0.0.21.44",
"m-im" : "0.0.21.50",
"m-dynamic" : "0.0.7.73",
"m-article" : "0.0.0.8",
"m-muse" : "0.0.28.61",
"m-muse" : "0.0.28.62",
"m-tests" : "0.0.24.18",
"m-course" : "0.0.43.37",
//-------------- 业务模块 API 层 --------------
......@@ -118,11 +118,11 @@ ext {
//mdt组件
"ydl-tuicore" : "0.0.23",
//第一步
"ydl-platform" : "0.0.41.20",
"ydl-platform" : "0.0.41.24",
//第二步 若干
"ydl-webview" : "0.0.38.86",
"ydl-media" : "0.0.21.44",
"ydl-media" : "0.0.21.46",
"ydl-pay" : "0.0.18.19",
"m-audioim" : "0.0.49.29.94",
"ydl-flutter-base": "0.0.14.38",
......
......@@ -104,7 +104,6 @@ public class MsgViewHolderConfirmOrder extends MsgViewHolderBase {
orderId = customAttachment.orderId;
serviceId = customAttachment.serviceId;
flag = customAttachment.status;
ToastUtil.toastShort("flag:"+flag);
if (flag == 1) {
// 1代表已确认,0代表待确认
tv_submit.setText("已确认");
......
......@@ -2,13 +2,16 @@ package com.yidianling.muse.service
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.Service
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import android.graphics.PixelFormat
import android.media.MediaPlayer
import android.os.Binder
import android.os.Build
import android.os.IBinder
import android.util.DisplayMetrics
import android.view.Gravity
import android.view.LayoutInflater
......@@ -17,14 +20,10 @@ import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import android.view.WindowManager
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.widget.AppCompatSeekBar
import androidx.core.app.NotificationCompat
import androidx.lifecycle.LifecycleService
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.GranularRoundedCorners
import com.ydl.ydlcommon.data.http.ThrowableConsumer
import com.ydl.ydlcommon.utils.actionutil.ActionCountUtils
import com.yidianling.common.tools.LogUtil
import com.yidianling.home.http.MuseHttp
import com.yidianling.muse.R
import com.yidianling.muse.activity.PlayMeditationActivity
......@@ -47,7 +46,7 @@ import java.util.*
import java.util.concurrent.TimeUnit
import kotlin.math.roundToInt
class MeditationWindowService : LifecycleService() {
class MeditationWindowService : Service() {
private lateinit var mWindowManager: WindowManager
private var floatRootView: View? = null
......@@ -74,6 +73,11 @@ class MeditationWindowService : LifecycleService() {
private var currentMediaId:Long? = null
inner class MeditationBinder : Binder() {
val service: MeditationWindowService
get() = this@MeditationWindowService
}
override fun onCreate() {
super.onCreate()
......@@ -122,7 +126,22 @@ class MeditationWindowService : LifecycleService() {
windowIsShow = true
}
fun onEventMainThread(event: MeditationFloatEvent) {
fun onEventMainThread(event: Any) {
if (event is com.ydl.ydlcommon.event.MeditationFloatEvent){
if (event.show!=null && !event.show) {
if (event.stop == true){
try {
mMediaPlayer?.stop()
}catch (e:Exception){
}
hideFloatWindow()
}
hideFloatWindow()
}
}
if (event is MeditationFloatEvent){
if (event.time!=null){
if (event.time>0){
initRxTimeOff(event.time)
......@@ -148,6 +167,8 @@ class MeditationWindowService : LifecycleService() {
updateFloatView(event.meditation)
}
}
}
}
......@@ -324,6 +345,10 @@ class MeditationWindowService : LifecycleService() {
}
}
override fun onBind(intent: Intent?): IBinder? {
return MeditationBinder()
}
private fun dp2px(dp: Float): Int {
val scale = resources.displayMetrics.density
return (dp * scale + 0.5f).toInt()
......
......@@ -13,8 +13,10 @@ import com.ydl.media.audio.manager.NotifyManager
import com.ydl.media.audio.model.Music
import com.ydl.media.audio.receiver.NoisyAudioStreamReceiver
import com.ydl.media.audio.utils.PlayProgressUtil
import com.ydl.ydlcommon.event.MeditationFloatEvent
import com.ydl.ydlcommon.utils.LogUtil
import com.yidianling.common.tools.ToastUtil
import de.greenrobot.event.EventBus
import tv.danmaku.ijk.media.player.IMediaPlayer
import tv.danmaku.ijk.media.player.IjkMediaPlayer
import java.io.IOException
......@@ -341,6 +343,10 @@ class AudioPlayer private constructor() {
listener.onPlayerStart()
}
}
val event = MeditationFloatEvent(show = false, stop = true, time = null)
EventBus.getDefault().post(event)
}
/**
......
package com.ydl.ydlcommon.event
class MeditationFloatEvent(
val show: Boolean,
val stop: Boolean? = null,
val time: Long? = null
// val meditation: MeditationPlayModuleBean.MeditationDetail? = null,
// val meditations: ArrayList<MeditationPlayModuleBean.MeditationDetail>? = null
)
\ 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