zhuguifei
2026-01-14 b7ee99a71e88a08a09fe9daada6675a175d09be1
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
package com.shlb.comb.base;
 
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.TextView;
 
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
 
import com.blankj.utilcode.util.SnackbarUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.qmuiteam.qmui.widget.dialog.QMUITipDialog;
import com.shlb.comb.R;
 
import org.greenrobot.eventbus.EventBus;
 
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
 
import pub.devrel.easypermissions.EasyPermissions;
 
public abstract class BaseActivity extends AppCompatActivity implements View.OnClickListener, EasyPermissions.PermissionCallbacks  {
    public String TAG = this.getClass().getSimpleName();
    //title左边按钮
    protected ImageView iv_left;
    //title标题
    protected TextView tv_center;
    //title右边按钮
    protected ImageView iv_right;
 
 
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        contentView();
        EventBus.getDefault().register(this);
        init();
    }
 
    private void init() {
        initView();
        initData();
        initEvent();
    }
 
    protected void initHead() {
        iv_left = findViewById(R.id.iv_left);
        tv_center = findViewById(R.id.tv_center);
        iv_right = findViewById(R.id.iv_right);
        initHeadEvent();
    }
 
 
    private void initHeadEvent() {
        iv_left.setOnClickListener(this);
        iv_right.setOnClickListener(this);
    }
 
    protected abstract void contentView();
 
    protected abstract void initView();
 
    protected abstract void initData();
 
    protected abstract void initEvent();
 
 
    @Override
    public void setTitle(CharSequence title) {
        tv_center.setText(title);
    }
 
    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.iv_left) {
            finish();
        } else if (id == R.id.iv_right) {
        }
 
    }
 
    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
 
    QMUITipDialog tipDialog;
 
    //弹出提示
    public void showTips(String tips) {
        tipDialog = new QMUITipDialog.CustomBuilder(this)
                .setContent(R.layout.tipdialog_custom)
                .create();
        tipDialog.setCanceledOnTouchOutside(true);
        ((TextView) tipDialog.findViewById(R.id.tv_tip)).setText(tips);
        tipDialog.show();
 
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                if (tipDialog != null)tipDialog.dismiss();
            }
        }, 1500);
//        LogUtils.e("TAG","准备");
//        handler.postDelayed(new Runnable() {
//            @Override
//            public void run() {
//                LogUtils.e("TAG","进入");
//                if (tipDialog != null) {
//                    LogUtils.e("TAG","关闭");
//                    tipDialog.dismiss();
//                }
//            }
//        }, 1500);
    }
    QMUITipDialog  loading;
    public void showLoading(){
        showLoading("正在加载");
    }
 
    public void showLoading(String msg){
        if(loading != null && loading.isShowing()){
            loading.dismiss();
        }
        loading = new QMUITipDialog.Builder(this)
                .setIconType(QMUITipDialog.Builder.ICON_TYPE_LOADING)
                .setTipWord(msg)
                .create();
        loading.show();
    }
 
    public void hiddeLoading(){
        if (loading != null) {
            loading.dismiss();
        }
    }
 
 
    /**
     * 强制隐藏键盘
     */
    protected void hideKeyborad() {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(iv_left.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
 
    /**
     * 打开至指定的Activity
     *
     * @param pClass
     */
    public void openActivity(Class<?> pClass) {
        openActivity(pClass, null);
    }
 
    /**
     * 打开至指定的Activity
     *
     * @param pClass
     * @param pBundle 传值
     */
    public void openActivity(Class<?> pClass, Bundle pBundle) {
        Intent intent = new Intent(this, pClass);
        if (pBundle != null) {
            intent.putExtras(pBundle);
        }
        startActivity(intent);
    }
 
    /**
     * 打开activity
     *
     * @param pAction activity动作
     */
    public void openActivity(String pAction) {
        openActivity(pAction, null);
    }
 
    /**
     * 打开activity
     *
     * @param pAction activity动作
     * @param pBundle 数据
     */
    public void openActivity(String pAction, Bundle pBundle) {
        Intent intent = new Intent(pAction);
        if (pBundle != null) {
            intent.putExtras(pBundle);
        }
        startActivity(intent);
    }
 
    /**
     * 返回activity ,绑定数据
     *
     * @param pClass
     */
    public void returnActivity(Class<?> pClass) {
        returnActivity(pClass, null);
    }
 
    /**
     * 返回activity ,绑定数据
     *
     * @param pClass
     * @param pBundle
     */
    public void returnActivity(Class<?> pClass, Bundle pBundle) {
        Intent intent = new Intent(this, pClass);
        if (pBundle != null) {
            intent.putExtras(pBundle);
        }
        intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        startActivity(intent);
    }
 
    /**
     * 返回activity
     *
     * @param pAction activity动作
     */
    public void returnActivity(String pAction) {
        returnActivity(pAction, null);
    }
 
    /**
     * 返回activity
     *
     * @param pAction activity动作
     * @param pBundle 数据
     */
    public void returnActivity(String pAction, Bundle pBundle) {
        Intent intent = new Intent(pAction);
        if (pBundle != null) {
            intent.putExtras(pBundle);
        }
        intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        startActivity(intent);
    }
 
    public void Toast(String text) {
        ToastUtils.showShort(text);
//        SnackbarUtils.with(tv_center).setDuration(SnackbarUtils.LENGTH_LONG).setMessage(text).show();
    }
    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
 
        // Forward results to EasyPermissions
        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
    }
 
 
 
    @Override
    public void onPermissionsGranted(int requestCode, List<String> list) {
        // Some permissions have been granted
        Toast("权限检测通过!");
    }
 
    @Override
    public void onPermissionsDenied(int requestCode, List<String> list) {
        // Some permissions have been denied
       Toast("未打开所需权限,程序无法正常运行"+list.toString());
    }
 
}