diff --git a/build.gradle b/build.gradle index 8ccd9c97..e67216e1 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,16 @@ buildscript { repositories { - jcenter() + google() + mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.1' + classpath 'com.android.tools.build:gradle:7.0.4' } } allprojects { - repositories { - jcenter() + repositories { + google() + mavenCentral() } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3c115268..d43a1018 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Apr 18 11:58:38 MSK 2017 +#Wed May 11 11:59:53 NPT 2022 distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +zipStoreBase=GRADLE_USER_HOME diff --git a/library/build.gradle b/library/build.gradle index 15dbe3df..8b85edf1 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,23 +1,22 @@ buildscript { repositories { - jcenter() + google() + mavenCentral() } dependencies { - classpath 'com.novoda:bintray-release:0.4.0' } } apply plugin: 'com.android.library' apply plugin: 'idea' -apply plugin: 'bintray-release' +apply plugin: 'maven-publish' android { - compileSdkVersion 23 - buildToolsVersion '25.0.2' + compileSdkVersion 31 defaultConfig { - minSdkVersion 9 - targetSdkVersion 23 + minSdkVersion 21 + targetSdkVersion 31 versionCode 22 versionName '2.7.1' } @@ -36,14 +35,14 @@ idea { } dependencies { - compile 'org.slf4j:slf4j-android:1.7.21' } -publish { - userOrg = 'alexeydanilov' - groupId = 'com.danikula' - artifactId = 'videocache' - publishVersion = android.defaultConfig.versionName - description = 'Cache support for android VideoView' - website = 'https://github.com/danikula/AndroidVideoCache' -} +publishing { + publications { + maven(MavenPublication) { + groupId = 'com.danikula' + artifactId = 'videocache' + version = '2.8.0' + } + } +} \ No newline at end of file diff --git a/library/src/main/java/com/danikula/videocache/HttpProxyCacheServer.java b/library/src/main/java/com/danikula/videocache/HttpProxyCacheServer.java index 1f34ae8f..832a8cd2 100644 --- a/library/src/main/java/com/danikula/videocache/HttpProxyCacheServer.java +++ b/library/src/main/java/com/danikula/videocache/HttpProxyCacheServer.java @@ -13,8 +13,7 @@ import com.danikula.videocache.sourcestorage.SourceInfoStorage; import com.danikula.videocache.sourcestorage.SourceInfoStorageFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + import java.io.File; import java.io.IOException; @@ -53,7 +52,7 @@ */ public class HttpProxyCacheServer { - private static final Logger LOG = LoggerFactory.getLogger("HttpProxyCacheServer"); + // private static final Logger LOG = LoggerFactory.getLogger("HttpProxyCacheServer"); private static final String PROXY_HOST = "127.0.0.1"; private final Object clientsLock = new Object(); @@ -81,7 +80,7 @@ private HttpProxyCacheServer(Config config) { this.waitConnectionThread.start(); startSignal.await(); // freeze thread, wait for server starts this.pinger = new Pinger(PROXY_HOST, port); - LOG.info("Proxy cache server started. Is it alive? " + isAlive()); + // Log.info("Proxy cache server started. Is it alive? " + isAlive()); } catch (IOException | InterruptedException e) { socketProcessor.shutdown(); throw new IllegalStateException("Error starting local proxy server", e); @@ -128,7 +127,7 @@ public void registerCacheListener(CacheListener cacheListener, String url) { try { getClients(url).registerCacheListener(cacheListener); } catch (ProxyCacheException e) { - LOG.warn("Error registering cache listener", e); + // Log.warn("Error registering cache listener", e); } } } @@ -139,7 +138,7 @@ public void unregisterCacheListener(CacheListener cacheListener, String url) { try { getClients(url).unregisterCacheListener(cacheListener); } catch (ProxyCacheException e) { - LOG.warn("Error registering cache listener", e); + // Log.warn("Error registering cache listener", e); } } } @@ -165,7 +164,7 @@ public boolean isCached(String url) { } public void shutdown() { - LOG.info("Shutdown proxy server"); + // Log.info("Shutdown proxy server"); shutdownClients(); @@ -199,7 +198,7 @@ private void touchFileSafely(File cacheFile) { try { config.diskUsage.touch(cacheFile); } catch (IOException e) { - LOG.error("Error touching file " + cacheFile, e); + // Log.error("Error touching file " + cacheFile, e); } } @@ -216,7 +215,7 @@ private void waitForRequest() { try { while (!Thread.currentThread().isInterrupted()) { Socket socket = serverSocket.accept(); - LOG.debug("Accept new socket " + socket); + // Log.debug("Accept new socket " + socket); socketProcessor.submit(new SocketProcessorRunnable(socket)); } } catch (IOException e) { @@ -227,7 +226,7 @@ private void waitForRequest() { private void processSocket(Socket socket) { try { GetRequest request = GetRequest.read(socket.getInputStream()); - LOG.debug("Request to cache proxy:" + request); + // Log.debug("Request to cache proxy:" + request); String url = ProxyCacheUtils.decode(request.uri); if (pinger.isPingRequest(url)) { pinger.responseToPing(socket); @@ -238,12 +237,12 @@ private void processSocket(Socket socket) { } catch (SocketException e) { // There is no way to determine that client closed connection http://stackoverflow.com/a/10241044/999458 // So just to prevent log flooding don't log stacktrace - LOG.debug("Closing socket… Socket is closed by client."); + // Log.debug("Closing socket… Socket is closed by client."); } catch (ProxyCacheException | IOException e) { onError(new ProxyCacheException("Error processing request", e)); } finally { releaseSocket(socket); - LOG.debug("Opened connections: " + getClientsCount()); + // Log.debug("Opened connections: " + getClientsCount()); } } @@ -282,7 +281,7 @@ private void closeSocketInput(Socket socket) { } catch (SocketException e) { // There is no way to determine that client closed connection http://stackoverflow.com/a/10241044/999458 // So just to prevent log flooding don't log stacktrace - LOG.debug("Releasing input stream… Socket is closed by client."); + // Log.debug("Releasing input stream… Socket is closed by client."); } catch (IOException e) { onError(new ProxyCacheException("Error closing socket input stream", e)); } @@ -294,7 +293,7 @@ private void closeSocketOutput(Socket socket) { socket.shutdownOutput(); } } catch (IOException e) { - LOG.warn("Failed to close socket on proxy side: {}. It seems client have already closed connection.", e.getMessage()); + // Log.warn("Failed to close socket on proxy side: {}. It seems client have already closed connection.", e.getMessage()); } } @@ -309,7 +308,7 @@ private void closeSocket(Socket socket) { } private void onError(Throwable e) { - LOG.error("HttpProxyCacheServer error", e); + // Log.error("HttpProxyCacheServer error", e); } private final class WaitRequestsRunnable implements Runnable { diff --git a/library/src/main/java/com/danikula/videocache/HttpUrlSource.java b/library/src/main/java/com/danikula/videocache/HttpUrlSource.java index c7fb8ada..9d581f4b 100644 --- a/library/src/main/java/com/danikula/videocache/HttpUrlSource.java +++ b/library/src/main/java/com/danikula/videocache/HttpUrlSource.java @@ -7,8 +7,7 @@ import com.danikula.videocache.sourcestorage.SourceInfoStorage; import com.danikula.videocache.sourcestorage.SourceInfoStorageFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + import java.io.BufferedInputStream; import java.io.IOException; @@ -33,7 +32,7 @@ */ public class HttpUrlSource implements Source { - private static final Logger LOG = LoggerFactory.getLogger("HttpUrlSource"); + // // private static final Logger LOG = LoggerFactory.getLogger("HttpUrlSource"); private static final int MAX_REDIRECTS = 5; private final SourceInfoStorage sourceInfoStorage; @@ -109,9 +108,9 @@ public void close() throws ProxyCacheException { "https://github.com/danikula/AndroidVideoCache/issues."; throw new RuntimeException(message, e); } catch (ArrayIndexOutOfBoundsException e) { - LOG.error("Error closing connection correctly. Should happen only on Android L. " + - "If anybody know how to fix it, please visit https://github.com/danikula/AndroidVideoCache/issues/88. " + - "Until good solution is not know, just ignore this issue :(", e); + // Log.error("Error closing connection correctly. Should happen only on Android L. " + + // "If anybody know how to fix it, please visit https://github.com/danikula/AndroidVideoCache/issues/88. " + + // "Until good solution is not know, just ignore this issue :(", e); } } } @@ -131,7 +130,7 @@ public int read(byte[] buffer) throws ProxyCacheException { } private void fetchContentInfo() throws ProxyCacheException { - LOG.debug("Read content info from " + sourceInfo.url); + // Log.debug("Read content info from " + sourceInfo.url); HttpURLConnection urlConnection = null; InputStream inputStream = null; try { @@ -141,9 +140,9 @@ private void fetchContentInfo() throws ProxyCacheException { inputStream = urlConnection.getInputStream(); this.sourceInfo = new SourceInfo(sourceInfo.url, length, mime); this.sourceInfoStorage.put(sourceInfo.url, sourceInfo); - LOG.debug("Source info fetched: " + sourceInfo); + // Log.debug("Source info fetched: " + sourceInfo); } catch (IOException e) { - LOG.error("Error fetching info from " + sourceInfo.url, e); + // Log.error("Error fetching info from " + sourceInfo.url, e); } finally { ProxyCacheUtils.close(inputStream); if (urlConnection != null) { @@ -158,7 +157,7 @@ private HttpURLConnection openConnection(long offset, int timeout) throws IOExce int redirectCount = 0; String url = this.sourceInfo.url; do { - LOG.debug("Open connection " + (offset > 0 ? " with offset " + offset : "") + " to " + url); + // Log.debug("Open connection " + (offset > 0 ? " with offset " + offset : "") + " to " + url); connection = (HttpURLConnection) new URL(url).openConnection(); injectCustomHeaders(connection, url); if (offset > 0) { diff --git a/library/src/main/java/com/danikula/videocache/Pinger.java b/library/src/main/java/com/danikula/videocache/Pinger.java index bea87f23..0628eae7 100644 --- a/library/src/main/java/com/danikula/videocache/Pinger.java +++ b/library/src/main/java/com/danikula/videocache/Pinger.java @@ -1,7 +1,6 @@ package com.danikula.videocache; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + import java.io.IOException; import java.io.OutputStream; @@ -32,7 +31,7 @@ class Pinger { - private static final Logger LOG = LoggerFactory.getLogger("Pinger"); + // private static final Logger LOG = LoggerFactory.getLogger("Pinger"); private static final String PING_REQUEST = "ping"; private static final String PING_RESPONSE = "ping ok"; @@ -59,9 +58,9 @@ boolean ping(int maxAttempts, int startTimeout) { return true; } } catch (TimeoutException e) { - LOG.warn("Error pinging server (attempt: " + attempts + ", timeout: " + timeout + "). "); + // Log.warn("Error pinging server (attempt: " + attempts + ", timeout: " + timeout + "). "); } catch (InterruptedException | ExecutionException e) { - LOG.error("Error pinging server due to unexpected error", e); + // Log.error("Error pinging server due to unexpected error", e); } attempts++; timeout *= 2; @@ -70,7 +69,7 @@ boolean ping(int maxAttempts, int startTimeout) { "If you see this message, please, report at https://github.com/danikula/AndroidVideoCache/issues/134. " + "Default proxies are: %s" , attempts, timeout / 2, getDefaultProxies()); - LOG.error(error, new ProxyCacheException(error)); + // Log.error(error, new ProxyCacheException(error)); return false; } @@ -102,10 +101,10 @@ private boolean pingServer() throws ProxyCacheException { byte[] response = new byte[expectedResponse.length]; source.read(response); boolean pingOk = Arrays.equals(expectedResponse, response); - LOG.info("Ping response: `" + new String(response) + "`, pinged? " + pingOk); + // Log.info("Ping response: `" + new String(response) + "`, pinged? " + pingOk); return pingOk; } catch (ProxyCacheException e) { - LOG.error("Error reading ping response", e); + // Log.error("Error reading ping response", e); return false; } finally { source.close(); diff --git a/library/src/main/java/com/danikula/videocache/ProxyCache.java b/library/src/main/java/com/danikula/videocache/ProxyCache.java index eeea9713..c4cde10c 100644 --- a/library/src/main/java/com/danikula/videocache/ProxyCache.java +++ b/library/src/main/java/com/danikula/videocache/ProxyCache.java @@ -1,7 +1,6 @@ package com.danikula.videocache; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + import java.util.concurrent.atomic.AtomicInteger; @@ -18,7 +17,7 @@ */ class ProxyCache { - private static final Logger LOG = LoggerFactory.getLogger("ProxyCache"); + // private static final Logger LOG = LoggerFactory.getLogger("ProxyCache"); private static final int MAX_READ_SOURCE_ATTEMPTS = 1; private final Source source; @@ -62,7 +61,7 @@ private void checkReadSourceErrorsCount() throws ProxyCacheException { public void shutdown() { synchronized (stopLock) { - LOG.debug("Shutdown proxy for " + source); + // Log.debug("Shutdown proxy for " + source); try { stopped = true; if (sourceReaderThread != null) { @@ -174,9 +173,9 @@ private void closeSource() { protected final void onError(final Throwable e) { boolean interruption = e instanceof InterruptedProxyCacheException; if (interruption) { - LOG.debug("ProxyCache is interrupted"); + // Log.debug("ProxyCache is interrupted"); } else { - LOG.error("ProxyCache error", e); + // Log.error("ProxyCache error", e); } } diff --git a/library/src/main/java/com/danikula/videocache/ProxyCacheException.java b/library/src/main/java/com/danikula/videocache/ProxyCacheException.java index af13246d..0af8a0f3 100644 --- a/library/src/main/java/com/danikula/videocache/ProxyCacheException.java +++ b/library/src/main/java/com/danikula/videocache/ProxyCacheException.java @@ -7,7 +7,7 @@ */ public class ProxyCacheException extends Exception { - private static final String LIBRARY_VERSION = ". Version: " + BuildConfig.VERSION_NAME; + private static final String LIBRARY_VERSION = ". Version: " + BuildConfig.LIBRARY_PACKAGE_NAME; public ProxyCacheException(String message) { super(message + LIBRARY_VERSION); diff --git a/library/src/main/java/com/danikula/videocache/ProxyCacheUtils.java b/library/src/main/java/com/danikula/videocache/ProxyCacheUtils.java index 7e26a2b2..43ccf5b7 100644 --- a/library/src/main/java/com/danikula/videocache/ProxyCacheUtils.java +++ b/library/src/main/java/com/danikula/videocache/ProxyCacheUtils.java @@ -3,8 +3,7 @@ import android.text.TextUtils; import android.webkit.MimeTypeMap; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + import java.io.Closeable; import java.io.IOException; @@ -25,7 +24,7 @@ */ public class ProxyCacheUtils { - private static final Logger LOG = LoggerFactory.getLogger("ProxyCacheUtils"); + // private static final Logger LOG = LoggerFactory.getLogger("ProxyCacheUtils"); static final int DEFAULT_BUFFER_SIZE = 8 * 1024; static final int MAX_ARRAY_PREVIEW = 16; @@ -72,7 +71,7 @@ static void close(Closeable closeable) { try { closeable.close(); } catch (IOException e) { - LOG.error("Error closing resource", e); + // Log.error("Error closing resource", e); } } } diff --git a/library/src/main/java/com/danikula/videocache/StorageUtils.java b/library/src/main/java/com/danikula/videocache/StorageUtils.java index a4f2dcef..3adb68b6 100644 --- a/library/src/main/java/com/danikula/videocache/StorageUtils.java +++ b/library/src/main/java/com/danikula/videocache/StorageUtils.java @@ -3,8 +3,7 @@ import android.content.Context; import android.os.Environment; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + import java.io.File; @@ -20,7 +19,7 @@ */ final class StorageUtils { - private static final Logger LOG = LoggerFactory.getLogger("StorageUtils"); + // private static final Logger LOG = LoggerFactory.getLogger("StorageUtils"); private static final String INDIVIDUAL_DIR_NAME = "video-cache"; /** @@ -63,7 +62,7 @@ private static File getCacheDirectory(Context context, boolean preferExternal) { } if (appCacheDir == null) { String cacheDirPath = "/data/data/" + context.getPackageName() + "/cache/"; - LOG.warn("Can't define system cache directory! '" + cacheDirPath + "%s' will be used."); + // Log.warn("Can't define system cache directory! '" + cacheDirPath + "%s' will be used."); appCacheDir = new File(cacheDirPath); } return appCacheDir; @@ -74,7 +73,7 @@ private static File getExternalCacheDir(Context context) { File appCacheDir = new File(new File(dataDir, context.getPackageName()), "cache"); if (!appCacheDir.exists()) { if (!appCacheDir.mkdirs()) { - LOG.warn("Unable to create external cache directory"); + // Log.warn("Unable to create external cache directory"); return null; } } diff --git a/library/src/main/java/com/danikula/videocache/file/Files.java b/library/src/main/java/com/danikula/videocache/file/Files.java index 5f5234a5..0967f979 100644 --- a/library/src/main/java/com/danikula/videocache/file/Files.java +++ b/library/src/main/java/com/danikula/videocache/file/Files.java @@ -1,7 +1,6 @@ package com.danikula.videocache.file; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + import java.io.File; import java.io.IOException; @@ -20,7 +19,7 @@ */ class Files { - private static final Logger LOG = LoggerFactory.getLogger("Files"); + // private static final Logger LOG = LoggerFactory.getLogger("Files"); static void makeDir(File directory) throws IOException { if (directory.exists()) { @@ -53,7 +52,7 @@ static void setLastModifiedNow(File file) throws IOException { modify(file); if (file.lastModified() < now) { // NOTE: apparently this is a known issue (see: http://stackoverflow.com/questions/6633748/file-lastmodified-is-never-what-was-set-with-file-setlastmodified) - LOG.warn("Last modified date {} is not set for file {}", new Date(file.lastModified()), file.getAbsolutePath()); + // Log.warn("Last modified date {} is not set for file {}", new Date(file.lastModified()), file.getAbsolutePath()); } } } diff --git a/library/src/main/java/com/danikula/videocache/file/LruDiskUsage.java b/library/src/main/java/com/danikula/videocache/file/LruDiskUsage.java index 0b0b03ad..16d277c2 100644 --- a/library/src/main/java/com/danikula/videocache/file/LruDiskUsage.java +++ b/library/src/main/java/com/danikula/videocache/file/LruDiskUsage.java @@ -1,7 +1,6 @@ package com.danikula.videocache.file; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + import java.io.File; import java.io.IOException; @@ -17,7 +16,7 @@ */ public abstract class LruDiskUsage implements DiskUsage { - private static final Logger LOG = LoggerFactory.getLogger("LruDiskUsage"); + // private static final Logger LOG = LoggerFactory.getLogger("LruDiskUsage"); private final ExecutorService workerThread = Executors.newSingleThreadExecutor(); @Override @@ -44,9 +43,9 @@ private void trim(List files) { if (deleted) { totalCount--; totalSize -= fileSize; - LOG.info("Cache file " + file + " is deleted because it exceeds cache limit"); + // Log.info("Cache file " + file + " is deleted because it exceeds cache limit"); } else { - LOG.error("Error deleting file " + file + " for trimming cache"); + // Log.error("Error deleting file " + file + " for trimming cache"); } } } diff --git a/sample/build.gradle b/sample/build.gradle deleted file mode 100644 index 2e337905..00000000 --- a/sample/build.gradle +++ /dev/null @@ -1,44 +0,0 @@ -buildscript { - repositories { - jcenter() - } - dependencies { - classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4' - } -} - -repositories { - maven { url 'https://github.com/dahlgren/vpi-aar/raw/master' } -} - -apply plugin: 'com.android.application' -apply plugin: 'com.neenbedankt.android-apt' - -android { - compileSdkVersion 23 - buildToolsVersion '25.0.2' - - defaultConfig { - applicationId 'com.danikula.videocache.sample' - minSdkVersion 15 - targetSdkVersion 23 - versionCode 1 - versionName '1.0' - } -} - -apt { - arguments { - androidManifestFile variant.outputs[0].processResources.manifestFile - resourcePackageName android.defaultConfig.applicationId - } -} - -dependencies { -// compile project(':library') - compile 'com.android.support:support-v4:23.1.0' - compile 'org.androidannotations:androidannotations-api:3.3.2' - compile 'com.danikula:videocache:2.7.1' - compile 'com.viewpagerindicator:library:2.4.2-SNAPSHOT@aar' - apt 'org.androidannotations:androidannotations:3.3.2' -} diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml deleted file mode 100644 index 3ba1f44d..00000000 --- a/sample/src/main/AndroidManifest.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/sample/src/main/java/com/danikula/videocache/sample/App.java b/sample/src/main/java/com/danikula/videocache/sample/App.java deleted file mode 100644 index 095469d9..00000000 --- a/sample/src/main/java/com/danikula/videocache/sample/App.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.danikula.videocache.sample; - -import android.app.Application; -import android.content.Context; - -import com.danikula.videocache.HttpProxyCacheServer; - -/** - * @author Alexey Danilov (danikula@gmail.com). - */ -public class App extends Application { - - private HttpProxyCacheServer proxy; - - public static HttpProxyCacheServer getProxy(Context context) { - App app = (App) context.getApplicationContext(); - return app.proxy == null ? (app.proxy = app.newProxy()) : app.proxy; - } - - private HttpProxyCacheServer newProxy() { - return new HttpProxyCacheServer.Builder(this) - .cacheDirectory(Utils.getVideoCacheDir(this)) - .build(); - } -} diff --git a/sample/src/main/java/com/danikula/videocache/sample/GalleryVideoFragment.java b/sample/src/main/java/com/danikula/videocache/sample/GalleryVideoFragment.java deleted file mode 100644 index 94a79ca0..00000000 --- a/sample/src/main/java/com/danikula/videocache/sample/GalleryVideoFragment.java +++ /dev/null @@ -1,130 +0,0 @@ -package com.danikula.videocache.sample; - -import android.os.Handler; -import android.os.Message; -import android.support.v4.app.Fragment; -import android.widget.ProgressBar; -import android.widget.VideoView; - -import com.danikula.videocache.CacheListener; -import com.danikula.videocache.HttpProxyCacheServer; - -import org.androidannotations.annotations.AfterViews; -import org.androidannotations.annotations.EFragment; -import org.androidannotations.annotations.FragmentArg; -import org.androidannotations.annotations.InstanceState; -import org.androidannotations.annotations.SeekBarTouchStop; -import org.androidannotations.annotations.ViewById; - -import java.io.File; - -@EFragment(R.layout.fragment_video) -public class GalleryVideoFragment extends Fragment implements CacheListener { - - @FragmentArg String url; - - @InstanceState int position; - @InstanceState boolean playerStarted; - - @ViewById VideoView videoView; - @ViewById ProgressBar progressBar; - - private boolean visibleForUser; - - private final VideoProgressUpdater updater = new VideoProgressUpdater(); - - public static Fragment build(String url) { - return GalleryVideoFragment_.builder() - .url(url) - .build(); - } - - @AfterViews - void afterViewInjected() { - startProxy(); - - if (visibleForUser) { - startPlayer(); - } - } - - private void startPlayer() { - videoView.seekTo(position); - videoView.start(); - playerStarted = true; - } - - private void startProxy() { - HttpProxyCacheServer proxy = App.getProxy(getActivity()); - proxy.registerCacheListener(this, url); - videoView.setVideoPath(proxy.getProxyUrl(url)); - } - - @Override - public void setUserVisibleHint(boolean isVisibleToUser) { - super.setUserVisibleHint(isVisibleToUser); - - visibleForUser = isVisibleToUser; - if (videoView != null) { - if (visibleForUser) { - startPlayer(); - } else if (playerStarted) { - position = videoView.getCurrentPosition(); - videoView.pause(); - } - } - } - - @Override - public void onResume() { - super.onResume(); - updater.start(); - } - - @Override - public void onPause() { - super.onPause(); - updater.stop(); - } - - @Override - public void onDestroy() { - super.onDestroy(); - - videoView.stopPlayback(); - App.getProxy(getActivity()).unregisterCacheListener(this); - } - - @Override - public void onCacheAvailable(File file, String url, int percentsAvailable) { - progressBar.setSecondaryProgress(percentsAvailable); - } - - private void updateVideoProgress() { - int videoProgress = videoView.getCurrentPosition() * 100 / videoView.getDuration(); - progressBar.setProgress(videoProgress); - } - - @SeekBarTouchStop(R.id.progressBar) - void seekVideo() { - int videoPosition = videoView.getDuration() * progressBar.getProgress() / 100; - videoView.seekTo(videoPosition); - } - - private final class VideoProgressUpdater extends Handler { - - public void start() { - sendEmptyMessage(0); - } - - public void stop() { - removeMessages(0); - } - - @Override - public void handleMessage(Message msg) { - updateVideoProgress(); - sendEmptyMessageDelayed(0, 500); - } - } -} diff --git a/sample/src/main/java/com/danikula/videocache/sample/MenuActivity.java b/sample/src/main/java/com/danikula/videocache/sample/MenuActivity.java deleted file mode 100644 index 353ab4e8..00000000 --- a/sample/src/main/java/com/danikula/videocache/sample/MenuActivity.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.danikula.videocache.sample; - -import android.content.Intent; -import android.support.annotation.NonNull; -import android.support.v4.app.FragmentActivity; -import android.util.Log; -import android.widget.ArrayAdapter; -import android.widget.ListAdapter; -import android.widget.ListView; -import android.widget.Toast; - -import org.androidannotations.annotations.AfterViews; -import org.androidannotations.annotations.Click; -import org.androidannotations.annotations.EActivity; -import org.androidannotations.annotations.ItemClick; -import org.androidannotations.annotations.ViewById; - -import java.io.IOException; -import java.util.Arrays; -import java.util.List; - -@EActivity(R.layout.activity_menu) -public class MenuActivity extends FragmentActivity { - - @ViewById ListView listView; - - @AfterViews - void onViewInjected() { - ListAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, android.R.id.text1, buildListData()); - listView.setAdapter(adapter); - } - - @NonNull - private List buildListData() { - return Arrays.asList( - new ListEntry("Single Video", SingleVideoActivity_.class), - new ListEntry("Multiple Videos", MultipleVideosActivity_.class), - new ListEntry("Video Gallery with pre-caching", VideoGalleryActivity_.class), - new ListEntry("Shared Cache", SharedCacheActivity_.class) - ); - } - - @ItemClick(R.id.listView) - void onListItemClicked(int position) { - ListEntry item = (ListEntry) listView.getAdapter().getItem(position); - startActivity(new Intent(this, item.activityClass)); - } - - @Click(R.id.cleanCacheButton) - void onClearCacheButtonClick() { - try { - - Utils.cleanVideoCacheDir(this); - } catch (IOException e) { - Log.e(null, "Error cleaning cache", e); - Toast.makeText(this, "Error cleaning cache", Toast.LENGTH_LONG).show(); - } - } - - private static final class ListEntry { - - private final String title; - private final Class activityClass; - - public ListEntry(String title, Class activityClass) { - this.title = title; - this.activityClass = activityClass; - } - - @Override - public String toString() { - return title; - } - } - -} diff --git a/sample/src/main/java/com/danikula/videocache/sample/MultipleVideosActivity.java b/sample/src/main/java/com/danikula/videocache/sample/MultipleVideosActivity.java deleted file mode 100644 index d27dd12a..00000000 --- a/sample/src/main/java/com/danikula/videocache/sample/MultipleVideosActivity.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.danikula.videocache.sample; - -import android.os.Bundle; -import android.support.v4.app.FragmentActivity; - -import org.androidannotations.annotations.EActivity; - -@EActivity(R.layout.activity_multiple_videos) -public class MultipleVideosActivity extends FragmentActivity { - - @Override - protected void onCreate(Bundle state) { - super.onCreate(state); - - if (state == null) { - addVideoFragment(Video.ORANGE_1, R.id.videoContainer0); - addVideoFragment(Video.ORANGE_2, R.id.videoContainer1); - addVideoFragment(Video.ORANGE_3, R.id.videoContainer2); - addVideoFragment(Video.ORANGE_4, R.id.videoContainer3); - } - } - - private void addVideoFragment(Video video, int containerViewId) { - getSupportFragmentManager() - .beginTransaction() - .add(containerViewId, VideoFragment.build(video.url)) - .commit(); - } -} diff --git a/sample/src/main/java/com/danikula/videocache/sample/SharedCacheActivity.java b/sample/src/main/java/com/danikula/videocache/sample/SharedCacheActivity.java deleted file mode 100644 index 80ca82c9..00000000 --- a/sample/src/main/java/com/danikula/videocache/sample/SharedCacheActivity.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.danikula.videocache.sample; - -import android.os.Bundle; -import android.support.v4.app.FragmentActivity; - -import org.androidannotations.annotations.EActivity; - -@EActivity(R.layout.activity_multiple_videos) -public class SharedCacheActivity extends FragmentActivity { - - @Override - protected void onCreate(Bundle state) { - super.onCreate(state); - - if (state == null) { - addVideoFragment(Video.ORANGE_1, R.id.videoContainer0); - addVideoFragment(Video.ORANGE_1, R.id.videoContainer1); - addVideoFragment(Video.ORANGE_1, R.id.videoContainer2); - addVideoFragment(Video.ORANGE_1, R.id.videoContainer3); - } - } - - private void addVideoFragment(Video video, int containerViewId) { - getSupportFragmentManager() - .beginTransaction() - .add(containerViewId, VideoFragment.build(video.url)) - .commit(); - } -} diff --git a/sample/src/main/java/com/danikula/videocache/sample/SingleVideoActivity.java b/sample/src/main/java/com/danikula/videocache/sample/SingleVideoActivity.java deleted file mode 100644 index 2ecbe562..00000000 --- a/sample/src/main/java/com/danikula/videocache/sample/SingleVideoActivity.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.danikula.videocache.sample; - -import android.os.Bundle; -import android.support.v4.app.FragmentActivity; - -import org.androidannotations.annotations.EActivity; - -@EActivity(R.layout.activity_single_video) -public class SingleVideoActivity extends FragmentActivity { - - @Override - protected void onCreate(Bundle state) { - super.onCreate(state); - - if (state == null) { - getSupportFragmentManager() - .beginTransaction() - .add(R.id.containerView, VideoFragment.build(Video.ORANGE_1.url)) - .commit(); - } - } -} diff --git a/sample/src/main/java/com/danikula/videocache/sample/Utils.java b/sample/src/main/java/com/danikula/videocache/sample/Utils.java deleted file mode 100644 index 43779832..00000000 --- a/sample/src/main/java/com/danikula/videocache/sample/Utils.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.danikula.videocache.sample; - -import android.content.Context; - -import java.io.File; -import java.io.IOException; - -/** - * Some utils methods. - * - * @author Alexey Danilov (danikula@gmail.com). - */ -public class Utils { - - public static File getVideoCacheDir(Context context) { - return new File(context.getExternalCacheDir(), "video-cache"); - } - - public static void cleanVideoCacheDir(Context context) throws IOException { - File videoCacheDir = getVideoCacheDir(context); - cleanDirectory(videoCacheDir); - } - - private static void cleanDirectory(File file) throws IOException { - if (!file.exists()) { - return; - } - File[] contentFiles = file.listFiles(); - if (contentFiles != null) { - for (File contentFile : contentFiles) { - delete(contentFile); - } - } - } - - private static void delete(File file) throws IOException { - if (file.isFile() && file.exists()) { - deleteOrThrow(file); - } else { - cleanDirectory(file); - deleteOrThrow(file); - } - } - - private static void deleteOrThrow(File file) throws IOException { - if (file.exists()) { - boolean isDeleted = file.delete(); - if (!isDeleted) { - throw new IOException(String.format("File %s can't be deleted", file.getAbsolutePath())); - } - } - } -} diff --git a/sample/src/main/java/com/danikula/videocache/sample/Video.java b/sample/src/main/java/com/danikula/videocache/sample/Video.java deleted file mode 100644 index f364f854..00000000 --- a/sample/src/main/java/com/danikula/videocache/sample/Video.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.danikula.videocache.sample; - -public enum Video { - - ORANGE_1(Config.ROOT + "orange1.mp4"), - ORANGE_2(Config.ROOT + "orange2.mp4"), - ORANGE_3(Config.ROOT + "orange3.mp4"), - ORANGE_4(Config.ROOT + "orange4.mp4"), - ORANGE_5(Config.ROOT + "orange5.mp4"); - - public final String url; - - Video(String url) { - this.url = url; - } - - private class Config { - private static final String ROOT = "https://raw.githubusercontent.com/danikula/AndroidVideoCache/master/files/"; - } -} diff --git a/sample/src/main/java/com/danikula/videocache/sample/VideoFragment.java b/sample/src/main/java/com/danikula/videocache/sample/VideoFragment.java deleted file mode 100644 index 85c8086d..00000000 --- a/sample/src/main/java/com/danikula/videocache/sample/VideoFragment.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.danikula.videocache.sample; - -import android.os.Handler; -import android.os.Message; -import android.support.v4.app.Fragment; -import android.util.Log; -import android.widget.ImageView; -import android.widget.ProgressBar; -import android.widget.VideoView; - -import com.danikula.videocache.CacheListener; -import com.danikula.videocache.HttpProxyCacheServer; - -import org.androidannotations.annotations.AfterViews; -import org.androidannotations.annotations.EFragment; -import org.androidannotations.annotations.FragmentArg; -import org.androidannotations.annotations.SeekBarTouchStop; -import org.androidannotations.annotations.ViewById; - -import java.io.File; - -@EFragment(R.layout.fragment_video) -public class VideoFragment extends Fragment implements CacheListener { - - private static final String LOG_TAG = "VideoFragment"; - - @FragmentArg String url; - - @ViewById ImageView cacheStatusImageView; - @ViewById VideoView videoView; - @ViewById ProgressBar progressBar; - - private final VideoProgressUpdater updater = new VideoProgressUpdater(); - - public static Fragment build(String url) { - return VideoFragment_.builder() - .url(url) - .build(); - } - - @AfterViews - void afterViewInjected() { - checkCachedState(); - startVideo(); - } - - private void checkCachedState() { - HttpProxyCacheServer proxy = App.getProxy(getActivity()); - boolean fullyCached = proxy.isCached(url); - setCachedState(fullyCached); - if (fullyCached) { - progressBar.setSecondaryProgress(100); - } - } - - private void startVideo() { - HttpProxyCacheServer proxy = App.getProxy(getActivity()); - proxy.registerCacheListener(this, url); - String proxyUrl = proxy.getProxyUrl(url); - Log.d(LOG_TAG, "Use proxy url " + proxyUrl + " instead of original url " + url); - videoView.setVideoPath(proxyUrl); - videoView.start(); - } - - @Override - public void onResume() { - super.onResume(); - updater.start(); - } - - @Override - public void onPause() { - super.onPause(); - updater.stop(); - } - - @Override - public void onDestroy() { - super.onDestroy(); - - videoView.stopPlayback(); - App.getProxy(getActivity()).unregisterCacheListener(this); - } - - @Override - public void onCacheAvailable(File file, String url, int percentsAvailable) { - progressBar.setSecondaryProgress(percentsAvailable); - setCachedState(percentsAvailable == 100); - Log.d(LOG_TAG, String.format("onCacheAvailable. percents: %d, file: %s, url: %s", percentsAvailable, file, url)); - } - - private void updateVideoProgress() { - int videoProgress = videoView.getCurrentPosition() * 100 / videoView.getDuration(); - progressBar.setProgress(videoProgress); - } - - @SeekBarTouchStop(R.id.progressBar) - void seekVideo() { - int videoPosition = videoView.getDuration() * progressBar.getProgress() / 100; - videoView.seekTo(videoPosition); - } - - private void setCachedState(boolean cached) { - int statusIconId = cached ? R.drawable.ic_cloud_done : R.drawable.ic_cloud_download; - cacheStatusImageView.setImageResource(statusIconId); - } - - private final class VideoProgressUpdater extends Handler { - - public void start() { - sendEmptyMessage(0); - } - - public void stop() { - removeMessages(0); - } - - @Override - public void handleMessage(Message msg) { - updateVideoProgress(); - sendEmptyMessageDelayed(0, 500); - } - } -} diff --git a/sample/src/main/java/com/danikula/videocache/sample/VideoGalleryActivity.java b/sample/src/main/java/com/danikula/videocache/sample/VideoGalleryActivity.java deleted file mode 100644 index 2a88bc0b..00000000 --- a/sample/src/main/java/com/danikula/videocache/sample/VideoGalleryActivity.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.danikula.videocache.sample; - -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentActivity; -import android.support.v4.app.FragmentStatePagerAdapter; -import android.support.v4.view.ViewPager; - -import com.viewpagerindicator.CirclePageIndicator; - -import org.androidannotations.annotations.AfterViews; -import org.androidannotations.annotations.EActivity; -import org.androidannotations.annotations.ViewById; - -@EActivity(R.layout.activity_video_gallery) -public class VideoGalleryActivity extends FragmentActivity { - - @ViewById ViewPager viewPager; - @ViewById CirclePageIndicator viewPagerIndicator; - - @AfterViews - void afterViewInjected() { - ViewsPagerAdapter viewsPagerAdapter = new ViewsPagerAdapter(this); - viewPager.setAdapter(viewsPagerAdapter); - viewPagerIndicator.setViewPager(viewPager); - } - - private static final class ViewsPagerAdapter extends FragmentStatePagerAdapter { - - public ViewsPagerAdapter(FragmentActivity activity) { - super(activity.getSupportFragmentManager()); - } - - @Override - public Fragment getItem(int position) { - Video video = Video.values()[position]; - return GalleryVideoFragment.build(video.url); - } - - @Override - public int getCount() { - return Video.values().length; - } - - @Override - public CharSequence getPageTitle(int position) { - return Video.values()[position].name(); - } - } -} diff --git a/sample/src/main/res/drawable-hdpi/ic_cloud_done.png b/sample/src/main/res/drawable-hdpi/ic_cloud_done.png deleted file mode 100644 index 6a15640f..00000000 Binary files a/sample/src/main/res/drawable-hdpi/ic_cloud_done.png and /dev/null differ diff --git a/sample/src/main/res/drawable-hdpi/ic_cloud_download.png b/sample/src/main/res/drawable-hdpi/ic_cloud_download.png deleted file mode 100644 index 4c5d2d04..00000000 Binary files a/sample/src/main/res/drawable-hdpi/ic_cloud_download.png and /dev/null differ diff --git a/sample/src/main/res/drawable-mdpi/ic_cloud_done.png b/sample/src/main/res/drawable-mdpi/ic_cloud_done.png deleted file mode 100644 index 99e1edf2..00000000 Binary files a/sample/src/main/res/drawable-mdpi/ic_cloud_done.png and /dev/null differ diff --git a/sample/src/main/res/drawable-mdpi/ic_cloud_download.png b/sample/src/main/res/drawable-mdpi/ic_cloud_download.png deleted file mode 100644 index 0c6978c1..00000000 Binary files a/sample/src/main/res/drawable-mdpi/ic_cloud_download.png and /dev/null differ diff --git a/sample/src/main/res/drawable-xhdpi/ic_cloud_done.png b/sample/src/main/res/drawable-xhdpi/ic_cloud_done.png deleted file mode 100644 index f715921d..00000000 Binary files a/sample/src/main/res/drawable-xhdpi/ic_cloud_done.png and /dev/null differ diff --git a/sample/src/main/res/drawable-xhdpi/ic_cloud_download.png b/sample/src/main/res/drawable-xhdpi/ic_cloud_download.png deleted file mode 100644 index d1a0573a..00000000 Binary files a/sample/src/main/res/drawable-xhdpi/ic_cloud_download.png and /dev/null differ diff --git a/sample/src/main/res/drawable-xxhdpi/ic_cloud_done.png b/sample/src/main/res/drawable-xxhdpi/ic_cloud_done.png deleted file mode 100644 index 6c6b4285..00000000 Binary files a/sample/src/main/res/drawable-xxhdpi/ic_cloud_done.png and /dev/null differ diff --git a/sample/src/main/res/drawable-xxhdpi/ic_cloud_download.png b/sample/src/main/res/drawable-xxhdpi/ic_cloud_download.png deleted file mode 100644 index 3392d972..00000000 Binary files a/sample/src/main/res/drawable-xxhdpi/ic_cloud_download.png and /dev/null differ diff --git a/sample/src/main/res/drawable-xxxhdpi/ic_cloud_done.png b/sample/src/main/res/drawable-xxxhdpi/ic_cloud_done.png deleted file mode 100644 index ffbfec29..00000000 Binary files a/sample/src/main/res/drawable-xxxhdpi/ic_cloud_done.png and /dev/null differ diff --git a/sample/src/main/res/drawable-xxxhdpi/ic_cloud_download.png b/sample/src/main/res/drawable-xxxhdpi/ic_cloud_download.png deleted file mode 100644 index b24e573e..00000000 Binary files a/sample/src/main/res/drawable-xxxhdpi/ic_cloud_download.png and /dev/null differ diff --git a/sample/src/main/res/layout/activity_menu.xml b/sample/src/main/res/layout/activity_menu.xml deleted file mode 100644 index 2cc27322..00000000 --- a/sample/src/main/res/layout/activity_menu.xml +++ /dev/null @@ -1,23 +0,0 @@ - - -