JLChen
2021-11-05 de72a7843ceb868c89fc11983e315849caa28573
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.hdl.sdk.ttl_sdk.base;
 
import android.content.Intent;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Toast;
 
import com.hdl.sdk.ttl_sdk.R;
 
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);
        }
    }
}