Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
lfkdsk committed Feb 22, 2016
1 parent bf1ab4e commit f9a8595
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.lfk.justwetools.Utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
Expand Down Expand Up @@ -70,6 +72,7 @@ public enum Type {
FIFO, LIFO
}

private static Context mContext;

/**
* 单例获得该实例对象
Expand Down Expand Up @@ -111,6 +114,7 @@ public void handleMessage(Message msg) {
try {
mPoolSemaphore.acquire();
} catch (InterruptedException e) {

}
}
};
Expand All @@ -129,13 +133,11 @@ public void handleMessage(Message msg) {
protected int sizeOf(String key, Bitmap value) {
return value.getRowBytes() * value.getHeight();
}

;
};

mThreadPool = Executors.newFixedThreadPool(threadCount);
mPoolSemaphore = new Semaphore(threadCount);
mTasks = new LinkedList<Runnable>();
mTasks = new LinkedList<>();
mType = type == null ? Type.LIFO : type;

}
Expand All @@ -159,7 +161,7 @@ public void handleMessage(Message msg) {
Bitmap bm = holder.bitmap;
String path = holder.path;
if (imageView.getTag().toString().equals(path)) {
imageView.setImageBitmap(bm);
imageView.setBackground(new BitmapDrawable(mContext.getResources(), bm));
}
}
};
Expand Down Expand Up @@ -237,8 +239,10 @@ private synchronized Runnable getTask() {
*
* @return
*/
public static ImageLoader getInstance(int threadCount, Type type) {

public static ImageLoader getInstance(Context context,
int threadCount,
Type type) {
ImageLoader.mContext = context;
if (mInstance == null) {
synchronized (ImageLoader.class) {
if (mInstance == null) {
Expand Down Expand Up @@ -351,9 +355,8 @@ private Bitmap decodeSampledBitmapFromResource(String pathName,
reqHeight);
// 使用获取到的inSampleSize值再次解析图片
options.inJustDecodeBounds = false;
Bitmap bitmap = BitmapFactory.decodeFile(pathName, options);

return bitmap;
return BitmapFactory.decodeFile(pathName, options);
}

private class ImgBeanHolder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,7 @@ public static Bitmap drawable2Bitmap(Drawable drawable) {
* @return
*/
public static Drawable Bitmap2Drawable(Context context, Bitmap bitmap) {
BitmapDrawable bd = new BitmapDrawable(context.getResources(), bitmap);
return bd;
return new BitmapDrawable(context.getResources(), bitmap);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lfk.justwetools.R;
Expand All @@ -20,11 +22,14 @@ public class CartoonAdapter extends BaseAdapter {
private ArrayList<String> userList;
private LayoutInflater mInflater;
private ImageLoader mImageLoader;
private Context mContext;
private int width, height;

public CartoonAdapter(Context context, ArrayList<String> userList) {
this.userList = userList;
this.mContext = context;
this.mInflater = LayoutInflater.from(context);
this.mImageLoader = ImageLoader.getInstance(3, ImageLoader.Type.LIFO);
this.mImageLoader = ImageLoader.getInstance(mContext,4, ImageLoader.Type.LIFO);
}

private class ViewHolder {
Expand All @@ -49,12 +54,19 @@ public long getItemId(int position) {

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
ViewHolder holder;

if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.cartoon_item, null);
holder.imageView = (ImageView) convertView.findViewById(R.id.cartoon_img);

WindowManager manager = (android.view.WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(manager.getDefaultDisplay().getWidth(),
manager.getDefaultDisplay().getHeight());

holder.imageView.setLayoutParams(params);

holder.textView = (TextView) convertView.findViewById(R.id.cartoon_num);
convertView.setTag(holder);
} else {
Expand All @@ -66,7 +78,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
mImageLoader.loadImage(userList.get(position),
holder.imageView);

// holder.textView.setText("");
holder.textView.setText("");

return convertView;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.os.Environment;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.ListView;

Expand Down Expand Up @@ -60,35 +59,35 @@ private ArrayList<String> getFileList() {

File[] list = new File(dirPath).listFiles();

Arrays.sort(list);

for (int i = 0; i < list.length; i++) {
Log.e("lfk", list[i].getName());
if (list[i].getName().endsWith(".jpg")
|| list[i].getName().endsWith(".png"))
fileList.add(list[i].getPath());
}

Arrays.sort(list);

return fileList;
}

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
int count = getChildCount();
// 为ViewGroup设定高度
MarginLayoutParams params = (MarginLayoutParams) getLayoutParams();
params.height = mScreenHeight * count;

setLayoutParams(params);

for (int i = 0; i < count; i++) {
View childView = getChildAt(i);
if (childView.getVisibility() != View.GONE) {
// 摆放每子View的位置
childView.layout(1, mScreenHeight * i,
r, (i + 1) * mScreenHeight);
}
}
}
// @Override
// protected void onLayout(boolean changed, int l, int t, int r, int b) {
// super.onLayout(changed, l, t, r, b);
// int count = getChildCount();
// // 为ViewGroup设定高度
// MarginLayoutParams params = (MarginLayoutParams) getLayoutParams();
// params.height = mScreenHeight * count;
//
// setLayoutParams(params);
//
// for (int i = 0; i < count; i++) {
// View childView = getChildAt(i);
// if (childView.getVisibility() != View.GONE) {
// // 摆放每子View的位置
// childView.layout(1, mScreenHeight * i,
// r, (i + 1) * mScreenHeight);
// }
// }
// }
}
1 change: 1 addition & 0 deletions justwetools/src/main/res/layout/cartoon_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<ImageView
android:id="@+id/cartoon_img"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />

Expand Down
2 changes: 1 addition & 1 deletion simple/src/main/res/layout/activity_cartoon_activiy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
tools:context=".Activity.CartoonActivity">
<com.lfk.justwetools.View.CartoonView.CartoonView
android:id="@+id/cartoon_view"
app:dir_path="/DrawAPicture/picture"
app:dir_path="/1"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.lfk.justwetools.View.CartoonView.CartoonView>
Expand Down

0 comments on commit f9a8595

Please sign in to comment.