Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eec69929 authored by Gary Mai's avatar Gary Mai
Browse files

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
parent 7201f700
Loading
Loading
Loading
Loading
+3 −35
Original line number Original line Diff line number Diff line
@@ -16,14 +16,11 @@


package com.android.contacts.editor;
package com.android.contacts.editor;


import android.app.Activity;
import android.content.Context;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Bitmap;
import android.net.Uri;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.util.TypedValue;
import android.view.View;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup;
@@ -58,9 +55,6 @@ public class PhotoEditorView extends RelativeLayout implements View.OnClickListe
    private final float mPortraitPhotoRatio;
    private final float mPortraitPhotoRatio;
    private final boolean mIsTwoPanel;
    private final boolean mIsTwoPanel;


    private final int mActionBarHeight;
    private final int mStatusBarHeight;

    private QuickContactImageView mPhotoImageView;
    private QuickContactImageView mPhotoImageView;
    private View mPhotoIcon;
    private View mPhotoIcon;
    private View mPhotoIconOverlay;
    private View mPhotoIconOverlay;
@@ -80,15 +74,6 @@ public class PhotoEditorView extends RelativeLayout implements View.OnClickListe
        mLandscapePhotoRatio = getTypedFloat(R.dimen.quickcontact_landscape_photo_ratio);
        mLandscapePhotoRatio = getTypedFloat(R.dimen.quickcontact_landscape_photo_ratio);
        mPortraitPhotoRatio = getTypedFloat(R.dimen.editor_portrait_photo_ratio);
        mPortraitPhotoRatio = getTypedFloat(R.dimen.editor_portrait_photo_ratio);
        mIsTwoPanel = getResources().getBoolean(R.bool.contacteditor_two_panel);
        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) {
    private float getTypedFloat(int resourceId) {
@@ -104,6 +89,7 @@ public class PhotoEditorView extends RelativeLayout implements View.OnClickListe
        mPhotoIcon = findViewById(R.id.photo_icon);
        mPhotoIcon = findViewById(R.id.photo_icon);
        mPhotoIconOverlay = findViewById(R.id.photo_icon_overlay);
        mPhotoIconOverlay = findViewById(R.id.photo_icon_overlay);
        mPhotoTouchInterceptOverlay = findViewById(R.id.photo_touch_intercept_overlay);
        mPhotoTouchInterceptOverlay = findViewById(R.id.photo_touch_intercept_overlay);

    }
    }


    public void setListener(Listener listener) {
    public void setListener(Listener listener) {
@@ -165,11 +151,11 @@ public class PhotoEditorView extends RelativeLayout implements View.OnClickListe
            public void run() {
            public void run() {
                final int photoHeight, photoWidth;
                final int photoHeight, photoWidth;
                if (mIsTwoPanel) {
                if (mIsTwoPanel) {
                    photoHeight = getContentViewHeight();
                    photoHeight = getHeight();
                    photoWidth = (int) (photoHeight * mLandscapePhotoRatio);
                    photoWidth = (int) (photoHeight * mLandscapePhotoRatio);
                } else {
                } else {
                    // Make the photo slightly shorter that it is wide
                    // Make the photo slightly shorter that it is wide
                    photoWidth = getContentViewWidth();
                    photoWidth = getWidth();
                    photoHeight = (int) (photoWidth / mPortraitPhotoRatio);
                    photoHeight = (int) (photoWidth / mPortraitPhotoRatio);
                }
                }
                final ViewGroup.LayoutParams layoutParams = getLayoutParams();
                final ViewGroup.LayoutParams layoutParams = getLayoutParams();
@@ -180,24 +166,6 @@ public class PhotoEditorView extends RelativeLayout implements View.OnClickListe
        });
        });
    }
    }


    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.
     * Whether a removable, non-default photo is bound to this view.
     */
     */