lmw
2023-03-11 4df5bb59e5fe9f9d140e5610f7772dd8a05a28d4
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
package com.fuban.driver.base;
 
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
 
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
 
import com.fuban.driver.R;
import com.fuban.driver.ui.DialogUtil;
import com.fuban.driver.ui.main.GetOrderFragment;
import com.fuban.driver.ui.main.TripActivity;
import com.fuban.driver.ui.to_city.GetCityFragment;
import com.fuban.driver.utils.ActivityCollector;
import com.fuban.driver.utils.EasePopup.EasyPopup;
import com.github.zackratos.ultimatebar.UltimateBar;
import com.google.gson.Gson;
 
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
 
import java.util.List;
 
import cn.sinata.xldutils.activitys.BaseActivity;
import pub.devrel.easypermissions.EasyPermissions;
 
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
 
/**
 * Created by Administrator on 2018/1/16.
 */
 
public abstract class MyBaseActivity extends BaseActivity implements EasyPermissions.PermissionCallbacks {
    public static final boolean D = true;
    public static final String TAG = "MyBaseActivity";
    //用户token
 
    private LinearLayout title_layout;
    public RelativeLayout rl_title, rl_header;
    public TextView tv_Left, tv_Right;
    public TextView tv_title;
    public TextView tv_test;
 
    public View view_bottom_title;
    public ImageView mIvRight, iv_right_title_two;
    private boolean hasTitle;
    public static final int PAGE_SIZE = 10;//每页条数
    public int pageNumber = 1;//当前第几页
    private boolean isBlackshow = true;//判断是否显示深色导航栏字体
    Bundle bundle;
    Intent intent;
    public Gson gson;
    public EasyPopup easyPopup;
 
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initParam();
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        EventBus.getDefault().register(this);
        ActivityCollector.addActivity(this, getClass());
        ActivityCollector.getActivityCollector().addActivity(this);
        setTouMing();
        initData();
        setBlcakShow(isBlackshow);
        setContentView();
        initView();
        setOnclick();
        settest();
    }
 
    Handler heartHandler;
 
    private void settest() {
//        tv_test.setVisibility(VISIBLE);
//        if (MyApplication.Companion.getLocation().getLatitude() != -1.0){
//            tv_test.setText(
//                    "定位位置:lat="+MyApplication.Companion.getLocation().getLatitude()+"  lng="+MyApplication.Companion.getLocation().getLongitude()
//                            + "  心跳数量()="+MyApplication.Companion.getTestHeartNunm()+"  收到的websocket数量="+MyApplication.Companion.getTestReceiveNum()
//                    +"  方向角="+MyApplication.Companion.getLocation().getBearing()+"  海拔"+MyApplication.Companion.getLocation().getAltitude()
//            );
//        }
//        if (heartHandler == null) {
//            heartHandler = new Handler(getMainLooper());
//        }
//        heartHandler.postDelayed(this::settest,1000);
    }
 
 
    @Override
    public void showDialog() {
        if (easyPopup == null) {
            easyPopup = DialogUtil.INSTANCE.getPopupwindow(this, R.layout.progress_dialog_main);
        }
        if (easyPopup.isShowing()) {
            return;
        }
        getWindow().getDecorView().post(showPopRun);
    }
 
    Runnable showPopRun = new Runnable() {
        @Override
        public void run() {
            easyPopup.showCenter(getWindow().getDecorView());
        }
    };
 
    public void closePop() {
        if (easyPopup != null) {
            getWindow().getDecorView().removeCallbacks(showPopRun);
            if (easyPopup.isShowing()) {
                easyPopup.dismiss();
            }
        }
    }
 
 
    /***
     * type 1:普通单 2:该派单
     * @param orderId
     * @param orderType
     * @param time
     * @param type
     */
    public void showOrder(String orderId, String orderType, int time, int type) {
//        Bundle bundle = creatBundleString("orderId", orderId);
//        bundle.putString("orderType", orderType);
        MyApplication.Companion.getTTsManager().setVideoText("福伴出行,有一条新的订单");
        Intent intent = new Intent(this, GetOrderFragment.class);
        intent.putExtra("orderId", orderId);
        intent.putExtra("orderType", orderType);
        intent.putExtra("time", time);
        intent.putExtra("type", type);
        startActivity(intent);
    }
 
    /***
     * 扫码
     * @param orderId
     * @param orderType
     */
    public void toDorderAct(String orderId, String orderType) {
        MyApplication.Companion.getTTsManager().setVideoText("福伴出行,有一条新的订单");
        Intent intent = new Intent(this, TripActivity.class);
        intent.putExtra("orderId", orderId);
        intent.putExtra("orderType", orderType);
        startActivity(intent);
    }
 
    /***
     * 跨城
     * @param orderId
     * @param orderType
     */
    public void toDorderActCity(String orderId, String orderType) {
        MyApplication.Companion.getTTsManager().setVideoText("福伴出行,有一条新的订单");
        Intent intent = new Intent(this, GetCityFragment.class);
        intent.putExtra("orderId", orderId);
        intent.putExtra("orderType", orderType);
        startActivity(intent);
    }
 
 
    @Override
    protected void onPause() {
        super.onPause();
        closePop();
    }
 
    @Override
    public void dismissDialog() {
        closePop();
    }
 
 
    protected void initParam() {
        gson = new Gson();
        intent = getIntent();
        bundle = intent == null ? null : intent.getExtras();
    }
 
 
    private void setTouMing() {
        UltimateBar.Companion.with(this)
                .statusDrawable2(getResources().getDrawable(R.drawable.bg_lucency))         // Android 6.0 以下状态栏灰色模式时状态栏颜色
                .applyNavigation(true)              // 应用到导航栏,默认 flase
                .navigationDark(false)              // 导航栏灰色模式(Android 8.0+),默认 false
//                .navigationDrawable2(getResources().getDrawable(R.drawable.bg_gray))     // Android 8.0 以下导航栏灰色模式时导航栏颜色
                .create()
                .immersionBar();
    }
 
 
    public void startActivity(Class tClass) {
        startActivity(new Intent(this, tClass));
    }
 
    public void startActivity(Class tClass, Bundle bundle) {
        if (bundle != null) {
            Intent intent = new Intent(this, tClass);
            intent.putExtras(bundle);
            startActivity(intent);
        } else {
            startActivity(tClass);
        }
 
    }
 
    public void startActivityResult(Class tClass, int code) {
        Intent intent = new Intent(this, tClass);
        startActivityForResult(intent, code);
    }
 
 
    public void initData() {
 
    }
 
    /**
     * 设置导航栏字体颜色  黑色 true / 白色 false
     *
     * @param isBlack
     */
    public void setBlcakShow(boolean isBlack) {
        getWindow().getDecorView().setBackgroundResource(R.color.white);
        if (isBlack) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                //设置状态栏文字颜色及图标为深色
                this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
            }
        } else {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                //设置状态栏文字颜色及图标为浅色
                getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            }
        }
    }
 
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(BaseEvent event) {
        switch (event.getCode()) {
            case BaseEvent.OUT_APP:
                finish();
                break;
        }
    }
 
    public abstract void setContentView();
 
    public abstract void initView();
 
    public abstract void setOnclick();
 
 
    @Override
    protected void onDestroy() {
        super.onDestroy();
        ActivityCollector.removeActivity(this);
        ActivityCollector.getActivityCollector().finishActivity(this);
        EventBus.getDefault().unregister(this);
    }
 
