Browse Source

1,优化了代码结构

lyn 5 years ago
parent
commit
ed727146fa

+ 0 - 1
app/src/main/java/com/haochuan/hciptvbasic/BaseApp.java

@@ -4,7 +4,6 @@ import android.app.Application;
 
 import com.liulishuo.filedownloader.FileDownloader;
 import com.yanzhenjie.nohttp.InitializationConfig;
-import com.yanzhenjie.nohttp.Logger;
 import com.yanzhenjie.nohttp.NoHttp;
 import com.yanzhenjie.nohttp.URLConnectionNetworkExecutor;
 import com.yanzhenjie.nohttp.cache.DBCacheStore;

+ 0 - 1
app/src/main/java/com/haochuan/hciptvbasic/BaseWebActivity.java

@@ -7,7 +7,6 @@ package com.haochuan.hciptvbasic;
 
 
 import android.annotation.SuppressLint;
-import android.content.Intent;
 import android.os.Build;
 import android.os.Bundle;
 import android.view.ViewGroup;

+ 0 - 1
app/src/main/java/com/haochuan/hciptvbasic/MainActivity.java

@@ -21,7 +21,6 @@ public class MainActivity extends BaseWebActivity {
         return mBasicUrl;
     }
 
-    /**-------------------BaseWebActivity重载函数 end--------------------------*/
 
 
 }

+ 0 - 1
app/src/main/java/com/haochuan/hciptvbasic/Util/JsUtil.java

@@ -3,7 +3,6 @@ package com.haochuan.hciptvbasic.Util;
 import android.app.Activity;
 import android.content.Context;
 import android.os.Build;
