Search in sources :

Example 1 with MapViewTrackingUtilities

use of net.osmand.plus.base.MapViewTrackingUtilities in project Osmand by osmandapp.

the class MapActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    setRequestedOrientation(AndroidUiHelper.getScreenOrientation(this));
    long tm = System.currentTimeMillis();
    app = getMyApplication();
    settings = app.getSettings();
    app.applyTheme(this);
    supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
    boolean portraitMode = AndroidUiHelper.isOrientationPortrait(this);
    boolean largeDevice = AndroidUiHelper.isXLargeDevice(this);
    landscapeLayout = !portraitMode && !largeDevice;
    mapContextMenu.setMapActivity(this);
    super.onCreate(savedInstanceState);
    // Full screen is not used here
    // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.main);
    if (Build.VERSION.SDK_INT >= 21) {
        enterToFullScreen();
        // Navigation Drawer:
        AndroidUtils.addStatusBarPadding21v(this, findViewById(R.id.menuItems));
    }
    int statusBarHeight = 0;
    int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        statusBarHeight = getResources().getDimensionPixelSize(resourceId);
    }
    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    int w = dm.widthPixels;
    int h = dm.heightPixels - statusBarHeight;
    mapView = new OsmandMapTileView(this, w, h);
    if (app.getAppInitializer().checkAppVersionChanged() && WhatsNewDialogFragment.SHOW) {
        SecondSplashScreenFragment.SHOW = false;
        WhatsNewDialogFragment.SHOW = false;
        new WhatsNewDialogFragment().show(getSupportFragmentManager(), null);
    }
    mapActions = new MapActivityActions(this);
    mapLayers = new MapActivityLayers(this);
    if (mapViewTrackingUtilities == null) {
        mapViewTrackingUtilities = new MapViewTrackingUtilities(app);
    }
    dashboardOnMap.createDashboardView();
    checkAppInitialization();
    parseLaunchIntentLocation();
    mapView.setTrackBallDelegate(new OsmandMapTileView.OnTrackBallListener() {

        @Override
        public boolean onTrackBallEvent(MotionEvent e) {
            showAndHideMapPosition();
            return MapActivity.this.onTrackballEvent(e);
        }
    });
    mapView.setAccessibilityActions(new MapAccessibilityActions(this));
    mapViewTrackingUtilities.setMapView(mapView);
    // to not let it gc
    downloaderCallback = new IMapDownloaderCallback() {

        @Override
        public void tileDownloaded(DownloadRequest request) {
            if (request != null && !request.error && request.fileToSave != null) {
                ResourceManager mgr = app.getResourceManager();
                mgr.tileDownloaded(request);
            }
            if (request == null || !request.error) {
                mapView.tileDownloaded(request);
            }
        }
    };
    app.getResourceManager().getMapTileDownloader().addDownloaderCallback(downloaderCallback);
    createProgressBarForRouting();
    mapLayers.createLayers(mapView);
    updateStatusBarColor();
    // it tries to continue the last route
    if (settings.FOLLOW_THE_ROUTE.get() && !app.getRoutingHelper().isRouteCalculated() && !app.getRoutingHelper().isRouteBeingCalculated()) {
        FailSafeFuntions.restoreRoutingMode(this);
    } else if (!app.getRoutingHelper().isRoutePlanningMode() && !settings.FOLLOW_THE_ROUTE.get() && app.getTargetPointsHelper().getAllPoints().size() > 0) {
        app.getRoutingHelper().clearCurrentRoute(null, new ArrayList<LatLon>());
        app.getTargetPointsHelper().removeAllWayPoints(false, false);
    }
    if (!settings.isLastKnownMapLocation()) {
        // show first time when application ran
        net.osmand.Location location = app.getLocationProvider().getFirstTimeRunDefaultLocation();
        mapViewTrackingUtilities.setMapLinkedToLocation(true);
        if (location != null) {
            mapView.setLatLon(location.getLatitude(), location.getLongitude());
            mapView.setIntZoom(14);
        }
    }
    addDialogProvider(mapActions);
    OsmandPlugin.onMapActivityCreate(this);
    importHelper = new ImportHelper(this, getMyApplication(), getMapView());
    wakeLockHelper = new WakeLockHelper(getMyApplication());
    if (System.currentTimeMillis() - tm > 50) {
        System.err.println("OnCreate for MapActivity took " + (System.currentTimeMillis() - tm) + " ms");
    }
    mapView.refreshMap(true);
    mapActions.updateDrawerMenu();
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
    screenOffReceiver = new ScreenOffReceiver();
    registerReceiver(screenOffReceiver, filter);
    app.getAidlApi().onCreateMapActivity(this);
    mIsDestroyed = false;
}
Also used : IntentFilter(android.content.IntentFilter) IMapDownloaderCallback(net.osmand.map.MapTileDownloader.IMapDownloaderCallback) MapViewTrackingUtilities(net.osmand.plus.base.MapViewTrackingUtilities) ArrayList(java.util.ArrayList) DownloadRequest(net.osmand.map.MapTileDownloader.DownloadRequest) WhatsNewDialogFragment(net.osmand.plus.dialogs.WhatsNewDialogFragment) ResourceManager(net.osmand.plus.resources.ResourceManager) DisplayMetrics(android.util.DisplayMetrics) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) QuadPoint(net.osmand.data.QuadPoint) NewGpxPoint(net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint) MapAccessibilityActions(net.osmand.access.MapAccessibilityActions) MotionEvent(android.view.MotionEvent) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) WakeLockHelper(net.osmand.plus.helpers.WakeLockHelper) ImportHelper(net.osmand.plus.helpers.ImportHelper) Location(net.osmand.Location)

