diff --git a/common/src/main/java/com/yunbao/common/dialog/FloatSettingsDialog.java b/common/src/main/java/com/yunbao/common/dialog/FloatSettingsDialog.java new file mode 100644 index 000000000..248d16f9a --- /dev/null +++ b/common/src/main/java/com/yunbao/common/dialog/FloatSettingsDialog.java @@ -0,0 +1,94 @@ +package com.yunbao.common.dialog; + +import android.os.Bundle; +import android.view.Gravity; +import android.view.Window; +import android.view.WindowManager; +import android.widget.ImageView; + +import com.lzf.easyfloat.interfaces.OnPermissionResult; +import com.lzf.easyfloat.permission.PermissionUtils; +import com.yunbao.common.R; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.views.weight.ViewClicksAntiShake; + +/** + * 悬浮窗设置页面 + */ +public class FloatSettingsDialog extends AbsDialogFragment { + private ImageView specialSwitch, specialMountSwitch; + private boolean isFloat; + + @Override + protected int getLayoutId() { + return R.layout.view_float_settings; + } + + @Override + protected int getDialogStyle() { + return R.style.dialog2; + } + + @Override + protected boolean canCancel() { + return true; + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + specialSwitch = (ImageView) findViewById(R.id.special_switch); + specialMountSwitch = (ImageView) findViewById(R.id.special_mount_switch); + isFloat = IMLoginManager.get(getActivity()).isFloat(); + if (!isFloat) { + ImgLoader.display(getContext(), R.mipmap.special_icon_off, specialSwitch); + } else { + ImgLoader.display(getContext(), R.mipmap.special_icon_on, specialSwitch); + } + boolean floatPermission = PermissionUtils.checkPermission(mContext); + if (!floatPermission) { + ImgLoader.display(getContext(), R.mipmap.special_icon_off, specialMountSwitch); + } else { + ImgLoader.display(getContext(), R.mipmap.special_icon_on, specialMountSwitch); + } + //礼物特效开关 + ViewClicksAntiShake.clicksAntiShake(specialSwitch, () -> { + isFloat = !isFloat; + if (!isFloat) { + ImgLoader.display(getContext(), R.mipmap.special_icon_off, specialSwitch); + } else { + ImgLoader.display(getContext(), R.mipmap.special_icon_on, specialSwitch); + } + //更新特效开关 + IMLoginManager.get(getContext()).initFloat(isFloat); + + } + ); + //坐骑特效开关 + ViewClicksAntiShake.clicksAntiShake(specialMountSwitch, () -> { + dismiss(); + PermissionUtils.requestPermission(getActivity(), new OnPermissionResult() { + @Override + public void permissionResult(boolean isFloat) { + if (!isFloat) { + ImgLoader.display(getContext(), R.mipmap.special_icon_off, specialSwitch); + } else { + ImgLoader.display(getContext(), R.mipmap.special_icon_on, specialSwitch); + } + } + }); + } + ); + } + + @Override + protected void setWindowAttributes(Window window) { + window.setWindowAnimations(R.style.bottomToTopAnim); + WindowManager.LayoutParams params = window.getAttributes(); + params.width = WindowManager.LayoutParams.MATCH_PARENT; + params.height = WindowManager.LayoutParams.WRAP_CONTENT; + params.gravity = Gravity.BOTTOM; + window.setAttributes(params); + } +}