From e8f4d55d6895e1f2bc298ef8978e1aef43ff57c5 Mon Sep 17 00:00:00 2001 From: Chris Wren Date: Fri, 12 Oct 2012 19:03:26 -0400 Subject: Be miserly with metered data. Bug: 7337804 Change-Id: I64d078396b112381b2971259c784ee6fdf5e5ca3 --- AndroidManifest.xml | 3 +- res/values/config.xml | 3 ++ .../android/dreams/phototable/PhotoCarousel.java | 1 - .../android/dreams/phototable/PicasaSource.java | 33 ++++++++++++++++++++-- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index b721312..412c0f7 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -2,8 +2,9 @@ - + + 10 + + + 20 diff --git a/src/com/android/dreams/phototable/PhotoCarousel.java b/src/com/android/dreams/phototable/PhotoCarousel.java index d03dde0..0c957ab 100644 --- a/src/com/android/dreams/phototable/PhotoCarousel.java +++ b/src/com/android/dreams/phototable/PhotoCarousel.java @@ -232,7 +232,6 @@ public class PhotoCarousel extends FrameLayout { mPanel[1] = findViewById(R.id.back); new PhotoLoadTask(mPanel[0]).execute(); - new PhotoLoadTask(mPanel[1]).execute(); scheduleNext(mDropPeriod); } diff --git a/src/com/android/dreams/phototable/PicasaSource.java b/src/com/android/dreams/phototable/PicasaSource.java index 8a3c751..3a7ca23 100644 --- a/src/com/android/dreams/phototable/PicasaSource.java +++ b/src/com/android/dreams/phototable/PicasaSource.java @@ -18,6 +18,7 @@ package com.android.dreams.phototable; import android.content.Context; import android.content.SharedPreferences; import android.database.Cursor; +import android.net.ConnectivityManager; import android.net.Uri; import android.util.Log; @@ -67,6 +68,9 @@ public class PicasaSource extends PhotoSource { private final String mPostsAlbumName; private final String mUploadsAlbumName; private final String mUnknownAlbumName; + private final LinkedList mRecycleBin; + private final ConnectivityManager mConnectivityManager; + private final int mMaxRecycleSize; private Set mFoundAlbumIds; private int mNextPosition; @@ -79,6 +83,10 @@ public class PicasaSource extends PhotoSource { mPostsAlbumName = mResources.getString(R.string.posts_album_name, "Posts"); mUploadsAlbumName = mResources.getString(R.string.uploads_album_name, "Instant Uploads"); mUnknownAlbumName = mResources.getString(R.string.unknown_album_name, "Unknown"); + mMaxRecycleSize = mResources.getInteger(R.integer.recycle_image_pool_size); + mConnectivityManager = + (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + mRecycleBin = new LinkedList(); fillQueue(); } @@ -86,6 +94,16 @@ public class PicasaSource extends PhotoSource { protected Collection findImages(int howMany) { log(TAG, "finding images"); LinkedList foundImages = new LinkedList(); + if (mConnectivityManager.isActiveNetworkMetered()) { + howMany = Math.min(howMany, mMaxRecycleSize); + log(TAG, "METERED: " + howMany); + if (!mRecycleBin.isEmpty()) { + foundImages.addAll(mRecycleBin); + log(TAG, "recycled " + foundImages.size() + " items."); + return foundImages; + } + } + String[] projection = {PICASA_ID, PICASA_URL, PICASA_ROTATION, PICASA_ALBUM_ID}; boolean usePosts = false; LinkedList albumIds = new LinkedList(); @@ -359,8 +377,12 @@ public class PicasaSource extends PhotoSource { .scheme("content") .authority(PICASA_AUTHORITY) .appendPath(PICASA_PHOTO_PATH) - .appendPath(data.id) - .appendQueryParameter(PICASA_TYPE_KEY, PICASA_TYPE_FULL_VALUE); + .appendPath(data.id); + if (mConnectivityManager.isActiveNetworkMetered()) { + photoUriBuilder.appendQueryParameter(PICASA_TYPE_KEY, PICASA_TYPE_SCREEN_VALUE); + } else { + photoUriBuilder.appendQueryParameter(PICASA_TYPE_KEY, PICASA_TYPE_FULL_VALUE); + } if (data.url != null) { photoUriBuilder.appendQueryParameter(PICASA_URL_KEY, data.url); } @@ -373,6 +395,13 @@ public class PicasaSource extends PhotoSource { is = null; } + if (is != null) { + mRecycleBin.offer(data); + log(TAG, "RECYCLED"); + while (mRecycleBin.size() > mMaxRecycleSize) { + mRecycleBin.poll(); + } + } return is; } } -- cgit v1.2.3