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 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; } }