Example 2 with MapViewTrackingUtilities

use of net.osmand.plus.base.MapViewTrackingUtilities in project Osmand by osmandapp.

the class SettingsGeneralActivity method addLocalPrefs.

private void addLocalPrefs(PreferenceGroup screen) {
    drivingRegionPreference.setTitle(R.string.driving_region);
    drivingRegionPreference.setSummary(R.string.driving_region_descr);
    drivingRegionPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            final AlertDialog.Builder b = new AlertDialog.Builder(SettingsGeneralActivity.this);
            b.setTitle(getString(R.string.driving_region));
            final List<DrivingRegion> drs = new ArrayList<>();
            drs.add(null);
            drs.addAll(Arrays.asList(DrivingRegion.values()));
            int sel = -1;
            DrivingRegion selectedDrivingRegion = settings.DRIVING_REGION.get();
            if (settings.DRIVING_REGION_AUTOMATIC.get()) {
                sel = 0;
            }
            for (int i = 1; i < drs.size(); i++) {
                if (sel == -1 && drs.get(i) == selectedDrivingRegion) {
                    sel = i;
                    break;
                }
            }
            final int selected = sel;
            final ArrayAdapter<DrivingRegion> singleChoiceAdapter = new ArrayAdapter<DrivingRegion>(SettingsGeneralActivity.this, R.layout.single_choice_description_item, R.id.text1, drs) {

                @NonNull
                @Override
                public View getView(int position, View convertView, @NonNull ViewGroup parent) {
                    View v = convertView;
                    if (v == null) {
                        LayoutInflater inflater = SettingsGeneralActivity.this.getLayoutInflater();
                        v = inflater.inflate(R.layout.single_choice_description_item, parent, false);
                    }
                    DrivingRegion item = getItem(position);
                    AppCompatCheckedTextView title = (AppCompatCheckedTextView) v.findViewById(R.id.text1);
                    TextView desc = (TextView) v.findViewById(R.id.description);
                    if (item != null) {
                        title.setText(getString(item.name));
                        desc.setVisibility(View.VISIBLE);
                        desc.setText(item.getDescription(v.getContext()));
                    } else {
                        title.setText(getString(R.string.driving_region_automatic));
                        desc.setVisibility(View.GONE);
                    }
                    title.setChecked(position == selected);
                    return v;
                }
            };
            b.setAdapter(singleChoiceAdapter, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (drs.get(which) == null) {
                        settings.DRIVING_REGION_AUTOMATIC.set(true);
                        MapViewTrackingUtilities mapViewTrackingUtilities = MapActivity.getSingleMapViewTrackingUtilities();
                        if (mapViewTrackingUtilities != null) {
                            mapViewTrackingUtilities.resetDrivingRegionUpdate();
                        }
                    } else {
                        settings.DRIVING_REGION_AUTOMATIC.set(false);
                        settings.DRIVING_REGION.set(drs.get(which));
                    }
                    updateAllSettings();
                }
            });
            b.setNegativeButton(R.string.shared_string_cancel, null);
            b.show();
            return true;
        }
    });
    String[] entries;
    String[] entrieValues;
    MetricsConstants[] mvls = MetricsConstants.values();
    entries = new String[mvls.length];
    for (int i = 0; i < entries.length; i++) {
        entries[i] = mvls[i].toHumanString(getMyApplication());
    }
    registerListPreference(settings.METRIC_SYSTEM, screen, entries, mvls);
    Integer[] cvls = new Integer[5];
    cvls[0] = PointDescription.FORMAT_DEGREES;
    cvls[1] = PointDescription.FORMAT_MINUTES;
    cvls[2] = PointDescription.FORMAT_SECONDS;
    cvls[3] = PointDescription.UTM_FORMAT;
    cvls[4] = PointDescription.OLC_FORMAT;
    entries = new String[5];
    entries[0] = PointDescription.formatToHumanString(this, PointDescription.FORMAT_DEGREES);
    entries[1] = PointDescription.formatToHumanString(this, PointDescription.FORMAT_MINUTES);
    entries[2] = PointDescription.formatToHumanString(this, PointDescription.FORMAT_SECONDS);
    entries[3] = PointDescription.formatToHumanString(this, PointDescription.UTM_FORMAT);
    entries[4] = PointDescription.formatToHumanString(this, PointDescription.OLC_FORMAT);
    registerListPreference(settings.COORDINATES_FORMAT, screen, entries, cvls);
    // See language list and statistics at: https://hosted.weblate.org/projects/osmand/main/
    // Hardy maintenance 2016-05-29:
    // - Include languages if their translation is >= ~10%    (but any language will be visible if it is the device's system locale)
    // - Mark as "incomplete" if                    < ~80%
    String incompleteSuffix = " (" + getString(R.string.incomplete_locale) + ")";
    // Add " (Device language)" to system default entry in Latin letters, so it can be more easily identified if a foreign language has been selected by mistake
    String latinSystemDefaultSuffix = " (" + getString(R.string.system_locale_no_translate) + ")";
    // getResources().getAssets().getLocales();
    entrieValues = new String[] { "", "en", "af", "ar", "ast", "az", "be", "be_BY", "bg", "ca", "cs", "cy", "da", "de", "el", "en_GB", "eo", "es", "es_AR", "es_US", "eu", "fa", "fi", "fr", "gl", "he", "hr", "hsb", "hu", "hy", "is", "it", "ja", "ka", "kab", "kn", "ko", "lt", "lv", "ml", "mr", "nb", "nl", "nn", "pl", "pt", "pt_BR", "ro", "ru", "sc", "sk", "sl", "sr", "sr+Latn", "sv", "tr", "uk", "vi", "zh_CN", "zh_TW" };
    entries = new String[] { getString(R.string.system_locale) + latinSystemDefaultSuffix, getString(R.string.lang_en), getString(R.string.lang_af) + incompleteSuffix, getString(R.string.lang_ar), getString(R.string.lang_ast) + incompleteSuffix, getString(R.string.lang_az), getString(R.string.lang_be), getString(R.string.lang_be_by), getString(R.string.lang_bg), getString(R.string.lang_ca), getString(R.string.lang_cs), getString(R.string.lang_cy) + incompleteSuffix, getString(R.string.lang_da), getString(R.string.lang_de), getString(R.string.lang_el) + incompleteSuffix, getString(R.string.lang_en_gb), getString(R.string.lang_eo), getString(R.string.lang_es), getString(R.string.lang_es_ar), getString(R.string.lang_es_us), getString(R.string.lang_eu) + incompleteSuffix, getString(R.string.lang_fa), getString(R.string.lang_fi) + incompleteSuffix, getString(R.string.lang_fr), getString(R.string.lang_gl) + incompleteSuffix, getString(R.string.lang_he) + incompleteSuffix, getString(R.string.lang_hr) + incompleteSuffix, getString(R.string.lang_hsb) + incompleteSuffix, getString(R.string.lang_hu), getString(R.string.lang_hy), getString(R.string.lang_is) + incompleteSuffix, getString(R.string.lang_it), getString(R.string.lang_ja), getString(R.string.lang_ka) + incompleteSuffix, getString(R.string.lang_kab) + incompleteSuffix, getString(R.string.lang_kn) + incompleteSuffix, getString(R.string.lang_ko), getString(R.string.lang_lt), getString(R.string.lang_lv), getString(R.string.lang_ml) + incompleteSuffix, getString(R.string.lang_mr) + incompleteSuffix, getString(R.string.lang_nb), getString(R.string.lang_nl), getString(R.string.lang_nn) + incompleteSuffix, getString(R.string.lang_pl), getString(R.string.lang_pt), getString(R.string.lang_pt_br), getString(R.string.lang_ro) + incompleteSuffix, getString(R.string.lang_ru), getString(R.string.lang_sc), getString(R.string.lang_sk), getString(R.string.lang_sl), getString(R.string.lang_sr) + incompleteSuffix, getString(R.string.lang_sr_latn) + incompleteSuffix, getString(R.string.lang_sv), getString(R.string.lang_tr), getString(R.string.lang_uk), getString(R.string.lang_vi) + incompleteSuffix, getString(R.string.lang_zh_cn) + incompleteSuffix, getString(R.string.lang_zh_tw) };
    String[] valuesPl = ConfigureMapMenu.getSortedMapNamesIds(this, entries, entries);
    String[] idsPl = ConfigureMapMenu.getSortedMapNamesIds(this, entrieValues, entries);
    registerListPreference(settings.PREFERRED_LOCALE, screen, valuesPl, idsPl);
    // Add " (Display language)" to menu title in Latin letters for all non-en languages
    if (!getResources().getString(R.string.preferred_locale).equals(getResources().getString(R.string.preferred_locale_no_translate))) {
        ((ListPreference) screen.findPreference(settings.PREFERRED_LOCALE.getId())).setTitle(getString(R.string.preferred_locale) + " (" + getString(R.string.preferred_locale_no_translate) + ")");
    }
