Search in sources :

Example 16 with UiUtilities

use of net.osmand.plus.utils.UiUtilities in project Osmand by osmandapp.

the class SecondSplashScreenFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    OsmandApplication app = requireMyApplication();
    FragmentActivity activity = requireActivity();
    UiUtilities iconsCache = app.getUIUtilities();
    systemDefaultNightMode = app.getSettings().isSupportSystemDefaultTheme() && !app.getSettings().isLightSystemDefaultTheme();
    RelativeLayout view = new RelativeLayout(activity);
    view.setOnClickListener(null);
    int backgroundColorId = systemDefaultNightMode ? R.color.list_background_color_dark : R.color.map_background_color_light;
    view.setBackgroundColor(getResources().getColor(backgroundColorId));
    ImageView logo = new ImageView(getContext());
    logo.setId(LOGO_ID);
    if (Version.isFreeVersion(app)) {
        logo.setImageDrawable(AppCompatResources.getDrawable(activity, R.drawable.ic_logo_splash_osmand));
    } else if (Version.isPaidVersion(app) || Version.isDeveloperVersion(app)) {
        logo.setImageDrawable(AppCompatResources.getDrawable(activity, R.drawable.ic_logo_splash_osmand_plus));
    }
    RelativeLayout.LayoutParams logoLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    if (isSmartphone()) {
        logoLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        logoLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    } else {
        logoLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    }
    ImageView text = new ImageView(activity);
    text.setId(TEXT_ID);
    int textColorId = ColorUtilities.getTertiaryTextColorId(systemDefaultNightMode);
    if (Version.isFreeVersion(app)) {
        if (InAppPurchaseHelper.isOsmAndProAvailable(app)) {
            text.setImageDrawable(iconsCache.getIcon(R.drawable.image_text_osmand_pro, textColorId));
        } else if (InAppPurchaseHelper.isSubscribedToMaps(app)) {
            text.setImageDrawable(iconsCache.getIcon(R.drawable.image_text_osmand_maps_plus, textColorId));
        } else if (InAppPurchaseHelper.isSubscribedToLiveUpdates(app)) {
            text.setImageDrawable(iconsCache.getIcon(R.drawable.image_text_osmand_osmlive, textColorId));
        } else if (InAppPurchaseHelper.isFullVersionPurchased(app)) {
            text.setImageDrawable(iconsCache.getIcon(R.drawable.image_text_osmand_inapp, textColorId));
        } else {
            text.setImageDrawable(iconsCache.getIcon(R.drawable.image_text_osmand, textColorId));
        }
    } else if (Version.isPaidVersion(app) || Version.isDeveloperVersion(app)) {
        if (InAppPurchaseHelper.isOsmAndProAvailable(app)) {
            text.setImageDrawable(iconsCache.getIcon(R.drawable.image_text_osmand_plus_pro, textColorId));
        } else if (InAppPurchaseHelper.isSubscribedToLiveUpdates(app)) {
            text.setImageDrawable(iconsCache.getIcon(R.drawable.image_text_osmand_plus_osmlive, textColorId));
        } else {
            text.setImageDrawable(iconsCache.getIcon(R.drawable.image_text_osmand_plus, textColorId));
        }
    }
    RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    textLayoutParams.addRule(RelativeLayout.ABOVE, OSM_TEXT_ID);
    textLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    ImageView osmText = new ImageView(activity);
    osmText.setId(OSM_TEXT_ID);
    osmText.setImageDrawable(iconsCache.getIcon(R.drawable.image_text_openstreetmap, textColorId));
    RelativeLayout.LayoutParams osmTextLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    osmTextLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    osmTextLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    int defaultLogoMarginTop = getResources().getDimensionPixelSize(R.dimen.splash_screen_logo_top);
    int logoMarginTop = defaultLogoMarginTop - (Build.VERSION.SDK_INT >= 21 ? 0 : AndroidUtils.getStatusBarHeight(activity));
    int textMarginBottom = getResources().getDimensionPixelSize(R.dimen.splash_screen_text_bottom);
    int osmTextMarginBottom = getResources().getDimensionPixelSize(R.dimen.splash_screen_osm_text_bottom);
    int elementsPaddingLeft = 0;
    int elementsPaddingRight = 0;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {
        int screenOrientation = AndroidUiHelper.getScreenOrientation(activity);
        if (screenOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
            elementsPaddingLeft = getNavigationBarWidth();
        } else if (screenOrientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) {
            elementsPaddingRight = getNavigationBarWidth();
        }
    } else {
        elementsPaddingLeft = getNavigationBarWidth();
    }
    AndroidUtils.setMargins(logoLayoutParams, 0, logoMarginTop, 0, 0);
    logo.setPadding(elementsPaddingLeft, 0, elementsPaddingRight, 0);
    logo.setLayoutParams(logoLayoutParams);
    view.addView(logo);
    textLayoutParams.setMargins(0, 0, 0, textMarginBottom);
    text.setPadding(elementsPaddingLeft, 0, elementsPaddingRight, 0);
    text.setLayoutParams(textLayoutParams);
    view.addView(text);
    osmTextLayoutParams.setMargins(0, 0, 0, osmTextMarginBottom);
    osmText.setPadding(elementsPaddingLeft, 0, elementsPaddingRight, 0);
    osmText.setLayoutParams(osmTextLayoutParams);
    view.addView(osmText);
    return view;
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) UiUtilities(net.osmand.plus.utils.UiUtilities) OsmandApplication(net.osmand.plus.OsmandApplication) RelativeLayout(android.widget.RelativeLayout) ImageView(android.widget.ImageView) Nullable(androidx.annotation.Nullable)

