Fix a possible NPE in View.
Change-Id: Ieebd176e1f42c78e298aca973e9e5eed2dc3c6d9
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index f63c2f1..2cc243e 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -6042,12 +6042,11 @@
int height = mBottom - mTop;
final AttachInfo attachInfo = mAttachInfo;
- final float scale = attachInfo.mApplicationScale;
+ final float scale = attachInfo != null ? attachInfo.mApplicationScale : 1.0f;
width = (int) ((width * scale) + 0.5f);
height = (int) ((height * scale) + 0.5f);
- Bitmap bitmap = Bitmap.createBitmap(width > 0 ? width : 1,
- height > 0 ? height : 1, quality);
+ Bitmap bitmap = Bitmap.createBitmap(width > 0 ? width : 1, height > 0 ? height : 1, quality);
if (bitmap == null) {
throw new OutOfMemoryError();
}
diff --git a/core/java/android/widget/Gallery.java b/core/java/android/widget/Gallery.java
index e7b303a..f34823c 100644
--- a/core/java/android/widget/Gallery.java
+++ b/core/java/android/widget/Gallery.java
@@ -23,7 +23,6 @@
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.util.AttributeSet;
-import android.util.Config;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Gravity;
@@ -36,8 +35,6 @@
import android.view.SoundEffectConstants;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.animation.Transformation;
-import android.widget.AbsSpinner;
-import android.widget.Scroller;
/**
* A view that shows items in a center-locked, horizontally scrolling list.
@@ -59,7 +56,7 @@
private static final String TAG = "Gallery";
- private static final boolean localLOGV = Config.LOGV;
+ private static final boolean localLOGV = false;
/**
* Duration in milliseconds from the start of a scroll during which we're
@@ -514,6 +511,7 @@
// We haven't been callbacking during the fling, so do it now
super.selectionChanged();
}
+ invalidate();
}
@Override
@@ -534,12 +532,9 @@
int galleryCenter = getCenterOfGallery();
- if (selView != null) {
-
- // Common case where the current selected position is correct
- if (selView.getLeft() <= galleryCenter && selView.getRight() >= galleryCenter) {
- return;
- }
+ // Common case where the current selected position is correct
+ if (selView.getLeft() <= galleryCenter && selView.getRight() >= galleryCenter) {
+ return;
}
// TODO better search
@@ -627,7 +622,6 @@
View sel = makeAndAddView(mSelectedPosition, 0, 0, true);
// Put the selected child in the center
- Gallery.LayoutParams lp = (Gallery.LayoutParams) sel.getLayoutParams();
int selectedOffset = childrenLeft + (childrenWidth / 2) - (sel.getWidth() / 2);
sel.offsetLeftAndRight(selectedOffset);
@@ -733,9 +727,6 @@
child = mRecycler.get(position);
if (child != null) {
// Can reuse an existing view
- Gallery.LayoutParams lp = (Gallery.LayoutParams)
- child.getLayoutParams();
-
int childLeft = child.getLeft();
// Remember left and right edges of where views have been placed
@@ -798,7 +789,7 @@
int childRight;
// Position vertically based on gravity setting
- int childTop = calculateTop(child, lp, true);
+ int childTop = calculateTop(child, true);
int childBottom = childTop + child.getMeasuredHeight();
int width = child.getMeasuredWidth();
@@ -817,11 +808,9 @@
* Figure out vertical placement based on mGravity
*
* @param child Child to place
- * @param lp LayoutParams for this view (just so we don't keep looking them
- * up)
* @return Where the top of the child should be
*/
- private int calculateTop(View child, Gallery.LayoutParams lp, boolean duringLayout) {
+ private int calculateTop(View child, boolean duringLayout) {
int myHeight = duringLayout ? mMeasuredHeight : getHeight();
int childHeight = duringLayout ? child.getMeasuredHeight() : child.getHeight();