// This setting now only in "Confgure map" menu
// String[] values = ConfigureMapMenu.getMapNamesValues(this, ConfigureMapMenu.mapNamesIds);
// String[] ids = ConfigureMapMenu.getSortedMapNamesIds(this, ConfigureMapMenu.mapNamesIds, values);
// registerListPreference(settings.MAP_PREFERRED_LOCALE, screen, ConfigureMapMenu.getMapNamesValues(this, ids), ids);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) MapViewTrackingUtilities(net.osmand.plus.base.MapViewTrackingUtilities) DrivingRegion(net.osmand.plus.OsmandSettings.DrivingRegion) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) NonNull(android.support.annotation.NonNull) List(java.util.List) ArrayList(java.util.ArrayList) AppCompatCheckedTextView(android.support.v7.widget.AppCompatCheckedTextView) TextView(android.widget.TextView) ViewGroup(android.view.ViewGroup) ListPreference(android.preference.ListPreference) AppCompatCheckedTextView(android.support.v7.widget.AppCompatCheckedTextView) View(android.view.View) TextView(android.widget.TextView) AppCompatCheckedTextView(android.support.v7.widget.AppCompatCheckedTextView) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) CheckBoxPreference(android.preference.CheckBoxPreference) Preference(android.preference.Preference) LayoutInflater(android.view.LayoutInflater) MetricsConstants(net.osmand.plus.OsmandSettings.MetricsConstants) OnClickListener(android.content.DialogInterface.OnClickListener) ArrayAdapter(android.widget.ArrayAdapter)

