Skip to content

Commit

Permalink
1.添加腾讯视频与优酷视频vip播放
Browse files Browse the repository at this point in the history
2.记住最后一次选择的解析源
3.支持手动输入视频网站
  • Loading branch information
liyiwei committed Aug 29, 2018
1 parent a48bc66 commit 93bab4b
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 36 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ android {
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0.6"
versionName "1.0.7"
}
buildTypes {
release {
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<application
android:name=".App"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
Expand All @@ -18,10 +19,11 @@
<activity
android:name=".activities.PlayActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="sensor"></activity>
android:screenOrientation="sensor" />
<activity
android:name=".activities.HomeActivity"
android:theme="@style/AppTheme.NoActionBar">
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/group/tonight/vipvideohelper/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.util.concurrent.TimeUnit;

import group.tonight.vipvideohelper.other.PrefUtils;
import okhttp3.OkHttpClient;

public class App extends Application {
Expand All @@ -12,6 +13,7 @@ public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
PrefUtils.init(this);
okHttpClient = new OkHttpClient.Builder()
.connectTimeout(2000, TimeUnit.MILLISECONDS)
.readTimeout(2000, TimeUnit.MILLISECONDS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.TextInputEditText;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.view.inputmethod.EditorInfo;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
Expand All @@ -30,18 +33,19 @@
import java.util.ArrayList;
import java.util.List;

import group.tonight.vipvideohelper.other.Consts;
import group.tonight.vipvideohelper.DownLoadService;
import group.tonight.vipvideohelper.R;
import group.tonight.vipvideohelper.VersionUpdateBean;
import group.tonight.vipvideohelper.VersionUpdater;
import group.tonight.vipvideohelper.VideoUrlLiveData;
import group.tonight.vipvideohelper.other.Consts;
import group.tonight.vipvideohelper.other.WebViewHelper;

public class HomeActivity extends AppCompatActivity {
private static final String TAG = HomeActivity.class.getSimpleName();
private WebView mWebView;
private String mCurrentVideoUrl;
private TextView mWebUrlView;
private TextInputEditText mWebUrlTextView;
private ProgressDialog mProgressDialog;
private SharedPreferences mPreferences;

Expand Down Expand Up @@ -75,22 +79,34 @@ public void onChanged(@Nullable final List<String> strings) {
});


mWebUrlView = (TextView) findViewById(R.id.web_url);
//http://jx.598110.com/index.php?url=https://v.qq.com/x/cover/y23mfuucvc2ihmy/90pXxfhH6mP.html?ptag=iqiyi
mWebView = (WebView) findViewById(R.id.web_view);
mWebUrlTextView = (TextInputEditText) findViewById(R.id.web_url);
mWebUrlTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_GO) {
String url = v.getText().toString();
Log.e(TAG, "onEditorAction: " + url);
if (!TextUtils.isEmpty(url)) {
mWebView.loadUrl(url);
}
}
return false;
}
});

WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);

//http://jx.598110.com/index.php?url=https://v.qq.com/x/cover/y23mfuucvc2ihmy/90pXxfhH6mP.html?ptag=iqiyi
mWebView = (WebView) findViewById(R.id.web_view);
mWebView.setWebViewClient(mWebViewClient);
mWebView.setWebChromeClient(new WebChromeClient());

WebViewHelper webViewHelper = new WebViewHelper(mWebView);
webViewHelper.setWebView();
webViewHelper.setWebChromeClient();

String url = "http://m.iqiyi.com/";
// String url = "www.pokonyan.cn/video/index.html";
mWebView.loadUrl(url);


mProgressDialog = new ProgressDialog(this);

mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
Expand Down Expand Up @@ -150,9 +166,21 @@ public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
Log.e(TAG, "onPageFinished: " + url);
mCurrentVideoUrl = url;
mWebUrlView.setText(url);
mWebUrlTextView.setText(url);
mProgressDialog.dismiss();
}

@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {

return super.shouldOverrideUrlLoading(view, request);
}

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.e(TAG, "shouldOverrideUrlLoading: " + url);
return super.shouldOverrideUrlLoading(view, url);
}
};

@Override
Expand Down Expand Up @@ -187,6 +215,22 @@ public void onClick(DialogInterface dialog, int which) {
})
.show();
break;
case R.id.action_select_site:
final String[] urlArray = {
"http://m.iqiyi.com/",
"http://m.v.qq.com/",
"https://www.youku.com",
};
new AlertDialog.Builder(this)
.setSingleChoiceItems(urlArray, 0, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mWebView.loadUrl(urlArray[which]);
dialog.dismiss();
}
})
.show();
break;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import java.util.List;

import group.tonight.vipvideohelper.R;
import group.tonight.vipvideohelper.other.PrefUtils;
import group.tonight.vipvideohelper.other.WebViewHelper;

