Skip to content

Commit

Permalink
Merge pull request #94 from Bai-Jie/mergeMasterToRelease
Browse files Browse the repository at this point in the history
Merge master to release
  • Loading branch information
Zhou-Peican committed Dec 6, 2015
2 parents 624a46c + 01afd4e commit 2a0a012
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 105 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [1.1.2] - 2015-12-06
### Fixed
- 修复无法播放视频的问题

## [1.1.1] - 2015-12-05
### Changed
- 微调界面
Expand Down Expand Up @@ -35,7 +39,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- 显示播放记录
- 搜索视频

[Unreleased]: https://github.com/OptimalOrange/CoolTechnologies/compare/v1.1.1...HEAD
[Unreleased]: https://github.com/OptimalOrange/CoolTechnologies/compare/v1.1.2...HEAD
[1.1.2]: https://github.com/OptimalOrange/CoolTechnologies/compare/v1.1.1...v1.1.2
[1.1.1]: https://github.com/OptimalOrange/CoolTechnologies/compare/v1.1.0...v1.1.1
[1.1.0]: https://github.com/OptimalOrange/CoolTechnologies/compare/v1.0.0...v1.1.0
[1.0.0]: https://github.com/OptimalOrange/CoolTechnologies/compare/8fada1475dc7a2ff179e3809650233fc2820c0fc...v1.0.0
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
maven { url "https://jitpack.io" }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha1'
classpath 'com.android.tools.build:gradle:2.0.0-alpha2'
classpath 'com.github.JakeWharton:sdk-manager-plugin:220bf7a88a'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</activity>

<activity
android:name=".ui.SimpleWebViewActivity"
android:name=".ui.PlayYoukuVideoActivity"
android:theme="@style/FullscreenTheme"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="sensorLandscape"/>
Expand Down
36 changes: 36 additions & 0 deletions app/src/main/assets/playvideo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<!-- used by PlayYoukuVideoActivity -->
<html lang="zh">

<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, height=device-height, user-scalable=no"/>
<title>播放视频</title>
<style>
* {
padding: 0;
margin: 0;
}
html, body, #youkuplayer {
width: 100%;
height: 100%;
}
</style>
</head>

<body>
<div id="youkuplayer"></div>
<script type="text/javascript" src="http://player.youku.com/jsapi"></script>
<script type="text/javascript">
player = new YKU.Player('youkuplayer', {
styleid: webAppInterface.getStyleId(),
client_id: webAppInterface.getClientId(),
vid: webAppInterface.getVid(),
autoplay: webAppInterface.isAutoplay(),
show_related: webAppInterface.isShowRelated()
});
</script>

</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
package com.optimalorange.cooltechnologies.ui;

import com.optimalorange.cooltechnologies.R;
import com.umeng.analytics.MobclickAgent;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class PlayYoukuVideoActivity extends Activity {

/**
* 应当显示的页面的url<br/>
* Type: {@link String}
*/
public static final String EXTRA_KEY_VIDEO_ID =
PlayYoukuVideoActivity.class.getName() + ".extra.KEY_VIDEO_ID";

/** 用于重置{@link WebView}的空网页 */
private static final String URL_BLANK = "about:blank";

/** {@link #URL_PLAY_VIDEO}中用到的{@link WebAppInterface WebAppInterface}实例名 */
private static final String JAVASCRIPT_INTERFACE_GENERIC = "webAppInterface";

/** 正常情况下,{@link android.webkit.WebView WebView}要加载的网页的路径 */
private static final String URL_PLAY_VIDEO = "file:///android_asset/playvideo.html";

private WebView mWebView;

public static Intent buildIntent(Context context, String videoId) {
final Intent result = new Intent(context, PlayYoukuVideoActivity.class);
result.putExtra(EXTRA_KEY_VIDEO_ID, videoId);
return result;
}

public static void start(Context context, String link) {
context.startActivity(buildIntent(context, link));
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play_youku_video);

final String videoId = getIntent().getStringExtra(EXTRA_KEY_VIDEO_ID);
if (videoId == null) {
throw new IllegalStateException("Please set url link with EXTRA_KEY_VIDEO_ID");
}

mWebView = (WebView) findViewById(R.id.web_view);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient());
// addJavascriptInterface
WebAppInterface webAppInterface = new WebAppInterface()
.setClientId(getString(R.string.youku_client_id))
.setVid(videoId);
//TODO 分析解决安全问题
mWebView.addJavascriptInterface(webAppInterface, JAVASCRIPT_INTERFACE_GENERIC);
}

