Skip to content

Commit

Permalink
Update bitmap differently
Browse files Browse the repository at this point in the history
- Okay, so perhaps relying on invalidate() calls in order to update the image bitmap wasn't the best idea. No we're simply overriding the usual setImage... methods instead. From my tests, this produced similar results... minus the StackOverflowErrors from certain image updates. (For example, updating the border/selector after the image has changed)

Hopefully this solves issue #23
  • Loading branch information
Pkmmte Xeleon committed Jan 16, 2015
1 parent 70ec35b commit b92cee8
Showing 1 changed file with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
Expand Down Expand Up @@ -272,38 +271,44 @@ public boolean dispatchTouchEvent(MotionEvent event) {
return super.dispatchTouchEvent(event);
}

public void invalidate(Rect dirty) {
super.invalidate(dirty);
@Override
public void setImageURI(Uri uri) {
super.setImageURI(uri);

long time = System.currentTimeMillis();
// Extract a Bitmap out of the drawable & set it as the main shader
image = drawableToBitmap(getDrawable());
if(shader != null || canvasSize > 0)
if(shader == null && canvasSize > 0)
refreshBitmapShader();
Log.w(TAG, "Bitmap extraction took " + (System.currentTimeMillis() - time) + "ms");
}

public void invalidate(int l, int t, int r, int b) {
super.invalidate(l, t, r, b);
@Override
public void setImageResource(int resId) {
super.setImageResource(resId);

long time = System.currentTimeMillis();
// Extract a Bitmap out of the drawable & set it as the main shader
image = drawableToBitmap(getDrawable());
if(shader != null || canvasSize > 0)
if(shader == null && canvasSize > 0)
refreshBitmapShader();
Log.w(TAG, "Bitmap extraction took " + (System.currentTimeMillis() - time) + "ms");
}

@Override
public void invalidate() {
super.invalidate();
public void setImageDrawable(Drawable drawable) {
super.setImageDrawable(drawable);

long time = System.currentTimeMillis();
// Extract a Bitmap out of the drawable & set it as the main shader
image = drawableToBitmap(getDrawable());
if(shader != null || canvasSize > 0)
if(shader == null && canvasSize > 0)
refreshBitmapShader();
}

@Override
public void setImageBitmap(Bitmap bm) {
super.setImageBitmap(bm);

// Extract a Bitmap out of the drawable & set it as the main shader
image = bm;
if(shader == null && canvasSize > 0)
refreshBitmapShader();
Log.w(TAG, "Bitmap extraction took " + (System.currentTimeMillis() - time) + "ms");
}

@Override
Expand Down Expand Up @@ -407,8 +412,11 @@ public void setIconModeEnabled(boolean e) {}
* the Circle upon drawing.
*/
public void refreshBitmapShader() {
if (image == null) return;
if (image == null)
return;
long time = System.currentTimeMillis();
shader = new BitmapShader(Bitmap.createScaledBitmap(image, canvasSize, canvasSize, false), Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Log.w(TAG, "refreshBitmapShader took " + (System.currentTimeMillis() - time) + "ms");
}

/**
Expand Down

0 comments on commit b92cee8

Please sign in to comment.