Search in sources :

Example 1 with LocalIndexInfo

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

the class ItemViewHolder method contextMenu.

protected void contextMenu(View v, final IndexItem indexItem, final DownloadResourceGroup parentOptional) {
    final PopupMenu optionsMenu = new PopupMenu(context, v);
    MenuItem item;
    final File fl = indexItem.getTargetFile(context.getMyApplication());
    if (fl.exists()) {
        item = optionsMenu.getMenu().add(R.string.shared_string_remove).setIcon(context.getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_remove_dark));
        item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

            @Override
            public boolean onMenuItemClick(MenuItem item) {
                LocalIndexType tp = LocalIndexType.MAP_DATA;
                if (indexItem.getType() == DownloadActivityType.HILLSHADE_FILE) {
                    tp = LocalIndexType.TILES_DATA;
                } else if (indexItem.getType() == DownloadActivityType.ROADS_FILE) {
                    tp = LocalIndexType.MAP_DATA;
                } else if (indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) {
                    tp = LocalIndexType.SRTM_DATA;
                } else if (indexItem.getType() == DownloadActivityType.WIKIPEDIA_FILE) {
                    tp = LocalIndexType.MAP_DATA;
                } else if (indexItem.getType() == DownloadActivityType.FONT_FILE) {
                    tp = LocalIndexType.FONT_DATA;
                } else if (indexItem.getType() == DownloadActivityType.VOICE_FILE) {
                    tp = indexItem.getBasename().contains("tts") ? LocalIndexType.TTS_VOICE_DATA : LocalIndexType.VOICE_DATA;
                }
                final LocalIndexInfo info = new LocalIndexInfo(tp, fl, false, context.getMyApplication());
                AlertDialog.Builder confirm = new AlertDialog.Builder(context);
                confirm.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        new LocalIndexOperationTask(context, null, LocalIndexOperationTask.DELETE_OPERATION).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, info);
                    }
                });
                confirm.setNegativeButton(R.string.shared_string_no, null);
                String fn = FileNameTranslationHelper.getFileName(context, context.getMyApplication().getRegions(), indexItem.getVisibleName(context, context.getMyApplication().getRegions()));
                confirm.setMessage(context.getString(R.string.delete_confirmation_msg, fn));
                confirm.show();
                return true;
            }
        });
    }
    item = optionsMenu.getMenu().add(R.string.shared_string_download).setIcon(context.getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_import));
    item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            download(indexItem, parentOptional);
            return true;
        }
    });
    optionsMenu.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) LocalIndexOperationTask(net.osmand.plus.download.ui.LocalIndexesFragment.LocalIndexOperationTask) MenuItem(android.view.MenuItem) LocalIndexType(net.osmand.plus.activities.LocalIndexHelper.LocalIndexType) OnClickListener(android.view.View.OnClickListener) LocalIndexInfo(net.osmand.plus.activities.LocalIndexInfo) File(java.io.File) PopupMenu(android.support.v7.widget.PopupMenu)

Example 2 with LocalIndexInfo

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

the class DownloadedRegionsLayer method getWorldRegionFromPoint.

