Avoid Resources$NotFoundException
I'm guessing that this bug was being caused by doOnPreDraw()
callbacks occuring after rotation (the monkey links 404, so it
is hard to do more than conjecture)? To fix this: define the
resource for both landscape and profile. To make this more
testable: load quickcontact_landscape_photo_ratio during
contruction instead of inside an asynchronous callback.
Additional cleanup: don't use two different ways to determine
whether we are in landscape mode. This wasn't causing a bug
that we know of.
Bug: 18102632
Change-Id: I1f27d873ca71be28de7a1e59aa628c4696cb4c89
diff --git a/res/values-land/vals.xml b/res/values-land/vals.xml
deleted file mode 100644
index ebcae31..0000000
--- a/res/values-land/vals.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2011 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<resources>
- <!-- The ratio of width:height for the contact's photo -->
- <item name="quickcontact_photo_ratio" type="vals" format="float">0.7</item>
-</resources>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index cd9795c..857045c 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -22,6 +22,8 @@
<dimen name="quickcontact_maximum_title_size">36dp</dimen>
<!-- When QC is uncollapsed, the title has this much margin on its left, right and bottom -->
<dimen name="quickcontact_title_initial_margin">16dp</dimen>
+ <!-- The ratio of width:height for the contact's photo in landscape -->
+ <item name="quickcontact_landscape_photo_ratio" type="dimen" format="float">0.7</item>
<!-- Top padding of the entire contact editor -->
<dimen name="editor_padding_top">0dip</dimen>
diff --git a/src/com/android/contacts/widget/MultiShrinkScroller.java b/src/com/android/contacts/widget/MultiShrinkScroller.java
index dcc3b61..72dc996 100644
--- a/src/com/android/contacts/widget/MultiShrinkScroller.java
+++ b/src/com/android/contacts/widget/MultiShrinkScroller.java
@@ -142,6 +142,7 @@
private final int mMaximumTitleMargin;
private final float mToolbarElevation;
private final boolean mIsTwoPanel;
+ private final float mLandscapePhotoRatio;
private final int mActionBarSize;
// Objects used to perform color filtering on the header. These are stored as fields for
@@ -251,6 +252,11 @@
mMaximumTitleMargin = (int) getResources().getDimension(
R.dimen.quickcontact_title_initial_margin);
+ final TypedValue photoRatio = new TypedValue();
+ getResources().getValue(R.dimen.quickcontact_landscape_photo_ratio, photoRatio,
+ /* resolveRefs = */ true);
+ mLandscapePhotoRatio = photoRatio.getFloat();
+
final TypedArray attributeArray = context.obtainStyledAttributes(
new int[]{android.R.attr.actionBarSize});
mActionBarSize = attributeArray.getDimensionPixelSize(0, 0);
@@ -317,9 +323,7 @@
mIntermediateHeaderHeight = (int) (mMaximumHeaderHeight
* INTERMEDIATE_HEADER_HEIGHT_RATIO);
}
- final boolean isLandscape = getResources().getConfiguration().orientation
- == Configuration.ORIENTATION_LANDSCAPE;
- mMaximumPortraitHeaderHeight = isLandscape ? getHeight()
+ mMaximumPortraitHeaderHeight = mIsTwoPanel ? getHeight()
: mPhotoViewContainer.getWidth();
setHeaderHeight(getMaximumScrollableHeaderHeight());
mMaximumHeaderTextSize = mLargeTextView.getHeight();
@@ -329,13 +333,10 @@
mIntermediateHeaderHeight = mMaximumHeaderHeight;
// Permanently set photo width and height.
- final TypedValue photoRatio = new TypedValue();
- getResources().getValue(R.vals.quickcontact_photo_ratio, photoRatio,
- /* resolveRefs = */ true);
final ViewGroup.LayoutParams photoLayoutParams
= mPhotoViewContainer.getLayoutParams();
photoLayoutParams.height = mMaximumHeaderHeight;
- photoLayoutParams.width = (int) (mMaximumHeaderHeight * photoRatio.getFloat());
+ photoLayoutParams.width = (int) (mMaximumHeaderHeight * mLandscapePhotoRatio);
mPhotoViewContainer.setLayoutParams(photoLayoutParams);
// Permanently set title width and margin.