[android-developers] Re: bitmap reuse via BitmapFactory.Options.inBitmap?

2011-09-23 Thread elliot
If anyone needs an example, here you go-

public class BitmapReuseActivity extends Activity {

private Paint mPaint = new Paint();
private Rect mRect = new Rect(0,0, 123, 109);
private Canvas mCanvas = new Canvas();
private Bitmap mBitmap = Bitmap.createBitmap(124, 110,
Bitmap.Config.ARGB_);
private Resources mResources;

private static BitmapFactory.Options sBitmapOptions =
new BitmapFactory.Options();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.bitmap_reuse_listview);

mResources = getResources();

// setup bitmap reuse options.
sBitmapOptions.inBitmap = mBitmap;
sBitmapOptions.inMutable = true;
sBitmapOptions.inSampleSize = 1;

// listview of 100 images.
ListView listview =
(ListView) findViewById(R.id.listView);

listview.setAdapter(new BaseAdapter() {

public View getView(int position, View convertView,
ViewGroup parent) {

ImageView imageView;

if (convertView == null) {
imageView = new
ImageView(BitmapReuseActivity.this);
} else {
imageView = (ImageView) convertView;
}

// decode into existing bitmap.
Bitmap bitmap =
BitmapFactory.decodeResource(mResources,
  R.drawable.my_image, sBitmapOptions);

if (bitmap != null) {
imageView.setImageBitmap(bitmap);
}

return imageView;

}

public long getItemId(int position) {
return 0;
}

public Object getItem(int position) {
return null;
}

public int getCount() {
return 100;
}
});

}

}

Elliot

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] bitmap reuse via BitmapFactory.Options.inBitmap?

2011-08-08 Thread elliot
I have a ListView that I need to populate with PNGs from Assets.  My
problem is that I want to reuse Bitmaps as the ListView scrolls.

I am running Honeycomb and I see that BitmapFactory.Options has the
field inBitmap, which I am setting. Unfortunately, I keep getting a
stack trace when I call BitmapFactory.decodeStream (InputStream is,
Rect outPadding, BitmapFactory.Options opts):

D/skia( 2310): --- decoder-decode returned false
D/App: Exception :java.lang.IllegalArgumentException: Problem decoding
into existing bitmap and Message:Problem decoding into existing bitmap
W/System.err( 2310): java.lang.IllegalArgumentException: Problem
decoding into existing bitmap
W/System.err( 2310):at
android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:496)


My code looks like the following, and fails in the getLogo() method.

public class SomeClass {
  private static BitmapFactory.Options sBitmapOptions;

  public static Bitmap getLogo() {

if (sBitmapOptions == null) {
  initOptions();
}

Bitmap bitmap = getBitMap();
Rect rect = new Rect();
sBitmapOptions.inBitmap = bitmap;

//
// exception thrown here.
//
Bitmap decodedBitmap = BitmapFactory
  .decodeStream(assetManager.open(somefile.png),
rect,
sBitmapOptions);

return decodedBitmap;
  }

  private static void initOptions() {
sBitmapOptions = new BitmapFactory.Options();
sBitmapOptions.inDither = false;
sBitmapOptions.inScaled = true;
sBitmapOptions.inSampleSize = 1;
sBitmapOptions.inPurgeable = false;
  }

  private static Bitmap getBitMap() {
// has logic to return new or recycled bitmap...
  }

}

Any ideas/suggestions or sample code of reusing Bitmaps?

Thanks-
Elliot

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: customized radiobutton

2009-09-27 Thread Elliot Schwartz

I think there are two options:
- use android:button to override the radio button with your image
- set android:button to @null and then the radio button will go away
and you'll be able to see your image.

Regards,

elliot

On Sep 25, 4:02 pm, jonathan topcod...@gmail.com wrote:
 I tries to modify the look of radiobutton:
 style name=MyRadioButton
 parent=android:Widget.CompoundButton.RadioButton
         item name=android:textColor#FF/item
         item name=android:background@drawable/btn_radio/item
 /style

 android:background doesn't seem to be the right property, the radio
 button image gets stretched and placed in the background of the radio
 button itself and its label.
 thanks for any pointers

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---