@Override
protected void onStart() {
super.onStart();
mWebView.loadUrl(URL_PLAY_VIDEO);
}

@Override
protected void onResume() {
super.onResume();
// call it because this didn't extend BaseActivity
MobclickAgent.onResume(this);
MobclickAgent.onPageStart(getClass().getSimpleName());

mWebView.onResume();
}

@Override
protected void onPause() {
mWebView.onPause();

MobclickAgent.onPageEnd(getClass().getSimpleName());
MobclickAgent.onPause(this);
super.onPause();
}

@Override
protected void onStop() {
mWebView.loadUrl(URL_BLANK);
super.onStop();
}

@Override
protected void onDestroy() {
final ViewParent parent = mWebView.getParent();
if (parent != null) {
((ViewGroup) parent).removeView(mWebView);
mWebView.destroy();
}
mWebView = null;
super.onDestroy();
}

//-------------------------------------
// JavascriptInterface
//-------------------------------------

/**
* {@link android.webkit.WebView WebView}中网页可以访问的本地API,用于设置参数,如
* {@link WebAppInterface#getVid() vid}<br/>
* 本类是线程安全的
*/
private static class WebAppInterface {

/** 控制条底色:明;主色板颜色:橘色 */
private static final String DEFAULT_STYLE_ID = "8";

// important! must be **volatile**
private volatile String mTitle = "";

private volatile String mStyleId = DEFAULT_STYLE_ID;

private volatile String mClientId;

/** Video ID */
private volatile String mVid;

private volatile boolean mAutoplay = false;

private volatile boolean mShowRelated = false;

public WebAppInterface setTitle(String title) {
mTitle = title;
return this;
}

public WebAppInterface setStyleId(String styleId) {
mStyleId = styleId;
return this;
}

public WebAppInterface setClientId(String clientId) {
mClientId = clientId;
return this;
}

public WebAppInterface setVid(String vid) {
mVid = vid;
return this;
}

public WebAppInterface setAutoplay(boolean autoplay) {
mAutoplay = autoplay;
return this;
}

public WebAppInterface setShowRelated(boolean showRelated) {
mShowRelated = showRelated;
return this;
}

@JavascriptInterface
public String getTitle() {
return mTitle;
}

@JavascriptInterface
public String getStyleId() {
return mStyleId;
}

@JavascriptInterface
public String getClientId() {
return mClientId;
}

@JavascriptInterface
public String getVid() {
return mVid;
}

@JavascriptInterface
public boolean isAutoplay() {
return mAutoplay;
}

@JavascriptInterface
public boolean isShowRelated() {
return mShowRelated;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ public void playVideo() {
case NO_ERROR:
// 保存播放历史
DBManager.getInstance(this).saveHistory(mVideo);
// 跳转到 SimpleWebViewActivity
SimpleWebViewActivity.start(this, mVideo.link);
// 跳转到 PlayYoukuVideoActivity
PlayYoukuVideoActivity.start(this, mVideo.id);
break;
case NO_WIFI_NETWORK:
new NoWifiNetworkDialogFragment()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.optimalorange.cooltechnologies.ui.SimpleWebViewActivity"
tools:context=".ui.PlayYoukuVideoActivity"
/>
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
PROJECTS_GROUP=com.optimalorange.cooltechnologies
VERSION_NAME=1.1.1
VERSION_NAME=1.1.2

0 comments on commit 2a0a012

Please sign in to comment.