Bug 769237: Menu popup arrow position doesn't need to be calculated. [r=mfinkle]

--HG--
extra : rebase_source : ae4e17c08a73223d49adfe55bb989261abb00f67
This commit is contained in:
Sriram Ramasubramanian 2012-07-09 13:23:16 -07:00
parent 4216d42ea8
commit c081f744e3
2 changed files with 4 additions and 31 deletions

View File

@ -548,7 +548,7 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
return false;
if (mMenuPopup != null && !mMenuPopup.isShowing())
mMenuPopup.show(mMenu);
mMenuPopup.showAsDropDown(mMenu);
return true;
}
@ -565,7 +565,6 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
// MenuPopup holds the MenuPanel in Honeycomb/ICS devices with no hardware key
public class MenuPopup extends PopupWindow {
private ImageView mArrow;
private RelativeLayout mPanel;
public MenuPopup(Context context) {
@ -581,7 +580,6 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.menu_popup, null);
setContentView(layout);
mArrow = (ImageView) layout.findViewById(R.id.menu_arrow);
mPanel = (RelativeLayout) layout.findViewById(R.id.menu_panel);
}
@ -589,32 +587,5 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
mPanel.removeAllViews();
mPanel.addView(view);
}
public void show(View anchor) {
showAsDropDown(anchor);
int location[] = new int[2];
anchor.getLocationOnScreen(location);
int menuButtonWidth = anchor.getWidth();
int arrowWidth = mArrow.getWidth();
int rightMostEdge = location[0] + menuButtonWidth;
DisplayMetrics metrics = new DisplayMetrics();
GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(metrics);
int leftMargin = (int)(240 * metrics.density) - (metrics.widthPixels - location[0] - menuButtonWidth/2);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mArrow.getLayoutParams();
RelativeLayout.LayoutParams newParams = new RelativeLayout.LayoutParams(params);
newParams.setMargins(leftMargin,
params.topMargin,
0,
params.bottomMargin);
// From the left of popup, the arrow should move half of (menuButtonWidth - arrowWidth)
mArrow.setLayoutParams(newParams);
}
}
}

View File

@ -10,6 +10,7 @@
<RelativeLayout android:id="@+id/menu_panel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@drawable/menu_popup_bg">
<!-- MenuPanel will be added here dynamically -->
@ -20,7 +21,8 @@
android:layout_width="28dip"
android:layout_height="10dip"
android:layout_marginTop="2dip"
android:layout_alignParentRight="true"
android:layout_marginRight="8dip"
android:layout_alignRight="@id/menu_panel"
android:src="@drawable/menu_popup_arrow"
android:scaleType="fitXY"/>