From 6a5762884adc64ea95bd206c46d60031428e977c Mon Sep 17 00:00:00 2001 From: Anthony Hugh Date: Mon, 5 Oct 2015 12:28:07 -0700 Subject: Permissions redline fixes This fixes the button bar animation to work on round devices and also fixes the max height animation to make sure the vertical button layout animates to max height when there are only two buttons. Also adjust some redlines like margins on the buttons and updated some files that were missing our licensing header. Change-Id: Ifad4d0f92605be04db2d3c991b4e8a26eadb4b14 --- res/drawable-watch/action_negative_bg.xml | 14 ++ res/drawable-watch/action_positive_bg.xml | 14 ++ res/drawable-watch/cancel_button.xml | 14 ++ res/drawable-watch/confirm_button.xml | 14 ++ res/drawable-watch/deny_button.xml | 14 ++ res/layout-watch/confirmation_dialog.xml | 12 +- res/values-round/dimens.xml | 2 - res/values-watch/dimens.xml | 4 +- res/values-watch/strings.xml | 4 +- .../ui/GrantPermissionsWatchViewHandler.java | 2 +- .../ui/wear/ConfirmationViewHandler.java | 147 ++++++++++++++------- 11 files changed, 181 insertions(+), 60 deletions(-) diff --git a/res/drawable-watch/action_negative_bg.xml b/res/drawable-watch/action_negative_bg.xml index f1c33b54..7b21ba6d 100644 --- a/res/drawable-watch/action_negative_bg.xml +++ b/res/drawable-watch/action_negative_bg.xml @@ -1,4 +1,18 @@ + diff --git a/res/drawable-watch/action_positive_bg.xml b/res/drawable-watch/action_positive_bg.xml index bc3e88ba..f3457c1a 100644 --- a/res/drawable-watch/action_positive_bg.xml +++ b/res/drawable-watch/action_positive_bg.xml @@ -1,4 +1,18 @@ + diff --git a/res/drawable-watch/cancel_button.xml b/res/drawable-watch/cancel_button.xml index 5b16f549..641526a5 100644 --- a/res/drawable-watch/cancel_button.xml +++ b/res/drawable-watch/cancel_button.xml @@ -1,4 +1,18 @@ + diff --git a/res/drawable-watch/confirm_button.xml b/res/drawable-watch/confirm_button.xml index 6a895ec6..2b53e42e 100644 --- a/res/drawable-watch/confirm_button.xml +++ b/res/drawable-watch/confirm_button.xml @@ -1,4 +1,18 @@ + diff --git a/res/drawable-watch/deny_button.xml b/res/drawable-watch/deny_button.xml index 70ea453f..1e7582bc 100644 --- a/res/drawable-watch/deny_button.xml +++ b/res/drawable-watch/deny_button.xml @@ -1,4 +1,18 @@ + diff --git a/res/layout-watch/confirmation_dialog.xml b/res/layout-watch/confirmation_dialog.xml index 783d4051..0b93579e 100644 --- a/res/layout-watch/confirmation_dialog.xml +++ b/res/layout-watch/confirmation_dialog.xml @@ -29,7 +29,6 @@ @@ -89,13 +88,13 @@ android:layout_marginTop="@dimen/conf_diag_2button_margin_top" android:background="@drawable/confirm_button"/> - + + + + diff --git a/res/values-round/dimens.xml b/res/values-round/dimens.xml index d9a522d4..5e7309b9 100644 --- a/res/values-round/dimens.xml +++ b/res/values-round/dimens.xml @@ -19,7 +19,5 @@ 96dp 32dp 10dp - 36dp - 24dp diff --git a/res/values-watch/dimens.xml b/res/values-watch/dimens.xml index fa657c73..24d2a058 100644 --- a/res/values-watch/dimens.xml +++ b/res/values-watch/dimens.xml @@ -30,8 +30,8 @@ 72dp 16dp 9dp - 16dp - 9dp + 32dp + 22dp diff --git a/res/values-watch/strings.xml b/res/values-watch/strings.xml index 2728da23..82fe4ae9 100644 --- a/res/values-watch/strings.xml +++ b/res/values-watch/strings.xml @@ -15,8 +15,8 @@ --> - - Deny and don\'t ask again + + Deny, don\'t ask again diff --git a/src/com/android/packageinstaller/permission/ui/GrantPermissionsWatchViewHandler.java b/src/com/android/packageinstaller/permission/ui/GrantPermissionsWatchViewHandler.java index 242d0bce..21042f00 100644 --- a/src/com/android/packageinstaller/permission/ui/GrantPermissionsWatchViewHandler.java +++ b/src/com/android/packageinstaller/permission/ui/GrantPermissionsWatchViewHandler.java @@ -57,7 +57,7 @@ final class GrantPermissionsWatchViewHandler extends ConfirmationViewHandler @Override public void updateWindowAttributes(WindowManager.LayoutParams outLayoutParams) { outLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; - outLayoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT; + outLayoutParams.height = WindowManager.LayoutParams.MATCH_PARENT; outLayoutParams.format = PixelFormat.OPAQUE; outLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG; outLayoutParams.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; diff --git a/src/com/android/packageinstaller/permission/ui/wear/ConfirmationViewHandler.java b/src/com/android/packageinstaller/permission/ui/wear/ConfirmationViewHandler.java index 277bada9..db3340f6 100644 --- a/src/com/android/packageinstaller/permission/ui/wear/ConfirmationViewHandler.java +++ b/src/com/android/packageinstaller/permission/ui/wear/ConfirmationViewHandler.java @@ -8,6 +8,7 @@ import android.graphics.drawable.Icon; import android.os.Handler; import android.os.Message; import android.text.TextUtils; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -24,11 +25,15 @@ import com.android.packageinstaller.R; public abstract class ConfirmationViewHandler implements Handler.Callback, View.OnClickListener, - ViewTreeObserver.OnScrollChangedListener { + ViewTreeObserver.OnScrollChangedListener, + ViewTreeObserver.OnGlobalLayoutListener { + private static final String TAG = "ConfirmationViewHandler"; + public static final int MODE_HORIZONTAL_BUTTONS = 0; public static final int MODE_VERTICAL_BUTTONS = 1; - private static final int MSG_HIDE_BUTTON_BAR = 1001; + private static final int MSG_SHOW_BUTTON_BAR = 1001; + private static final int MSG_HIDE_BUTTON_BAR = 1002; private static final long HIDE_ANIM_DURATION = 500; private View mRoot; @@ -103,6 +108,9 @@ public abstract class ConfirmationViewHandler implements R.dimen.conf_diag_floating_height); mHideHandler = new Handler(this); + mScrollingContainer.getViewTreeObserver().addOnScrollChangedListener(this); + mRoot.getViewTreeObserver().addOnGlobalLayoutListener(this); + return mRoot; } @@ -158,54 +166,41 @@ public abstract class ConfirmationViewHandler implements mVerticalButton3.setCompoundDrawablesWithIntrinsicBounds( getVerticalButton3Icon(), null, null, null); } - break; } mScrollingContainer.scrollTo(0, 0); - mScrollingContainer.getViewTreeObserver().addOnScrollChangedListener(this); + mHideHandler.removeMessages(MSG_HIDE_BUTTON_BAR); + mHideHandler.removeMessages(MSG_SHOW_BUTTON_BAR); + } + + @Override + public void onGlobalLayout() { + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, "onGlobalLayout"); + Log.d(TAG, " contentHeight: " + mContent.getHeight()); + } + + if (mButtonBarAnimator != null) { + mButtonBarAnimator.cancel(); + } + + // In order to fake the buttons peeking at the bottom, need to do set the + // padding properly. + if (mContent.getPaddingBottom() != mButtonBarContainer.getHeight()) { + mContent.setPadding(0, 0, 0, mButtonBarContainer.getHeight()); + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, " set mContent.PaddingBottom: " + mButtonBarContainer.getHeight()); + } + } - mRoot.getViewTreeObserver().addOnGlobalLayoutListener( - new ViewTreeObserver.OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - // Setup Button animation. - // pop the button bar back to full height, stop all animation - if (mButtonBarAnimator != null) { - mButtonBarAnimator.cancel(); - } - - // In order to fake the buttons peeking at the bottom, need to do set the - // padding properly. - if (mContent.getPaddingBottom() != mButtonBarContainer.getHeight()) { - mContent.setPadding(0, 0, 0, mButtonBarContainer.getHeight()); - } - - // stop any calls to hide the button bar in the future - mHideHandler.removeMessages(MSG_HIDE_BUTTON_BAR); - mHiddenBefore = false; - - // determine which mode the scrolling should work at. - if (mContent.getHeight() > mScrollingContainer.getHeight()) { - mButtonBarContainer.setTranslationZ(mButtonBarFloatingHeight); - mHideHandler.sendEmptyMessageDelayed(MSG_HIDE_BUTTON_BAR, 3000); - int maxButtonBarHeight = 0; - if (mButtonBarContainer.getHeight() >= mRoot.getHeight() / 2) { - // If the ButtonBar is bigger than half the screen, then don't - // animate all the way. - maxButtonBarHeight = mRoot.getHeight() / 2; - } - generateButtonBarAnimator(mButtonBarContainer.getHeight(), - maxButtonBarHeight, 0, mButtonBarFloatingHeight, 1000); - } else { - mButtonBarContainer.setTranslationY(0); - mButtonBarContainer.setTranslationZ(0); - } - mRoot.getViewTreeObserver().removeOnGlobalLayoutListener(this); - } - }); + mButtonBarContainer.setTranslationY(mButtonBarContainer.getHeight()); + // Give everything a chance to render + mHideHandler.removeMessages(MSG_HIDE_BUTTON_BAR); + mHideHandler.removeMessages(MSG_SHOW_BUTTON_BAR); + mHideHandler.sendEmptyMessageDelayed(MSG_SHOW_BUTTON_BAR, 50); } @Override @@ -229,6 +224,9 @@ public abstract class ConfirmationViewHandler implements @Override public boolean handleMessage (Message msg) { switch (msg.what) { + case MSG_SHOW_BUTTON_BAR: + showButtonBar(); + return true; case MSG_HIDE_BUTTON_BAR: hideButtonBar(); return true; @@ -237,21 +235,72 @@ public abstract class ConfirmationViewHandler implements } @Override - public void onScrollChanged() { + public void onScrollChanged () { mHideHandler.removeMessages(MSG_HIDE_BUTTON_BAR); hideButtonBar(); } + private void showButtonBar() { + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, "showButtonBar"); + } + + // Setup Button animation. + // pop the button bar back to full height, stop all animation + if (mButtonBarAnimator != null) { + mButtonBarAnimator.cancel(); + } + + // stop any calls to hide the button bar in the future + mHideHandler.removeMessages(MSG_HIDE_BUTTON_BAR); + mHiddenBefore = false; + + // Evaluate the max height the button bar can go + final int screenHeight = mRoot.getHeight(); + final int buttonBarHeight = mButtonBarContainer.getHeight(); + final int buttonBarMaxHeight = + Math.min(buttonBarHeight, screenHeight / 2); + + if (Log.isLoggable(TAG, Log.DEBUG)) { + final int contentHeight = mContent.getHeight() - buttonBarHeight; + Log.d(TAG, " screenHeight: " + screenHeight); + Log.d(TAG, " contentHeight: " + contentHeight); + Log.d(TAG, " buttonBarHeight: " + buttonBarHeight); + Log.d(TAG, " buttonBarMaxHeight: " + buttonBarMaxHeight); + } + + mButtonBarContainer.setTranslationZ(mButtonBarFloatingHeight); + mHideHandler.sendEmptyMessageDelayed(MSG_HIDE_BUTTON_BAR, 3000); + + generateButtonBarAnimator(buttonBarHeight, + buttonBarHeight - buttonBarMaxHeight, 0, mButtonBarFloatingHeight, 1000); + } + private void hideButtonBar() { - // get the offset to the top of the button bar - int offset = mScrollingContainer.getHeight() + mButtonBarContainer.getHeight() - - mContent.getHeight() + Math.max(mScrollingContainer.getScrollY(), 0); + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, "hideButtonBar"); + } + // The desired margin space between the button bar and the bottom of the dialog text - int topMargin = mContext.getResources().getDimensionPixelSize( + final int topMargin = mContext.getResources().getDimensionPixelSize( R.dimen.conf_diag_button_container_top_margin); - int translationY = topMargin + (offset > 0 ? + final int contentHeight = mContent.getHeight() + topMargin; + final int screenHeight = mRoot.getHeight(); + final int buttonBarHeight = mButtonBarContainer.getHeight(); + + final int offset = screenHeight + buttonBarHeight + - contentHeight + Math.max(mScrollingContainer.getScrollY(), 0); + final int translationY = (offset > 0 ? mButtonBarContainer.getHeight() - offset : mButtonBarContainer.getHeight()); + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, " contentHeight: " + contentHeight); + Log.d(TAG, " buttonBarHeight: " + buttonBarHeight); + Log.d(TAG, " mContent.getPaddingBottom(): " + mContent.getPaddingBottom()); + Log.d(TAG, " mScrollingContainer.getScrollY(): " + mScrollingContainer.getScrollY()); + Log.d(TAG, " translationY: " + translationY); + } + if (!mHiddenBefore || mButtonBarAnimator == null) { // hasn't hidden the bar yet, just hide now to the right height generateButtonBarAnimator( -- cgit v1.2.3