Search in sources :

Example 6 with DrawSettings

use of net.osmand.plus.views.OsmandMapLayer.DrawSettings in project Osmand by osmandapp.

the class RouteInfoWidgetsFactory method createPlainTimeControl.

public TextInfoWidget createPlainTimeControl(final MapActivity map) {
    final OsmandApplication ctx = map.getMyApplication();
    final TextInfoWidget plainTimeControl = new TextInfoWidget(map) {

        private long cachedLeftTime = 0;

        @Override
        public boolean updateInfo(DrawSettings drawSettings) {
            long time = System.currentTimeMillis();
            if (time - cachedLeftTime > 5000) {
                cachedLeftTime = time;
                if (DateFormat.is24HourFormat(ctx)) {
                    // $NON-NLS-1$
                    setText(DateFormat.format("k:mm", time).toString(), null);
                } else {
                    setText(DateFormat.format("h:mm", time).toString(), // $NON-NLS-1$
                    DateFormat.format("aa", time).toString());
                }
            }
            return false;
        }
    };
    plainTimeControl.setText(null, null);
    plainTimeControl.setIcons(R.drawable.widget_time_day, R.drawable.widget_time_night);
    return plainTimeControl;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings)

Example 7 with DrawSettings

use of net.osmand.plus.views.OsmandMapLayer.DrawSettings in project Osmand by osmandapp.

the class RouteInfoWidgetsFactory method createBatteryControl.

public TextInfoWidget createBatteryControl(final MapActivity map) {
    final int battery = R.drawable.widget_battery_day;
    final int batteryN = R.drawable.widget_battery_night;
    final int batteryCharging = R.drawable.widget_battery_charging_day;
    final int batteryChargingN = R.drawable.widget_battery_charging_night;
    final OsmandApplication ctx = map.getMyApplication();
    final TextInfoWidget batteryControl = new TextInfoWidget(map) {

        private long cachedLeftTime = 0;

        @Override
        public boolean updateInfo(DrawSettings drawSettings) {
            long time = System.currentTimeMillis();
            if (time - cachedLeftTime > 1000) {
                cachedLeftTime = time;
                Intent batteryIntent = ctx.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
                int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
                int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
                int status = batteryIntent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
                if (level == -1 || scale == -1 || status == -1) {
                    setText("?", null);
                    setIcons(battery, batteryN);
                } else {
                    boolean charging = ((status == BatteryManager.BATTERY_STATUS_CHARGING) || (status == BatteryManager.BATTERY_STATUS_FULL));
                    setText(String.format("%d%%", (level * 100) / scale), null);
                    setIcons(charging ? batteryCharging : battery, charging ? batteryChargingN : batteryN);
                }
            }
            return false;
        }
    };
    batteryControl.setText(null, null);
    batteryControl.setIcons(battery, batteryN);
    return batteryControl;
}
Also used : IntentFilter(android.content.IntentFilter) OsmandApplication(net.osmand.plus.OsmandApplication) Intent(android.content.Intent) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) Paint(android.graphics.Paint) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings)

Example 8 with DrawSettings

use of net.osmand.plus.views.OsmandMapLayer.DrawSettings in project Osmand by osmandapp.

the class OsmandAidlApi method createWidgetControl.

private TextInfoWidget createWidgetControl(final MapActivity mapActivity, final String widgetId) {
    final TextInfoWidget control = new TextInfoWidget(mapActivity) {

        @Override
        public boolean updateInfo(DrawSettings drawSettings) {
            AMapWidget widget = widgets.get(widgetId);
            if (widget != null) {
                String txt = widget.getText();
                String subtxt = widget.getDescription();
                boolean night = drawSettings != null && drawSettings.isNightMode();
                int icon = night ? getDrawableId(widget.getDarkIconName()) : getDrawableId(widget.getLightIconName());
                setText(txt, subtxt);
                if (icon != 0) {
                    setImageDrawable(icon);
                } else {
                    setImageDrawable(null);
                }
                return true;
            } else {
                return false;
            }
        }
    };
    control.updateInfo(null);
    control.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            AMapWidget widget = widgets.get(widgetId);
            if (widget != null && widget.getIntentOnClick() != null) {
                app.startActivity(widget.getIntentOnClick());
            }
        }
    });
    return control;
}
Also used : TextInfoWidget(net.osmand.plus.views.mapwidgets.TextInfoWidget) AMapWidget(net.osmand.aidl.mapwidget.AMapWidget) View(android.view.View) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) FavouritePoint(net.osmand.data.FavouritePoint) AMapPoint(net.osmand.aidl.maplayer.point.AMapPoint) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings)

Example 9 with DrawSettings

use of net.osmand.plus.views.OsmandMapLayer.DrawSettings in project Osmand by osmandapp.

the class TrackSegmentFragment method updateHeader.