private void getWorldRegionFromPoint(RotatedTileBox tb, PointF point, List<? super DownloadMapObject> dataObjects) {
    int zoom = tb.getZoom();
    if (zoom >= ZOOM_TO_SHOW_SELECTION_ST && zoom < ZOOM_TO_SHOW_SELECTION && data.results != null && osmandRegions.isInitialized()) {
        LatLon pointLatLon = tb.getLatLonFromPixel(point.x, point.y);
        int point31x = MapUtils.get31TileNumberX(pointLatLon.getLongitude());
        int point31y = MapUtils.get31TileNumberY(pointLatLon.getLatitude());
        List<BinaryMapDataObject> result = new LinkedList<>(data.results);
        Iterator<BinaryMapDataObject> it = result.iterator();
        while (it.hasNext()) {
            BinaryMapDataObject o = it.next();
            boolean isRegion = true;
            for (int i = 0; i < o.getTypes().length; i++) {
                TagValuePair tp = o.getMapIndex().decodeType(o.getTypes()[i]);
                if ("boundary".equals(tp.value)) {
                    isRegion = false;
                    break;
                }
            }
            if (!isRegion || !osmandRegions.contain(o, point31x, point31y)) {
                it.remove();
            }
        }
        OsmandRegions osmandRegions = app.getRegions();
        for (BinaryMapDataObject o : result) {
            String fullName = osmandRegions.getFullName(o);
            WorldRegion region = osmandRegions.getRegionData(fullName);
            if (region != null && region.isRegionMapDownload()) {
                List<IndexItem> indexItems = app.getDownloadThread().getIndexes().getIndexItems(region);
                List<IndexItem> dataItems = new LinkedList<>();
                IndexItem regularMapItem = null;
                for (IndexItem item : indexItems) {
                    if (item.isDownloaded() || app.getDownloadThread().isDownloading(item)) {
                        dataItems.add(item);
                        if (item.getType() == DownloadActivityType.NORMAL_FILE) {
                            regularMapItem = item;
                        }
                    }
                }
                if (dataItems.isEmpty() && regularMapItem != null) {
                    dataItems.add(regularMapItem);
                }
                if (!dataItems.isEmpty()) {
                    for (IndexItem item : dataItems) {
                        dataObjects.add(new DownloadMapObject(o, region, item, null));
                    }
                } else {
                    String downloadName = osmandRegions.getDownloadName(o);
                    List<LocalIndexInfo> infos = helper.getLocalIndexInfos(downloadName);
                    if (infos.size() == 0) {
                        dataObjects.add(new DownloadMapObject(o, region, null, null));
                    } else {
                        for (LocalIndexInfo info : infos) {
                            dataObjects.add(new DownloadMapObject(o, region, null, info));
                        }
                    }
                }
            }
        }
    }
}
Also used : WorldRegion(net.osmand.map.WorldRegion) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) LinkedList(java.util.LinkedList) IndexItem(net.osmand.plus.download.IndexItem) LatLon(net.osmand.data.LatLon) OsmandRegions(net.osmand.map.OsmandRegions) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) TagValuePair(net.osmand.binary.BinaryMapIndexReader.TagValuePair) LocalIndexInfo(net.osmand.plus.activities.LocalIndexInfo)

Example 3 with LocalIndexInfo

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

the class LocalIndexesFragment method onChildClick.

@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
    LocalIndexInfo child = listAdapter.getChild(groupPosition, childPosition);
    if (!selectionMode) {
        openPopUpMenu(v, child);
        return true;
    }
    selectedItems.add(child);
    listAdapter.notifyDataSetChanged();
    return true;
}
Also used : LocalIndexInfo(net.osmand.plus.activities.LocalIndexInfo)

Example 4 with LocalIndexInfo

use of net.osmand.plus.activities.LocalIndexInfo 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)

Example 5 with LocalIndexInfo

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

the class MapDataMenuController method restoreFromBackup.

public void restoreFromBackup() {
    final OsmandApplication app = getMapActivity().getMyApplication();
    new AsyncTask<Void, Void, Void>() {

        @Override
        protected void onPreExecute() {
            getMapActivity().getContextMenu().close();
        }

        @Override
        protected Void doInBackground(Void... params) {
            if (localIndexInfo != null) {
                LocalIndexInfo info = localIndexInfo;
                move(new File(info.getPathToData()), getFileToRestore(info));
                app.getResourceManager().reloadIndexes(IProgress.EMPTY_PROGRESS, new ArrayList<String>());
                app.getDownloadThread().updateLoadedFiles();
            } else if (indexItem != null) {
                move(indexItem.getBackupFile(app), indexItem.getTargetFile(app));
                app.getResourceManager().reloadIndexes(IProgress.EMPTY_PROGRESS, new ArrayList<String>());
                app.getDownloadThread().updateLoadedFiles();
            }
            return null;
        }

        protected void onPostExecute(Void result) {
            getMapActivity().refreshMap();
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) ArrayList(java.util.ArrayList) LocalIndexInfo(net.osmand.plus.activities.LocalIndexInfo) File(java.io.File)

Aggregations

LocalIndexInfo (net.osmand.plus.activities.LocalIndexInfo)6 MenuItem (android.view.MenuItem)2 File (java.io.File)2 SuppressLint (android.annotation.SuppressLint)1 AlarmManager (android.app.AlarmManager)1 PendingIntent (android.app.PendingIntent)1 DialogInterface (android.content.DialogInterface)1 Paint (android.graphics.Paint)1 ActionBar (android.support.v7.app.ActionBar)1 AlertDialog (android.support.v7.app.AlertDialog)1 PopupMenu (android.support.v7.widget.PopupMenu)1 TextPaint (android.text.TextPaint)1 SubMenu (android.view.SubMenu)1 OnClickListener (android.view.View.OnClickListener)1 ArrayAdapter (android.widget.ArrayAdapter)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)1 TagValuePair (net.osmand.binary.BinaryMapIndexReader.TagValuePair)1 LatLon (net.osmand.data.LatLon)1