Search in sources :

Example 1 with TitleProgressController

use of net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController in project Osmand by osmandapp.

the class MapContextMenuFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    processScreenHeight(container);
    menu = getMapActivity().getContextMenu();
    markerPaddingPx = dpToPx(MARKER_PADDING_DP);
    markerPaddingXPx = dpToPx(MARKER_PADDING_X_DP);
    shadowHeight = dpToPx(SHADOW_HEIGHT_TOP_DP);
    topScreenPosY = addStatusBarHeightIfNeeded(-shadowHeight);
    bottomToolbarPosY = addStatusBarHeightIfNeeded(getResources().getDimensionPixelSize(R.dimen.dashboard_map_toolbar));
    minHalfY = viewHeight - (int) (viewHeight * menu.getHalfScreenMaxHeightKoef());
    zoomPaddingTop = dpToPx(ZOOM_PADDING_TOP_DP);
    view = inflater.inflate(R.layout.map_context_menu_fragment, container, false);
    if (!menu.isActive()) {
        return view;
    }
    AndroidUtils.addStatusBarPadding21v(getMapActivity(), view);
    nightMode = menu.isNightMode();
    mainView = view.findViewById(R.id.context_menu_main);
    toolbarContainer = view.findViewById(R.id.context_menu_toolbar_container);
    toolbarView = view.findViewById(R.id.context_menu_toolbar);
    toolbarBackButton = view.findViewById(R.id.context_menu_toolbar_back);
    toolbarTextView = (TextView) view.findViewById(R.id.context_menu_toolbar_text);
    updateVisibility(toolbarContainer, 0);
    toolbarBackButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            openMenuHeaderOnly();
        }
    });
    topButtonContainer = view.findViewById(R.id.context_menu_top_button_container);
    view.findViewById(R.id.context_menu_top_back).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            openMenuHeaderOnly();
        }
    });
    updateVisibility(topButtonContainer, 0);
    map = getMapActivity().getMapView();
    RotatedTileBox box = map.getCurrentRotatedTileBox().copy();
    customMapCenter = menu.getMapCenter() != null;
    if (!customMapCenter) {
        mapCenter = box.getCenterLatLon();
        menu.setMapCenter(mapCenter);
        double markerLat = menu.getLatLon().getLatitude();
        double markerLon = menu.getLatLon().getLongitude();
        origMarkerX = (int) box.getPixXFromLatLon(markerLat, markerLon);
        origMarkerY = (int) box.getPixYFromLatLon(markerLat, markerLon);
    } else {
        mapCenter = menu.getMapCenter();
        origMarkerX = box.getCenterPixelX();
        origMarkerY = box.getCenterPixelY();
    }
    mapZoom = menu.getMapZoom();
    if (mapZoom == 0) {
        mapZoom = map.getZoom();
    }
    // Left title button
    final View leftTitleButtonView = view.findViewById(R.id.title_button_view);
    leftTitleButtonView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            TitleButtonController leftTitleButtonController = menu.getLeftTitleButtonController();
            if (leftTitleButtonController != null) {
                leftTitleButtonController.buttonPressed();
            }
        }
    });
    // Right title button
    final View rightTitleButtonView = view.findViewById(R.id.title_button_right_view);
    rightTitleButtonView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            TitleButtonController rightTitleButtonController = menu.getRightTitleButtonController();
            if (rightTitleButtonController != null) {
                rightTitleButtonController.buttonPressed();
            }
        }
    });
    // Left download button
    final View leftDownloadButtonView = view.findViewById(R.id.download_button_left_view);
    leftDownloadButtonView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            TitleButtonController leftDownloadButtonController = menu.getLeftDownloadButtonController();
            if (leftDownloadButtonController != null) {
                leftDownloadButtonController.buttonPressed();
            }
        }
    });
    // Right download button
    final View rightDownloadButtonView = (View) view.findViewById(R.id.download_button_right_view);
    rightDownloadButtonView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            TitleButtonController rightDownloadButtonController = menu.getRightDownloadButtonController();
            if (rightDownloadButtonController != null) {
                rightDownloadButtonController.buttonPressed();
            }
        }
    });
    // Bottom title button
    final View bottomTitleButtonView = view.findViewById(R.id.title_button_bottom_view);
    bottomTitleButtonView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            TitleButtonController bottomTitleButtonController = menu.getBottomTitleButtonController();
            if (bottomTitleButtonController != null) {
                bottomTitleButtonController.buttonPressed();
            }
        }
    });
    // Progress bar
    final ImageView progressButton = (ImageView) view.findViewById(R.id.progressButton);
    progressButton.setImageDrawable(getIcon(R.drawable.ic_action_remove_dark, R.color.ctx_menu_buttons_icon_color));
    progressButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            TitleProgressController titleProgressController = menu.getTitleProgressController();
            if (titleProgressController != null) {
                titleProgressController.buttonPressed();
            }
        }
    });
    menu.updateData();
    updateButtonsAndProgress();
    if (menu.isLandscapeLayout()) {
        final TypedValue typedValueAttr = new TypedValue();
        getMapActivity().getTheme().resolveAttribute(R.attr.left_menu_view_bg, typedValueAttr, true);
        mainView.setBackgroundResource(typedValueAttr.resourceId);
        mainView.setLayoutParams(new FrameLayout.LayoutParams(menu.getLandscapeWidthPx(), ViewGroup.LayoutParams.MATCH_PARENT));
        View fabContainer = view.findViewById(R.id.context_menu_fab_container);
        fabContainer.setLayoutParams(new FrameLayout.LayoutParams(menu.getLandscapeWidthPx(), ViewGroup.LayoutParams.MATCH_PARENT));
    }
    runLayoutListener();
    final GestureDetector singleTapDetector = new GestureDetector(view.getContext(), new SingleTapConfirm());
    final GestureDetector swipeDetector = new GestureDetector(view.getContext(), new HorizontalSwipeConfirm(true));
    final View.OnTouchListener slideTouchListener = new View.OnTouchListener() {

        private float dy;

        private float dyMain;

        private float mDownY;

        private int minimumVelocity;

        private int maximumVelocity;

        private VelocityTracker velocityTracker;

        private OverScroller scroller;

        private boolean slidingUp;

        private boolean slidingDown;

        private boolean hasMoved;

        {
            scroller = new OverScroller(getContext());
            final ViewConfiguration configuration = ViewConfiguration.get(getContext());
            minimumVelocity = configuration.getScaledMinimumFlingVelocity();
            maximumVelocity = configuration.getScaledMaximumFlingVelocity();
        }

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (!hasMoved && event.getY() <= menuTopViewHeight) {
                if (singleTapDetector.onTouchEvent(event)) {
                    moving = false;
                    openMenuHalfScreen();
                    recycleVelocityTracker();
                    return true;
                }
            }
            if (menu.isLandscapeLayout()) {
                if (swipeDetector.onTouchEvent(event)) {
                    menu.close();
                    recycleVelocityTracker();
                    return true;
                }
            }
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    hasMoved = false;
                    mDownY = event.getRawY();
                    dy = event.getY();
                    dyMain = getViewY();
                    initOrResetVelocityTracker();
                    velocityTracker.addMovement(event);
                    break;
                case MotionEvent.ACTION_MOVE:
                    if (Math.abs(event.getRawY() - mDownY) > mainView.getTouchSlop()) {
                        moving = true;
                    }
                    if (moving) {
                        hasMoved = true;
                        float y = event.getY();
                        float newY = getViewY() + (y - dy);
                        if (menu.isLandscapeLayout() && newY > topScreenPosY) {
                            newY = topScreenPosY;
                        }
                        setViewY((int) newY, false, false);
                        menuFullHeight = view.getHeight() - (int) newY + 10;
                        ViewGroup.LayoutParams lp = mainView.getLayoutParams();
                        lp.height = Math.max(menuFullHeight, menuTitleHeight);
                        mainView.setLayoutParams(lp);
                        mainView.requestLayout();
                        float newEventY = newY - (dyMain - dy);
                        MotionEvent ev = MotionEvent.obtain(event.getDownTime(), event.getEventTime(), event.getAction(), event.getX(), newEventY, event.getMetaState());
                        initVelocityTrackerIfNotExists();
                        velocityTracker.addMovement(ev);
                        updateToolbar();
                        updateTopButton();
                    }
                    break;
                case MotionEvent.ACTION_UP:
                    if (moving) {
                        moving = false;
                        hasMoved = false;
                        int currentY = getViewY();
                        final VelocityTracker velocityTracker = this.velocityTracker;
                        velocityTracker.computeCurrentVelocity(1000, maximumVelocity);
                        int initialVelocity = (int) velocityTracker.getYVelocity();
                        if ((Math.abs(initialVelocity) > minimumVelocity)) {
                            scroller.abortAnimation();
                            scroller.fling(0, currentY, 0, initialVelocity, 0, 0, Math.min(viewHeight - menuFullHeightMax, getFullScreenTopPosY()), screenHeight, 0, 0);
                            currentY = scroller.getFinalY();
                            scroller.abortAnimation();
                            slidingUp = initialVelocity < -2000;
                            slidingDown = initialVelocity > 2000;
                        } else {
                            slidingUp = false;
                            slidingDown = false;
                        }
                        changeMenuState(currentY, slidingUp, slidingDown);
                    }
                    recycleVelocityTracker();
                    break;
                case MotionEvent.ACTION_CANCEL:
                    moving = false;
                    hasMoved = false;
                    recycleVelocityTracker();
                    break;
            }
            return true;
        }

        private void initOrResetVelocityTracker() {
            if (velocityTracker == null) {
                velocityTracker = VelocityTracker.obtain();
            } else {
                velocityTracker.clear();
            }
        }

        private void initVelocityTrackerIfNotExists() {
            if (velocityTracker == null) {
                velocityTracker = VelocityTracker.obtain();
                velocityTracker.clear();
            }
        }

        private void recycleVelocityTracker() {
            if (velocityTracker != null) {
                velocityTracker.recycle();
                velocityTracker = null;
            }
        }
    };
    View topShadowAllView = view.findViewById(R.id.context_menu_top_shadow_all);
    AndroidUtils.setBackground(getMapActivity(), topShadowAllView, nightMode, R.drawable.bg_map_context_menu_light, R.drawable.bg_map_context_menu_dark);
    ((InterceptorLinearLayout) mainView).setListener(slideTouchListener);
    mainView.setOnTouchListener(slideTouchListener);
    buildHeader();
    ((TextView) view.findViewById(R.id.context_menu_line1)).setTextColor(ContextCompat.getColor(getContext(), nightMode ? R.color.ctx_menu_title_color_dark : R.color.ctx_menu_title_color_light));
    View menuLine2 = view.findViewById(R.id.context_menu_line2);
    if (menuLine2 != null) {
        ((TextView) menuLine2).setTextColor(ContextCompat.getColor(getContext(), R.color.ctx_menu_subtitle_color));
    }
    ((TextView) view.findViewById(R.id.distance)).setTextColor(ContextCompat.getColor(getContext(), nightMode ? R.color.ctx_menu_direction_color_dark : R.color.ctx_menu_direction_color_light));
    AndroidUtils.setTextSecondaryColor(getMapActivity(), (TextView) view.findViewById(R.id.title_button_right_text), nightMode);
    AndroidUtils.setTextSecondaryColor(getMapActivity(), (TextView) view.findViewById(R.id.progressTitle), nightMode);
    // Zoom buttons
    zoomButtonsView = view.findViewById(R.id.context_menu_zoom_buttons);
    zoomInButtonView = (ImageButton) view.findViewById(R.id.context_menu_zoom_in_button);
    zoomOutButtonView = (ImageButton) view.findViewById(R.id.context_menu_zoom_out_button);
    if (menu.zoomButtonsVisible()) {
        updateImageButton(zoomInButtonView, R.drawable.map_zoom_in, R.drawable.map_zoom_in_night, R.drawable.btn_circle_trans, R.drawable.btn_circle_night, nightMode);
        updateImageButton(zoomOutButtonView, R.drawable.map_zoom_out, R.drawable.map_zoom_out_night, R.drawable.btn_circle_trans, R.drawable.btn_circle_night, nightMode);
        zoomInButtonView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                menu.zoomInPressed();
            }
        });
        zoomOutButtonView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                menu.zoomOutPressed();
            }
        });
        zoomButtonsView.setVisibility(View.VISIBLE);
    } else {
        zoomButtonsView.setVisibility(View.GONE);
    }
    GridView localTransportStopRoutesGrid = (GridView) view.findViewById(R.id.transport_stop_routes_grid);
    GridView nearbyTransportStopRoutesGrid = (GridView) view.findViewById(R.id.transport_stop_nearby_routes_grid);
    TextView nearbRoutesWithinTv = (TextView) view.findViewById(R.id.nearby_routes_within_text_view);
    LinearLayout nearbyRoutesLayout = (LinearLayout) view.findViewById(R.id.nearby_routes);
    List<TransportStopRoute> localTransportStopRoutes = menu.getLocalTransportStopRoutes();
    List<TransportStopRoute> nearbyTransportStopRoutes = menu.getNearbyTransportStopRoutes();
    if (nightMode) {
        nearbRoutesWithinTv.setTextColor(ContextCompat.getColor(getContext(), R.color.ctx_menu_bottom_view_secondary_text_color_dark));
    } else {
        nearbRoutesWithinTv.setTextColor(ContextCompat.getColor(getContext(), R.color.ctx_menu_nearby_routes_text_color_dark));
    }
    if (localTransportStopRoutes != null && localTransportStopRoutes.size() > 0) {
        localTransportStopRoutesGrid.setAdapter(createTransportStopRouteAdapter(localTransportStopRoutes));
        localTransportStopRoutesGrid.setVisibility(View.VISIBLE);
    } else {
        localTransportStopRoutesGrid.setVisibility(View.GONE);
    }
    if (nearbyTransportStopRoutes != null && nearbyTransportStopRoutes.size() > 0) {
        String nearInDistance = getMyApplication().getString(R.string.transport_nearby_routes) + " " + OsmAndFormatter.getFormattedDistance(TransportStopController.SHOW_STOPS_RADIUS_METERS, getMyApplication()).toUpperCase() + ":";
        nearbRoutesWithinTv.setText(nearInDistance);
        nearbyTransportStopRoutesGrid.setAdapter(createTransportStopRouteAdapter(nearbyTransportStopRoutes));
        nearbyTransportStopRoutesGrid.setVisibility(View.VISIBLE);
    } else {
        nearbyRoutesLayout.setVisibility(View.GONE);
    }
    View buttonsBottomBorder = view.findViewById(R.id.buttons_bottom_border);
    View buttonsTopBorder = view.findViewById(R.id.buttons_top_border);
    buttonsBottomBorder.setBackgroundColor(ContextCompat.getColor(getContext(), nightMode ? R.color.ctx_menu_buttons_divider_dark : R.color.ctx_menu_buttons_divider_light));
    buttonsTopBorder.setBackgroundColor(ContextCompat.getColor(getContext(), nightMode ? R.color.ctx_menu_buttons_divider_dark : R.color.ctx_menu_buttons_divider_light));
    View buttons = view.findViewById(R.id.context_menu_buttons);
    buttons.setBackgroundColor(ContextCompat.getColor(getContext(), nightMode ? R.color.ctx_menu_buttons_bg_dark : R.color.ctx_menu_buttons_bg_light));
    if (!menu.buttonsVisible()) {
        buttonsTopBorder.setVisibility(View.GONE);
        buttons.setVisibility(View.GONE);
    }
    View bottomButtons = view.findViewById(R.id.context_menu_bottom_buttons);
    bottomButtons.setBackgroundColor(ContextCompat.getColor(getContext(), nightMode ? R.color.ctx_menu_buttons_bg_dark : R.color.ctx_menu_buttons_bg_light));
    if (!menu.navigateButtonVisible()) {
        bottomButtons.findViewById(R.id.context_menu_directions_button).setVisibility(View.GONE);
    }
    // Action buttons
    final ImageView imageFavorite = (ImageView) view.findViewById(R.id.context_menu_fav_image_view);
    imageFavorite.setImageDrawable(getIcon(menu.getFavActionIconId(), R.color.ctx_menu_buttons_icon_color));
    imageFavorite.setContentDescription(getString(menu.getFavActionStringId()));
    ((TextView) view.findViewById(R.id.context_menu_fav_text_view)).setText(menu.getFavActionStringId());
    View favView = view.findViewById(R.id.context_menu_fav_view);
    favView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            menu.buttonFavoritePressed();
        }
    });
    final ImageView imageWaypoint = (ImageView) view.findViewById(R.id.context_menu_route_image_view);
    imageWaypoint.setImageDrawable(getIcon(menu.getWaypointActionIconId(), R.color.ctx_menu_buttons_icon_color));
    imageWaypoint.setContentDescription(getString(menu.getWaypointActionStringId()));
    View waypointView = view.findViewById(R.id.context_menu_route_view);
    if (menu.isButtonWaypointEnabled()) {
        waypointView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                menu.buttonWaypointPressed();
            }
        });
    } else {
        deactivate(waypointView);
    }
    final ImageView imageShare = (ImageView) view.findViewById(R.id.context_menu_share_image_view);
    imageShare.setImageDrawable(getIcon(R.drawable.map_action_gshare_dark, R.color.ctx_menu_buttons_icon_color));
    View shareView = view.findViewById(R.id.context_menu_share_view);
    shareView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            menu.buttonSharePressed();
        }
    });
    final ImageView imageMore = (ImageView) view.findViewById(R.id.context_menu_more_image_view);
    imageMore.setImageDrawable(getIcon(R.drawable.map_overflow_menu_white, R.color.ctx_menu_buttons_icon_color));
    View moreView = view.findViewById(R.id.context_menu_more_view);
    moreView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            menu.buttonMorePressed();
        }
    });
    // Bottom buttons
    int bottomButtonsColor = nightMode ? R.color.ctx_menu_controller_button_text_color_dark_n : R.color.ctx_menu_controller_button_text_color_light_n;
    TextView detailsButton = (TextView) view.findViewById(R.id.context_menu_details_button);
    detailsButton.setTextColor(ContextCompat.getColor(getContext(), bottomButtonsColor));
    detailsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            openMenuHalfScreen();
        }
    });
    TextView directionsButton = (TextView) view.findViewById(R.id.context_menu_directions_button);
    int iconResId = R.drawable.map_directions;
    if (menu.navigateInPedestrianMode()) {
        iconResId = R.drawable.map_action_pedestrian_dark;
    }
    Drawable drawable = getIcon(iconResId, bottomButtonsColor);
    directionsButton.setTextColor(ContextCompat.getColor(getContext(), bottomButtonsColor));
    directionsButton.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null);
    directionsButton.setCompoundDrawablePadding(dpToPx(8));
    directionsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            menu.navigateButtonPressed();
        }
    });
    buildBottomView();
    LockableScrollView bottomScrollView = (LockableScrollView) view.findViewById(R.id.context_menu_bottom_scroll);
    bottomScrollView.setScrollingEnabled(false);
    bottomScrollView.setBackgroundColor(getResources().getColor(nightMode ? R.color.ctx_menu_bottom_view_bg_dark : R.color.ctx_menu_bottom_view_bg_light));
    view.findViewById(R.id.context_menu_bottom_view).setBackgroundColor(getResources().getColor(nightMode ? R.color.ctx_menu_bottom_view_bg_dark : R.color.ctx_menu_bottom_view_bg_light));
    // getMapActivity().getMapLayers().getMapControlsLayer().setControlsClickable(false);
    containerLayoutListener = new OnLayoutChangeListener() {

        @Override
        public void onLayoutChange(View view, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
            if (bottom != oldBottom) {
                processScreenHeight(view.getParent());
                runLayoutListener();
            }
        }
    };
    created = true;
    return view;
}
Also used : GestureDetector(android.view.GestureDetector) SingleTapConfirm(net.osmand.plus.views.controls.SingleTapConfirm) ViewConfiguration(android.view.ViewConfiguration) TransportStopRoute(net.osmand.plus.transport.TransportStopRoute) TextView(android.widget.TextView) ImageView(android.widget.ImageView) TypedValue(android.util.TypedValue) OverScroller(android.widget.OverScroller) RotatedTileBox(net.osmand.data.RotatedTileBox) VelocityTracker(android.view.VelocityTracker) OnLayoutChangeListener(android.view.View.OnLayoutChangeListener) ViewGroup(android.view.ViewGroup) Drawable(android.graphics.drawable.Drawable) GridView(android.widget.GridView) ImageView(android.widget.ImageView) View(android.view.View) LockableScrollView(net.osmand.plus.LockableScrollView) TextView(android.widget.TextView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) QuadPoint(net.osmand.data.QuadPoint) LockableScrollView(net.osmand.plus.LockableScrollView) MotionEvent(android.view.MotionEvent) TitleButtonController(net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController) FrameLayout(android.widget.FrameLayout) HorizontalSwipeConfirm(net.osmand.plus.views.controls.HorizontalSwipeConfirm) GridView(android.widget.GridView) TitleProgressController(net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController) LinearLayout(android.widget.LinearLayout)

