Showing
6 changed files
with
45 additions
and
51 deletions
... | ... | @@ -18,7 +18,11 @@ import java.util.logging.LogRecord; |
18 | 18 | public class ModeHandler extends Handler { |
19 | 19 | |
20 | 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 | 27 | public ModeHandler(AppPresentation presentation) { |
24 | 28 | this.presentation = presentation; |
... | ... | @@ -26,6 +30,7 @@ public class ModeHandler extends Handler { |
26 | 30 | |
27 | 31 | @Override |
28 | 32 | public void handleMessage(@NonNull Message msg) { |
33 | + modeTime = System.currentTimeMillis(); | |
29 | 34 | presentation.setMode(msg.what); |
30 | 35 | super.handleMessage(msg); |
31 | 36 | } | ... | ... |
... | ... | @@ -57,16 +57,18 @@ public class MainJavaScriptInterface { |
57 | 57 | private String time; |
58 | 58 | private boolean isSwfPlay = false; |
59 | 59 | private int mode; |
60 | + private AppPresentation presentation; | |
60 | 61 | |
61 | 62 | public MainJavaScriptInterface(Activity context, X5WebView x5WebView) { |
62 | 63 | mContext = context; |
63 | 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 | 68 | mContext = context; |
68 | 69 | mX5WebView = x5WebView; |
69 | 70 | this.handler = handler; |
71 | + this.presentation = presentation; | |
70 | 72 | } |
71 | 73 | |
72 | 74 | /** |
... | ... | @@ -244,6 +246,9 @@ public class MainJavaScriptInterface { |
244 | 246 | } |
245 | 247 | |
246 | 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 | 111 | mControlMode = findViewById(R.id.control_mode); |
112 | 112 | mControlBack.setVisibility(View.VISIBLE); |
113 | 113 | mControlChange.setVisibility(View.GONE); |
114 | - mControlMode.setVisibility(View.VISIBLE); | |
114 | + mControlMode.setVisibility(View.GONE); | |
115 | 115 | mControlLine = findViewById(R.id.control_line); |
116 | 116 | mControlBack.setOnClickListener(new View.OnClickListener() { |
117 | 117 | @Override | ... | ... |
... | ... | @@ -115,7 +115,7 @@ public final class BrowserActivity extends AppActivity |
115 | 115 | mControlMode = findViewById(R.id.control_mode); |
116 | 116 | mControlBack.setVisibility(View.VISIBLE); |
117 | 117 | mControlChange.setVisibility(View.VISIBLE); |
118 | - mControlMode.setVisibility(View.VISIBLE); | |
118 | + mControlMode.setVisibility(View.GONE); | |
119 | 119 | mControlLine = findViewById(R.id.control_line); |
120 | 120 | mControlBack.setOnClickListener(new View.OnClickListener() { |
121 | 121 | @Override |
... | ... | @@ -190,7 +190,7 @@ public final class BrowserActivity extends AppActivity |
190 | 190 | @Override |
191 | 191 | public boolean dispatchTouchEvent(MotionEvent ev) { |
192 | 192 | float y = mControlLine.getY(); |
193 | - if (ev.getY() < y){ | |
193 | + if (ev.getY() < y) { | |
194 | 194 | return super.dispatchTouchEvent(ev); |
195 | 195 | } |
196 | 196 | if (presentation != null) { |
... | ... | @@ -230,7 +230,9 @@ public final class BrowserActivity extends AppActivity |
230 | 230 | @Override |
231 | 231 | protected void onDestroy() { |
232 | 232 | super.onDestroy(); |
233 | - presentation.dismiss(); | |
233 | + if (presentation != null) { | |
234 | + presentation.dismiss(); | |
235 | + } | |
234 | 236 | } |
235 | 237 | |
236 | 238 | private class AppBrowserViewClient extends WebViewClient { | ... | ... |
... | ... | @@ -62,7 +62,7 @@ public class BrowserPresentation extends AppPresentation implements StatusAction |
62 | 62 | mProgressBar = findViewById(R.id.pb_browser_progress); |
63 | 63 | mX5WebView = findViewById(R.id.wv_browser_view); |
64 | 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 | 67 | GlideApp.with(getOwnerActivity()) |
68 | 68 | .asGif() |
... | ... | @@ -71,28 +71,19 @@ public class BrowserPresentation extends AppPresentation implements StatusAction |
71 | 71 | mX5WebView.setWebViewClient(new AppBrowserViewClient()); |
72 | 72 | mX5WebView.setWebChromeClient(new AppBrowserChromeClient()); |
73 | 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 | 112 | mStatusLayout = findViewById(R.id.hl_browser_hint); |
113 | 113 | mIvBack = findViewById(R.id.iv_back); |
114 | 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 | 116 | mX5WebView.addJavascriptInterface(mainJavaScriptInterface, "studyMachine"); |
117 | 117 | String currentDateTimeString = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US).format(new Date()); |
118 | 118 | mainJavaScriptInterface.setTime(currentDateTimeString); |
... | ... | @@ -132,27 +132,18 @@ public class WebPresentation extends AppPresentation implements StatusAction { |
132 | 132 | } |
133 | 133 | }); |
134 | 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 | 149 | @Subscribe(threadMode = ThreadMode.MAIN) | ... | ... |