Example 3 with MapViewTrackingUtilities

use of net.osmand.plus.base.MapViewTrackingUtilities in project Osmand by osmandapp.

the class MapMarkerSelectionFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Bundle bundle = null;
    if (getArguments() != null) {
        bundle = getArguments();
    } else if (savedInstanceState != null) {
        bundle = savedInstanceState;
    }
    if (bundle != null) {
        target = bundle.getBoolean(TARGET_KEY);
        intermediate = bundle.getBoolean(INTERMEDIATE_KEY);
    }
    MapActivity mapActivity = getMapActivity();
    OsmandApplication app = getMyApplication();
    if (mapActivity != null) {
        MapRouteInfoMenu routeInfoMenu = mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu();
        onClickListener = routeInfoMenu.getOnMarkerSelectListener();
        screenOrientation = DashLocationFragment.getScreenOrientation(mapActivity);
        MapViewTrackingUtilities trackingUtils = mapActivity.getMapViewTrackingUtilities();
        if (trackingUtils != null) {
            Float head = trackingUtils.getHeading();
            float mapRotation = mapActivity.getMapRotate();
            LatLon mw = mapActivity.getMapLocation();
            Location l = trackingUtils.getMyLocation();
            boolean mapLinked = trackingUtils.isMapLinkedToLocation() && l != null;
            LatLon myLoc = l == null ? null : new LatLon(l.getLatitude(), l.getLongitude());
            useCenter = !mapLinked;
            loc = (useCenter ? mw : myLoc);
            if (useCenter) {
                heading = -mapRotation;
            } else {
                heading = head;
            }
        }
    }
    nightMode = !app.getSettings().isLightContent();
    View view = inflater.inflate(R.layout.map_marker_selection_fragment, container, false);
    ImageButton closeButton = (ImageButton) view.findViewById(R.id.closeButton);
    closeButton.setImageDrawable(getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_mode_back));
    closeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    ListView listView = (ListView) view.findViewById(android.R.id.list);
    final ArrayAdapter<MapMarker> adapter = new MapMarkersListAdapter();
    List<MapMarker> markers = getMyApplication().getMapMarkersHelper().getMapMarkers();
    if (markers.size() > 0) {
        for (MapMarker marker : markers) {
            adapter.add(marker);
        }
    }
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (onClickListener != null) {
                onClickListener.onSelect(position, target, intermediate);
            }
            dismiss();
        }
    });
    return view;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) Bundle(android.os.Bundle) MapViewTrackingUtilities(net.osmand.plus.base.MapViewTrackingUtilities) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) LatLon(net.osmand.data.LatLon) ImageButton(android.widget.ImageButton) MapRouteInfoMenu(net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu) ListView(android.widget.ListView) AdapterView(android.widget.AdapterView) MapActivity(net.osmand.plus.activities.MapActivity) Location(net.osmand.Location) Nullable(android.support.annotation.Nullable)

