|
@@ -16,6 +16,7 @@ import android.animation.Animator;
|
|
|
import android.animation.ValueAnimator;
|
|
|
import android.app.Activity;
|
|
|
import android.content.Context;
|
|
|
+import android.content.DialogInterface;
|
|
|
import android.content.SharedPreferences;
|
|
|
import android.graphics.Bitmap;
|
|
|
import android.graphics.Color;
|
|
@@ -26,9 +27,10 @@ import android.os.CountDownTimer;
|
|
|
import android.os.Handler;
|
|
|
import android.os.Looper;
|
|
|
import android.text.TextUtils;
|
|
|
-import android.util.Log;
|
|
|
+import android.util.DisplayMetrics;
|
|
|
import android.util.TypedValue;
|
|
|
import android.view.Gravity;
|
|
|
+import android.view.LayoutInflater;
|
|
|
import android.view.MotionEvent;
|
|
|
import android.view.View;
|
|
|
import android.view.View.OnClickListener;
|
|
@@ -37,8 +39,13 @@ import android.view.ViewGroup;
|
|
|
import android.view.WindowManager;
|
|
|
import android.view.animation.Interpolator;
|
|
|
import android.view.animation.LinearInterpolator;
|
|
|
-import android.widget.Button;
|
|
|
import android.widget.LinearLayout;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.yyrh.ui.dialog.CustomExitGameDialog;
|
|
|
+import com.yyrh.utils.ResourceUtil;
|
|
|
+import com.yyrh.utils.TosUtil;
|
|
|
+import com.yyrh.utils.YYLog;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
@@ -47,6 +54,11 @@ import java.util.List;
|
|
|
* Created by wengyiming on 2017/7/20.
|
|
|
*/
|
|
|
public class FloatLogoMenu {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 记录 logo 停放的位置,以备下次恢复
|
|
|
*/
|
|
@@ -96,7 +108,7 @@ public class FloatLogoMenu {
|
|
|
/**
|
|
|
* 记录屏幕的宽度
|
|
|
*/
|
|
|
- private int mScreenWidth;
|
|
|
+ private int mScreenWidth,screenHeigth;
|
|
|
|
|
|
/**
|
|
|
* 来自 activity 的 wManager
|
|
@@ -107,7 +119,7 @@ public class FloatLogoMenu {
|
|
|
/**
|
|
|
* 为 wManager 设置 LayoutParams
|
|
|
*/
|
|
|
- private WindowManager.LayoutParams wmParams;
|
|
|
+ private WindowManager.LayoutParams wmParams,wmParams2;
|
|
|
|
|
|
/**
|
|
|
* 带透明度动画、旋转、放大的悬浮球
|
|
@@ -132,11 +144,6 @@ public class FloatLogoMenu {
|
|
|
*/
|
|
|
private Interpolator mLinearInterpolator = new LinearInterpolator();
|
|
|
|
|
|
- /**
|
|
|
- * 用于记录上次菜单打开的时间,判断时间间隔
|
|
|
- */
|
|
|
- private static double DOUBLE_CLICK_TIME = 0L;
|
|
|
-
|
|
|
/**
|
|
|
* 标记是否拖动中
|
|
|
*/
|
|
@@ -147,6 +154,9 @@ public class FloatLogoMenu {
|
|
|
*/
|
|
|
private int mResetLocationValue;
|
|
|
|
|
|
+ private LinearLayout ll_hide;
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 手指离开屏幕后 用于恢复 悬浮球的 logo 的左右位置
|
|
|
*/
|
|
@@ -159,16 +169,7 @@ public class FloatLogoMenu {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- /**
|
|
|
- * 这个事件不做任何事情、直接return false则 onclick 事件生效
|
|
|
- */
|
|
|
- private OnTouchListener mDefaultOnTouchListerner = new OnTouchListener() {
|
|
|
- @Override
|
|
|
- public boolean onTouch(View v, MotionEvent event) {
|
|
|
- isDraging = false;
|
|
|
- return false;
|
|
|
- }
|
|
|
- };
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 这个事件用于处理移动、自定义点击或者其它事情,return true可以保证onclick事件失效
|
|
@@ -184,8 +185,9 @@ public class FloatLogoMenu {
|
|
|
floatEventMove(event);
|
|
|
break;
|
|
|
case MotionEvent.ACTION_UP:
|
|
|
- case MotionEvent.ACTION_CANCEL:
|
|
|
floatEventUp();
|
|
|
+ case MotionEvent.ACTION_CANCEL:
|
|
|
+ floatEventCancel();
|
|
|
break;
|
|
|
}
|
|
|
return true;
|
|
@@ -193,21 +195,17 @@ public class FloatLogoMenu {
|
|
|
};
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 菜单背景颜色
|
|
|
- */
|
|
|
- private int mBackMenuColor = 0xffe4e3e1;
|
|
|
+ private View createHideView(Context context){
|
|
|
+ hideView = LayoutInflater.from(context).inflate(ResourceUtil.getLayoutId(context,
|
|
|
+ "qj_hide_float_view"), null);
|
|
|
+ ll_hide = hideView.findViewById(ResourceUtil.getId(context,
|
|
|
+ "ll_hide"));
|
|
|
+ return hideView;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- /**
|
|
|
- * 是否绘制红点数字
|
|
|
- */
|
|
|
- private boolean mDrawRedPointNum;
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 是否绘制圆形菜单项,false绘制方形
|
|
|
- */
|
|
|
- private boolean mCicleMenuBg;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -222,10 +220,7 @@ public class FloatLogoMenu {
|
|
|
*/
|
|
|
private Context mActivity;
|
|
|
|
|
|
- /**
|
|
|
- * 菜单 点击、关闭 监听
|
|
|
- */
|
|
|
- private FloatMenuView.OnMenuClickListener mOnMenuClickListener;
|
|
|
+
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -240,32 +235,23 @@ public class FloatLogoMenu {
|
|
|
private int mHintLocation = mDefaultLocation;
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 用于记录菜单项内容
|
|
|
- */
|
|
|
- private List<FloatItem> mFloatItems = new ArrayList<>();
|
|
|
-
|
|
|
- private LinearLayout rootViewRight;
|
|
|
|
|
|
- private LinearLayout rootView;
|
|
|
|
|
|
private ValueAnimator valueAnimator;
|
|
|
|
|
|
- private boolean isExpaned = false;
|
|
|
|
|
|
- private Drawable mBackground;
|
|
|
+ private View hideView;
|
|
|
|
|
|
+ private OnFloatClickListener mListener;
|
|
|
|
|
|
private FloatLogoMenu(Builder builder) {
|
|
|
- mBackMenuColor = builder.mBackMenuColor;
|
|
|
- mDrawRedPointNum = builder.mDrawRedPointNum;
|
|
|
- mCicleMenuBg = builder.mCicleMenuBg;
|
|
|
+
|
|
|
+
|
|
|
mLogoRes = builder.mLogoRes;
|
|
|
mActivity = builder.mActivity;
|
|
|
- mOnMenuClickListener = builder.mOnMenuClickListener;
|
|
|
+
|
|
|
mDefaultLocation = builder.mDefaultLocation;
|
|
|
- mFloatItems = builder.mFloatItems;
|
|
|
- mBackground = builder.mDrawable;
|
|
|
+ mListener = builder.listener;
|
|
|
|
|
|
|
|
|
// if (mActivity == null || mActivity.isFinishing() || mActivity.getWindowManager() == null) {
|
|
@@ -276,9 +262,6 @@ public class FloatLogoMenu {
|
|
|
throw new IllegalArgumentException("No logo found,you can setLogo/showWithLogo to set a FloatLogo ");
|
|
|
}
|
|
|
|
|
|
- if (mFloatItems.isEmpty()) {
|
|
|
- throw new IllegalArgumentException("At least one menu item!");
|
|
|
- }
|
|
|
|
|
|
initFloatWindow();
|
|
|
initTimer();
|
|
@@ -286,10 +269,6 @@ public class FloatLogoMenu {
|
|
|
|
|
|
}
|
|
|
|
|
|
- public void setFloatItemList(List<FloatItem> floatItems) {
|
|
|
- this.mFloatItems = floatItems;
|
|
|
- caculateDotNum();
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 初始化悬浮球 window
|
|
@@ -302,6 +281,8 @@ public class FloatLogoMenu {
|
|
|
| WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
|
|
PixelFormat.TRANSLUCENT);
|
|
|
|
|
|
+
|
|
|
+
|
|
|
if (mActivity instanceof Activity) {
|
|
|
Activity activity = (Activity) mActivity;
|
|
|
wManager = activity.getWindowManager();
|
|
@@ -309,7 +290,6 @@ public class FloatLogoMenu {
|
|
|
wmParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL;
|
|
|
|
|
|
|
|
|
-
|
|
|
} else {
|
|
|
wManager = (WindowManager) mActivity.getSystemService(Context.WINDOW_SERVICE);
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
|
@@ -323,9 +303,10 @@ public class FloatLogoMenu {
|
|
|
wmParams.type = WindowManager.LayoutParams.TYPE_PHONE;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- mScreenWidth = wManager.getDefaultDisplay().getWidth();
|
|
|
- int screenHeigth = wManager.getDefaultDisplay().getHeight();
|
|
|
+ DisplayMetrics dm = new DisplayMetrics();
|
|
|
+ wManager.getDefaultDisplay().getMetrics(dm);
|
|
|
+ mScreenWidth = dm.widthPixels;
|
|
|
+ screenHeigth = dm.heightPixels;
|
|
|
|
|
|
//判断状态栏是否显示 如果不显示则statusBarHeight为0
|
|
|
mStatusBarHeight = dp2Px(0, mActivity);
|
|
@@ -357,6 +338,17 @@ public class FloatLogoMenu {
|
|
|
wmParams.alpha = 1;
|
|
|
wmParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
|
|
|
wmParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ wmParams2 = new WindowManager.LayoutParams();
|
|
|
+ wmParams2.format = PixelFormat.RGBA_8888;
|
|
|
+ wmParams2.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
|
|
+ wmParams2.width = WindowManager.LayoutParams.WRAP_CONTENT;
|
|
|
+ wmParams2.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
|
|
+ wmParams2.y=-screenHeigth / 4;
|
|
|
+ wmParams2.gravity = Gravity.CENTER_HORIZONTAL;
|
|
|
+ wmParams2.type = WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -364,127 +356,26 @@ public class FloatLogoMenu {
|
|
|
* 初始化悬浮球
|
|
|
*/
|
|
|
private void initFloat() {
|
|
|
- genarateLeftLineLayout();
|
|
|
- genarateRightLineLayout();
|
|
|
+
|
|
|
mFloatLogo = new DotImageView(mActivity, mLogoRes);
|
|
|
mFloatLogo.setLayoutParams(new WindowManager.LayoutParams(dp2Px(50, mActivity), dp2Px(50, mActivity)));
|
|
|
- mFloatLogo.setDrawNum(mDrawRedPointNum);
|
|
|
- mFloatLogo.setBgColor(mBackMenuColor);
|
|
|
mFloatLogo.setDrawDarkBg(true);
|
|
|
|
|
|
- caculateDotNum();
|
|
|
floatBtnEvent();
|
|
|
try {
|
|
|
|
|
|
-
|
|
|
+ wManager.addView(createHideView(mActivity), wmParams2);
|
|
|
+ hideView.setVisibility(View.INVISIBLE);
|
|
|
wManager.addView(mFloatLogo, wmParams);
|
|
|
|
|
|
+
|
|
|
}
|
|
|
catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
-
|
|
|
+ mHideTimer.start();
|
|
|
}
|
|
|
|
|
|
- private void genarateLeftLineLayout() {
|
|
|
- DotImageView floatLogo = new DotImageView(mActivity, mLogoRes);
|
|
|
- floatLogo.setLayoutParams(new WindowManager.LayoutParams(dp2Px(50, mActivity), dp2Px(50, mActivity)));
|
|
|
- floatLogo.setDrawNum(mDrawRedPointNum);
|
|
|
- floatLogo.setDrawDarkBg(false);
|
|
|
-
|
|
|
- rootView = new LinearLayout(mActivity);
|
|
|
- rootView.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
- rootView.setGravity(Gravity.CENTER);
|
|
|
- rootView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, dp2Px(50, mActivity)));
|
|
|
-
|
|
|
- rootView.setBackgroundDrawable(mBackground);
|
|
|
-
|
|
|
-
|
|
|
- final FloatMenuView mFloatMenuView = new FloatMenuView.Builder(mActivity)
|
|
|
- .setFloatItems(mFloatItems)
|
|
|
- .setBackgroundColor(Color.TRANSPARENT)
|
|
|
- .setCicleBg(mCicleMenuBg)
|
|
|
- .setStatus(FloatMenuView.STATUS_LEFT)
|
|
|
- .setMenuBackgroundColor(Color.TRANSPARENT)
|
|
|
- .drawNum(mDrawRedPointNum)
|
|
|
- .create();
|
|
|
- setMenuClickListener(mFloatMenuView);
|
|
|
-
|
|
|
- rootView.addView(floatLogo);
|
|
|
- rootView.addView(mFloatMenuView);
|
|
|
-
|
|
|
-
|
|
|
- floatLogo.setOnClickListener(new OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- if (isExpaned) {
|
|
|
- try {
|
|
|
- wManager.removeViewImmediate(rootView);
|
|
|
- wManager.addView(FloatLogoMenu.this.mFloatLogo, wmParams);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- isExpaned = false;
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- public void hideMenu(){
|
|
|
- if (isExpaned) {
|
|
|
- try {
|
|
|
- wManager.removeViewImmediate(mHintLocation == LEFT ? rootView : rootViewRight);
|
|
|
- wManager.addView(FloatLogoMenu.this.mFloatLogo, wmParams);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- isExpaned = false;
|
|
|
- }
|
|
|
- }
|
|
|
- private void genarateRightLineLayout() {
|
|
|
- final DotImageView floatLogo = new DotImageView(mActivity, mLogoRes);
|
|
|
- floatLogo.setLayoutParams(new WindowManager.LayoutParams(dp2Px(50, mActivity), dp2Px(50, mActivity)));
|
|
|
- floatLogo.setDrawNum(mDrawRedPointNum);
|
|
|
- floatLogo.setDrawDarkBg(false);
|
|
|
-
|
|
|
- floatLogo.setOnClickListener(new OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- if (isExpaned) {
|
|
|
- try {
|
|
|
- wManager.removeViewImmediate(rootViewRight);
|
|
|
- wManager.addView(FloatLogoMenu.this.mFloatLogo, wmParams);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- isExpaned = false;
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- rootViewRight = new LinearLayout(mActivity);
|
|
|
- rootViewRight.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
- rootViewRight.setGravity(Gravity.CENTER);
|
|
|
- rootViewRight.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, dp2Px(50, mActivity)));
|
|
|
-
|
|
|
-
|
|
|
- rootViewRight.setBackgroundDrawable(mBackground);
|
|
|
-
|
|
|
-
|
|
|
- FloatMenuView mFloatMenuView = new FloatMenuView.Builder(mActivity)
|
|
|
- .setFloatItems(mFloatItems)
|
|
|
- .setBackgroundColor(Color.TRANSPARENT)
|
|
|
- .setCicleBg(mCicleMenuBg)
|
|
|
- .setStatus(FloatMenuView.STATUS_RIGHT)
|
|
|
- .setMenuBackgroundColor(Color.TRANSPARENT)
|
|
|
- .drawNum(mDrawRedPointNum)
|
|
|
- .create();
|
|
|
- setMenuClickListener(mFloatMenuView);
|
|
|
-
|
|
|
- rootViewRight.addView(mFloatMenuView);
|
|
|
- rootViewRight.addView(floatLogo);
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 初始化 隐藏悬浮球的定时器
|
|
@@ -493,17 +384,13 @@ public class FloatLogoMenu {
|
|
|
mHideTimer = new CountDownTimer(2000, 10) { //悬浮窗超过5秒没有操作的话会自动隐藏
|
|
|
@Override
|
|
|
public void onTick(long millisUntilFinished) {
|
|
|
- if (isExpaned) {
|
|
|
- mHideTimer.cancel();
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onFinish() {
|
|
|
- if (isExpaned) {
|
|
|
- mHideTimer.cancel();
|
|
|
- return;
|
|
|
- }
|
|
|
+
|
|
|
if (!isDraging) {
|
|
|
if (mHintLocation == LEFT) {
|
|
|
mFloatLogo.setStatus(DotImageView.HIDE_LEFT);
|
|
@@ -512,69 +399,24 @@ public class FloatLogoMenu {
|
|
|
mFloatLogo.setStatus(DotImageView.HIDE_RIGHT);
|
|
|
mFloatLogo.setDrawDarkBg(true);
|
|
|
}
|
|
|
-// mFloatLogo.setOnTouchListener(mDefaultOnTouchListerner);//把onClick事件分发下去,防止onclick无效
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 用于 拦截 菜单项的 关闭事件,以方便开始 隐藏定时器
|
|
|
- *
|
|
|
- * @param mFloatMenuView
|
|
|
- */
|
|
|
- private void setMenuClickListener(final FloatMenuView mFloatMenuView) {
|
|
|
- mFloatMenuView.setOnMenuClickListener(new FloatMenuView.OnMenuClickListener() {
|
|
|
- @Override
|
|
|
- public void onItemClick(int position, String title) {
|
|
|
|
|
|
|
|
|
-
|
|
|
- mFloatLogo.refreshDot(0);
|
|
|
-
|
|
|
- mOnMenuClickListener.onItemClick(position, title);
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void dismiss() {
|
|
|
- mFloatLogo.setDrawDarkBg(true);
|
|
|
- mOnMenuClickListener.dismiss();
|
|
|
- mHideTimer.start();
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- }
|
|
|
-private void closeMenu(){
|
|
|
- wManager.removeViewImmediate(rootView);
|
|
|
- wManager.addView(FloatLogoMenu.this.mFloatLogo, wmParams);
|
|
|
-}
|
|
|
-
|
|
|
/**
|
|
|
* 悬浮窗的点击事件和touch事件的切换
|
|
|
*/
|
|
|
private void floatBtnEvent() {
|
|
|
- //这里的onCick只有 touchListener = mDefaultOnTouchListerner 才会触发
|
|
|
-// mFloatLogo.setOnClickListener(new OnClickListener() {
|
|
|
-// @Override
|
|
|
-// public void onClick(View v) {
|
|
|
-// if (!isDraging) {
|
|
|
-// if (mFloatLogo.getStatus() != DotImageView.NORMAL) {
|
|
|
-// mFloatLogo.setBitmap(mLogoRes);
|
|
|
-// mFloatLogo.setStatus(DotImageView.NORMAL);
|
|
|
-// if (!mFloatLogo.mDrawDarkBg) {
|
|
|
-// mFloatLogo.setDrawDarkBg(true);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// mFloatLogo.setOnTouchListener(touchListener);
|
|
|
-// mHideTimer.start();
|
|
|
-// }
|
|
|
-// }
|
|
|
-// });
|
|
|
|
|
|
mFloatLogo.setOnTouchListener(touchListener);//恢复touch事件
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -622,12 +464,79 @@ private void closeMenu(){
|
|
|
isDraging = false;
|
|
|
mFloatLogo.setDraging(false, 0, true);
|
|
|
}
|
|
|
+
|
|
|
+ hideView.setVisibility(View.VISIBLE);
|
|
|
+
|
|
|
+ float x = wmParams.x;
|
|
|
+ float y = wmParams.y;
|
|
|
+ float XMinPoint = mScreenWidth / 2 - hideView.getWidth();
|
|
|
+ float XMaxPoint = mScreenWidth / 2 + hideView.getWidth();
|
|
|
+ float YMinPoint = screenHeigth / 4 - hideView.getHeight() - mStatusBarHeight;
|
|
|
+
|
|
|
+ float YMaxPoint = screenHeigth / 4 - mStatusBarHeight;
|
|
|
+
|
|
|
+ if (x >= XMinPoint && x <= XMaxPoint && y >=YMinPoint && y <= YMaxPoint){
|
|
|
+
|
|
|
+ ll_hide.setBackgroundResource(ResourceUtil.getDrawableId(mActivity, "qj_hide_float_view_bg"));
|
|
|
+
|
|
|
+ }else {
|
|
|
+ ll_hide.setBackgroundResource(ResourceUtil.getDrawableId(mActivity, "qj_text_black"));
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void floatEventUp() {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ float x = wmParams.x;
|
|
|
+ float y = wmParams.y;
|
|
|
+ float RawX = mScreenWidth / 2 - hideView.getWidth();
|
|
|
+ float RawX1 = mScreenWidth / 2 + hideView.getWidth();
|
|
|
+ float RawY = screenHeigth / 4 - hideView.getHeight() - mStatusBarHeight;
|
|
|
+
|
|
|
+ float RawY1 = screenHeigth / 4 - mStatusBarHeight;
|
|
|
+
|
|
|
+ hideView.setVisibility(View.INVISIBLE);
|
|
|
+
|
|
|
+ if (x >= RawX && x <= RawX1 && y >=RawY && y <= RawY1){
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ CustomExitGameDialog.Builder builder = new CustomExitGameDialog.Builder(mActivity);
|
|
|
+ builder.Create().show();
|
|
|
+ builder.setPositiveButton(new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+
|
|
|
+ destoryFloat();
|
|
|
+
|
|
|
+
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.setnegativeButton(new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.setTitle(mActivity.getString(ResourceUtil.getStringId(mActivity, "qj_close_float_view_tip")));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
/**
|
|
|
* 悬浮窗touch事件的 up 事件
|
|
|
*/
|
|
|
- private void floatEventUp() {
|
|
|
+ private void floatEventCancel() {
|
|
|
if (mXInScreen < mScreenWidth / 2) { //在左边
|
|
|
mHintLocation = LEFT;
|
|
|
} else { //在右边
|
|
@@ -692,8 +601,12 @@ private void closeMenu(){
|
|
|
// //这里需要判断如果如果手指所在位置和logo所在位置在一个宽度内则不移动,
|
|
|
if (Math.abs(mXInScreen - mXDownInScreen) > mFloatLogo.getWidth() / 5 || Math.abs(mYInScreen - mYDownInScreen) > mFloatLogo.getHeight() / 5) {
|
|
|
isDraging = false;
|
|
|
- } else {
|
|
|
- openMenu();
|
|
|
+
|
|
|
+ }else {
|
|
|
+ if (isDraging)
|
|
|
+ return;
|
|
|
+ if (mListener != null) mListener.onClick();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -734,43 +647,6 @@ private void closeMenu(){
|
|
|
}
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 打开菜单
|
|
|
- */
|
|
|
- private void openMenu() {
|
|
|
- if (isDraging) return;
|
|
|
-
|
|
|
- if (!isExpaned) {
|
|
|
- mFloatLogo.setDrawDarkBg(false);
|
|
|
- try {
|
|
|
- wManager.removeViewImmediate(mFloatLogo);
|
|
|
- if (mHintLocation == RIGHT) {
|
|
|
- wManager.addView(rootViewRight, wmParams);
|
|
|
- } else {
|
|
|
- wManager.addView(rootView, wmParams);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- isExpaned = true;
|
|
|
- mHideTimer.cancel();
|
|
|
- } else {
|
|
|
- mFloatLogo.setDrawDarkBg(true);
|
|
|
- if (isExpaned) {
|
|
|
- try {
|
|
|
- wManager.removeViewImmediate(mHintLocation == LEFT ? rootView : rootViewRight);
|
|
|
- wManager.addView(mFloatLogo, wmParams);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- isExpaned = false;
|
|
|
- }
|
|
|
- mHideTimer.start();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -779,13 +655,7 @@ private void closeMenu(){
|
|
|
private void updateViewPosition() {
|
|
|
isDraging = true;
|
|
|
try {
|
|
|
- if (!isExpaned) {
|
|
|
- if (wmParams.y - mFloatLogo.getHeight() / 2 <= 0) {
|
|
|
- wmParams.y = mStatusBarHeight;
|
|
|
- isDraging = true;
|
|
|
- }
|
|
|
- wManager.updateViewLayout(mFloatLogo, wmParams);
|
|
|
- }
|
|
|
+ wManager.updateViewLayout(mFloatLogo, wmParams);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -794,6 +664,10 @@ private void closeMenu(){
|
|
|
public void show() {
|
|
|
try {
|
|
|
if (wManager != null && wmParams != null && mFloatLogo != null) {
|
|
|
+
|
|
|
+ wManager.addView(createHideView(mActivity), wmParams2);
|
|
|
+
|
|
|
+
|
|
|
wManager.addView(mFloatLogo, wmParams);
|
|
|
}
|
|
|
if (mHideTimer != null) {
|
|
@@ -807,12 +681,6 @@ private void closeMenu(){
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 关闭菜单
|
|
|
- */
|
|
|
- public void hide() {
|
|
|
- destoryFloat();
|
|
|
- }
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -825,79 +693,19 @@ private void closeMenu(){
|
|
|
mFloatLogo.clearAnimation();
|
|
|
try {
|
|
|
mHideTimer.cancel();
|
|
|
- if (isExpaned) {
|
|
|
- wManager.removeViewImmediate(mHintLocation == LEFT ? rootView : rootViewRight);
|
|
|
- } else {
|
|
|
- wManager.removeViewImmediate(mFloatLogo);
|
|
|
- }
|
|
|
|
|
|
- isExpaned = false;
|
|
|
+ wManager.removeViewImmediate(mFloatLogo);
|
|
|
+ wManager.removeViewImmediate(hideView);
|
|
|
isDraging = false;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 计算总红点数
|
|
|
- */
|
|
|
- private void caculateDotNum() {
|
|
|
- int dotNum = 0;
|
|
|
- for (FloatItem floatItem : mFloatItems) {
|
|
|
- if (!TextUtils.isEmpty(floatItem.getDotNum())) {
|
|
|
- int num = Integer.parseInt(floatItem.getDotNum());
|
|
|
- dotNum = dotNum + num;
|
|
|
- }
|
|
|
- }
|
|
|
- mFloatLogo.setDrawNum(mDrawRedPointNum);
|
|
|
- setDotNum(dotNum);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 绘制悬浮球的红点
|
|
|
- *
|
|
|
- * @param dotNum d
|
|
|
- */
|
|
|
- private void setDotNum(int dotNum) {
|
|
|
- mFloatLogo.setDotNum(dotNum, new Animator.AnimatorListener() {
|
|
|
- @Override
|
|
|
- public void onAnimationStart(Animator animation) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onAnimationEnd(Animator animation) {
|
|
|
- if (!isDraging) {
|
|
|
- mHideTimer.start();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onAnimationCancel(Animator animation) {
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
- @Override
|
|
|
- public void onAnimationRepeat(Animator animation) {
|
|
|
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 用于暴露给外部判断是否包含某个菜单项
|
|
|
- *
|
|
|
- * @param menuLabel string
|
|
|
- * @return boolean
|
|
|
- */
|
|
|
- public boolean hasMenu(String menuLabel) {
|
|
|
- for (FloatItem menuItem : mFloatItems) {
|
|
|
- if (TextUtils.equals(menuItem.getTitle(), menuLabel)) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 用于保存悬浮球的位置记录
|
|
@@ -940,59 +748,33 @@ private void closeMenu(){
|
|
|
}
|
|
|
|
|
|
|
|
|
- public interface OnMenuClickListener {
|
|
|
- void onMenuExpended(boolean isExpened);
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
- public void setValueAnimator() {
|
|
|
|
|
|
- }
|
|
|
|
|
|
public static final class Builder {
|
|
|
- private int mBackMenuColor;
|
|
|
- private boolean mDrawRedPointNum;
|
|
|
- private boolean mCicleMenuBg;
|
|
|
+
|
|
|
+
|
|
|
private Bitmap mLogoRes;
|
|
|
private int mDefaultLocation;
|
|
|
- private List<FloatItem> mFloatItems = new ArrayList<>();
|
|
|
+
|
|
|
private Context mActivity;
|
|
|
- private FloatMenuView.OnMenuClickListener mOnMenuClickListener;
|
|
|
- private Drawable mDrawable;
|
|
|
|
|
|
+ private OnFloatClickListener listener;
|
|
|
|
|
|
public Builder setBgDrawable(Drawable drawable) {
|
|
|
- mDrawable = drawable;
|
|
|
+
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
public Builder() {
|
|
|
}
|
|
|
|
|
|
- public Builder setFloatItems(List<FloatItem> mFloatItems) {
|
|
|
- this.mFloatItems = mFloatItems;
|
|
|
- return this;
|
|
|
- }
|
|
|
|
|
|
- public Builder addFloatItem(FloatItem floatItem) {
|
|
|
- this.mFloatItems.add(floatItem);
|
|
|
- return this;
|
|
|
- }
|
|
|
|
|
|
- public Builder backMenuColor(int val) {
|
|
|
- mBackMenuColor = val;
|
|
|
- return this;
|
|
|
- }
|
|
|
|
|
|
- public Builder drawRedPointNum(boolean val) {
|
|
|
- mDrawRedPointNum = val;
|
|
|
- return this;
|
|
|
- }
|
|
|
|
|
|
- public Builder drawCicleMenuBg(boolean val) {
|
|
|
- mCicleMenuBg = val;
|
|
|
- return this;
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
public Builder logo(Bitmap val) {
|
|
|
mLogoRes = val;
|
|
@@ -1004,35 +786,29 @@ private void closeMenu(){
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public Builder withContext(Context val) {
|
|
|
- mActivity = val;
|
|
|
- return this;
|
|
|
- }
|
|
|
|
|
|
- public Builder setOnMenuItemClickListener(FloatMenuView.OnMenuClickListener val) {
|
|
|
- mOnMenuClickListener = val;
|
|
|
- return this;
|
|
|
- }
|
|
|
|
|
|
public Builder defaultLocation(int val) {
|
|
|
mDefaultLocation = val;
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public FloatLogoMenu showWithListener(FloatMenuView.OnMenuClickListener val) {
|
|
|
- mOnMenuClickListener = val;
|
|
|
- return new FloatLogoMenu(this);
|
|
|
- }
|
|
|
|
|
|
- public FloatLogoMenu showWithLogo(Bitmap val) {
|
|
|
- mLogoRes = val;
|
|
|
- return new FloatLogoMenu(this);
|
|
|
+
|
|
|
+ public Builder setOnFloatClickListener(OnFloatClickListener onClickFloatListener) {
|
|
|
+ this.listener = onClickFloatListener;
|
|
|
+ return this;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
public FloatLogoMenu show() {
|
|
|
+
|
|
|
return new FloatLogoMenu(this);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ public interface OnFloatClickListener {
|
|
|
+ void onClick();
|
|
|
+ }
|
|
|
|
|
|
}
|