use of android.widget.ListPopupWindow in project XobotOS by xamarin.
the class MenuPopupHelper method tryShow.
public boolean tryShow() {
mPopup = new ListPopupWindow(mContext, null, com.android.internal.R.attr.popupMenuStyle);
mPopup.setOnDismissListener(this);
mPopup.setOnItemClickListener(this);
mAdapter = new MenuAdapter(mMenu);
mPopup.setAdapter(mAdapter);
mPopup.setModal(true);
View anchor = mAnchorView;
if (anchor != null) {
final boolean addGlobalListener = mTreeObserver == null;
// Refresh to latest
mTreeObserver = anchor.getViewTreeObserver();
if (addGlobalListener)
mTreeObserver.addOnGlobalLayoutListener(this);
anchor.addOnAttachStateChangeListener(this);
mPopup.setAnchorView(anchor);
} else {
return false;
}
mPopup.setContentWidth(Math.min(measureContentWidth(mAdapter), mPopupMaxWidth));
mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
mPopup.show();
mPopup.getListView().setOnKeyListener(this);
return true;
}
use of android.widget.ListPopupWindow in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class DateTimeSettingsSetupWizard method showTimezonePicker.
private void showTimezonePicker(int anchorViewId) {
View anchorView = findViewById(anchorViewId);
if (anchorView == null) {
Log.e(TAG, "Unable to find zone picker anchor view " + anchorViewId);
return;
}
mTimeZonePopup = new ListPopupWindow(this, null);
mTimeZonePopup.setWidth(anchorView.getWidth());
mTimeZonePopup.setAnchorView(anchorView);
mTimeZonePopup.setAdapter(mTimeZoneAdapter);
mTimeZonePopup.setOnItemClickListener(this);
mTimeZonePopup.setModal(true);
mTimeZonePopup.show();
}
use of android.widget.ListPopupWindow in project android_packages_apps_Settings by DirtyUnicorns.
the class EditUserPhotoController method showUpdatePhotoPopup.
private void showUpdatePhotoPopup() {
final boolean canTakePhoto = canTakePhoto();
final boolean canChoosePhoto = canChoosePhoto();
if (!canTakePhoto && !canChoosePhoto) {
return;
}
final Context context = mImageView.getContext();
final List<EditUserPhotoController.RestrictedMenuItem> items = new ArrayList<>();
if (canTakePhoto) {
final String title = context.getString(R.string.user_image_take_photo);
final Runnable action = new Runnable() {
@Override
public void run() {
takePhoto();
}
};
items.add(new RestrictedMenuItem(context, title, UserManager.DISALLOW_SET_USER_ICON, action));
}
if (canChoosePhoto) {
final String title = context.getString(R.string.user_image_choose_photo);
final Runnable action = new Runnable() {
@Override
public void run() {
choosePhoto();
}
};
items.add(new RestrictedMenuItem(context, title, UserManager.DISALLOW_SET_USER_ICON, action));
}
final ListPopupWindow listPopupWindow = new ListPopupWindow(context);
listPopupWindow.setAnchorView(mImageView);
listPopupWindow.setModal(true);
listPopupWindow.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
listPopupWindow.setAdapter(new RestrictedPopupMenuAdapter(context, items));
final int width = Math.max(mImageView.getWidth(), context.getResources().getDimensionPixelSize(R.dimen.update_user_photo_popup_min_width));
listPopupWindow.setWidth(width);
listPopupWindow.setDropDownGravity(Gravity.START);
listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
listPopupWindow.dismiss();
final RestrictedMenuItem item = (RestrictedMenuItem) parent.getAdapter().getItem(position);
item.doAction();
}
});
listPopupWindow.show();
}
use of android.widget.ListPopupWindow in project LibreraReader by foobnix.
the class MyPopupMenu method show.
public void show(int pos) {
final ListPopupWindow p1 = new ListPopupWindow(c);
p1.setModal(true);
p1.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss() {
p1.dismiss();
if (isTabsActivity) {
if (AppState.get().isFullScreenMain) {
Keyboards.hideNavigation((Activity) c);
}
} else {
if (AppState.get().isFullScreen) {
Keyboards.hideNavigation((Activity) c);
}
}
}
});
BaseItemLayoutAdapter<Menu> a = new BaseItemLayoutAdapter<Menu>(c, R.layout.item_dict_line, list) {
@Override
public void populateView(View layout, int position, final Menu item) {
TextView textView = (TextView) layout.findViewById(R.id.text1);
textView.setText(item.stringRes);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
if (TxtUtils.isNotEmpty(item.fontPath)) {
textView.setTypeface(BookCSS.getTypeFaceForFont(item.fontPath));
}
ImageView imageView = (ImageView) layout.findViewById(R.id.image1);
if (item.iconRes != 0) {
imageView.setImageResource(item.iconRes);
if (item.iconRes == R.drawable.icon_pdf_pro) {
TintUtil.setNoTintImage(imageView);
} else {
if (isTabsActivity) {
if (AppState.get().isInkMode || AppState.get().isWhiteTheme) {
TintUtil.setTintImageWithAlpha(imageView, TintUtil.color);
} else {
TintUtil.setTintImageWithAlpha(imageView, Color.LTGRAY);
}
} else {
if (AppState.get().isDayNotInvert) {
TintUtil.setTintImageWithAlpha(imageView, TintUtil.color);
} else {
TintUtil.setTintImageWithAlpha(imageView, Color.LTGRAY);
}
}
}
} else {
imageView.setVisibility(View.GONE);
}
layout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
item.click.onMenuItemClick(null);
try {
p1.dismiss();
} catch (Exception e) {
LOG.e(e);
}
}
});
layout.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (item.onLongClick == null) {
return false;
}
item.onLongClick.onMenuItemClick(null);
try {
p1.dismiss();
} catch (Exception e) {
LOG.e(e);
}
return true;
}
});
}
};
p1.setAnchorView(anchor);
p1.setAdapter(a);
try {
p1.setWidth(measureContentWidth(a, c) + Dips.dpToPx(20));
} catch (Exception e) {
p1.setWidth(200);
}
p1.show();
if (pos != -1) {
p1.setSelection(pos - 2);
}
}
use of android.widget.ListPopupWindow in project xabber-android by redsolution.
the class CustomMessageMenu method showMenu.
public static void showMenu(Context context, View anchor, List<HashMap<String, String>> items, final AdapterView.OnItemClickListener itemClickListener, PopupWindow.OnDismissListener dismissListener) {
// build popup
final ListPopupWindow popup = new ListPopupWindow(context);
CustomMessageMenuAdapter adapter = new CustomMessageMenuAdapter(context, items);
popup.setAdapter(adapter);
popup.setAnchorView(anchor);
popup.setModal(true);
popup.setSoftInputMode(SOFT_INPUT_ADJUST_NOTHING);
popup.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
itemClickListener.onItemClick(parent, view, position, id);
popup.dismiss();
}
});
popup.setOnDismissListener(dismissListener);
// measure content dimens
ViewGroup mMeasureParent = null;
int height = 0;
int maxWidth = 0;
View itemView = null;
int itemType = 0;
final int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
final int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.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 (mMeasureParent == null) {
mMeasureParent = new FrameLayout(context);
}
itemView = adapter.getView(i, itemView, mMeasureParent);
itemView.measure(widthMeasureSpec, heightMeasureSpec);
final int itemHeight = itemView.getMeasuredHeight();
final int itemWidth = itemView.getMeasuredWidth();
if (itemWidth > maxWidth) {
maxWidth = itemWidth;
}
height += itemHeight;
}
// set dimens and show
popup.setWidth(maxWidth);
popup.setHeight(height);
popup.show();
}
Aggregations