554325746@qq.com
2019-08-07 2539f53391765abb74b6fe63f46e5a2c701e950f
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
package com.basic.security.activity.helper;
 
import com.basic.security.base.BaseFragment;
import com.basic.security.manager.impl.cblite.BaseSettingManager;
 
import org.androidannotations.annotations.EActivity;
 
import java.util.HashMap;
import java.util.Map;
 
@EActivity
public abstract class MaTimeoutToBlank extends MaClick {
 
    Map<BaseFragment, TimeoutToBlank> timeoutToBlankMap = new HashMap();
    public long currentFragmentShowTime;
 
    public int defaultTimeoutSeconds = 5;
 
    public void refreshCurrentFragmentShowTime(BaseFragment showFragment) {
        currentFragment = showFragment;
        refreshCurrentFragmentShowTime();
    }
 
    public void refreshCurrentFragmentShowTime() {
        currentFragmentShowTime = System.currentTimeMillis();
//        System.out.println("时间 = " +System.currentTimeMillis() );
    }
 
    public boolean isTimeout(int timeoutSeconds) {
        return System.currentTimeMillis() > (currentFragmentShowTime + timeoutSeconds * 1000);
    }
 
    public class TimeoutToBlank {
        public int fixedTimeoutSeconds;
        public BaseFragment from_fragment;
        public BaseFragment to_fragment;
        boolean useDefaultTimeout = true;
 
        public TimeoutToBlank(int fixedTimeoutSeconds, BaseFragment from_fragment, BaseFragment to_fragment) {
            useDefaultTimeout = false;
            this.from_fragment = from_fragment;
            this.fixedTimeoutSeconds = fixedTimeoutSeconds;
            this.to_fragment = to_fragment;
        }
 
        public TimeoutToBlank(BaseFragment from_fragment, BaseFragment to_fragment) {
            this.from_fragment = from_fragment;
            this.to_fragment = to_fragment;
        }
 
        public int getTimeoutSeconds() {
            if (useDefaultTimeout) {
                return defaultTimeoutSeconds;
            } else {
                return fixedTimeoutSeconds;
            }
        }
 
        public void toFragment() {
            if (isTimeout(getTimeoutSeconds())) {
                if (currentFragment == from_fragment) {
                    showFragment(to_fragment);
                }
            }
        }
    }
 
    public void addTimeoutToBlank() {
        timeoutToBlankMap.put(fragment_door_access_result, new TimeoutToBlank(fragment_door_access_result, fragment_su_auto_wait_face));
        timeoutToBlankMap.put(fragment_door_access_fail, new TimeoutToBlank(fragment_door_access_fail, fragment_su_auto_wait_face));
        timeoutToBlankMap.put(fragment_door_access_success, new TimeoutToBlank(fragment_door_access_success, fragment_su_auto_wait_face));
        timeoutToBlankMap.put(fragment_su_auto_wait_face, new TimeoutToBlank(fragment_su_auto_wait_face, fragment_home));
        timeoutToBlankMap.put(fragment_su_auto_wait_admin, new TimeoutToBlank(fragment_su_auto_wait_admin, fragment_su_auto_wait_face));
        timeoutToBlankMap.put(fragment_su_auto_ic_wait_idcard, new TimeoutToBlank(20, fragment_su_auto_ic_wait_idcard, fragment_su_auto_wait_face));
 
        timeoutToBlankMap.put(fragment_sign_up_success, new TimeoutToBlank(5, fragment_sign_up_success, fragment_su_auto_wait_face));
        timeoutToBlankMap.put(fragment_admin_password_login, new TimeoutToBlank(30, fragment_admin_password_login, fragment_home));
        timeoutToBlankMap.put(fragment_admin_face_login, new TimeoutToBlank(10, fragment_admin_face_login, fragment_home));
        timeoutToBlankMap.put(fragment_su_auto_nic_wait_detail, new TimeoutToBlank(25, fragment_su_auto_nic_wait_detail, fragment_home));
        timeoutToBlankMap.put(fragment_su_auto_ic_compare_success, new TimeoutToBlank(25, fragment_su_auto_ic_compare_success, fragment_home));
    }
 
    public boolean needTimeoutToBlank() {
        if (timeoutToBlankMap == null) {
            return false;
        }
        try {
            defaultTimeoutSeconds = BaseSettingManager.getBackToHomeInSeconds();
            TimeoutToBlank timeoutToBlank = timeoutToBlankMap.get(currentFragment);
            if (timeoutToBlank != null) {
                timeoutToBlank.toFragment();
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
 
}