Last active
August 29, 2015 14:26
-
-
Save SelvinPL/916ea634693fda05545b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //naive way of not getting OOME (still terrible but...) | |
| //in loop DO NOT DECODE TO BITMAP | |
| //map.put(TAG_Photo, bitmap); should become: | |
| map.put(TAG_Photo, Base64.decode(photo, Base64.DEFAULT)); //byte array take less space than coresponded base64 string | |
| SimpleAdapter adapter = ...; | |
| adapter.setViewBinder(new SimpleAdapter.ViewBinder() { | |
| @Override | |
| public boolean setViewValue(View view, Object data, String textRepresentation) { | |
| if(view.getId() == R.id.imageView1) { //view is our ImageView | |
| ImageView imageView = (ImageView)view; | |
| Drawable drawable = imageView.getDrawable(); | |
| //trying to recycle old bitmap to avoid OOME | |
| if (drawable != null && drawable instanceof BitmapDrawable) { | |
| BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; | |
| Bitmap bitmapold = bitmapDrawable.getBitmap(); | |
| bitmapold.recycle(); | |
| } | |
| byte[] imageAsBytes = (byte[])data; | |
| //TERRIBLE IDEA - IT SHOULD BE DONE ON NON UI THREAD | |
| Bitmap bitmap = BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length); | |
| imageView.setImageBitmap(bitmap); | |
| return true; | |
| } | |
| //Otherwise do default stuff | |
| return false; | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment