summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2018-02-09 22:55:39 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2018-02-09 22:55:39 +0000
commiteffa40ca44ac1881cfa41749753b51cacdcb02cb (patch)
treecf49157b2b2c49ab820dc0f63b0b952a02e57ea2
parent7cc9c01db7fce67e683fe6f1550c81549962fa02 (diff)
parent30dd125acfe3a38f3c81d397f5f359bfcac57702 (diff)
Merge "The volume dialog window size should match content"
-rw-r--r--packages/SystemUI/res/layout/volume_dialog.xml9
-rw-r--r--packages/SystemUI/res/values/dimens.xml2
-rw-r--r--packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java32
-rw-r--r--packages/SystemUI/src/com/android/systemui/volume/VolumeUiLayout.java62
4 files changed, 36 insertions, 69 deletions
diff --git a/packages/SystemUI/res/layout/volume_dialog.xml b/packages/SystemUI/res/layout/volume_dialog.xml
index 36298ca0c095..bab4eba72822 100644
--- a/packages/SystemUI/res/layout/volume_dialog.xml
+++ b/packages/SystemUI/res/layout/volume_dialog.xml
@@ -15,8 +15,8 @@
-->
<com.android.systemui.volume.VolumeUiLayout
xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:theme="@style/qs_theme"
android:clipChildren="false" >
@@ -29,7 +29,6 @@
android:minWidth="@dimen/volume_dialog_panel_width"
android:background="@android:color/transparent"
android:layout_margin="@dimen/volume_dialog_base_margin"
- android:translationZ="8dp"
android:orientation="vertical"
android:clipChildren="false" >
@@ -42,7 +41,7 @@
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:background="@drawable/rounded_bg_full"
- android:translationZ="8dp"
+ android:translationZ="@dimen/volume_panel_elevation"
android:orientation="horizontal" >
<!-- volume rows added and removed here! :-) -->
</LinearLayout>
@@ -59,7 +58,7 @@
android:background="@drawable/rounded_bg_full"
android:gravity="center"
android:layout_gravity="end"
- android:translationZ="8dp"
+ android:translationZ="@dimen/volume_panel_elevation"
android:clickable="true"
android:orientation="vertical" >
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
index a9021ae674f0..c351b9427e4c 100644
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -704,6 +704,8 @@
<dimen name="volume_expander_margin_end">2dp</dimen>
<dimen name="volume_expander_margin_top">6dp</dimen>
+ <dimen name="volume_panel_elevation">8dp</dimen>
+
<!-- Padding between icon and text for managed profile toast -->
<dimen name="managed_profile_toast_padding">4dp</dimen>
diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java
index c622677ceb7e..fb5c447c2592 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java
@@ -37,6 +37,7 @@ import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Color;
+import android.graphics.PixelFormat;
import android.graphics.drawable.ColorDrawable;
import android.media.AudioManager;
import android.media.AudioSystem;
@@ -54,6 +55,7 @@ import android.util.Log;
import android.util.Slog;
import android.util.SparseBooleanArray;
import android.view.ContextThemeWrapper;
+import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.AccessibilityDelegate;
@@ -176,7 +178,15 @@ public class VolumeDialogImpl implements VolumeDialog {
mWindow.setTitle(VolumeDialogImpl.class.getSimpleName());
mWindow.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
mWindow.setWindowAnimations(com.android.internal.R.style.Animation_Toast);
-
+ final WindowManager.LayoutParams lp = mWindow.getAttributes();
+ lp.format = PixelFormat.TRANSLUCENT;
+ lp.setTitle(VolumeDialogImpl.class.getSimpleName());
+ lp.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
+ lp.windowAnimations = -1;
+ mWindow.setAttributes(lp);
+ mWindow.setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
+
+ mDialog.setCanceledOnTouchOutside(true);
mDialog.setContentView(R.layout.volume_dialog);
mDialog.setOnShowListener(dialog -> {
mDialogView.setTranslationX(mDialogView.getWidth() / 2);
@@ -199,8 +209,8 @@ public class VolumeDialogImpl implements VolumeDialog {
rescheduleTimeoutH();
return true;
});
- VolumeUiLayout hardwareLayout = VolumeUiLayout.get(mDialogView);
- hardwareLayout.setOutsideTouchListener(view -> dismiss(DISMISS_REASON_TOUCH_OUTSIDE));
+ VolumeUiLayout uiLayout = VolumeUiLayout.get(mDialogView);
+ uiLayout.updateRotation();
mDialogRowsView = mDialog.findViewById(R.id.volume_dialog_rows);
mFooter = mDialog.findViewById(R.id.footer);
@@ -1015,15 +1025,21 @@ public class VolumeDialogImpl implements VolumeDialog {
}
@Override
+ public boolean onTouchEvent(MotionEvent event) {
+ if (isShowing()) {
+ if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
+ dismissH(Events.DISMISS_REASON_TOUCH_OUTSIDE);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
public boolean dispatchPopulateAccessibilityEvent(@NonNull AccessibilityEvent event) {
event.setClassName(getClass().getSuperclass().getName());
event.setPackageName(mContext.getPackageName());
- ViewGroup.LayoutParams params = getWindow().getAttributes();
- boolean isFullScreen = (params.width == ViewGroup.LayoutParams.MATCH_PARENT) &&
- (params.height == ViewGroup.LayoutParams.MATCH_PARENT);
- event.setFullScreen(isFullScreen);
-
if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
if (mShowing) {
event.getText().add(mContext.getString(
diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeUiLayout.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeUiLayout.java
index 3d4438148c39..0a3a2ab7c61f 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/VolumeUiLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeUiLayout.java
@@ -37,10 +37,6 @@ import com.android.systemui.util.leak.RotationUtils;
public class VolumeUiLayout extends FrameLayout {
private View mChild;
- private int mOldHeight;
- private boolean mAnimating;
- private AnimatorSet mAnimation;
- private boolean mHasOutsideTouch;
private int mRotation = ROTATION_NONE;
@Nullable
private DisplayCutout mDisplayCutout;
@@ -52,13 +48,11 @@ public class VolumeUiLayout extends FrameLayout {
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
- getViewTreeObserver().addOnComputeInternalInsetsListener(mInsetsListener);
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
- getViewTreeObserver().removeOnComputeInternalInsetsListener(mInsetsListener);
mDisplayCutout = null;
}
@@ -68,16 +62,11 @@ public class VolumeUiLayout extends FrameLayout {
if (mChild == null) {
if (getChildCount() != 0) {
mChild = getChildAt(0);
- mOldHeight = mChild.getMeasuredHeight();
updateRotation();
} else {
return;
}
}
- int newHeight = mChild.getMeasuredHeight();
- if (newHeight != mOldHeight) {
- animateChild(mOldHeight, newHeight);
- }
}
@Override
@@ -95,8 +84,13 @@ public class VolumeUiLayout extends FrameLayout {
}
}
- private void updateRotation() {
+ public void updateRotation() {
setDisplayCutout();
+ if (mChild == null) {
+ if (getChildCount() != 0) {
+ mChild = getChildAt(0);
+ }
+ }
int rotation = RotationUtils.getRotation(getContext());
if (rotation != mRotation) {
updateSafeInsets(rotation);
@@ -144,43 +138,11 @@ public class VolumeUiLayout extends FrameLayout {
return r.bottom - r.top;
}
-
- private void animateChild(int oldHeight, int newHeight) {
- if (true) return;
- if (mAnimating) {
- mAnimation.cancel();
- }
- mAnimating = true;
- mAnimation = new AnimatorSet();
- mAnimation.addListener(new AnimatorListenerAdapter() {
- @Override
- public void onAnimationEnd(Animator animation) {
- mAnimating = false;
- }
- });
- int fromTop = mChild.getTop();
- int fromBottom = mChild.getBottom();
- int toTop = fromTop - ((newHeight - oldHeight) / 2);
- int toBottom = fromBottom + ((newHeight - oldHeight) / 2);
- ObjectAnimator top = ObjectAnimator.ofInt(mChild, "top", fromTop, toTop);
- mAnimation.playTogether(top,
- ObjectAnimator.ofInt(mChild, "bottom", fromBottom, toBottom));
- }
-
-
@Override
public ViewOutlineProvider getOutlineProvider() {
return super.getOutlineProvider();
}
- public void setOutsideTouchListener(OnClickListener onClickListener) {
- mHasOutsideTouch = true;
- requestLayout();
- setOnClickListener(onClickListener);
- setClickable(true);
- setFocusable(true);
- }
-
public static VolumeUiLayout get(View v) {
if (v instanceof VolumeUiLayout) return (VolumeUiLayout) v;
if (v.getParent() instanceof View) {
@@ -188,16 +150,4 @@ public class VolumeUiLayout extends FrameLayout {
}
return null;
}
-
- private final ViewTreeObserver.OnComputeInternalInsetsListener mInsetsListener = inoutInfo -> {
- if (mHasOutsideTouch || (mChild == null)) {
- inoutInfo.setTouchableInsets(
- ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME);
- return;
- }
- inoutInfo.setTouchableInsets(
- ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT);
- inoutInfo.contentInsets.set(mChild.getLeft(), mChild.getTop(),
- 0, getBottom() - mChild.getBottom());
- };
}