TIM v2.3.1版本的 MD5 值为:d6957e3ee7ce901ccc491cefdea0da8c
以下内容为反编译后的 QzoneWebMusicJsPlugin.java 源代码,内容仅作参考
package cooperation.qzone.music;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.widget.TextView;
import com.tencent.mobileqq.activity.QQBrowserActivity;
import com.tencent.mobileqq.app.AppConstants;
import com.tencent.mobileqq.music.SongInfo;
import com.tencent.mobileqq.structmsg.StructMsgConstants;
import com.tencent.mobileqq.utils.DialogUtil;
import com.tencent.mobileqq.utils.QQCustomDialog;
import com.tencent.mobileqq.vas.ColorRingConstants;
import com.tencent.mobileqq.vaswebviewplugin.IndividuationPlugin;
import com.tencent.mobileqq.webview.swift.JsBridgeListener;
import com.tencent.mobileqq.webview.swift.WebViewPlugin;
import com.tencent.mobileqq.widget.QQToast;
import com.tencent.qphone.base.util.BaseApplication;
import com.tencent.qphone.base.util.QLog;
import com.tencent.tim.R;
import cooperation.qzone.LocalMultiProcConfig;
import cooperation.qzone.remote.logic.RemoteHandleConst;
import cooperation.qzone.remote.logic.RemoteHandleManager;
import cooperation.qzone.remote.logic.WebEventListener;
import cooperation.qzone.util.NetworkState;
import cooperation.qzone.webviewplugin.QZoneJsConstants;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class QzoneWebMusicJsPlugin extends WebViewPlugin implements WebEventListener {
public static final String CONFIG_MOBINET_TIPS = "qzbg_music_mobinet_tips";
public static final String EVENT_BUFFERING = "buffering";
public static final String EVENT_BUTTON_CLICK = "buttonclick";
public static final String EVENT_CANCEL = "cancel";
public static final String EVENT_ERROR = "error";
public static final String EVENT_FINISH = "finish";
public static final String EVENT_GET_LIVINGINGO = "livinginfo";
public static final String EVENT_GET_NETWORKE_TYPE = "networktype";
public static final String EVENT_GET_PLAY_MODE = "playmode";
public static final String EVENT_GET_SONGINFO = "songinfo";
public static final String EVENT_PAUSED = "paused";
public static final String EVENT_PLAYING = "playing";
public static final String EVENT_STOP = "stop";
public static final String EVENT_UNKOWN = "unknow";
public static final String MUSIC_METHOD_NAMESPACE = "QzMusic";
public static final String WEB_APP_MUSIC_EVENT = "WEBAPP_MUSIC";
private static JsBridgeListener mFMLiveInfoJsBridgeListener;
private boolean isAutoPlay;
public boolean isFlowWarningVisible;
private boolean isRandom;
private boolean isShowing;
private boolean isUseRemoteMusicManager;
private boolean isWebPageListening;
private Handler mMainHandler;
private String TAG = QzoneWebMusicJsPlugin.class.getSimpleName();
private boolean isLoop = true;
public QzoneWebMusicJsPlugin() {
this.mPluginNameSpace = MUSIC_METHOD_NAMESPACE;
}
@Override
public boolean handleJsRequest(JsBridgeListener jsBridgeListener, String str, String str2, String str3, String... strArr) {
if (str2.equals(MUSIC_METHOD_NAMESPACE)) {
if (str3.equals("playMusic") && strArr != null && strArr.length > 0 && !this.isFlowWarningVisible) {
doPlayMusicOrAudioCommon(new ybw(this, strArr[0]));
return true;
} else if (str3.equals("playMusicList") && strArr != null && strArr.length > 0 && !this.isFlowWarningVisible) {
doPlayMusicOrAudioCommon(new ych(this, strArr[0]));
return true;
} else if (str3.equals("playAudioList") && strArr != null && strArr.length > 0 && !this.isFlowWarningVisible) {
doPlayMusicOrAudioCommon(new ycs(this, strArr[0]));
return true;
} else if ("playLiveList".equals(str3) && strArr != null && strArr.length > 0 && !this.isFlowWarningVisible) {
doPlayMusicOrAudioCommon(new yct(this, strArr[0]));
return true;
} else if (str3.equals("resumePlay")) {
resumePlay();
return true;
} else if (str3.equals(QZoneJsConstants.av)) {
pausePlay();
return true;
} else if (str3.equals("listenMusicState") && strArr != null && strArr.length > 0) {
listenMusicState(strArr[0]);
return true;
} else if (str3.equals("musicListChange")) {
musicListChange();
return true;
} else if (str3.equals("setPlayMode") && strArr != null && strArr.length > 0) {
setPlayMode(strArr[0]);
return true;
} else if (str3.equals(IndividuationPlugin.Method_setRightButton) && strArr != null && strArr.length > 0) {
setRightButton(strArr[0]);
return true;
} else if (str3.equals("getPlayingSongInfo")) {
getPlayingSongInfo();
return true;
} else if (str3.equals("playMusicList") && strArr != null && strArr.length > 0) {
playMusicList(strArr[0]);
return true;
} else if (str3.equals("getPlayMode")) {
getPlayMode();
return true;
} else if (str3.equals("getNetworkType")) {
if (NetworkState.e()) {
callNetWorkInterface("true");
} else {
callNetWorkInterface("false");
}
return true;
} else if ("playAudioListForBgMusic".equals(str3) && strArr != null && strArr.length > 0 && !this.isFlowWarningVisible) {
doPlayMusicOrAudioCommon(new ycu(this, strArr[0]));
return true;
} else if ("FmListChange".equals(str3)) {
musicListChange();
return true;
} else if ("getLivingInfo".equals(str3)) {
mFMLiveInfoJsBridgeListener = jsBridgeListener;
getLivingInfo();
return true;
} else {
QLog.w(this.TAG, 1, "method :" + str3 + " 没有做任何处理。");
return false;
}
}
return false;
}
public void playMusic(String str) {
ArrayList arrayList = new ArrayList();
try {
arrayList.add(QzoneMusicHelper.convertSongInfo(new JSONObject(str)));
} catch (JSONException e) {
e.printStackTrace();
}
if (arrayList.size() > 0) {
this.mRuntime.m9632a().getHandler(QzoneWebMusicJsPlugin.class).post(new ycv(this, ((SongInfo) arrayList.get(0)).f90838a == 6 ? 6 : 1, arrayList));
} else if (QLog.isColorLevel()) {
QLog.e(this.TAG, 2, "song info error");
}
}
public void playMusicList(String str) {
int i;
JSONException e;
JSONObject jSONObject;
ArrayList arrayList = new ArrayList();
try {
jSONObject = new JSONObject(str);
i = jSONObject.getInt("index");
} catch (JSONException e2) {
i = 0;
e = e2;
}
try {
JSONArray jSONArray = jSONObject.getJSONArray("songList");
for (int i2 = 0; i2 < jSONArray.length(); i2++) {
arrayList.add(QzoneMusicHelper.convertSongInfo(jSONArray.getJSONObject(i2)));
}
} catch (JSONException e3) {
e = e3;
e.printStackTrace();
if (arrayList.size() <= 0) {
}
}
if (arrayList.size() <= 0) {
this.mRuntime.m9632a().getHandler(QzoneWebMusicJsPlugin.class).post(new ycw(this, i, arrayList));
} else if (QLog.isColorLevel()) {
QLog.e(this.TAG, 2, "no song in song list");
}
}
public void playAudioList(String str) {
int i;
JSONException e;
int i2;
ArrayList arrayList = new ArrayList();
try {
JSONObject jSONObject = new JSONObject(str);
i = jSONObject.getInt("index");
try {
i2 = jSONObject.getInt("playType");
try {
JSONArray jSONArray = jSONObject.getJSONArray("songList");
for (int i3 = 0; i3 < jSONArray.length(); i3++) {
arrayList.add(QzoneMusicHelper.convertAudioSongInfo(jSONArray.getJSONObject(i3)));
}
} catch (JSONException e2) {
e = e2;
e.printStackTrace();
if (arrayList.size() <= 0) {
}
}
} catch (JSONException e3) {
i2 = 0;
e = e3;
}
} catch (JSONException e4) {
i = 0;
e = e4;
i2 = 0;
}
if (arrayList.size() <= 0) {
this.mRuntime.m9632a().getHandler(QzoneWebMusicJsPlugin.class).post(new ycx(this, (i2 == 1 || i2 == 3) ? 2 : 6, i, arrayList));
} else if (QLog.isColorLevel()) {
QLog.e(this.TAG, 2, "no song in song list");
}
}
public void playAudioListForBgMusic(String str) {
ArrayList arrayList = new ArrayList();
try {
JSONObject jSONObject = new JSONObject(str);
int optInt = jSONObject.optInt("index");
JSONArray jSONArray = jSONObject.getJSONArray("songList");
for (int i = 0; i < jSONArray.length(); i++) {
arrayList.add(QzoneMusicHelper.convertFMBgMusic(jSONArray.getJSONObject(i)));
}
if (arrayList.size() > 0) {
this.mRuntime.m9632a().getHandler(QzoneWebMusicJsPlugin.class).post(new ycy(this, optInt, arrayList));
} else {
QLog.e(this.TAG, 2, "playAudioListForBgMusic no song in song list");
}
} catch (JSONException e) {
QLog.e(this.TAG, 1, "playAudioListForBgMusic 参数异常", e);
}
}
public void playFMBrocastList(String str) {
ArrayList arrayList = new ArrayList();
try {
JSONObject jSONObject = new JSONObject(str);
int optInt = jSONObject.optInt("index");
int optInt2 = jSONObject.optInt("playMode");
JSONArray jSONArray = jSONObject.getJSONArray("liveList");
new BroadcastMusicInfo();
for (int i = 0; i < jSONArray.length(); i++) {
arrayList.add(BroadcastMusicInfo.createFromJsonString(jSONArray.getString(i)).toQusicInfo(NetworkState.c()));
}
if (arrayList.size() > 0) {
this.mRuntime.m9632a().getHandler(QzoneWebMusicJsPlugin.class).post(new ybx(this, optInt2 != 1 ? 4 : 2, optInt, arrayList));
} else {
QLog.e(this.TAG, 2, "playAudioListForBgMusic no song in song list");
}
} catch (JSONException e) {
QLog.e(this.TAG, 1, "playFMBrocastList 参数异常", e);
}
}
private boolean needPlayTips() {
return NetworkState.m11078b() && !LocalMultiProcConfig.m10831a(CONFIG_MOBINET_TIPS, false);
}
private boolean needSetAutoPlayTips() {
return BaseApplication.getContext().getSharedPreferences("share", 0).getBoolean(AppConstants.Preferences.dz, true);
}
public long getCurrentHostUin() {
String str = "";
long j = 10000;
try {
str = this.mRuntime.m9631a().getUrl();
String queryParameter = Uri.parse(str).getQueryParameter("guestuin");
if (queryParameter == null) {
j = this.mRuntime.m9632a().getLongAccountUin();
} else {
j = Long.parseLong(queryParameter);
}
} catch (Exception e) {
if (QLog.isColorLevel()) {
QLog.e(this.TAG, 2, "illegal guestuin,url=" + str, e);
}
}
return j;
}
public void resumePlay() {
this.mRuntime.m9632a().getHandler(QzoneWebMusicJsPlugin.class).post(new yby(this));
}
public void pausePlay() {
this.mRuntime.m9632a().getHandler(QzoneWebMusicJsPlugin.class).post(new ybz(this));
}
public void stopPlay() {
this.mRuntime.m9632a().getHandler(QzoneWebMusicJsPlugin.class).post(new yca(this));
}
public void listenMusicState(String str) {
try {
int i = new JSONObject(str).getInt("isOpen");
if (i == 1) {
if (!this.isWebPageListening) {
RemoteHandleManager.a().a(this);
initUserInfo();
}
this.isWebPageListening = true;
this.isUseRemoteMusicManager = true;
} else if (i == 0) {
if (this.isWebPageListening) {
RemoteHandleManager.a().b(this);
}
this.isWebPageListening = false;
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void initUserInfo() {
this.mRuntime.m9632a().getHandler(QzoneWebMusicJsPlugin.class).post(new ycb(this));
}
public void musicListChange() {
this.mRuntime.m9632a().getHandler(QzoneWebMusicJsPlugin.class).post(new ycc(this));
}
public void getPlayingSongInfo() {
this.mRuntime.m9632a().getHandler(QzoneWebMusicJsPlugin.class).post(new ycd(this));
}
public void getLivingInfo() {
this.mRuntime.m9632a().getHandler(QzoneWebMusicJsPlugin.class).post(new yce(this));
}
public void setRightButton(String str) {
try {
JSONObject jSONObject = new JSONObject(str);
String string = jSONObject.getString("text");
String string2 = jSONObject.getString(StructMsgConstants.bK);
boolean z = jSONObject.getBoolean("visible");
if (this.mRuntime.a() instanceof QQBrowserActivity) {
TextView textView = (TextView) this.mRuntime.a().findViewById(R.id.f48299ivTitleBtnRightText);
try {
if (z) {
textView.setVisibility(0);
textView.setTextColor(Color.parseColor("#" + string2));
textView.setText(string);
textView.setOnClickListener(new ycf(this));
} else {
textView.setVisibility(8);
}
} catch (Exception e) {
if (QLog.isColorLevel()) {
QLog.e(this.TAG, 2, "set right textview error");
}
e.printStackTrace();
}
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
public void getPlayMode() {
this.mRuntime.m9632a().getHandler(QzoneWebMusicJsPlugin.class).post(new ycg(this));
}
public void setPlayMode(String str) {
JSONException jSONException;
int i;
int i2;
JSONObject jSONObject;
int i3;
int i4;
int i5 = 0;
if (!NetworkState.d()) {
QQToast.a(BaseApplication.getContext(), 2, QzoneMusicHelper.NO_NETWORK_MSG, 1).m9833a();
getPlayMode();
return;
}
try {
jSONObject = new JSONObject(str);
i3 = jSONObject.optBoolean(QzoneMusicConst.KEY_PLAY_MODE_RANDOM, this.isRandom) ? 1 : 0;
try {
i4 = jSONObject.optBoolean(QzoneMusicConst.KEY_PLAY_MODE_AUTO_PLAY, this.isAutoPlay) ? 1 : 0;
} catch (JSONException e) {
i = i3;
jSONException = e;
}
} catch (JSONException e2) {
jSONException = e2;
i = 0;
}
try {
if (!jSONObject.has(QzoneMusicConst.KEY_PLAY_MODE_LOOP)) {
i5 = -1;
} else if (!jSONObject.optBoolean(QzoneMusicConst.KEY_PLAY_MODE_LOOP)) {
i5 = 1;
}
i2 = i4;
i = i3;
} catch (JSONException e3) {
i5 = i4;
i = i3;
jSONException = e3;
jSONException.printStackTrace();
i2 = i5;
i5 = -1;
boolean needSetAutoPlayTips = needSetAutoPlayTips();
if (i2 != 1) {
}
doSetPlayMode(i, i2, i5);
}
boolean needSetAutoPlayTips2 = needSetAutoPlayTips();
if (i2 != 1 && !this.isAutoPlay && needSetAutoPlayTips2) {
showAutoPlayTips(this.mRuntime.a(), new yci(this), new ycj(this, i, i2, i5), new yck(this));
} else {
doSetPlayMode(i, i2, i5);
}
}
public void doSetPlayMode(int i, int i2, int i3) {
this.mRuntime.m9632a().getHandler(QzoneWebMusicJsPlugin.class).post(new ycl(this, i, i2, i3));
}
public void callWebPageInterface(String str) {
if (this.isWebPageListening && !this.isDestroy) {
this.mRuntime.m9631a().loadUrl("javascript:try{QQMusicJSInterface.onRecieve({type:\"WEBAPP_MUSIC\",data:{type:\"" + str + "\"}})}catch(e){}");
}
}
private void callNetWorkInterface(String str) {
if (!this.isDestroy) {
this.mRuntime.m9631a().loadUrl("javascript:try{QQMusicJSInterface.onRecieve({type:\"networktype\",data:{type:\"isUnicomNetwork\",value:" + str + "}})}catch(e){}");
}
}
private void callNetWorkInterfaceForGetttingLiveInfo(String str, Bundle bundle) {
if (this.mMainHandler == null) {
this.mMainHandler = new Handler(Looper.getMainLooper());
}
this.mMainHandler.post(new ycm(this, bundle));
}
private void callWebPageInterface(String str, Bundle bundle) {
if (this.mMainHandler == null) {
this.mMainHandler = new Handler(Looper.getMainLooper());
}
this.mMainHandler.post(new ycn(this, str, bundle));
}
public void callWebPageInterfaceImpl(String str, Bundle bundle) {
if (this.isWebPageListening) {
JSONObject jSONObject = new JSONObject();
if (bundle != null) {
try {
SongInfo songInfo = (SongInfo) bundle.getParcelable(RemoteHandleConst.ac);
if (songInfo != null) {
jSONObject.put("name", songInfo.f25180b);
jSONObject.put(ColorRingConstants.f34180e, songInfo.f25185g);
jSONObject.put("songId", songInfo.f25176a);
jSONObject.put("singerId", songInfo.f25179b);
jSONObject.put("type", songInfo.f90838a);
jSONObject.put("cover", songInfo.f25182d);
jSONObject.put("playUrl", songInfo.f25178a);
jSONObject.put("detailUrl", songInfo.f25183e);
if (!TextUtils.isEmpty(songInfo.f25181c)) {
jSONObject.put("showId", songInfo.f25181c);
}
switch (songInfo.f90838a) {
case 6:
case 8:
jSONObject.put("voiceType", 1);
break;
case 7:
default:
jSONObject.put("voiceType", 0);
break;
case 9:
jSONObject.put("voiceType", 2);
break;
}
}
jSONObject.put("uin", bundle.getLong("param.uin"));
jSONObject.put("state", getStateString(bundle.getInt(RemoteHandleConst.af, -1)));
jSONObject.put("total", bundle.getInt("param.duration"));
jSONObject.put("curr", bundle.getInt(RemoteHandleConst.ae));
jSONObject.put("isDefaultList", bundle.getInt(RemoteHandleConst.Z) == 2);
} catch (Exception e) {
e.printStackTrace();
}
}
if (bundle != null) {
try {
this.isRandom = bundle.getInt(RemoteHandleConst.ag, 0) == 1;
this.isAutoPlay = bundle.getInt(RemoteHandleConst.ah, 0) == 1;
this.isLoop = bundle.getInt(RemoteHandleConst.ai, 0) == 0;
jSONObject.put(QzoneMusicConst.KEY_PLAY_MODE_RANDOM, this.isRandom);
jSONObject.put(QzoneMusicConst.KEY_PLAY_MODE_AUTO_PLAY, this.isAutoPlay);
jSONObject.put(QzoneMusicConst.KEY_PLAY_MODE_LOOP, this.isLoop);
} catch (Exception e2) {
e2.printStackTrace();
}
}
if (QLog.isColorLevel()) {
QLog.w(this.TAG, 1, " callWebPageInterfaceImpl :" + str + " isdetroy " + this.isDestroy + " value " + jSONObject.toString() + " plugin " + this);
}
if (!this.isDestroy) {
this.mRuntime.m9631a().loadUrl("javascript:try{QQMusicJSInterface.onRecieve({type:\"WEBAPP_MUSIC\",data:{type:\"" + str + "\",value:" + jSONObject.toString() + "}})}catch(e){}");
}
}
}
private String getStateString(int i) {
switch (i) {
case 1:
return EVENT_BUFFERING;
case 2:
return EVENT_PLAYING;
case 3:
return EVENT_PAUSED;
case 4:
case 6:
return "stop";
case 5:
case 7:
return "error";
default:
return "unknow";
}
}
@Override
public void onDestroy() {
super.onDestroy();
RemoteHandleManager.a().b(this);
if (this.isUseRemoteMusicManager) {
RemoteHandleManager.a().m11011a();
}
}
@Override
public void onCreate() {
super.onCreate();
if (this.isWebPageListening) {
RemoteHandleManager.a().a(this);
}
}
@Override
public void onWebEvent(String str, Bundle bundle) {
if (bundle != null && bundle.containsKey("data")) {
Bundle bundle2 = bundle.getBundle("data");
if (bundle2 == null) {
if (QLog.isColorLevel()) {
QLog.e(this.TAG, 2, "call js function,bundle is empty");
return;
}
return;
}
String stateString = getStateString(bundle2.getInt(RemoteHandleConst.af, -1));
if (str.equals(RemoteHandleConst.k)) {
callWebPageInterface(stateString, bundle2);
boolean z = bundle2.getBoolean(RemoteHandleConst.aj);
Activity a2 = this.mRuntime.a();
if (a2 != null && !a2.isFinishing() && !this.isShowing && z && needPlayTips()) {
pausePlay();
showPlayTips(a2, new yco(this), new ycp(this));
this.isShowing = true;
}
} else if (str.equals(RemoteHandleConst.h)) {
callWebPageInterface(EVENT_GET_PLAY_MODE, bundle2);
} else if (str.equals(RemoteHandleConst.g)) {
callWebPageInterface(EVENT_GET_SONGINFO, bundle2);
} else if (str.equals(RemoteHandleConst.q)) {
callNetWorkInterfaceForGetttingLiveInfo(EVENT_GET_LIVINGINGO, bundle2);
}
}
}
private static final void showPlayTips(Context context, DialogInterface.OnClickListener onClickListener, DialogInterface.OnClickListener onClickListener2) {
DialogUtil.a(context, 230, "流量提示", "你正处于非WiFi环境,继续播放将会消耗流量,运营商可能会收取费用,是否继续\n", "继续", "取消", onClickListener2, onClickListener).show();
}
private static final void showAutoPlayTips(Context context, DialogInterface.OnClickListener onClickListener, DialogInterface.OnClickListener onClickListener2, DialogInterface.OnCancelListener onCancelListener) {
QQCustomDialog a2 = DialogUtil.a(context, 230, "", "打开后,wifi环境下访问自己和好友的空间将自动播放背景音乐", "取消", "知道了", onClickListener2, onClickListener);
a2.setOnCancelListener(onCancelListener);
a2.show();
}
private void doPlayMusicOrAudioCommon(ycz yczVar) {
Activity a2 = this.mRuntime.a();
if (a2 != null && needPlayTips()) {
showPlayTips(a2, new ycq(this, yczVar), new ycr(this));
this.isFlowWarningVisible = true;
} else if (yczVar != null) {
yczVar.a();
}
}
}