parent
4b81861a56
commit
25fafe5bab
Binary file not shown.
@ -0,0 +1,33 @@
|
||||
package com.allthelucky.common.view.network;
|
||||
|
||||
import com.android.http.RequestManager;
|
||||
import com.android.volley.toolbox.ImageLoader;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
/**
|
||||
* @description NetworkApp
|
||||
*
|
||||
* @author steven-pan
|
||||
*
|
||||
*/
|
||||
public class NetworkApp extends Application {
|
||||
|
||||
private static ImageLoader sImageLoader = null;
|
||||
|
||||
private final NetworkImageCache imageCacheMap = new NetworkImageCache();
|
||||
|
||||
public static ImageLoader getImageLoader() {
|
||||
return sImageLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
RequestManager.getInstance().init(NetworkApp.this);
|
||||
sImageLoader = new ImageLoader(RequestManager.getInstance()
|
||||
.getRequestQueue(), imageCacheMap);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
package com.allthelucky.common.view.network;
|
||||
|
||||
import com.android.volley.toolbox.ImageLoader.ImageCache;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.support.v4.util.LruCache;
|
||||
|
||||
/**
|
||||
* @description NetworkImageCache
|
||||
*
|
||||
* @auther steven-pan
|
||||
*/
|
||||
public class NetworkImageCache extends LruCache<String, Bitmap> implements
|
||||
ImageCache {
|
||||
|
||||
public NetworkImageCache() {
|
||||
this(getDefaultLruCacheSize());
|
||||
}
|
||||
|
||||
public NetworkImageCache(int sizeInKiloBytes) {
|
||||
super(sizeInKiloBytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int sizeOf(String key, Bitmap value) {
|
||||
return value.getRowBytes() * value.getHeight() / 1024;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap getBitmap(String url) {
|
||||
return get(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putBitmap(String url, Bitmap bitmap) {
|
||||
put(url, bitmap);
|
||||
}
|
||||
|
||||
public static int getDefaultLruCacheSize() {
|
||||
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
|
||||
final int cacheSize = maxMemory / 8;
|
||||
return cacheSize;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
package com.allthelucky.common.view.network;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.ImageView.ScaleType;
|
||||
|
||||
import com.allthelucky.common.view.ImageIndicatorView;
|
||||
import com.android.http.WebImageView;
|
||||
import com.app.library.common.view.R;
|
||||
|
||||
/**
|
||||
* Network ImageIndicatorView, by urls
|
||||
*
|
||||
* @author steven-pan
|
||||
*
|
||||
*/
|
||||
public class NetworkImageIndicatorView extends ImageIndicatorView {
|
||||
|
||||
public NetworkImageIndicatorView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public NetworkImageIndicatorView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置显示图片URL列表
|
||||
*
|
||||
* @param urlList
|
||||
* URL列表
|
||||
*/
|
||||
public void setupLayoutByImageUrl(final List<String> urlList) {
|
||||
if (urlList == null)
|
||||
throw new NullPointerException();
|
||||
|
||||
final int len = urlList.size();
|
||||
if (len > 0) {
|
||||
for (int index = 0; index < len; index++) {
|
||||
final WebImageView pageItem = new WebImageView(getContext());
|
||||
pageItem.setScaleType(ScaleType.FIT_XY);
|
||||
pageItem.setDefaultImageResId(R.drawable.ic_launcher);
|
||||
pageItem.setImageUrl(urlList.get(index),
|
||||
NetworkApp.getImageLoader());
|
||||
addViewItem(pageItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package com.allthelucky.common.view.sample;
|
||||
|
||||
import com.allthelucky.common.view.network.NetworkApp;
|
||||
|
||||
/**
|
||||
* SampleApp
|
||||
*
|
||||
* @author steven-pan
|
||||
*
|
||||
*/
|
||||
public class SampleApp extends NetworkApp {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in new issue