mac
2024-07-24 30b7d526263abf634ee1003a572930822e81c8a2
app/src/main/java/com/hdl/photovoltaic/base/BaseActivity.java
@@ -2,25 +2,27 @@
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import com.hdl.photovoltaic.R;
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.listener.BaseView;
import com.hdl.photovoltaic.other.HdlThreadLogic;
import com.hdl.photovoltaic.utils.AppManagerUtils;
import com.hdl.photovoltaic.utils.LocalManageUtil;
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;
public abstract class BaseActivity extends AppCompatActivity implements BaseView {
@@ -28,9 +30,11 @@
    private LoadingDialog loadingDialog;
    protected Activity _mActivity;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        _mActivity = this;
        Object content = getContentView();
        //添加Activity到堆栈
@@ -43,6 +47,17 @@
            throw new RuntimeException("getContentView() should be a @LayoutRes or a View");
        }
        onBindView(savedInstanceState);
        //注册EventBus
        registerEventBus();
    }
    @Override
    protected void attachBaseContext(Context newBase) {
        //app中英文设置
        LocalManageUtil.changeAppLanguage(UserConfigManage.getInstance().getCurrentAppLanguage(), newBase);
        super.attachBaseContext(newBase);
    }
@@ -53,7 +68,7 @@
     */
    protected LoadingDialog getLoadingDialog() {
        if (loadingDialog == null && _mActivity != null) {
            loadingDialog = new LoadingDialog(_mActivity, R.style.Custom_AlertDialog);
            loadingDialog = new LoadingDialog(_mActivity, R.style.Custom_Dialog);
        }
        return loadingDialog;
    }
@@ -95,8 +110,29 @@
        super.onDestroy();
        //隐藏Loading
        hideLoading();
        //移除Activity
        AppManagerUtils.getAppManager().removeActivity(this);
        //注销EventBus
        unregisterEventBus();
    }
    protected void unregisterEventBus() {
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
    }
    protected void registerEventBus() {
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
    }
    @Subscribe(threadMode = ThreadMode.POSTING)
    public void onEventMessage(BaseEventBus eventBus) {
    }
    /**
     * 显示View
@@ -137,6 +173,7 @@
    public int dip2px(float dpValue) {
        final float scale = getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }
    /**