mac
2024-01-02 d1ebb94e1a17b7c25d4fcf73d85345d92cc86b5c
app/src/main/java/com/hdl/photovoltaic/base/BaseActivity.java
@@ -2,25 +2,25 @@
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
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.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 +28,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 +45,16 @@
            throw new RuntimeException("getContentView() should be a @LayoutRes or a View");
        }
        onBindView(savedInstanceState);
        //注册EventBus
        registerEventBus();
    }
    @Override
    protected void attachBaseContext(Context newBase) {
        super.attachBaseContext(newBase);
        //app中英文设置
        LocalManageUtil.changeAppLanguage(UserConfigManage.getInstance().getCurrentAppLanguage(), newBase);
    }
@@ -53,7 +65,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,9 +107,30 @@
        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
     *