修改悬浮窗样式,添加悬浮设置

This commit is contained in:
18401019693 2022-10-20 11:32:33 +08:00
parent ad785f2b39
commit a09cbf4776

View File

@ -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);
}
}