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();
}
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));
}
}
}
}
}
}
}
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;
}
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);
}
}
}
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);
}
Aggregations