private void updateHeader() {
    imageView = (ImageView) headerView.findViewById(R.id.imageView);
    imageView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            GpxDataItem gpxDataItem = getGpxDataItem();
            GPXFile gpx = getGpx();
            WptPt pointToShow = gpx != null ? gpx.findPointToShow() : null;
            if (pointToShow != null) {
                LatLon location = new LatLon(pointToShow.getLatitude(), pointToShow.getLongitude());
                final OsmandSettings settings = app.getSettings();
                String trackName = "";
                if (gpx.showCurrentTrack) {
                    trackName = getString(R.string.shared_string_currently_recording_track);
                } else if (gpxDataItem != null) {
                    trackName = gpxDataItem.getFile().getName();
                } else {
                    trackName = gpx.path;
                }
                settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), settings.getLastKnownMapZoom(), new PointDescription(PointDescription.POINT_TYPE_WPT, trackName), false, getRect());
                MapActivity.launchMapActivityMoveToTop(getActivity());
            }
        }
    });
    final View splitColorView = headerView.findViewById(R.id.split_color_view);
    final View divider = headerView.findViewById(R.id.divider);
    final View splitIntervalView = headerView.findViewById(R.id.split_interval_view);
    final View colorView = headerView.findViewById(R.id.color_view);
    vis = (SwitchCompat) headerView.findViewById(R.id.showOnMapToggle);
    final ProgressBar progressBar = (ProgressBar) headerView.findViewById(R.id.mapLoadProgress);
    final boolean selected = getGpx() != null && ((getGpx().showCurrentTrack && app.getSelectedGpxHelper().getSelectedCurrentRecordingTrack() != null) || (getGpx().path != null && app.getSelectedGpxHelper().getSelectedFileByPath(getGpx().path) != null));
    vis.setChecked(selected);
    vis.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (!isChecked) {
                selectedSplitInterval = 0;
            }
            SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(getGpx(), vis.isChecked(), false);
            final List<GpxDisplayGroup> groups = getDisplayGroups();
            if (groups.size() > 0) {
                updateSplit(groups, vis.isChecked() ? sf : null);
                if (getGpxDataItem() != null) {
                    updateSplitInDatabase();
                }
            }
            updateSplitIntervalView(splitIntervalView);
            updateColorView(colorView);
        }
    });
    updateColorView(colorView);
    colorView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            colorListPopupWindow = new ListPopupWindow(getActivity());
            colorListPopupWindow.setAnchorView(colorView);
            colorListPopupWindow.setContentWidth(AndroidUtils.dpToPx(app, 200f));
            colorListPopupWindow.setModal(true);
            colorListPopupWindow.setDropDownGravity(Gravity.RIGHT | Gravity.TOP);
            colorListPopupWindow.setVerticalOffset(AndroidUtils.dpToPx(app, -48f));
            colorListPopupWindow.setHorizontalOffset(AndroidUtils.dpToPx(app, -6f));
            final GpxAppearanceAdapter gpxApprAdapter = new GpxAppearanceAdapter(getActivity(), getGpx().getColor(0), GpxAppearanceAdapterType.TRACK_COLOR);
            colorListPopupWindow.setAdapter(gpxApprAdapter);
            colorListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    AppearanceListItem item = gpxApprAdapter.getItem(position);
                    if (item != null) {
                        if (item.getAttrName() == CURRENT_TRACK_COLOR_ATTR) {
                            int clr = item.getColor();
                            if (vis.isChecked()) {
                                SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(getGpx(), vis.isChecked(), false);
                                if (clr != 0 && sf.getModifiableGpxFile() != null) {
                                    sf.getModifiableGpxFile().setColor(clr);
                                    if (getGpxDataItem() != null) {
                                        app.getGpxDatabase().updateColor(getGpxDataItem(), clr);
                                    }
                                }
                            } else if (getGpxDataItem() != null) {
                                app.getGpxDatabase().updateColor(getGpxDataItem(), clr);
                            }
                            if (getGpx().showCurrentTrack) {
                                app.getSettings().CURRENT_TRACK_COLOR.set(clr);
                            }
                            refreshTrackBitmap();
                        }
                    }
                    colorListPopupWindow.dismiss();
                    updateColorView(colorView);
                }
            });
            colorListPopupWindow.show();
        }
    });
    boolean hasPath = getGpx() != null && (getGpx().tracks.size() > 0 || getGpx().routes.size() > 0);
    if (rotatedTileBox == null || mapBitmap == null || mapTrackBitmap == null) {
        QuadRect rect = getRect();
        if (rect.left != 0 && rect.top != 0) {
            progressBar.setVisibility(View.VISIBLE);
            double clat = rect.bottom / 2 + rect.top / 2;
            double clon = rect.left / 2 + rect.right / 2;
            WindowManager mgr = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
            DisplayMetrics dm = new DisplayMetrics();
            mgr.getDefaultDisplay().getMetrics(dm);
            RotatedTileBoxBuilder boxBuilder = new RotatedTileBoxBuilder().setLocation(clat, clon).setZoom(15).density(dm.density).setPixelDimensions(dm.widthPixels, AndroidUtils.dpToPx(app, 152f), 0.5f, 0.5f);
            rotatedTileBox = boxBuilder.build();
            while (rotatedTileBox.getZoom() < 17 && rotatedTileBox.containsLatLon(rect.top, rect.left) && rotatedTileBox.containsLatLon(rect.bottom, rect.right)) {
                rotatedTileBox.setZoom(rotatedTileBox.getZoom() + 1);
            }
            while (rotatedTileBox.getZoom() >= 7 && (!rotatedTileBox.containsLatLon(rect.top, rect.left) || !rotatedTileBox.containsLatLon(rect.bottom, rect.right))) {
                rotatedTileBox.setZoom(rotatedTileBox.getZoom() - 1);
            }
            final DrawSettings drawSettings = new DrawSettings(!app.getSettings().isLightContent(), true);
            final ResourceManager resourceManager = app.getResourceManager();
            final MapRenderRepositories renderer = resourceManager.getRenderer();
            if (resourceManager.updateRenderedMapNeeded(rotatedTileBox, drawSettings)) {
                resourceManager.updateRendererMap(rotatedTileBox, new AsyncLoadingThread.OnMapLoadedListener() {

                    @Override
                    public void onMapLoaded(boolean interrupted) {
                        app.runInUIThread(new Runnable() {

                            @Override
                            public void run() {
                                if (updateEnable) {
                                    mapBitmap = renderer.getBitmap();
                                    if (mapBitmap != null) {
                                        progressBar.setVisibility(View.GONE);
                                        refreshTrackBitmap();
                                    }
                                }
                            }
                        });
                    }
                });
            }
            imageView.setVisibility(View.VISIBLE);
        } else {
            imageView.setVisibility(View.GONE);
        }
    } else {
        refreshTrackBitmap();
    }
    if (hasPath) {
        if (getGpx() != null && !getGpx().showCurrentTrack && adapter.getCount() > 0) {
            prepareSplitIntervalAdapterData();
            setupSplitIntervalView(splitIntervalView);
            updateSplitIntervalView(splitIntervalView);
            splitIntervalView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    splitListPopupWindow = new ListPopupWindow(getActivity());
                    splitListPopupWindow.setAnchorView(splitIntervalView);
                    splitListPopupWindow.setContentWidth(AndroidUtils.dpToPx(app, 200f));
                    splitListPopupWindow.setModal(true);
                    splitListPopupWindow.setDropDownGravity(Gravity.RIGHT | Gravity.TOP);
                    splitListPopupWindow.setVerticalOffset(AndroidUtils.dpToPx(app, -48f));
                    splitListPopupWindow.setHorizontalOffset(AndroidUtils.dpToPx(app, -6f));
                    splitListPopupWindow.setAdapter(new ArrayAdapter<>(getTrackActivity(), R.layout.popup_list_text_item, options));
                    splitListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                        @Override
                        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                            selectedSplitInterval = position;
                            SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(getGpx(), vis.isChecked(), false);
                            final List<GpxDisplayGroup> groups = getDisplayGroups();
                            if (groups.size() > 0) {
                                updateSplit(groups, vis.isChecked() ? sf : null);
                                if (getGpxDataItem() != null) {
                                    updateSplitInDatabase();
                                }
                            }
                            splitListPopupWindow.dismiss();
                            updateSplitIntervalView(splitIntervalView);
                        }
                    });
                    splitListPopupWindow.show();
                }
            });
            splitIntervalView.setVisibility(View.VISIBLE);
        } else {
            splitIntervalView.setVisibility(View.GONE);
        }
        splitColorView.setVisibility(View.VISIBLE);
        divider.setVisibility(View.VISIBLE);
    } else {
        splitColorView.setVisibility(View.GONE);
        divider.setVisibility(View.GONE);
    }
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) GpxDisplayGroup(net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup) QuadRect(net.osmand.data.QuadRect) DisplayMetrics(android.util.DisplayMetrics) WindowManager(android.view.WindowManager) AppearanceListItem(net.osmand.plus.dialogs.ConfigureMapMenu.AppearanceListItem) ListPopupWindow(android.support.v7.widget.ListPopupWindow) GpxAppearanceAdapter(net.osmand.plus.dialogs.ConfigureMapMenu.GpxAppearanceAdapter) GpxDataItem(net.osmand.plus.GPXDatabase.GpxDataItem) MapRenderRepositories(net.osmand.plus.render.MapRenderRepositories) ArrayList(java.util.ArrayList) TIntArrayList(gnu.trove.list.array.TIntArrayList) List(java.util.List) ProgressBar(android.widget.ProgressBar) ResourceManager(net.osmand.plus.resources.ResourceManager) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) OsmandSettings(net.osmand.plus.OsmandSettings) Paint(android.graphics.Paint) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings) LatLon(net.osmand.data.LatLon) RotatedTileBoxBuilder(net.osmand.data.RotatedTileBox.RotatedTileBoxBuilder) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) PointDescription(net.osmand.data.PointDescription) AdapterView(android.widget.AdapterView) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) AsyncLoadingThread(net.osmand.plus.resources.AsyncLoadingThread) CompoundButton(android.widget.CompoundButton) ArrayAdapter(android.widget.ArrayAdapter)

