mac
2024-06-12 12d6db5780d8a2121a3bef2d58bf897b24ff552a
app/src/main/java/com/hdl/photovoltaic/base/BaseFragment.java
@@ -3,11 +3,9 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
@@ -16,9 +14,16 @@
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.Lifecycle;
import com.hdl.photovoltaic.R;
import com.hdl.photovoltaic.listener.BaseView;
import com.hdl.photovoltaic.other.HdlThreadLogic;
import com.hdl.photovoltaic.widget.LoadingDialog;
import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.Locale;
@@ -27,9 +32,7 @@
    private boolean isFirst = true;
    protected FragmentActivity _mActivity;
    protected View mContainerView;
//    private LoadingDialog loadingDialog;
//    private LoadingDialog loadingGetDataDialog;
//    private DeviceLoadingDialog deviceLoadingDialog;
    private LoadingDialog loadingDialog;
    @Override
    public void onAttach(@NonNull Context context) {
@@ -46,7 +49,7 @@
            view = inflater.inflate((int) getContentView(), container, false);
        } else if (getContentView() instanceof View) {
            view = (View) getContentView();
            FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            view.setLayoutParams(layoutParams);
        } else {
            view = null;
@@ -58,6 +61,7 @@
    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        view.setClickable(true);
        view.postDelayed(new Runnable() {
            @Override
            public void run() {
@@ -90,7 +94,8 @@
    protected void onLazyInitView(Bundle savedInstanceState) {
        onBindView(savedInstanceState);
//        registerEventBus();
        //注册EventBus
        registerEventBus();
    }
@@ -99,7 +104,10 @@
        super.onDestroyView();
        _mActivity = null;
        isFirst = true;
//        unregisterEventBus();
        //隐藏Loading
        hideLoading();
        //注销EventBus
        unregisterEventBus();
    }
@@ -115,10 +123,15 @@
        }
    }
//    @Subscribe(threadMode = ThreadMode.MAIN)
//    public void onEventMessage(BaseEvent event) {
//
//    }
    /**
     * 收到EventBUs通知
     *
     * @param eventBus 数据
     */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMessage(BaseEventBus eventBus) {
    }
    /**
     * 显示View
@@ -154,118 +167,52 @@
        }
    }
    /* *//**
    /**
     * 获取LoadingDialog
     *
     * @return
     *//*
     * @return LoadingDialog
     */
    protected LoadingDialog getLoadingDialog() {
        if (loadingDialog == null && _mActivity != null) {
            loadingDialog = new LoadingDialog(_mActivity, R.style.loading_dialog);
            loadingDialog = new LoadingDialog(_mActivity, R.style.Custom_Dialog);
        }
        return loadingDialog;
    }
    public LoadingDialog getLoadingGetDataDialog() {
        if (loadingGetDataDialog == null && _mActivity != null) {
            loadingGetDataDialog = new LoadingDialog(_mActivity, R.style.loading_dialog);
        }
        return loadingGetDataDialog;
    }
    *//**
     * 获取DeviceLoadingDialog
     *
     * @return
     *//*
    protected DeviceLoadingDialog getDeviceLoadingDialog() {
        if (deviceLoadingDialog == null && _mActivity != null) {
            deviceLoadingDialog = new DeviceLoadingDialog(_mActivity, R.style.loading_dialog);
        }
        return deviceLoadingDialog;
    }
    *//**
    /**
     * 开始Loading
     *//*
    public void showLoading() {
     */
    protected void showLoading() {
        getLoadingDialog().setText("");
        getLoadingDialog().start();
    }
    *//**
    /**
     * 开始Loading
     *//*
    public void showDeviceLoading() {
        getDeviceLoadingDialog().start();
    }
    *//**
     * 开始Loading
     *//*
     *
     * @param mes 自定义文本
     */
    protected void showLoading(String mes) {
        getLoadingDialog().start();
        getLoadingDialog().setText(mes);
    }
    *//**
     * 开始Loading
     *//*
    protected void showGetDataLoading(String mes) {
        getLoadingGetDataDialog().startTouchNotGone();
        getLoadingGetDataDialog().setText(mes);
    }
    *//**
     * 开始Loading
     *//*
    protected void showDeviceLoading(String mes) {
        getDeviceLoadingDialog().start();
        getDeviceLoadingDialog().setText(mes);
    }
    *//**
     * 停止隐藏Loading
     *//*
    protected void hideLoading() {
        if (loadingDialog != null && loadingDialog.isShowing()) {
            loadingDialog.stop();
        }
    }
    *//**
     * 停止隐藏Loading
     *//*
    protected void hideGetDataLoading() {
        if (loadingGetDataDialog != null && loadingGetDataDialog.isShowing()) {
            loadingGetDataDialog.stop();
        }
    }
    */
    /**
     * 停止隐藏Loading
     *//*
    protected void hideDeviceLoading() {
        if (deviceLoadingDialog != null && deviceLoadingDialog.isShowing()) {
            deviceLoadingDialog.stop();
        }
    }*/
    //用于popwindow显示隐藏时候背景的颜色更换
    protected void backgroundAlpha(float bgAlpha) {
        if (_mActivity != null) {
            WindowManager.LayoutParams lp = _mActivity.getWindow().getAttributes();
            _mActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
            lp.alpha = bgAlpha; //0.0-1.0
            _mActivity.getWindow().setAttributes(lp);
        }
     */
    protected void hideLoading() {
        HdlThreadLogic.runMainThread(new Runnable() {
            @Override
            public void run() {
                if (loadingDialog != null && loadingDialog.isShowing()) {
                    loadingDialog.stop();
                }
            }
        }, null, null);
    }
    public static boolean isZh(Context context) {
        Locale locale = context.getResources().getConfiguration().locale;
        String language = locale.getLanguage();