package com.yeshi.video.utils;
|
|
import android.content.Context;
|
import android.webkit.JavascriptInterface;
|
|
|
import com.yeshi.video.entity.UserInfoVO;
|
|
import org.json.JSONObject;
|
|
public class PPJavaInterface {
|
private static final String TAG = "PPJavaInterface";
|
private Context mContext;
|
private IEventListener eventListener;
|
|
public PPJavaInterface(Context context, IEventListener eventListener) {
|
mContext = context;
|
this.eventListener = eventListener;
|
}
|
|
|
/**
|
* 跳转登录页
|
*/
|
@JavascriptInterface
|
public void login() {
|
eventListener.onLogin();
|
}
|
|
|
/**
|
* 返回用户信息(JSON格式)。
|
* code为0标识用户未登录,data的值为空;
|
* code为1表示用户已经登录,data为用户信息
|
* 如: {"code":1,"data":{"code":"123","nickname":"昵称","isSVip":false,"isCoupon":false}}
|
*
|
* @return
|
*/
|
@JavascriptInterface
|
public String getUserInfo() {
|
try {
|
JSONObject root = new JSONObject();
|
UserInfoVO user = null;//UserUtil.getLoginUserInfoDetail(mContext);
|
if (user == null) {
|
root.put("code", 0);
|
} else {
|
root.put("code", 1);
|
JSONObject data = new JSONObject();
|
data.put("code", user.getPptvCode());
|
data.put("nickname", user.getNickName());
|
data.put("isSVip", "false");
|
data.put("isCoupon", false);
|
root.put("data", data);
|
}
|
return root.toString();
|
} catch (Exception e) {
|
|
}
|
return null;
|
}
|
|
|
/**
|
* 试看结束
|
*/
|
@JavascriptInterface
|
public void tryPlayFinish() {
|
eventListener.onTryPlayFinish();
|
}
|
|
/**
|
* 视频播放完成
|
*/
|
@JavascriptInterface
|
public void playFinish() {
|
eventListener.onPlayFinish();
|
}
|
|
/**
|
* 视频信息回调
|
*
|
* @param name 视频名称
|
* @param cid
|
* @param vid
|
*/
|
@JavascriptInterface
|
public void videoInfo(String name, String cid, String vid) {
|
|
}
|
|
@JavascriptInterface
|
public void stopPlay(String cid, String vid, int currentTime) {
|
|
}
|
|
|
public interface IEventListener {
|
public void onLogin();
|
|
public void onTryPlayFinish();
|
|
public void onPlayFinish();
|
|
|
}
|
|
}
|