Commit a5e0551a authored by Tommy Martino's avatar Tommy Martino Committed by Commit Bot

[AF Android] Use rounded corners and elevation

This CL adds rounded corners and elevation to DropdownPopupWindowImpl.
It also adds a small util function to ApiCompatibilityUtils to
facilitate elevation.

Screenshots: https://docs.google.com/presentation/d/1cSW-l62jY_6HB3UA-KDg8JlguNrVJlncse9HL7xIhuU/edit?usp=sharing

BUG: 874077
Change-Id: Icd01731c2f7292d3ea1397e6790525af00bfa71d
Reviewed-on: https://chromium-review.googlesource.com/c/1265595Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Tommy Martino <tmartino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#598761}
parent 2be780e8
...@@ -46,6 +46,7 @@ import android.view.WindowManager; ...@@ -46,6 +46,7 @@ import android.view.WindowManager;
import android.view.inputmethod.InputMethodSubtype; import android.view.inputmethod.InputMethodSubtype;
import android.view.textclassifier.TextClassifier; import android.view.textclassifier.TextClassifier;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView; import android.widget.TextView;
import java.io.File; import java.io.File;
...@@ -325,6 +326,17 @@ public class ApiCompatibilityUtils { ...@@ -325,6 +326,17 @@ public class ApiCompatibilityUtils {
return true; return true;
} }
/**
* Set elevation if supported.
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static boolean setElevation(PopupWindow window, float elevationValue) {
if (!isElevationSupported()) return false;
window.setElevation(elevationValue);
return true;
}
/** /**
* Gets an intent to start the Android system notification settings activity for an app. * Gets an intent to start the Android system notification settings activity for an app.
* *
......
...@@ -150,7 +150,7 @@ public abstract class SuggestionsPopupWindow ...@@ -150,7 +150,7 @@ public abstract class SuggestionsPopupWindow
// Set this on the content view instead of on the PopupWindow so we can retrieve the // Set this on the content view instead of on the PopupWindow so we can retrieve the
// padding later. // padding later.
mContentView.setBackground(ApiCompatibilityUtils.getDrawable( mContentView.setBackground(ApiCompatibilityUtils.getDrawable(
mContext.getResources(), R.drawable.dropdown_popup_background)); mContext.getResources(), R.drawable.popup_bg));
} }
// mPopupVerticalMargin is the minimum amount of space we want to have between the popup // mPopupVerticalMargin is the minimum amount of space we want to have between the popup
......
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2014 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_above_anchor="true"
android:drawable="@drawable/dropdown_popup_background_up" />
<item android:drawable="@drawable/dropdown_popup_background_down" />
</selector>
\ No newline at end of file
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<resources xmlns:tools="http://schemas.android.com/tools"> <resources xmlns:tools="http://schemas.android.com/tools">
<style name="DropdownPopupWindow" parent="@android:style/Widget.ListPopupWindow"> <style name="DropdownPopupWindow" parent="@android:style/Widget.ListPopupWindow">
<item name="android:popupBackground">@drawable/dropdown_popup_background</item> <item name="android:popupBackground">@drawable/popup_bg</item>
</style> </style>
<!-- Buttons --> <!-- Buttons -->
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
<dimen name="dropdown_item_label_margin">10dp</dimen> <dimen name="dropdown_item_label_margin">10dp</dimen>
<dimen name="dropdown_icon_margin">8dp</dimen> <dimen name="dropdown_icon_margin">8dp</dimen>
<dimen name="dropdown_vertical_margin">4dp</dimen> <dimen name="dropdown_vertical_margin">4dp</dimen>
<dimen name="dropdown_elevation">2dp</dimen>
<dimen name="button_compat_corner_radius">4dp</dimen> <dimen name="button_compat_corner_radius">4dp</dimen>
<!-- Divider Dimensions --> <!-- Divider Dimensions -->
......
...@@ -82,12 +82,14 @@ class DropdownPopupWindowImpl ...@@ -82,12 +82,14 @@ class DropdownPopupWindowImpl
ViewRectProvider rectProvider = new ViewRectProvider(mAnchorView); ViewRectProvider rectProvider = new ViewRectProvider(mAnchorView);
rectProvider.setIncludePadding(true); rectProvider.setIncludePadding(true);
mBackground = ApiCompatibilityUtils.getDrawable( mBackground =
context.getResources(), R.drawable.dropdown_popup_background); ApiCompatibilityUtils.getDrawable(context.getResources(), R.drawable.popup_bg);
mAnchoredPopupWindow = new AnchoredPopupWindow( mAnchoredPopupWindow = new AnchoredPopupWindow(
context, mAnchorView, mBackground, mContentView, rectProvider); context, mAnchorView, mBackground, mContentView, rectProvider);
mAnchoredPopupWindow.addOnDismissListener(onDismissLitener); mAnchoredPopupWindow.addOnDismissListener(onDismissLitener);
mAnchoredPopupWindow.setLayoutObserver(this); mAnchoredPopupWindow.setLayoutObserver(this);
mAnchoredPopupWindow.setElevation(
context.getResources().getDimensionPixelSize(R.dimen.dropdown_elevation));
Rect paddingRect = new Rect(); Rect paddingRect = new Rect();
mBackground.getPadding(paddingRect); mBackground.getPadding(paddingRect);
rectProvider.setInsetPx(0, /* top= */ paddingRect.bottom, 0, /* bottom= */ paddingRect.top); rectProvider.setInsetPx(0, /* top= */ paddingRect.bottom, 0, /* bottom= */ paddingRect.top);
...@@ -115,11 +117,8 @@ class DropdownPopupWindowImpl ...@@ -115,11 +117,8 @@ class DropdownPopupWindowImpl
public void onPreLayoutChange( public void onPreLayoutChange(
boolean positionBelow, int x, int y, int width, int height, Rect anchorRect) { boolean positionBelow, int x, int y, int width, int height, Rect anchorRect) {
mBackground.setBounds(anchorRect); mBackground.setBounds(anchorRect);
mAnchoredPopupWindow.setBackgroundDrawable(positionBelow mAnchoredPopupWindow.setBackgroundDrawable(
? ApiCompatibilityUtils.getDrawable(mContext.getResources(), ApiCompatibilityUtils.getDrawable(mContext.getResources(), R.drawable.popup_bg));
R.drawable.dropdown_popup_background_down)
: ApiCompatibilityUtils.getDrawable(mContext.getResources(),
R.drawable.dropdown_popup_background_up));
} }
/** /**
......
...@@ -20,6 +20,7 @@ import android.view.WindowManager; ...@@ -20,6 +20,7 @@ import android.view.WindowManager;
import android.widget.PopupWindow; import android.widget.PopupWindow;
import android.widget.PopupWindow.OnDismissListener; import android.widget.PopupWindow.OnDismissListener;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ObserverList; import org.chromium.base.ObserverList;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
...@@ -344,6 +345,13 @@ public class AnchoredPopupWindow implements OnTouchListener, RectProvider.Observ ...@@ -344,6 +345,13 @@ public class AnchoredPopupWindow implements OnTouchListener, RectProvider.Observ
mPopupWindow.setBackgroundDrawable(background); mPopupWindow.setBackgroundDrawable(background);
} }
/**
* Sets the elevation of the popup, if elevation is supported.
*/
public void setElevation(float elevation) {
ApiCompatibilityUtils.setElevation(mPopupWindow, elevation);
}
// RectProvider.Observer implementation. // RectProvider.Observer implementation.
@Override @Override
public void onRectChanged() { public void onRectChanged() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment