Photo view in editor fixes
Use the height/width returned from getHeight and getWidth to
resize the photo view. Since it takes up all available space
initially these two values essentially function as the content
view height/width.
Test: Manually verified photo view sizing on M, N, and O with
rotation.
Also verified editor alignment in multiwindow mode on N.
One caveat is when rotating to landscape with the keyboard up on
O only, there's still a little bit of space at the bottom of the
photo view. This doesn't repro when loading initially in landscape
or rotating into landscape without the keyboard up. So the bug
isn't fixed entirely but it handles the more common cases.
Bug: 33922016
Bug: 27887505
Change-Id: I89ad06bfb07d8891c6ecb57cc7cb0452a2112385
diff --git a/src/com/android/contacts/editor/PhotoEditorView.java b/src/com/android/contacts/editor/PhotoEditorView.java
index 607c42c..09ba797 100644
--- a/src/com/android/contacts/editor/PhotoEditorView.java
+++ b/src/com/android/contacts/editor/PhotoEditorView.java
@@ -16,14 +16,11 @@
package com.android.contacts.editor;
-import android.app.Activity;
import android.content.Context;
-import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.net.Uri;
import android.provider.ContactsContract;
import android.util.AttributeSet;
-import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
@@ -58,9 +55,6 @@
private final float mPortraitPhotoRatio;
private final boolean mIsTwoPanel;
- private final int mActionBarHeight;
- private final int mStatusBarHeight;
-
private QuickContactImageView mPhotoImageView;
private View mPhotoIcon;
private View mPhotoIconOverlay;
@@ -80,15 +74,6 @@
mLandscapePhotoRatio = getTypedFloat(R.dimen.quickcontact_landscape_photo_ratio);
mPortraitPhotoRatio = getTypedFloat(R.dimen.editor_portrait_photo_ratio);
mIsTwoPanel = getResources().getBoolean(R.bool.contacteditor_two_panel);
-
- final TypedArray styledAttributes = getContext().getTheme().obtainStyledAttributes(
- new int[] { android.R.attr.actionBarSize });
- mActionBarHeight = (int) styledAttributes.getDimension(0, 0);
- styledAttributes.recycle();
-
- final int resourceId = getResources().getIdentifier(
- "status_bar_height", "dimen", "android");
- mStatusBarHeight = resourceId > 0 ? getResources().getDimensionPixelSize(resourceId) : 0;
}
private float getTypedFloat(int resourceId) {
@@ -104,6 +89,7 @@
mPhotoIcon = findViewById(R.id.photo_icon);
mPhotoIconOverlay = findViewById(R.id.photo_icon_overlay);
mPhotoTouchInterceptOverlay = findViewById(R.id.photo_touch_intercept_overlay);
+
}
public void setListener(Listener listener) {
@@ -165,11 +151,11 @@
public void run() {
final int photoHeight, photoWidth;
if (mIsTwoPanel) {
- photoHeight = getContentViewHeight();
+ photoHeight = getHeight();
photoWidth = (int) (photoHeight * mLandscapePhotoRatio);
} else {
// Make the photo slightly shorter that it is wide
- photoWidth = getContentViewWidth();
+ photoWidth = getWidth();
photoHeight = (int) (photoWidth / mPortraitPhotoRatio);
}
final ViewGroup.LayoutParams layoutParams = getLayoutParams();
@@ -180,24 +166,6 @@
});
}
- private int getContentViewWidth() {
- final Activity activity = (Activity) getContext();
- final DisplayMetrics displayMetrics = new DisplayMetrics();
- activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
- return displayMetrics.widthPixels;
- }
-
- // We're calculating the height the hard way because using the height of the content view
- // (found using android.view.Window.ID_ANDROID_CONTENT) with the soft keyboard up when
- // going from portrait to landscape mode results in a very small height value.
- // See b/20526470
- private int getContentViewHeight() {
- final Activity activity = (Activity) getContext();
- final DisplayMetrics displayMetrics = new DisplayMetrics();
- activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
- return displayMetrics.heightPixels - mActionBarHeight - mStatusBarHeight;
- }
-
/**
* Whether a removable, non-default photo is bound to this view.
*/