PageRenderTime 613ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/ShareText/youkuLoginSDK/src/main/java/com/youku/login/util/Utils.java

https://gitlab.com/ShaneNilsson/JarToUnity
Java | 961 lines | 74 code | 9 blank | 878 comment | 5 complexity | 0e7c0b01b8f36878e76007e47fe41470 MD5 | raw file
  1. package com.youku.login.util;
  2. import java.io.UnsupportedEncodingException;
  3. import java.lang.reflect.Field;
  4. import java.util.Calendar;
  5. import java.util.Set;
  6. import android.annotation.SuppressLint;
  7. import android.app.Activity;
  8. import android.app.DownloadManager;
  9. import android.content.Context;
  10. import android.content.DialogInterface;
  11. import android.content.DialogInterface.OnCancelListener;
  12. import android.content.Intent;
  13. import android.content.pm.ActivityInfo;
  14. import android.content.res.Configuration;
  15. import android.content.res.Resources;
  16. import android.graphics.Point;
  17. import android.os.BatteryManager;
  18. import android.preference.PreferenceManager;
  19. import android.provider.MediaStore.Audio.Media;
  20. import android.support.v4.widget.SwipeRefreshLayout;
  21. import android.text.TextUtils;
  22. import android.util.Base64;
  23. import android.util.DisplayMetrics;
  24. import android.util.TypedValue;
  25. import android.view.View;
  26. import android.view.View.OnClickListener;
  27. import android.view.ViewConfiguration;
  28. import android.widget.ImageView;
  29. import android.widget.TextView;
  30. import com.alibaba.fastjson.JSONObject;
  31. import com.baseproject.utils.UIUtils;
  32. import com.example.youkuloginsdk.R;
  33. import com.youku.analytics.Constants;
  34. import com.youku.login.config.Profile;
  35. import com.youku.login.network.HttpIntent;
  36. import com.youku.login.network.HttpRequestManager;
  37. import com.youku.login.network.IHttpRequest;
  38. import com.youku.login.network.IHttpRequest.IHttpRequestCallBack;
  39. import com.youku.login.network.URLContainer;
  40. import com.youku.login.service.YoukuService;
  41. public final class Utils {
  42. private Utils() {
  43. }
  44. public static boolean isVipUser() {
  45. boolean isVipUser = false;
  46. if (!TextUtils.isEmpty(Youku.COOKIE)) {
  47. try {
  48. // cookie里边的yktk 键的内容是由| 分隔的。用base64
  49. // 把第4个内容解析出来。解析出来后的内容格式是id:XXX,nn:XXX,vip:true,ytid:XXX,tid:XXX。vip
  50. // 字段内容true 代表vip .false代表不是。
  51. org.json.JSONObject objContent = BaseHelper.string2JSON(Youku.COOKIE, ";");
  52. String yktk = objContent.getString("yktk");
  53. String decode_yktk = URLDecoder(yktk);
  54. String[] decode_yktk_array = decode_yktk.split("\\|");
  55. String base64_temp = decode_yktk_array[3];
  56. String temp = new String(Base64.decode(base64_temp, Base64.DEFAULT), "utf-8");
  57. isVipUser = temp.contains("vip:true");
  58. } catch (Exception e) {
  59. e.printStackTrace();
  60. isVipUser = false;
  61. }
  62. }
  63. return isVipUser;
  64. }
  65. private static String URLDecoder(String s) {
  66. if (s == null || s.length() == 0)
  67. return "";
  68. try {
  69. s = java.net.URLDecoder.decode(s, "UTF-8");
  70. } catch (UnsupportedEncodingException e) {
  71. return "";
  72. } catch (NullPointerException e) {
  73. return "";
  74. }
  75. return s;
  76. }
  77. /* public static void setSwipeRefreshLayoutHeight(Context mContext, SwipeRefreshLayout mSwipeRefreshLayout) {
  78. try {
  79. Class<SwipeRefreshLayout> mClass = SwipeRefreshLayout.class;
  80. Field field = mClass.getDeclaredField("mProgressBarHeight");
  81. field.setAccessible(true);
  82. DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
  83. field.set(mSwipeRefreshLayout, (int) (metrics.density * 2F));
  84. } catch (NoSuchFieldException e) {
  85. e.printStackTrace();
  86. } catch (IllegalAccessException e) {
  87. e.printStackTrace();
  88. } catch (IllegalArgumentException e) {
  89. e.printStackTrace();
  90. } catch (Exception e) {
  91. e.printStackTrace();
  92. }
  93. }
  94. public static String getFormatTime(long millseconds) {
  95. long seconds = millseconds / 1000;
  96. StringBuffer buf = new StringBuffer();
  97. // long hour = seconds / 3600;
  98. long min = seconds / 60 - hour * 60;
  99. long sec = seconds - hour * 3600- min * 60;
  100. * if (hour < 10) { buf.append("0"); } buf.append(hour).append(":");
  101. if (min < 10) {
  102. buf.append("0");
  103. }
  104. buf.append(min).append(":");
  105. if (sec < 10) {
  106. buf.append("0");
  107. }
  108. buf.append(sec);
  109. return buf.toString();
  110. }
  111. public static String getFormatTimeForGesture(long millseconds) {
  112. long tempSeconds = millseconds / 1000;
  113. StringBuffer buf = new StringBuffer();
  114. long seconds = tempSeconds % 60;
  115. long minutes = tempSeconds / 60;
  116. if (minutes < 10) {
  117. buf.append("0");
  118. }
  119. buf.append(minutes).append(":");
  120. if (seconds < 10) {
  121. buf.append("0");
  122. }
  123. buf.append(seconds);
  124. return buf.toString();
  125. }
  126. *//**
  127. * 是否是剧集网格样式
  128. *
  129. * @return
  130. *//*
  131. public static boolean isSeriesGrid() {
  132. if (DetailDataSource.mDetailVideoInfo != null) {
  133. switch (DetailDataSource.mDetailVideoInfo.getType()) {
  134. case Constants.CARTOON_MANY:
  135. case Constants.CARTOON_SINGLE:
  136. case Constants.SHOW_MANY:
  137. case Constants.SHOW_SINLE:
  138. return true;
  139. default:
  140. break;
  141. }
  142. }
  143. return false;
  144. }
  145. private static boolean isVideoInfoDataValid(PluginOverlay mPluginOverlay) {
  146. return mPluginOverlay != null && mPluginOverlay.mMediaPlayerDelegate != null && mPluginOverlay.mMediaPlayerDelegate.videoInfo != null;
  147. }
  148. *//**
  149. * 是否是专辑
  150. *
  151. * @return
  152. *//*
  153. public static boolean isAlbum(PluginOverlay mPluginOverlay) {
  154. if (isVideoInfoDataValid(mPluginOverlay)) {
  155. return !TextUtils.isEmpty(mPluginOverlay.mMediaPlayerDelegate.videoInfo.playlistId);
  156. }
  157. return false;
  158. }
  159. *//**
  160. * 是否是Show
  161. *
  162. * @return
  163. *//*
  164. public static boolean isShow(PluginOverlay mPluginOverlay) {
  165. if (isVideoInfoDataValid(mPluginOverlay)) {
  166. return !TextUtils.isEmpty(mPluginOverlay.mMediaPlayerDelegate.videoInfo.getShowId());
  167. }
  168. return false;
  169. }
  170. *//**
  171. * 是否是UGC
  172. *
  173. * @return
  174. *//*
  175. public static boolean isUGC(PluginOverlay mPluginOverlay) {
  176. return !isAlbum(mPluginOverlay) && !isShow(mPluginOverlay) && !isMusic();
  177. }
  178. *//**
  179. * 是否播放的是本地视频
  180. *
  181. * @return
  182. *//*
  183. public static boolean isPlayLocalType(PluginOverlay mPluginOverlay) {
  184. return mPluginOverlay != null && mPluginOverlay.mMediaPlayerDelegate != null && mPluginOverlay.mMediaPlayerDelegate.isPlayLocalType();
  185. }
  186. *//**
  187. * 是否播放的是本机视频
  188. *
  189. * @return
  190. *//*
  191. public static boolean isPlayExternalVideo(PluginOverlay mPluginOverlay) {
  192. return mPluginOverlay != null && mPluginOverlay.mMediaPlayerDelegate != null && mPluginOverlay.mMediaPlayerDelegate.videoInfo != null && mPluginOverlay.mMediaPlayerDelegate.videoInfo.isExternalVideo;
  193. }
  194. *//**
  195. * 是否播放的是直播
  196. *
  197. * @return
  198. *//*
  199. public static boolean isPlayLive(PluginOverlay mPluginOverlay) {
  200. return mPluginOverlay != null && mPluginOverlay.mMediaPlayerDelegate != null && mPluginOverlay.mMediaPlayerDelegate.videoInfo != null && mPluginOverlay.mMediaPlayerDelegate.videoInfo.isHLS;
  201. }
  202. *//**
  203. * 是否是音乐
  204. *
  205. * @return
  206. *//*
  207. public static boolean isMusic() {
  208. if (DetailDataSource.mDetailVideoInfo != null) {
  209. switch (DetailDataSource.mDetailVideoInfo.getType()) {
  210. case Constants.MUSIC:
  211. return true;
  212. default:
  213. break;
  214. }
  215. }
  216. return false;
  217. }
  218. *//**
  219. * 是否是音乐类型且没有歌手
  220. *
  221. * @return
  222. *//*
  223. public static boolean isMusicNoSinger() {
  224. return isMusic() && TextUtils.isEmpty(DetailDataSource.mDetailVideoInfo.getSinger());
  225. }
  226. *//**
  227. * 是否请求相关片段
  228. *
  229. * @return
  230. *//*
  231. public static boolean isRequestRelatedPart(PluginOverlay mPluginOverlay) {
  232. if (isPlayingRelatedPart(mPluginOverlay) || isDetailDataValid() && !isMusic() && !TextUtils.isEmpty(DetailDataSource.mDetailVideoInfo.getShow_videotype()) && !"正片".equals(DetailDataSource.mDetailVideoInfo.getShow_videotype())) {
  233. return true;
  234. }
  235. return false;
  236. }
  237. *//**
  238. * 是否剧集是倒序
  239. *
  240. * @return
  241. *//*
  242. public static boolean isSeriesReversed() {
  243. if (DetailDataSource.mSeriesVideoDataInfo != null) {
  244. return DetailDataSource.mSeriesVideoDataInfo.isReversed();
  245. }
  246. return false;
  247. }
  248. public static boolean isDetailDataValid() {
  249. return DetailDataSource.mDetailVideoInfo != null;
  250. }
  251. public static String[] getCacheSelectedVids(Set<CacheSelectedInfo> cacheSelectedInfos) {
  252. String[] vidStrings = new String[cacheSelectedInfos.size()];
  253. int i = 0;
  254. for (CacheSelectedInfo cacheSelectedInfo : cacheSelectedInfos) {
  255. vidStrings[i] = cacheSelectedInfo.getVid();
  256. i++;
  257. }
  258. return vidStrings;
  259. }
  260. public static String[] getCacheSelectedTitles(Set<CacheSelectedInfo> cacheSelectedInfos) {
  261. String[] titleStrings = new String[cacheSelectedInfos.size()];
  262. int i = 0;
  263. for (CacheSelectedInfo cacheSelectedInfo : cacheSelectedInfos) {
  264. titleStrings[i] = cacheSelectedInfo.getTitle();
  265. i++;
  266. }
  267. return titleStrings;
  268. }
  269. *//**
  270. * 获取缓存默认设置格式
  271. *
  272. * @param mContext
  273. * @return
  274. *//*
  275. public static String getDownloadFormatString(Context mContext) {
  276. String downloadFormatString = null;
  277. switch (DownloadManager.getInstance().getDownloadFormat()) {
  278. case Youku.FORMAT_3GPHD:
  279. case Youku.FORMAT_FLV:
  280. downloadFormatString = mContext.getResources().getString(R.string.standard_definition);
  281. break;
  282. case Youku.FORMAT_MP4:
  283. downloadFormatString = mContext.getResources().getString(R.string.high_definition);
  284. break;
  285. case Youku.FORMAT_HD2:
  286. downloadFormatString = mContext.getResources().getString(R.string.super_definition);
  287. break;
  288. default:
  289. downloadFormatString = mContext.getResources().getString(R.string.standard_definition);
  290. break;
  291. }
  292. return downloadFormatString;
  293. }
  294. *//**
  295. * 锁屏
  296. *
  297. * @param mActivity
  298. *//*
  299. public static void lockScreen(Activity mActivity) {
  300. switch (mActivity.getResources().getConfiguration().orientation) {
  301. case Configuration.ORIENTATION_LANDSCAPE:
  302. if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO) {
  303. mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
  304. } else {
  305. int rotation = mActivity.getWindowManager().getDefaultDisplay().getRotation();
  306. if (rotation == android.view.Surface.ROTATION_0 || rotation == android.view.Surface.ROTATION_90) {
  307. mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
  308. } else {
  309. mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
  310. }
  311. }
  312. break;
  313. }
  314. }
  315. *//**
  316. * 解锁屏
  317. *
  318. * @param mActivity
  319. *//*
  320. public static void unlockScreen(Activity mActivity) {
  321. if (Configuration.ORIENTATION_LANDSCAPE == UIUtils.getDeviceDefaultOrientation(mActivity)) {
  322. mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
  323. } else {
  324. mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
  325. }
  326. }
  327. public static boolean checkNetPlayVideo(String videoid) {
  328. if (TextUtils.isEmpty(videoid)) {
  329. return false;
  330. }
  331. if (!YoukuUtil.hasInternet()) {// 无网
  332. if (!DownloadManager.getInstance().isDownloadFinished(videoid)) {// 无缓存
  333. YoukuUtil.showTips(R.string.tips_no_network);
  334. return false;
  335. }
  336. }
  337. if (YoukuUtil.hasInternet() && !YoukuUtil.isWifi()) {// 3g
  338. boolean isAllow3GPlay = PreferenceManager.getDefaultSharedPreferences(Youku.context).getBoolean("allowONline3G", true);
  339. if (!isAllow3GPlay) {// 禁止3g播放
  340. if (!DownloadManager.getInstance().isDownloadFinished(videoid)) {// 无缓存
  341. YoukuUtil.showTips(R.string.detail_3g_tips);
  342. return false;
  343. }
  344. }
  345. }
  346. return true;
  347. }
  348. public static String isHasNextAlbum(PluginOverlay mPluginOverlay) {
  349. String nextVideoId = null;
  350. if (Utils.isAlbum(mPluginOverlay)) {
  351. String vid = mPluginOverlay.mMediaPlayerDelegate.videoInfo.getVid();
  352. int length = DetailDataSource.allSeriesVideos.size();
  353. if (length > 0 && !TextUtils.isEmpty(vid)) {
  354. int index = -1;
  355. for (int i = 0; i < length; i++) {
  356. if (TextUtils.equals(vid, DetailDataSource.allSeriesVideos.get(i).getVideoid())) {
  357. index = i;
  358. break;
  359. }
  360. }
  361. if (index >= 0 && index + 1 < length) {
  362. nextVideoId = DetailDataSource.allSeriesVideos.get(index + 1).getVideoid();
  363. }
  364. }
  365. }
  366. return nextVideoId;
  367. }
  368. public static boolean isInShowSeries(PluginOverlay mPluginOverlay) {
  369. if (Utils.isShow(mPluginOverlay)) {
  370. String vid = mPluginOverlay.mMediaPlayerDelegate.videoInfo.getVid();
  371. int length = DetailDataSource.allSeriesVideos.size();
  372. if (length > 0 && !TextUtils.isEmpty(vid)) {
  373. for (int i = 0; i < length; i++) {
  374. if (TextUtils.equals(vid, DetailDataSource.allSeriesVideos.get(i).getVideoid())) {
  375. return true;
  376. }
  377. }
  378. }
  379. }
  380. return false;
  381. }
  382. public static boolean isInShowPart(PluginOverlay mPluginOverlay) {
  383. if (Utils.isShow(mPluginOverlay)) {
  384. String vid = mPluginOverlay.mMediaPlayerDelegate.videoInfo.getVid();
  385. int length = DetailDataSource.playRelatedParts.size();
  386. if (length > 0 && !TextUtils.isEmpty(vid)) {
  387. for (int i = 0; i < length; i++) {
  388. if (TextUtils.equals(vid, DetailDataSource.playRelatedParts.get(i).getVideoid())) {
  389. return true;
  390. }
  391. }
  392. }
  393. }
  394. return false;
  395. }
  396. public static String isHasNextShowSeries(PluginOverlay mPluginOverlay) {
  397. String nextVideoId = null;
  398. if (Utils.isShow(mPluginOverlay)) {
  399. String vid = mPluginOverlay.mMediaPlayerDelegate.videoInfo.getVid();
  400. int length = DetailDataSource.allSeriesVideos.size();
  401. if (length > 0 && !TextUtils.isEmpty(vid)) {
  402. int index = -1;
  403. if (Utils.isSeriesReversed()) {
  404. for (int i = length - 1; i >= 0; i--) {
  405. if (TextUtils.equals(vid, DetailDataSource.allSeriesVideos.get(i).getVideoid())) {
  406. index = i;
  407. break;
  408. }
  409. }
  410. if (index >= 0 && index - 1 >= 0) {
  411. nextVideoId = DetailDataSource.allSeriesVideos.get(index - 1).getVideoid();
  412. }
  413. } else {
  414. for (int i = 0; i < length; i++) {
  415. if (TextUtils.equals(vid, DetailDataSource.allSeriesVideos.get(i).getVideoid())) {
  416. index = i;
  417. break;
  418. }
  419. }
  420. if (index >= 0 && index + 1 < length) {
  421. nextVideoId = DetailDataSource.allSeriesVideos.get(index + 1).getVideoid();
  422. }
  423. }
  424. }
  425. }
  426. return nextVideoId;
  427. }
  428. public static String isHasNextUGC(PluginOverlay mPluginOverlay) {
  429. String nextVideoId = null;
  430. if (Utils.isUGC(mPluginOverlay)) {
  431. if (DetailDataSource.mPlayRelatedVideoDataInfo != null) {
  432. int length = DetailDataSource.mPlayRelatedVideoDataInfo.getPlayRelatedVideos().size();
  433. for (int i = 0; i < length; i++) {
  434. String videoid = DetailDataSource.mPlayRelatedVideoDataInfo.getPlayRelatedVideos().get(i).getVideoid();
  435. String showid = DetailDataSource.mPlayRelatedVideoDataInfo.getPlayRelatedVideos().get(i).getShowid();
  436. if (!TextUtils.isEmpty(videoid) || !TextUtils.isEmpty(showid)) {
  437. nextVideoId = TextUtils.isEmpty(videoid) ? showid : videoid;
  438. break;
  439. }
  440. }
  441. }
  442. }
  443. return nextVideoId;
  444. }
  445. public static String isHasFirstShowPart(PluginOverlay mPluginOverlay) {
  446. String nextVideoId = null;
  447. if (Utils.isShow(mPluginOverlay)) {
  448. int length = DetailDataSource.playRelatedParts.size();
  449. if (length > 0) {
  450. nextVideoId = DetailDataSource.playRelatedParts.get(0).getVideoid();
  451. }
  452. }
  453. return nextVideoId;
  454. }
  455. public static String isHasNextShowPart(PluginOverlay mPluginOverlay) {
  456. String nextVideoId = null;
  457. if (Utils.isShow(mPluginOverlay)) {
  458. String vid = mPluginOverlay.mMediaPlayerDelegate.videoInfo.getVid();
  459. int length = DetailDataSource.playRelatedParts.size();
  460. if (length > 0 && !TextUtils.isEmpty(vid)) {
  461. int index = -1;
  462. for (int i = 0; i < length; i++) {
  463. if (TextUtils.equals(vid, DetailDataSource.playRelatedParts.get(i).getVideoid())) {
  464. index = i;
  465. break;
  466. }
  467. }
  468. if (index >= 0 && index + 1 < length) {
  469. nextVideoId = DetailDataSource.playRelatedParts.get(index + 1).getVideoid();
  470. }
  471. }
  472. }
  473. return nextVideoId;
  474. }
  475. public static boolean isPlayingRelatedPart(PluginOverlay mPluginOverlay) {
  476. if (Utils.isShow(mPluginOverlay)) {
  477. String vid = mPluginOverlay.mMediaPlayerDelegate.videoInfo.getVid();
  478. int length = DetailDataSource.playRelatedParts.size();
  479. if (length > 0 && !TextUtils.isEmpty(vid)) {
  480. for (int i = 0; i < length; i++) {
  481. if (TextUtils.equals(vid, DetailDataSource.playRelatedParts.get(i).getVideoid())) {
  482. return true;
  483. }
  484. }
  485. }
  486. }
  487. return false;
  488. }
  489. public static String isHasNextMusic(PluginOverlay mPluginOverlay) {
  490. String nextVideoId = null;
  491. if (Utils.isMusic() && !TextUtils.isEmpty(DetailDataSource.mDetailVideoInfo.getSinger())) {
  492. String vid = mPluginOverlay.mMediaPlayerDelegate.videoInfo.getVid();
  493. int length = DetailDataSource.allSeriesVideos.size();
  494. if (length > 0 && !TextUtils.isEmpty(vid)) {
  495. int index = -1;
  496. for (int i = 0; i < length; i++) {
  497. if (TextUtils.equals(vid, DetailDataSource.allSeriesVideos.get(i).getVideoid())) {
  498. index = i;
  499. break;
  500. }
  501. }
  502. if (index >= 0 && index + 1 <= length) {
  503. if (index + 1 == length) {
  504. if (Profile.ALWAYSHOOKUP == Youku.getPreferenceInt("music_play_mode", Profile.ALWAYSHOOKUP)) {
  505. nextVideoId = DetailDataSource.allSeriesVideos.get(0).getVideoid();
  506. }
  507. } else {
  508. nextVideoId = DetailDataSource.allSeriesVideos.get(index + 1).getVideoid();
  509. }
  510. }
  511. }
  512. }
  513. return nextVideoId;
  514. }
  515. public static String isHasNextShow(PluginOverlay mPluginOverlay) {
  516. String nextVideoId = null;
  517. if (Utils.isShow(mPluginOverlay)) {
  518. if (isInShowSeries(mPluginOverlay)) {
  519. nextVideoId = isHasNextShowSeries(mPluginOverlay);
  520. if (TextUtils.isEmpty(nextVideoId)) {
  521. nextVideoId = isHasFirstShowPart(mPluginOverlay);
  522. }
  523. } else if (isInShowPart(mPluginOverlay)) {
  524. nextVideoId = isHasNextShowPart(mPluginOverlay);
  525. }
  526. }
  527. return nextVideoId;
  528. }
  529. public static String isHasNextVideo(PluginOverlay mPluginOverlay) {
  530. String nextVideoId = null;
  531. if (Utils.isPlayExternalVideo(mPluginOverlay)) {
  532. nextVideoId = isHasNextExternalVideo(mPluginOverlay);
  533. } else if (Utils.isPlayLocalType(mPluginOverlay)) {
  534. nextVideoId = isHasNextLocalVideo(mPluginOverlay);
  535. } else {
  536. nextVideoId = isHasNextNetVideo(mPluginOverlay);
  537. }
  538. return nextVideoId;
  539. }
  540. public static String isHasNextNetVideo(PluginOverlay mPluginOverlay) {
  541. String nextVideoId = null;
  542. if (isVideoInfoDataValid(mPluginOverlay)) {
  543. if (Utils.isAlbum(mPluginOverlay)) {
  544. nextVideoId = isHasNextAlbum(mPluginOverlay);
  545. } else if (Utils.isShow(mPluginOverlay)) {
  546. nextVideoId = isHasNextShow(mPluginOverlay);
  547. } else if (Utils.isMusic() && !TextUtils.isEmpty(DetailDataSource.mDetailVideoInfo.getSinger())) {
  548. nextVideoId = isHasNextMusic(mPluginOverlay);
  549. } else {
  550. nextVideoId = isHasNextUGC(mPluginOverlay);
  551. }
  552. if (TextUtils.isEmpty(nextVideoId)) {
  553. nextVideoId = mPluginOverlay.mMediaPlayerDelegate.videoInfo.nextVideoId;
  554. }
  555. }
  556. return nextVideoId;
  557. }
  558. public static String isHasNextLocalVideo(PluginOverlay mPluginOverlay) {
  559. String nextVideoId = null;
  560. if (isVideoInfoDataValid(mPluginOverlay)) {
  561. if (YoukuUtil.hasInternet()) {
  562. DownloadInfo nextInfo = DownloadManager.getInstance().getDownloadInfo(mPluginOverlay.mMediaPlayerDelegate.videoInfo.getShowId(), mPluginOverlay.mMediaPlayerDelegate.videoInfo.getShow_videoseq() + 1);
  563. if (nextInfo != null) {
  564. nextVideoId = nextInfo.videoid;
  565. } else {
  566. DownloadInfo currentInfo = DownloadManager.getInstance().getDownloadInfo(mPluginOverlay.mMediaPlayerDelegate.videoInfo.getVid());
  567. if (currentInfo != null && currentInfo.show_videoseq < currentInfo.showepisode_total) {
  568. nextVideoId = currentInfo.videoid;
  569. } else {
  570. DownloadInfo info = DownloadManager.getInstance().getNextDownloadInfo(mPluginOverlay.mMediaPlayerDelegate.videoInfo.getVid());
  571. if (info != null) {
  572. nextVideoId = info.videoid;
  573. }
  574. }
  575. }
  576. } else {
  577. DownloadInfo info = DownloadManager.getInstance().getNextDownloadInfo(mPluginOverlay.mMediaPlayerDelegate.videoInfo.getVid());
  578. if (info != null) {
  579. nextVideoId = info.videoid;
  580. }
  581. }
  582. }
  583. return nextVideoId;
  584. }
  585. public static String isHasNextExternalVideo(PluginOverlay mPluginOverlay) {
  586. String nextVideoId = null;
  587. if (isVideoInfoDataValid(mPluginOverlay)) {
  588. Media nextMedia = FragmentLocalVideoList.getNextVideo(mPluginOverlay.mMediaPlayerDelegate.videoInfo.getVid());
  589. if (nextMedia != null) {
  590. nextVideoId = nextMedia.getLocation();
  591. }
  592. }
  593. return nextVideoId;
  594. }
  595. public static PlayRelatedVideo getPlayRelatedVideo(String id) {
  596. PlayRelatedVideo mPlayRelatedVideo = null;
  597. if (DetailDataSource.mPlayRelatedVideoDataInfo != null && !TextUtils.isEmpty(id)) {
  598. int length = DetailDataSource.mPlayRelatedVideoDataInfo.getPlayRelatedVideos().size();
  599. for (int i = 0; i < length; i++) {
  600. String videoid = DetailDataSource.mPlayRelatedVideoDataInfo.getPlayRelatedVideos().get(i).getVideoid();
  601. String showid = DetailDataSource.mPlayRelatedVideoDataInfo.getPlayRelatedVideos().get(i).getShowid();
  602. if (TextUtils.equals(id, videoid) || TextUtils.equals(id, showid)) {
  603. mPlayRelatedVideo = DetailDataSource.mPlayRelatedVideoDataInfo.getPlayRelatedVideos().get(i);
  604. break;
  605. }
  606. }
  607. }
  608. return mPlayRelatedVideo;
  609. }
  610. public static long lastClickTime = 0;
  611. public static long currentClickTime = 0;
  612. public static boolean checkClickEvent() {
  613. return checkClickEvent(1000);
  614. }
  615. public static boolean checkClickEvent(long interval) {
  616. currentClickTime = System.currentTimeMillis();
  617. if (currentClickTime - lastClickTime > interval) {
  618. lastClickTime = currentClickTime;
  619. return true;
  620. } else {
  621. lastClickTime = currentClickTime;
  622. return false;
  623. }
  624. }
  625. public static long lastPlayClickTime = 0;
  626. public static long currentPlayClickTime = 0;
  627. public static boolean checkPlayClickEvent() {
  628. return checkClickPlayEvent(1000);
  629. }
  630. public static boolean checkClickPlayEvent(long interval) {
  631. currentPlayClickTime = System.currentTimeMillis();
  632. if (currentPlayClickTime - lastPlayClickTime > interval) {
  633. lastPlayClickTime = currentPlayClickTime;
  634. return true;
  635. } else {
  636. lastPlayClickTime = currentPlayClickTime;
  637. return false;
  638. }
  639. }
  640. public static String getStringTwo(String strIn) {
  641. String strResult;
  642. if (strIn.length() >= 2) {
  643. strResult = strIn;
  644. } else {
  645. strResult = "0".concat(String.valueOf(String.valueOf(strIn)));
  646. }
  647. return strResult;
  648. }
  649. public static void changeBatteryState(int status, int value, ImageView mImageView) {
  650. if (mImageView != null) {
  651. boolean isCharging = false;
  652. switch (status) {
  653. case BatteryManager.BATTERY_STATUS_CHARGING:// 充电状态
  654. isCharging = true;
  655. break;
  656. case BatteryManager.BATTERY_STATUS_DISCHARGING:// 放电状态
  657. break;
  658. case BatteryManager.BATTERY_STATUS_NOT_CHARGING:// 未充电
  659. break;
  660. case BatteryManager.BATTERY_STATUS_FULL:// 充满电
  661. break;
  662. case BatteryManager.BATTERY_STATUS_UNKNOWN:// 未知状态
  663. break;
  664. default:
  665. break;
  666. }
  667. if (isCharging) {
  668. mImageView.setImageResource(R.drawable.battery_charge);
  669. } else {
  670. if (value >= 90) {
  671. mImageView.setImageResource(R.drawable.battery3);
  672. } else if (value >= 60) {
  673. mImageView.setImageResource(R.drawable.battery2);
  674. } else {
  675. mImageView.setImageResource(R.drawable.battery1);
  676. }
  677. }
  678. }
  679. }
  680. public static void changeTimeState(TextView mTextView) {
  681. if (mTextView != null) {
  682. Calendar mCalendar = Calendar.getInstance();
  683. mCalendar.setTimeInMillis(System.currentTimeMillis());
  684. int hour = mCalendar.get(Calendar.HOUR_OF_DAY);
  685. int minite = mCalendar.get(Calendar.MINUTE);
  686. mTextView.setText(getStringTwo(String.valueOf(hour)) + ":" + getStringTwo(String.valueOf(minite)));
  687. }
  688. }
  689. public static void showPlayNextDialog(final DetailActivity context, final DownloadInfo currentInfo, final MediaPlayerDelegate mMediaPlayerDelegate) {
  690. final YoukuDialog dialog = new YoukuDialog(context, TYPE.normal);
  691. context.tempYoukuDialog = dialog;
  692. dialog.setNormalPositiveBtn("在线续播", new OnClickListener() {
  693. @Override
  694. public void onClick(View v) {
  695. boolean isAllow3GPlay = PreferenceManager.getDefaultSharedPreferences(Youku.context).getBoolean("allowONline3G", true);
  696. dialog.dismiss();
  697. if (!isAllow3GPlay && YoukuUtil.hasInternet() && !YoukuUtil.isWifi()) {// 有网
  698. YoukuUtil.showTips(R.string.detail_3g_play_toast);
  699. context.finish();
  700. }
  701. YoukuService.getService(IHttpRequest.class, true).request(new HttpIntent(URLContainer.getNextSeries(currentInfo.showid, currentInfo.videoid)), new IHttpRequestCallBack() {
  702. @Override
  703. public void onSuccess(HttpRequestManager httpRequestManager) {
  704. String str = httpRequestManager.getDataString();
  705. try {
  706. final JSONObject jsonObject = JSONObject.parseObject(str);
  707. JSONObject result = jsonObject.getJSONObject("result");
  708. String nextVid = result.getString("next_videoid");
  709. if (TextUtils.isEmpty(nextVid)) {
  710. YoukuUtil.showTips("当前已是最新一集");
  711. mMediaPlayerDelegate.finishActivity();
  712. return;
  713. }
  714. mMediaPlayerDelegate.videoInfo.playType = StaticsUtil.PLAY_TYPE_NET;
  715. context.on3gStartPlay(nextVid);
  716. context.getDetailLayoutData();
  717. } catch (Exception e) {
  718. mMediaPlayerDelegate.finishActivity();
  719. Logger.e(Youku.TAG_GLOBAL, "FullScreenUtils#showPlayNextDialog()", e);
  720. }
  721. }
  722. @Override
  723. public void onFailed(String failReason) {
  724. context.finish();
  725. YoukuUtil.showTips(failReason);
  726. }
  727. });
  728. }
  729. });
  730. dialog.setNormalNegtiveTextColor(context.getResources().getColor(R.color.cancel_text_color));
  731. dialog.setNormalNegtiveBackGround(R.drawable.btn_vip_dialog_cancel);
  732. dialog.setNormalNegtiveBtn("立即下载", new OnClickListener() {
  733. @Override
  734. public void onClick(View v) {
  735. dialog.dismiss();
  736. YoukuService.getService(IHttpRequest.class, true).request(new HttpIntent(URLContainer.getNextSeries(currentInfo.showid, currentInfo.videoid)), new IHttpRequestCallBack() {
  737. @Override
  738. public void onSuccess(HttpRequestManager httpRequestManager) {
  739. String str = httpRequestManager.getDataString();
  740. try {
  741. final JSONObject jsonObject = JSONObject.parseObject(str);
  742. JSONObject result = jsonObject.getJSONObject("result");
  743. String nextVid = result.getString("next_videoid");
  744. String title = result.getString("next_title");
  745. if (TextUtils.isEmpty(nextVid)) {
  746. YoukuUtil.showTips("当前已是最新一集");
  747. mMediaPlayerDelegate.finishActivity();
  748. return;
  749. }
  750. DownloadManager download = DownloadManager.getInstance();
  751. download.createDownload(nextVid, title, new OnCreateDownloadListener() {
  752. @Override
  753. public void onfinish(boolean isNeedRefresh) {
  754. Intent godown = new Intent(context, CachePageActivity.class);
  755. context.startActivity(godown);
  756. context.finish();
  757. }
  758. @Override
  759. public void onOneFailed() {
  760. Intent godown = new Intent(context, CachePageActivity.class);
  761. context.startActivity(godown);
  762. context.finish();
  763. }
  764. });
  765. } catch (Exception e) {
  766. Logger.e(Youku.TAG_GLOBAL, "FullScreenUtils.showPlayNextDialog(...).new OnClickListener() {...}.onClick(...).new IHttpRequestCallBack() {...}#onSuccess()", e);
  767. }
  768. }
  769. @Override
  770. public void onFailed(String failReason) {
  771. context.finish();
  772. YoukuUtil.showTips(failReason);
  773. }
  774. });
  775. }
  776. });
  777. dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
  778. @Override
  779. public void onDismiss(DialogInterface dialog) {
  780. context.tempYoukuDialog = null;
  781. }
  782. });
  783. dialog.setMessage("是否续播下一集");
  784. dialog.setCanceledOnTouchOutside(true);
  785. dialog.setOnCancelListener(new OnCancelListener() {
  786. @Override
  787. public void onCancel(DialogInterface dialog) {
  788. mMediaPlayerDelegate.finishActivity();
  789. }
  790. });
  791. dialog.show();
  792. }
  793. public static boolean isVipUser() {
  794. boolean isVipUser = false;
  795. if (!TextUtils.isEmpty(Youku.COOKIE)) {
  796. try {
  797. // cookie里边的yktk 键的内容是由| 分隔的。用base64
  798. // 把第4个内容解析出来。解析出来后的内容格式是id:XXX,nn:XXX,vip:true,ytid:XXX,tid:XXX。vip
  799. // 字段内容true 代表vip .false代表不是。
  800. org.json.JSONObject objContent = BaseHelper.string2JSON(Youku.COOKIE, ";");
  801. String yktk = objContent.getString("yktk");
  802. String decode_yktk = URLDecoder(yktk);
  803. String[] decode_yktk_array = decode_yktk.split("\\|");
  804. String base64_temp = decode_yktk_array[3];
  805. String temp = new String(Base64.decode(base64_temp, Base64.DEFAULT), "utf-8");
  806. isVipUser = temp.contains("vip:true");
  807. } catch (Exception e) {
  808. e.printStackTrace();
  809. isVipUser = false;
  810. }
  811. }
  812. return isVipUser;
  813. }
  814. private static String URLDecoder(String s) {
  815. if (s == null || s.length() == 0)
  816. return "";
  817. try {
  818. s = java.net.URLDecoder.decode(s, "UTF-8");
  819. } catch (UnsupportedEncodingException e) {
  820. return "";
  821. } catch (NullPointerException e) {
  822. return "";
  823. }
  824. return s;
  825. }
  826. @SuppressLint("NewApi")
  827. public static int getRealScreenHeight(Activity activity) {
  828. int realScreenHeight = 0;
  829. int heightPixels = 0;
  830. final Point size = new Point();
  831. try {
  832. activity.getWindowManager().getDefaultDisplay().getRealSize(size);
  833. heightPixels = size.y;
  834. } catch (NoSuchMethodError e) {
  835. heightPixels = activity.getResources().getDisplayMetrics().heightPixels;
  836. }
  837. if (Youku.isTablet) {
  838. boolean hasVirtualButtonBar = false;
  839. if (android.os.Build.VERSION.SDK_INT >= 14) {
  840. hasVirtualButtonBar = !ViewConfiguration.get(activity).hasPermanentMenuKey();
  841. } else if (android.os.Build.VERSION.SDK_INT >= 11 && android.os.Build.VERSION.SDK_INT <= 13) {
  842. hasVirtualButtonBar = true;
  843. } else {
  844. hasVirtualButtonBar = false;
  845. }
  846. if (hasVirtualButtonBar) {
  847. realScreenHeight = heightPixels - getNavigationBarHeight(activity);
  848. } else {
  849. realScreenHeight = heightPixels;
  850. }
  851. } else {
  852. realScreenHeight = heightPixels;
  853. }
  854. return realScreenHeight;
  855. }
  856. public static int getNavigationBarHeight(Context mContext) {
  857. int navigationBarHeight = 0;
  858. if (mContext != null) {
  859. if (android.os.Build.VERSION.SDK_INT >= 11 && android.os.Build.VERSION.SDK_INT <= 13) {
  860. Resources resources = mContext.getResources();
  861. navigationBarHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48, resources.getDisplayMetrics());
  862. } else {
  863. if ("MI PAD".equalsIgnoreCase(android.os.Build.MODEL)) {
  864. navigationBarHeight = 0;
  865. } else {
  866. Resources resources = mContext.getResources();
  867. int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
  868. if (resourceId > 0) {
  869. navigationBarHeight = resources.getDimensionPixelSize(resourceId);
  870. }
  871. }
  872. }
  873. }
  874. return navigationBarHeight;
  875. }*/
  876. }