Example 2 with TitleProgressController

use of net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController in project Osmand by osmandapp.

the class MapContextMenuFragment method updateButtonsAndProgress.

public void updateButtonsAndProgress() {
    if (view != null) {
        TitleButtonController leftTitleButtonController = menu.getLeftTitleButtonController();
        TitleButtonController rightTitleButtonController = menu.getRightTitleButtonController();
        TitleButtonController bottomTitleButtonController = menu.getBottomTitleButtonController();
        TitleButtonController leftDownloadButtonController = menu.getLeftDownloadButtonController();
        TitleButtonController rightDownloadButtonController = menu.getRightDownloadButtonController();
        TitleProgressController titleProgressController = menu.getTitleProgressController();
        // Title buttons
        boolean showTitleButtonsContainer = (leftTitleButtonController != null || rightTitleButtonController != null);
        final View titleButtonsContainer = view.findViewById(R.id.title_button_container);
        titleButtonsContainer.setVisibility(showTitleButtonsContainer ? View.VISIBLE : View.GONE);
        // Left title button
        final View leftTitleButtonView = view.findViewById(R.id.title_button_view);
        final TextView leftTitleButton = (TextView) view.findViewById(R.id.title_button);
        final TextView titleButtonRightText = (TextView) view.findViewById(R.id.title_button_right_text);
        if (leftTitleButtonController != null) {
            enableDisableButtons(leftTitleButtonView, leftTitleButton, leftTitleButtonController.enabled);
            leftTitleButton.setText(leftTitleButtonController.caption);
            if (leftTitleButtonController.visible) {
                leftTitleButtonView.setVisibility(View.VISIBLE);
                Drawable leftIcon = leftTitleButtonController.getLeftIcon();
                Drawable rightIcon = leftTitleButtonController.getRightIcon();
                leftTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, rightIcon, null);
                leftTitleButton.setCompoundDrawablePadding(dpToPx(8f));
                ((LinearLayout) leftTitleButtonView).setGravity(rightIcon != null ? Gravity.END : Gravity.START);
                if (leftTitleButtonController.needRightText) {
                    titleButtonRightText.setText(leftTitleButtonController.rightTextCaption);
                    titleButtonRightText.setVisibility(View.VISIBLE);
                } else {
                    titleButtonRightText.setVisibility(View.GONE);
                }
            } else {
                leftTitleButtonView.setVisibility(View.INVISIBLE);
            }
        } else {
            leftTitleButtonView.setVisibility(View.INVISIBLE);
            titleButtonRightText.setVisibility(View.GONE);
        }
        // Right title button
        final View rightTitleButtonView = view.findViewById(R.id.title_button_right_view);
        final TextView rightTitleButton = (TextView) view.findViewById(R.id.title_button_right);
        if (rightTitleButtonController != null) {
            enableDisableButtons(rightTitleButtonView, rightTitleButton, rightTitleButtonController.enabled);
            rightTitleButton.setText(rightTitleButtonController.caption);
            rightTitleButtonView.setVisibility(rightTitleButtonController.visible ? View.VISIBLE : View.INVISIBLE);
            Drawable leftIcon = rightTitleButtonController.getLeftIcon();
            Drawable rightIcon = rightTitleButtonController.getRightIcon();
            rightTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, rightIcon, null);
            rightTitleButton.setCompoundDrawablePadding(dpToPx(8f));
            ((LinearLayout) rightTitleButtonView).setGravity(rightIcon != null ? Gravity.END : Gravity.START);
        } else {
            rightTitleButtonView.setVisibility(View.INVISIBLE);
        }
        // Bottom title button
        final View bottomTitleButtonView = view.findViewById(R.id.title_button_bottom_view);
        final TextView bottomTitleButton = (TextView) view.findViewById(R.id.title_button_bottom);
        if (bottomTitleButtonController != null) {
            enableDisableButtons(bottomTitleButtonView, bottomTitleButton, bottomTitleButtonController.enabled);
            bottomTitleButton.setText(bottomTitleButtonController.caption);
            bottomTitleButtonView.setVisibility(bottomTitleButtonController.visible ? View.VISIBLE : View.GONE);
            Drawable leftIcon = bottomTitleButtonController.getLeftIcon();
            Drawable rightIcon = bottomTitleButtonController.getRightIcon();
            bottomTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, rightIcon, null);
            bottomTitleButton.setCompoundDrawablePadding(dpToPx(8f));
            ((LinearLayout) bottomTitleButtonView).setGravity(rightIcon != null ? Gravity.END : Gravity.START);
        } else {
            bottomTitleButtonView.setVisibility(View.GONE);
        }
        // Download buttons
        boolean showDownloadButtonsContainer = ((leftDownloadButtonController != null && leftDownloadButtonController.visible) || (rightDownloadButtonController != null && rightDownloadButtonController.visible)) && (titleProgressController == null || !titleProgressController.visible);
        final View downloadButtonsContainer = view.findViewById(R.id.download_buttons_container);
        downloadButtonsContainer.setVisibility(showDownloadButtonsContainer ? View.VISIBLE : View.GONE);
        // Left download button
        final View leftDownloadButtonView = view.findViewById(R.id.download_button_left_view);
        final TextView leftDownloadButton = (TextView) view.findViewById(R.id.download_button_left);
        if (leftDownloadButtonController != null) {
            enableDisableButtons(leftDownloadButtonView, leftDownloadButton, leftDownloadButtonController.enabled);
            leftDownloadButton.setText(leftDownloadButtonController.caption);
            leftDownloadButtonView.setVisibility(leftDownloadButtonController.visible ? View.VISIBLE : View.INVISIBLE);
            Drawable leftIcon = leftDownloadButtonController.getLeftIcon();
            Drawable rightIcon = leftDownloadButtonController.getRightIcon();
            leftDownloadButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, rightIcon, null);
            leftDownloadButton.setCompoundDrawablePadding(dpToPx(8f));
            ((LinearLayout) leftDownloadButtonView).setGravity(rightIcon != null ? Gravity.END : Gravity.START);
        } else {
            leftDownloadButtonView.setVisibility(View.INVISIBLE);
        }
        // Right download button
        final View rightDownloadButtonView = view.findViewById(R.id.download_button_right_view);
        final TextView rightDownloadButton = (TextView) view.findViewById(R.id.download_button_right);
        if (rightDownloadButtonController != null) {
            enableDisableButtons(rightDownloadButtonView, rightDownloadButton, rightDownloadButtonController.enabled);
            rightDownloadButton.setText(rightDownloadButtonController.caption);
            rightDownloadButtonView.setVisibility(rightDownloadButtonController.visible ? View.VISIBLE : View.INVISIBLE);
            Drawable leftIcon = rightDownloadButtonController.getLeftIcon();
            Drawable rightIcon = rightDownloadButtonController.getRightIcon();
            rightDownloadButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, rightIcon, null);
            rightDownloadButton.setCompoundDrawablePadding(dpToPx(8f));
            ((LinearLayout) rightDownloadButtonView).setGravity(rightIcon != null ? Gravity.END : Gravity.START);
        } else {
            rightDownloadButtonView.setVisibility(View.INVISIBLE);
        }
        // Progress bar
        final View titleProgressContainer = view.findViewById(R.id.title_progress_container);
        if (titleProgressController != null) {
            titleProgressContainer.setVisibility(titleProgressController.visible ? View.VISIBLE : View.GONE);
            if (titleProgressController.visible && showTitleButtonsContainer) {
                LinearLayout.LayoutParams ll = (LinearLayout.LayoutParams) titleProgressContainer.getLayoutParams();
                if (ll.topMargin != 0) {
                    ll.setMargins(0, 0, 0, 0);
                }
            }
            final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
            final TextView progressTitle = (TextView) view.findViewById(R.id.progressTitle);
            progressTitle.setText(titleProgressController.caption);
            progressBar.setIndeterminate(titleProgressController.indeterminate);
            progressBar.setProgress(titleProgressController.progress);
            progressBar.setVisibility(titleProgressController.progressVisible ? View.VISIBLE : View.GONE);
            final ImageView progressButton = (ImageView) view.findViewById(R.id.progressButton);
            progressButton.setVisibility(titleProgressController.buttonVisible ? View.VISIBLE : View.GONE);
        } else {
            titleProgressContainer.setVisibility(View.GONE);
        }
    }
}
Also used : TitleButtonController(net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController) Drawable(android.graphics.drawable.Drawable) TextView(android.widget.TextView) ImageView(android.widget.ImageView) GridView(android.widget.GridView) ImageView(android.widget.ImageView) View(android.view.View) LockableScrollView(net.osmand.plus.LockableScrollView) TextView(android.widget.TextView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) ProgressBar(android.widget.ProgressBar) TitleProgressController(net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController) LinearLayout(android.widget.LinearLayout)

Aggregations

Drawable (android.graphics.drawable.Drawable)2 View (android.view.View)2 GridView (android.widget.GridView)2 ImageView (android.widget.ImageView)2 LinearLayout (android.widget.LinearLayout)2 TextView (android.widget.TextView)2 LockableScrollView (net.osmand.plus.LockableScrollView)2 TitleButtonController (net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController)2 TitleProgressController (net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController)2 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)2 TypedValue (android.util.TypedValue)1 GestureDetector (android.view.GestureDetector)1 MotionEvent (android.view.MotionEvent)1 VelocityTracker (android.view.VelocityTracker)1 OnLayoutChangeListener (android.view.View.OnLayoutChangeListener)1 ViewConfiguration (android.view.ViewConfiguration)1 ViewGroup (android.view.ViewGroup)1 FrameLayout (android.widget.FrameLayout)1 OverScroller (android.widget.OverScroller)1 ProgressBar (android.widget.ProgressBar)1