PageRenderTime 69ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/ShareText/youkuLoginSDK/src/main/java/com/youku/login/activity/CaptureResultAcitvity.java

https://gitlab.com/ShaneNilsson/JarToUnity
Java | 528 lines | 404 code | 73 blank | 51 comment | 42 complexity | 3c8ed5417f55b12c23237cbf12b663c8 MD5 | raw file
  1. package com.youku.login.activity;
  2. import android.app.Activity;
  3. import android.content.Intent;
  4. import android.content.pm.ActivityInfo;
  5. import android.os.Bundle;
  6. import android.text.TextUtils;
  7. import android.util.DisplayMetrics;
  8. import android.view.Gravity;
  9. import android.view.Menu;
  10. import android.view.MenuItem;
  11. import android.view.View;
  12. import android.view.View.OnClickListener;
  13. import android.widget.Button;
  14. import android.widget.FrameLayout;
  15. import android.widget.ImageView;
  16. import android.widget.LinearLayout;
  17. import android.widget.TextView;
  18. import com.alibaba.fastjson.JSON;
  19. import com.example.youkuloginsdk.R;
  20. import com.youku.login.base.YoukuLoginBaseActivity;
  21. import com.youku.login.data.Saosao;
  22. import com.youku.login.data.SaosaoResult;
  23. import com.youku.login.network.HttpIntent;
  24. import com.youku.login.network.HttpRequestManager;
  25. import com.youku.login.network.IHttpRequest;
  26. import com.youku.login.network.IHttpRequest.IHttpRequestCallBack;
  27. import com.youku.login.network.URLContainer;
  28. import com.youku.login.service.YoukuService;
  29. import com.youku.login.statics.StaticsConfigFile;
  30. import com.youku.login.util.DetailUtil;
  31. import com.youku.login.util.Logger;
  32. import com.youku.login.util.Youku;
  33. import com.youku.login.util.YoukuUtil;
  34. import com.youku.login.widget.YoukuLoading;
  35. public class CaptureResultAcitvity extends YoukuLoginBaseActivity implements OnClickListener {
  36. private Button mResaosao;// 重新扫描按钮
  37. private View mNoResult;// 无结果页面
  38. private View mHasResult;// 有结果页面
  39. private View mNORight;// 无版权
  40. private TextView title;
  41. private TextView seeToo;
  42. private ImageView img;
  43. private Button play;
  44. private ImageView img_play;
  45. private Saosao saoJson;
  46. private int margin16 = 16;
  47. private int margin20 = 20;
  48. private int margin32 = 32;
  49. private int margin24 = 24;
  50. private int margin26 = 26;
  51. private int margin28 = 28;
  52. private int margin30 = 30;
  53. private int margin34 = 34;
  54. private int margin60 = 60;
  55. private int margin80 = 80;
  56. private int margin84 = 84;
  57. private int margin120 = 120;
  58. private int margin100 = 100;
  59. private int margin176 = 176;
  60. private int img_width = 716;
  61. private int img_hight = 400;
  62. private int btn_width;
  63. private int btn_hight;
  64. private int tishi_img_hight = 378;
  65. private int tishi_img_width = 524;
  66. private int img_play_width = 112;
  67. private int img_play_hight = 108;
  68. public final static int REQUESTCODE_CAPTURE_LOGIN = 1000;
  69. private final int REQUEST_TV_SCAN_CODE_LENGTH = 32;//扫描TV二维码之后获得的32位的结果
  70. @Override
  71. protected void onCreate(Bundle savedInstanceState) {
  72. // TODO Auto-generated method stub
  73. super.onCreate(savedInstanceState);
  74. setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  75. String url = getBundleValue(getIntent().getExtras(), "url", "", false);
  76. if (!TextUtils.isEmpty(url)&&REQUEST_TV_SCAN_CODE_LENGTH==url.length()&&!url.contains("http")) {
  77. setContentView(R.layout.activity_captureresult_tvlogin);
  78. View cancel = findViewById(R.id.layout_soku_dialog_cancel);
  79. cancel.setOnClickListener(new OnClickListener() {
  80. @Override
  81. public void onClick(View v) {
  82. finish();
  83. }
  84. });
  85. View confrim = findViewById(R.id.layout_soku_dialog_goplay);
  86. confrim.setOnClickListener(new OnClickListener() {
  87. @Override
  88. public void onClick(View v) {
  89. toPullLogin();
  90. }
  91. });
  92. } else {
  93. setContentView(R.layout.activity_captureresult);
  94. initParm();
  95. initView();
  96. mResaosao.setOnClickListener(this);
  97. img_play.setOnClickListener(this);
  98. play.setOnClickListener(this);
  99. getVideo();
  100. }
  101. }
  102. @Override
  103. protected void onStart() {
  104. super.onStart();
  105. }
  106. @Override
  107. protected void onResume() {
  108. super.onResume();
  109. }
  110. @Override
  111. public boolean onOptionsItemSelected(MenuItem item) {
  112. // TODO Auto-generated method stub
  113. if (item.getItemId() == R.id.menu_saosao) {
  114. CaptureResultAcitvity.this.finish();
  115. return true;
  116. }
  117. return super.onOptionsItemSelected(item);
  118. }
  119. private void initView() {
  120. setWhiteANDTextPrarms();
  121. mNORight = findViewById(R.id.no_right);
  122. mNORight.setPadding(16, margin32, 16, 16);
  123. mResaosao = (Button) findViewById(R.id.re_saosao);// 重新扫描
  124. mNoResult = findViewById(R.id.no_result);
  125. mHasResult = findViewById(R.id.has_result);
  126. title = (TextView) findViewById(R.id.title);
  127. seeToo = (TextView) findViewById(R.id.seeToo);
  128. img = (ImageView) findViewById(R.id.img);
  129. play = (Button) findViewById(R.id.play);
  130. img_play = (ImageView) findViewById(R.id.img_play);
  131. setTitleParams();
  132. setSeeTooParams();
  133. setBtnPlayParams();
  134. setBtnReSaoParams();
  135. setImgParams();
  136. setImg_playParams();
  137. }
  138. private void setBtnReSaoParams() {
  139. LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(btn_width, btn_hight);
  140. params.gravity = Gravity.CENTER_HORIZONTAL;
  141. params.topMargin = margin60;
  142. mResaosao.setLayoutParams(params);
  143. }
  144. private void setBtnPlayParams() {
  145. LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(btn_width, btn_hight);
  146. params.gravity = Gravity.CENTER_HORIZONTAL;
  147. play.setLayoutParams(params);
  148. }
  149. private void setWhiteANDTextPrarms() {
  150. // 适配
  151. LinearLayout has_result_white = (LinearLayout) findViewById(R.id.has_result_white);
  152. has_result_white.setPadding(16, margin32, 16, margin34);
  153. LinearLayout no_result_white = (LinearLayout) findViewById(R.id.no_result_white);
  154. no_result_white.setPadding(16, margin80, 16, margin80);
  155. ImageView no_result_img_tishi = (ImageView) findViewById(R.id.no_result_img_tishi);
  156. LinearLayout.LayoutParams no_result_img_tishi_params = new LinearLayout.LayoutParams(tishi_img_width, tishi_img_hight);
  157. no_result_img_tishi_params.leftMargin = margin100;
  158. no_result_img_tishi_params.rightMargin = margin176;
  159. no_result_img_tishi_params.topMargin = margin84;
  160. no_result_img_tishi.setLayoutParams(no_result_img_tishi_params);
  161. }
  162. private void setSeeTooParams() {
  163. seeToo.setPadding(0, margin20, 0, margin30);
  164. }
  165. private void setTitleParams() {
  166. title.setPadding(0, 0, 0, margin20);
  167. }
  168. private void setImgParams() {
  169. FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(img_width, img_hight);
  170. // Log.e("ImgParams", "img_width:" + img_width + ",img_hight:" +
  171. // img_hight);
  172. img.setLayoutParams(params);
  173. }
  174. private void setImg_playParams() {
  175. FrameLayout.LayoutParams img_play_params = new FrameLayout.LayoutParams(img_play_width, img_play_hight);
  176. img_play_params.gravity = Gravity.BOTTOM;
  177. img_play_params.bottomMargin = margin28;
  178. img_play_params.leftMargin = margin28;
  179. img_play.setLayoutParams(img_play_params);
  180. }
  181. private void initParm() {
  182. // TODO 适配参数
  183. DisplayMetrics dm = new DisplayMetrics();
  184. dm = this.getResources().getDisplayMetrics();
  185. if (dm.widthPixels > dm.heightPixels) {
  186. dm.widthPixels = dm.heightPixels;
  187. }
  188. img_width = dm.widthPixels - 16 * 2 - 16 * 2;
  189. img_hight = img_width * 400 / 716;
  190. if ((img_width - 112) >= 560) {
  191. btn_width = 560;
  192. btn_hight = 88;
  193. } else {
  194. btn_width = img_width - 112;
  195. btn_hight = 88 * btn_width / 560;
  196. }
  197. btn_width = 560 * img_hight / 400;
  198. btn_hight = 88 * img_hight / 400;
  199. img_play_width = img_play_width * img_hight / 400;
  200. img_play_hight = img_play_hight * img_hight / 400;
  201. tishi_img_hight = tishi_img_hight * img_hight / 400;
  202. tishi_img_width = tishi_img_width * img_hight / 400;
  203. margin20 = 20 * img_hight / 400;
  204. margin24 = 24 * img_hight / 400;
  205. margin26 = 26 * img_hight / 400;
  206. margin28 = 28 * img_hight / 400;
  207. margin30 = 30 * img_hight / 400;
  208. margin32 = 32 * img_hight / 400;
  209. margin34 = 34 * img_hight / 400;
  210. margin60 = 60 * img_hight / 400;
  211. margin84 = 84 * img_hight / 400;
  212. margin80 = 80 * img_hight / 400;
  213. margin120 = 120 * img_hight / 400;
  214. margin100 = 68 * img_hight / 400 + 32;
  215. margin176 = 144 * img_hight / 400 + 32;
  216. }
  217. void showNoResult(boolean IsShowNoResult) {
  218. if (IsShowNoResult) {
  219. mNoResult.setVisibility(View.VISIBLE);
  220. mHasResult.setVisibility(View.GONE);
  221. } else {
  222. mNoResult.setVisibility(View.GONE);
  223. mHasResult.setVisibility(View.VISIBLE);
  224. }
  225. }
  226. @Override
  227. protected void onDestroy() {
  228. // TODO Auto-generated method stub
  229. YoukuLoading.dismiss();
  230. super.onDestroy();
  231. }
  232. private void toPullLogin() {
  233. if (!YoukuUtil.hasInternet()) {
  234. YoukuUtil.showTips("没有网络,无法发送信息,请检查网络连接。");
  235. return;
  236. }
  237. YoukuLoading.show(this);
  238. IHttpRequest httpRequest = YoukuService.getService(IHttpRequest.class, true);
  239. String posturl = getBundleValue(getIntent().getExtras(), "url", "", false);
  240. String url = URLContainer.getSaosaoTvLoginUrl(posturl, Youku.getPreference("loginAccount"), Youku.getPreference("loginPassword"));
  241. HttpIntent httpIntent = new HttpIntent(url);
  242. httpRequest.request(httpIntent, new IHttpRequestCallBack() {
  243. @Override
  244. public void onSuccess(HttpRequestManager httpRequestManager) {
  245. YoukuLoading.dismiss();
  246. setResult(RESULT_OK);
  247. finish();
  248. }
  249. @Override
  250. public void onFailed(String failReason) {
  251. YoukuLoading.dismiss();
  252. YoukuUtil.showTips(failReason);
  253. setResult(RESULT_OK);
  254. finish();
  255. }
  256. });
  257. }
  258. private void getVideo() {
  259. mNoResult.setVisibility(View.GONE);
  260. mHasResult.setVisibility(View.GONE);
  261. if (!YoukuUtil.hasInternet()) {
  262. // Util.showTips(R.string.download_no_network);
  263. TextView no_result_white_tt = (TextView) findViewById(R.id.no_result_white_tt);
  264. no_result_white_tt.setText("没有网络,无法查询视频信息,请检查网络连接。");
  265. // ImageView no_result_img_tishi=(ImageView)
  266. // findViewById(R.id.no_result_img_tishi);
  267. // no_result_img_tishi.setVisibility(View.GONE) ;
  268. // TextView no_result_tt_tishi=(TextView)
  269. // findViewById(R.id.no_result_tt_tishi);
  270. // no_result_tt_tishi.setVisibility(View.GONE) ;
  271. showNoResult(true);
  272. return;
  273. }
  274. YoukuLoading.show(this);
  275. String posturl = getBundleValue(getIntent().getExtras(), "url", "", false);
  276. posturl = URLEncode(posturl);
  277. // Logger.d("二维码", "result:" + posturl);
  278. IHttpRequest httpRequest = YoukuService.getService(IHttpRequest.class, true);
  279. String url = URLContainer.getSaosaoUrl(posturl);
  280. // Logger.d("二维码", "url:" + url);
  281. HttpIntent httpIntent = new HttpIntent(url);
  282. httpRequest.request(httpIntent, new IHttpRequestCallBack() {
  283. @Override
  284. public void onSuccess(HttpRequestManager httpRequestManager) {
  285. String str = httpRequestManager.getDataString();
  286. // Logger.e("二维码", "请求成功 str:" + str);
  287. YoukuLoading.dismiss();
  288. try {
  289. saoJson = JSON.parseObject(str, Saosao.class);
  290. // Logger.e("二维码", "请求成功 status:" + saoJson.status);
  291. if (null != saoJson && TextUtils.equals("success", saoJson.status)) {
  292. // if (saoJson.result.paid == 1) {
  293. // showPaidView();
  294. // return;
  295. // }
  296. title.setText(saoJson.result.title);
  297. seeToo.setText("观看到:" + YoukuUtil.formatTime(saoJson.result.firsttime));
  298. if (saoJson.result.limit >= 4) {
  299. mNORight.setVisibility(View.VISIBLE);
  300. } else {
  301. mNORight.setVisibility(View.GONE);
  302. }
  303. getImageLoader().displayImage(saoJson.result.img, img);
  304. showNoResult(false);
  305. } else {
  306. showNoResult(true);
  307. }
  308. } catch (Exception e) {
  309. Logger.e("二维码", "请求成功 parseObject error");
  310. showNoResult(true);
  311. }
  312. }
  313. @Override
  314. public void onFailed(String failReason) {
  315. // Util.showTips(failReason);
  316. // Logger.e("二维码", "请求失败 原因:" + failReason);
  317. YoukuLoading.dismiss();
  318. showNoResult(true);
  319. }
  320. });
  321. }
  322. private void showPaidView() {
  323. TextView no_result_white_tt = (TextView) findViewById(R.id.no_result_white_tt);
  324. no_result_white_tt.setText("非常抱歉,我们暂时不能支持付费视频的播放。");
  325. // TextView no_result_white_tt2=(TextView)
  326. // findViewById(R.id.no_result_white_tt2);
  327. // no_result_white_tt2.setVisibility(View.GONE);
  328. ImageView no_result_img_tishi = (ImageView) findViewById(R.id.no_result_img_tishi);
  329. no_result_img_tishi.setVisibility(View.GONE);
  330. findViewById(R.id.no_result_tt_tishi).setVisibility(View.GONE);
  331. findViewById(R.id.no_result_tt_tishi2).setVisibility(View.GONE);
  332. findViewById(R.id.no_result_tt_tishi3).setVisibility(View.GONE);
  333. showNoResult(true);
  334. }
  335. public static String URLEncode(String text) {
  336. StringBuffer StrUrl = new StringBuffer();
  337. for (int i = 0; i < text.length(); ++i) {
  338. switch (text.charAt(i)) {
  339. case '/':
  340. StrUrl.append("%2F");
  341. break;
  342. case ':':
  343. StrUrl.append("%3A");
  344. break;
  345. case '?':
  346. StrUrl.append("%3F");
  347. break;
  348. case '=':
  349. StrUrl.append("%3D");
  350. break;
  351. case '&':
  352. StrUrl.append("%26");
  353. break;
  354. default:
  355. StrUrl.append(text.charAt(i));
  356. break;
  357. }
  358. }
  359. return StrUrl.toString();
  360. }
  361. /*
  362. * (non-Javadoc)
  363. *
  364. * @see
  365. * com.actionbarsherlock.app.SherlockFragmentActivity#onCreateOptionsMenu
  366. * (com.actionbarsherlock.view.Menu)
  367. */
  368. @Override
  369. public boolean onCreateOptionsMenu(Menu menu) {
  370. super.onCreateOptionsMenu(menu);
  371. // menuUtil=new MenuService(this);
  372. // menuUtil.creatMenu(menu);
  373. // getSupportActionBar().setDisplayUseLogoEnabled(false);
  374. // getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  375. return true;
  376. }
  377. @Override
  378. public String getPageName() {
  379. return "二维码搜索结果页";
  380. }
  381. @Override
  382. public void onClick(View v) {
  383. int id = v.getId();
  384. if(id == R.id.re_saosao){
  385. onMenuSaoSaoClick();
  386. }else if(id == R.id.img_play){
  387. goPlayer();
  388. }else if(id == R.id.play){
  389. goPlayer();
  390. }
  391. /*switch (v.getId()) {
  392. case R.id.re_saosao:
  393. onMenuSaoSaoClick();
  394. break;
  395. case R.id.img_play:
  396. goPlayer();
  397. break;
  398. case R.id.play:
  399. goPlayer();
  400. break;
  401. default:
  402. break;
  403. }*/
  404. }
  405. @Override
  406. public void onMenuSaoSaoClick() {
  407. CaptureResultAcitvity.this.finish();
  408. }
  409. void goPlayer() {
  410. if (null == saoJson) {
  411. return;
  412. }
  413. if (!YoukuUtil.hasInternet()) {
  414. YoukuUtil.showTips(R.string.tips_no_network);
  415. return;
  416. }
  417. if (saoJson.result.paid == SaosaoResult.PAY_YES && !Youku.isLogined) {
  418. Intent intent = new Intent(this, LoginRegistCardViewDialogActivity.class);
  419. intent.putExtra(LoginRegistCardViewDialogActivity.KEY_FROM, LoginRegistCardViewDialogActivity.INTENT_CAPTURERESULT_ACTIVITY);
  420. startActivityForResult(intent, REQUESTCODE_CAPTURE_LOGIN);
  421. return;
  422. }
  423. Youku.iStaticsManager.TrackCommonClickEvent(StaticsConfigFile.SCAN_AND_SCAN_VIDEO_PLAY_CLICK, StaticsConfigFile.SCAN_AND_SCAN_PAGE,
  424. Youku.iStaticsManager.getHashMapStyleValue("vid", saoJson.result.videoid), StaticsConfigFile.SCAN_AND_SCAN_VIDEO_PLAY_ENCODE_VALUE);
  425. goPlayer(saoJson.result.videoid, saoJson.result.title, (int) saoJson.result.firsttime, saoJson.result.paid == SaosaoResult.PAY_YES);
  426. }
  427. @Override
  428. public void onActivityResult(int requestCode, int resultCode, Intent data) {
  429. if (resultCode == Activity.RESULT_OK) {
  430. if (requestCode == REQUESTCODE_CAPTURE_LOGIN) {
  431. goPlayer();
  432. }
  433. }
  434. super.onActivityResult(requestCode, resultCode, data);
  435. }
  436. void goPlayer(String id, String title, int point, boolean isPay) {
  437. DetailUtil.goPlayerWithpoint(this, id, title, point * 1000, isPay);
  438. }
  439. public String getBundleValue(Bundle bundle, String label, String Default, boolean throwException) {
  440. String value = null;
  441. try {
  442. value = bundle.getString(label);
  443. } catch (Exception e) {
  444. if (throwException) {
  445. Logger.e(Youku.TAG_GLOBAL, "F.getBundleValue()", e);
  446. } else {
  447. Logger.e(Youku.TAG_GLOBAL, "throw Exception: get String Bundle label " + label + " is null");
  448. }
  449. }
  450. if (value == null || value.length() == 0) {
  451. return Default;
  452. }
  453. return value;
  454. }
  455. }