Bug 1341275: Rm redundant mActualHeight/Width variables. r=sebastian
These are already present in View.getHeight/Width and:
1) Having duplicated values can lead to bugs
2) Having them around makes it harder to see what's important in this code.
MozReview-Commit-ID: 7IvipoJXmF7
--- a/mobile/android/base/java/org/mozilla/gecko/widget/FaviconView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/widget/FaviconView.java
@@ -36,19 +36,16 @@ public class FaviconView extends ImageVi
private static final int DEFAULT_CORNER_RADIUS_DP = 2;
private Bitmap mIconBitmap;
// Reference to the unscaled bitmap, if any, to prevent repeated assignments of the same bitmap
// to the view from causing repeated rescalings (Some of the callers do this)
private Bitmap mUnscaledBitmap;
- private int mActualWidth;
- private int mActualHeight;
-
// Flag indicating if the most recently assigned image is considered likely to need scaling.
private boolean mScalingExpected;
// Dominant color of the favicon.
private int mDominantColor;
// Paint for drawing the background.
private static final Paint sBackgroundPaint;
@@ -100,23 +97,20 @@ public class FaviconView extends ImageVi
mResources = getResources();
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
// No point rechecking the image if there hasn't really been any change.
- if (w == mActualWidth && h == mActualHeight) {
+ if (w == oldw && h == oldh) {
return;
}
- mActualWidth = w;
- mActualHeight = h;
-
mBackgroundRect.right = w;
mBackgroundRect.bottom = h;
formatImage();
}
@Override
public void onDraw(Canvas canvas) {
@@ -135,62 +129,62 @@ public class FaviconView extends ImageVi
/**
* Formats the image for display, if the prerequisite data are available. Upscales tiny Favicons to
* normal sized ones, replaces null bitmaps with the default Favicon, and fills all remaining space
* in this view with the coloured background.
*/
private void formatImage() {
// We're waiting for both onSizeChanged and updateImage to be called before scaling.
- if (mIconBitmap == null || mActualWidth == 0 || mActualHeight == 0) {
+ if (mIconBitmap == null || getWidth() == 0 || getHeight() == 0) {
showNoImage();
return;
}
- if (mScalingExpected && mActualWidth != mIconBitmap.getWidth()) {
+ if (mScalingExpected && getWidth() != mIconBitmap.getWidth()) {
scaleBitmap();
// Don't scale the image every time something changes.
mScalingExpected = false;
}
// In original, there is no round corners if FaviconView has bitmap icon. But the new design
// needs round corners all the time, so we use RoundedBitmapDrawableFactory to create round corners.
if (areRoundCornersEnabled) {
- // mIconBitmap's size must bew small or equal to mActualWidth, or we cannot see the round corners.
- if (mActualWidth < mIconBitmap.getWidth()) {
+ // mIconBitmap's size must bew small or equal to getWidth(), or we cannot see the round corners.
+ if (getWidth() < mIconBitmap.getWidth()) {
scaleBitmap();
}
RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(mResources, mIconBitmap);
roundedBitmapDrawable.setCornerRadius(mBackgroundCornerRadius);
roundedBitmapDrawable.setAntiAlias(true);
setImageDrawable(roundedBitmapDrawable);
} else {
setImageBitmap(mIconBitmap);
}
// After scaling, determine if we have empty space around the scaled image which we need to
// fill with the coloured background. If applicable, show it.
// We assume Favicons are still squares and only bother with the background if more than 3px
// of it would be displayed.
- if (Math.abs(mIconBitmap.getWidth() - mActualWidth) < 3) {
+ if (Math.abs(mIconBitmap.getWidth() - getWidth()) < 3) {
mDominantColor = 0;
}
}
private void scaleBitmap() {
// If the Favicon can be resized to fill the view exactly without an enlargment of more than
// a factor of two, do so.
int doubledSize = mIconBitmap.getWidth() * 2;
- if (mActualWidth > doubledSize) {
+ if (getWidth() > doubledSize) {
// If the view is more than twice the size of the image, just double the image size
// and do the rest with padding.
mIconBitmap = Bitmap.createScaledBitmap(mIconBitmap, doubledSize, doubledSize, true);
} else {
// Otherwise, scale the image to fill the view.
- mIconBitmap = Bitmap.createScaledBitmap(mIconBitmap, mActualWidth, mActualWidth, true);
+ mIconBitmap = Bitmap.createScaledBitmap(mIconBitmap, getWidth(), getWidth(), true);
}
}
/**
* Sets the icon displayed in this Favicon view to the bitmap provided. If the size of the view
* has been set, the display will be updated right away, otherwise the update will be deferred
* until then. The key provided is used to cache the result of the calculation of the dominant
* colour of the provided image - this value is used to draw the coloured background in this view