diff options
author | Carey Metcalfe <carey@cmetcalfe.ca> | 2017-10-13 22:34:23 -0400 |
---|---|---|
committer | Carey Metcalfe <carey@cmetcalfe.ca> | 2017-10-13 23:02:15 -0400 |
commit | 28336265e822ab4b2ff1697fd5066fc0cfd88861 (patch) | |
tree | fff3daff98137c530a4d0eb2291acd5fc6709ef0 /app/src/main/java/github/daneren2005/dsub/util | |
parent | d0223c6eab8f58799c8c3ff0e67f5974c237e01c (diff) | |
download | dsub-28336265e822ab4b2ff1697fd5066fc0cfd88861.tar.gz dsub-28336265e822ab4b2ff1697fd5066fc0cfd88861.tar.bz2 dsub-28336265e822ab4b2ff1697fd5066fc0cfd88861.zip |
Use product flavours to enable builds without proprietary libraries
This commit uses build flavours to provide two different builds: A
'floss' build and a 'google' build.
- The 'floss' build builds a basic version of the app with no
dependencies on proprietary libraries.
- The 'google' build adds Chromecast support and a few other extras
provided by Google Play Services
Diffstat (limited to 'app/src/main/java/github/daneren2005/dsub/util')
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/util/MediaRouteManager.java | 29 | ||||
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/util/compat/CastCompat.java | 56 |
2 files changed, 5 insertions, 80 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/util/MediaRouteManager.java b/app/src/main/java/github/daneren2005/dsub/util/MediaRouteManager.java index 73ec6aec..e19cc156 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/MediaRouteManager.java +++ b/app/src/main/java/github/daneren2005/dsub/util/MediaRouteManager.java @@ -19,10 +19,6 @@ import android.os.Build; import android.support.v7.media.MediaRouteProvider; import android.support.v7.media.MediaRouteSelector; import android.support.v7.media.MediaRouter; -import android.util.Log; - -import com.google.android.gms.common.ConnectionResult; -import com.google.android.gms.common.GooglePlayServicesUtil; import java.util.ArrayList; import java.util.List; @@ -32,7 +28,7 @@ import github.daneren2005.dsub.provider.DLNARouteProvider; import github.daneren2005.dsub.provider.JukeboxRouteProvider; import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.service.RemoteController; -import github.daneren2005.dsub.util.compat.CastCompat; +import github.daneren2005.dsub.util.compat.GoogleCompat; import static android.support.v7.media.MediaRouter.RouteInfo; @@ -50,25 +46,10 @@ public class MediaRouteManager extends MediaRouter.Callback { private List<MediaRouteProvider> onlineProviders = new ArrayList<MediaRouteProvider>(); private DLNARouteProvider dlnaProvider; - static { - try { - CastCompat.checkAvailable(); - castAvailable = true; - } catch(Throwable t) { - castAvailable = false; - } - } - public MediaRouteManager(DownloadService downloadService) { this.downloadService = downloadService; router = MediaRouter.getInstance(downloadService); - - // Check if play services is available - int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(downloadService); - if(result != ConnectionResult.SUCCESS){ - Log.w(TAG, "No play services, failed with result: " + result); - castAvailable = false; - } + castAvailable = GoogleCompat.playServicesAvailable(downloadService) && GoogleCompat.castAvailable(); addProviders(); buildSelector(); @@ -83,7 +64,7 @@ public class MediaRouteManager extends MediaRouter.Callback { @Override public void onRouteSelected(MediaRouter router, RouteInfo info) { if(castAvailable) { - RemoteController controller = CastCompat.getController(downloadService, info); + RemoteController controller = GoogleCompat.getController(downloadService, info); if(controller != null) { downloadService.setRemoteEnabled(RemoteControlState.CHROMECAST, controller); } @@ -137,7 +118,7 @@ public class MediaRouteManager extends MediaRouter.Callback { } public RemoteController getRemoteController(RouteInfo info) { if(castAvailable) { - return CastCompat.getController(downloadService, info); + return GoogleCompat.getController(downloadService, info); } else { return null; } @@ -170,7 +151,7 @@ public class MediaRouteManager extends MediaRouter.Callback { builder.addControlCategory(JukeboxRouteProvider.CATEGORY_JUKEBOX_ROUTE); } if(castAvailable) { - builder.addControlCategory(CastCompat.getCastControlCategory()); + builder.addControlCategory(GoogleCompat.getCastControlCategory()); } if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { builder.addControlCategory(DLNARouteProvider.CATEGORY_DLNA); diff --git a/app/src/main/java/github/daneren2005/dsub/util/compat/CastCompat.java b/app/src/main/java/github/daneren2005/dsub/util/compat/CastCompat.java deleted file mode 100644 index 08bac263..00000000 --- a/app/src/main/java/github/daneren2005/dsub/util/compat/CastCompat.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - This file is part of Subsonic. - Subsonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - Subsonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with Subsonic. If not, see <http://www.gnu.org/licenses/>. - Copyright 2014 (C) Scott Jackson -*/ - -package github.daneren2005.dsub.util.compat; - -import android.support.v7.media.MediaRouter; - -import com.google.android.gms.cast.CastDevice; -import com.google.android.gms.cast.CastMediaControlIntent; - -import github.daneren2005.dsub.service.ChromeCastController; -import github.daneren2005.dsub.service.DownloadService; -import github.daneren2005.dsub.service.RemoteController; -import github.daneren2005.dsub.util.EnvironmentVariables; - -public final class CastCompat { - static { - if (EnvironmentVariables.CAST_APPLICATION_ID == null) { - throw new RuntimeException("CAST_APPLICATION_ID not provided"); - } - try { - Class.forName("com.google.android.gms.cast.CastDevice"); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - public static void checkAvailable() throws Throwable { - // Calling here forces class initialization. - } - - public static RemoteController getController(DownloadService downloadService, MediaRouter.RouteInfo info) { - CastDevice device = CastDevice.getFromBundle(info.getExtras()); - if(device != null) { - return new ChromeCastController(downloadService, device); - } else { - return null; - } - } - - public static String getCastControlCategory() { - return CastMediaControlIntent.categoryForCast(EnvironmentVariables.CAST_APPLICATION_ID); - } -} |