public class PlayActivity extends BaseBackActivity {
private static final String TAG = PlayActivity.class.getSimpleName();
Expand All @@ -37,36 +37,31 @@ public class PlayActivity extends BaseBackActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
// this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
// this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏
// } else {
// requestWindowFeature(Window.FEATURE_ACTION_BAR);
// }

setContentView(R.layout.activity_play);
//http://jx.598110.com/index.php?url=http://m.iqiyi.com/v_19rr24dq6c.html
//http://jx.598110.com/index.php?url=https://v.qq.com/x/cover/y23mfuucvc2ihmy/90pXxfhH6mP.html?ptag=iqiyi
mWebView = (WebView) findViewById(R.id.web_view);

WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
// webSettings.setUserAgentString("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0");

mWebView.setWebViewClient(mWebViewClient);
mWebView.setWebChromeClient(new WebChromeClient());
WebViewHelper webViewHelper = new WebViewHelper(mWebView);
webViewHelper.setWebView();
webViewHelper.setWebChromeClient();

String url = DEFAULT_PARSE_URL + "http://www.iqiyi.com/v_19rrcd03uk.html";
if (getIntent().hasExtra("videoUrlList")) {
mVideoUrlList = getIntent().getStringArrayListExtra("videoUrlList");
url = mVideoUrlList.get(0);
int lastParseIndex = PrefUtils.get().getInt(PrefUtils.KEY_LAST_SELECT_API_INDEX, 0);
if (lastParseIndex < mVideoUrlList.size()) {
url = mVideoUrlList.get(lastParseIndex);
} else {
url = mVideoUrlList.get(0);
}
} else if (getIntent().hasExtra("videoUrl")) {
url = getIntent().getStringExtra("videoUrl");
}
mWebView.loadUrl(url);

mDialog = new ProgressDialog(this);
mDialog.setMessage("请稍候。。。");
}

@Override
Expand Down Expand Up @@ -106,12 +101,20 @@ public boolean onOptionsItemSelected(MenuItem item) {
if (mVideoUrlList != null) {
if (!mVideoUrlList.isEmpty()) {
String[] urlArray = mVideoUrlList.toArray(new String[mVideoUrlList.size()]);
int index = PrefUtils.get().getInt(PrefUtils.KEY_LAST_SELECT_API_INDEX, 0);
if (index >= urlArray.length) {
index = 0;
}
new AlertDialog.Builder(PlayActivity.this)
.setSingleChoiceItems(urlArray, 0, new DialogInterface.OnClickListener() {
.setSingleChoiceItems(urlArray, index, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
mWebView.loadUrl(mVideoUrlList.get(i));
PrefUtils.get()
.edit()
.putInt(PrefUtils.KEY_LAST_SELECT_API_INDEX, i)
.apply();
}
})
.show();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package group.tonight.vipvideohelper.other;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class PrefUtils {
public static final String KEY_LAST_SELECT_API_INDEX = "last_parse_index";
private static SharedPreferences INSTANCE;

public static SharedPreferences init(Context context) {
if (INSTANCE == null) {
synchronized (PrefUtils.class) {
if (INSTANCE == null) {
INSTANCE = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
}
}
}
return INSTANCE;
}

public static SharedPreferences get() {
if (INSTANCE == null) {
throw new NullPointerException("必须在Application的onCreate()中调用PrefUtils.init(this)");
}
return INSTANCE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package group.tonight.vipvideohelper.other;

import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class WebViewHelper {
private WebView mWebView;

public WebViewHelper(WebView webView) {
this.mWebView = webView;
}

public void setWebView() {
WebSettings webSettings = mWebView.getSettings();
webSettings.setBuiltInZoomControls(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setSavePassword(true);
webSettings.setSaveFormData(true);
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setSupportMultipleWindows(true);
webSettings.setPluginState(WebSettings.PluginState.ON);//设置webview支持插件
}

public void setWebChromeClient() {
mWebView.setWebChromeClient(new WebChromeClient());
}
}
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/format_list_bulleted.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!-- drawable/format-list-bulleted.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#fff" android:pathData="M7,5H21V7H7V5M7,13V11H21V13H7M4,4.5A1.5,1.5 0 0,1 5.5,6A1.5,1.5 0 0,1 4,7.5A1.5,1.5 0 0,1 2.5,6A1.5,1.5 0 0,1 4,4.5M4,10.5A1.5,1.5 0 0,1 5.5,12A1.5,1.5 0 0,1 4,13.5A1.5,1.5 0 0,1 2.5,12A1.5,1.5 0 0,1 4,10.5M7,19V17H21V19H7M4,16.5A1.5,1.5 0 0,1 5.5,18A1.5,1.5 0 0,1 4,19.5A1.5,1.5 0 0,1 2.5,18A1.5,1.5 0 0,1 4,16.5Z" />
</vector>
21 changes: 18 additions & 3 deletions app/src/main/res/layout/content_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,29 @@
tools:context=".activities.HomeActivity"
tools:showIn="@layout/activity_home">

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp">

<android.support.design.widget.TextInputEditText
android:id="@+id/web_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="当前网址"
android:imeOptions="actionGo"
android:inputType="textWebEditText"
android:textSize="12sp" />
</android.support.design.widget.TextInputLayout>

<TextView
android:id="@+id/web_url"
android:layout_width="match_parent"
android:gravity="center_vertical"
android:layout_height="?android:listPreferredItemHeightSmall"
android:gravity="center_vertical"
android:paddingLeft="?android:listPreferredItemPaddingLeft"
android:paddingRight="?android:listPreferredItemPaddingRight"
android:text="当前网址" />
android:text="当前网址"
android:visibility="gone" />

<WebView
android:id="@+id/web_view"
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/menu/menu_home_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@
android:icon="@drawable/help_circle_outline"
android:title="帮助"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_select_site"
android:icon="@drawable/format_list_bulleted"
android:title="选择视频网站"
app:showAsAction="ifRoom" />

</menu>

0 comments on commit 93bab4b

Please sign in to comment.