From 02dd493e62f22a488c4bc8438471e30d9b84b936 Mon Sep 17 00:00:00 2001 From: yueg Date: Thu, 25 Jan 2018 14:17:06 -0800 Subject: Set avatar as background instead of src. Since we don't need background any more, setting avatar as background makes elevation work on the same view. So we don't need setOutlineProvider() which might provide a different outline to the image's. Also fix an windowParams NPE. Test: manual PiperOrigin-RevId: 183289973 Change-Id: I452b3f2b66b1810839626f57449be7d10662f2c5 --- java/com/android/newbubble/NewBubble.java | 26 ++++++++-------------- .../newbubble/res/layout/new_bubble_base.xml | 10 ++++----- java/com/android/newbubble/res/values/values.xml | 1 + 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/java/com/android/newbubble/NewBubble.java b/java/com/android/newbubble/NewBubble.java index 2e98ad17b..54e56ba61 100644 --- a/java/com/android/newbubble/NewBubble.java +++ b/java/com/android/newbubble/NewBubble.java @@ -25,7 +25,6 @@ import android.annotation.SuppressLint; import android.app.PendingIntent.CanceledException; import android.content.Context; import android.content.Intent; -import android.graphics.Outline; import android.graphics.PixelFormat; import android.graphics.Rect; import android.graphics.drawable.Animatable; @@ -47,7 +46,6 @@ import android.view.MotionEvent; import android.view.View; import android.view.View.AccessibilityDelegate; import android.view.ViewGroup; -import android.view.ViewOutlineProvider; import android.view.ViewTreeObserver.OnPreDrawListener; import android.view.WindowManager; import android.view.WindowManager.LayoutParams; @@ -525,7 +523,7 @@ public class NewBubble { public void updateAvatar(@NonNull Drawable avatar) { if (!avatar.equals(currentInfo.getAvatar())) { currentInfo = NewBubbleInfo.from(currentInfo).setAvatar(avatar).build(); - viewHolder.getPrimaryAvatar().setImageDrawable(currentInfo.getAvatar()); + viewHolder.getPrimaryAvatar().setBackground(currentInfo.getAvatar()); } } @@ -560,7 +558,7 @@ public class NewBubble { savedYPosition = -1; viewHolder - .getPrimaryButton() + .getPrimaryAvatar() .animate() .translationZ( context @@ -569,7 +567,7 @@ public class NewBubble { } void onMoveFinish() { - viewHolder.getPrimaryButton().animate().translationZ(0); + viewHolder.getPrimaryAvatar().animate().translationZ(0); } void primaryButtonClick() { @@ -669,17 +667,9 @@ public class NewBubble { primaryIconMoveDistance = context.getResources().getDimensionPixelSize(R.dimen.bubble_size) - context.getResources().getDimensionPixelSize(R.dimen.bubble_small_icon_size); - // Set boundary for primary button to show elevation (background is transparent) - viewHolder - .getPrimaryButton() - .setOutlineProvider( - new ViewOutlineProvider() { - @Override - public void getOutline(View view, Outline outline) { - ViewOutlineProvider.BACKGROUND.getOutline(view, outline); - outline.setAlpha(1); - } - }); + + // Avatar + viewHolder.getPrimaryAvatar().setBackground(currentInfo.getAvatar()); // Small icon Drawable smallIconBackgroundCircle = @@ -689,7 +679,6 @@ public class NewBubble { smallIconBackgroundCircle.setTint(context.getColor(R.color.bubble_button_color_blue)); viewHolder.getPrimaryIcon().setBackground(smallIconBackgroundCircle); viewHolder.getPrimaryIcon().setImageIcon(currentInfo.getPrimaryIcon()); - viewHolder.getPrimaryAvatar().setImageDrawable(currentInfo.getAvatar()); updatePrimaryIconAnimation(); updateButtonStates(); @@ -873,6 +862,9 @@ public class NewBubble { xValueAnimator.setInterpolator(new LinearOutSlowInInterpolator()); xValueAnimator.addUpdateListener( (valueAnimator) -> { + if (windowParams == null) { + return; + } // Update windowParams and the root layout. // We can't do ViewPropertyAnimation since it clips children. float newX = (float) valueAnimator.getAnimatedValue(); diff --git a/java/com/android/newbubble/res/layout/new_bubble_base.xml b/java/com/android/newbubble/res/layout/new_bubble_base.xml index c86d3bbcc..9b8250d6b 100644 --- a/java/com/android/newbubble/res/layout/new_bubble_base.xml +++ b/java/com/android/newbubble/res/layout/new_bubble_base.xml @@ -40,14 +40,13 @@ android:layout_marginTop="@dimen/bubble_shadow_padding_size_vertical" android:layout_marginBottom="@dimen/bubble_shadow_padding_size_vertical" android:contentDescription="@string/a11y_bubble_description" - android:background="@drawable/bubble_shape_circle" - android:measureAllChildren="false" - android:elevation="@dimen/bubble_elevation"> + android:measureAllChildren="false"> + android:background="@android:drawable/ic_btn_speak_now" + android:elevation="@dimen/bubble_elevation"/> + tools:src="@android:drawable/ic_btn_speak_now" + android:elevation="@dimen/bubble_dragging_elevation"/> diff --git a/java/com/android/newbubble/res/values/values.xml b/java/com/android/newbubble/res/values/values.xml index 2e72c5e5e..f449c9bed 100644 --- a/java/com/android/newbubble/res/values/values.xml +++ b/java/com/android/newbubble/res/values/values.xml @@ -19,6 +19,7 @@ 56dp 16dp 6dp + 12dp 36dp 16dp -- cgit v1.2.3