Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
223c92a
refactor some image resize util methods, start new resizing strategy
amstone326 Oct 16, 2015
c3b0487
move all image-related util methods to MediaUtil, refactor CashingAsy…
amstone326 Oct 16, 2015
3bbc715
more reorganizing
amstone326 Oct 16, 2015
696da17
Merge branch 'master' into image-resizing-by-dpi
amstone326 Oct 16, 2015
d576832
use new inflate method in MediaLayout
amstone326 Oct 16, 2015
64494aa
handle scale up and scale down cases correctly
amstone326 Oct 16, 2015
198d880
merge master
amstone326 Oct 16, 2015
c1a0235
clearly distinguish between and separate the steps of: a) scaling bas…
amstone326 Oct 19, 2015
b944890
introduce bounded scale up, add boundingWidth and boundingHeight in G…
amstone326 Oct 19, 2015
d5a1b0b
passing bounds for GridEntityView properly
amstone326 Oct 19, 2015
2389abf
add bounding dimens for GridMediaView
amstone326 Oct 19, 2015
768098f
final fix for scale up vs scale down conditions
amstone326 Oct 20, 2015
6285577
refactor images in case list to use new inflation method; create dist…
amstone326 Oct 20, 2015
6752de4
add more inflation bounds
amstone326 Oct 20, 2015
eed6c7b
define rule for when still allowed to use ResizingImageView
amstone326 Oct 20, 2015
0ca8a08
make using smart image inflation and the target density developer pre…
amstone326 Oct 20, 2015
58b6dde
finalize calculation of scale factor
amstone326 Oct 20, 2015
3e516ad
better method names and comments
amstone326 Oct 20, 2015
f561635
PR cleanup
amstone326 Oct 20, 2015
2d03392
merge master
amstone326 Oct 20, 2015
a4e3a84
start refactoring for testing; stop passing around image file unneces…
amstone326 Oct 20, 2015
3dcf706
started writing tests, bug discovered in scaling down that needs to b…
amstone326 Oct 20, 2015
a811746
move geo helper to GeoUtils
amstone326 Oct 21, 2015
7a20e8e
refactor to fix scale down bug
amstone326 Oct 21, 2015
a448dbd
check both container dimens
amstone326 Oct 21, 2015
cc99d76
finished tests, all passing
amstone326 Oct 21, 2015
012cea9
remove log statements, remove unncessary check for aspect ratio equality
amstone326 Oct 21, 2015
8c18d3c
Merge branch 'master' into image-resizing-by-dpi
amstone326 Oct 21, 2015
85b46da
fallback for if reference is not a file
amstone326 Oct 21, 2015
8d5a76c
for scaleDownExact, when decoding the bitmap initially, use the large…
amstone326 Oct 21, 2015
39c8c40
use helper method to remove duplicate code, fix getBitmapScaledToCont…
amstone326 Oct 21, 2015
979331b
use camel case
amstone326 Oct 21, 2015
e49e315
remove unneeded try/catch
amstone326 Oct 21, 2015
18df285
reorganize and rename methods
amstone326 Oct 21, 2015
55462cb
add check for 0 scale factor
amstone326 Oct 21, 2015
a8bbea8
don't create exact scaled bitmap if we're just sizing for container
amstone326 Oct 21, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions app/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,24 @@ Copyright (c) 2012 readyState Software Ltd.</string>
<item>Enabled</item>
<item>Disabled</item>
</string-array>
<string-array name="target_density_labels">
<item>DENSITY_LOW</item>
<item>DENSITY_MEDIUM</item>
<item>DENSITY_HIGH</item>
<item>DENSITY_280</item>
<item>DENSITY_XHIGH</item>
<item>DENSITY_400</item>
<item>DENSITY_XXHIGH</item>
</string-array>
<string-array name="target_density_vals">
<item>120</item>
<item>160</item>
<item>240</item>
<item>280</item>
<item>320</item>
<item>400</item>
<item>480</item>
</string-array>

<item name="detail_size_cutoff" format="integer" type="integer">500</item>

