Bug 1271428 - Use CardView for main menu r?sebastian draft
authorAndrzej Hunt <andrzej@ahunt.org>
Mon, 09 May 2016 15:18:07 -0700
changeset 365564 1910bee3c6649ba7a53ad48cc9335afda8f243c9
parent 365563 00f9e5202cc48631b75b970413e9be58d22c4e3f
child 365565 655c136c0417af9dcf129bcf9b66e92ccdc898e6
push id17789
push userbmo:ahunt@mozilla.com
push dateWed, 11 May 2016 03:29:35 +0000
reviewerssebastian
bugs1271428
milestone49.0a1
Bug 1271428 - Use CardView for main menu r?sebastian MozReview-Commit-ID: BCZ3tmgqY0z
mobile/android/base/java/org/mozilla/gecko/menu/MenuPopup.java
mobile/android/base/resources/drawable-hdpi/menu_popup_bg.9.png
mobile/android/base/resources/drawable-xhdpi/menu_popup_bg.9.png
mobile/android/base/resources/layout/menu_popup.xml
--- a/mobile/android/base/java/org/mozilla/gecko/menu/MenuPopup.java
+++ b/mobile/android/base/java/org/mozilla/gecko/menu/MenuPopup.java
@@ -5,46 +5,60 @@
 
 package org.mozilla.gecko.menu;
 
 import org.mozilla.gecko.R;
 
 import android.content.Context;
 import android.graphics.Color;
 import android.graphics.drawable.ColorDrawable;
+import android.os.Build;
+import android.support.v7.widget.CardView;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.FrameLayout;
 import android.widget.PopupWindow;
 
 /**
  * A popup to show the inflated MenuPanel.
  */
 public class MenuPopup extends PopupWindow {
-    private final FrameLayout mPanel;
+    private final CardView mPanel;
 
     private final int mPopupWidth;
 
     public MenuPopup(Context context) {
         super(context);
 
         setFocusable(true);
 
         mPopupWidth = context.getResources().getDimensionPixelSize(R.dimen.menu_popup_width);
 
         // Setting a null background makes the popup to not close on touching outside.
         setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
         setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT,
                             ViewGroup.LayoutParams.WRAP_CONTENT);
 
         LayoutInflater inflater = LayoutInflater.from(context);
-        mPanel = (FrameLayout) inflater.inflate(R.layout.menu_popup, null);
+        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 (Build.VERSION.SDK_INT < 21) {
+            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.
      */
deleted file mode 100644
index 6bfdcc1ed38d5859634741c82ebd5bd1cbc55d80..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 858d7f8fae277c25b0117c3fadc38fea01597167..0000000000000000000000000000000000000000
GIT binary patch
literal 0
Hc$@<O00001
--- a/mobile/android/base/resources/layout/menu_popup.xml
+++ b/mobile/android/base/resources/layout/menu_popup.xml
@@ -1,16 +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/. -->
 
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<android.support.v7.widget.CardView 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"
-              android:background="@drawable/menu_popup_bg">
+              app:cardBackgroundColor="@color/toolbar_grey"
+              app:cardUseCompatPadding="true">
 
     <!-- MenuPanel will be added here dynamically -->
 
-</FrameLayout>
+</android.support.v7.widget.CardView>
\ No newline at end of file