From 05d4b29991a1d6003c27541f387d1b8f27932c5d Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Fri, 21 Oct 2022 15:52:53 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=B4=E6=92=AD=E5=86=85=E6=92=AD=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/floatingview/APPEasyFloat.java | 172 ++++++++++++ .../views/floatingview/EnFloatingView.java | 39 +++ .../floatingview/FloatingMagnetView.java | 252 ++++++++++++++++++ .../views/floatingview/FloatingView.java | 219 +++++++++++++++ .../views/floatingview/IFloatingView.java | 45 ++++ .../floatingview/MagnetViewListener.java | 10 + .../views/floatingview/utils/EnContext.java | 33 +++ .../views/floatingview/utils/SystemUtils.java | 39 +++ .../common/views/weight/LiveFloatView.java | 46 +++- live/src/main/AndroidManifest.xml | 17 +- .../activity/FALiveRoomInOneActivity.java | 36 +++ .../live/activity/LiveAudienceActivity.java | 26 ++ .../live/views/PortraitLiveManager.java | 3 +- .../yunbao/main/activity/MainActivity.java | 15 +- 14 files changed, 928 insertions(+), 24 deletions(-) create mode 100644 common/src/main/java/com/yunbao/common/views/floatingview/APPEasyFloat.java create mode 100644 common/src/main/java/com/yunbao/common/views/floatingview/EnFloatingView.java create mode 100644 common/src/main/java/com/yunbao/common/views/floatingview/FloatingMagnetView.java create mode 100644 common/src/main/java/com/yunbao/common/views/floatingview/FloatingView.java create mode 100644 common/src/main/java/com/yunbao/common/views/floatingview/IFloatingView.java create mode 100644 common/src/main/java/com/yunbao/common/views/floatingview/MagnetViewListener.java create mode 100644 common/src/main/java/com/yunbao/common/views/floatingview/utils/EnContext.java create mode 100644 common/src/main/java/com/yunbao/common/views/floatingview/utils/SystemUtils.java create mode 100644 live/src/main/java/com/yunbao/live/activity/FALiveRoomInOneActivity.java diff --git a/common/src/main/java/com/yunbao/common/views/floatingview/APPEasyFloat.java b/common/src/main/java/com/yunbao/common/views/floatingview/APPEasyFloat.java new file mode 100644 index 000000000..dae2d455e --- /dev/null +++ b/common/src/main/java/com/yunbao/common/views/floatingview/APPEasyFloat.java @@ -0,0 +1,172 @@ +package com.yunbao.common.views.floatingview; + +import android.app.Activity; +import android.app.Application; +import android.os.Bundle; +import android.view.Gravity; +import android.widget.FrameLayout; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import java.util.ArrayList; +import java.util.List; + +public class APPEasyFloat implements Application.ActivityLifecycleCallbacks { + private List> blackList = new ArrayList<>(); + private int mLayout = 0; + private FrameLayout.LayoutParams mLayoutParams = getFloatingLayoutParams(); + private boolean dragEnable = true; + private boolean autoMoveToEdge = true; + private static APPEasyFloat instance; + private MagnetViewListener magnetViewListener; + + public APPEasyFloat setMagnetViewListener(MagnetViewListener magnetViewListener) { + this.magnetViewListener = magnetViewListener; + return this; + } + + public static APPEasyFloat getInstance() { + if (instance == null) { + instance = new APPEasyFloat(); + } + + return instance; + } + + public APPEasyFloat layout(int layout) { + mLayout = layout; + return this; + } + + public APPEasyFloat layoutParams(FrameLayout.LayoutParams layoutParams) { + mLayoutParams = layoutParams; + return this; + } + + public APPEasyFloat blackList(List> blackList) { + this.blackList.addAll(blackList); + return this; + } + + public APPEasyFloat black(Class back) { + this.blackList.add(back); + return this; + } + + /** + * 是否可拖拽(位置是否固定) + */ + public APPEasyFloat dragEnable(boolean dragEnable) { + this.dragEnable = dragEnable; + FloatingView.get().dragEnable(dragEnable); + return this; + } + + public boolean isDragEnable() { + + return dragEnable; + } + + /** + * 是否自动靠边 + */ + public APPEasyFloat setAutoMoveToEdge(boolean autoMoveToEdge) { + this.autoMoveToEdge = autoMoveToEdge; + FloatingView.get().setAutoMoveToEdge(autoMoveToEdge); + return this; + } + + public boolean isAutoMoveToEdge() { + return autoMoveToEdge; + } + + private boolean isActivityInValid(Activity activity) { + return blackList.contains(activity.getClass()); + } + + @Override + public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) { + + } + + @Override + public void onActivityStarted(@NonNull Activity activity) { + if (isActivityInValid(activity)) { + return; + } + initShow(activity); + } + + @Override + public void onActivityResumed(@NonNull Activity activity) { + if (isActivityInValid(activity)) + return; + + } + + @Override + public void onActivityPaused(@NonNull Activity activity) { + + } + + @Override + public void onActivityStopped(@NonNull Activity activity) { + if (isActivityInValid(activity)) { + return; + } + if (magnetViewListener != null) { + magnetViewListener.onRemove(); + } + FloatingView.get().detach(activity); + + } + + @Override + public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) { + + } + + @Override + public void onActivityDestroyed(@NonNull Activity activity) { + + } + + + private FrameLayout.LayoutParams getFloatingLayoutParams() { + FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( + FrameLayout.LayoutParams.WRAP_CONTENT, + FrameLayout.LayoutParams.WRAP_CONTENT + ); + params.gravity = Gravity.BOTTOM | Gravity.END; + params.setMargins(0, params.topMargin, params.rightMargin, 500); + return params; + } + + private void initShow(Activity activity) { + if (FloatingView.get().getContainer() == null) { + EnFloatingView enFloatingView = new EnFloatingView(activity, mLayout); + FloatingView.get().customView(enFloatingView); + if (magnetViewListener != null) { + magnetViewListener.invoke(enFloatingView); + } + } + FloatingView.get(). + layoutParams(mLayoutParams). + attach(activity). + dragEnable(dragEnable); + + + } + + public void show(Activity activity) { + initShow(activity); + activity.getApplication().registerActivityLifecycleCallbacks(this); + } + + public void dismiss(Activity activity) { + FloatingView.get().remove(); + FloatingView.get().detach(activity); + activity.getApplication().unregisterActivityLifecycleCallbacks(this); + } +} diff --git a/common/src/main/java/com/yunbao/common/views/floatingview/EnFloatingView.java b/common/src/main/java/com/yunbao/common/views/floatingview/EnFloatingView.java new file mode 100644 index 000000000..4a19d209a --- /dev/null +++ b/common/src/main/java/com/yunbao/common/views/floatingview/EnFloatingView.java @@ -0,0 +1,39 @@ +package com.yunbao.common.views.floatingview; + +import android.content.Context; +import android.widget.ImageView; + +import androidx.annotation.DrawableRes; +import androidx.annotation.LayoutRes; +import androidx.annotation.NonNull; + +import com.yunbao.common.R; + + +/** + * @ClassName EnFloatingView + * @Description 悬浮窗 + * @Author Yunpeng Li + * @Creation 2018/3/15 下午5:04 + * @Mender Yunpeng Li + * @Modification 2018/3/15 下午5:04 + */ +public class EnFloatingView extends FloatingMagnetView { + + private final ImageView mIcon; + + public EnFloatingView(@NonNull Context context) { + this(context, R.layout.view_flaot_live); + } + + public EnFloatingView(@NonNull Context context, @LayoutRes int resource) { + super(context, null); + inflate(context, resource, this); + mIcon = findViewById(R.id.icon); + } + + public void setIconImage(@DrawableRes int resId){ + mIcon.setImageResource(resId); + } + +} diff --git a/common/src/main/java/com/yunbao/common/views/floatingview/FloatingMagnetView.java b/common/src/main/java/com/yunbao/common/views/floatingview/FloatingMagnetView.java new file mode 100644 index 000000000..bf9142925 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/views/floatingview/FloatingMagnetView.java @@ -0,0 +1,252 @@ +package com.yunbao.common.views.floatingview; + +import android.content.Context; +import android.content.res.Configuration; +import android.os.Handler; +import android.os.Looper; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.view.ViewConfiguration; +import android.view.ViewGroup; +import android.widget.FrameLayout; + +import com.yunbao.common.views.floatingview.utils.SystemUtils; + + +public class FloatingMagnetView extends FrameLayout { + + public static final int MARGIN_EDGE = 13; + private float mOriginalRawX; + private float mOriginalRawY; + private float mOriginalX; + private float mOriginalY; + private static final int TOUCH_TIME_THRESHOLD = 150; + private long mLastTouchDownTime; + protected MoveAnimator mMoveAnimator; + protected int mScreenWidth; + private int mScreenHeight; + private int mStatusBarHeight; + private boolean isNearestLeft = true; + private float mPortraitY; + private boolean dragEnable = true; + private boolean autoMoveToEdge = false; + + + public FloatingMagnetView(Context context) { + this(context, null); + } + + public FloatingMagnetView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public FloatingMagnetView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(); + } + + private void init() { + mMoveAnimator = new MoveAnimator(); + mStatusBarHeight = SystemUtils.getStatusBarHeight(getContext()); + setClickable(true); +// updateSize(); + } + + /** + * @param dragEnable 是否可拖动 + */ + public void updateDragState(boolean dragEnable) { + this.dragEnable = dragEnable; + } + + /** + * @param autoMoveToEdge 是否自动到边缘 + */ + public void setAutoMoveToEdge(boolean autoMoveToEdge) { + this.autoMoveToEdge = autoMoveToEdge; + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + if (event == null) { + return false; + } + switch (event.getAction()) { + case MotionEvent.ACTION_DOWN: + break; + case MotionEvent.ACTION_MOVE: + updateViewPosition(event); + break; + case MotionEvent.ACTION_UP: + clearPortraitY(); + if (autoMoveToEdge) { + moveToEdge(); + } + + break; + } + return true; + } + + + private void updateViewPosition(MotionEvent event) { + //dragEnable + if (!dragEnable) return; + //占满width或height时不用变 + LayoutParams params = (LayoutParams) getLayoutParams(); + //限制不可超出屏幕宽度 + float desX = mOriginalX + event.getRawX() - mOriginalRawX; + if (params.width == LayoutParams.WRAP_CONTENT) { + if (desX < 0) { + desX = MARGIN_EDGE; + } + if (desX > mScreenWidth) { + desX = mScreenWidth - MARGIN_EDGE; + } + setX(desX); + } + // 限制不可超出屏幕高度 + float desY = mOriginalY + event.getRawY() - mOriginalRawY; + if (params.height == LayoutParams.WRAP_CONTENT) { + if (desY < mStatusBarHeight) { + desY = mStatusBarHeight; + } + if (desY > mScreenHeight - getHeight()) { + desY = mScreenHeight - getHeight(); + } + setY(desY); + } + } + + private void changeOriginalTouchParams(MotionEvent event) { + mOriginalX = getX(); + mOriginalY = getY(); + mOriginalRawX = event.getRawX(); + mOriginalRawY = event.getRawY(); + mLastTouchDownTime = System.currentTimeMillis(); + } + + protected void updateSize() { + ViewGroup viewGroup = (ViewGroup) getParent(); + if (viewGroup != null) { + mScreenWidth = viewGroup.getWidth() - getWidth(); + mScreenHeight = viewGroup.getHeight(); + } +// mScreenWidth = (SystemUtils.getScreenWidth(getContext()) - this.getWidth()); +// mScreenHeight = SystemUtils.getScreenHeight(getContext()); + } + + public void moveToEdge() { + //dragEnable + if (!dragEnable) return; + moveToEdge(isNearestLeft(), false); + } + + public void moveToEdge(boolean isLeft, boolean isLandscape) { + float moveDistance = isLeft ? MARGIN_EDGE : mScreenWidth - MARGIN_EDGE; + float y = getY(); + if (!isLandscape && mPortraitY != 0) { + y = mPortraitY; + clearPortraitY(); + } + mMoveAnimator.start(moveDistance, Math.min(Math.max(0, y), mScreenHeight - getHeight())); + } + + private void clearPortraitY() { + mPortraitY = 0; + } + + protected boolean isNearestLeft() { + int middle = mScreenWidth / 2; + isNearestLeft = getX() < middle; + return isNearestLeft; + } + + + protected class MoveAnimator implements Runnable { + + private Handler handler = new Handler(Looper.getMainLooper()); + private float destinationX; + private float destinationY; + private long startingTime; + + void start(float x, float y) { + this.destinationX = x; + this.destinationY = y; + startingTime = System.currentTimeMillis(); + handler.post(this); + } + + @Override + public void run() { + if (getRootView() == null || getRootView().getParent() == null) { + return; + } + float progress = Math.min(1, (System.currentTimeMillis() - startingTime) / 400f); + float deltaX = (destinationX - getX()) * progress; + float deltaY = (destinationY - getY()) * progress; + move(deltaX, deltaY); + if (progress < 1) { + handler.post(this); + } + } + + private void stop() { + handler.removeCallbacks(this); + } + } + + private void move(float deltaX, float deltaY) { + setX(getX() + deltaX); + setY(getY() + deltaY); + } + + @Override + protected void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + if (getParent() != null) { + final boolean isLandscape = newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE; + markPortraitY(isLandscape); + ((ViewGroup) getParent()).post(new Runnable() { + @Override + public void run() { + updateSize(); + moveToEdge(isNearestLeft, isLandscape); + } + }); + } + } + + private void markPortraitY(boolean isLandscape) { + if (isLandscape) { + mPortraitY = getY(); + } + } + + private float touchDownX; + + private void initTouchDown(MotionEvent ev) { + changeOriginalTouchParams(ev); + updateSize(); + mMoveAnimator.stop(); + } + + @Override + public boolean onInterceptTouchEvent(MotionEvent ev) { + boolean intercepted = false; + switch (ev.getActionMasked()) { + case MotionEvent.ACTION_DOWN: + intercepted = false; + touchDownX = ev.getX(); + initTouchDown(ev); + break; + case MotionEvent.ACTION_MOVE: + intercepted = Math.abs(touchDownX - ev.getX()) >= ViewConfiguration.get(getContext()).getScaledTouchSlop(); + break; + case MotionEvent.ACTION_UP: + intercepted = false; + break; + } + return intercepted; + } +} diff --git a/common/src/main/java/com/yunbao/common/views/floatingview/FloatingView.java b/common/src/main/java/com/yunbao/common/views/floatingview/FloatingView.java new file mode 100644 index 000000000..48fe060b2 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/views/floatingview/FloatingView.java @@ -0,0 +1,219 @@ +package com.yunbao.common.views.floatingview; + +import android.app.Activity; +import android.os.Handler; +import android.os.Looper; +import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.widget.FrameLayout; +import android.widget.RelativeLayout; + +import androidx.annotation.DrawableRes; +import androidx.annotation.LayoutRes; +import androidx.core.view.ViewCompat; + +import com.yunbao.common.R; +import com.yunbao.common.views.floatingview.utils.EnContext; + +import java.lang.ref.WeakReference; + + +/** + * @ClassName FloatingView + * @Description 悬浮窗管理器 + * @Author Yunpeng Li + * @Creation 2018/3/15 下午5:05 + * @Mender Yunpeng Li + * @Modification 2018/3/15 下午5:05 + */ +public class FloatingView implements IFloatingView { + + private FloatingMagnetView mEnFloatingView; + private static volatile FloatingView mInstance; + private WeakReference mContainer; + @LayoutRes + private int mLayoutId = R.layout.view_flaot_live; + @DrawableRes + private int mIconRes = R.drawable.com_facebook_button_icon; + private ViewGroup.LayoutParams mLayoutParams = getParams(); + + private FloatingView() { + } + + public static FloatingView get() { + if (mInstance == null) { + synchronized (FloatingView.class) { + if (mInstance == null) { + mInstance = new FloatingView(); + } + } + } + return mInstance; + } + + @Override + public FloatingView remove() { + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + if (mEnFloatingView == null) { + return; + } + if (ViewCompat.isAttachedToWindow(mEnFloatingView) && getContainer() != null) { + getContainer().removeView(mEnFloatingView); + } + mEnFloatingView = null; + } + }); + return this; + } + + private void ensureFloatingView() { + synchronized (this) { + if (mEnFloatingView != null) { + return; + } + EnFloatingView enFloatingView = new EnFloatingView(EnContext.get(), mLayoutId); + mEnFloatingView = enFloatingView; + enFloatingView.setLayoutParams(mLayoutParams); + enFloatingView.setIconImage(mIconRes); + addViewToWindow(enFloatingView); + } + } + + @Override + public FloatingView add() { + ensureFloatingView(); + return this; + } + + @Override + public FloatingView attach(Activity activity) { + attach(getActivityRoot(activity)); + return this; + } + + @Override + public FloatingView attach(FrameLayout container) { + if (container == null || mEnFloatingView == null) { + mContainer = new WeakReference<>(container); + return this; + } + if (mEnFloatingView.getParent() == container) { + return this; + } + if (mEnFloatingView.getParent() != null) { + ((ViewGroup) mEnFloatingView.getParent()).removeView(mEnFloatingView); + } + mContainer = new WeakReference<>(container); + container.addView(mEnFloatingView); + return this; + } + + @Override + public FloatingView detach(Activity activity) { + detach(getActivityRoot(activity)); + return this; + } + + @Override + public FloatingView detach(FrameLayout container) { + if (mEnFloatingView != null && container != null && ViewCompat.isAttachedToWindow(mEnFloatingView)) { + container.removeView(mEnFloatingView); + } + if (getContainer() == container) { + mContainer = null; + } + return this; + } + + @Override + public FloatingMagnetView getView() { + return mEnFloatingView; + } + + @Override + public FloatingView icon(@DrawableRes int resId) { + mIconRes = resId; + return this; + } + + @Override + public FloatingView customView(FloatingMagnetView viewGroup) { + mEnFloatingView = viewGroup; + return this; + } + + @Override + public FloatingView customView(@LayoutRes int resource) { + mLayoutId = resource; + return this; + } + + @Override + public FloatingView layoutParams(ViewGroup.LayoutParams params) { + mLayoutParams = params; + if (mEnFloatingView != null) { + mEnFloatingView.setLayoutParams(params); + } + return this; + } + + @Override + public FloatingView listener(MagnetViewListener magnetViewListener) { + + return this; + } + + @Override + public FloatingView dragEnable(boolean dragEnable) { + if (mEnFloatingView != null) { + mEnFloatingView.updateDragState(dragEnable); + } + return this; + } + + @Override + public FloatingView setAutoMoveToEdge(boolean autoMoveToEdge) { + if (mEnFloatingView != null) { + mEnFloatingView.setAutoMoveToEdge(autoMoveToEdge); + } + return this; + } + + private void addViewToWindow(final View view) { + if (getContainer() == null) { + return; + } + getContainer().addView(view); + } + + public FrameLayout getContainer() { + if (mContainer == null) { + return null; + } + return mContainer.get(); + } + + private FrameLayout.LayoutParams getParams() { + FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( + RelativeLayout.LayoutParams.WRAP_CONTENT, + RelativeLayout.LayoutParams.WRAP_CONTENT); + params.gravity = Gravity.BOTTOM | Gravity.START; + params.setMargins(13, params.topMargin, params.rightMargin, 500); + return params; + } + + private FrameLayout getActivityRoot(Activity activity) { + if (activity == null) { + return null; + } + try { + return (FrameLayout) activity.getWindow().getDecorView().findViewById(android.R.id.content); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } +} \ No newline at end of file diff --git a/common/src/main/java/com/yunbao/common/views/floatingview/IFloatingView.java b/common/src/main/java/com/yunbao/common/views/floatingview/IFloatingView.java new file mode 100644 index 000000000..4f2410c45 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/views/floatingview/IFloatingView.java @@ -0,0 +1,45 @@ +package com.yunbao.common.views.floatingview; + +import android.app.Activity; +import android.view.ViewGroup; +import android.widget.FrameLayout; + +import androidx.annotation.DrawableRes; +import androidx.annotation.LayoutRes; + + +/** + * Created by Yunpeng Li on 2018/3/15. + */ + +public interface IFloatingView { + + FloatingView remove(); + + FloatingView add(); + + FloatingView attach(Activity activity); + + FloatingView attach(FrameLayout container); + + FloatingView detach(Activity activity); + + FloatingView detach(FrameLayout container); + + FloatingMagnetView getView(); + + FloatingView icon(@DrawableRes int resId); + + FloatingView customView(FloatingMagnetView viewGroup); + + FloatingView customView(@LayoutRes int resource); + + FloatingView layoutParams(ViewGroup.LayoutParams params); + + FloatingView listener(MagnetViewListener magnetViewListener); + + FloatingView dragEnable(boolean dragEnable); + + FloatingView setAutoMoveToEdge(boolean autoMoveToEdge); + +} diff --git a/common/src/main/java/com/yunbao/common/views/floatingview/MagnetViewListener.java b/common/src/main/java/com/yunbao/common/views/floatingview/MagnetViewListener.java new file mode 100644 index 000000000..ea41fa0eb --- /dev/null +++ b/common/src/main/java/com/yunbao/common/views/floatingview/MagnetViewListener.java @@ -0,0 +1,10 @@ +package com.yunbao.common.views.floatingview; + +/** + * Created by liyunpeng on 17/11/29. + */ +public interface MagnetViewListener { + void invoke(FloatingMagnetView magnetView); + + void onRemove(); +} diff --git a/common/src/main/java/com/yunbao/common/views/floatingview/utils/EnContext.java b/common/src/main/java/com/yunbao/common/views/floatingview/utils/EnContext.java new file mode 100644 index 000000000..00dc3c666 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/views/floatingview/utils/EnContext.java @@ -0,0 +1,33 @@ +package com.yunbao.common.views.floatingview.utils; + +import android.app.Application; + +/** + * Created by Yunpeng Li on 2018/11/8. + */ +public class EnContext { + + private static final Application INSTANCE; + + static { + Application app = null; + try { + app = (Application) Class.forName("android.app.AppGlobals").getMethod("getInitialApplication").invoke(null); + if (app == null) + throw new IllegalStateException("Static initialization of Applications must be on main thread."); + } catch (final Exception e) { + e.printStackTrace(); + try { + app = (Application) Class.forName("android.app.ActivityThread").getMethod("currentApplication").invoke(null); + } catch (final Exception ex) { + e.printStackTrace(); + } + } finally { + INSTANCE = app; + } + } + + public static Application get() { + return INSTANCE; + } +} diff --git a/common/src/main/java/com/yunbao/common/views/floatingview/utils/SystemUtils.java b/common/src/main/java/com/yunbao/common/views/floatingview/utils/SystemUtils.java new file mode 100644 index 000000000..c219be148 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/views/floatingview/utils/SystemUtils.java @@ -0,0 +1,39 @@ +package com.yunbao.common.views.floatingview.utils; + +import android.content.Context; + +/** + * Created by Yunpeng Li on 2018/3/15. + */ +public class SystemUtils { + + public static int getStatusBarHeight(Context context) { + int result = 0; + int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android"); + if (resourceId > 0) { + result = context.getResources().getDimensionPixelSize(resourceId); + } + return result; + } + + public static int getScreenWidth(Context context) { + int screenWith = -1; + try { + screenWith = context.getResources().getDisplayMetrics().widthPixels; + } catch (Exception e) { + e.printStackTrace(); + } + return screenWith; + } + + public static int getScreenHeight(Context context) { + int screenHeight = -1; + try { + screenHeight = context.getResources().getDisplayMetrics().heightPixels; + } catch (Exception e) { + e.printStackTrace(); + } + return screenHeight; + } + +} diff --git a/common/src/main/java/com/yunbao/common/views/weight/LiveFloatView.java b/common/src/main/java/com/yunbao/common/views/weight/LiveFloatView.java index e8b4a0422..8e13863b3 100644 --- a/common/src/main/java/com/yunbao/common/views/weight/LiveFloatView.java +++ b/common/src/main/java/com/yunbao/common/views/weight/LiveFloatView.java @@ -15,6 +15,9 @@ import com.tencent.rtmp.ui.TXCloudVideoView; import com.yunbao.common.R; import com.yunbao.common.bean.LiveBean; import com.yunbao.common.utils.RouteUtil; +import com.yunbao.common.views.floatingview.APPEasyFloat; +import com.yunbao.common.views.floatingview.FloatingMagnetView; +import com.yunbao.common.views.floatingview.MagnetViewListener; import kotlin.Unit; import kotlin.jvm.functions.Function1; @@ -44,17 +47,41 @@ public class LiveFloatView implements Function1 { return instance; } - public void builderFloat(Activity mContext, String url) { - liveOnInvokeView = new LiveOnInvokeView(); + public void builderFloat(Activity mContext, String url,Class back) { this.mContext = mContext; this.url = url; - EasyFloat.with(mContext) - .setTag(TAG) - .setLayout(R.layout.view_flaot_live, liveOnInvokeView) - .setShowPattern(ShowPattern.CURRENT_ACTIVITY) - .setGravity(Gravity.END | Gravity.CENTER_VERTICAL, 0, 200) - .registerCallback(this) - .show(); + APPEasyFloat.getInstance().layout(R.layout.view_flaot_live) + .dragEnable(true) + .setAutoMoveToEdge(true) + .black(back) + .setMagnetViewListener(new MagnetViewListener() { + @Override + public void invoke(FloatingMagnetView magnetView) { + TXCloudVideoView videoView = magnetView.findViewById(R.id.video_view); + mPlayer = new V2TXLivePlayerImpl(mContext); + mPlayer.setRenderView(videoView); + mPlayer.startPlay(url); + ViewClicksAntiShake.clicksAntiShake(magnetView.findViewById(R.id.btn_close), new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + mPlayer.stopPlay(); + APPEasyFloat.getInstance().dismiss(mContext); + } + }); + ViewClicksAntiShake.clicksAntiShake(videoView, () -> { + mPlayer.stopPlay(); + APPEasyFloat.getInstance().dismiss(mContext); + RouteUtil.forwardLiveAudienceActivity(mLiveBean, mLiveType, mLiveSDK, mLiveTypeVal); + }); + } + + @Override + public void onRemove() { + mPlayer.stopPlay(); + } + }) + .show(mContext); + } public void builderSystemFloat(Activity mContext, String url) { @@ -65,6 +92,7 @@ public class LiveFloatView implements Function1 { .setTag(TAG) .setLayout(R.layout.view_flaot_live, liveOnInvokeView) .setShowPattern(ShowPattern.ALL_TIME) + .setFilter() .setGravity(Gravity.END | Gravity.CENTER_VERTICAL, 0, 200) .registerCallback(this) .show(); diff --git a/live/src/main/AndroidManifest.xml b/live/src/main/AndroidManifest.xml index ebe6a3ed9..58c8d2033 100644 --- a/live/src/main/AndroidManifest.xml +++ b/live/src/main/AndroidManifest.xml @@ -1,7 +1,8 @@ - + + + android:theme="@style/AppTheme" + android:windowSoftInputMode="adjustPan|stateAlwaysHidden" + tools:targetApi="n" /> + LiveFloatView.getInstance() - .cacheLiveData(event.getmLiveBean(), event.getmLiveType(), event.getmLiveSDK(), event.getmLiveTypeVal()) - .builderFloat(mContext, event.getmLiveBean().getPull()), 800); - } else { - new Handler().post(() -> LiveFloatView.getInstance() - .cacheLiveData(event.getmLiveBean(), event.getmLiveType(), event.getmLiveSDK(), event.getmLiveTypeVal()) - .builderFloat(mContext, event.getmLiveBean().getPull())); - } + + new Handler().post(() -> LiveFloatView.getInstance() + .cacheLiveData(event.getmLiveBean(), event.getmLiveType(), event.getmLiveSDK(), event.getmLiveTypeVal()) + .builderFloat(mContext, event.getmLiveBean().getPull(), LiveAudienceActivity.class)); }