Expand Down
13 changes: 13 additions & 0 deletions app/res/xml/preferences_developer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,17 @@ the License.
android:entryValues="@array/pref_enabled_vals"
android:key="cc-alternate-question-text-format"
android:title="Image Above Question Text Enabled" />
<ListPreference
android:enabled="true"
android:entries="@array/pref_enabled_labels"
android:entryValues="@array/pref_enabled_vals"
android:key="cc-use-smart-inflation"
android:title="Smart Image Inflation Enabled" />
<ListPreference
android:enabled="true"
android:entries="@array/target_density_labels"
android:entryValues="@array/target_density_vals"
android:key="cc-target-density"
android:defaultValue="160"
android:title="Target Screen Density for Inflation" />
</PreferenceScreen>
3 changes: 1 addition & 2 deletions app/src/org/commcare/android/adapters/EntityListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public class EntityListAdapter implements ListAdapter {
EntitySearcher mCurrentSortThread = null;
Object mSyncLock = new Object();

public static int SCALE_FACTOR = 1; // How much we want to degrade the image quality to enable faster laoding. TODO: get cleverer
private CachingAsyncImageLoader mImageLoader; // Asyncronous image loader, allows rows with images to scroll smoothly
private boolean usesGridView = false; // false until we determine the Detail has at least one <grid> block

Expand Down Expand Up @@ -122,7 +121,7 @@ public EntityListAdapter(Activity activity, Detail detail,

this.tts = tts;
if (android.os.Build.VERSION.SDK_INT >= 14) {
mImageLoader = new CachingAsyncImageLoader(context, SCALE_FACTOR);
mImageLoader = new CachingAsyncImageLoader(context);
} else {
mImageLoader = null;
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/org/commcare/android/adapters/MenuAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import org.commcare.android.javarosa.AndroidLogger;
import org.commcare.android.models.AndroidSessionWrapper;
import org.commcare.android.view.ViewUtil;
import org.commcare.android.util.MediaUtil;
import org.commcare.dalvik.R;
import org.commcare.dalvik.application.CommCareApplication;
import org.commcare.dalvik.preferences.DeveloperPreferences;
Expand Down Expand Up @@ -290,7 +290,7 @@ public View getView(int i, View v, ViewGroup vg) {

String imageURI = mObject.getImageURI();

Bitmap image = ViewUtil.inflateDisplayImage(context, imageURI);
Bitmap image = MediaUtil.inflateDisplayImage(context, imageURI);
if (image != null && mIconView != null) {
mIconView.setImageBitmap(image);
mIconView.setAdjustViewBounds(true);
Expand Down
5 changes: 2 additions & 3 deletions app/src/org/commcare/android/framework/CommCareActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
import org.commcare.android.tasks.templates.CommCareTaskConnector;
import org.commcare.android.util.AndroidUtil;
import org.commcare.android.util.MarkupUtil;
import org.commcare.android.util.MediaUtil;
import org.commcare.android.util.SessionStateUninitException;
import org.commcare.android.util.StringUtils;
import org.commcare.android.view.ViewUtil;
import org.commcare.dalvik.BuildConfig;
import org.commcare.dalvik.application.CommCareApp;
import org.commcare.dalvik.application.CommCareApplication;
Expand Down Expand Up @@ -264,13 +264,12 @@ public void updateCommCareBanner() {

Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int screenHeight = display.getHeight();

int maxBannerHeight = screenHeight / 4;

// Override default CommCare banner if requested
String customBannerURI = app.getAppPreferences().getString(CommCarePreferences.BRAND_BANNER_HOME, "");
if (!"".equals(customBannerURI)) {
Bitmap bitmap = ViewUtil.inflateDisplayImage(this, customBannerURI);
Bitmap bitmap = MediaUtil.inflateDisplayImage(this, customBannerURI, display.getWidth(), maxBannerHeight);
if (bitmap != null) {
if (topBannerImageView != null) {
topBannerImageView.setMaxHeight(maxBannerHeight);
Expand Down
38 changes: 22 additions & 16 deletions app/src/org/commcare/android/util/CachingAsyncImageLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.os.AsyncTask;
import android.util.LruCache;
import android.widget.ImageView;

/**
* Class used for managing the LoadImageTasks that load images into a list.
* Ensures that proper caching occurs and attempts to limit overflows
Expand All @@ -19,29 +20,29 @@
@SuppressLint("NewApi")
public class CachingAsyncImageLoader implements ComponentCallbacks2 {
private TCLruCache cache;
public static final int RETRY_LIMIT=5; // how many times we should retry loading the image before giving up
private int scaleFactor; // how much to degrade the quality of the image to ensure no heap overflow
private final int CACHE_DIVISOR =2 ;
private final int CACHE_DIVISOR =2;
private Context context;

public CachingAsyncImageLoader(Context context, int mScaleFactor) {
public CachingAsyncImageLoader(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(
Context.ACTIVITY_SERVICE);
int memoryClass = (am.getMemoryClass() * 1024 * 1024)/CACHE_DIVISOR; //basically, set the heap to be everything we can get
cache = new TCLruCache(memoryClass);
scaleFactor = mScaleFactor;
this.context = context;
this.cache = new TCLruCache(memoryClass);
}

public void display(String url, ImageView imageview, int defaultresource) {
imageview.setImageResource(defaultresource);
public void display(String url, ImageView imageView, int defaultResource,
int boundingWidth, int boundingHeight) {
imageView.setImageResource(defaultResource);
Bitmap image;
synchronized(cache) {
image = cache.get(url);
}
if (image != null) {
imageview.setImageBitmap(image);
imageView.setImageBitmap(image);
}
else {
new SetImageTask(imageview).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, url);
new SetImageTask(imageView, this.context, boundingWidth, boundingHeight).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, url);
}
}

Expand All @@ -59,10 +60,16 @@ public TCLruCache(int maxSize) {
*
*/
private class SetImageTask extends AsyncTask<String, Void, Bitmap> {
private ImageView mImageView = null;
private ImageView mImageView;
private Context mContext;
private int mBoundingWidth;
private int mBoundingHeight;

public SetImageTask(ImageView imageView) {
public SetImageTask(ImageView imageView, Context context, int maxWidth, int maxHeight) {
mImageView = imageView;
mContext = context;
mBoundingWidth = maxWidth;
mBoundingHeight = maxHeight;
}

protected Bitmap doInBackground(String... file) {
Expand All @@ -76,13 +83,12 @@ protected void onPostExecute(Bitmap result) {
}
}

public Bitmap getImageBitmap(String file){
Bitmap bitmap = null;
bitmap = MediaUtil.getScaledImageFromReference(file, scaleFactor);
public Bitmap getImageBitmap(String filePath) {
Bitmap bitmap = MediaUtil.inflateDisplayImage(mContext, filePath, mBoundingWidth, mBoundingHeight);

if (bitmap != null) {
synchronized(cache) {
cache.put(file, bitmap);
cache.put(filePath, bitmap);
}
}

Expand Down
Loading