Example 4 with MapViewTrackingUtilities

use of net.osmand.plus.base.MapViewTrackingUtilities in project Osmand by osmandapp.

the class RouteInfoWidgetsFactory method createMaxSpeedControl.

public TextInfoWidget createMaxSpeedControl(final MapActivity map) {
    final RoutingHelper rh = map.getMyApplication().getRoutingHelper();
    final OsmAndLocationProvider locationProvider = map.getMyApplication().getLocationProvider();
    final MapViewTrackingUtilities trackingUtilities = map.getMapViewTrackingUtilities();
    final TextInfoWidget speedControl = new TextInfoWidget(map) {

        private float cachedSpeed = 0;

        @Override
        public boolean updateInfo(DrawSettings drawSettings) {
            float mx = 0;
            if ((rh == null || !rh.isFollowingMode() || rh.isDeviatedFromRoute() || rh.getCurrentGPXRoute() != null) && trackingUtilities.isMapLinkedToLocation()) {
                RouteDataObject ro = locationProvider.getLastKnownRouteSegment();
                if (ro != null) {
                    mx = ro.getMaximumSpeed(ro.bearingVsRouteDirection(locationProvider.getLastKnownLocation()));
                }
            } else if (rh != null) {
                mx = rh.getCurrentMaxSpeed();
            } else {
                mx = 0f;
            }
            if (cachedSpeed != mx) {
                cachedSpeed = mx;
                if (cachedSpeed == 0) {
                    setText(null, null);
                } else if (cachedSpeed == RouteDataObject.NONE_MAX_SPEED) {
                    setText(map.getString(R.string.max_speed_none), "");
                } else {
                    String ds = OsmAndFormatter.getFormattedSpeed(cachedSpeed, map.getMyApplication());
                    int ls = ds.lastIndexOf(' ');
                    if (ls == -1) {
                        setText(ds, null);
                    } else {
                        setText(ds.substring(0, ls), ds.substring(ls + 1));
                    }
                }
                return true;
            }
            return false;
        }
    };
    speedControl.setIcons(R.drawable.widget_max_speed_day, R.drawable.widget_max_speed_night);
    speedControl.setText(null, null);
    return speedControl;
}
Also used : OsmAndLocationProvider(net.osmand.plus.OsmAndLocationProvider) MapViewTrackingUtilities(net.osmand.plus.base.MapViewTrackingUtilities) RouteDataObject(net.osmand.binary.RouteDataObject) RoutingHelper(net.osmand.plus.routing.RoutingHelper) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings)

Aggregations

MapViewTrackingUtilities (net.osmand.plus.base.MapViewTrackingUtilities)4 View (android.view.View)2 ArrayList (java.util.ArrayList)2 Location (net.osmand.Location)2 DialogInterface (android.content.DialogInterface)1 OnClickListener (android.content.DialogInterface.OnClickListener)1 IntentFilter (android.content.IntentFilter)1 Bundle (android.os.Bundle)1 CheckBoxPreference (android.preference.CheckBoxPreference)1 EditTextPreference (android.preference.EditTextPreference)1 ListPreference (android.preference.ListPreference)1 Preference (android.preference.Preference)1 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 AlertDialog (android.support.v7.app.AlertDialog)1 AppCompatCheckedTextView (android.support.v7.widget.AppCompatCheckedTextView)1 DisplayMetrics (android.util.DisplayMetrics)1 LayoutInflater (android.view.LayoutInflater)1 MotionEvent (android.view.MotionEvent)1