Bug 1293790 - Pre: extract CardView corner workaround into FilledCardView r?sebastian
We'll need this workaround for all the other CardView's we use.
MozReview-Commit-ID: 1B96Y2ZNKrY
--- a/mobile/android/base/java/org/mozilla/gecko/menu/MenuPopup.java
+++ b/mobile/android/base/java/org/mozilla/gecko/menu/MenuPopup.java
@@ -37,28 +37,16 @@ public class MenuPopup extends PopupWind
setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
LayoutInflater inflater = LayoutInflater.from(context);
mPanel = (CardView) inflater.inflate(R.layout.menu_popup, null);
setContentView(mPanel);
- // Disable corners on < lollipop:
- // CardView only supports clipping content on API >= 21 (for performance reasons). Without
- // content clipping the "action bar" will look ugly because it has its own background:
- // by default there's a 2px white edge along the top and sides (i.e. an inset corresponding
- // to the corner radius), if we disable the inset then the corners overlap.
- // It's possible to implement custom clipping, however given that the support library
- // chose not to support this for performance reasons, we too have chosen to just disable
- // corners on < 21, see Bug 1271428.
- if (AppConstants.Versions.preLollipop) {
- mPanel.setRadius(0);
- }
-
setAnimationStyle(R.style.PopupAnimation);
}
/**
* Adds the panel with the menu to its content.
*
* @param view The panel view with the menu to be shown.
*/
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/widget/FilledCardView.java
@@ -0,0 +1,39 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.mozilla.gecko.widget;
+
+import android.content.Context;
+import android.support.v7.widget.CardView;
+import android.util.AttributeSet;
+
+import org.mozilla.gecko.AppConstants;
+
+/**
+ * CardView that ensures its content can fill the entire card. Use this instead of CardView
+ * if you want to fill the card with e.g. images, backgrounds, etc.
+ *
+ * On API < 21, CardView content isn't clipped for performance reasons. We work around this by disabling
+ * rounded corners on those devices.
+ */
+public class FilledCardView extends CardView {
+
+ public FilledCardView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+
+ // Disable corners on < lollipop:
+ // CardView only supports clipping content on API >= 21 (for performance reasons). Without
+ // content clipping, any cards that provide their own content that fills the card will look
+ // ugly: by default there is a 2px white edge along the top and sides (i.e. an inset corresponding
+ // to the corner radius), if we disable the inset then the corners overlap.
+ // It's possible to implement custom clipping, however given that the support library
+ // chose not to support this for performance reasons, we too have chosen to just disable
+ // corners on < 21, see Bug 1271428.
+ if (AppConstants.Versions.preLollipop) {
+ setRadius(0);
+ }
+
+ setUseCompatPadding(true);
+ }
+}
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -666,16 +666,17 @@ gbjar.sources += ['java/org/mozilla/geck
'widget/DoorHanger.java',
'widget/DoorhangerConfig.java',
'widget/EllipsisTextView.java',
'widget/ExternalIntentDuringPrivateBrowsingPromptFragment.java',
'widget/FadedMultiColorTextView.java',
'widget/FadedSingleColorTextView.java',
'widget/FadedTextView.java',
'widget/FaviconView.java',
+ 'widget/FilledCardView.java',
'widget/FlowLayout.java',
'widget/GeckoActionProvider.java',
'widget/GeckoPopupMenu.java',
'widget/HistoryDividerItemDecoration.java',
'widget/IconTabWidget.java',
'widget/LoginDoorHanger.java',
'widget/RecyclerViewClickSupport.java',
'widget/ResizablePathDrawable.java',
--- a/mobile/android/base/resources/layout/menu_popup.xml
+++ b/mobile/android/base/resources/layout/menu_popup.xml
@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
-<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
+<org.mozilla.gecko.widget.FilledCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/menu_panel"
android:layout_width="@dimen/menu_popup_width"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:minWidth="@dimen/menu_popup_width"
app:cardBackgroundColor="@color/toolbar_grey"
app:cardUseCompatPadding="true">
<!-- MenuPanel will be added here dynamically -->
-</android.support.v7.widget.CardView>
\ No newline at end of file
+</org.mozilla.gecko.widget.FilledCardView>
\ No newline at end of file