소스 검색

优化了代码

lyn 5 년 전
부모
커밋
3edd99a907

+ 5 - 4
app/build.gradle

@@ -5,7 +5,7 @@ android {
         config {
             keyAlias 'hc'
             keyPassword 'hc123456'
-            storeFile file('C:/dev/project/android/hcGit/hcKeyStore.jks')
+            storeFile file('D:\\android project\\sxyd\\sxyd_dudu_weilai\\key\\hcKeyStore.jks')
             storePassword 'hc123456'
         }
     }
@@ -14,14 +14,15 @@ android {
         applicationId "com.sxyd.duduUp"
         minSdkVersion versions.minSdk
         targetSdkVersion versions.targetSdk
-        versionCode 4
-        versionName "v1.0.4"
+        versionCode 7
+        versionName "v1.0.7"
         ndk {
             //APP的build.gradle设置支持的SO库架构
             abiFilters 'armeabi', 'armeabi-v7a'
         }
         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
-        buildConfigField 'int','platformType','3'   ////1:百事通,2:银河,3:未来
+        buildConfigField 'int','platformType','2'   ////1:百事通,2:银河,3:未来
+        buildConfigField 'int','devicesType','1'   ////1:中兴,2:华为
     }
     buildTypes {
         debug {

+ 1 - 1
app/release/output.json

@@ -1 +1 @@
-[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":4,"versionName":"v1.0.4","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
+[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":7,"versionName":"v1.0.7","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]

+ 75 - 0
app/src/main/java/com/hc/webapp/GetSXHeZiParam.java

@@ -0,0 +1,75 @@
+package com.hc.webapp;
+
+import android.content.Context;
+import android.database.Cursor;
+import android.net.Uri;
+import android.util.Log;
+
+public class GetSXHeZiParam {
+    private Context context;
+    private static GetSXHeZiParam instance;
+
+    public static GetSXHeZiParam getInstance(Context context){
+        if(instance == null){
+            instance = new GetSXHeZiParam(context);
+        }
+        return instance;
+    }
+
+    public GetSXHeZiParam(Context context){
+        this.context = context;
+    }
+
+    public String getUserName(){
+        try{
+            Uri queryUri = Uri.parse("content://stbauthinfo/authentication/");
+            Cursor cursor = context.getContentResolver().query(queryUri,new String[]{"value"},"name='username'",null,null);
+            if(cursor == null){
+                return "";
+            }
+            cursor.moveToFirst();
+            String userName = cursor.getString(cursor.getColumnIndexOrThrow("value"));
+            cursor.close();
+            return userName;
+        }catch (Exception e){
+            e.printStackTrace();
+            return "";
+        }
+    }
+
+
+
+    public String getUserToken(){
+        try{
+            Uri queryUri = Uri.parse("content://stbauthinfo/authentication/");
+            Cursor cursor = context.getContentResolver().query(queryUri,new String[]{"value"},"name='user_token'",null,null);
+            if(cursor == null){
+                return "";
+            }
+            cursor.moveToFirst();
+            String userToken = cursor.getString(cursor.getColumnIndexOrThrow("value"));
+            cursor.close();
+            return userToken;
+        }catch (Exception e){
+            e.printStackTrace();
+            return "";
+        }
+    }
+
+    public String getUserEpgServer(){
+        try{
+            Uri queryUri = Uri.parse("content://stbauthinfo/authentication/");
+            Cursor cursor = context.getContentResolver().query(queryUri,new String[]{"value"},"name='epg_server'",null,null);
+            if(cursor == null){
+                return "";
+            }
+            cursor.moveToFirst();
+            String epgServer = cursor.getString(cursor.getColumnIndexOrThrow("value"));
+            cursor.close();
+            return epgServer;
+        }catch (Exception e){
+            e.printStackTrace();
+            return "";
+        }
+    }
+}

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 63 - 13
app/src/main/java/com/hc/webapp/MainActivity.java


+ 25 - 9
app/src/main/java/com/hc/webapp/web/AndroidToJS.java

@@ -23,6 +23,7 @@ import com.hc.model.YNYD.YNYDService;
 import com.hc.request.Config;
 import com.hc.request.core.DefaultCallback;
 import com.hc.webapp.BuildConfig;
+import com.hc.webapp.GetSXHeZiParam;
 import com.jewel.lib.java.StringUtil;
 import com.orhanobut.logger.Logger;
 
@@ -41,9 +42,13 @@ public class AndroidToJS {
     private static final String JS_EVENT_AUTH_RESULT = "javascript:onAuthResult(%s, %s)";
     public static final String JS_EVENT_PLAY_NEXT = "javascript:onPlayNextEvent()";
 
+    static String backFuc = "function(){if(document.onkeydown){document.onkeydown({keyCode:8});}}";
+    public static final String JS_BACK_EVENT = "javascript:(" + backFuc + ")()";
+
     private static final String HAD_FLOAT_VIDEO = "1"; // 当前H5页面存在小窗视频
     private static final String NEED_MUTE = "0";
 
+
     String TAG ="AndroidToJS";
 
 //    private String testVideo = "http://hnh5pic.oss-cn-shenzhen.aliyuncs.com/3.mp4";
@@ -51,6 +56,7 @@ public class AndroidToJS {
     private String testVideo = "http://192.168.2.112/000079/000079.m3u8";
 
     private int platformType = BuildConfig.platformType; //1:百事通,2:银河,3:未来
+    private int deviceType = BuildConfig.devicesType;
 
     /**
      * JS调用类型
@@ -131,11 +137,11 @@ public class AndroidToJS {
 
     private void playFull(String url, String sourceId, String title, long time, boolean hadFloat, boolean isNextVideo, boolean showCompleteDialog, int seekTime) {
         if (isNextVideo) { // 播放下一条视频时,直接在当前全屏窗口开启新视频的播放
-            playVideoListener.playFullVideo(url, title, getUserName(), sourceId, time, hadFloat, showCompleteDialog, seekTime);
+            playVideoListener.playFullVideo(url, title, GetSXHeZiParam.getInstance(context).getUserName(), sourceId, time, hadFloat, showCompleteDialog, seekTime);
         } else if (hadFloat) { // 有小窗时,直接切换成全屏
-            playVideoListener.playFullVideo(url, title, getUserName(), sourceId, time, true, showCompleteDialog, 0);
+            playVideoListener.playFullVideo(url, title, GetSXHeZiParam.getInstance(context).getUserName(), sourceId, time, true, showCompleteDialog, 0);
         } else { // 开启新的全屏播放窗口
-            playVideoListener.playFullVideo(url, title, getUserName(), sourceId, time, false, showCompleteDialog, seekTime);
+            playVideoListener.playFullVideo(url, title, GetSXHeZiParam.getInstance(context).getUserName(), sourceId, time, false, showCompleteDialog, seekTime);
         }
     }
 
@@ -167,7 +173,7 @@ public class AndroidToJS {
     private void playFloat(String url, String sourceId, String title, final int x, final int y, final int width, final int height, boolean needMute) {
         playVideoListener.playFloatVideo(url,
                 x, y, width, height,
-                getUserName(), sourceId, title, needMute);
+                GetSXHeZiParam.getInstance(context).getUserName(), sourceId, title, needMute);
     }
 
     /**
@@ -209,7 +215,7 @@ public class AndroidToJS {
 
     @JavascriptInterface
     public String getUserId() {
-        return getUserName();
+        return GetSXHeZiParam.getInstance(context).getUserName();
     }
 
     @JavascriptInterface
@@ -219,7 +225,7 @@ public class AndroidToJS {
 
     @JavascriptInterface
     public String getEpgServer() {
-        return getUserEpgServer();
+        return GetSXHeZiParam.getInstance(context).getUserEpgServer();
     }
 
     @JavascriptInterface
@@ -229,7 +235,7 @@ public class AndroidToJS {
 
     @JavascriptInterface
     public String getToken() {
-        return getUserToken();
+        return GetSXHeZiParam.getInstance(context).getUserToken();
     }
 
     @JavascriptInterface
@@ -254,10 +260,17 @@ public class AndroidToJS {
 
     @JavascriptInterface
     public int getPlatformType() {
+        Log.d(TAG,"platformType:" + platformType );
         return platformType;
     }
 
     @JavascriptInterface
+    public int getDeviceType() {
+        Log.d(TAG,"deviceType:" + deviceType);
+        return deviceType;
+    }
+
+    @JavascriptInterface
     public void pay() {
     }
 
@@ -374,13 +387,14 @@ public class AndroidToJS {
         return pattern.matcher(str).matches();
     }
 
-    private String getUserName(){
+    /*private String getUserName(){
         try{
             Uri queryUri = Uri.parse("content://stbauthinfo/authentication/");
             Cursor cursor = context.getContentResolver().query(queryUri,new String[]{"value"},"name='username'",null,null);
             cursor.moveToFirst();
             String userName = cursor.getString(cursor.getColumnIndexOrThrow("value"));
             Log.d(TAG,"userName:" + userName);
+            cursor.close();
             return userName;
         }catch (Exception e){
             e.printStackTrace();
@@ -388,6 +402,8 @@ public class AndroidToJS {
         }
     }
 
+
+
     private String getUserToken(){
         try{
             Uri queryUri = Uri.parse("content://stbauthinfo/authentication/");
@@ -418,7 +434,7 @@ public class AndroidToJS {
             e.printStackTrace();
             return "";
         }
-    }
+    }*/
 
 
     public interface PlayVideoListener {

+ 18 - 2
app/src/main/java/com/hc/webapp/web/BaseWebActivity.java

@@ -48,11 +48,12 @@ public abstract class BaseWebActivity extends AppCompatActivity {
 
     public static final int REQUEST_PLAY_FINISH = 0x100;
 
-    private WebView webView;
+    protected WebView webView;
     private ImageView noticeImage;
     protected FrameLayout webViewContainer;
     protected boolean hasShowWebView = false;
     protected boolean hasOneFloatViewToShow = true;
+    String TAG = "BaseWebActivity";
     /**
      * JS调用对象名
      */
@@ -67,6 +68,7 @@ public abstract class BaseWebActivity extends AppCompatActivity {
     private boolean shouldOverrideBackPressToJS = true;
 
     private int platformType = BuildConfig.platformType; //1:百事通,2:银河,3:未来
+    private int deviceType = BuildConfig.devicesType;
 
 
     /**
@@ -278,6 +280,7 @@ public abstract class BaseWebActivity extends AppCompatActivity {
             setShouldOverrideBackPressToJS(true);
             webView.loadUrl(getIndexURL());
         }
+
     }
 
     /*
@@ -391,7 +394,8 @@ public abstract class BaseWebActivity extends AppCompatActivity {
     }
 
     protected void updateApk(){
-        String url = "http://112.35.32.145:8090/index.php?m=Home&c=AndroidApi&a=uploadVersion&origin="+platformType;
+        String url = "http://112.35.32.145:8090/index.php?m=Home&c=AndroidApi&a=uploadVersion&origin="+platformType + "&platform=" + deviceType;
+        Log.d(TAG,"update url:" + url);
         GetRuquest getRuquest = new GetRuquest();
         getRuquest.RequestAsync(url, new GetRequestListener() {
             @Override
@@ -490,12 +494,24 @@ public abstract class BaseWebActivity extends AppCompatActivity {
     @Override
     public void onBackPressed() {
         if (shouldOverrideBackPressToJS) {
+            notifyKeyEvent("back",8,true);
             AndroidToJS.evaluateJavascript(webView, AndroidToJS.JS_EVENT_BACK);
         } else {
             super.onBackPressed();
         }
     }
 
+    public void notifyKeyEvent(String key, final int code, boolean keyDown) {
+        Log.d(TAG, "notifyKeyEvent('" + key + "', " + code + ", " + keyDown + ")" );
+        webView.loadUrl("javascript:" +
+                "(function(){" +
+                "var e=document.createEvent('Event');" +
+                "e.initEvent('keydown',true, true); " +
+                "e.keyCode=" + code + ";" +
+                "e.which=" + code + ";" +
+                "document.body.dispatchEvent(e);})()");
+    }
+
 
 //    @Override
 //    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

+ 0 - 1
lib/src/main/java/com/hc/lib/video/MVideoPlayer.java

@@ -696,7 +696,6 @@ public class MVideoPlayer extends FrameLayout implements IVideoPlayer {
         if (videoView.isPlaying() && play) { //已是播放状态,忽略
             return;
         }
-
         if (play) {
             videoView.start();
             //add by 许林 2018/12/6