Commit 3d52a11f authored by ankit2.kumar's avatar ankit2.kumar Committed by Commit bot

Making suggestion popup scrollable in landscape mode

Setting height for Suggestion popup correctly for portrait
as well as landscape mode so that it is scrollable and does
not overlap with IME.

BUG=409619

Review URL: https://codereview.chromium.org/517403003

Cr-Commit-Position: refs/heads/master@{#292917}
parent 8537d1c3
......@@ -5,6 +5,7 @@
package org.chromium.chrome.shell.omnibox;
import android.content.Context;
import android.graphics.Rect;
import android.os.Handler;
import android.text.Editable;
import android.text.TextUtils;
......@@ -20,6 +21,7 @@ import android.widget.TextView;
import org.chromium.chrome.browser.omnibox.AutocompleteController;
import org.chromium.chrome.browser.omnibox.AutocompleteController.OnSuggestionsReceivedListener;
import org.chromium.chrome.browser.omnibox.OmniboxSuggestion;
import org.chromium.chrome.shell.ChromeShellActivity;
import org.chromium.chrome.shell.ChromeShellToolbar;
import org.chromium.chrome.shell.R;
......@@ -40,6 +42,7 @@ public class SuggestionPopup implements OnSuggestionsReceivedListener, TextWatch
private Runnable mRequestSuggestions;
private ListPopupWindow mSuggestionsPopup;
private SuggestionArrayAdapter mSuggestionArrayAdapter;
private int mSuggestionsPopupItemsCount;
/**
* Initializes a suggestion popup that will track urlField value and display suggestions based
......@@ -57,6 +60,7 @@ public class SuggestionPopup implements OnSuggestionsReceivedListener, TextWatch
int oldLeft, int oldTop, int oldRight, int oldBottom) {
if (mSuggestionsPopup == null || !mSuggestionsPopup.isShowing()) return;
mSuggestionsPopup.setWidth(mUrlField.getWidth());
mSuggestionsPopup.setHeight(getSuggestionPopupHeight());
mSuggestionsPopup.show();
}
};
......@@ -98,13 +102,29 @@ public class SuggestionPopup implements OnSuggestionsReceivedListener, TextWatch
if (mRequestSuggestions != null) mRequestSuggestions = null;
}
// OnSuggestionsReceivedListener implementation
private int getSuggestionPopupHeight() {
Rect appRect = new Rect();
((ChromeShellActivity)mContext).getWindow().getDecorView().
getWindowVisibleDisplayFrame(appRect);
int dropDownItemHeight = mContext.getResources().
getDimensionPixelSize(R.dimen.dropdown_item_height);
// Applying margin height equal to |dropDownItemHeight| if constrained by app rect.
int popupHeight = appRect.height() - dropDownItemHeight;
if (mSuggestionsPopup != null) {
int height = mSuggestionsPopupItemsCount * dropDownItemHeight;
if (height < popupHeight)
popupHeight = height;
}
return popupHeight;
}
// OnSuggestionsReceivedListener implementation
@Override
public void onSuggestionsReceived(List<OmniboxSuggestion> suggestions,
String inlineAutocompleteText) {
if (!mUrlField.isFocused() || suggestions.isEmpty())
return;
mSuggestionsPopupItemsCount = suggestions.size();
if (mSuggestionsPopup == null) {
mSuggestionsPopup = new ListPopupWindow(
mContext, null, android.R.attr.autoCompleteTextViewStyle);
......@@ -116,9 +136,11 @@ public class SuggestionPopup implements OnSuggestionsReceivedListener, TextWatch
}
});
}
mSuggestionsPopup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NEEDED);
mSuggestionsPopup.setWidth(mUrlField.getWidth());
mSuggestionArrayAdapter =
new SuggestionArrayAdapter(mContext, R.layout.dropdown_item, suggestions);
mSuggestionsPopup.setHeight(getSuggestionPopupHeight());
mSuggestionsPopup.setAdapter(mSuggestionArrayAdapter);
mSuggestionsPopup.setAnchorView(mUrlField);
mSuggestionsPopup.setOnItemClickListener(new OnItemClickListener() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment