JLChen
2019-08-02 425b2352c57a377b1594097a69aabcc87207b683
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
package com.hdl.sdk.hdl_sdk.base;
 
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;
 
import org.greenrobot.eventbus.EventBus;
 
 
public class BaseActivity extends AppCompatActivity {
    private static final String TAG = "BaseActivity";
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initEventBusRegister();
    }
 
    @Override
    protected void onDestroy() {
        super.onDestroy();
        unEventBusRegister();
    }
 
 
    /**
     * 是否注册事件分发
     *
     * @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);
        }
    }
}