use of android.widget.FrameLayout in project platform_frameworks_base by android.
the class MenuPopup method measureIndividualMenuWidth.
/**
* Measures the width of the given menu view.
*
* @param view The view to measure.
* @return The width.
*/
protected static int measureIndividualMenuWidth(ListAdapter adapter, ViewGroup parent, Context context, int maxAllowedWidth) {
// Menus don't tend to be long, so this is more sane than it looks.
int maxWidth = 0;
View itemView = null;
int itemType = 0;
final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
final int count = adapter.getCount();
for (int i = 0; i < count; i++) {
final int positionType = adapter.getItemViewType(i);
if (positionType != itemType) {
itemType = positionType;
itemView = null;
}
if (parent == null) {
parent = new FrameLayout(context);
}
itemView = adapter.getView(i, itemView, parent);
itemView.measure(widthMeasureSpec, heightMeasureSpec);
final int itemWidth = itemView.getMeasuredWidth();
if (itemWidth >= maxAllowedWidth) {
return maxAllowedWidth;
} else if (itemWidth > maxWidth) {
maxWidth = itemWidth;
}
}
return maxWidth;
}
use of android.widget.FrameLayout in project platform_frameworks_base by android.
the class StandardMenuPopup method tryShow.
private boolean tryShow() {
if (isShowing()) {
return true;
}
if (mWasDismissed || mAnchorView == null) {
return false;
}
mShownAnchorView = mAnchorView;
mPopup.setOnDismissListener(this);
mPopup.setOnItemClickListener(this);
mPopup.setAdapter(mAdapter);
mPopup.setModal(true);
final View anchor = mShownAnchorView;
final boolean addGlobalListener = mTreeObserver == null;
// Refresh to latest
mTreeObserver = anchor.getViewTreeObserver();
if (addGlobalListener) {
mTreeObserver.addOnGlobalLayoutListener(mGlobalLayoutListener);
}
anchor.addOnAttachStateChangeListener(mAttachStateChangeListener);
mPopup.setAnchorView(anchor);
mPopup.setDropDownGravity(mDropDownGravity);
if (!mHasContentWidth) {
mContentWidth = measureIndividualMenuWidth(mAdapter, null, mContext, mPopupMaxWidth);
mHasContentWidth = true;
}
mPopup.setContentWidth(mContentWidth);
mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
mPopup.setEpicenterBounds(getEpicenterBounds());
mPopup.show();
ListView listView = mPopup.getListView();
listView.setOnKeyListener(this);
if (mShowTitle && mMenu.getHeaderTitle() != null) {
FrameLayout titleItemView = (FrameLayout) LayoutInflater.from(mContext).inflate(com.android.internal.R.layout.popup_menu_header_item_layout, listView, false);
TextView titleView = (TextView) titleItemView.findViewById(com.android.internal.R.id.title);
if (titleView != null) {
titleView.setText(mMenu.getHeaderTitle());
}
titleItemView.setEnabled(false);
listView.addHeaderView(titleItemView, null, false);
// Update to show the title.
mPopup.show();
}
return true;
}
use of android.widget.FrameLayout in project platform_frameworks_base by android.
the class CascadingMenuPopup method showMenu.
/**
* Prepares and shows the specified menu immediately.
*
* @param menu the menu to show
*/
private void showMenu(@NonNull MenuBuilder menu) {
final LayoutInflater inflater = LayoutInflater.from(mContext);
final MenuAdapter adapter = new MenuAdapter(menu, inflater, mOverflowOnly);
// (3) This is the top level menu and icon spacing isn't forced. Do not add spacing.
if (!isShowing() && mForceShowIcon) {
// Case 1
adapter.setForceShowIcon(true);
} else if (isShowing()) {
// Case 2
adapter.setForceShowIcon(MenuPopup.shouldPreserveIconSpacing(menu));
}
// Case 3: Else, don't allow spacing for icons (default behavior; do nothing).
final int menuWidth = measureIndividualMenuWidth(adapter, null, mContext, mMenuMaxWidth);
final MenuPopupWindow popupWindow = createPopupWindow();
popupWindow.setAdapter(adapter);
popupWindow.setContentWidth(menuWidth);
popupWindow.setDropDownGravity(mDropDownGravity);
final CascadingMenuInfo parentInfo;
final View parentView;
if (mShowingMenus.size() > 0) {
parentInfo = mShowingMenus.get(mShowingMenus.size() - 1);
parentView = findParentViewForSubmenu(parentInfo, menu);
} else {
parentInfo = null;
parentView = null;
}
if (parentView != null) {
// This menu is a cascading submenu anchored to a parent view.
popupWindow.setTouchModal(false);
popupWindow.setEnterTransition(null);
@HorizPosition final int nextMenuPosition = getNextMenuPosition(menuWidth);
final boolean showOnRight = nextMenuPosition == HORIZ_POSITION_RIGHT;
mLastPosition = nextMenuPosition;
final int[] tempLocation = new int[2];
// This popup menu will be positioned relative to the top-left edge
// of the view representing its parent menu.
parentView.getLocationInWindow(tempLocation);
final int parentOffsetLeft = parentInfo.window.getHorizontalOffset() + tempLocation[0];
final int parentOffsetTop = parentInfo.window.getVerticalOffset() + tempLocation[1];
// By now, mDropDownGravity is the resolved absolute gravity, so
// this should work in both LTR and RTL.
final int x;
if ((mDropDownGravity & Gravity.RIGHT) == Gravity.RIGHT) {
if (showOnRight) {
x = parentOffsetLeft + menuWidth;
} else {
x = parentOffsetLeft - parentView.getWidth();
}
} else {
if (showOnRight) {
x = parentOffsetLeft + parentView.getWidth();
} else {
x = parentOffsetLeft - menuWidth;
}
}
popupWindow.setHorizontalOffset(x);
final int y = parentOffsetTop;
popupWindow.setVerticalOffset(y);
} else {
if (mHasXOffset) {
popupWindow.setHorizontalOffset(mXOffset);
}
if (mHasYOffset) {
popupWindow.setVerticalOffset(mYOffset);
}
final Rect epicenterBounds = getEpicenterBounds();
popupWindow.setEpicenterBounds(epicenterBounds);
}
final CascadingMenuInfo menuInfo = new CascadingMenuInfo(popupWindow, menu, mLastPosition);
mShowingMenus.add(menuInfo);
popupWindow.show();
// If this is the root menu, show the title if requested.
if (parentInfo == null && mShowTitle && menu.getHeaderTitle() != null) {
final ListView listView = popupWindow.getListView();
final FrameLayout titleItemView = (FrameLayout) inflater.inflate(R.layout.popup_menu_header_item_layout, listView, false);
final TextView titleView = (TextView) titleItemView.findViewById(R.id.title);
titleItemView.setEnabled(false);
titleView.setText(menu.getHeaderTitle());
listView.addHeaderView(titleItemView, null, false);
// Show again to update the title.
popupWindow.show();
}
}
use of android.widget.FrameLayout in project vlayout by alibaba.
the class TestActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_view);
StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
findViewById(R.id.jump).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText position = (EditText) findViewById(R.id.position);
if (!TextUtils.isEmpty(position.getText())) {
try {
int pos = Integer.parseInt(position.getText().toString());
recyclerView.scrollToPosition(pos);
} catch (Exception e) {
Log.e("VlayoutActivity", e.getMessage(), e);
}
}
}
});
recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
outRect.set(4, 4, 4, 4);
}
});
recyclerView.setAdapter(new RecyclerView.Adapter() {
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// TextView view = (TextView) LayoutInflater.from(TestActivity.this).inflate(R.layout.item, parent, false);
// FrameLayout frameLayout = new FrameLayout(TestActivity.this);
FrameLayout frameLayout = (FrameLayout) LayoutInflater.from(TestActivity.this).inflate(R.layout.item, parent, false);
;
// frameLayout.addView(view);
return new MainViewHolder(frameLayout);
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300);
layoutParams.height = (int) (200 + (position % 15) * 10);
holder.itemView.findViewById(R.id.title).setLayoutParams(layoutParams);
if (position == 30) {
StaggeredGridLayoutManager.LayoutParams lp = new StaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
lp.setFullSpan(true);
holder.itemView.setLayoutParams(lp);
} else {
ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();
if (lp instanceof StaggeredGridLayoutManager.LayoutParams) {
((StaggeredGridLayoutManager.LayoutParams) lp).setFullSpan(false);
}
}
((TextView) holder.itemView.findViewById(R.id.title)).setText(Integer.toString(position));
}
@Override
public int getItemCount() {
return 60;
}
});
}
use of android.widget.FrameLayout in project robolectric by robolectric.
the class ShadowActivityTest method shouldFindContentViewContainerWithChild.
@Test
public void shouldFindContentViewContainerWithChild() throws Exception {
Activity activity = buildActivity(Activity.class).create().get();
View contentView = new View(activity);
activity.setContentView(contentView);
FrameLayout contentViewContainer = (FrameLayout) activity.findViewById(android.R.id.content);
assertThat(contentViewContainer.getChildAt(0)).isSameAs(contentView);
}
Aggregations