-import android.util.Log;
 import android.webkit.WebView;
 
 public class JsUtil {

+ 2 - 3
app/src/main/java/com/haochuan/hciptvbasic/Util/Logger.java

@@ -10,8 +10,8 @@ import com.haochuan.hciptvbasic.BuildConfig;
 import com.haochuan.hciptvbasic.MainActivity;
 
 public class Logger {
-    static String  TAG = "HcIPTV";
-    static Context context;
+    private static String TAG = "HcIPTV";
+    private static Context context;
 
     public static void init(Context appContext){
         context = appContext;
@@ -50,5 +50,4 @@ public class Logger {
         }
     }
 
-
 }

+ 5 - 5
app/src/main/java/com/haochuan/hciptvbasic/Util/MacUtil.java

@@ -57,7 +57,7 @@ public final class MacUtil {
      * 根据wifi信息获取本地mac
      */
     @SuppressLint("HardwareIds")
-    public static String getLocalMacAddressFromWifiInfo(Context context) {
+    private static String getLocalMacAddressFromWifiInfo(Context context) {
         WifiManager wifi = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
         WifiInfo info = null;
         if (wifi != null) {
@@ -73,7 +73,7 @@ public final class MacUtil {
     /**
      * android 6.0及以上、7.0以下 获取mac地址
      */
-    public static String getMacAddress(Context context) {
+    private static String getMacAddress(Context context) {
         // 如果是6.0以下,直接通过wifimanager获取
         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
             String macAddress0 = getMacAddress0(context);
@@ -84,7 +84,7 @@ public final class MacUtil {
         return getMacAddress2();
     }
 
-    public static String getMacAddress2() {
+    private static String getMacAddress2() {
         String str = "";
         String macSerial = "";
         try {
@@ -166,7 +166,7 @@ public final class MacUtil {
     /**
      * 根据IP地址获取MAC地址
      */
-    public static String getMacAddress() {
+    private static String getMacAddress() {
         String strMacAddr = null;
         try {
             // 获得IpD地址
@@ -296,7 +296,7 @@ public final class MacUtil {
      *
      * @return
      */
-    public static String getLocalMacAddressFromBusybox() {
+    private static String getLocalMacAddressFromBusybox() {
         String result = "";
         String Mac = "";
         result = callCmd("busybox ifconfig", "HWaddr");

+ 2 - 2
app/src/main/java/com/haochuan/hciptvbasic/Util/MathUtil.java

@@ -9,7 +9,7 @@ public class MathUtil {
     }
 
     // 判断整数(int)
-    public static boolean isInteger(String str) {
+    private static boolean isInteger(String str) {
         if (null == str || "".equals(str)) {
             return false;
         }
@@ -18,7 +18,7 @@ public class MathUtil {
     }
 
     //判断浮点数(double和float)
-    public static boolean isDouble(String str) {
+    private static boolean isDouble(String str) {
         if (null == str || "".equals(str)) {
             return false;
         }

+ 1 - 1
app/src/main/java/com/haochuan/hciptvbasic/Util/Md5Util.java

@@ -27,7 +27,7 @@ public class Md5Util {
         return bytesToHexString(digest.digest());
     }
 
-    public static String bytesToHexString(byte[] src) {
+    private static String bytesToHexString(byte[] src) {
         StringBuilder stringBuilder = new StringBuilder("");
         if (src == null || src.length <= 0) {
             return null;

+ 2 - 15
app/src/main/java/com/haochuan/hciptvbasic/Util/ScreenSnap.java

@@ -2,7 +2,6 @@ package com.haochuan.hciptvbasic.Util;
 
 import android.content.Context;
 import android.graphics.Point;
-import android.os.Build;
 import android.view.WindowManager;
 
 public class ScreenSnap {
@@ -10,13 +9,7 @@ public class ScreenSnap {
     public static int getScreenWidth(Context context) {
         WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
         Point point = new Point();
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
-            //noinspection ConstantConditions
-            wm.getDefaultDisplay().getRealSize(point);
-        } else {
-            //noinspection ConstantConditions
-            wm.getDefaultDisplay().getSize(point);
-        }
+        wm.getDefaultDisplay().getRealSize(point);
         return point.x;
     }
 
@@ -24,13 +17,7 @@ public class ScreenSnap {
     public static int getScreenHeight(Context context) {
         WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
         Point point = new Point();
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
-            //noinspection ConstantConditions
-            wm.getDefaultDisplay().getRealSize(point);
-        } else {
-            //noinspection ConstantConditions
-            wm.getDefaultDisplay().getSize(point);
-        }
+        wm.getDefaultDisplay().getRealSize(point);
         return point.y;
     }
 }

+ 2 - 7
app/src/main/java/com/haochuan/hciptvbasic/Util/ToolsUtil.java

@@ -8,7 +8,6 @@ import android.content.pm.PackageManager;
 import android.net.Uri;
 import android.os.Bundle;
 import android.util.Base64;
-import android.util.Log;
 
 import com.yanzhenjie.nohttp.NoHttp;
 import com.yanzhenjie.nohttp.RequestMethod;
@@ -37,11 +36,7 @@ public class ToolsUtil {
             packageInfo = null;
             e.printStackTrace();
         }
-        if(packageInfo == null) {
-            return false;
-        } else {
-            return true;//true为安装了,false为未安装
-        }
+       return packageInfo == null;
     }
 
     public void installApk(Context context,String filePath) {
@@ -98,7 +93,7 @@ public class ToolsUtil {
      *@param ignoreResult 是否忽略结果,true,忽略;false,不忽略.
      *@param tag 透传参数,将在结果回调中一并返回,主要区别多个并发请求
      * */
-    public void clientWebRequest(Context context,String url,String paramJson,
+    public void clientWebRequest(String url,String paramJson,
                                  String headJson,int method, boolean ignoreResult,
                                  String tag,IResponseListener listener){
         if(url == null || paramJson == null || headJson == null || tag == null){

+ 0 - 6
app/src/main/java/com/haochuan/hciptvbasic/test/TestActivity.java

@@ -1,16 +1,10 @@
 package com.haochuan.hciptvbasic.test;
 
-import android.bluetooth.le.BluetoothLeScanner;
-import android.content.Intent;
 import android.os.Bundle;
 import android.widget.Button;
 
 import com.haochuan.hciptvbasic.BaseWebActivity;
 import com.haochuan.hciptvbasic.R;
-import com.haochuan.hciptvbasic.Util.Logger;
-import com.haochuan.hciptvbasic.Util.ScreenSnap;
-import com.haochuan.hciptvbasic.webview.PlayerToJS;
-import com.haochuan.hciptvbasic.webview.ToolToJS;
 
 public class TestActivity extends BaseWebActivity {
 

+ 1 - 1
app/src/main/java/com/haochuan/hciptvbasic/video/EmptyControlVideoView.java

@@ -128,7 +128,7 @@ public class EmptyControlVideoView extends StandardGSYVideoPlayer {
 
     public void setStartTime(int time){
         this.startTime = time;
-    };
+    }
 
     /*-----------------*/
 

+ 1 - 1
app/src/main/java/com/haochuan/hciptvbasic/video/HCGsyVideoPlayer.java

@@ -54,7 +54,7 @@ public class HCGsyVideoPlayer extends BaseMediaPlayer {
     @Override
     public void setStartTime(int time){
         mEmptyControlVideo.setStartTime(time);
-    };
+    }
 
     @Override
     public void resume() {

+ 1 - 3
app/src/main/java/com/haochuan/hciptvbasic/video/HCPlayer.java

@@ -1,6 +1,5 @@
 package com.haochuan.hciptvbasic.video;
 
-import android.app.Activity;
 import android.content.Context;
 import android.util.AttributeSet;
 import android.view.View;
@@ -10,7 +9,6 @@ import androidx.annotation.Nullable;
 
 import com.haochuan.hciptvbasic.R;
 import com.haochuan.hciptvbasic.Util.Logger;
-import com.shuyu.gsyvideoplayer.utils.CommonUtil;
 
 public class HCPlayer extends BaseMediaPlayer implements IVideoPlayer{
 
@@ -123,7 +121,7 @@ public class HCPlayer extends BaseMediaPlayer implements IVideoPlayer{
     }
 
     @Override
-    public void setStartTime(int time){mHcGsyVideoPlayer.setStartTime(time);};
+    public void setStartTime(int time){mHcGsyVideoPlayer.setStartTime(time);}
 
     @Override
     public void resume() {

+ 3 - 0
app/src/main/java/com/haochuan/hciptvbasic/webview/HCWebChromeClient.java

@@ -4,6 +4,8 @@ import android.util.Log;
 import android.webkit.ConsoleMessage;
 import android.webkit.WebChromeClient;
 
+import com.haochuan.hciptvbasic.Util.Logger;
+
 
 public class HCWebChromeClient extends WebChromeClient {
 
@@ -16,6 +18,7 @@ public class HCWebChromeClient extends WebChromeClient {
                 + consoleMessage.lineNumber() + " of "
                 + consoleMessage.sourceId();
         Log.d(TAG,  errorMsg);
+        Logger.e("浏览器错误:" + errorMsg);
         return true;
     }
 

+ 3 - 3
app/src/main/java/com/haochuan/hciptvbasic/webview/PayToJS.java

@@ -15,20 +15,20 @@ public class PayToJS {
      * 将SDK初始化结果传递给js
      * 参数:0,成功;-1,失败
      */
-    String JS_EVENT_SDK_INIT_RESULT = "javascript:onSDKInitResult(%s)";
+    private String JS_EVENT_SDK_INIT_RESULT = "javascript:onSDKInitResult(%s)";
 
     /**
      * 将SDK鉴权结果传递给js
      * 参数:json字符串
      */
-    String JS_EVENT_AUTH_RESULT = "javascript:onAuthResult('%s')";
+    private String JS_EVENT_AUTH_RESULT = "javascript:onAuthResult('%s')";
 
 
     /*
      * 将计费结果传递给js
      * 参数:json字符串
      * */
-    String JS_EVENT_PAY_RESULT = "javascript:onPayResult('%s')";
+    private String JS_EVENT_PAY_RESULT = "javascript:onPayResult('%s')";
 
 
     public PayToJS(Context context, WebView webView) {

+ 7 - 7
app/src/main/java/com/haochuan/hciptvbasic/webview/PlayerToJS.java

@@ -25,13 +25,13 @@ public class PlayerToJS {
 
 
     /*--------------------传给前端的播放器事件--------------------------*/
-    String JS_EVENT_PREPARING = "javascript:onPlayerPreparing()";
-    String JS_EVENT_PLAYING = "javascript:onPlayerPlaying()";
-    String JS_EVENT_RESUME = "javascript:onPlayerResume()";
-    String JS_EVENT_PAUSE = "javascript:onPlayerPause()";
-    String JS_EVENT_PLAYINGBUFFER = "javascript:onPlayingBuffer()";
-    String JS_EVENT_COMPLETE = "javascript:onPlayerComplete()";
-    String JS_EVENT_PLAYERROR="javascript:onPlayerError(%s,%s)";
+    private String JS_EVENT_PREPARING = "javascript:onPlayerPreparing()";
+    private String JS_EVENT_PLAYING = "javascript:onPlayerPlaying()";
+    private String JS_EVENT_RESUME = "javascript:onPlayerResume()";
+    private String JS_EVENT_PAUSE = "javascript:onPlayerPause()";
+    private String JS_EVENT_PLAYINGBUFFER = "javascript:onPlayingBuffer()";
+    private String JS_EVENT_COMPLETE = "javascript:onPlayerComplete()";
+    private String JS_EVENT_PLAYERROR="javascript:onPlayerError(%s,%s)";
 
 
     public PlayerToJS(Context context, WebView webView, BaseMediaPlayer mediaPlayer) {

+ 10 - 13
app/src/main/java/com/haochuan/hciptvbasic/webview/ToolToJS.java

@@ -1,12 +1,9 @@
 package com.haochuan.hciptvbasic.webview;
 
 import android.app.Activity;
-import android.app.Dialog;
 import android.content.Context;
-import android.util.TypedValue;
 import android.webkit.JavascriptInterface;
 import android.webkit.WebView;
-import android.widget.TextView;
 
 import com.haochuan.hciptvbasic.BuildConfig;
 import com.haochuan.hciptvbasic.Util.DownloadUtils;
@@ -25,25 +22,25 @@ public class ToolToJS {
     private ToolsUtil toolsUtil;
 
     //将遥控返回按键事件传递给前端
-    String JS_EVENT_BACK = "javascript:onBackEvent()";
+    private String JS_EVENT_BACK = "javascript:onBackEvent()";
 
     //将日志传递给js
-    String JS_EVENT_LOG = "javascript:onLog('%s')";
+    private String JS_EVENT_LOG = "javascript:onLog('%s')";
 
     //将response传递给js
-    String JS_EVENT_RESPONSE ="javascript:onWebRequestResponse('%s','%s','%s')";
+    private String JS_EVENT_RESPONSE ="javascript:onWebRequestResponse('%s','%s','%s')";
 
     //开始下载事件
-    String JS_EVENT_DOWNLOAD_START = "javascript:onDownloadStart()";
+    private String JS_EVENT_DOWNLOAD_START = "javascript:onDownloadStart()";
 
     //下载进度通知,参数progress,下载进度
-    String JS_EVENT_DOWNLOAD_PROGRESS = "javascript:onDownloadProgress(%s)";
+    private String JS_EVENT_DOWNLOAD_PROGRESS = "javascript:onDownloadProgress(%s)";
 
     //下载成功事件,参数filePath,下载路径
-    String JS_EVENT_DOWNLOAD_SUCCESS = "javascript:onDownloadSuccess('%s')";
+    private String JS_EVENT_DOWNLOAD_SUCCESS = "javascript:onDownloadSuccess('%s')";
 
     //下载失败事件,参数errorMessage,错误信息
-    String JS_EVENT_DOWNLOAD_FAIL = "javascript:onDownloadFail('%s')";
+    private String JS_EVENT_DOWNLOAD_FAIL = "javascript:onDownloadFail('%s')";
 
 
     public ToolToJS(Context context, WebView webView){
@@ -131,7 +128,7 @@ public class ToolToJS {
             @Override
             public void onDownloadProgress(int progress) {
                 JsUtil.evaluateJavascript(context,webView,
-                        String.format(JS_EVENT_DOWNLOAD_START,progress));
+                        String.format(JS_EVENT_DOWNLOAD_PROGRESS,progress));
             }
 
             @Override
@@ -192,9 +189,9 @@ public class ToolToJS {
      * */
     @JavascriptInterface
     public void clientWebRequest(String url,String paramJson,String headJson,int method,boolean ignoreResult,String tag){
-        toolsUtil.clientWebRequest(context, url, paramJson, headJson, method, ignoreResult, tag,
+        toolsUtil.clientWebRequest(url, paramJson, headJson, method, ignoreResult, tag,
                 (int what,String response,String tag1)->{
-                    Logger.d(String.format("what:%s,response:%s;tag:%s",response,tag1));
+                    Logger.d(String.format("what:%s,response:%s;tag:%s",what,response,tag1));
                     JsUtil.evaluateJavascript(context,webView,
                             String.format(JS_EVENT_RESPONSE,what,response,tag1));
                 });