Skip to content

Instantly share code, notes, and snippets.

View duanhong169's full-sized avatar
💭
I may be slow to respond.

Hong Duan duanhong169

💭
I may be slow to respond.
View GitHub Profile
@duanhong169
duanhong169 / boost.sh
Last active February 18, 2022 04:08 — forked from rsobik/boost.sh
#===============================================================================
# Filename: boost.sh
# Author: Pete Goodliffe
# Copyright: (c) Copyright 2009 Pete Goodliffe
# Licence: Please feel free to use this, with attribution
# Modified version
#===============================================================================
#
# Builds a Boost framework for the iPhone.
# Creates a set of universal libraries that can be used on an iPhone and in the
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <linux/netdevice.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <sys/system_properties.h>
#include <stdio.h>
char cmd_res_line[256];
#import <Foundation/Foundation.h>
@interface BDSBlockingQueue : NSObject
- (void)enqueue:(id)item;
- (id)dequeue;
@end
public static VersionedOperation () {
final int sdkVersion = Integer.parseInt(Build.VERSION.SDK);
if (sdkVersion > Build.VERSION_CODES.ECLAIR) {
// do something with new API features
} else {
// do normal
}
}
private DiskLruCache mDiskLruCache;
private final Object mDiskCacheLock = new Object();
private boolean mDiskCacheStarting = true;
private static final int DISK_CACHE_SIZE = 1024 * 1024 * 10; // 10MB
private static final String DISK_CACHE_SUBDIR = "disk_cache";
File cacheDir = getDiskCacheDir(this, DISK_CACHE_SUBDIR);
new InitDiskCacheTask().execute(cacheDir);
class InitDiskCacheTask extends AsyncTask<File, Void, Void> {
public void addBitmapToMemoryCache(String key, Bitmap bitmap) {
if (getBitmapFromMemCache(key) == null) {
mMemoryCache.put(key, bitmap);
}
}
public Bitmap getBitmapFromMemCache(String key) {
return mMemoryCache.get(key);
}
private LruCache<String, BitmapDrawable> mMemoryCache;
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
// 使用最大可使用内存的1/8作为缓存
final int cacheSize = maxMemory / 8;
mMemoryCache = new LruCache<String, BitmapDrawable>(cacheSize) {
/**
/**
* 如果当前存在一致的任务,返回false,代表不需要新建任务,否则返回true
*/
public static boolean cancelPotentialWork(Object data, ImageView imageView) {
final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView);
if (bitmapWorkerTask != null) {
final Object bitmapData = bitmapWorkerTask.data;
if (bitmapData == null || !bitmapData.equals(data)) {
bitmapWorkerTask.cancel(true);
/**
* 比较之前传入的ImageView在当前时刻关联的`AsyncTask`是否等于自身
* 来确定是否需要将结果返回给ImageView
*/
private ImageView getAttachedImageView() {
final ImageView imageView = imageViewReference.get();
final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView);
if (this == bitmapWorkerTask) {
return imageView;
private static BitmapWorkerTask getBitmapWorkerTask(ImageView imageView) {
if (imageView != null) {
final Drawable drawable = imageView.getDrawable();
if (drawable instanceof AsyncDrawable) {
final AsyncDrawable asyncDrawable = (AsyncDrawable) drawable;
return asyncDrawable.getBitmapWorkerTask();
}
}
return null;
}