Bug 884851 - Replace the mIsAutoComplete boolean with an enum. r=kats

This commit is contained in:
Michael Nares 2014-01-21 14:24:52 -05:00
parent 10b18773b9
commit 586200c281

View File

@ -51,7 +51,12 @@ public class FormAssistPopup extends RelativeLayout implements GeckoEventListene
private double mY;
private double mW;
private double mH;
private boolean mIsAutoComplete = true;
private enum PopupType {
AUTOCOMPLETE,
VALIDATIONMESSAGE;
}
private PopupType mPopupType;
private static int sAutoCompleteMinWidth = 0;
private static int sAutoCompleteRowHeight = 0;
@ -208,7 +213,8 @@ public class FormAssistPopup extends RelativeLayout implements GeckoEventListene
return false;
}
mIsAutoComplete = isAutoComplete;
mPopupType = (isAutoComplete ?
PopupType.AUTOCOMPLETE : PopupType.VALIDATIONMESSAGE);
return true;
}
@ -227,9 +233,9 @@ public class FormAssistPopup extends RelativeLayout implements GeckoEventListene
// Hide/show the appropriate popup contents
if (mAutoCompleteList != null)
mAutoCompleteList.setVisibility(mIsAutoComplete ? VISIBLE : GONE);
mAutoCompleteList.setVisibility((mPopupType == PopupType.AUTOCOMPLETE) ? VISIBLE : GONE);
if (mValidationMessage != null)
mValidationMessage.setVisibility(mIsAutoComplete ? GONE : VISIBLE);
mValidationMessage.setVisibility((mPopupType == PopupType.AUTOCOMPLETE) ? GONE : VISIBLE);
if (sAutoCompleteMinWidth == 0) {
Resources res = mContext.getResources();
@ -255,7 +261,7 @@ public class FormAssistPopup extends RelativeLayout implements GeckoEventListene
// For autocomplete suggestions, if the input is smaller than the screen-width,
// shrink the popup's width. Otherwise, keep it as FILL_PARENT.
if (mIsAutoComplete && (left + width) < viewport.width) {
if ((mPopupType == PopupType.AUTOCOMPLETE) && (left + width) < viewport.width) {
popupWidth = left < 0 ? left + width : width;
// Ensure the popup has a minimum width.
@ -269,14 +275,14 @@ public class FormAssistPopup extends RelativeLayout implements GeckoEventListene
}
int popupHeight;
if (mIsAutoComplete)
if (mPopupType == PopupType.AUTOCOMPLETE)
popupHeight = sAutoCompleteRowHeight * mAutoCompleteList.getAdapter().getCount();
else
popupHeight = sValidationMessageHeight;
int popupTop = top + height;
if (!mIsAutoComplete) {
if (mPopupType == PopupType.VALIDATIONMESSAGE) {
mValidationMessageText.setLayoutParams(sValidationTextLayoutNormal);
mValidationMessageArrow.setVisibility(VISIBLE);
mValidationMessageArrowInverted.setVisibility(GONE);
@ -299,7 +305,7 @@ public class FormAssistPopup extends RelativeLayout implements GeckoEventListene
popupHeight = top;
}
if (!mIsAutoComplete) {
if (mPopupType == PopupType.VALIDATIONMESSAGE) {
mValidationMessageText.setLayoutParams(sValidationTextLayoutInverted);
mValidationMessageArrow.setVisibility(GONE);
mValidationMessageArrowInverted.setVisibility(VISIBLE);