package com.hdl.sdk.ttl_sdk.base; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; import org.greenrobot.eventbus.EventBus; /** * Created by JLChen on 2019/7/4 */ public class BaseActivity extends AppCompatActivity { private static final String TAG = "BaseActivity"; // protected Toolbar mToolBar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); initEventBusRegister(); } @Override protected void onDestroy() { super.onDestroy(); unEventBusRegister(); } // // 抽象 - 初始化方法,可以对数据进行初始化 // protected abstract void initView(); /** * 是否注册事件分发 * * @return true绑定EventBus事件分发,默认不绑定,子类需要绑定的话复写此方法返回true. */ protected boolean isRegisterEventBus() { return false; } /** * 注册事件分发初始化 */ private void initEventBusRegister() { if (isRegisterEventBus()) { if (!EventBus.getDefault().isRegistered(this)) { EventBus.getDefault().register(this); } } } /** * 注册事件分发反始化 */ private void unEventBusRegister() { if (isRegisterEventBus()) { EventBus.getDefault().unregister(this); } } // protected void initToolbar() { // if (mToolBar == null) { // mToolBar = (Toolbar) findViewById(R.id.toolbar_view_b); // if (mToolBar == null) { // // } else { // // } // } // } public void showToast(String text) { Toast.makeText(this, text, Toast.LENGTH_SHORT).show(); } public void startActivity(Class clazz) { Intent intent = new Intent(this, clazz); startActivity(intent); } public static void setViewVisible(View view) { if (view.getVisibility() != View.VISIBLE) { view.setVisibility(View.VISIBLE); } } public static void setViewGone(View view) { if (view.getVisibility() != View.GONE) { view.setVisibility(View.GONE); } } }