Search in sources :

Example 6 with ListPopupWindow

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;
}
Also used : Context(android.content.Context) ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView) ObservableScrollViewCallbacks(com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) Paint(android.graphics.Paint) ImageView(android.widget.ImageView) ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) Paint(android.graphics.Paint) ListPopupWindow(androidx.appcompat.widget.ListPopupWindow) ScrollState(com.github.ksoichiro.android.observablescrollview.ScrollState) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter) CompoundButton(android.widget.CompoundButton) Toolbar(androidx.appcompat.widget.Toolbar) Nullable(androidx.annotation.Nullable)

Example 7 with ListPopupWindow

use of androidx.appcompat.widget.ListPopupWindow in project Osmand by osmandapp.

the class PopUpMenuHelper method show.

private void show() {
    ListPopupWindow listPopupWindow = createPopUpWindow();
    listPopupWindow.show();
}
Also used : ListPopupWindow(androidx.appcompat.widget.ListPopupWindow)

Example 8 with ListPopupWindow

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;
}
Also used : Context(android.content.Context) ListPopupWindow(androidx.appcompat.widget.ListPopupWindow) ColorDrawable(android.graphics.drawable.ColorDrawable) ArrayList(java.util.ArrayList)

Aggregations

ListPopupWindow (androidx.appcompat.widget.ListPopupWindow)8 View (android.view.View)6 AdapterView (android.widget.AdapterView)6 ImageView (android.widget.ImageView)5 TextView (android.widget.TextView)4 Context (android.content.Context)3 ArrayAdapter (android.widget.ArrayAdapter)3 ArrayList (java.util.ArrayList)3 DialogInterface (android.content.DialogInterface)2 Bundle (android.os.Bundle)2 ContextThemeWrapper (android.view.ContextThemeWrapper)2 CompoundButton (android.widget.CompoundButton)2 AlertDialog (androidx.appcompat.app.AlertDialog)2 OsmandApplication (net.osmand.plus.OsmandApplication)2 MapActivity (net.osmand.plus.activities.MapActivity)2 SelectedGpxFile (net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 OnClickListener (android.content.DialogInterface.OnClickListener)1