Bug 1137483 - Move search engine bar under keyboard when shown. r=liuche
This requires the window to resize when the keyboard is shown, which required a
revision in when we draw the window background.
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -2629,32 +2629,44 @@ public class BrowserApp extends GeckoApp
// (see bug 925012). Because of an Android bug (http://code.google.com/p/android/issues/detail?id=61179),
// calling FragmentTransaction#add immediately after FragmentTransaction#remove won't add the fragment's
// view to the layout. Calling FragmentManager#executePendingTransactions before re-adding the fragment
// prevents this issue.
fm.executePendingTransactions();
fm.beginTransaction().add(R.id.search_container, mBrowserSearch, BROWSER_SEARCH_TAG).commitAllowingStateLoss();
mBrowserSearch.setUserVisibleHint(true);
+
+ // We want to adjust the window size when the keyboard appears to bring the
+ // SearchEngineBar above the keyboard. However, adjusting the window size
+ // when hiding the keyboard results in graphical glitches where the keyboard was
+ // because nothing was being drawn underneath (bug 933422). This can be
+ // prevented drawing content under the keyboard (i.e. in the Window).
+ //
+ // We do this here because there are glitches when unlocking a device with
+ // BrowserSearch in the foreground if we use BrowserSearch.onStart/Stop.
+ getActivity().getWindow().setBackgroundDrawableResource(android.R.color.white);
}
private void hideBrowserSearch() {
if (!mBrowserSearch.getUserVisibleHint()) {
return;
}
// To prevent overdraw, the HomePager is hidden when BrowserSearch is displayed:
// reverse that.
mHomePagerContainer.setVisibility(View.VISIBLE);
mBrowserSearchContainer.setVisibility(View.INVISIBLE);
getSupportFragmentManager().beginTransaction()
.remove(mBrowserSearch).commitAllowingStateLoss();
mBrowserSearch.setUserVisibleHint(false);
+
+ getWindow().setBackgroundDrawable(null);
}
/**
* Hides certain UI elements (e.g. button toast, tabs panel) when the
* user touches the main layout.
*/
private class HideOnTouchListener implements TouchEventInterceptor {
private boolean mIsHidingTabs;
--- a/mobile/android/base/home/BrowserSearch.java
+++ b/mobile/android/base/home/BrowserSearch.java
@@ -226,33 +226,16 @@ public class BrowserSearch extends HomeF
@Override
public void onDestroy() {
super.onDestroy();
mSearchEngines = null;
}
@Override
- public void onStart() {
- super.onStart();
-
- // Adjusting the window size when showing the keyboard results in the underlying
- // activity being painted when the keyboard is hidden (bug 933422). This can be
- // prevented by not resizing the window.
- getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
- }
-
- @Override
- public void onStop() {
- super.onStop();
-
- getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
- }
-
- @Override
public void onResume() {
super.onResume();
// Fetch engines if we need to.
if (mSearchEngines.isEmpty() || !Locale.getDefault().equals(mLastLocale)) {
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SearchEngines:GetVisible", null));
}
--- a/mobile/android/base/resources/layout/browser_search.xml
+++ b/mobile/android/base/resources/layout/browser_search.xml
@@ -14,20 +14,25 @@
android:layout="@layout/home_suggestion_prompt" />
<view class="org.mozilla.gecko.home.BrowserSearch$HomeSearchListView"
android:id="@+id/home_list_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
+ <!-- The window background is set to our desired color, #fff, so
+ reduce overdraw by not drawing the background.
+
+ Note: this needs to be transparent and not null because we
+ draw a divider in onDraw. -->
<view class="org.mozilla.gecko.home.SearchEngineBar$SearchEngineBarContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:background="#fff">
+ android:background="@android:color/transparent">
<!-- We add a marginTop so the outer container can draw a divider.
listSelector is too slow for showing pressed state
so we set the pressed colors on the child. -->
<org.mozilla.gecko.home.SearchEngineBar
android:id="@+id/search_engine_bar"
android:layout_width="wrap_content"
--- a/mobile/android/base/resources/layout/gecko_app.xml
+++ b/mobile/android/base/resources/layout/gecko_app.xml
@@ -72,17 +72,16 @@
android:layout_alignParentBottom="true"
style="@style/FindBar"
android:visibility="gone"/>
<FrameLayout android:id="@+id/search_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/browser_chrome"
- android:background="@android:color/white"
android:visibility="invisible"/>
<!-- When focus is cleared from from BrowserToolbar's EditText to
lower the virtual keyboard, focus will be returned to the root
view. To make sure the EditText is not the first focusable view in
the root view, BrowserToolbar should be specified as low in the
view hierarchy as possible. -->