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