Permalink
Browse files

Step 6: Make the default build be an exopackage

  • Loading branch information...
dreiss authored and k21 committed Jul 8, 2014
1 parent 1f1b375 commit 4250292b4d4742d40a9b06ce638741b2873210f1
View
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.danoeh.antennapod"
android:versionCode="37"
@@ -32,7 +33,7 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:name="de.danoeh.antennapod.PodcastApp"
android:name="de.danoeh.antennapod.AppShell"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:backupAgent=".backup.OpmlBackupAgent"
View
21 BUCK
@@ -37,9 +37,11 @@ android_build_config(
package = 'de.danoeh.antennapod',
)
APP_CLASS_SOURCE = 'src/de/danoeh/antennapod/AppShell.java'
android_library(
name = 'main-lib',
srcs = glob(['src/de/danoeh/antennapod/**/*.java']),
srcs = glob(['src/de/danoeh/antennapod/**/*.java'], excludes = [APP_CLASS_SOURCE]),
deps = [
':all-jars',
':dslv-lib',
@@ -50,6 +52,15 @@ android_library(
],
)
android_library(
name = 'application-lib',
srcs = [APP_CLASS_SOURCE],
deps = [
':build-config',
':jars__buck-android-support',
],
)
android_resource(
name = 'res',
package = 'de.danoeh.antennapod',
@@ -105,8 +116,16 @@ android_binary(
name = 'antennapod',
manifest = ':manifest',
keystore = ':debug_keystore',
use_split_dex = True,
exopackage = True,
primary_dex_patterns = [
'^de/danoeh/antennapod/AppShell^',
'^de/danoeh/antennapod/BuildConfig^',
'^com/facebook/buck/android/support/exopackage/'
],
deps = [
':main-lib',
':application-lib',
],
)
@@ -0,0 +1,10 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod;
import com.facebook.buck.android.support.exopackage.ExopackageApplication;
public class AppShell extends ExopackageApplication {
public AppShell() {
super("de.danoeh.antennapod.PodcastApp", BuildConfig.IS_EXOPACKAGE);
}
}
@@ -1,16 +1,18 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod;
import android.app.Application;
import android.content.res.Configuration;
import android.util.Log;
import com.facebook.buck.android.support.exopackage.DefaultApplicationLike;
import de.danoeh.antennapod.asynctask.ImageLoader;
import de.danoeh.antennapod.feed.EventDistributor;
import de.danoeh.antennapod.preferences.PlaybackPreferences;
import de.danoeh.antennapod.preferences.UserPreferences;
import de.danoeh.antennapod.spa.SPAUtil;
/** Main application class. */
public class PodcastApp extends Application {
public class PodcastApp extends DefaultApplicationLike {
private static final String TAG = "PodcastApp";
public static final String EXPORT_DIR = "export/";
@@ -19,37 +21,45 @@
private static PodcastApp singleton;
public static PodcastApp getInstance() {
public static PodcastApp getInstance() {
return singleton;
}
private final Application appContext;
public static Application getAppContext() {
return getInstance().appContext;
}
public PodcastApp(Application appContext) {
this.appContext = appContext;
}
@Override
public void onCreate() {
super.onCreate();
singleton = this;
LOGICAL_DENSITY = getResources().getDisplayMetrics().density;
LOGICAL_DENSITY = appContext.getResources().getDisplayMetrics().density;
UserPreferences.createInstance(this);
PlaybackPreferences.createInstance(this);
UserPreferences.createInstance(appContext);
PlaybackPreferences.createInstance(appContext);
EventDistributor.getInstance();
SPAUtil.sendSPAppsQueryFeedsIntent(this);
SPAUtil.sendSPAppsQueryFeedsIntent(appContext);
}
@Override
public void onLowMemory() {
super.onLowMemory();
Log.w(TAG, "Received onLowOnMemory warning. Cleaning image cache...");
ImageLoader.getInstance().wipeImageCache();
}
public static float getLogicalDensity() {
public static float getLogicalDensity() {
return LOGICAL_DENSITY;
}
public boolean isLargeScreen() {
return (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE
|| (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE;
return (appContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE
|| (appContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE;
}
}
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.asynctask;
import android.graphics.BitmapFactory;
@@ -57,8 +58,8 @@ protected void onPostExecute() {
// check if imageview is still supposed to display this image
if (tagsMatching(target) && cBitmap.getBitmap() != null) {
Drawable[] drawables = new Drawable[]{
PodcastApp.getInstance().getResources().getDrawable(android.R.color.transparent),
new BitmapDrawable(PodcastApp.getInstance().getResources(), cBitmap.getBitmap())
PodcastApp.getAppContext().getResources().getDrawable(android.R.color.transparent),
new BitmapDrawable(PodcastApp.getAppContext().getResources(), cBitmap.getBitmap())
};
TransitionDrawable transitionDrawable = new TransitionDrawable(drawables);
target.setImageDrawable(transitionDrawable);
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.asynctask;
import android.os.Handler;
@@ -37,7 +38,7 @@ public static synchronized ImageDiskCache getDefaultInstance() {
final String DEFAULT_PATH = "imagecache";
final long DEFAULT_MAX_CACHE_SIZE = 10 * 1024 * 1024;
File cacheDir = PodcastApp.getInstance().getExternalCacheDir();
File cacheDir = PodcastApp.getAppContext().getExternalCacheDir();
if (cacheDir == null) {
return null;
}
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.asynctask;
import android.annotation.SuppressLint;
@@ -40,7 +41,7 @@
* the FeedImage the bitmap belongs to.
*/
final int memClass = ((ActivityManager) PodcastApp.getInstance()
final int memClass = ((ActivityManager) PodcastApp.getAppContext()
.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
// Use 1/8th of the available memory for this memory cache.
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.feed;
import de.danoeh.antennapod.PodcastApp;
@@ -253,7 +254,7 @@ private boolean isPlaying() {
public String call() throws Exception {
if (contentEncoded == null || description == null) {
DBReader.loadExtraInformationOfFeedItem(PodcastApp.getInstance(), FeedItem.this);
DBReader.loadExtraInformationOfFeedItem(PodcastApp.getAppContext(), FeedItem.this);
}
return (contentEncoded != null) ? contentEncoded : description;
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.feed;
import android.content.SharedPreferences;
@@ -239,7 +240,7 @@ public void writeToPreferences(Editor prefEditor) {
@Override
public void loadMetadata() throws PlayableException {
if (item == null && itemID != 0) {
item = DBReader.getFeedItem(PodcastApp.getInstance(), itemID);
item = DBReader.getFeedItem(PodcastApp.getAppContext(), itemID);
}
}
@@ -248,7 +249,7 @@ public void loadChapterMarks() {
if (getChapters() == null && !localFileAvailable()) {
ChapterUtils.loadChaptersFromStreamUrl(this);
if (getChapters() != null && item != null) {
DBWriter.setFeedItem(PodcastApp.getInstance(),
DBWriter.setFeedItem(PodcastApp.getAppContext(),
item);
}
}
@@ -327,7 +328,7 @@ public boolean streamAvailable() {
@Override
public void saveCurrentPosition(SharedPreferences pref, int newPosition) {
setPosition(newPosition);
DBWriter.setFeedMediaPlaybackInformation(PodcastApp.getInstance(), this);
DBWriter.setFeedMediaPlaybackInformation(PodcastApp.getAppContext(), this);
}
@Override
@@ -355,10 +356,10 @@ public void setChapters(List<Chapter> chapters) {
@Override
public String call() throws Exception {
if (item == null) {
item = DBReader.getFeedItem(PodcastApp.getInstance(), itemID);
item = DBReader.getFeedItem(PodcastApp.getAppContext(), itemID);
}
if (item.getContentEncoded() == null || item.getDescription() == null) {
DBReader.loadExtraInformationOfFeedItem(PodcastApp.getInstance(), item);
DBReader.loadExtraInformationOfFeedItem(PodcastApp.getAppContext(), item);
}
return (item.getContentEncoded() != null) ? item.getContentEncoded() : item.getDescription();
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.preferences;
import android.content.Context;
@@ -48,7 +49,7 @@
private static boolean preferencesLoaded = false;
private static SharedPreferences getPreferences() {
return PodcastApp.getInstance().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
return PodcastApp.getAppContext().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
}
private static synchronized void ensurePreferencesLoaded() {
@@ -148,7 +149,7 @@ public static void addAddedFeed(String feed) {
writePreference(PREF_SYNC_REMOVED, removedFeeds);
}
feedListLock.unlock();
GpodnetSyncService.sendSyncIntent(PodcastApp.getInstance());
GpodnetSyncService.sendSyncIntent(PodcastApp.getAppContext());
}
public static void addRemovedFeed(String feed) {
@@ -161,7 +162,7 @@ public static void addRemovedFeed(String feed) {
writePreference(PREF_SYNC_ADDED, addedFeeds);
}
feedListLock.unlock();
GpodnetSyncService.sendSyncIntent(PodcastApp.getInstance());
GpodnetSyncService.sendSyncIntent(PodcastApp.getAppContext());
}
public static Set<String> getAddedFeedsCopy() {
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.service.download;
import android.content.Context;
@@ -29,7 +30,7 @@ public Downloader(DownloadRequest request) {
protected abstract void download();
public final Downloader call() {
WifiManager wifiManager = (WifiManager) PodcastApp.getInstance().getSystemService(Context.WIFI_SERVICE);
WifiManager wifiManager = (WifiManager) PodcastApp.getAppContext().getSystemService(Context.WIFI_SERVICE);
WifiManager.WifiLock wifiLock = null;
if (wifiManager != null) {
wifiLock = wifiManager.createWifiLock(TAG);
@@ -66,4 +67,4 @@ public void cancel() {
cancelled = true;
}
}
}
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.service.download;
import android.net.http.AndroidHttpClient;
@@ -104,7 +105,7 @@ protected void download() {
return;
}
if (!StorageUtils.storageAvailable(PodcastApp.getInstance())) {
if (!StorageUtils.storageAvailable(PodcastApp.getAppContext())) {
onFail(DownloadError.ERROR_DEVICE_NOT_FOUND, null);
return;
}
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.service.playback;
import android.annotation.SuppressLint;
@@ -758,7 +759,7 @@ private synchronized void saveCurrentPosition(boolean updatePlayedDuration, int
Log.d(TAG, "saveCurrentPosition: performing auto flattr since played duration " + Integer.toString(m.getPlayedDuration())
+ " is " + UserPreferences.getPlayedDurationAutoflattrThreshold() * 100 + "% of file duration " + Integer.toString(duration));
item.getFlattrStatus().setFlattrQueue();
DBWriter.setFeedItemFlattrStatus(PodcastApp.getInstance(), item, false);
DBWriter.setFeedItemFlattrStatus(PodcastApp.getAppContext(), item, false);
}
}
playable.saveCurrentPosition(PreferenceManager
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.util;
import android.app.Activity;
@@ -51,7 +52,7 @@ public static boolean checkStorageAvailability(Activity activity) {
/** Get the number of free bytes that are available on the external storage. */
public static long getFreeSpaceAvailable() {
StatFs stat = new StatFs(UserPreferences.getDataFolder(
PodcastApp.getInstance(), null).getAbsolutePath());
PodcastApp.getAppContext(), null).getAbsolutePath());
long availableBlocks;
long blockSize;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.util.flattr;
import android.app.AlertDialog;
@@ -59,7 +60,7 @@ private static AccessToken retrieveToken() {
if (BuildConfig.DEBUG)
Log.d(TAG, "Retrieving access token");
String token = PreferenceManager.getDefaultSharedPreferences(
PodcastApp.getInstance())
PodcastApp.getAppContext())
.getString(PREF_ACCESS_TOKEN, null);
if (token != null) {
if (BuildConfig.DEBUG)
@@ -83,7 +84,7 @@ public static void storeToken(AccessToken token) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Storing token");
SharedPreferences.Editor editor = PreferenceManager
.getDefaultSharedPreferences(PodcastApp.getInstance()).edit();
.getDefaultSharedPreferences(PodcastApp.getAppContext()).edit();
if (token != null) {
editor.putString(PREF_ACCESS_TOKEN, token.getToken());
} else {
@@ -271,4 +272,4 @@ public void onClick(DialogInterface dialog, int which) {
builder.create().show();
}
}
}

0 comments on commit 4250292

Please sign in to comment.