From 91deaf4b78444198298046d04f2355cd412599f2 Mon Sep 17 00:00:00 2001 From: Michael Comella Date: Tue, 21 Apr 2015 17:12:43 -0700 Subject: [PATCH] Bug 1137483 - Center SearchEngineBar when it doesn't fill the screen. r=liuche --HG-- extra : rebase_source : f0b129e08472e8b2430e2a3d8e64691fd4311dcb --- mobile/android/base/home/SearchEngineBar.java | 42 +++++++++++++------ .../base/resources/layout/browser_search.xml | 38 +++++++++-------- .../layout/search_engine_bar_item.xml | 2 +- 3 files changed, 51 insertions(+), 31 deletions(-) diff --git a/mobile/android/base/home/SearchEngineBar.java b/mobile/android/base/home/SearchEngineBar.java index f7ffe230328b..9374c9b97669 100644 --- a/mobile/android/base/home/SearchEngineBar.java +++ b/mobile/android/base/home/SearchEngineBar.java @@ -14,6 +14,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.BaseAdapter; +import android.widget.FrameLayout; import org.mozilla.gecko.R; import org.mozilla.gecko.widget.FaviconView; @@ -33,24 +34,12 @@ public class SearchEngineBar extends TwoWayView private final SearchEngineAdapter adapter; private OnSearchBarClickListener onSearchBarClickListener; - private final Paint dividerPaint; - public SearchEngineBar(final Context context, final AttributeSet attrs) { super(context, attrs); adapter = new SearchEngineAdapter(); setAdapter(adapter); setOnItemClickListener(this); - - dividerPaint = new Paint(); - dividerPaint.setColor(getResources().getColor(R.color.divider_light)); - } - - @Override - public void onDraw(final Canvas canvas) { - super.onDraw(canvas); - - canvas.drawLine(0, 0, getWidth(), 0, dividerPaint); } @Override @@ -112,4 +101,33 @@ public class SearchEngineBar extends TwoWayView return view; } } + + /** + * A Container to surround the SearchEngineBar. This is necessary so we can draw + * a divider across the entire width of the screen, but have the inner list layout + * not take up the full width of the screen so it can be centered within this container + * if there aren't enough items that it needs to scroll. + * + * Note: a better implementation would have this View inflating an inner layout so + * the containing layout doesn't need two "SearchEngineBar" Views but it wasn't + * worth the refactor time. + */ + @SuppressWarnings("unused") // via XML + public static class SearchEngineBarContainer extends FrameLayout { + private final Paint dividerPaint; + + public SearchEngineBarContainer(final Context context, final AttributeSet attrs) { + super(context, attrs); + + dividerPaint = new Paint(); + dividerPaint.setColor(getResources().getColor(R.color.divider_light)); + } + + @Override + public void onDraw(final Canvas canvas) { + super.onDraw(canvas); + + canvas.drawLine(0, 0, getWidth(), 0, dividerPaint); + } + } } diff --git a/mobile/android/base/resources/layout/browser_search.xml b/mobile/android/base/resources/layout/browser_search.xml index 11fe78cd8fc3..27f9ebc1d8d5 100644 --- a/mobile/android/base/resources/layout/browser_search.xml +++ b/mobile/android/base/resources/layout/browser_search.xml @@ -19,24 +19,26 @@ android:layout_height="0dp" android:layout_weight="1" /> - - + android:layout_height="wrap_content" + android:background="#fff"> + + + + + diff --git a/mobile/android/base/resources/layout/search_engine_bar_item.xml b/mobile/android/base/resources/layout/search_engine_bar_item.xml index 6d0e9e2ee288..3230afc7093a 100644 --- a/mobile/android/base/resources/layout/search_engine_bar_item.xml +++ b/mobile/android/base/resources/layout/search_engine_bar_item.xml @@ -11,7 +11,7 @@ View (browser_search at the time of this writing). -->