use of androidx.appcompat.widget.ListPopupWindow in project Osmand by osmandapp.
the class DirectionIndicationDialogFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final OsmandSettings settings = getSettings();
boolean nightMode = isNightMode(usedOnMap);
helpImgHeight = getResources().getDimensionPixelSize(R.dimen.action_bar_image_height);
mainView = UiUtilities.getInflater(getContext(), !settings.isLightContent()).inflate(R.layout.fragment_direction_indication_dialog, container);
Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.toolbar);
int navigationIconResId = AndroidUtils.getNavigationIconResId(getContext());
toolbar.setNavigationIcon(getIconsCache().getIcon(navigationIconResId));
toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
}
});
TextView appModeTv = (TextView) mainView.findViewById(R.id.app_mode_text_view);
ApplicationMode appMode = settings.APPLICATION_MODE.get();
appModeTv.setText(appMode.toHumanString());
appModeTv.setCompoundDrawablesWithIntrinsicBounds(null, null, getIconsCache().getIcon(appMode.getIconRes()), null);
if (AndroidUiHelper.isOrientationPortrait(getActivity())) {
((ObservableScrollView) mainView.findViewById(R.id.scroll_view)).setScrollViewCallbacks(new ObservableScrollViewCallbacks() {
@Override
public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
if (scrollY >= helpImgHeight) {
if (!shadowVisible) {
mainView.findViewById(R.id.app_bar_shadow).setVisibility(View.VISIBLE);
shadowVisible = true;
}
} else if (shadowVisible) {
mainView.findViewById(R.id.app_bar_shadow).setVisibility(View.GONE);
shadowVisible = false;
}
}
@Override
public void onDownMotionEvent() {
}
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
}
});
}
updateHelpImage();
final TextView menuTv = (TextView) mainView.findViewById(R.id.active_markers_text_view);
menuTv.setText(settings.DISPLAYED_MARKERS_WIDGETS_COUNT.get() == 1 ? R.string.shared_string_one : R.string.shared_string_two);
menuTv.setCompoundDrawablesWithIntrinsicBounds(null, null, getContentIcon(R.drawable.ic_action_arrow_drop_down), null);
menuTv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Context themedContext = UiUtilities.getThemedContext(getActivity(), !settings.isLightContent());
CharSequence[] titles = getMenuTitles();
Paint paint = new Paint();
paint.setTextSize(getResources().getDimensionPixelSize(R.dimen.default_list_text_size));
float titleTextWidth = Math.max(paint.measureText(titles[0].toString()), paint.measureText(titles[1].toString()));
float itemWidth = titleTextWidth + AndroidUtils.dpToPx(themedContext, 32);
float minWidth = AndroidUtils.dpToPx(themedContext, 100);
final ListPopupWindow listPopupWindow = new ListPopupWindow(themedContext);
listPopupWindow.setAnchorView(menuTv);
listPopupWindow.setContentWidth((int) (Math.max(itemWidth, minWidth)));
listPopupWindow.setDropDownGravity(Gravity.END | Gravity.TOP);
listPopupWindow.setHorizontalOffset(AndroidUtils.dpToPx(themedContext, 8));
listPopupWindow.setVerticalOffset(-menuTv.getHeight());
listPopupWindow.setModal(true);
listPopupWindow.setAdapter(new ArrayAdapter<>(themedContext, R.layout.popup_list_text_item, titles));
listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
updateDisplayedMarkersCount(position == 0 ? 1 : 2);
listPopupWindow.dismiss();
}
});
listPopupWindow.show();
}
});
final CompoundButton distanceIndicationToggle = (CompoundButton) mainView.findViewById(R.id.distance_indication_switch);
distanceIndicationToggle.setChecked(settings.MARKERS_DISTANCE_INDICATION_ENABLED.get());
mainView.findViewById(R.id.distance_indication_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
updateChecked(settings.MARKERS_DISTANCE_INDICATION_ENABLED, distanceIndicationToggle);
updateSelection(true);
}
});
UiUtilities.setupCompoundButton(distanceIndicationToggle, nightMode, PROFILE_DEPENDENT);
mainView.findViewById(R.id.top_bar_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
settings.MAP_MARKERS_MODE.set(MapMarkersMode.TOOLBAR);
updateSelection(true);
}
});
mainView.findViewById(R.id.widget_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
settings.MAP_MARKERS_MODE.set(MapMarkersMode.WIDGETS);
updateSelection(true);
}
});
updateSelection(false);
final CompoundButton showArrowsToggle = (CompoundButton) mainView.findViewById(R.id.show_arrows_switch);
showArrowsToggle.setChecked(settings.SHOW_ARROWS_TO_FIRST_MARKERS.get());
mainView.findViewById(R.id.show_arrows_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
updateChecked(settings.SHOW_ARROWS_TO_FIRST_MARKERS, showArrowsToggle);
}
});
UiUtilities.setupCompoundButton(showArrowsToggle, nightMode, PROFILE_DEPENDENT);
final CompoundButton showLinesToggle = (CompoundButton) mainView.findViewById(R.id.show_guide_line_switch);
showLinesToggle.setChecked(settings.SHOW_LINES_TO_FIRST_MARKERS.get());
mainView.findViewById(R.id.show_guide_line_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
updateChecked(settings.SHOW_LINES_TO_FIRST_MARKERS, showLinesToggle);
}
});
UiUtilities.setupCompoundButton(showLinesToggle, nightMode, PROFILE_DEPENDENT);
final CompoundButton oneTapActiveToggle = (CompoundButton) mainView.findViewById(R.id.one_tap_active_switch);
oneTapActiveToggle.setChecked(settings.SELECT_MARKER_ON_SINGLE_TAP.get());
mainView.findViewById(R.id.one_tap_active_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
updateChecked(settings.SELECT_MARKER_ON_SINGLE_TAP, oneTapActiveToggle);
}
});
UiUtilities.setupCompoundButton(oneTapActiveToggle, nightMode, PROFILE_DEPENDENT);
final CompoundButton keepPassedToggle = (CompoundButton) mainView.findViewById(R.id.keep_passed_switch);
keepPassedToggle.setChecked(settings.KEEP_PASSED_MARKERS_ON_MAP.get());
mainView.findViewById(R.id.keep_passed_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateChecked(settings.KEEP_PASSED_MARKERS_ON_MAP, keepPassedToggle);
}
});
UiUtilities.setupCompoundButton(keepPassedToggle, nightMode, PROFILE_DEPENDENT);
return mainView;
}
use of androidx.appcompat.widget.ListPopupWindow in project Osmand by osmandapp.
the class PopUpMenuHelper method show.
private void show() {
ListPopupWindow listPopupWindow = createPopUpWindow();
listPopupWindow.show();
}
use of androidx.appcompat.widget.ListPopupWindow in project Osmand by osmandapp.
the class PopUpMenuHelper method createPopUpWindow.
private ListPopupWindow createPopUpWindow() {
Context ctx = UiUtilities.getThemedContext(anchorView.getContext(), nightMode);
int contentPadding = getDimensionPixelSize(ctx, R.dimen.content_padding);
int contentPaddingHalf = getDimensionPixelSize(ctx, R.dimen.content_padding_half);
int defaultListTextSize = getDimensionPixelSize(ctx, R.dimen.default_list_text_size);
int standardIconSize = getDimensionPixelSize(ctx, R.dimen.standard_icon_size);
boolean hasIcon = false;
List<String> titles = new ArrayList<>();
for (PopUpMenuItem item : items) {
titles.add(String.valueOf(item.getTitle()));
hasIcon = hasIcon || item.getIcon() != null;
}
float itemWidth = AndroidUtils.getTextMaxWidth(defaultListTextSize, titles) + contentPadding * 2;
float iconPartWidth = hasIcon ? standardIconSize + contentPaddingHalf : 0;
float compoundBtnWidth = contentPadding * 3;
int minWidth = widthType == PopUpMenuWidthType.AS_ANCHOR_VIEW ? anchorView.getWidth() : 0;
float additional;
if (widthType == PopUpMenuWidthType.STANDARD) {
additional = iconPartWidth + compoundBtnWidth;
} else {
additional = iconPartWidth;
}
int totalWidth = (int) (Math.max(itemWidth, minWidth) + additional);
PopUpMenuArrayAdapter adapter = new PopUpMenuArrayAdapter(ctx, R.layout.popup_menu_item, items, nightMode);
final ListPopupWindow listPopupWindow = new ListPopupWindow(ctx);
listPopupWindow.setAnchorView(anchorView);
listPopupWindow.setContentWidth((int) (totalWidth));
listPopupWindow.setDropDownGravity(Gravity.START | Gravity.TOP);
listPopupWindow.setVerticalOffset(-anchorView.getHeight() + contentPaddingHalf);
listPopupWindow.setModal(true);
listPopupWindow.setAdapter(adapter);
if (backgroundColor != 0) {
listPopupWindow.setBackgroundDrawable(new ColorDrawable(backgroundColor));
}
listPopupWindow.setOnItemClickListener((parent, view, position, id) -> {
if (listener != null) {
listener.onItemClick(parent, view, position, id);
}
listPopupWindow.dismiss();
});
return listPopupWindow;
}
Aggregations