-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5048ba4
commit a6677dc
Showing
8 changed files
with
325 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Tue Sep 05 12:03:48 CST 2017 | ||
#Fri Sep 15 10:45:07 CST 2017 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletions
166
sample/src/main/java/com/sample/ui/activity/WebVideoActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
package com.sample.ui.activity; | ||
|
||
import android.content.pm.ActivityInfo; | ||
import android.content.res.Configuration; | ||
import android.os.Message; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.view.Window; | ||
import android.view.WindowManager; | ||
import android.webkit.WebChromeClient; | ||
import android.webkit.WebSettings; | ||
import android.webkit.WebView; | ||
import android.webkit.WebViewClient; | ||
import android.widget.FrameLayout; | ||
|
||
import com.sample.R; | ||
|
||
public class WebVideoActivity extends BaseActivity { | ||
private FrameLayout mFrameLayout; | ||
private WebView mWebView; | ||
private InsideWebChromeClient mInsideWebChromeClient; | ||
//private JavascriptInterface javascriptInterface; | ||
private String URL = "http://www.chinichi.cn/news/index/app_detail.html?id=2362"; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
// 1 | ||
requestWindowFeature(Window.FEATURE_NO_TITLE); | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_web_video); | ||
// 2 | ||
mFrameLayout = (FrameLayout) findViewById(R.id.mFrameLayout); | ||
mWebView = (WebView) findViewById(R.id.mWebView); | ||
// 3 | ||
initWebView(); | ||
mWebView.loadUrl(URL); | ||
} | ||
|
||
private void initWebView() { | ||
WebSettings settings = mWebView.getSettings(); | ||
settings.setJavaScriptEnabled(true); | ||
settings.setJavaScriptCanOpenWindowsAutomatically(true); | ||
settings.setPluginState(WebSettings.PluginState.ON); | ||
//settings.setPluginsEnabled(true); | ||
settings.setAllowFileAccess(true); | ||
settings.setLoadWithOverviewMode(true); | ||
settings.setUseWideViewPort(true); | ||
settings.setAppCacheEnabled(false); | ||
// settings.setCacheMode(WebSettings.LOAD_NO_CACHE); | ||
// settings.setCacheMode(WebSettings.LOAD_DEFAULT); | ||
mInsideWebChromeClient = new InsideWebChromeClient(); | ||
InsideWebViewClient mInsideWebViewClient = new InsideWebViewClient(); | ||
//javascriptInterface = new JavascriptInterface(); | ||
//mWebView.addJavascriptInterface(javascriptInterface, "java2js_laole918"); | ||
mWebView.setWebChromeClient(mInsideWebChromeClient); | ||
mWebView.setWebViewClient(mInsideWebViewClient); | ||
} | ||
|
||
private class InsideWebChromeClient extends WebChromeClient { | ||
private View mCustomView; | ||
private CustomViewCallback mCustomViewCallback; | ||
|
||
@Override | ||
public void onShowCustomView(View view, CustomViewCallback callback) { | ||
super.onShowCustomView(view, callback); | ||
if (mCustomView != null) { | ||
callback.onCustomViewHidden(); | ||
return; | ||
} | ||
mCustomView = view; | ||
mFrameLayout.addView(mCustomView); | ||
mCustomViewCallback = callback; | ||
mWebView.setVisibility(View.GONE); | ||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); | ||
} | ||
|
||
public void onHideCustomView() { | ||
mWebView.setVisibility(View.VISIBLE); | ||
if (mCustomView == null) { | ||
return; | ||
} | ||
mCustomView.setVisibility(View.GONE); | ||
mFrameLayout.removeView(mCustomView); | ||
mCustomViewCallback.onCustomViewHidden(); | ||
mCustomView = null; | ||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); | ||
super.onHideCustomView(); | ||
} | ||
|
||
@Override | ||
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) { | ||
mWebView = new WebView(view.getContext()); | ||
view.addView(mWebView); | ||
WebSettings settings = mWebView.getSettings(); | ||
settings.setJavaScriptEnabled(true); | ||
mWebView.setWebViewClient(new WebViewClient()); | ||
mWebView.setWebChromeClient(this); | ||
|
||
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj; | ||
transport.setWebView(mWebView); | ||
resultMsg.sendToTarget(); | ||
return true; | ||
} | ||
} | ||
|
||
private class InsideWebViewClient extends WebViewClient { | ||
|
||
@Override | ||
public boolean shouldOverrideUrlLoading(WebView view, String url) { | ||
// TODO Auto-generated method stub | ||
view.loadUrl(url); | ||
return true; | ||
} | ||
|
||
@Override | ||
public void onPageFinished(WebView view, String url) { | ||
super.onPageFinished(view, url); | ||
//mWebView.loadUrl(javascript); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void onConfigurationChanged(Configuration config) { | ||
super.onConfigurationChanged(config); | ||
switch (config.orientation) { | ||
case Configuration.ORIENTATION_LANDSCAPE: | ||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); | ||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); | ||
break; | ||
case Configuration.ORIENTATION_PORTRAIT: | ||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); | ||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); | ||
break; | ||
} | ||
} | ||
|
||
@Override | ||
public void onPause() { | ||
super.onPause(); | ||
mWebView.onPause(); | ||
} | ||
|
||
@Override | ||
public void onResume() { | ||
super.onResume(); | ||
mWebView.onResume(); | ||
} | ||
|
||
@Override | ||
public void onBackPressed() { | ||
if (mWebView.canGoBack()) { | ||
mWebView.goBack(); | ||
return; | ||
} | ||
super.onBackPressed(); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
mWebView.destroy(); | ||
super.onDestroy(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/mFrameLayout" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<WebView | ||
android:id="@+id/mWebView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
|
||
</FrameLayout> |
Oops, something went wrong.