Merge "Improve AyncTask throughput inside WidgetPreviewLoader" into ub-launcher3-burnaby

This commit is contained in:
Hyunyoung Song 2015-06-05 21:14:32 +00:00 committed by Android (Google) Code Review
commit 90429e11e7
3 changed files with 21 additions and 11 deletions

View File

@ -586,26 +586,26 @@ public class WidgetPreviewLoader {
protected Bitmap doInBackground(Void... params) {
Bitmap unusedBitmap = null;
// If already cancelled before this gets to run in the background, then return early
if (isCancelled()) {
return null;
}
synchronized (mUnusedBitmaps) {
// If already cancelled before this gets to run in the background, then return early
if (isCancelled()) {
return null;
}
// Check if we can use a bitmap
// Check if we can re-use a bitmap
for (Bitmap candidate : mUnusedBitmaps) {
if (candidate != null && candidate.isMutable() &&
candidate.getWidth() == mPreviewWidth &&
candidate.getHeight() == mPreviewHeight) {
unusedBitmap = candidate;
mUnusedBitmaps.remove(unusedBitmap);
break;
}
}
}
if (unusedBitmap == null) {
unusedBitmap = Bitmap.createBitmap(mPreviewWidth, mPreviewHeight, Config.ARGB_8888);
} else {
mUnusedBitmaps.remove(unusedBitmap);
}
// creating a bitmap is expensive. Do not do this inside synchronized block.
if (unusedBitmap == null) {
unusedBitmap = Bitmap.createBitmap(mPreviewWidth, mPreviewHeight, Config.ARGB_8888);
}
// If cancelled now, don't bother reading the preview from the DB
if (isCancelled()) {

View File

@ -26,6 +26,7 @@ import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnLayoutChangeListener;
import android.view.ViewPropertyAnimator;
import android.widget.LinearLayout;
import android.widget.TextView;
@ -175,7 +176,8 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
if (bitmap != null) {
mWidgetImage.setBitmap(bitmap);
mWidgetImage.setAlpha(0f);
mWidgetImage.animate().alpha(1.0f).setDuration(FADE_IN_DURATION_MS);
ViewPropertyAnimator anim = mWidgetImage.animate();
anim.alpha(1.0f).setDuration(FADE_IN_DURATION_MS);
}
}

View File

@ -64,6 +64,14 @@ public class WidgetImageView extends View {
}
}
/**
* Prevents the inefficient alpha view rendering.
*/
@Override
public boolean hasOverlappingRendering() {
return false;
}
private void updateDstRectF() {
if (mBitmap.getWidth() > getWidth()) {
float scale = ((float) getWidth()) / mBitmap.getWidth();