Bitmapfun Sample: Minor updates/fixes.
Change-Id: I71dce2fdbe41ff67cc0aac9456d72d9aa7cb8318
This commit is contained in:
@@ -14,7 +14,7 @@ repositories {
|
||||
|
||||
android {
|
||||
compileSdkVersion 19
|
||||
buildToolsVersion "18.1.1"
|
||||
buildToolsVersion "19.0.0"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 7
|
||||
@@ -23,5 +23,5 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.android.support:support-v4:18.0.0'
|
||||
compile 'com.android.support:support-v4:19.0.+'
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.example.android.bitmapfun.ui;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.ActionBar;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
@@ -48,7 +49,7 @@ public class ImageDetailActivity extends FragmentActivity implements OnClickList
|
||||
private ImageFetcher mImageFetcher;
|
||||
private ViewPager mPager;
|
||||
|
||||
@TargetApi(11)
|
||||
@TargetApi(VERSION_CODES.HONEYCOMB)
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
@@ -199,7 +200,7 @@ public class ImageDetailActivity extends FragmentActivity implements OnClickList
|
||||
* Set on the ImageView in the ViewPager children fragments, to enable/disable low profile mode
|
||||
* when the ImageView is touched.
|
||||
*/
|
||||
@TargetApi(11)
|
||||
@TargetApi(VERSION_CODES.HONEYCOMB)
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final int vis = mPager.getSystemUiVisibility();
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.annotation.TargetApi;
|
||||
import android.app.ActivityOptions;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.Log;
|
||||
@@ -134,6 +135,13 @@ public class ImageGridFragment extends Fragment implements AdapterView.OnItemCli
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.d(TAG, "onCreateView - numColumns set to " + numColumns);
|
||||
}
|
||||
if (Utils.hasJellyBean()) {
|
||||
mGridView.getViewTreeObserver()
|
||||
.removeOnGlobalLayoutListener(this);
|
||||
} else {
|
||||
mGridView.getViewTreeObserver()
|
||||
.removeGlobalOnLayoutListener(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,7 +171,7 @@ public class ImageGridFragment extends Fragment implements AdapterView.OnItemCli
|
||||
mImageFetcher.closeCache();
|
||||
}
|
||||
|
||||
@TargetApi(16)
|
||||
@TargetApi(VERSION_CODES.JELLY_BEAN)
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
|
||||
final Intent i = new Intent(getActivity(), ImageDetailActivity.class);
|
||||
@@ -226,6 +234,11 @@ public class ImageGridFragment extends Fragment implements AdapterView.OnItemCli
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
// If columns have yet to be determined, return no items
|
||||
if (getNumColumns() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Size + number of columns for top empty row
|
||||
return Images.imageThumbUrls.length + mNumColumns;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.graphics.Bitmap.CompressFormat;
|
||||
import android.graphics.Bitmap.Config;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.StatFs;
|
||||
@@ -354,24 +355,26 @@ public class ImageCache {
|
||||
Bitmap bitmap = null;
|
||||
|
||||
if (mReusableBitmaps != null && !mReusableBitmaps.isEmpty()) {
|
||||
final Iterator<SoftReference<Bitmap>> iterator = mReusableBitmaps.iterator();
|
||||
Bitmap item;
|
||||
synchronized (mReusableBitmaps) {
|
||||
final Iterator<SoftReference<Bitmap>> iterator = mReusableBitmaps.iterator();
|
||||
Bitmap item;
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
item = iterator.next().get();
|
||||
while (iterator.hasNext()) {
|
||||
item = iterator.next().get();
|
||||
|
||||
if (null != item && item.isMutable()) {
|
||||
// Check to see it the item can be used for inBitmap
|
||||
if (canUseForInBitmap(item, options)) {
|
||||
bitmap = item;
|
||||
if (null != item && item.isMutable()) {
|
||||
// Check to see it the item can be used for inBitmap
|
||||
if (canUseForInBitmap(item, options)) {
|
||||
bitmap = item;
|
||||
|
||||
// Remove from reusable set so it can't be used again
|
||||
// Remove from reusable set so it can't be used again
|
||||
iterator.remove();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// Remove from the set if the reference has been cleared.
|
||||
iterator.remove();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// Remove from the set if the reference has been cleared.
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -503,6 +506,7 @@ public class ImageCache {
|
||||
* @return true if <code>candidate</code> can be used for inBitmap re-use with
|
||||
* <code>targetOptions</code>
|
||||
*/
|
||||
@TargetApi(VERSION_CODES.KITKAT)
|
||||
private static boolean canUseForInBitmap(
|
||||
Bitmap candidate, BitmapFactory.Options targetOptions) {
|
||||
|
||||
@@ -594,7 +598,7 @@ public class ImageCache {
|
||||
* @param value
|
||||
* @return size in bytes
|
||||
*/
|
||||
@TargetApi(12)
|
||||
@TargetApi(VERSION_CODES.KITKAT)
|
||||
public static int getBitmapSize(BitmapDrawable value) {
|
||||
Bitmap bitmap = value.getBitmap();
|
||||
|
||||
@@ -618,7 +622,7 @@ public class ImageCache {
|
||||
* @return True if external storage is removable (like an SD card), false
|
||||
* otherwise.
|
||||
*/
|
||||
@TargetApi(9)
|
||||
@TargetApi(VERSION_CODES.GINGERBREAD)
|
||||
public static boolean isExternalStorageRemovable() {
|
||||
if (Utils.hasGingerbread()) {
|
||||
return Environment.isExternalStorageRemovable();
|
||||
@@ -632,7 +636,7 @@ public class ImageCache {
|
||||
* @param context The context to use
|
||||
* @return The external cache dir
|
||||
*/
|
||||
@TargetApi(8)
|
||||
@TargetApi(VERSION_CODES.FROYO)
|
||||
public static File getExternalCacheDir(Context context) {
|
||||
if (Utils.hasFroyo()) {
|
||||
return context.getExternalCacheDir();
|
||||
@@ -649,7 +653,7 @@ public class ImageCache {
|
||||
* @param path The path to check
|
||||
* @return The space available in bytes
|
||||
*/
|
||||
@TargetApi(9)
|
||||
@TargetApi(VERSION_CODES.GINGERBREAD)
|
||||
public static long getUsableSpace(File path) {
|
||||
if (Utils.hasGingerbread()) {
|
||||
return path.getUsableSpace();
|
||||
|
||||
@@ -16,20 +16,22 @@
|
||||
|
||||
package com.example.android.bitmapfun.util;
|
||||
|
||||
import com.example.android.bitmapfun.ui.ImageDetailActivity;
|
||||
import com.example.android.bitmapfun.ui.ImageGridActivity;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.os.Build;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.os.StrictMode;
|
||||
|
||||
import com.example.android.bitmapfun.ui.ImageDetailActivity;
|
||||
import com.example.android.bitmapfun.ui.ImageGridActivity;
|
||||
|
||||
/**
|
||||
* Class containing some static utility methods.
|
||||
*/
|
||||
public class Utils {
|
||||
private Utils() {};
|
||||
|
||||
@TargetApi(11)
|
||||
|
||||
@TargetApi(VERSION_CODES.HONEYCOMB)
|
||||
public static void enableStrictMode() {
|
||||
if (Utils.hasGingerbread()) {
|
||||
StrictMode.ThreadPolicy.Builder threadPolicyBuilder =
|
||||
|
||||
Reference in New Issue
Block a user