test
test 001
代码测试1import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import android.app.Activity; import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import com.thinkland.demo.comic.data.BookShelfAsyncImageLoader; import com.thinkland.demo.comic.data.BookShelfAsyncImageLoader.ImageCallback; import com.thinkland.demo.comic.data.BookShelfListViewCache; import com.thinkland.demo.comic.view.comicViewHelper; public class BookshelfAdapter extends ArrayAdapter { private ListView listView; private BookShelfAsyncImageLoader asyncImageLoader; private String TAG = "bookshelfAdapter"; private ArrayList<Map<String, Object>> list; private LayoutInflater mInflater; private Bitmap cachedImage; private Activity activity; private Resources res; public BookshelfAdapter(Activity activity, List<Map<String, Object>> imageAndTexts, Context context,ListView listView) { super(context, 0, imageAndTexts); this.listView = listView; this.mInflater = LayoutInflater.from(context); asyncImageLoader = new BookShelfAsyncImageLoader(); this.list = (ArrayList<Map<String, Object>>) imageAndTexts; this.activity = activity; this.res = activity.getResources(); } public View getView(int position, View convertView, ViewGroup parent) { // Activity activity = (Activity) getContext(); // Log.v("sssss", "--------------------- position : " + position); // Inflate the views from XML // Log.v("sssss","convertView := " + convertView); View rowView = convertView; BookShelfListViewCache viewCache; if (rowView == null) { // Log.v("sssss", "--------------------- rowView - position : " + position); LayoutInflater inflater = activity.getLayoutInflater(); rowView = mInflater.inflate(R.layout.bookshelf_simpleinfo_list, null); viewCache = new BookShelfListViewCache(rowView); rowView.setTag(viewCache); } else { viewCache = (BookShelfListViewCache) rowView.getTag(); } Map<String, Object> map = (Map<String, Object>) getItem(position); String imageUrl = (String) map.get("TOTALPATH"); String book_name = (String) map.get("BOOK_NAME"); // Log.e("ssssss", "------------------- position | imageUrl : " + position + " | " + imageUrl); // Load the image and set it on the ImageView ImageView imageView = viewCache.getImgView(); if(imageUrl != null && !"=".equals(imageUrl)){ imageView.setTag(imageUrl); Bitmap bitmap; ZipFile zf; try { zf = new ZipFile(imageUrl); ZipEntry ze = null; for(Enumeration<ZipEntry> e = (Enumeration<ZipEntry>) zf.entries();e.hasMoreElements();) { ze = e.nextElement(); break; } // Log.v(TAG,"imageUrl := " + imageUrl); // Log.v(TAG,"ze.getName() = "+ze.getName()); InputStream in; in = zf.getInputStream(ze); bitmap = comicViewHelper.getBitmapByStream(in); //============================== float scaleWidth = (float) 50/ bitmap.getWidth(); float scaleHeight = (float) 65/bitmap.getHeight(); Matrix matrix=new Matrix(); matrix.postScale(scaleWidth, scaleHeight); Bitmap oldBitmap = bitmap; cachedImage = Bitmap.createBitmap(bitmap,0,0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); oldBitmap.recycle(); oldBitmap = null; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }else{ Bitmap lajiBp = BitmapFactory.decodeResource(res, R.drawable.zhengli); float scaleWidth = (float) 50/ lajiBp.getWidth(); float scaleHeight = (float) 65/lajiBp.getHeight(); Matrix matrix=new Matrix(); matrix.postScale(scaleWidth, scaleHeight); Bitmap oldBitmap = lajiBp; cachedImage = Bitmap.createBitmap(lajiBp,0,0, lajiBp.getWidth(), lajiBp.getHeight(), matrix, true); oldBitmap.recycle(); oldBitmap = null; } // // cachedImage = asyncImageLoader.loadDrawable(imageUrl, new ImageCallback() { // public void imageLoaded(Bitmap imageBitmap, String imageUrl) { // Log.e("ssssss", "------------------- imageUrl : " + imageUrl); // ImageView imageViewByTag = (ImageView) listView.findViewWithTag(imageUrl); // if (imageViewByTag != null) { // imageViewByTag.setImageBitmap(imageBitmap); // } // } // }); if (cachedImage == null) { // Log.v("sssss", "--------------------- check cachedImage - position : " + position); //try { imageView.setImageResource(R.drawable.loading); // Thread.sleep(200); // cachedImage = asyncImageLoader.loadDrawable(imageUrl, new ImageCallback() { // public void imageLoaded(Bitmap imageBitmap, String imageUrl) { // ImageView imageViewByTag = (ImageView) listView.findViewWithTag(imageUrl); // if (imageViewByTag != null) { // imageViewByTag.setImageBitmap(imageBitmap); // } // } // }); // } catch (InterruptedException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } }else{ // Log.v("ssss","cachedImage.width := " + cachedImage.getWidth()); // Log.v("ssss","cachedImage.heigth := " + cachedImage.getHeight()); // float scaleWidth = (float) 50/ cachedImage.getWidth(); // float scaleHeight = (float) 65/cachedImage.getHeight(); // // Matrix matrix=new Matrix(); // matrix.postScale(scaleWidth, scaleHeight); // // Bitmap aimg = Bitmap.createBitmap(cachedImage,0,0, cachedImage.getWidth(), cachedImage.getHeight(), matrix, true); imageView.setImageBitmap(cachedImage); // Log.v("ssss","aimg.width := " + aimg.getWidth()); // Log.v("ssss","imageView.width := " + imageView.getWidth()); } // Set the text on the TextView TextView bookname = viewCache.getBook_name(); bookname.setText(book_name); return rowView; } @Override public Map<String, Object> getItem(int position) { // TODO Auto-generated method stub return list.get(position); } }
posted on 2010-09-18 10:33 thinkland001 阅读(160) 评论(0) 收藏 举报