yangchong 3 лет назад
Родитель
Сommit
5c61aace28

+ 13 - 3
Demo/src/main/java/com/yc/ycvideoplayer/BaseApplication.java

@@ -6,15 +6,18 @@ import android.content.res.Configuration;
 import android.util.Log;
 
 
+import androidx.annotation.NonNull;
+
 import com.yc.kernel.factory.PlayerFactory;
 import com.yc.kernel.utils.PlayerConstant;
 import com.yc.kernel.utils.PlayerFactoryUtils;
 
-import com.yc.music.utils.MusicSpUtils;
 import com.yc.video.config.VideoPlayerConfig;
 import com.yc.video.player.VideoViewManager;
 import com.yc.videosqllite.manager.CacheConfig;
 import com.yc.videosqllite.manager.LocationManager;
+import com.yc.videotool.VideoSpUtils;
+import com.yc.videotool.ScheduleTask;
 
 /**
  * ================================================
@@ -69,9 +72,16 @@ public class BaseApplication extends Application {
                 //创建SurfaceView
                 //.setRenderViewFactory(SurfaceViewFactory.create())
                 .build());
-        MusicSpUtils.init(this);
+        VideoSpUtils.init(this);
 
         initVideoCache();
+
+        ScheduleTask.getInstance().schedule(new Runnable() {
+            @Override
+            public void run() {
+                //初始化一些耗时的操作
+            }
+        });
     }
 
     private void initVideoCache() {
@@ -119,7 +129,7 @@ public class BaseApplication extends Application {
      * onConfigurationChanged
      */
     @Override
