Bug 965070 - Support GridViews in dynamic panels. r=lucasr
authorSola Ogunsakin <oogunsakin@mozilla.com>
Wed, 29 Jan 2014 16:37:58 -0800
changeset 183028 0935601c8611c1a301acea0633c9720f21c69460
parent 183027 9ed86b468f73de63f402a350017d567232ccd3e9
child 183029 16dbb9ba6d52e82534828fb2a181b100edef5c6d
push id462
push userraliiev@mozilla.com
push dateTue, 22 Apr 2014 00:22:30 +0000
treeherdermozilla-release@ac5db8c74ac0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr
bugs965070
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 965070 - Support GridViews in dynamic panels. r=lucasr
mobile/android/base/home/HomeConfig.java
mobile/android/base/home/PanelGridItemView.java
mobile/android/base/home/PanelGridView.java
mobile/android/base/home/PanelLayout.java
mobile/android/base/moz.build
mobile/android/base/resources/layout/panel_grid_item_view.xml
mobile/android/base/resources/values-large-land-v11/styles.xml
mobile/android/base/resources/values-large-v11/styles.xml
mobile/android/base/resources/values-v11/themes.xml
mobile/android/base/resources/values-xlarge-land-v11/styles.xml
mobile/android/base/resources/values/attrs.xml
mobile/android/base/resources/values/styles.xml
mobile/android/base/resources/values/themes.xml
--- a/mobile/android/base/home/HomeConfig.java
+++ b/mobile/android/base/home/HomeConfig.java
@@ -383,17 +383,18 @@ public final class HomeConfig {
             @Override
             public LayoutType[] newArray(final int size) {
                 return new LayoutType[size];
             }
         };
     }
 
     public static enum ViewType implements Parcelable {
-        LIST("list");
+        LIST("list"),
+        GRID("grid");
 
         private final String mId;
 
         ViewType(String id) {
             mId = id;
         }
 
         public static ViewType fromId(String id) {
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/home/PanelGridItemView.java
@@ -0,0 +1,52 @@
+/* -*- 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.home;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.mozilla.gecko.db.BrowserContract.URLColumns;
+import org.mozilla.gecko.favicons.Favicons;
+import org.mozilla.gecko.R;
+
+import android.content.Context;
+import android.database.Cursor;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Color;
+import android.text.TextUtils;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.ImageView.ScaleType;
+import android.widget.FrameLayout;
+import android.widget.TextView;
+
+public class PanelGridItemView extends FrameLayout {
+    private static final String LOGTAG = "GeckoPanelGridItemView";
+
+    private final ImageView mThumbnailView;
+
+    public PanelGridItemView(Context context) {
+        this(context, null);
+    }
+
+    public PanelGridItemView(Context context, AttributeSet attrs) {
+        this(context, attrs, 0);
+    }
+
+    public PanelGridItemView(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+
+        LayoutInflater.from(context).inflate(R.layout.panel_grid_item_view, this);
+        mThumbnailView = (ImageView) findViewById(R.id.image);
+        mThumbnailView.setBackgroundColor(Color.rgb(255, 148, 0));
+    }
+
+    public void updateFromCursor(Cursor cursor) { }
+}
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/home/PanelGridView.java
@@ -0,0 +1,54 @@
+/* -*- 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.home;
+
+import org.mozilla.gecko.R;
+import org.mozilla.gecko.home.HomeConfig.ViewConfig;
+import org.mozilla.gecko.home.PanelLayout.DatasetBacked;
+
+import android.content.Context;
+import android.database.Cursor;
+import android.support.v4.widget.CursorAdapter;
+import android.util.Log;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.GridView;
+
+public class PanelGridView extends GridView implements DatasetBacked {
+    private static final String LOGTAG = "GeckoPanelGridView";
+
+    private final PanelGridViewAdapter mAdapter;
+
+    public PanelGridView(Context context, ViewConfig viewConfig) {
+        super(context, null, R.attr.homeGridViewStyle);
+        mAdapter = new PanelGridViewAdapter(context);
+        setAdapter(mAdapter);
+        setNumColumns(AUTO_FIT);
+    }
+
+    @Override
+    public void setDataset(Cursor cursor) {
+        mAdapter.swapCursor(cursor);
+    }
+
+    private class PanelGridViewAdapter extends CursorAdapter {
+
+        public PanelGridViewAdapter(Context context) {
+            super(context, null, 0);
+        }
+
+        @Override
+        public void bindView(View bindView, Context context, Cursor cursor) {
+            final PanelGridItemView item = (PanelGridItemView) bindView;
+            item.updateFromCursor(cursor);
+        }
+
+        @Override
+        public View newView(Context context, Cursor cursor, ViewGroup parent) {
+            return new PanelGridItemView(context);
+        }
+    }
+}
--- a/mobile/android/base/home/PanelLayout.java
+++ b/mobile/android/base/home/PanelLayout.java
@@ -139,16 +139,20 @@ abstract class PanelLayout extends Frame
 
         Log.d(LOGTAG, "Creating panel view: " + viewConfig.getType());
 
         switch(viewConfig.getType()) {
             case LIST:
                 view = new PanelListView(getContext(), viewConfig);
                 break;
 
+            case GRID:
+                view = new PanelGridView(getContext(), viewConfig);
+                break;
+
             default:
                 throw new IllegalStateException("Unrecognized view type in " + getClass().getSimpleName());
         }
 
         final ViewEntry entry = new ViewEntry(view, viewConfig);
         mViewEntries.add(entry);
 
         return view;
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -224,16 +224,18 @@ gbjar.sources += [
     'home/HomeConfigPrefsBackend.java',
     'home/HomeFragment.java',
     'home/HomeListView.java',
     'home/HomePager.java',
     'home/HomePagerTabStrip.java',
     'home/LastTabsPanel.java',
     'home/MostRecentPanel.java',
     'home/MultiTypeCursorAdapter.java',
+    'home/PanelGridItemView.java',
+    'home/PanelGridView.java',
     'home/PanelLayout.java',
     'home/PanelListRow.java',
     'home/PanelListView.java',
     'home/PanelManager.java',
     'home/PinSiteDialog.java',
     'home/ReadingListPanel.java',
     'home/SearchEngine.java',
     'home/SearchEngineRow.java',
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/resources/layout/panel_grid_item_view.xml
@@ -0,0 +1,14 @@
+<?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/. -->
+
+<merge xmlns:android="http://schemas.android.com/apk/res/android"
+       xmlns:gecko="http://schemas.android.com/apk/res-auto">
+
+    <ImageView android:id="@+id/image"
+               android:layout_width="fill_parent"
+               android:layout_height="80dp"
+               android:layout_marginRight="5dp" />
+
+</merge>
--- a/mobile/android/base/resources/values-large-land-v11/styles.xml
+++ b/mobile/android/base/resources/values-large-land-v11/styles.xml
@@ -23,24 +23,26 @@
     <style name="Widget.BookmarksListView" parent="Widget.HomeListView">
         <item name="android:paddingTop">30dp</item>
         <item name="android:paddingLeft">120dp</item>
         <item name="android:paddingRight">120dp</item>
         <item name="android:scrollbarStyle">outsideOverlay</item>
         <item name="topDivider">true</item>
     </style>
 
-    <style name="Widget.TopSitesGridView" parent="Widget.GridView">
+    <style name="Widget.HomeGridView" parent="Widget.GridView">
         <item name="android:paddingLeft">55dp</item>
         <item name="android:paddingRight">55dp</item>
         <item name="android:paddingBottom">30dp</item>
         <item name="android:horizontalSpacing">20dp</item>
         <item name="android:verticalSpacing">20dp</item>
     </style>
 
+    <style name="Widget.TopSitesGridView" parent="Widget.HomeGridView" />
+
     <style name="Widget.Home.HistoryListView">
         <item name="android:paddingLeft">50dp</item>
         <item name="android:paddingRight">100dp</item>
         <item name="android:paddingTop">30dp</item>
         <item name="android:scrollbarStyle">outsideOverlay</item>
         <item name="topDivider">true</item>
     </style>
 
--- a/mobile/android/base/resources/values-large-v11/styles.xml
+++ b/mobile/android/base/resources/values-large-v11/styles.xml
@@ -72,24 +72,26 @@
     <style name="Widget.BookmarksListView" parent="Widget.HomeListView">
         <item name="android:paddingTop">30dp</item>
         <item name="android:paddingLeft">32dp</item>
         <item name="android:paddingRight">32dp</item>
         <item name="android:scrollbarStyle">outsideOverlay</item>
         <item name="topDivider">true</item>
     </style>
 
-    <style name="Widget.TopSitesGridView" parent="Widget.GridView">
+    <style name="Widget.HomeGridView" parent="Widget.GridView">
         <item name="android:paddingLeft">5dp</item>
         <item name="android:paddingRight">5dp</item>
         <item name="android:paddingBottom">30dp</item>
         <item name="android:horizontalSpacing">10dp</item>
         <item name="android:verticalSpacing">10dp</item>
     </style>
 
+    <style name="Widget.TopSitesGridView" parent="Widget.HomeGridView" />
+
     <style name="Widget.TopSitesListView" parent="Widget.BookmarksListView">
         <item name="topDivider">false</item>
     </style>
 
     <style name="Widget.ReadingListView" parent="Widget.BookmarksListView"/>
 
     <style name="Widget.Home.HistoryPanelTitle" parent="Widget.Home.HistoryTabIndicator">
         <item name="android:layout_marginLeft">32dp</item>
--- a/mobile/android/base/resources/values-v11/themes.xml
+++ b/mobile/android/base/resources/values-v11/themes.xml
@@ -42,16 +42,17 @@
         <item name="menuItemActionBarStyle">@style/Widget.MenuItemActionBar</item>
         <item name="menuItemActionViewStyle">@style/Widget.MenuItemActionView</item>
         <item name="menuItemDefaultStyle">@style/Widget.MenuItemDefault</item>
         <item name="menuItemSecondaryActionBarStyle">@style/Widget.MenuItemSecondaryActionBar</item>
         <item name="menuItemShareActionButtonStyle">@style/Widget.MenuItemSecondaryActionBar</item>
         <item name="bookmarksListViewStyle">@style/Widget.BookmarksListView</item>
         <item name="topSitesGridItemViewStyle">@style/Widget.TopSitesGridItemView</item>
         <item name="topSitesGridViewStyle">@style/Widget.TopSitesGridView</item>
+        <item name="homeGridViewStyle">@style/Widget.HomeGridView</item>
         <item name="topSitesThumbnailViewStyle">@style/Widget.TopSitesThumbnailView</item>
         <item name="homeListViewStyle">@style/Widget.HomeListView</item>
         <item name="geckoMenuListViewStyle">@style/Widget.GeckoMenuListView</item>
         <item name="menuItemActionModeStyle">@style/GeckoActionBar.Button</item>
         <item name="android:actionModeStyle">@style/GeckoActionBar</item>
         <item name="android:actionButtonStyle">@style/GeckoActionBar.Button</item>
         <item name="android:actionModeCutDrawable">@drawable/ab_cut</item>
         <item name="android:actionModeCopyDrawable">@drawable/ab_copy</item>
--- a/mobile/android/base/resources/values-xlarge-land-v11/styles.xml
+++ b/mobile/android/base/resources/values-xlarge-land-v11/styles.xml
@@ -1,23 +1,25 @@
 <?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/. -->
 
 <resources>
 
-    <style name="Widget.TopSitesGridView" parent="Widget.GridView">
+    <style name="Widget.HomeGridView" parent="Widget.GridView">
         <item name="android:paddingLeft">55dp</item>
         <item name="android:paddingRight">55dp</item>
         <item name="android:paddingBottom">30dp</item>
         <item name="android:horizontalSpacing">56dp</item>
         <item name="android:verticalSpacing">20dp</item>
     </style>
 
+    <style name="Widget.TopSitesGridView" parent="Widget.HomeGridView" />
+
     <style name="Widget.Home.HistoryListView">
         <item name="android:paddingLeft">50dp</item>
         <item name="android:paddingRight">100dp</item>
         <item name="android:paddingTop">30dp</item>
         <item name="android:scrollbarStyle">outsideOverlay</item>
         <item name="topDivider">true</item>
     </style>
 
--- a/mobile/android/base/resources/values/attrs.xml
+++ b/mobile/android/base/resources/values/attrs.xml
@@ -30,16 +30,19 @@
         <attr name="menuItemShareActionButtonStyle" format="reference"/>
 
         <!-- Default style for the BookmarksListView -->
         <attr name="bookmarksListViewStyle" format="reference" />
 
         <!-- Default style for the TopSitesGridItemView -->
         <attr name="topSitesGridItemViewStyle" format="reference" />
 
+        <!-- Default style for the HomeGridView -->
+        <attr name="homeGridViewStyle" format="reference" />
+
         <!-- Default style for the TopSitesGridView -->
         <attr name="topSitesGridViewStyle" format="reference" />
 
         <!-- Default style for the TopSitesThumbnailView -->
         <attr name="topSitesThumbnailViewStyle" format="reference" />
 
         <!-- Default style for the HomeListView -->
         <attr name="homeListViewStyle" format="reference" />
--- a/mobile/android/base/resources/values/styles.xml
+++ b/mobile/android/base/resources/values/styles.xml
@@ -125,22 +125,24 @@
     </style>
 
     <style name="Widget.BookmarkFolderView" parent="Widget.TwoLineRow.PrimaryText">
         <item name="android:paddingLeft">10dip</item>
         <item name="android:drawablePadding">10dip</item>
         <item name="android:drawableLeft">@drawable/bookmark_folder</item>
     </style>
 
-    <style name="Widget.TopSitesGridView" parent="Widget.GridView">
+    <style name="Widget.HomeGridView" parent="Widget.GridView">
         <item name="android:padding">7dp</item>
         <item name="android:horizontalSpacing">0dp</item>
         <item name="android:verticalSpacing">7dp</item>
     </style>
 
+    <style name="Widget.TopSitesGridView" parent="Widget.HomeGridView" />
+
     <style name="Widget.TopSitesGridItemView">
       <item name="android:layout_width">fill_parent</item>
       <item name="android:layout_height">fill_parent</item>
       <item name="android:padding">5dip</item>
       <item name="android:orientation">vertical</item>
     </style>
 
     <style name="Widget.BookmarkItemView" parent="Widget.TwoLineRow"/>
--- a/mobile/android/base/resources/values/themes.xml
+++ b/mobile/android/base/resources/values/themes.xml
@@ -75,16 +75,17 @@
         <item name="android:dropDownItemStyle">@style/Widget.DropDownItem</item>
         <item name="android:editTextStyle">@style/Widget.EditText</item>
         <item name="android:gridViewStyle">@style/Widget.GridView</item>
         <item name="android:textViewStyle">@style/Widget.TextView</item>
         <item name="android:spinnerStyle">@style/Widget.Spinner</item>
         <item name="bookmarksListViewStyle">@style/Widget.BookmarksListView</item>
         <item name="topSitesGridItemViewStyle">@style/Widget.TopSitesGridItemView</item>
         <item name="topSitesGridViewStyle">@style/Widget.TopSitesGridView</item>
+        <item name="homeGridViewStyle">@style/Widget.HomeGridView</item>
         <item name="topSitesThumbnailViewStyle">@style/Widget.TopSitesThumbnailView</item>
         <item name="homeListViewStyle">@style/Widget.HomeListView</item>
         <item name="geckoMenuListViewStyle">@style/Widget.GeckoMenuListView</item>
         <item name="menuItemDefaultStyle">@style/Widget.MenuItemDefault</item>
         <item name="menuItemActionBarStyle">@style/Widget.MenuItemActionBar</item>
         <item name="menuItemActionModeStyle">@style/GeckoActionBar.Button</item>
     </style>