summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/build.gradle2
-rw-r--r--app/src/main/java/de/danoeh/antennapod/PodcastApp.java2
-rw-r--r--app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java7
-rw-r--r--app/src/main/java/de/danoeh/antennapod/activity/DefaultOnlineFeedViewActivity.java5
-rw-r--r--app/src/main/java/de/danoeh/antennapod/activity/FeedInfoActivity.java14
-rw-r--r--app/src/main/java/de/danoeh/antennapod/adapter/DownloadedEpisodesListAdapter.java5
-rw-r--r--app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java5
-rw-r--r--app/src/main/java/de/danoeh/antennapod/adapter/NewEpisodesListAdapter.java5
-rw-r--r--app/src/main/java/de/danoeh/antennapod/adapter/QueueListAdapter.java12
-rw-r--r--app/src/main/java/de/danoeh/antennapod/adapter/SearchlistAdapter.java7
-rw-r--r--app/src/main/java/de/danoeh/antennapod/adapter/gpodnet/PodcastListAdapter.java5
-rw-r--r--app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java5
-rw-r--r--app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java5
-rw-r--r--app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java5
-rw-r--r--core/build.gradle2
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/asynctask/PicassoProvider.java241
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java53
17 files changed, 229 insertions, 151 deletions
diff --git a/app/build.gradle b/app/build.gradle
index d236c907b..e58524e30 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -17,7 +17,7 @@ dependencies {
compile project('dslv:library')
compile 'com.jayway.android.robotium:robotium-solo:5.2.1'
compile 'org.jsoup:jsoup:1.7.3'
- compile 'com.squareup.picasso:picasso:2.3.4'
+ compile 'com.squareup.picasso:picasso:2.4.0'
compile 'com.squareup.okhttp:okhttp:2.0.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
compile 'com.squareup.okio:okio:1.0.0'
diff --git a/app/src/main/java/de/danoeh/antennapod/PodcastApp.java b/app/src/main/java/de/danoeh/antennapod/PodcastApp.java
index 87474dbdd..451094909 100644
--- a/app/src/main/java/de/danoeh/antennapod/PodcastApp.java
+++ b/app/src/main/java/de/danoeh/antennapod/PodcastApp.java
@@ -3,6 +3,7 @@ package de.danoeh.antennapod;
import android.app.Application;
import android.content.res.Configuration;
+import de.danoeh.antennapod.core.asynctask.PicassoProvider;
import de.danoeh.antennapod.core.feed.EventDistributor;
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
import de.danoeh.antennapod.core.preferences.UserPreferences;
@@ -36,6 +37,7 @@ public class PodcastApp extends Application {
singleton = this;
LOGICAL_DENSITY = getResources().getDisplayMetrics().density;
+ PicassoProvider.setupPicassoInstance(this);
UserPreferences.createInstance(this);
PlaybackPreferences.createInstance(this);
EventDistributor.getInstance();
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java
index 9979896f6..eb7a844db 100644
--- a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java
+++ b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java
@@ -25,13 +25,14 @@ import android.widget.ImageView.ScaleType;
import android.widget.ListView;
import android.widget.TextView;
+import com.squareup.picasso.Picasso;
+
import org.apache.commons.lang3.StringUtils;
import de.danoeh.antennapod.BuildConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.adapter.ChapterListAdapter;
import de.danoeh.antennapod.adapter.NavListAdapter;
-import de.danoeh.antennapod.core.asynctask.PicassoProvider;
import de.danoeh.antennapod.core.feed.Chapter;
import de.danoeh.antennapod.core.feed.EventDistributor;
import de.danoeh.antennapod.core.feed.Feed;
@@ -383,7 +384,7 @@ public class AudioplayerActivity extends MediaplayerActivity implements ItemDesc
@Override
public void run() {
- PicassoProvider.getMediaMetadataPicassoInstance(AudioplayerActivity.this)
+ Picasso.with(AudioplayerActivity.this)
.load(media.getImageUri())
.fit()
.into(butNavLeft);
@@ -400,7 +401,7 @@ public class AudioplayerActivity extends MediaplayerActivity implements ItemDesc
@Override
public void run() {
- PicassoProvider.getMediaMetadataPicassoInstance(AudioplayerActivity.this)
+ Picasso.with(AudioplayerActivity.this)
.load(media.getImageUri())
.fit()
.into(butNavLeft);
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/DefaultOnlineFeedViewActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/DefaultOnlineFeedViewActivity.java
index 5e3817796..d265c05b1 100644
--- a/app/src/main/java/de/danoeh/antennapod/activity/DefaultOnlineFeedViewActivity.java
+++ b/app/src/main/java/de/danoeh/antennapod/activity/DefaultOnlineFeedViewActivity.java
@@ -17,6 +17,8 @@ import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
+import com.squareup.picasso.Picasso;
+
import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.examples.HtmlToPlainText;
@@ -30,7 +32,6 @@ import java.util.Map;
import de.danoeh.antennapod.BuildConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.adapter.FeedItemlistDescriptionAdapter;
-import de.danoeh.antennapod.core.asynctask.PicassoProvider;
import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator;
import de.danoeh.antennapod.core.feed.EventDistributor;
import de.danoeh.antennapod.core.feed.Feed;
@@ -123,7 +124,7 @@ public class DefaultOnlineFeedViewActivity extends OnlineFeedViewActivity {
subscribeButton = (Button) header.findViewById(R.id.butSubscribe);
if (feed.getImage() != null && StringUtils.isNoneBlank(feed.getImage().getDownload_url())) {
- PicassoProvider.getDefaultPicassoInstance(this)
+ Picasso.with(this)
.load(feed.getImage().getDownload_url())
.fit()
.into(cover);
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/FeedInfoActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/FeedInfoActivity.java
index 3000cfaeb..93c71a868 100644
--- a/app/src/main/java/de/danoeh/antennapod/activity/FeedInfoActivity.java
+++ b/app/src/main/java/de/danoeh/antennapod/activity/FeedInfoActivity.java
@@ -9,10 +9,16 @@ import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
-import android.widget.*;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
+import android.widget.EditText;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.squareup.picasso.Picasso;
+
import de.danoeh.antennapod.BuildConfig;
import de.danoeh.antennapod.R;
-import de.danoeh.antennapod.core.asynctask.PicassoProvider;
import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator;
import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.feed.FeedPreferences;
@@ -78,7 +84,7 @@ public class FeedInfoActivity extends ActionBarActivity {
@Override
public void run() {
- PicassoProvider.getDefaultPicassoInstance(FeedInfoActivity.this)
+ Picasso.with(FeedInfoActivity.this)
.load(feed.getImageUri())
.fit()
.into(imgvCover);
@@ -167,7 +173,7 @@ public class FeedInfoActivity extends ActionBarActivity {
super.onPrepareOptionsMenu(menu);
menu.findItem(R.id.support_item).setVisible(
feed != null && feed.getPaymentLink() != null);
- menu.findItem(R.id.share_link_item).setVisible(feed != null &&feed.getLink() != null);
+ menu.findItem(R.id.share_link_item).setVisible(feed != null && feed.getLink() != null);
menu.findItem(R.id.visit_website_item).setVisible(feed != null && feed.getLink() != null);
return true;
}
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadedEpisodesListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadedEpisodesListAdapter.java
index 3af9bdcda..15e0a7a33 100644
--- a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadedEpisodesListAdapter.java
+++ b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadedEpisodesListAdapter.java
@@ -10,8 +10,9 @@ import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
+import com.squareup.picasso.Picasso;
+
import de.danoeh.antennapod.R;
-import de.danoeh.antennapod.core.asynctask.PicassoProvider;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.util.Converter;
@@ -87,7 +88,7 @@ public class DownloadedEpisodesListAdapter extends BaseAdapter {
holder.butSecondary.setOnClickListener(secondaryActionListener);
- PicassoProvider.getMediaMetadataPicassoInstance(context)
+ Picasso.with(context)
.load(item.getImageUri())
.fit()
.into(holder.imageView);
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java
index cbe7665fd..a0ba0f794 100644
--- a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java
+++ b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java
@@ -11,8 +11,9 @@ import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
+import com.squareup.picasso.Picasso;
+
import de.danoeh.antennapod.R;
-import de.danoeh.antennapod.core.asynctask.PicassoProvider;
import de.danoeh.antennapod.core.feed.Feed;
/**
@@ -180,7 +181,7 @@ public class NavListAdapter extends BaseAdapter {
holder.title.setText(feed.getTitle());
- PicassoProvider.getDefaultPicassoInstance(context)
+ Picasso.with(context)
.load(feed.getImageUri())
.fit()
.into(holder.image);
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/NewEpisodesListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/NewEpisodesListAdapter.java
index 171f82114..1f98ec158 100644
--- a/app/src/main/java/de/danoeh/antennapod/adapter/NewEpisodesListAdapter.java
+++ b/app/src/main/java/de/danoeh/antennapod/adapter/NewEpisodesListAdapter.java
@@ -11,8 +11,9 @@ import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
+import com.squareup.picasso.Picasso;
+
import de.danoeh.antennapod.R;
-import de.danoeh.antennapod.core.asynctask.PicassoProvider;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.storage.DownloadRequester;
@@ -133,7 +134,7 @@ public class NewEpisodesListAdapter extends BaseAdapter {
holder.butSecondary.setTag(item);
holder.butSecondary.setOnClickListener(secondaryActionListener);
- PicassoProvider.getMediaMetadataPicassoInstance(context)
+ Picasso.with(context)
.load(item.getImageUri())
.fit()
.into(holder.imageView);
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/QueueListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/QueueListAdapter.java
index bc42ad063..d5b85575b 100644
--- a/app/src/main/java/de/danoeh/antennapod/adapter/QueueListAdapter.java
+++ b/app/src/main/java/de/danoeh/antennapod/adapter/QueueListAdapter.java
@@ -4,9 +4,15 @@ import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.*;
+import android.widget.BaseAdapter;
+import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.ProgressBar;
+import android.widget.TextView;
+
+import com.squareup.picasso.Picasso;
+
import de.danoeh.antennapod.R;
-import de.danoeh.antennapod.core.asynctask.PicassoProvider;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.storage.DownloadRequester;
@@ -92,7 +98,7 @@ public class QueueListAdapter extends BaseAdapter {
holder.butSecondary.setTag(item);
holder.butSecondary.setOnClickListener(secondaryActionListener);
- PicassoProvider.getMediaMetadataPicassoInstance(context)
+ Picasso.with(context)
.load(item.getImageUri())
.fit()
.into(holder.imageView);
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/SearchlistAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/SearchlistAdapter.java
index 79c1f6f99..cedce7903 100644
--- a/app/src/main/java/de/danoeh/antennapod/adapter/SearchlistAdapter.java
+++ b/app/src/main/java/de/danoeh/antennapod/adapter/SearchlistAdapter.java
@@ -8,8 +8,9 @@ import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
+import com.squareup.picasso.Picasso;
+
import de.danoeh.antennapod.R;
-import de.danoeh.antennapod.core.asynctask.PicassoProvider;
import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.feed.FeedComponent;
import de.danoeh.antennapod.core.feed.FeedItem;
@@ -72,7 +73,7 @@ public class SearchlistAdapter extends BaseAdapter {
holder.title.setText(feed.getTitle());
holder.subtitle.setVisibility(View.GONE);
- PicassoProvider.getDefaultPicassoInstance(context)
+ Picasso.with(context)
.load(feed.getImageUri())
.fit()
.into(holder.cover);
@@ -85,7 +86,7 @@ public class SearchlistAdapter extends BaseAdapter {
holder.subtitle.setText(result.getSubtitle());
}
- PicassoProvider.getDefaultPicassoInstance(context)
+ Picasso.with(context)
.load(item.getFeed().getImageUri())
.fit()
.into(holder.cover);
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/gpodnet/PodcastListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/gpodnet/PodcastListAdapter.java
index 8549f4f7a..51569e92e 100644
--- a/app/src/main/java/de/danoeh/antennapod/adapter/gpodnet/PodcastListAdapter.java
+++ b/app/src/main/java/de/danoeh/antennapod/adapter/gpodnet/PodcastListAdapter.java
@@ -8,12 +8,13 @@ import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
+import com.squareup.picasso.Picasso;
+
import org.apache.commons.lang3.StringUtils;
import java.util.List;
import de.danoeh.antennapod.R;
-import de.danoeh.antennapod.core.asynctask.PicassoProvider;
import de.danoeh.antennapod.core.gpoddernet.model.GpodnetPodcast;
/**
@@ -49,7 +50,7 @@ public class PodcastListAdapter extends ArrayAdapter<GpodnetPodcast> {
holder.title.setText(podcast.getTitle());
if (StringUtils.isNoneBlank(podcast.getLogoUrl())) {
- PicassoProvider.getDefaultPicassoInstance(convertView.getContext())
+ Picasso.with(convertView.getContext())
.load(podcast.getLogoUrl())
.fit()
.into(holder.image);
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java
index 69bd2b099..efe3e7ab4 100644
--- a/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java
+++ b/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java
@@ -9,10 +9,11 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
+import com.squareup.picasso.Picasso;
+
import de.danoeh.antennapod.BuildConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.AudioplayerActivity.AudioplayerContentFragment;
-import de.danoeh.antennapod.core.asynctask.PicassoProvider;
import de.danoeh.antennapod.core.util.playback.Playable;
/**
@@ -68,7 +69,7 @@ public class CoverFragment extends Fragment implements
public void run() {
Context c = getActivity();
if (c != null) {
- PicassoProvider.getMediaMetadataPicassoInstance(c)
+ Picasso.with(c)
.load(media.getImageUri())
.into(imgvCover);
}
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java
index 99320cffa..a42658057 100644
--- a/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java
+++ b/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java
@@ -11,9 +11,10 @@ import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
+import com.squareup.picasso.Picasso;
+
import de.danoeh.antennapod.BuildConfig;
import de.danoeh.antennapod.R;
-import de.danoeh.antennapod.core.asynctask.PicassoProvider;
import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.core.util.playback.Playable;
@@ -207,7 +208,7 @@ public class ExternalPlayerFragment extends Fragment {
if (media != null) {
txtvTitle.setText(media.getEpisodeTitle());
- PicassoProvider.getMediaMetadataPicassoInstance(getActivity())
+ Picasso.with(getActivity())
.load(media.getImageUri())
.fit()
.into(imgvCover);
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java
index abf894c2a..be9a9c12d 100644
--- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java
+++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java
@@ -21,6 +21,8 @@ import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
+import com.squareup.picasso.Picasso;
+
import org.apache.commons.lang3.Validate;
import java.util.List;
@@ -33,7 +35,6 @@ import de.danoeh.antennapod.adapter.DefaultActionButtonCallback;
import de.danoeh.antennapod.adapter.FeedItemlistAdapter;
import de.danoeh.antennapod.core.asynctask.DownloadObserver;
import de.danoeh.antennapod.core.asynctask.FeedRemover;
-import de.danoeh.antennapod.core.asynctask.PicassoProvider;
import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator;
import de.danoeh.antennapod.core.feed.EventDistributor;
@@ -367,7 +368,7 @@ public class ItemlistFragment extends ListFragment {
txtvTitle.setText(feed.getTitle());
txtvAuthor.setText(feed.getAuthor());
- PicassoProvider.getDefaultPicassoInstance(getActivity())
+ Picasso.with(getActivity())
.load(feed.getImageUri())
.fit()
.into(imgvCover);
diff --git a/core/build.gradle b/core/build.gradle
index be0fb109c..6949fd4ad 100644
--- a/core/build.gradle
+++ b/core/build.gradle
@@ -38,7 +38,7 @@ dependencies {
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.jayway.android.robotium:robotium-solo:5.2.1'
compile 'org.jsoup:jsoup:1.7.3'
- compile 'com.squareup.picasso:picasso:2.3.4'
+ compile 'com.squareup.picasso:picasso:2.4.0'
compile 'com.squareup.okhttp:okhttp:2.0.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
compile 'com.squareup.okio:okio:1.0.0'
diff --git a/core/src/main/java/de/danoeh/antennapod/core/asynctask/PicassoProvider.java b/core/src/main/java/de/danoeh/antennapod/core/asynctask/PicassoProvider.java
index 6ace92800..6d9353a93 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/asynctask/PicassoProvider.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/asynctask/PicassoProvider.java
@@ -1,26 +1,26 @@
package de.danoeh.antennapod.core.asynctask;
+import android.content.ContentResolver;
import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.media.MediaMetadataRetriever;
import android.net.Uri;
import android.util.Log;
-import android.webkit.MimeTypeMap;
import com.squareup.picasso.Cache;
-import com.squareup.picasso.Downloader;
import com.squareup.picasso.LruCache;
import com.squareup.picasso.OkHttpDownloader;
import com.squareup.picasso.Picasso;
+import com.squareup.picasso.Request;
+import com.squareup.picasso.RequestHandler;
-import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.Validate;
-import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -35,9 +35,6 @@ public class PicassoProvider {
private static ExecutorService executorService;
private static Cache memoryCache;
- private static Picasso defaultPicassoInstance;
- private static Picasso mediaMetadataPicassoInstance;
-
private static synchronized ExecutorService getExecutorService() {
if (executorService == null) {
executorService = Executors.newFixedThreadPool(3);
@@ -52,101 +49,161 @@ public class PicassoProvider {
return memoryCache;
}
- /**
- * Returns a Picasso instance that uses an OkHttpDownloader. This instance can only load images
- * from image files.
- * <p/>
- * This instance should be used as long as no images from media files are loaded.
- */
- public static synchronized Picasso getDefaultPicassoInstance(Context context) {
- Validate.notNull(context);
- if (defaultPicassoInstance == null) {
- defaultPicassoInstance = new Picasso.Builder(context)
- .indicatorsEnabled(DEBUG)
- .loggingEnabled(DEBUG)
- .downloader(new OkHttpDownloader(context))
- .executor(getExecutorService())
- .memoryCache(getMemoryCache(context))
- .listener(new Picasso.Listener() {
- @Override
- public void onImageLoadFailed(Picasso picasso, Uri uri, Exception e) {
- Log.e(TAG, "Failed to load Uri:" + uri.toString());
- e.printStackTrace();
- }
- })
- .build();
- }
- return defaultPicassoInstance;
- }
+ private static volatile boolean picassoSetup = false;
- /**
- * Returns a Picasso instance that uses a MediaMetadataRetriever if the given Uri is a media file
- * and a default OkHttpDownloader otherwise.
- */
- public static synchronized Picasso getMediaMetadataPicassoInstance(Context context) {
- Validate.notNull(context);
- if (mediaMetadataPicassoInstance == null) {
- mediaMetadataPicassoInstance = new Picasso.Builder(context)
- .indicatorsEnabled(DEBUG)
- .loggingEnabled(DEBUG)
- .downloader(new MediaMetadataDownloader(context))
- .executor(getExecutorService())
- .memoryCache(getMemoryCache(context))
- .listener(new Picasso.Listener() {
- @Override
- public void onImageLoadFailed(Picasso picasso, Uri uri, Exception e) {
- Log.e(TAG, "Failed to load Uri:" + uri.toString());
- e.printStackTrace();
- }
- })
- .build();
+ public static synchronized void setupPicassoInstance(Context appContext) {
+ if (picassoSetup) {
+ return;
}
- return mediaMetadataPicassoInstance;
+ Picasso picasso = new Picasso.Builder(appContext)
+ .indicatorsEnabled(DEBUG)
+ .loggingEnabled(DEBUG)
+ .downloader(new OkHttpDownloader(appContext))
+ .addRequestHandler(new MediaRequestHandler(appContext))
+ .executor(getExecutorService())
+ .memoryCache(getMemoryCache(appContext))
+ .listener(new Picasso.Listener() {
+ @Override
+ public void onImageLoadFailed(Picasso picasso, Uri uri, Exception e) {
+ Log.e(TAG, "Failed to load Uri:" + uri.toString());
+ e.printStackTrace();
+ }
+ })
+ .build();
+ Picasso.setSingletonInstance(picasso);
+ picassoSetup = true;
}
- private static class MediaMetadataDownloader implements Downloader {
+ private static class MediaRequestHandler extends RequestHandler {
+
+ final MediaMetadataRetriever mmr;
+ final Context context;
- private static final String TAG = "MediaMetadataDownloader";
+ public MediaRequestHandler(Context context) {
+ super();
+ this.context = context;
+ mmr = new MediaMetadataRetriever();
+ }
- private final OkHttpDownloader okHttpDownloader;
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ mmr.release();
+ }
- public MediaMetadataDownloader(Context context) {
- Validate.notNull(context);
- okHttpDownloader = new OkHttpDownloader(context);
+ @Override
+ public boolean canHandleRequest(Request data) {
+ return StringUtils.equals(data.uri.getScheme(), PicassoImageResource.SCHEME_MEDIA);
}
@Override
- public Response load(Uri uri, boolean b) throws IOException {
- if (StringUtils.equals(uri.getScheme(), PicassoImageResource.SCHEME_MEDIA)) {
- String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(FilenameUtils.getExtension(uri.getLastPathSegment()));
- if (StringUtils.startsWith(type, "image")) {
- File imageFile = new File(uri.toString());
- return new Response(new BufferedInputStream(new FileInputStream(imageFile)), true, imageFile.length());
+ public Result load(Request data) throws IOException {
+ Bitmap bitmap = null;
+ mmr.setDataSource(data.uri.getPath());
+ byte[] image = mmr.getEmbeddedPicture();
+ if (image != null) {
+ bitmap = decodeStreamFromByteArray(data, image);
+ }
+ if (bitmap == null) {
+ // check for fallback Uri
+ String fallbackParam = data.uri.getQueryParameter(PicassoImageResource.PARAM_FALLBACK);
+
+ if (fallbackParam != null) {
+ Uri fallback = Uri.parse(fallbackParam);
+ bitmap = decodeStreamFromFile(data, fallback);
+ }
+ }
+ return new Result(bitmap, Picasso.LoadedFrom.DISK);
+
+ }
+
+ /* Copied/Adapted from Picasso RequestHandler classes */
+
+ private Bitmap decodeStreamFromByteArray(Request data, byte[] bytes) throws IOException {
+
+ final BitmapFactory.Options options = createBitmapOptions(data);
+ final ByteArrayInputStream in = new ByteArrayInputStream(bytes);
+ in.mark(0);
+ if (requiresInSampleSize(options)) {
+ try {
+ BitmapFactory.decodeStream(in, null, options);
+ } finally {
+ in.reset();
+ }
+ calculateInSampleSize(data.targetWidth, data.targetHeight, options, data);
+ }
+ try {
+ return BitmapFactory.decodeStream(in, null, options);
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ }
+
+ private Bitmap decodeStreamFromFile(Request data, Uri uri) throws IOException {
+ ContentResolver contentResolver = context.getContentResolver();
+ final BitmapFactory.Options options = createBitmapOptions(data);
+ if (requiresInSampleSize(options)) {
+ InputStream is = null;
+ try {
+ is = contentResolver.openInputStream(uri);
+ BitmapFactory.decodeStream(is, null, options);
+ } finally {
+ IOUtils.closeQuietly(is);
+ }
+ calculateInSampleSize(data.targetWidth, data.targetHeight, options, data);
+ }
+ InputStream is = contentResolver.openInputStream(uri);
+ try {
+ return BitmapFactory.decodeStream(is, null, options);
+ } finally {
+ IOUtils.closeQuietly(is);
+ }
+ }
+
+ private BitmapFactory.Options createBitmapOptions(Request data) {
+ final boolean justBounds = data.hasSize();
+ final boolean hasConfig = data.config != null;
+ BitmapFactory.Options options = null;
+ if (justBounds || hasConfig) {
+ options = new BitmapFactory.Options();
+ options.inJustDecodeBounds = justBounds;
+ if (hasConfig) {
+ options.inPreferredConfig = data.config;
+ }
+ }
+ return options;
+ }
+
+ private static boolean requiresInSampleSize(BitmapFactory.Options options) {
+ return options != null && options.inJustDecodeBounds;
+ }
+
+ private static void calculateInSampleSize(int reqWidth, int reqHeight, BitmapFactory.Options options,
+ Request request) {
+ calculateInSampleSize(reqWidth, reqHeight, options.outWidth, options.outHeight, options,
+ request);
+ }
+
+ private static void calculateInSampleSize(int reqWidth, int reqHeight, int width, int height,
+ BitmapFactory.Options options, Request request) {
+ int sampleSize = 1;
+ if (height > reqHeight || width > reqWidth) {
+ final int heightRatio;
+ final int widthRatio;
+ if (reqHeight == 0) {
+ sampleSize = (int) Math.floor((float) width / (float) reqWidth);
+ } else if (reqWidth == 0) {
+ sampleSize = (int) Math.floor((float) height / (float) reqHeight);
} else {
- MediaMetadataRetriever mmr = new MediaMetadataRetriever();
- mmr.setDataSource(uri.getPath());
- byte[] data = mmr.getEmbeddedPicture();
- mmr.release();
-
- if (data != null) {
- return new Response(new ByteArrayInputStream(data), true, data.length);
- } else {
-
- // check for fallback Uri
- String fallbackParam = uri.getQueryParameter(PicassoImageResource.PARAM_FALLBACK);
-
- if (fallbackParam != null) {
- String fallback = Uri.decode(Uri.parse(fallbackParam).getPath());
- if (fallback != null) {
- File imageFile = new File(fallback);
- return new Response(new BufferedInputStream(new FileInputStream(imageFile)), true, imageFile.length());
- }
- }
- return null;
- }
+ heightRatio = (int) Math.floor((float) height / (float) reqHeight);
+ widthRatio = (int) Math.floor((float) width / (float) reqWidth);
+ sampleSize = request.centerInside
+ ? Math.max(heightRatio, widthRatio)
+ : Math.min(heightRatio, widthRatio);
}
}
- return okHttpDownloader.load(uri, b);
+ options.inSampleSize = sampleSize;
+ options.inJustDecodeBounds = false;
}
}
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java
index 1261c21fe..a5560e3fb 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java
@@ -29,6 +29,8 @@ import android.view.KeyEvent;
import android.view.SurfaceHolder;
import android.widget.Toast;
+import com.squareup.picasso.Picasso;
+
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
@@ -37,7 +39,6 @@ import java.util.List;
import de.danoeh.antennapod.core.BuildConfig;
import de.danoeh.antennapod.core.ClientConfig;
import de.danoeh.antennapod.core.R;
-import de.danoeh.antennapod.core.asynctask.PicassoProvider;
import de.danoeh.antennapod.core.feed.Chapter;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.FeedMedia;
@@ -291,10 +292,9 @@ public class PlaybackService extends Service {
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
if (status == PlayerStatus.PLAYING) {
if (UserPreferences.isPersistNotify()) {
- mediaPlayer.pause(false, true);
- }
- else {
- mediaPlayer.pause(true, true);
+ mediaPlayer.pause(false, true);
+ } else {
+ mediaPlayer.pause(true, true);
}
} else if (status == PlayerStatus.PAUSED || status == PlayerStatus.PREPARED) {
mediaPlayer.resume();
@@ -315,12 +315,11 @@ public class PlaybackService extends Service {
break;
case KeyEvent.KEYCODE_MEDIA_PAUSE:
if (status == PlayerStatus.PLAYING) {
- if (UserPreferences.isPersistNotify()) {
- mediaPlayer.pause(false, true);
- }
- else {
- mediaPlayer.pause(true, true);
- }
+ if (UserPreferences.isPersistNotify()) {
+ mediaPlayer.pause(false, true);
+ } else {
+ mediaPlayer.pause(true, true);
+ }
}
break;
case KeyEvent.KEYCODE_MEDIA_NEXT:
@@ -332,11 +331,11 @@ public class PlaybackService extends Service {
mediaPlayer.seekDelta(-UserPreferences.getSeekDeltaMs());
break;
case KeyEvent.KEYCODE_MEDIA_STOP:
- if (status == PlayerStatus.PLAYING) {
- mediaPlayer.pause(true, true);
- }
- stopForeground(true); // gets rid of persistent notification
- break;
+ if (status == PlayerStatus.PLAYING) {
+ mediaPlayer.pause(true, true);
+ }
+ stopForeground(true); // gets rid of persistent notification
+ break;
default:
if (info.playable != null && info.playerStatus == PlayerStatus.PLAYING) { // only notify the user about an unknown key event if it is actually doing something
String message = String.format(getResources().getString(R.string.unknown_media_key), keycode);
@@ -411,11 +410,10 @@ public class PlaybackService extends Service {
saveCurrentPosition(false, 0);
taskManager.cancelWidgetUpdater();
if (UserPreferences.isPersistNotify() && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- // do not remove notification on pause based on user pref and whether android version supports expanded notifications
- }
- else {
- // remove notifcation on pause
- stopForeground(true);
+ // do not remove notification on pause based on user pref and whether android version supports expanded notifications
+ } else {
+ // remove notifcation on pause
+ stopForeground(true);
}
break;
@@ -709,7 +707,7 @@ public class PlaybackService extends Service {
try {
int iconSize = getResources().getDimensionPixelSize(
android.R.dimen.notification_large_icon_width);
- icon = PicassoProvider.getMediaMetadataPicassoInstance(PlaybackService.this)
+ icon = Picasso.with(PlaybackService.this)
.load(info.playable.getImageUri())
.resize(iconSize, iconSize)
.get();
@@ -1005,12 +1003,11 @@ public class PlaybackService extends Service {
*/
private void pauseIfPauseOnDisconnect() {
if (UserPreferences.isPauseOnHeadsetDisconnect()) {
- if (UserPreferences.isPersistNotify()) {
- mediaPlayer.pause(false, true);
- }
- else {
- mediaPlayer.pause(true, true);
- }
+ if (UserPreferences.isPersistNotify()) {
+ mediaPlayer.pause(false, true);
+ } else {
+ mediaPlayer.pause(true, true);
+ }
}
}