|
@@ -1,13 +1,21 @@
|
|
|
package com.guangzhou.haochuan.jxtv.activity;
|
|
|
|
|
|
import android.app.Activity;
|
|
|
+import android.app.ActivityManager;
|
|
|
+import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.content.pm.PackageInfo;
|
|
|
import android.graphics.Bitmap;
|
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
+import android.os.Process;
|
|
|
+import android.util.Log;
|
|
|
+import android.view.KeyEvent;
|
|
|
+import android.view.MotionEvent;
|
|
|
+import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.view.WindowManager;
|
|
|
+import android.view.inputmethod.InputMethodManager;
|
|
|
import android.webkit.JavascriptInterface;
|
|
|
import android.webkit.ValueCallback;
|
|
|
import android.webkit.WebChromeClient;
|
|
@@ -25,39 +33,43 @@ import com.android.volley.toolbox.Volley;
|
|
|
import com.guangzhou.haochuan.jxtv.R;
|
|
|
import com.guangzhou.haochuan.jxtv.model.H5Switch;
|
|
|
import com.guangzhou.haochuan.jxtv.model.LoadingImage;
|
|
|
+import com.guangzhou.haochuan.jxtv.model.MiniVideo;
|
|
|
import com.guangzhou.haochuan.jxtv.util.FileUtil;
|
|
|
import com.guangzhou.haochuan.jxtv.util.LocalHttpRequest;
|
|
|
import com.guangzhou.haochuan.jxtv.util.LocalStore;
|
|
|
import com.guangzhou.haochuan.jxtv.util.ScreenUtil;
|
|
|
+import com.guangzhou.haochuan.jxtv.util.UrlManager;
|
|
|
import com.guangzhou.haochuan.jxtv.viewModel.DeviceInfoViewModel;
|
|
|
import com.guangzhou.haochuan.jxtv.viewModel.H5SwitchViewModel;
|
|
|
import com.guangzhou.haochuan.jxtv.viewModel.LoadingImageViewModel;
|
|
|
+import com.guangzhou.haochuan.jxtv.viewModel.MiniVideoViewModel;
|
|
|
+import com.ystgame.sdk.billing.api.GameInterface;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.FileNotFoundException;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.util.List;
|
|
|
import java.util.Observable;
|
|
|
-import java.util.Observer;
|
|
|
|
|
|
-public class MainActivity extends PayActivity {
|
|
|
+public class DjblWebActivity extends PayActivity {
|
|
|
|
|
|
- String TAG = "MainActivity";
|
|
|
+ String TAG = "DjblWebActivity";
|
|
|
WebView webView;
|
|
|
int playerRequestCode = 2;
|
|
|
- int payRequestCode = 2;
|
|
|
+ int payRequestCode = 3;
|
|
|
|
|
|
Boolean isPlaying = false;
|
|
|
+ Boolean isPaying = false;
|
|
|
+ Boolean isExiting = false;
|
|
|
FrameLayout container;
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
setContentView(R.layout.activity_main);
|
|
|
- getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
|
|
|
init();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
protected void onActivityResult(int requestCode,int resultCode,Intent data){
|
|
|
super.onActivityResult(requestCode,resultCode,data);
|
|
@@ -69,25 +81,33 @@ public class MainActivity extends PayActivity {
|
|
|
}
|
|
|
}else if(requestCode == payRequestCode){
|
|
|
onPayBack(resultCode);
|
|
|
+ isPaying = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void gotoPayActivity(){
|
|
|
+ isPaying = true;
|
|
|
+ if(LocalStore.getInstance().getIsVip(this)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
Intent intent = new Intent(this,DjblPayActivity.class);
|
|
|
- MainActivity.this.startActivityForResult(intent,payRequestCode);
|
|
|
+ DjblWebActivity.this.startActivityForResult(intent,payRequestCode);
|
|
|
}
|
|
|
|
|
|
private void init(){
|
|
|
container = findViewById(R.id.webview_container);
|
|
|
- String url = "http://117.169.11.222:8000/h5v2/index.html";
|
|
|
- webView = new WebView(this);
|
|
|
- container.addView(webView,new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT));
|
|
|
+ String url = UrlManager.getInstance().getWebIndexPageUrl();
|
|
|
+ //url = "http://117.169.11.222:8018/tv/h5v2/activity/20180720/index.html";
|
|
|
+ //url= "http://117.169.11.222:8018/tv/h5v2/test.html";
|
|
|
+ webView = findViewById(R.id.h5_web);
|
|
|
+ //container.addView(webView,new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT));
|
|
|
webView.getSettings().setJavaScriptEnabled(true);
|
|
|
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
|
|
|
+ webView.setVisibility(View.INVISIBLE);
|
|
|
webView.setWebChromeClient(new WebChromeClient() {
|
|
|
@Override
|
|
|
public void onProgressChanged(WebView view, int progress) {
|
|
|
- MainActivity.this.setProgress(progress * 1000);
|
|
|
+ DjblWebActivity.this.setProgress(progress * 1000);
|
|
|
}
|
|
|
});
|
|
|
webView.setWebViewClient(new WebViewClient() {
|
|
@@ -95,11 +115,12 @@ public class MainActivity extends PayActivity {
|
|
|
public void onPageFinished(WebView view, String url)
|
|
|
{
|
|
|
super.onPageFinished(view, url);
|
|
|
+ webView.setVisibility(View.VISIBLE);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
|
|
- Toast.makeText(MainActivity.this, "Oh no! " + description, Toast.LENGTH_SHORT).show();
|
|
|
+ Toast.makeText(DjblWebActivity.this, "Oh no! " + description, Toast.LENGTH_SHORT).show();
|
|
|
}
|
|
|
});
|
|
|
webView.addJavascriptInterface(new AndroidToJs(h5Result),"djbl2");
|
|
@@ -108,11 +129,13 @@ public class MainActivity extends PayActivity {
|
|
|
//下载loading图
|
|
|
new LoadingImageViewModel(ScreenUtil.getInstance().getDpiType(this)).addObserver(this);
|
|
|
|
|
|
+ //下载miniVideo图
|
|
|
+ new MiniVideoViewModel(ScreenUtil.getInstance().getDpiType(this)).addObserver(this);
|
|
|
|
|
|
- //活动开关
|
|
|
+ /* //活动开关
|
|
|
if(!LocalStore.getInstance().getDeviceInfoSaved(this)){
|
|
|
new H5SwitchViewModel().addObserver(this);
|
|
|
- }
|
|
|
+ }*/
|
|
|
}
|
|
|
|
|
|
String deviceId = "";
|
|
@@ -122,22 +145,22 @@ public class MainActivity extends PayActivity {
|
|
|
localHttpRequest.getUrls(this, new LocalHttpRequest.GetUrlsListener() {
|
|
|
@Override
|
|
|
public void onFinished() {
|
|
|
- localHttpRequest.getParam1(MainActivity.this, new LocalHttpRequest.ResultListener() {
|
|
|
+ localHttpRequest.getParam1(DjblWebActivity.this, new LocalHttpRequest.ResultListener() {
|
|
|
@Override
|
|
|
public void onResult(String result) {
|
|
|
if(result != null){
|
|
|
deviceId = result;
|
|
|
}
|
|
|
- localHttpRequest.getParam2(MainActivity.this, new LocalHttpRequest.ResultListener() {
|
|
|
+ localHttpRequest.getParam2(DjblWebActivity.this, new LocalHttpRequest.ResultListener() {
|
|
|
@Override
|
|
|
public void onResult(String result) {
|
|
|
final String token = result ==null?"":result;
|
|
|
- localHttpRequest.getParam3(MainActivity.this, new LocalHttpRequest.ResultListener() {
|
|
|
+ localHttpRequest.getParam3(DjblWebActivity.this, new LocalHttpRequest.ResultListener() {
|
|
|
@Override
|
|
|
public void onResult(String result) {
|
|
|
String phone = result;
|
|
|
- int isVip = LocalStore.getInstance().getIsVip(MainActivity.this)?1:0;
|
|
|
- String uId = LocalStore.getInstance().getUserId(MainActivity.this);
|
|
|
+ int isVip = LocalStore.getInstance().getIsVip(DjblWebActivity.this)?1:0;
|
|
|
+ String uId = LocalStore.getInstance().getUserId(DjblWebActivity.this);
|
|
|
new DeviceInfoViewModel(deviceId,phone,token,isVip,uId);
|
|
|
}
|
|
|
});
|
|
@@ -171,6 +194,26 @@ public class MainActivity extends PayActivity {
|
|
|
}));
|
|
|
}
|
|
|
|
|
|
+ //下载miniVideo背景图
|
|
|
+ private void downloadMiniVideoImage(String imageUrl){
|
|
|
+ final String path = FileUtil.getInstance().getMiniVideoImageSavePath(this,ScreenUtil.getInstance().getDpiType(this));
|
|
|
+ File file = new File(path);
|
|
|
+ if(file.exists()){
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+ Volley.newRequestQueue(this).add(new ImageRequest(imageUrl, new Response.Listener<Bitmap>() {
|
|
|
+ @Override
|
|
|
+ public void onResponse(Bitmap response) {
|
|
|
+ saveImage(path,response);
|
|
|
+ }
|
|
|
+ },2000,2000,ImageView.ScaleType.CENTER, null,new Response.ErrorListener() {
|
|
|
+ @Override
|
|
|
+ public void onErrorResponse(VolleyError error) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
public void saveImage(String imagePath,Bitmap bmp) {
|
|
|
File file = new File(imagePath);
|
|
|
try {
|
|
@@ -192,10 +235,10 @@ public class MainActivity extends PayActivity {
|
|
|
return;
|
|
|
}
|
|
|
if(!examineStatus.equals("10")){
|
|
|
- Toast.makeText(MainActivity.this,"视频未通过审核,或已下架",Toast.LENGTH_SHORT).show();
|
|
|
+ Toast.makeText(DjblWebActivity.this,"视频未通过审核,或已下架",Toast.LENGTH_SHORT).show();
|
|
|
return;
|
|
|
}
|
|
|
- Intent intent = new Intent(MainActivity.this,CntvPlayerActivity.class);
|
|
|
+ Intent intent = new Intent(DjblWebActivity.this,CntvPlayerActivity.class);
|
|
|
intent.putExtra("url",url);
|
|
|
intent.putExtra("title",title);
|
|
|
intent.putExtra("sourceId",sourceId);
|
|
@@ -203,11 +246,12 @@ public class MainActivity extends PayActivity {
|
|
|
intent.putExtra("examineId",examineId);
|
|
|
intent.putExtra("examineStatus",examineStatus);
|
|
|
intent.putExtra("examineType",examineType);
|
|
|
- MainActivity.this.startActivityForResult(intent,playerRequestCode);
|
|
|
+ DjblWebActivity.this.startActivityForResult(intent,playerRequestCode);
|
|
|
isPlaying = true;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+
|
|
|
//将原生Toast包含在UI线程中
|
|
|
private void Toast(final Activity activity, final String msg){
|
|
|
activity.runOnUiThread(new Runnable() {
|
|
@@ -239,34 +283,34 @@ public class MainActivity extends PayActivity {
|
|
|
|
|
|
@JavascriptInterface
|
|
|
public void appExit(){
|
|
|
- MainActivity.this.runOnUiThread(new Runnable() {
|
|
|
+ DjblWebActivity.this.runOnUiThread(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- MainActivity.this.finish();
|
|
|
+ onExit();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@JavascriptInterface
|
|
|
public String getUser(){
|
|
|
- return LocalStore.getInstance().getUserId(MainActivity.this);
|
|
|
+ return LocalStore.getInstance().getUserId(DjblWebActivity.this);
|
|
|
}
|
|
|
|
|
|
@JavascriptInterface
|
|
|
public int getVipState(){
|
|
|
- boolean vipState = LocalStore.getInstance().getIsVip(MainActivity.this);
|
|
|
+ boolean vipState = LocalStore.getInstance().getIsVip(DjblWebActivity.this);
|
|
|
return vipState?1:-1;
|
|
|
}
|
|
|
|
|
|
@JavascriptInterface
|
|
|
public String getMac(){
|
|
|
- return LocalStore.getInstance().getMac(MainActivity.this);
|
|
|
+ return LocalStore.getInstance().getMac(DjblWebActivity.this);
|
|
|
}
|
|
|
|
|
|
@JavascriptInterface
|
|
|
public int getVersionCode(){
|
|
|
try{
|
|
|
- PackageInfo packageInfo = MainActivity.this.getPackageManager().getPackageInfo(MainActivity.this.getPackageName(),0);
|
|
|
+ PackageInfo packageInfo = DjblWebActivity.this.getPackageManager().getPackageInfo(DjblWebActivity.this.getPackageName(),0);
|
|
|
return packageInfo.versionCode;
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
@@ -277,7 +321,7 @@ public class MainActivity extends PayActivity {
|
|
|
@JavascriptInterface
|
|
|
public String getVersionName(){
|
|
|
try{
|
|
|
- PackageInfo packageInfo = MainActivity.this.getPackageManager().getPackageInfo(MainActivity.this.getPackageName(),0);
|
|
|
+ PackageInfo packageInfo = DjblWebActivity.this.getPackageManager().getPackageInfo(DjblWebActivity.this.getPackageName(),0);
|
|
|
return packageInfo.versionName;
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
@@ -286,6 +330,17 @@ public class MainActivity extends PayActivity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void onExit(){
|
|
|
+ isExiting = true;
|
|
|
+ GameInterface.finishAllDialog();
|
|
|
+ //GameInterface.exit();
|
|
|
+ this.finish();
|
|
|
+ Intent intent = new Intent(Intent.ACTION_MAIN);
|
|
|
+ intent.addCategory(Intent.CATEGORY_HOME);
|
|
|
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
+ startActivity(intent);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void onBackPressed() {
|
|
|
onJsBack();
|
|
@@ -341,6 +396,30 @@ public class MainActivity extends PayActivity {
|
|
|
String isFee,String examineId,String examineStatus,String examineType);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ protected void onStop(){
|
|
|
+ super.onStop();
|
|
|
+ killOriginProcess();
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 因为本activity是单独一个线程,如果退出的话,必须还要关闭原先线程才能起作用
|
|
|
+ * */
|
|
|
+ private void killOriginProcess(){
|
|
|
+ ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
|
|
|
+ List<ActivityManager.RunningAppProcessInfo> runningAppProcessInfos = am.getRunningAppProcesses();
|
|
|
+ Log.d("djbl","index 0 pacagename:" + runningAppProcessInfos.get(0).processName);
|
|
|
+ if(!runningAppProcessInfos.get(0).processName.equals("com.guangzhou.haochuan.jxtv")
|
|
|
+ &&!runningAppProcessInfos.get(0).processName.equals("com.guangzhou.haochuan.jxtv:remote")
|
|
|
+ && !isPaying){
|
|
|
+ am.killBackgroundProcesses("com.guangzhou.haochuan.jxtv:remote"); // API Level至少为8才能使用
|
|
|
+ am.killBackgroundProcesses("com.guangzhou.haochuan.jxtv");
|
|
|
+ DjblWebActivity.this.finish();
|
|
|
+ System.exit(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
protected void onDestroy(){
|
|
@@ -362,10 +441,11 @@ public class MainActivity extends PayActivity {
|
|
|
if(container != null){
|
|
|
container = null;
|
|
|
}
|
|
|
-
|
|
|
super.onDestroy();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public void update(Observable o, Object arg) {
|
|
|
super.update(o,arg);
|
|
@@ -375,7 +455,7 @@ public class MainActivity extends PayActivity {
|
|
|
if(loadingImage.code == 0){
|
|
|
downloadLoadingImage(loadingImage.data.imgUrl);
|
|
|
}
|
|
|
- }if(o instanceof H5SwitchViewModel){
|
|
|
+ }else if(o instanceof H5SwitchViewModel){
|
|
|
H5SwitchViewModel h5SwitchViewModel = (H5SwitchViewModel)o;
|
|
|
H5Switch h5Switch = h5SwitchViewModel.getH5Switch();
|
|
|
if(h5Switch.code == 0){
|
|
@@ -383,6 +463,15 @@ public class MainActivity extends PayActivity {
|
|
|
saveInfo();
|
|
|
}
|
|
|
}
|
|
|
+ }else if(o instanceof MiniVideoViewModel){
|
|
|
+ MiniVideoViewModel miniVideoViewModel = (MiniVideoViewModel)o;
|
|
|
+ MiniVideo miniVideo = miniVideoViewModel.getMiniVideo();
|
|
|
+ if(miniVideo.code == 0){
|
|
|
+ MiniVideo.MiniVideoData miniVideoData = miniVideo.data;
|
|
|
+ if(miniVideoData != null){
|
|
|
+ downloadMiniVideoImage(miniVideoData.videoWindowImage);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|