Example 17 with UiUtilities

use of net.osmand.plus.utils.UiUtilities in project Osmand by osmandapp.

the class TrackDetailsMenu method updateView.

private void updateView(final View parentView, boolean forceFitTrackOnMap) {
    MapActivity mapActivity = getMapActivity();
    GpxDisplayItem gpxItem = getGpxItem();
    if (mapActivity == null || gpxItem == null) {
        return;
    }
    final OsmandApplication app = mapActivity.getMyApplication();
    final UiUtilities ic = app.getUIUtilities();
    final boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
    GPXTrackAnalysis analysis = gpxItem.analysis;
    if (analysis == null || gpxItem.chartTypes == null) {
        parentView.setVisibility(View.GONE);
        if (analysis != null && analysis.isBoundsCalculated()) {
            mapActivity.getMapView().fitRectToMap(analysis.left, analysis.right, analysis.top, analysis.bottom, 0, 0, 0);
        }
        return;
    }
    final LineChart chart = (LineChart) parentView.findViewById(R.id.chart);
    chart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {

        @Override
        public void onValueSelected(Entry e, Highlight h) {
            refreshChart(chart, false);
        }

        @Override
        public void onNothingSelected() {
        }
    });
    // final float minDragTriggerDist = AndroidUtils.dpToPx(app, 3);
    // chart.setOnTouchListener(new BarLineChartTouchListener(chart, chart.getViewPortHandler().getMatrixTouch(), 3f) {
    // private PointF touchStartPoint = new PointF();
    // 
    // @SuppressLint("ClickableViewAccessibility")
    // @Override
    // public boolean onTouch(View v, MotionEvent event) {
    // switch (event.getAction() & MotionEvent.ACTION_MASK) {
    // case MotionEvent.ACTION_DOWN:
    // saveTouchStart(event);
    // break;
    // case MotionEvent.ACTION_POINTER_DOWN:
    // if (event.getPointerCount() >= 2) {
    // saveTouchStart(event);
    // }
    // break;
    // case MotionEvent.ACTION_MOVE:
    // if (mTouchMode == NONE && mChart.hasNoDragOffset()) {
    // float touchDistance = distance(event.getX(), touchStartPoint.x, event.getY(), touchStartPoint.y);
    // if (Math.abs(touchDistance) > minDragTriggerDist) {
    // mTouchMode = DRAG;
    // }
    // }
    // break;
    // }
    // return super.onTouch(v, event);
    // }
    // 
    // private void saveTouchStart(MotionEvent event) {
    // touchStartPoint.x = event.getX();
    // touchStartPoint.y = event.getY();
    // }
    // });
    chart.setOnChartGestureListener(new OnChartGestureListener() {

        boolean hasTranslated = false;

        float highlightDrawX = -1;

        @Override
        public void onChartGestureStart(MotionEvent me, ChartGesture lastPerformedGesture) {
            hasTranslated = false;
            if (chart.getHighlighted() != null && chart.getHighlighted().length > 0) {
                highlightDrawX = chart.getHighlighted()[0].getDrawX();
            } else {
                highlightDrawX = -1;
            }
            MapActivity mapActivity = getMapActivity();
            if (lastPerformedGesture != ChartGesture.NONE && mapActivity != null && mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation()) {
                mapActivity.getMapViewTrackingUtilities().setMapLinkedToLocation(false);
            }
        }

        @Override
        public void onChartGestureEnd(MotionEvent me, ChartGesture lastPerformedGesture) {
            GpxDisplayItem gpxItem = getGpxItem();
            if (gpxItem != null) {
                if ((lastPerformedGesture == ChartGesture.DRAG && hasTranslated) || lastPerformedGesture == ChartGesture.X_ZOOM || lastPerformedGesture == ChartGesture.Y_ZOOM || lastPerformedGesture == ChartGesture.PINCH_ZOOM || lastPerformedGesture == ChartGesture.DOUBLE_TAP || lastPerformedGesture == ChartGesture.ROTATE) {
                    gpxItem.chartMatrix = new Matrix(chart.getViewPortHandler().getMatrixTouch());
                    refreshChart(chart, false);
                }
            }
        }

        @Override
        public void onChartLongPressed(MotionEvent me) {
        }

        @Override
        public void onChartDoubleTapped(MotionEvent me) {
        }

        @Override
        public void onChartSingleTapped(MotionEvent me) {
        }

        @Override
        public void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) {
        }

        @Override
        public void onChartScale(MotionEvent me, float scaleX, float scaleY) {
        }

        @Override
        public void onChartTranslate(MotionEvent me, float dX, float dY) {
            hasTranslated = true;
            if (highlightDrawX != -1) {
                Highlight h = chart.getHighlightByTouchPoint(highlightDrawX, 0f);
                if (h != null) {
                    chart.highlightValue(h);
                    refreshChart(chart, false);
                }
            }
        }
    });
    boolean useHours = analysis.timeSpan != 0 && analysis.timeSpan / HOUR_IN_MILLIS > 0;
    GpxMarkerView markerView = new GpxMarkerView(mapActivity, analysis.startTime, useHours);
    GpxUiHelper.setupGPXChart(chart, markerView, 24, 16, true);
    List<ILineDataSet> dataSets = new ArrayList<>();
    if (gpxItem.chartTypes != null && gpxItem.chartTypes.length > 0) {
        for (int i = 0; i < gpxItem.chartTypes.length; i++) {
            OrderedLineDataSet dataSet = null;
            boolean withoutGaps = selectedGpxFile != null && (!selectedGpxFile.isJoinSegments() && gpxItem.isGeneralTrack());
            switch(gpxItem.chartTypes[i]) {
                case ALTITUDE:
                    dataSet = GpxUiHelper.createGPXElevationDataSet(app, chart, analysis, gpxItem.chartAxisType, false, true, withoutGaps);
                    break;
                case SPEED:
                    dataSet = GpxUiHelper.createGPXSpeedDataSet(app, chart, analysis, gpxItem.chartAxisType, gpxItem.chartTypes.length > 1, true, withoutGaps);
                    break;
                case SLOPE:
                    dataSet = GpxUiHelper.createGPXSlopeDataSet(app, chart, analysis, gpxItem.chartAxisType, null, gpxItem.chartTypes.length > 1, true, withoutGaps);
                    break;
            }
            if (dataSet != null) {
                dataSets.add(dataSet);
            }
        }
    }
    Collections.sort(dataSets, new Comparator<ILineDataSet>() {

        @Override
        public int compare(ILineDataSet ds1, ILineDataSet ds2) {
            OrderedLineDataSet dataSet1 = (OrderedLineDataSet) ds1;
            OrderedLineDataSet dataSet2 = (OrderedLineDataSet) ds2;
            return dataSet1.getPriority() > dataSet2.getPriority() ? -1 : (dataSet1.getPriority() == dataSet2.getPriority() ? 0 : 1);
        }
    });
    chart.setData(new LineData(dataSets));
    updateChart(chart);
    View yAxis = parentView.findViewById(R.id.y_axis);
    ImageView yAxisIcon = (ImageView) parentView.findViewById(R.id.y_axis_icon);
    TextView yAxisTitle = (TextView) parentView.findViewById(R.id.y_axis_title);
    View yAxisArrow = parentView.findViewById(R.id.y_axis_arrow);
    final List<GPXDataSetType[]> availableTypes = new ArrayList<>();
    boolean hasSlopeChart = false;
    if (analysis.hasElevationData) {
        availableTypes.add(new GPXDataSetType[] { GPXDataSetType.ALTITUDE });
        if (gpxItem.chartAxisType != GPXDataSetAxisType.TIME && gpxItem.chartAxisType != GPXDataSetAxisType.TIMEOFDAY) {
            availableTypes.add(new GPXDataSetType[] { GPXDataSetType.SLOPE });
        }
    }
    if (analysis.hasSpeedData) {
        availableTypes.add(new GPXDataSetType[] { GPXDataSetType.SPEED });
    }
    if (analysis.hasElevationData && gpxItem.chartAxisType != GPXDataSetAxisType.TIME && gpxItem.chartAxisType != GPXDataSetAxisType.TIMEOFDAY) {
        availableTypes.add(new GPXDataSetType[] { GPXDataSetType.ALTITUDE, GPXDataSetType.SLOPE });
    }
    if (analysis.hasElevationData && analysis.hasSpeedData) {
        availableTypes.add(new GPXDataSetType[] { GPXDataSetType.ALTITUDE, GPXDataSetType.SPEED });
    }
    for (GPXDataSetType t : gpxItem.chartTypes) {
        if (t == GPXDataSetType.SLOPE) {
            hasSlopeChart = true;
            break;
        }
    }
    yAxisIcon.setImageDrawable(GPXDataSetType.getImageDrawable(app, gpxItem.chartTypes));
    yAxisTitle.setText(GPXDataSetType.getName(app, gpxItem.chartTypes));
    if (availableTypes.size() > 0) {
        yAxis.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                List<PopUpMenuItem> items = new ArrayList<>();
                for (GPXDataSetType[] types : availableTypes) {
                    String title = GPXDataSetType.getName(app, types);
                    Drawable icon = GPXDataSetType.getImageDrawable(app, types);
                    items.add(new PopUpMenuItem.Builder(app).setTitle(title).setIcon(icon).create());
                }
                AdapterView.OnItemClickListener listener = new AdapterView.OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        fitTrackOnMapForbidden = true;
                        GpxDisplayItem gpxItem = getGpxItem();
                        gpxItem.chartTypes = availableTypes.get(position);
                        update();
                        fitTrackOnMapForbidden = false;
                    }
                };
                new PopUpMenuHelper.Builder(v, items, nightMode).setListener(listener).show();
            }
        });
        yAxisArrow.setVisibility(View.VISIBLE);
    } else {
        yAxis.setOnClickListener(null);
        yAxis.setBackgroundResource(0);
        yAxisArrow.setVisibility(View.GONE);
    }
    View xAxis = parentView.findViewById(R.id.x_axis);
    ImageView xAxisIcon = (ImageView) parentView.findViewById(R.id.x_axis_icon);
    TextView xAxisTitle = (TextView) parentView.findViewById(R.id.x_axis_title);
    View xAxisArrow = parentView.findViewById(R.id.x_axis_arrow);
    if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME) {
        xAxisIcon.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_time));
        xAxisTitle.setText(app.getString(R.string.shared_string_time));
    } else if (gpxItem.chartAxisType == GPXDataSetAxisType.TIMEOFDAY) {
        xAxisIcon.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_time_span));
        xAxisTitle.setText(app.getString(R.string.time_of_day));
    } else {
        xAxisIcon.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_marker_dark));
        xAxisTitle.setText(app.getString(R.string.distance));
    }
    if (analysis.isTimeSpecified() && !hasSlopeChart) {
        xAxis.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                List<PopUpMenuItem> items = new ArrayList<>();
                for (GPXDataSetAxisType type : GPXDataSetAxisType.values()) {
                    items.add(new PopUpMenuItem.Builder(app).setTitleId(type.getStringId()).setIcon(type.getImageDrawable(app)).create());
                }
                new PopUpMenuHelper.Builder(v, items, nightMode).setListener(new AdapterView.OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        fitTrackOnMapForbidden = true;
                        GpxDisplayItem gpxItem = getGpxItem();
                        if (gpxItem != null) {
                            gpxItem.chartAxisType = GPXDataSetAxisType.values()[position];
                            gpxItem.chartHighlightPos = -1;
                            gpxItem.chartMatrix = null;
                            update();
                        }
                        fitTrackOnMapForbidden = false;
                    }
                }).show();
            }
        });
        xAxisArrow.setVisibility(View.VISIBLE);
    } else {
        xAxis.setOnClickListener(null);
        xAxis.setBackgroundResource(0);
        xAxisArrow.setVisibility(View.GONE);
    }
    refreshChart(chart, forceFitTrackOnMap);
}
Also used : OnChartValueSelectedListener(com.github.mikephil.charting.listener.OnChartValueSelectedListener) Highlight(com.github.mikephil.charting.highlight.Highlight) OsmandApplication(net.osmand.plus.OsmandApplication) GpxDisplayItem(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem) ArrayList(java.util.ArrayList) ChartGesture(com.github.mikephil.charting.listener.ChartTouchListener.ChartGesture) Entry(com.github.mikephil.charting.data.Entry) Matrix(android.graphics.Matrix) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) GPXDataSetType(net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType) TextView(android.widget.TextView) List(java.util.List) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) MapActivity(net.osmand.plus.activities.MapActivity) OnChartGestureListener(com.github.mikephil.charting.listener.OnChartGestureListener) GPXTrackAnalysis(net.osmand.GPXUtilities.GPXTrackAnalysis) Drawable(android.graphics.drawable.Drawable) PopUpMenuItem(net.osmand.plus.widgets.popup.PopUpMenuItem) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) TopToolbarView(net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarView) GpxMarkerView(net.osmand.plus.track.GpxMarkerView) MotionEvent(android.view.MotionEvent) UiUtilities(net.osmand.plus.utils.UiUtilities) PopUpMenuHelper(net.osmand.plus.widgets.popup.PopUpMenuHelper) LineData(com.github.mikephil.charting.data.LineData) GPXDataSetAxisType(net.osmand.plus.helpers.GpxUiHelper.GPXDataSetAxisType) OrderedLineDataSet(net.osmand.plus.helpers.GpxUiHelper.OrderedLineDataSet) AdapterView(android.widget.AdapterView) LineChart(com.github.mikephil.charting.charts.LineChart) GpxMarkerView(net.osmand.plus.track.GpxMarkerView)

