Search in sources :

Example 1 with ScrollState

use of com.github.ksoichiro.android.observablescrollview.ScrollState in project Osmand by osmandapp.

the class MapMultiSelectionMenuFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    menu = ((MapActivity) getActivity()).getContextMenu().getMultiSelectionMenu();
    view = inflater.inflate(R.layout.menu_obj_selection_fragment, container, false);
    if (menu.isLandscapeLayout()) {
        AndroidUtils.setBackground(view.getContext(), view, !menu.isLight(), R.drawable.multi_selection_menu_bg_light_land, R.drawable.multi_selection_menu_bg_dark_land);
    } else {
        AndroidUtils.setBackground(view.getContext(), view.findViewById(R.id.cancel_row), !menu.isLight(), R.color.ctx_menu_bg_light, R.color.ctx_menu_bg_dark);
    }
    final ListView listView = (ListView) view.findViewById(R.id.list);
    if (menu.isLandscapeLayout() && Build.VERSION.SDK_INT >= 21) {
        AndroidUtils.addStatusBarPadding21v(getActivity(), listView);
    }
    listAdapter = createAdapter();
    listAdapter.setListener(this);
    if (!menu.isLandscapeLayout()) {
        final Context context = getContext();
        FrameLayout paddingView = new FrameLayout(context);
        paddingView.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, getPaddingViewHeight()));
        paddingView.setClickable(true);
        paddingView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                dismissMenu();
            }
        });
        FrameLayout shadowContainer = new FrameLayout(context);
        shadowContainer.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT, Gravity.BOTTOM));
        ImageView shadow = new ImageView(context);
        shadow.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.bg_shadow_onmap));
        shadow.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM));
        shadow.setScaleType(ImageView.ScaleType.FIT_XY);
        shadowContainer.addView(shadow);
        paddingView.addView(shadowContainer);
        listView.addHeaderView(paddingView);
        view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {
                float titleHeight = getResources().getDimension(R.dimen.multi_selection_header_height);
                int maxHeight = (int) (titleHeight);
                for (int i = 0; i < 3 && i < listAdapter.getCount(); i++) {
                    View childView = listAdapter.getView(0, null, (ListView) view.findViewById(R.id.list));
                    childView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
                    maxHeight += childView.getMeasuredHeight();
                }
                listView.setSelectionFromTop(0, -maxHeight);
                ViewTreeObserver obs = view.getViewTreeObserver();
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    obs.removeOnGlobalLayoutListener(this);
                } else {
                    obs.removeGlobalOnLayoutListener(this);
                }
            }
        });
        ((ObservableListView) listView).setScrollViewCallbacks(new ObservableScrollViewCallbacks() {

            boolean initialScroll = true;

            int minHeight = getResources().getDimensionPixelSize(R.dimen.multi_selection_header_height) + getResources().getDimensionPixelSize(R.dimen.list_item_height);

            @Override
            public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
                if (scrollY <= minHeight && !initialScroll) {
                    dismissMenu();
                }
            }

            @Override
            public void onDownMotionEvent() {
                initialScroll = false;
            }

            @Override
            public void onUpOrCancelMotionEvent(ScrollState scrollState) {
            }
        });
    }
    listView.setAdapter(listAdapter);
    View headerView = inflater.inflate(R.layout.menu_obj_selection_header, listView, false);
    if (!menu.isLandscapeLayout()) {
        AndroidUtils.setBackground(getContext(), headerView, !menu.isLight(), R.color.ctx_menu_bg_light, R.color.ctx_menu_bg_dark);
    }
    headerView.setOnClickListener(null);
    listView.addHeaderView(headerView);
    view.findViewById(R.id.divider).setBackgroundColor(ContextCompat.getColor(getContext(), menu.isLight() ? R.color.multi_selection_menu_divider_light : R.color.multi_selection_menu_divider_dark));
    ((TextView) view.findViewById(R.id.cancel_row_text)).setTextColor(ContextCompat.getColor(getContext(), menu.isLight() ? R.color.multi_selection_menu_close_btn_light : R.color.multi_selection_menu_close_btn_dark));
    view.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            dismissMenu();
        }
    });
    return view;
}
Also used : Context(android.content.Context) AbsListView(android.widget.AbsListView) ObservableScrollViewCallbacks(com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks) ImageView(android.widget.ImageView) View(android.view.View) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) ListView(android.widget.ListView) ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView) ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView) AbsListView(android.widget.AbsListView) ListView(android.widget.ListView) ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView) FrameLayout(android.widget.FrameLayout) ScrollState(com.github.ksoichiro.android.observablescrollview.ScrollState) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ViewTreeObserver(android.view.ViewTreeObserver) MapActivity(net.osmand.plus.activities.MapActivity) Nullable(android.support.annotation.Nullable)

Example 2 with ScrollState

use of com.github.ksoichiro.android.observablescrollview.ScrollState 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();
    helpImgHeight = getResources().getDimensionPixelSize(R.dimen.action_bar_image_height);
    mainView = inflater.inflate(R.layout.fragment_direction_indication_dialog, container);
    Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.toolbar);
    toolbar.setNavigationIcon(getIconsCache().getIcon(R.drawable.ic_arrow_back));
    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.getStringResource());
    appModeTv.setCompoundDrawablesWithIntrinsicBounds(null, null, getIconsCache().getIcon(appMode.getSmallIconDark()), 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) {
            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(getActivity(), 32);
            float minWidth = AndroidUtils.dpToPx(getActivity(), 100);
            final ListPopupWindow listPopupWindow = new ListPopupWindow(getActivity());
            listPopupWindow.setAnchorView(menuTv);
            listPopupWindow.setContentWidth((int) (Math.max(itemWidth, minWidth)));
            listPopupWindow.setDropDownGravity(Gravity.END | Gravity.TOP);
            listPopupWindow.setHorizontalOffset(AndroidUtils.dpToPx(getActivity(), 8));
            listPopupWindow.setVerticalOffset(-menuTv.getHeight());
            listPopupWindow.setModal(true);
            listPopupWindow.setAdapter(new ArrayAdapter<>(getActivity(), 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);
        }
    });
    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);
        }
    });
    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);
        }
    });
    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);
        }
    });
    return mainView;
}
Also used : ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView) ObservableScrollViewCallbacks(com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks) ApplicationMode(net.osmand.plus.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.OsmandSettings) Paint(android.graphics.Paint) ListPopupWindow(android.support.v7.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(android.support.v7.widget.Toolbar) Nullable(android.support.annotation.Nullable)

Aggregations

Nullable (android.support.annotation.Nullable)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 ObservableScrollViewCallbacks (com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks)2 ScrollState (com.github.ksoichiro.android.observablescrollview.ScrollState)2 Context (android.content.Context)1 Paint (android.graphics.Paint)1 ListPopupWindow (android.support.v7.widget.ListPopupWindow)1 Toolbar (android.support.v7.widget.Toolbar)1 ViewTreeObserver (android.view.ViewTreeObserver)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 ArrayAdapter (android.widget.ArrayAdapter)1 CompoundButton (android.widget.CompoundButton)1 FrameLayout (android.widget.FrameLayout)1 ListView (android.widget.ListView)1 ObservableListView (com.github.ksoichiro.android.observablescrollview.ObservableListView)1 ObservableScrollView (com.github.ksoichiro.android.observablescrollview.ObservableScrollView)1 ApplicationMode (net.osmand.plus.ApplicationMode)1