Search in sources :

Example 1 with LocalIndexHelper

use of net.osmand.plus.activities.LocalIndexHelper in project Osmand by osmandapp.

the class DownloadedRegionsLayer method initLayer.

@Override
public void initLayer(final OsmandMapTileView view) {
    this.view = view;
    app = view.getApplication();
    rm = app.getResourceManager();
    osmandRegions = rm.getOsmandRegions();
    helper = new LocalIndexHelper(app);
    paintDownloaded = getPaint(view.getResources().getColor(R.color.region_uptodate));
    paintSelected = getPaint(view.getResources().getColor(R.color.region_selected));
    paintBackuped = getPaint(view.getResources().getColor(R.color.region_backuped));
    textPaint = new TextPaint();
    final WindowManager wmgr = (WindowManager) view.getApplication().getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics dm = new DisplayMetrics();
    wmgr.getDefaultDisplay().getMetrics(dm);
    textPaint.setStrokeWidth(21 * dm.scaledDensity);
    textPaint.setAntiAlias(true);
    textPaint.setTextAlign(Paint.Align.CENTER);
    pathDownloaded = new Path();
    pathSelected = new Path();
    pathBackuped = new Path();
    data = new MapLayerData<List<BinaryMapDataObject>>() {

        @Override
        public void layerOnPostExecute() {
            view.refreshMap();
        }

        public boolean queriedBoxContains(final RotatedTileBox queriedData, final RotatedTileBox newBox) {
            if (newBox.getZoom() < ZOOM_TO_SHOW_SELECTION) {
                if (queriedData != null && queriedData.getZoom() < ZOOM_TO_SHOW_SELECTION) {
                    return queriedData.containsTileBox(newBox);
                } else {
                    return false;
                }
            }
            List<BinaryMapDataObject> queriedResults = getResults();
            if (queriedData != null && queriedData.containsTileBox(newBox) && queriedData.getZoom() >= ZOOM_TO_SHOW_MAP_NAMES) {
                if (queriedResults != null && (queriedResults.isEmpty() || Math.abs(queriedData.getZoom() - newBox.getZoom()) <= 1)) {
                    return true;
                }
            }
            return false;
        }

        @Override
        protected List<BinaryMapDataObject> calculateResult(RotatedTileBox tileBox) {
            return queryData(tileBox);
        }
    };
}
Also used : Path(android.graphics.Path) RotatedTileBox(net.osmand.data.RotatedTileBox) LocalIndexHelper(net.osmand.plus.activities.LocalIndexHelper) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) DisplayMetrics(android.util.DisplayMetrics) TextPaint(android.text.TextPaint) WindowManager(android.view.WindowManager)

Example 2 with LocalIndexHelper

use of net.osmand.plus.activities.LocalIndexHelper in project Osmand by osmandapp.

the class AppInitializer method checkLiveUpdatesAlerts.

private void checkLiveUpdatesAlerts() {
    OsmandSettings settings = app.getSettings();
    if (!settings.IS_LIVE_UPDATES_ON.get()) {
        return;
    }
    LocalIndexHelper helper = new LocalIndexHelper(app);
    List<LocalIndexInfo> fullMaps = helper.getLocalFullMaps(new AbstractLoadLocalIndexTask() {

        @Override
        public void loadFile(LocalIndexInfo... loaded) {
        }
    });
    AlarmManager alarmMgr = (AlarmManager) app.getSystemService(Context.ALARM_SERVICE);
    for (LocalIndexInfo fm : fullMaps) {
        String fileName = fm.getFileName();
        if (!preferenceLiveUpdatesOn(fileName, settings).get()) {
            continue;
        }
        int updateFrequencyOrd = preferenceUpdateFrequency(fileName, settings).get();
        LiveUpdatesHelper.UpdateFrequency updateFrequency = LiveUpdatesHelper.UpdateFrequency.values()[updateFrequencyOrd];
        long lastCheck = preferenceLastCheck(fileName, settings).get();
        if (System.currentTimeMillis() - lastCheck > updateFrequency.getTime() * 2) {
            runLiveUpdate(app, fileName, false);
            PendingIntent alarmIntent = getPendingIntent(app, fileName);
            int timeOfDayOrd = preferenceTimeOfDayToUpdate(fileName, settings).get();
            LiveUpdatesHelper.TimeOfDay timeOfDayToUpdate = LiveUpdatesHelper.TimeOfDay.values()[timeOfDayOrd];
            setAlarmForPendingIntent(alarmIntent, alarmMgr, updateFrequency, timeOfDayToUpdate);
        }
    }
}
Also used : LiveUpdatesHelper(net.osmand.plus.liveupdates.LiveUpdatesHelper) SuppressLint(android.annotation.SuppressLint) AbstractLoadLocalIndexTask(net.osmand.plus.download.ui.AbstractLoadLocalIndexTask) AlarmManager(android.app.AlarmManager) LocalIndexHelper(net.osmand.plus.activities.LocalIndexHelper) PendingIntent(android.app.PendingIntent) LiveUpdatesHelper.getPendingIntent(net.osmand.plus.liveupdates.LiveUpdatesHelper.getPendingIntent) LiveUpdatesHelper.setAlarmForPendingIntent(net.osmand.plus.liveupdates.LiveUpdatesHelper.setAlarmForPendingIntent) LocalIndexInfo(net.osmand.plus.activities.LocalIndexInfo)

Aggregations

LocalIndexHelper (net.osmand.plus.activities.LocalIndexHelper)2 SuppressLint (android.annotation.SuppressLint)1 AlarmManager (android.app.AlarmManager)1 PendingIntent (android.app.PendingIntent)1 Path (android.graphics.Path)1 TextPaint (android.text.TextPaint)1 DisplayMetrics (android.util.DisplayMetrics)1 WindowManager (android.view.WindowManager)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 RotatedTileBox (net.osmand.data.RotatedTileBox)1 LocalIndexInfo (net.osmand.plus.activities.LocalIndexInfo)1 AbstractLoadLocalIndexTask (net.osmand.plus.download.ui.AbstractLoadLocalIndexTask)1 LiveUpdatesHelper (net.osmand.plus.liveupdates.LiveUpdatesHelper)1 LiveUpdatesHelper.getPendingIntent (net.osmand.plus.liveupdates.LiveUpdatesHelper.getPendingIntent)1 LiveUpdatesHelper.setAlarmForPendingIntent (net.osmand.plus.liveupdates.LiveUpdatesHelper.setAlarmForPendingIntent)1