Example 18 with UiUtilities

use of net.osmand.plus.utils.UiUtilities in project Osmand by osmandapp.

the class DestinationReachedMenuFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    MapActivity mapActivity = getMapActivity();
    if (mapActivity == null || menu == null) {
        return null;
    }
    ContextThemeWrapper ctx = new ContextThemeWrapper(mapActivity, menu.isLight() ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme);
    LayoutInflater inf = LayoutInflater.from(ctx);
    View view = inf.inflate(R.layout.dest_reached_menu_fragment, container, false);
    AndroidUtils.addStatusBarPadding21v(ctx, view);
    view.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finishNavigation();
        }
    });
    UiUtilities iconsCache = mapActivity.getMyApplication().getUIUtilities();
    ImageButton closeImageButton = (ImageButton) view.findViewById(R.id.closeImageButton);
    closeImageButton.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_remove_dark, menu.isLight()));
    closeImageButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finishNavigation();
        }
    });
    Button removeDestButton = (Button) view.findViewById(R.id.removeDestButton);
    removeDestButton.setCompoundDrawablesWithIntrinsicBounds(iconsCache.getIcon(R.drawable.ic_action_done, menu.isLight()), null, null, null);
    removeDestButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finishNavigation();
        }
    });
    Button recalcDestButton = (Button) view.findViewById(R.id.recalcDestButton);
    recalcDestButton.setCompoundDrawablesWithIntrinsicBounds(iconsCache.getIcon(R.drawable.ic_action_gdirections_dark, menu.isLight()), null, null, null);
    recalcDestButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            MapActivity mapActivity = getMapActivity();
            if (mapActivity != null) {
                TargetPointsHelper helper = mapActivity.getMyApplication().getTargetPointsHelper();
                TargetPoint target = helper.getPointToNavigate();
                dismissMenu();
                if (target != null) {
                    helper.navigateToPoint(new LatLon(target.getLatitude(), target.getLongitude()), true, -1, target.getOriginalPointDescription());
                    mapActivity.getMapActions().recalculateRoute(false);
                    mapActivity.getMapLayers().getMapControlsLayer().startNavigation();
                }
            }
        }
    });
    Button findParkingButton = (Button) view.findViewById(R.id.findParkingButton);
    ApplicationMode appMode = mapActivity.getMyApplication().getRoutingHelper().getAppMode();
    if (!appMode.isDerivedRoutingFrom(ApplicationMode.CAR)) {
        findParkingButton.setVisibility(View.GONE);
    }
    findParkingButton.setCompoundDrawablesWithIntrinsicBounds(iconsCache.getIcon(R.drawable.ic_action_parking_dark, menu.isLight()), null, null, null);
    findParkingButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            MapActivity mapActivity = getMapActivity();
            if (mapActivity != null) {
                PoiFiltersHelper helper = mapActivity.getMyApplication().getPoiFilters();
                PoiUIFilter parkingFilter = helper.getFilterById(PoiUIFilter.STD_PREFIX + "parking");
                mapActivity.showQuickSearch(parkingFilter);
            }
            dismissMenu();
        }
    });
    View mainView = view.findViewById(R.id.main_view);
    if (menu.isLandscapeLayout()) {
        AndroidUtils.setBackground(view.getContext(), mainView, !menu.isLight(), R.drawable.bg_left_menu_light, R.drawable.bg_left_menu_dark);
    } else {
        AndroidUtils.setBackground(view.getContext(), mainView, !menu.isLight(), R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
    }
    return view;
}
Also used : ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) PoiFiltersHelper(net.osmand.plus.poi.PoiFiltersHelper) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) View(android.view.View) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) UiUtilities(net.osmand.plus.utils.UiUtilities) LatLon(net.osmand.data.LatLon) ImageButton(android.widget.ImageButton) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) ImageButton(android.widget.ImageButton) Button(android.widget.Button) LayoutInflater(android.view.LayoutInflater) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) MapActivity(net.osmand.plus.activities.MapActivity) Nullable(androidx.annotation.Nullable)