Example 10 with DrawSettings

use of net.osmand.plus.views.OsmandMapLayer.DrawSettings in project Osmand by osmandapp.

the class ParkingPositionPlugin method createParkingPlaceInfoControl.

/**
 * @return the control to be added on a MapInfoLayer
 * that shows a distance between
 * the current position on the map
 * and the location of the parked car
 */
private TextInfoWidget createParkingPlaceInfoControl(final MapActivity map) {
    TextInfoWidget parkingPlaceControl = new TextInfoWidget(map) {

        private float[] calculations = new float[1];

        private int cachedMeters = 0;

        @Override
        public boolean updateInfo(DrawSettings drawSettings) {
            LatLon parkingPoint = parkingLayer.getParkingPoint();
            if (parkingPoint != null && !map.getRoutingHelper().isFollowingMode()) {
                OsmandMapTileView view = map.getMapView();
                int d = 0;
                if (d == 0) {
                    net.osmand.Location.distanceBetween(view.getLatitude(), view.getLongitude(), parkingPoint.getLatitude(), parkingPoint.getLongitude(), calculations);
                    d = (int) calculations[0];
                }
                if (distChanged(cachedMeters, d)) {
                    cachedMeters = d;
                    if (cachedMeters <= 20) {
                        cachedMeters = 0;
                        setText(null, null);
                    } else {
                        String ds = OsmAndFormatter.getFormattedDistance(cachedMeters, map.getMyApplication());
                        int ls = ds.lastIndexOf(' ');
                        if (ls == -1) {
                            setText(ds, null);
                        } else {
                            setText(ds.substring(0, ls), ds.substring(ls + 1));
                        }
                    }
                    return true;
                }
            } else if (cachedMeters != 0) {
                cachedMeters = 0;
                setText(null, null);
                return true;
            }
            return false;
        }

        /**
         * Utility method.
         * @param oldDist
         * @param dist
         * @return
         */
        private boolean distChanged(int oldDist, int dist) {
            if (oldDist != 0 && Math.abs(oldDist - dist) < 30) {
                return false;
            }
            return true;
        }
    };
    parkingPlaceControl.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            OsmandMapTileView view = map.getMapView();
            AnimateDraggingMapThread thread = view.getAnimatedDraggingThread();
            LatLon parkingPoint = parkingPosition;
            if (parkingPoint != null) {
                int fZoom = view.getZoom() < 15 ? 15 : view.getZoom();
                thread.startMoving(parkingPoint.getLatitude(), parkingPoint.getLongitude(), fZoom, true);
            }
        }
    });
    parkingPlaceControl.setText(null, null);
    parkingPlaceControl.setIcons(R.drawable.widget_parking_day, R.drawable.widget_parking_night);
    return parkingPlaceControl;
}
Also used : TextInfoWidget(net.osmand.plus.views.mapwidgets.TextInfoWidget) LatLon(net.osmand.data.LatLon) AnimateDraggingMapThread(net.osmand.plus.views.AnimateDraggingMapThread) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) View(android.view.View) TextView(android.widget.TextView) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings)

Aggregations

DrawSettings (net.osmand.plus.views.OsmandMapLayer.DrawSettings)20 View (android.view.View)10 TextView (android.widget.TextView)9 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)9 Paint (android.graphics.Paint)7 ImageView (android.widget.ImageView)7 OsmandApplication (net.osmand.plus.OsmandApplication)6 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)6 Location (net.osmand.Location)4 LatLon (net.osmand.data.LatLon)4 RoutingHelper (net.osmand.plus.routing.RoutingHelper)3 TextInfoWidget (net.osmand.plus.views.mapwidgets.TextInfoWidget)3 Message (android.os.Message)2 OnClickListener (android.view.View.OnClickListener)2 OsmAndLocationProvider (net.osmand.plus.OsmAndLocationProvider)2 OsmandSettings (net.osmand.plus.OsmandSettings)2 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 GeomagneticField (android.hardware.GeomagneticField)1 ListPopupWindow (android.support.v7.widget.ListPopupWindow)1