-    public void onConfigurationChanged(Configuration newConfig) {
+    public void onConfigurationChanged(@NonNull Configuration newConfig) {
         Log.d("Application", "onConfigurationChanged");
         super.onConfigurationChanged(newConfig);
     }

+ 4 - 7
Demo/src/main/java/com/yc/ycvideoplayer/music/PlayMusicFragment.java

@@ -26,16 +26,13 @@ import com.yc.music.config.PlayModeEnum;
 import com.yc.music.inter.OnPlayerEventListener;
 import com.yc.music.model.AudioBean;
 import com.yc.music.tool.BaseAppHelper;
-import com.yc.music.utils.MusicSpUtils;
 import com.yc.video.tool.PlayerUtils;
+import com.yc.videotool.VideoSpUtils;
 import com.yc.videotool.VideoLogUtils;
 
 import org.yc.ycvideoplayer.R;
 
-import java.io.File;
-import java.util.List;
 import java.util.Objects;
-import java.util.concurrent.TimeUnit;
 
 
 public class PlayMusicFragment extends Fragment implements View.OnClickListener, OnPlayerEventListener {
@@ -328,7 +325,7 @@ public class PlayMusicFragment extends Fragment implements View.OnClickListener,
     }
 
     private void switchPlayMode() {
-        int playMode = MusicSpUtils.getInstance(MusicConstant.SP_NAME).getInt(MusicConstant.PLAY_MODE, 0);
+        int playMode = VideoSpUtils.getInstance(MusicConstant.SP_NAME).getInt(MusicConstant.PLAY_MODE, 0);
         PlayModeEnum mode = PlayModeEnum.valueOf(playMode);
         switch (mode) {
             case LOOP:
@@ -343,13 +340,13 @@ public class PlayMusicFragment extends Fragment implements View.OnClickListener,
             default:
                 break;
         }
-        MusicSpUtils.getInstance(MusicConstant.SP_NAME).put(MusicConstant.PLAY_MODE, mode.value());
+        VideoSpUtils.getInstance(MusicConstant.SP_NAME).put(MusicConstant.PLAY_MODE, mode.value());
         initPlayMode();
     }
 
 
     private void initPlayMode() {
-        int playMode = MusicSpUtils.getInstance(MusicConstant.SP_NAME).getInt(MusicConstant.PLAY_MODE, 0);
+        int playMode = VideoSpUtils.getInstance(MusicConstant.SP_NAME).getInt(MusicConstant.PLAY_MODE, 0);
         ivMode.setImageLevel(playMode);
     }
 

+ 0 - 1
MusicPlayer/src/main/java/com/yc/music/impl/PlayAudioImpl.java

@@ -18,7 +18,6 @@ import com.yc.music.receiver.AudioEarPhoneReceiver;
 import com.yc.music.service.PlayAudioService;
 import com.yc.music.tool.BaseAppHelper;
 import com.yc.music.tool.QuitTimerHelper;
-import com.yc.music.utils.MusicSpUtils;
 import com.yc.music.utils.NotificationHelper;
 import com.yc.videotool.VideoLogUtils;
 

+ 0 - 416
MusicPlayer/src/main/java/com/yc/music/utils/MusicSpUtils.java

@@ -1,416 +0,0 @@
-package com.yc.music.utils;
-
-import android.annotation.SuppressLint;
-import android.app.Application;
-import android.content.Context;
-import android.content.SharedPreferences;
-
-import androidx.annotation.NonNull;
-import androidx.collection.SimpleArrayMap;
-
-import java.util.Collections;
-import java.util.Map;
-import java.util.Set;
-
-
-@SuppressLint("ApplySharedPref")
-public final class MusicSpUtils {
-
-    private static SimpleArrayMap<String, MusicSpUtils> SP_UTILS_MAP = new SimpleArrayMap<>();
-    private SharedPreferences sp;
-    private static Context context;
-
-    public static void init(Application application){
-        context = application;
-    }
-
-    /**
-     * 获取 SP 实例
-     *
-     * @return {@link MusicSpUtils}
-     */
-    public static MusicSpUtils getInstance() {
-        return getInstance("");
-    }
-
-    /**
-     * 获取 SP 实例
-     *
-     * @param spName sp 名
-     * @return {@link MusicSpUtils}
-     */
-    public static MusicSpUtils getInstance(String spName) {
-        if (isSpace(spName)) spName = "spUtils";
-        MusicSpUtils spUtils = SP_UTILS_MAP.get(spName);
-        if (spUtils == null) {
-            spUtils = new MusicSpUtils(spName);
-            SP_UTILS_MAP.put(spName, spUtils);
-        }
-        return spUtils;
-    }
-
-    private MusicSpUtils(final String spName) {
-        sp = context.getSharedPreferences(spName, Context.MODE_PRIVATE);
-    }
-
-    /**
-     * SP 中写入 String
-     *
-     * @param key   键
-     * @param value 值
-     */
-    public void put(@NonNull final String key, @NonNull final String value) {
-        put(key, value, false);
-    }
-
-    /**
-     * SP 中写入 String
-     *
-     * @param key      键
-     * @param value    值
-     * @param isCommit {@code true}: {@link SharedPreferences.Editor#commit()}<br>
-     *                 {@code false}: {@link SharedPreferences.Editor#apply()}
-     */
-    public void put(@NonNull final String key,
-                    @NonNull final String value,
-                    final boolean isCommit) {
-        if (isCommit) {
-            sp.edit().putString(key, value).commit();
-        } else {
-            sp.edit().putString(key, value).apply();
-        }
-    }
-
-    /**
-     * SP 中读取 String
-     *
-     * @param key 键
-     * @return 存在返回对应值,不存在返回默认值{@code ""}
-     */
-    public String getString(@NonNull final String key) {
-        return getString(key, "");
-    }
-
-    /**
-     * SP 中读取 String
-     *
-     * @param key          键
-     * @param defaultValue 默认值
-     * @return 存在返回对应值,不存在返回默认值{@code defaultValue}
-     */
-    public String getString(@NonNull final String key, @NonNull final String defaultValue) {
-        return sp.getString(key, defaultValue);
-    }
-
-    /**
-     * SP 中写入 int
-     *
-     * @param key   键
-     * @param value 值
-     */
-    public void put(@NonNull final String key, final int value) {
-        put(key, value, false);
-    }
-
-    /**
-     * SP 中写入 int
-     *
-     * @param key      键
-     * @param value    值
-     * @param isCommit {@code true}: {@link SharedPreferences.Editor#commit()}<br>
-     *                 {@code false}: {@link SharedPreferences.Editor#apply()}
-     */
-    public void put(@NonNull final String key, final int value, final boolean isCommit) {
-        if (isCommit) {
-            sp.edit().putInt(key, value).commit();
-        } else {
-            sp.edit().putInt(key, value).apply();
-        }
-    }
-
-    /**
-     * SP 中读取 int
-     *
-     * @param key 键
-     * @return 存在返回对应值,不存在返回默认值-1
-     */
-    public int getInt(@NonNull final String key) {
-        return getInt(key, -1);
-    }
-
-    /**
-     * SP 中读取 int
-     *
-     * @param key          键
-     * @param defaultValue 默认值
-     * @return 存在返回对应值,不存在返回默认值{@code defaultValue}
-     */
-    public int getInt(@NonNull final String key, final int defaultValue) {
-        return sp.getInt(key, defaultValue);
-    }
-
-    /**
-     * SP 中写入 long
-     *
-     * @param key   键
-     * @param value 值
-     */
-    public void put(@NonNull final String key, final long value) {
-        put(key, value, false);
-    }
-
-    /**
-     * SP 中写入 long
-     *
-     * @param key      键
-     * @param value    值
-     * @param isCommit {@code true}: {@link SharedPreferences.Editor#commit()}<br>
-     *                 {@code false}: {@link SharedPreferences.Editor#apply()}
-     */
-    public void put(@NonNull final String key, final long value, final boolean isCommit) {
-        if (isCommit) {
-            sp.edit().putLong(key, value).commit();
-        } else {
-            sp.edit().putLong(key, value).apply();
-        }
-    }
-
-    /**
-     * SP 中读取 long
-     *
-     * @param key 键
-     * @return 存在返回对应值,不存在返回默认值-1
-     */
-    public long getLong(@NonNull final String key) {
-        return getLong(key, -1L);
-    }
-
-    /**
-     * SP 中读取 long
-     *
-     * @param key          键
-     * @param defaultValue 默认值
-     * @return 存在返回对应值,不存在返回默认值{@code defaultValue}
-     */
-    public long getLong(@NonNull final String key, final long defaultValue) {
-        return sp.getLong(key, defaultValue);
-    }
-
-    /**
-     * SP 中写入 float
-     *
-     * @param key   键
-     * @param value 值
-     */
-    public void put(@NonNull final String key, final float value) {
-        put(key, value, false);
-    }
-
-    /**
-     * SP 中写入 float
-     *
-     * @param key      键
-     * @param value    值
-     * @param isCommit {@code true}: {@link SharedPreferences.Editor#commit()}<br>
-     *                 {@code false}: {@link SharedPreferences.Editor#apply()}
-     */
-    public void put(@NonNull final String key, final float value, final boolean isCommit) {
-        if (isCommit) {
-            sp.edit().putFloat(key, value).commit();
-        } else {
-            sp.edit().putFloat(key, value).apply();
-        }
-    }
-
-    /**
-     * SP 中读取 float
-     *
-     * @param key 键
-     * @return 存在返回对应值,不存在返回默认值-1
-     */
-    public float getFloat(@NonNull final String key) {
-        return getFloat(key, -1f);
-    }
-
-    /**
-     * SP 中读取 float
-     *
-     * @param key          键
-     * @param defaultValue 默认值
-     * @return 存在返回对应值,不存在返回默认值{@code defaultValue}
-     */
-    public float getFloat(@NonNull final String key, final float defaultValue) {
-        return sp.getFloat(key, defaultValue);
-    }
-
-    /**
-     * SP 中写入 boolean
-     *
-     * @param key   键
-     * @param value 值
-     */
-    public void put(@NonNull final String key, final boolean value) {
-        put(key, value, false);
-    }
-
-    /**
-     * SP 中写入 boolean
-     *
-     * @param key      键
-     * @param value    值
-     * @param isCommit {@code true}: {@link SharedPreferences.Editor#commit()}<br>
-     *                 {@code false}: {@link SharedPreferences.Editor#apply()}
-     */
-    public void put(@NonNull final String key, final boolean value, final boolean isCommit) {
-        if (isCommit) {
-            sp.edit().putBoolean(key, value).commit();
-        } else {
-            sp.edit().putBoolean(key, value).apply();
-        }
-    }
-
-    /**
-     * SP 中读取 boolean
-     *
-     * @param key 键
-     * @return 存在返回对应值,不存在返回默认值{@code false}
-     */
-    public boolean getBoolean(@NonNull final String key) {
-        return getBoolean(key, false);
-    }
-
-    /**
-     * SP 中读取 boolean
-     *
-     * @param key          键
-     * @param defaultValue 默认值
-     * @return 存在返回对应值,不存在返回默认值{@code defaultValue}
-     */
-    public boolean getBoolean(@NonNull final String key, final boolean defaultValue) {
-        return sp.getBoolean(key, defaultValue);
-    }
-
-    /**
-     * SP 中写入 String 集合
-     *
-     * @param key    键
-     * @param values 值
-     */
-    public void put(@NonNull final String key, @NonNull final Set<String> values) {
-        put(key, values, false);
-    }
-
-    /**
-     * SP 中写入 String 集合
-     *
-     * @param key      键
-     * @param values   值
-     * @param isCommit {@code true}: {@link SharedPreferences.Editor#commit()}<br>
-     *                 {@code false}: {@link SharedPreferences.Editor#apply()}
-     */
-    public void put(@NonNull final String key,
-                    @NonNull final Set<String> values,
-                    final boolean isCommit) {
-        if (isCommit) {
-            sp.edit().putStringSet(key, values).commit();
-        } else {
-            sp.edit().putStringSet(key, values).apply();
-        }
-    }
-
-    /**
-     * SP 中读取 StringSet
-     *
-     * @param key 键
-     * @return 存在返回对应值,不存在返回默认值{@code Collections.<String>emptySet()}
-     */
-    public Set<String> getStringSet(@NonNull final String key) {
-        return getStringSet(key, Collections.<String>emptySet());
-    }
-
-    /**
-     * SP 中读取 StringSet
-     *
-     * @param key          键
-     * @param defaultValue 默认值
-     * @return 存在返回对应值,不存在返回默认值{@code defaultValue}
-     */
-    public Set<String> getStringSet(@NonNull final String key,
-                                    @NonNull final Set<String> defaultValue) {
-        return sp.getStringSet(key, defaultValue);
-    }
-
-    /**
-     * SP 中获取所有键值对
-     *
-     * @return Map 对象
-     */
-    public Map<String, ?> getAll() {
-        return sp.getAll();
-    }
-
-    /**
-     * SP 中是否存在该 key
-     *
-     * @param key 键
-     * @return {@code true}: 存在<br>{@code false}: 不存在
-     */
-    public boolean contains(@NonNull final String key) {
-        return sp.contains(key);
-    }
-
-    /**
-     * SP 中移除该 key
-     *
-     * @param key 键
-     */
-    public void remove(@NonNull final String key) {
-        remove(key, false);
-    }
-
-    /**
-     * SP 中移除该 key
-     *
-     * @param key      键
-     * @param isCommit {@code true}: {@link SharedPreferences.Editor#commit()}<br>
-     *                 {@code false}: {@link SharedPreferences.Editor#apply()}
-     */
-    public void remove(@NonNull final String key, final boolean isCommit) {
-        if (isCommit) {
-            sp.edit().remove(key).commit();
-        } else {
-            sp.edit().remove(key).apply();
-        }
-    }
-
-    /**
-     * SP 中清除所有数据
-     */
-    public void clear() {
-        clear(false);
-    }
-
-    /**
-     * SP 中清除所有数据
-     *
-     * @param isCommit {@code true}: {@link SharedPreferences.Editor#commit()}<br>
-     *                 {@code false}: {@link SharedPreferences.Editor#apply()}
-     */
-    public void clear(final boolean isCommit) {
-        if (isCommit) {
-            sp.edit().clear().commit();
-        } else {
-            sp.edit().clear().apply();
-        }
-    }
-
-    private static boolean isSpace(final String s) {
-        if (s == null) return true;
-        for (int i = 0, len = s.length(); i < len; ++i) {
-            if (!Character.isWhitespace(s.charAt(i))) {
-                return false;
-            }
-        }
-        return true;
-    }
-}

+ 4 - 3
VideoPlayer/src/main/java/com/yc/video/bridge/ControlWrapper.java

@@ -35,10 +35,11 @@ import com.yc.video.player.InterVideoPlayer;
  */
 public class ControlWrapper implements InterVideoPlayer, InterVideoController {
     
-    private InterVideoPlayer mVideoPlayer;
-    private InterVideoController mController;
+    private final InterVideoPlayer mVideoPlayer;
+    private final InterVideoController mController;
     
-    public ControlWrapper(@NonNull InterVideoPlayer videoPlayer, @NonNull InterVideoController controller) {
+    public ControlWrapper(@NonNull InterVideoPlayer videoPlayer,
+                          @NonNull InterVideoController controller) {
         mVideoPlayer = videoPlayer;
         mController = controller;
     }

+ 7 - 2
VideoSqlLite/src/main/java/com/yc/videosqllite/disk/DiskLruCache.java

@@ -112,9 +112,14 @@ public final class DiskLruCache implements Closeable {
     /**
      * 该缓存使用单个后台线程来清除条目
      */
-    final ThreadPoolExecutor executorService =
-            new ThreadPoolExecutor(0, 1, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(),
+    final ThreadPoolExecutor executorService = new ThreadPoolExecutor(
+            0, 1, 60L,
+                    TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(),
                     new DiskLruCacheThreadFactory());
+
+    /**
+     * 创建清除callable
+     */
     private final Callable<Void> cleanupCallable = new Callable<Void>() {
         public Void call() throws Exception {
             synchronized (DiskLruCache.this) {

+ 45 - 0
VideoTool/src/main/java/com/yc/videotool/ScheduleTask.java

@@ -0,0 +1,45 @@
+package com.yc.videotool;
+
+import androidx.annotation.NonNull;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+
+/**
+ * <pre>
+ *     @author yangchong
+ *     blog  : https://github.com/yangchong211
+ *     time  : 2017/10/21
+ *     desc  : 线程工具类
+ *     revise:
+ * </pre>
+ */
+public class ScheduleTask {
+
+    private final ExecutorService mExecutors;
+
+    private ScheduleTask() {
+        this.mExecutors = Executors.newSingleThreadExecutor(new ThreadFactory() {
+            public Thread newThread(@NonNull Runnable r) {
+                return new Thread(r, "ScheduleTask");
+            }
+        });
+    }
+
+    public static ScheduleTask getInstance() {
+        return ScheduleTask.Holder.INSTANCE;
+    }
+
+    public void schedule(Runnable runnable) {
+        this.mExecutors.execute(runnable);
+    }
+
+    private static class Holder {
+        private static final ScheduleTask INSTANCE = new ScheduleTask();
+
+        private Holder() {
+        }
+    }
+
+}

+ 30 - 4
VideoTool/src/main/java/com/yc/videotool/VideoLogUtils.java

@@ -43,20 +43,42 @@ public final class VideoLogUtils {
         return isLog;
     }
 
+    /**
+     * Log.v 的输出颜色为黑色的,输出大于或等于VERBOSE日志级别的信息,也就是可见级别,一般是最低的信息提示
+     * @param message                       message
+     */
+    public static void v(String message) {
+        if(isLog){
+            Log.v(TAG, message);
+        }
+    }
+
+    /**
+     * Log.d的输出颜色是蓝色的,也就是调式级别,一般不会中止程序,一般是程序员为了调试而打印的log
+     * @param message                       message
+     */
     public static void d(String message) {
         if(isLog){
             Log.d(TAG, message);
         }
     }
 
-    public static void d(Object object){
+    /**
+     * Log.d的输出颜色是蓝色的,也就是调式级别,一般不会中止程序,一般是程序员为了调试而打印的log
+     * @param message                       message
+     */
+    public static void d(Object message){
         if(isLog){
             //这个方法 建议 Debug 进入不执行,因为 object 会进行字符串+拼接,产生大量内存对象。
             //Log.d(TAG, object.toString());
-            Log.d(TAG, " log : " + object);
+            Log.d(TAG, " log : " + message);
         }
     }
 
+    /**
+     * Log.i的输出为绿色,输出大于或等于INFO日志级别的信息,也就是信息界级别,不会中止程序,一般是系统中执行操作的信息提示
+     * @param message                       message
+     */
     public static void i(String message) {
         if(isLog){
             Log.i(TAG, message);
@@ -64,9 +86,13 @@ public final class VideoLogUtils {
 
     }
 
-    public static void e(String msg) {
+    /**
+     * Log.e的输出为红色,仅输出ERROR日志级别的信息,也就是错误级别,一般会中止程序运行,是最严重的Log级别。
+     * @param message                       message
+     */
+    public static void e(String message) {
         if (isLog) {
-            Log.e(TAG, msg);
+            Log.e(TAG, message);
         }
     }
 

+ 11 - 11
VideoTool/src/main/java/com/yc/videotool/MusicSpUtils.java → VideoTool/src/main/java/com/yc/videotool/VideoSpUtils.java

@@ -14,11 +14,11 @@ import java.util.Set;
 
 
 @SuppressLint("ApplySharedPref")
-public final class MusicSpUtils {
+public final class VideoSpUtils {
 
-    private static SimpleArrayMap<String, MusicSpUtils> SP_UTILS_MAP = new SimpleArrayMap<>();
-    private SharedPreferences sp;
-    private static Context context;
+    private static final SimpleArrayMap<String, VideoSpUtils> SP_UTILS_MAP = new SimpleArrayMap<>();
+    private final SharedPreferences sp;
+    private static Application context;
 
     public static void init(Application application){
         context = application;
@@ -27,9 +27,9 @@ public final class MusicSpUtils {
     /**
      * 获取 SP 实例
      *
-     * @return {@link MusicSpUtils}
+     * @return {@link VideoSpUtils}
      */
-    public static MusicSpUtils getInstance() {
+    public static VideoSpUtils getInstance() {
         return getInstance("");
     }
 
@@ -37,19 +37,19 @@ public final class MusicSpUtils {
      * 获取 SP 实例
      *
      * @param spName sp 名
-     * @return {@link MusicSpUtils}
+     * @return {@link VideoSpUtils}
      */
-    public static MusicSpUtils getInstance(String spName) {
+    public static VideoSpUtils getInstance(String spName) {
         if (isSpace(spName)) spName = "spUtils";
-        MusicSpUtils spUtils = SP_UTILS_MAP.get(spName);
+        VideoSpUtils spUtils = SP_UTILS_MAP.get(spName);
         if (spUtils == null) {
-            spUtils = new MusicSpUtils(spName);
+            spUtils = new VideoSpUtils(spName);
             SP_UTILS_MAP.put(spName, spUtils);
         }
         return spUtils;
     }
 
-    private MusicSpUtils(final String spName) {
+    private VideoSpUtils(final String spName) {
         sp = context.getSharedPreferences(spName, Context.MODE_PRIVATE);
     }
 

+ 1 - 1
VideoTool/src/main/java/com/yc/videotool/ClickUtils.java → VideoTool/src/main/java/com/yc/videotool/ViewClickUtils.java

@@ -14,7 +14,7 @@ import java.util.HashMap;
  *     revise:
  * </pre>
  */
-public final class ClickUtils {
+public final class ViewClickUtils {
 
     /**
      * 默认最大点击间隔时间