Example 19 with UiUtilities

use of net.osmand.plus.utils.UiUtilities in project Osmand by osmandapp.

the class RearrangePoiFiltersFragment method updateProfileButton.

protected void updateProfileButton() {
    View view = getView();
    if (view == null) {
        return;
    }
    OsmandApplication app = requireMyApplication();
    UiUtilities uiUtilities = app.getUIUtilities();
    ApplicationMode selectedAppMode = getSelectedAppMode();
    boolean nightMode = isNightMode(app, usedOnMap);
    ImageView profileIcon = (ImageView) view.findViewById(R.id.profile_icon);
    if (profileIcon != null) {
        int iconRes = selectedAppMode.getIconRes();
        profileIcon.setImageDrawable(uiUtilities.getPaintedIcon(iconRes, selectedAppMode.getProfileColor(nightMode)));
    }
    View profileButton = view.findViewById(R.id.profile_button);
    if (profileButton != null) {
        int iconColor = getSelectedAppMode().getProfileColor(nightMode);
        int bgColor = ContextCompat.getColor(app, nightMode ? R.color.divider_color_dark : R.color.active_buttons_and_links_text_light);
        int selectedColor = ColorUtilities.getColorWithAlpha(iconColor, 0.3f);
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
            int bgResId = R.drawable.circle_background_light;
            int selectableResId = R.drawable.ripple_circle;
            Drawable bgDrawable = uiUtilities.getPaintedIcon(bgResId, bgColor);
            Drawable selectable = uiUtilities.getPaintedIcon(selectableResId, selectedColor);
            Drawable[] layers = { bgDrawable, selectable };
            AndroidUtils.setBackground(profileButton, new LayerDrawable(layers));
        } else {
            int bgResId = R.drawable.circle_background_light;
            Drawable bgDrawable = uiUtilities.getPaintedIcon(bgResId, bgColor);
            AndroidUtils.setBackground(profileButton, bgDrawable);
        }
    }
}
Also used : UiUtilities(net.osmand.plus.utils.UiUtilities) OsmandApplication(net.osmand.plus.OsmandApplication) LayerDrawable(android.graphics.drawable.LayerDrawable) Drawable(android.graphics.drawable.Drawable) LayerDrawable(android.graphics.drawable.LayerDrawable) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint)

