Showing
6 changed files
with
45 additions
and
51 deletions
@@ -18,7 +18,11 @@ import java.util.logging.LogRecord; | @@ -18,7 +18,11 @@ import java.util.logging.LogRecord; | ||
18 | public class ModeHandler extends Handler { | 18 | public class ModeHandler extends Handler { |
19 | 19 | ||
20 | private AppPresentation presentation; | 20 | private AppPresentation presentation; |
21 | - private int mode; | 21 | + private long modeTime = 0; |
22 | + | ||
23 | + public long getModeTime() { | ||
24 | + return modeTime; | ||
25 | + } | ||
22 | 26 | ||
23 | public ModeHandler(AppPresentation presentation) { | 27 | public ModeHandler(AppPresentation presentation) { |
24 | this.presentation = presentation; | 28 | this.presentation = presentation; |
@@ -26,6 +30,7 @@ public class ModeHandler extends Handler { | @@ -26,6 +30,7 @@ public class ModeHandler extends Handler { | ||
26 | 30 | ||
27 | @Override | 31 | @Override |
28 | public void handleMessage(@NonNull Message msg) { | 32 | public void handleMessage(@NonNull Message msg) { |
33 | + modeTime = System.currentTimeMillis(); | ||
29 | presentation.setMode(msg.what); | 34 | presentation.setMode(msg.what); |
30 | super.handleMessage(msg); | 35 | super.handleMessage(msg); |
31 | } | 36 | } |
@@ -57,16 +57,18 @@ public class MainJavaScriptInterface { | @@ -57,16 +57,18 @@ public class MainJavaScriptInterface { | ||
57 | private String time; | 57 | private String time; |
58 | private boolean isSwfPlay = false; | 58 | private boolean isSwfPlay = false; |
59 | private int mode; | 59 | private int mode; |
60 | + private AppPresentation presentation; | ||
60 | 61 | ||
61 | public MainJavaScriptInterface(Activity context, X5WebView x5WebView) { | 62 | public MainJavaScriptInterface(Activity context, X5WebView x5WebView) { |
62 | mContext = context; | 63 | mContext = context; |
63 | mX5WebView = x5WebView; | 64 | mX5WebView = x5WebView; |
64 | } | 65 | } |
65 | 66 | ||
66 | - public MainJavaScriptInterface(Activity context, X5WebView x5WebView, ModeHandler handler) { | 67 | + public MainJavaScriptInterface(Activity context, X5WebView x5WebView, ModeHandler handler, AppPresentation presentation) { |
67 | mContext = context; | 68 | mContext = context; |
68 | mX5WebView = x5WebView; | 69 | mX5WebView = x5WebView; |
69 | this.handler = handler; | 70 | this.handler = handler; |
71 | + this.presentation = presentation; | ||
70 | } | 72 | } |
71 | 73 | ||
72 | /** | 74 | /** |
@@ -244,6 +246,9 @@ public class MainJavaScriptInterface { | @@ -244,6 +246,9 @@ public class MainJavaScriptInterface { | ||
244 | } | 246 | } |
245 | 247 | ||
246 | Tool.startOtherApp(mContext, packageName); | 248 | Tool.startOtherApp(mContext, packageName); |
249 | + if (presentation != null) { | ||
250 | + presentation.dismiss(); | ||
251 | + } | ||
247 | } | 252 | } |
248 | 253 | ||
249 | 254 |
@@ -111,7 +111,7 @@ public final class AiDetailActivity extends AppActivity | @@ -111,7 +111,7 @@ public final class AiDetailActivity extends AppActivity | ||
111 | mControlMode = findViewById(R.id.control_mode); | 111 | mControlMode = findViewById(R.id.control_mode); |
112 | mControlBack.setVisibility(View.VISIBLE); | 112 | mControlBack.setVisibility(View.VISIBLE); |
113 | mControlChange.setVisibility(View.GONE); | 113 | mControlChange.setVisibility(View.GONE); |
114 | - mControlMode.setVisibility(View.VISIBLE); | 114 | + mControlMode.setVisibility(View.GONE); |
115 | mControlLine = findViewById(R.id.control_line); | 115 | mControlLine = findViewById(R.id.control_line); |
116 | mControlBack.setOnClickListener(new View.OnClickListener() { | 116 | mControlBack.setOnClickListener(new View.OnClickListener() { |
117 | @Override | 117 | @Override |
@@ -115,7 +115,7 @@ public final class BrowserActivity extends AppActivity | @@ -115,7 +115,7 @@ public final class BrowserActivity extends AppActivity | ||
115 | mControlMode = findViewById(R.id.control_mode); | 115 | mControlMode = findViewById(R.id.control_mode); |
116 | mControlBack.setVisibility(View.VISIBLE); | 116 | mControlBack.setVisibility(View.VISIBLE); |
117 | mControlChange.setVisibility(View.VISIBLE); | 117 | mControlChange.setVisibility(View.VISIBLE); |
118 | - mControlMode.setVisibility(View.VISIBLE); | 118 | + mControlMode.setVisibility(View.GONE); |
119 | mControlLine = findViewById(R.id.control_line); | 119 | mControlLine = findViewById(R.id.control_line); |
120 | mControlBack.setOnClickListener(new View.OnClickListener() { | 120 | mControlBack.setOnClickListener(new View.OnClickListener() { |
121 | @Override | 121 | @Override |
@@ -190,7 +190,7 @@ public final class BrowserActivity extends AppActivity | @@ -190,7 +190,7 @@ public final class BrowserActivity extends AppActivity | ||
190 | @Override | 190 | @Override |
191 | public boolean dispatchTouchEvent(MotionEvent ev) { | 191 | public boolean dispatchTouchEvent(MotionEvent ev) { |
192 | float y = mControlLine.getY(); | 192 | float y = mControlLine.getY(); |
193 | - if (ev.getY() < y){ | 193 | + if (ev.getY() < y) { |
194 | return super.dispatchTouchEvent(ev); | 194 | return super.dispatchTouchEvent(ev); |
195 | } | 195 | } |
196 | if (presentation != null) { | 196 | if (presentation != null) { |
@@ -230,7 +230,9 @@ public final class BrowserActivity extends AppActivity | @@ -230,7 +230,9 @@ public final class BrowserActivity extends AppActivity | ||
230 | @Override | 230 | @Override |
231 | protected void onDestroy() { | 231 | protected void onDestroy() { |
232 | super.onDestroy(); | 232 | super.onDestroy(); |
233 | - presentation.dismiss(); | 233 | + if (presentation != null) { |
234 | + presentation.dismiss(); | ||
235 | + } | ||
234 | } | 236 | } |
235 | 237 | ||
236 | private class AppBrowserViewClient extends WebViewClient { | 238 | private class AppBrowserViewClient extends WebViewClient { |
@@ -62,7 +62,7 @@ public class BrowserPresentation extends AppPresentation implements StatusAction | @@ -62,7 +62,7 @@ public class BrowserPresentation extends AppPresentation implements StatusAction | ||
62 | mProgressBar = findViewById(R.id.pb_browser_progress); | 62 | mProgressBar = findViewById(R.id.pb_browser_progress); |
63 | mX5WebView = findViewById(R.id.wv_browser_view); | 63 | mX5WebView = findViewById(R.id.wv_browser_view); |
64 | mImgView = findViewById(R.id.loadview); | 64 | mImgView = findViewById(R.id.loadview); |
65 | - mX5WebView.addJavascriptInterface(new MainJavaScriptInterface(getOwnerActivity(), mX5WebView, handler), "studyMachine"); | 65 | + mX5WebView.addJavascriptInterface(new MainJavaScriptInterface(getOwnerActivity(), mX5WebView, handler,this), "studyMachine"); |
66 | 66 | ||
67 | GlideApp.with(getOwnerActivity()) | 67 | GlideApp.with(getOwnerActivity()) |
68 | .asGif() | 68 | .asGif() |
@@ -71,28 +71,19 @@ public class BrowserPresentation extends AppPresentation implements StatusAction | @@ -71,28 +71,19 @@ public class BrowserPresentation extends AppPresentation implements StatusAction | ||
71 | mX5WebView.setWebViewClient(new AppBrowserViewClient()); | 71 | mX5WebView.setWebViewClient(new AppBrowserViewClient()); |
72 | mX5WebView.setWebChromeClient(new AppBrowserChromeClient()); | 72 | mX5WebView.setWebChromeClient(new AppBrowserChromeClient()); |
73 | mX5WebView.loadUrl(url); | 73 | mX5WebView.loadUrl(url); |
74 | -// handler.sendEmptyMessage(0); | ||
75 | -// Runnable task = new Runnable() { | ||
76 | -// public void run() { | ||
77 | -// mX5WebView.evaluateJavascript("javascript:answerExist()", new ValueCallback<String>() { | ||
78 | -// @Override | ||
79 | -// public void onReceiveValue(String s) { | ||
80 | -// try { | ||
81 | -// mode = Integer.valueOf(s); | ||
82 | -// } catch (Exception e) { | ||
83 | -// mode = 0; | ||
84 | -// } | ||
85 | -// | ||
86 | -// } | ||
87 | -// }); | ||
88 | -// | ||
89 | -// handler.sendEmptyMessage(0);//设置循环时间,此处是5秒 | ||
90 | -// handler.postDelayed(this, 100); | ||
91 | -// //需要执行的代码 | ||
92 | -// } | ||
93 | -// }; | ||
94 | -// | ||
95 | -// handler.post(task); | 74 | + handler.sendEmptyMessage(0); |
75 | + Runnable task = new Runnable() { | ||
76 | + public void run() { | ||
77 | + if ((System.currentTimeMillis() - handler.getModeTime()) > 2000) { | ||
78 | + handler.sendEmptyMessage(0);//设置循环时间,此处是5秒 | ||
79 | + } | ||
80 | + | ||
81 | + handler.postDelayed(this, 1000); | ||
82 | + //需要执行的代码 | ||
83 | + } | ||
84 | + }; | ||
85 | + | ||
86 | + handler.post(task); | ||
96 | } | 87 | } |
97 | 88 | ||
98 | 89 |
@@ -112,7 +112,7 @@ public class WebPresentation extends AppPresentation implements StatusAction { | @@ -112,7 +112,7 @@ public class WebPresentation extends AppPresentation implements StatusAction { | ||
112 | mStatusLayout = findViewById(R.id.hl_browser_hint); | 112 | mStatusLayout = findViewById(R.id.hl_browser_hint); |
113 | mIvBack = findViewById(R.id.iv_back); | 113 | mIvBack = findViewById(R.id.iv_back); |
114 | mX5WebView = findViewById(R.id.wv_browser_view); | 114 | mX5WebView = findViewById(R.id.wv_browser_view); |
115 | - MainJavaScriptInterface mainJavaScriptInterface = new MainJavaScriptInterface(getOwnerActivity(), mX5WebView,handler); | 115 | + MainJavaScriptInterface mainJavaScriptInterface = new MainJavaScriptInterface(getOwnerActivity(), mX5WebView,handler,this); |
116 | mX5WebView.addJavascriptInterface(mainJavaScriptInterface, "studyMachine"); | 116 | mX5WebView.addJavascriptInterface(mainJavaScriptInterface, "studyMachine"); |
117 | String currentDateTimeString = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US).format(new Date()); | 117 | String currentDateTimeString = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US).format(new Date()); |
118 | mainJavaScriptInterface.setTime(currentDateTimeString); | 118 | mainJavaScriptInterface.setTime(currentDateTimeString); |
@@ -132,27 +132,18 @@ public class WebPresentation extends AppPresentation implements StatusAction { | @@ -132,27 +132,18 @@ public class WebPresentation extends AppPresentation implements StatusAction { | ||
132 | } | 132 | } |
133 | }); | 133 | }); |
134 | handler.sendEmptyMessage(0); | 134 | handler.sendEmptyMessage(0); |
135 | -// Runnable task = new Runnable() { | ||
136 | -// public void run() { | ||
137 | -// mX5WebView.evaluateJavascript("javascript:answerExist()", new ValueCallback<String>() { | ||
138 | -// @Override | ||
139 | -// public void onReceiveValue(String s) { | ||
140 | -// try { | ||
141 | -// mode = Integer.valueOf(s); | ||
142 | -// } catch (Exception e) { | ||
143 | -// mode = 1; | ||
144 | -// } | ||
145 | -// | ||
146 | -// } | ||
147 | -// }); | ||
148 | -// | ||
149 | -// handler.sendEmptyMessage(mode);//设置循环时间,此处是5秒 | ||
150 | -// handler.postDelayed(this, 1000); | ||
151 | -// //需要执行的代码 | ||
152 | -// } | ||
153 | -// }; | ||
154 | -// | ||
155 | -// handler.post(task); | 135 | + Runnable task = new Runnable() { |
136 | + public void run() { | ||
137 | + if ((System.currentTimeMillis() - handler.getModeTime()) > 2000) { | ||
138 | + handler.sendEmptyMessage(0);//设置循环时间,此处是5秒 | ||
139 | + } | ||
140 | + | ||
141 | + handler.postDelayed(this, 1000); | ||
142 | + //需要执行的代码 | ||
143 | + } | ||
144 | + }; | ||
145 | + | ||
146 | + handler.post(task); | ||
156 | } | 147 | } |
157 | 148 | ||
158 | @Subscribe(threadMode = ThreadMode.MAIN) | 149 | @Subscribe(threadMode = ThreadMode.MAIN) |