//    @Override
//    protected boolean shouldPortrait() {
//        return isShouldPortrait();
//    }
 
    protected boolean isShouldPortrait() {
        return true;
    }
 
 
    /**
     * 获取string数据
     *
     * @param key
     * @return
     */
    public String getBundleString(String key) {
        if (bundle != null) {
            return bundle.getString(key);
        }
        return "";
    }
 
    /**
     * 获取int数据
     *
     * @param key
     * @return
     */
    public int getBundleInt(String key, int defaultValue) {
        if (bundle != null) {
            return bundle.getInt(key, defaultValue);
        }
        return defaultValue;
    }
 
    public Bundle creatBundleString(String key, String value) {
        Bundle bundle = new Bundle();
        bundle.putString(key, value);
        return bundle;
    }
 
    public Object getBundleSerializable(String key) {
        if (bundle != null) {
            return bundle.getSerializable(key);
        }
        return null;
    }
 
    public boolean getBundleBoolean(String key, boolean defaultValue) {
        if (bundle != null) {
            return bundle.getBoolean(key, defaultValue);
        }
        return defaultValue;
    }
 
 
    //设置字体不随系统改变
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        if (newConfig.fontScale != 1)//非默认值
        {
            getResources();
        }
        super.onConfigurationChanged(newConfig);
    }
 
    @Override
    public Resources getResources() {
        Resources res = super.getResources();
        if (res.getConfiguration().fontScale != 1) { //非默认值
            Configuration newConfig = new Configuration();
            newConfig.setToDefaults();//设置默认
            res.updateConfiguration(newConfig, res.getDisplayMetrics());
        }
        return res;
    }
 
 
    /**
     * 结束页面的时候将页面中相关控件移除
     * http://blog.csdn.net/newlai913/article/details/78095873
     */
    @Override
    public void finish() {
        super.finish();
    }
 
    @SuppressLint("ResourceType")
    @Override
    public void setContentView(@LayoutRes int layoutResID) {
        super.setContentView(R.layout.app_title);
        init();
        if (layoutResID > 0) {
            LayoutInflater.from(this).inflate(layoutResID, title_layout, true);
        }
    }
 
    @Override
    public void setContentView(View view) {
        super.setContentView(view);
        init();
        if (view != null) {
            title_layout.addView(view);
        }
    }
 
    @Override
    public void setContentView(View view, ViewGroup.LayoutParams params) {
        super.setContentView(view, params);
        init();
        if (view != null) {
            title_layout.addView(view, params);
        }
    }
 
    private void init() {
        title_layout = (LinearLayout) findViewById(R.id.title_layout);
        rl_title = (RelativeLayout) findViewById(R.id.rl_title);
        tv_Left = (TextView) findViewById(R.id.tv_left_title);
        tv_Right = (TextView) findViewById(R.id.tv_right_title);
        rl_header = (RelativeLayout) findViewById(R.id.rl_header_title);
        tv_title = (TextView) findViewById(R.id.tv_title);
        view_bottom_title = findViewById(R.id.view_bottom_title);
        mIvRight = findViewById(R.id.iv_right_title);
        iv_right_title_two = findViewById(R.id.iv_right_title_two);
        tv_test = findViewById(R.id.tv_test_content);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
            rl_header.setBackgroundResource(R.color.gray);
        }
 
        setBack(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
 
    }
 
    @Override
    public boolean onTouchEvent(@NonNull MotionEvent event) {
        if (null != this.getCurrentFocus()) {
            /**
             * 点击空白位置 隐藏软键盘
             */
            InputMethodManager mInputMethodManager = null;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.CUPCAKE) {
                mInputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.CUPCAKE) {
                if (mInputMethodManager != null) {
                    return mInputMethodManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);
                }
            }
        }
        return super.onTouchEvent(event);
    }
 
 
    /**
     * 是否显示title
     *
     * @param hasTitle
     */
    public void showTitle(boolean hasTitle) {
        rl_title.setVisibility(hasTitle ? VISIBLE : GONE);
    }
 
    public ImageView getmIvRight() {
        return mIvRight;
    }
 
    public ImageView getIv_right_title_two() {
        return iv_right_title_two;
    }
 
    public void setBack(View.OnClickListener onClickListener) {
        tv_Left.setOnClickListener(onClickListener);
    }
 
    /**
     * 是否显示返回键
     *
     * @param v
     */
    public void showBack(int v) {
        tv_Left.setVisibility(v);
    }
 
    /**
     * 是否显示白色状态栏
     *
     * @param hasHeader 是否显示头部
     */
    public void showHeader(boolean hasHeader) {
        rl_header.setVisibility(hasHeader ? VISIBLE : GONE);
    }
 
    /**
     * 设置title文字
     *
     * @param titleId
     */
    public void setTitleText(int titleId) {
        tv_title.setText(titleId);
    }
 
    /**
     * 设置title文字
     *
     * @param title
     */
    public void setTitleText(String title) {
        tv_title.setText(title);
    }
 
    //设置title点击事件
    public void setTitleOnClicker(View.OnClickListener onClicker) {
        tv_title.setOnClickListener(onClicker);
    }
 
    //设置title图片资源id
    public void setTitleShow(int ResId) {
        Drawable nav_up = getResources().getDrawable(ResId);
        nav_up.setBounds(0, 0, nav_up.getMinimumWidth(), nav_up.getMinimumHeight());
        tv_title.setCompoundDrawables(null, null, nav_up, null);
    }
 
    /**
     * 设置左边按钮文字
     *
     * @param titleId
     */
    public void setLeftText(int titleId) {
        tv_Left.setText(titleId);
    }
 
    public void setRightImg(Drawable drawable) {
        tv_Right.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null);
    }
 
    /**
     * 设置右边按钮文字
     *
     * @param titleId
     */
    public void setRightText(String titleId) {
        tv_Right.setText(titleId);
    }
 
    public void setRightClickerable(boolean clickerable) {
        tv_Right.setEnabled(clickerable);
    }
 
    public void setRightButton(View.OnClickListener onClickListener) {
        tv_Right.setOnClickListener(onClickListener);
    }
 
    /**
     * 设置是否显示分割线
     */
    public void setBottomShow(boolean isShow) {
        if (isShow) {
            view_bottom_title.setVisibility(View.VISIBLE);
        } else {
            view_bottom_title.setVisibility(View.INVISIBLE);
        }
    }
 
 
    /***
     * 添加一个fragment 到栈
     * @param fragment 目标类
     * @param container 容器id
     */
    public void addFragment(Fragment fragment, int container) {
        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        if (!fragment.isAdded()) {
            fragmentTransaction.add(container, fragment);
        }
        for (Fragment currentFragment : getSupportFragmentManager().getFragments()) {
            if (currentFragment.isAdded() && currentFragment != fragment) {
                fragmentTransaction.hide(currentFragment);
            }
        }
        fragmentTransaction.show(fragment);
        fragmentTransaction.commitAllowingStateLoss();
        getSupportFragmentManager().executePendingTransactions();
    }
 
 
    //    获取权限
    public boolean checkPermissions(String... per) {
        if (EasyPermissions.hasPermissions(this, per)) {
            //已经打开权限
            return true;
        } else {
            return false;
        }
    }
 
    //成功打开权限
    @Override
    public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) {
 
    }
 
    //用户未同意权限
    @Override
    public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) {
 
    }
 
 
    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
    }
 
 
    public void closeSoftKeybord(EditText mEditText, Context mContext) {
        InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null)
            imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
    }
 
}