Example 20 with UiUtilities

use of net.osmand.plus.utils.UiUtilities in project Osmand by osmandapp.

the class MapWidgetRegistry method showPopUpMenu.

public void showPopUpMenu(@NonNull MapActivity mapActivity, @NonNull View view, @NonNull final ArrayAdapter<ContextMenuItem> adapter, @Nullable final WidgetState widgetState, @Nullable final String message, @NonNull ApplicationMode mode, @NonNull OnClickListener showBtnListener, @NonNull OnClickListener hideBtnListener, @Nullable OnClickListener collapseBtnListener, boolean selected, final int pos) {
    final boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
    final int currentModeColor = mode.getProfileColor(nightMode);
    View parentView = view.findViewById(R.id.text_wrapper);
    List<PopUpMenuItem> items = new ArrayList<>();
    UiUtilities uiUtilities = app.getUIUtilities();
    if (widgetState != null) {
        final int[] menuIconIds = widgetState.getMenuIconIds();
        final int[] menuTitleIds = widgetState.getMenuTitleIds();
        final int[] menuItemIds = widgetState.getMenuItemIds();
        if (menuIconIds != null && menuTitleIds != null && menuItemIds != null && menuIconIds.length == menuTitleIds.length && menuIconIds.length == menuItemIds.length) {
            for (int i = 0; i < menuIconIds.length; i++) {
                int iconId = menuIconIds[i];
                int titleId = menuTitleIds[i];
                final int id = menuItemIds[i];
                boolean checkedItem = id == widgetState.getMenuItemId();
                Drawable icon = checkedItem && selected ? uiUtilities.getPaintedIcon(iconId, currentModeColor) : uiUtilities.getThemedIcon(iconId);
                items.add(new PopUpMenuItem.Builder(app).setTitle(getString(titleId)).setIcon(icon).setOnClickListener(v -> {
                    widgetState.changeState(id);
                    MapInfoLayer mil = mapActivity.getMapLayers().getMapInfoLayer();
                    if (mil != null) {
                        mil.recreateControls();
                    }
                    ContextMenuItem item = adapter.getItem(pos);
                    item.setIcon(widgetState.getMenuIconId());
                    if (message != null) {
                        item.setTitle(message);
                    } else {
                        item.setTitle(getString(widgetState.getMenuTitleId()));
                    }
                    adapter.notifyDataSetChanged();
                }).showCompoundBtn(currentModeColor).setSelected(checkedItem).create());
            }
        }
    }
    // show
    items.add(new PopUpMenuItem.Builder(app).setTitleId(R.string.shared_string_show).setIcon(uiUtilities.getThemedIcon(R.drawable.ic_action_view)).setOnClickListener(showBtnListener).showTopDivider(items.size() > 0).create());
    // hide
    items.add(new PopUpMenuItem.Builder(app).setTitleId(R.string.shared_string_hide).setIcon(uiUtilities.getThemedIcon(R.drawable.ic_action_hide)).setOnClickListener(hideBtnListener).create());
    // collapse
    if (collapseBtnListener != null) {
        items.add(new PopUpMenuItem.Builder(app).setTitleId(R.string.shared_string_collapse).setIcon(uiUtilities.getThemedIcon(R.drawable.ic_action_widget_collapse)).setOnClickListener(collapseBtnListener).create());
    }
    new PopUpMenuHelper.Builder(parentView, items, nightMode).setWidthType(PopUpMenuWidthType.STANDARD).setBackgroundColor(ColorUtilities.getListBgColor(mapActivity, nightMode)).show();
}
Also used : ContextMenuItem(net.osmand.plus.ContextMenuItem) ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) PopUpMenuItem(net.osmand.plus.widgets.popup.PopUpMenuItem) View(android.view.View) UiUtilities(net.osmand.plus.utils.UiUtilities) PopUpMenuHelper(net.osmand.plus.widgets.popup.PopUpMenuHelper) MapInfoLayer(net.osmand.plus.views.layers.MapInfoLayer)

Aggregations

UiUtilities (net.osmand.plus.utils.UiUtilities)35 View (android.view.View)16 ImageView (android.widget.ImageView)16 Drawable (android.graphics.drawable.Drawable)13 TextView (android.widget.TextView)13 OsmandApplication (net.osmand.plus.OsmandApplication)13 MenuItem (android.view.MenuItem)7 ArrayList (java.util.ArrayList)7 MapActivity (net.osmand.plus.activities.MapActivity)7 LatLon (net.osmand.data.LatLon)6 PopupMenu (androidx.appcompat.widget.PopupMenu)5 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 SuppressLint (android.annotation.SuppressLint)3 Bundle (android.os.Bundle)3 Editable (android.text.Editable)3 TextWatcher (android.text.TextWatcher)3 LayoutInflater (android.view.LayoutInflater)3 MotionEvent (android.view.MotionEvent)3 AdapterView (android.widget.AdapterView)3 PointDescription (net.osmand.data.PointDescription)3