|
@@ -15,18 +15,25 @@ import android.webkit.JavascriptInterface;
|
|
|
import android.webkit.WebView;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.hc.lib.DownloadUtils;
|
|
|
import com.hc.lib.MacUtil;
|
|
|
+import com.hc.model.BaseResponse;
|
|
|
import com.hc.model.YNYD.YNYDContentProvider;
|
|
|
import com.hc.model.YNYD.YNYDService;
|
|
|
import com.hc.request.Config;
|
|
|
+import com.hc.request.core.CallServer;
|
|
|
import com.hc.request.core.DefaultCallback;
|
|
|
+import com.hc.request.core.parse.FastGetRequest;
|
|
|
+import com.hc.request.core.parse.FastJsonRequest;
|
|
|
import com.hc.webapp.BuildConfig;
|
|
|
import com.jewel.lib.java.StringUtil;
|
|
|
import com.orhanobut.logger.Logger;
|
|
|
+import com.yanzhenjie.nohttp.rest.Request;
|
|
|
|
|
|
import java.lang.annotation.Retention;
|
|
|
import java.lang.annotation.RetentionPolicy;
|
|
|
+import java.lang.reflect.Method;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
import static com.hc.lib.video.IVideoPlayer.PLAY_TIME_NO_LIMIT;
|
|
@@ -39,6 +46,8 @@ public class AndroidToJS {
|
|
|
public static final String JS_EVENT_PLAY_FINISH = "javascript:onPlayBackEvent()";
|
|
|
private static final String JS_EVENT_AUTH_RESULT = "javascript:onAuthResult(%s, %s)";
|
|
|
public static final String JS_EVENT_PLAY_NEXT = "javascript:onPlayNextEvent()";
|
|
|
+ public static final String JS_PAY_BACK = "javascript:onPayBack()";
|
|
|
+ public static final String WEB_REQUEST_RESPONSE = "javascript:onWebRequestResponse()";
|
|
|
|
|
|
private static final String HAD_FLOAT_VIDEO = "1"; // 当前H5页面存在小窗视频
|
|
|
private static final String NEED_MUTE = "0";
|
|
@@ -50,7 +59,7 @@ public class AndroidToJS {
|
|
|
/**
|
|
|
* JS调用类型
|
|
|
*/
|
|
|
- @StringDef({JS_EVENT_BACK, JS_EVENT_PLAY_FINISH, JS_EVENT_PLAY_NEXT})
|
|
|
+ @StringDef({JS_EVENT_BACK, JS_EVENT_PLAY_FINISH, JS_EVENT_PLAY_NEXT,JS_PAY_BACK,WEB_REQUEST_RESPONSE})
|
|
|
@Retention(RetentionPolicy.SOURCE)
|
|
|
private @interface JsEvent {
|
|
|
|
|
@@ -63,11 +72,35 @@ public class AndroidToJS {
|
|
|
private PlayVideoListener playVideoListener;
|
|
|
private long playTime = PLAY_TIME_NO_LIMIT;
|
|
|
|
|
|
+ //陕西广电盒子参数
|
|
|
+ String stbId = "";
|
|
|
+ String token = "";
|
|
|
+ String userName = "";
|
|
|
+ String cardId="";
|
|
|
+ String versionType="";
|
|
|
+ String mac ="";
|
|
|
+
|
|
|
public AndroidToJS(Context context, WebView webView) {
|
|
|
this.context = context;
|
|
|
this.webView = webView;
|
|
|
contentProvider = new YNYDContentProvider(context);
|
|
|
service = new YNYDService(context);
|
|
|
+ getDeviceInfo();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void getDeviceInfo(){
|
|
|
+ try{
|
|
|
+ Method localMethod = Class.forName("android.os.SystemProperties").getMethod("get", new Class[] { String.class });
|
|
|
+ stbId = (String)localMethod.invoke(null, new Object[] { "ro.di.stb_id" });
|
|
|
+ token = (String)localMethod.invoke(null, new Object[] { "sys.auth.AAAtoken" });
|
|
|
+ userName = (String)localMethod.invoke(null, new Object[] { "sys.auth.username" });
|
|
|
+ cardId = (String)localMethod.invoke(null, new Object[] { "sys.ca.cardid" });
|
|
|
+ versionType = (String)localMethod.invoke(null, new Object[] { "ro.di.hw_version" });
|
|
|
+ mac=(String)localMethod.invoke(null, new Object[] { "ro.di.mac" });
|
|
|
+ Log.d("android_js","token:" + token + "; versionType:" + versionType);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void setPlayVideoListener(PlayVideoListener playVideoListener) {
|
|
@@ -84,7 +117,7 @@ public class AndroidToJS {
|
|
|
*/
|
|
|
@JavascriptInterface
|
|
|
public void playFull(String url, String sourceId, String title, String time, String hadFloatVideo, String isNextVideo, String showCompleteDialog) {
|
|
|
- Logger.d("调用全屏播放。源ID(%s),标题(%s),播放地址(%s)", sourceId, title, url);
|
|
|
+ //Logger.d("调用全屏播放。源ID(%s),标题(%s),播放地址(%s)", sourceId, title, url);
|
|
|
if (playVideoListener != null) {
|
|
|
|
|
|
playTime = PLAY_TIME_NO_LIMIT;
|
|
@@ -94,7 +127,7 @@ public class AndroidToJS {
|
|
|
boolean hadFloat = TextUtils.equals(HAD_FLOAT_VIDEO, hadFloatVideo);
|
|
|
boolean isCurrentNextVideo = TextUtils.equals(HAD_FLOAT_VIDEO, isNextVideo);
|
|
|
boolean isShowCompleteDialog = TextUtils.equals(HAD_FLOAT_VIDEO, showCompleteDialog);
|
|
|
- Logger.d("调用全屏播放。有小窗(%s),当前为非初始视频(%s),显示结束弹窗(%s)", hadFloat, isCurrentNextVideo, isShowCompleteDialog);
|
|
|
+ //Logger.d("调用全屏播放。有小窗(%s),当前为非初始视频(%s),显示结束弹窗(%s)", hadFloat, isCurrentNextVideo, isShowCompleteDialog);
|
|
|
((Activity) context).runOnUiThread(() -> playFull(url, sourceId, title, playTime, hadFloat, isCurrentNextVideo, isShowCompleteDialog, 0));
|
|
|
}
|
|
|
}
|
|
@@ -110,7 +143,7 @@ public class AndroidToJS {
|
|
|
*/
|
|
|
@JavascriptInterface
|
|
|
public void playFull(String url, String sourceId, String title, String time, String hadFloatVideo, String isNextVideo, String showCompleteDialog, int seekTime) {
|
|
|
- Logger.d("调用全屏播放。源ID(%s),标题(%s),播放地址(%s)", sourceId, title, url);
|
|
|
+ //Logger.d("调用全屏播放。源ID(%s),标题(%s),播放地址(%s)", sourceId, title, url);
|
|
|
if (playVideoListener != null) {
|
|
|
|
|
|
playTime = PLAY_TIME_NO_LIMIT;
|
|
@@ -120,7 +153,7 @@ public class AndroidToJS {
|
|
|
boolean hadFloat = TextUtils.equals(HAD_FLOAT_VIDEO, hadFloatVideo);
|
|
|
boolean isCurrentNextVideo = TextUtils.equals(HAD_FLOAT_VIDEO, isNextVideo);
|
|
|
boolean isShowCompleteDialog = TextUtils.equals(HAD_FLOAT_VIDEO, showCompleteDialog);
|
|
|
- Logger.d("调用全屏播放。有小窗(%s),当前为非初始视频(%s),显示结束弹窗(%s),快进时间(%s)", hadFloat, isCurrentNextVideo, isShowCompleteDialog, seekTime);
|
|
|
+ //Logger.d("调用全屏播放。有小窗(%s),当前为非初始视频(%s),显示结束弹窗(%s),快进时间(%s)", hadFloat, isCurrentNextVideo, isShowCompleteDialog, seekTime);
|
|
|
((Activity) context).runOnUiThread(() -> playFull(url, sourceId, title, playTime, hadFloat, isCurrentNextVideo, isShowCompleteDialog, seekTime));
|
|
|
}
|
|
|
}
|
|
@@ -147,10 +180,10 @@ public class AndroidToJS {
|
|
|
@JavascriptInterface
|
|
|
public void playFloat(String url, String sourceId, String title,
|
|
|
final String x, final String y, final String width, final String height, String needMute) {
|
|
|
- Logger.d("调用小窗口播放。播放地址(%s), 源ID(%s),标题(%s)", url, sourceId, title);
|
|
|
- Logger.d("调用小窗口播放。坐标(%s, %s),宽高(%s, %s)", x, y, width, height);
|
|
|
+ //Logger.d("调用小窗口播放。播放地址(%s), 源ID(%s),标题(%s)", url, sourceId, title);
|
|
|
+ //Logger.d("调用小窗口播放。坐标(%s, %s),宽高(%s, %s)", x, y, width, height);
|
|
|
boolean isMute = TextUtils.equals(NEED_MUTE, needMute);
|
|
|
- Logger.d("调用小窗口播放。需要静音:%s", isMute);
|
|
|
+ //Logger.d("调用小窗口播放。需要静音:%s", isMute);
|
|
|
if (isDigitsOnly(x) && isDigitsOnly(y) && isDigitsOnly(width) && isDigitsOnly(height) && playVideoListener != null) {
|
|
|
((Activity) context).runOnUiThread(() -> playFloat(url, sourceId, title,
|
|
|
(int) Float.parseFloat(x),
|
|
@@ -171,7 +204,7 @@ public class AndroidToJS {
|
|
|
*/
|
|
|
@JavascriptInterface
|
|
|
public void closeFloat() {
|
|
|
- Logger.d("关闭小窗口播放。");
|
|
|
+ //Logger.d("关闭小窗口播放。");
|
|
|
if (playVideoListener != null) {
|
|
|
playVideoListener.stopFloatVideo();
|
|
|
}
|
|
@@ -204,8 +237,15 @@ public class AndroidToJS {
|
|
|
}
|
|
|
|
|
|
@JavascriptInterface
|
|
|
+ public void webRequest(String tag,String url){
|
|
|
+ playVideoListener.webRequest(tag,url);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @JavascriptInterface
|
|
|
public String getUser() {
|
|
|
- return contentProvider.getUserName();
|
|
|
+ return userName;
|
|
|
}
|
|
|
|
|
|
@JavascriptInterface
|
|
@@ -219,8 +259,18 @@ public class AndroidToJS {
|
|
|
}
|
|
|
|
|
|
@JavascriptInterface
|
|
|
+ public String getStbId() {
|
|
|
+ return stbId;
|
|
|
+ }
|
|
|
+
|
|
|
+ @JavascriptInterface
|
|
|
public String getToken() {
|
|
|
- return contentProvider.getToken();
|
|
|
+ return token;
|
|
|
+ }
|
|
|
+
|
|
|
+ @JavascriptInterface
|
|
|
+ public String getCardId() {
|
|
|
+ return cardId;
|
|
|
}
|
|
|
|
|
|
@JavascriptInterface
|
|
@@ -240,11 +290,28 @@ public class AndroidToJS {
|
|
|
|
|
|
@JavascriptInterface
|
|
|
public String getMac() {
|
|
|
- return MacUtil.getMac(context);
|
|
|
+ return mac;
|
|
|
+ }
|
|
|
+
|
|
|
+ @JavascriptInterface
|
|
|
+ public String getVersionType() {
|
|
|
+ return versionType;
|
|
|
+ }
|
|
|
+
|
|
|
+ @JavascriptInterface
|
|
|
+ public void toast(String msg){
|
|
|
+ playVideoListener.Toast(msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ @JavascriptInterface
|
|
|
+ public void pay(String orderNum) {
|
|
|
+ Log.d("SXGD","pay, num:" + orderNum);
|
|
|
+ playVideoListener.pay(orderNum);
|
|
|
}
|
|
|
|
|
|
@JavascriptInterface
|
|
|
- public void pay() {
|
|
|
+ public void reLogin() {
|
|
|
+ playVideoListener.reLogin();
|
|
|
}
|
|
|
|
|
|
@JavascriptInterface
|
|
@@ -316,7 +383,7 @@ public class AndroidToJS {
|
|
|
* 调用js事件
|
|
|
*
|
|
|
* @param webView webView
|
|
|
- * @param script {@link AndroidToJS#JS_EVENT_BACK}、{@link AndroidToJS#JS_EVENT_PLAY_FINISH}
|
|
|
+ * @param script {@link AndroidToJS#JS_EVENT_BACK}、{@link AndroidToJS#JS_EVENT_PLAY_FINISH}、{@link AndroidToJS#JS_PAY_BACK、{@link AndroidToJS#WEB_REQUEST_RESPONSE}
|
|
|
*/
|
|
|
public static void evaluateJavascript(WebView webView, @JsEvent String script) {
|
|
|
if (webView == null) {
|
|
@@ -378,7 +445,7 @@ public class AndroidToJS {
|
|
|
* @param sourceId 源ID
|
|
|
* @param playTime 可播放时间。如果为{@link com.hc.lib.video.IVideoPlayer#PLAY_TIME_NO_LIMIT},代表无限制播放
|
|
|
* @param hadFloatVideo 当前H5页面是否有小窗
|
|
|
- * @param seekTime 全屏时需要快进的时间
|
|
|
+ * @param seekTime 全屏时需要快进的时间
|
|
|
*/
|
|
|
void playFullVideo(String url, String title, String uid, String sourceId, long playTime, boolean hadFloatVideo, boolean showCompleteDialog, int seekTime);
|
|
|
|
|
@@ -386,5 +453,25 @@ public class AndroidToJS {
|
|
|
* 结束小窗播放
|
|
|
*/
|
|
|
void stopFloatVideo();
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 支付
|
|
|
+ * */
|
|
|
+ void pay(String orderNum);
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 前端网络访问;
|
|
|
+ * */
|
|
|
+ void webRequest(String tag,String url);
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 提示;
|
|
|
+ * */
|
|
|
+ void Toast(String msg);
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 重新令牌登陆
|
|
|
+ * */
|
|
|
+ void reLogin();
|
|
|
}
|
|
|
}
|