This commit is contained in:
GaidamakUA 2015-11-10 15:37:41 +02:00
commit e16f0d284c
8 changed files with 53 additions and 13 deletions

View file

@ -208,6 +208,9 @@ public abstract class OsmandPlugin {
public void mapActivityDestroy(MapActivity activity) {
}
public void mapActivityScreenOff(MapActivity activity) {
}
public boolean destinationReached() {
return true;
}
@ -341,6 +344,11 @@ public abstract class OsmandPlugin {
}
}
public static void onMapActivityScreenOff(MapActivity activity) {
for (OsmandPlugin plugin : getEnabledPlugins()) {
plugin.mapActivityScreenOff(activity);
}
}
public static boolean onDestinationReached() {
boolean b = true;

View file

@ -4,8 +4,10 @@ import android.app.Dialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioManager;
import android.net.Uri;
import android.os.AsyncTask;
@ -104,6 +106,8 @@ public class MapActivity extends AccessibleActivity implements DownloadEvents {
private static MapContextMenu mapContextMenu = new MapContextMenu();
private static MapMultiSelectionMenu mapMultiSelectionMenu;
private BroadcastReceiver screenOffReceiver;
/**
* Called when the activity is first created.
*/
@ -250,6 +254,10 @@ public class MapActivity extends AccessibleActivity implements DownloadEvents {
}
mapActions.updateDrawerMenu();
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
screenOffReceiver = new ScreenOffReceiver();
registerReceiver(screenOffReceiver, filter);
}
@ -671,6 +679,7 @@ public class MapActivity extends AccessibleActivity implements DownloadEvents {
@Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(screenOffReceiver);
FailSafeFuntions.quitRouteRestoreDialog();
OsmandPlugin.onMapActivityDestroy(this);
getMyApplication().unsubscribeInitListener(initListener);
@ -1064,4 +1073,13 @@ public class MapActivity extends AccessibleActivity implements DownloadEvents {
refreshMap();
}
}
private class ScreenOffReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
OsmandPlugin.onMapActivityScreenOff(MapActivity.this);
}
}
}

View file

@ -135,7 +135,8 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
private Map<String, Recording> recordingByFileName = new LinkedHashMap<>();
private AudioNotesLayer audioNotesLayer;
private MapActivity activity;
private MediaRecorder mediaRec;
private static File mediaRecFile;
private static MediaRecorder mediaRec;
private File lastTakingPhoto;
private final static char SPLIT_DESC = ' ';
@ -590,8 +591,12 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
MapInfoLayer mapInfoLayer = activity.getMapLayers().getMapInfoLayer();
if (mapInfoLayer != null) {
recordControl = new TextInfoWidget(activity);
recordControl.setImageDrawable(activity.getResources().getDrawable(R.drawable.monitoring_rec_inactive));
setRecordListener(recordControl, activity);
if (mediaRec != null && mediaRecFile != null) {
updateRecordControl(activity, mediaRecFile);
} else {
recordControl.setImageDrawable(activity.getResources().getDrawable(R.drawable.monitoring_rec_inactive));
setRecordListener(recordControl, activity);
}
mapInfoLayer.registerSideWidget(recordControl, R.drawable.ic_action_micro_dark,
R.string.map_widget_av_notes, "audionotes", false, 22);
mapInfoLayer.recreateControls();
@ -705,8 +710,9 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
mapActivity.startActivityForResult(intent, 205);
}
@Override
public void mapActivityPause(MapActivity activity) {
public void mapActivityScreenOff(MapActivity activity) {
stopRecording(activity);
}
@ -814,6 +820,8 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
mediaRec.stop();
mediaRec.release();
mediaRec = null;
indexFile(true, mediaRecFile);
mediaRecFile = null;
}
if (recordControl != null) {
setRecordListener(recordControl, mapActivity);
@ -1020,6 +1028,12 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
mr.prepare();
mr.start();
mediaRec = mr;
mediaRecFile = f;
updateRecordControl(mapActivity, f);
}
private void updateRecordControl(final MapActivity mapActivity, final File f) {
recordControl.setText(app.getString(R.string.shared_string_control_stop), "");
recordControl.setImageDrawable(activity.getResources().getDrawable(R.drawable.widget_icon_av_active));
final MapInfoLayer mil = mapActivity.getMapLayers().getMapInfoLayer();
@ -1039,7 +1053,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
}
stopRecording(mapActivity);
SHOW_RECORDINGS.set(true);
indexFile(true, f);
mapActivity.getMapView().refreshMap();
updateWidgetIcon(recordControl);
}

View file

@ -45,6 +45,9 @@ public class MapContextMenu extends MenuTitleController {
this.mapActivity = mapActivity;
if (active) {
acquireMenuController();
if (menuController != null) {
menuController.addPlainMenuItems(typeStr, this.pointDescription, this.latLon);
}
} else {
menuController = null;
}

View file

@ -34,7 +34,7 @@ public class EditPOIMenuController extends MenuController {
private String pointTypeStr;
private ProgressDialogPoiUploader poiUploader;
public EditPOIMenuController(OsmandApplication app, final MapActivity mapActivity, PointDescription pointDescription, final OsmPoint osmPoint) {
public EditPOIMenuController(OsmandApplication app, MapActivity mapActivity, PointDescription pointDescription, final OsmPoint osmPoint) {
super(new EditPOIMenuBuilder(app, osmPoint), pointDescription, mapActivity);
plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
@ -74,7 +74,7 @@ public class EditPOIMenuController extends MenuController {
if (plugin != null) {
SendPoiDialogFragment sendPoiDialogFragment = SendPoiDialogFragment.createInstance(new OsmPoint[]{osmPoint});
sendPoiDialogFragment.setPoiUploader(poiUploader);
sendPoiDialogFragment.show(mapActivity.getSupportFragmentManager(), SendPoiDialogFragment.TAG);
sendPoiDialogFragment.show(getMapActivity().getSupportFragmentManager(), SendPoiDialogFragment.TAG);
}
}
};

View file

@ -36,15 +36,13 @@ public class MapDataMenuController extends MenuController {
private IndexItem indexItem;
private List<IndexItem> otherIndexItems;
private DownloadValidationManager downloadValidationManager;
private DownloadIndexesThread downloadThread;
public MapDataMenuController(final OsmandApplication app, final MapActivity mapActivity, PointDescription pointDescription, final BinaryMapDataObject dataObject) {
public MapDataMenuController(OsmandApplication app, MapActivity mapActivity, PointDescription pointDescription, final BinaryMapDataObject dataObject) {
super(new MenuBuilder(app), pointDescription, mapActivity);
OsmandRegions osmandRegions = app.getRegions();
String fullName = osmandRegions.getFullName(dataObject);
this.region = osmandRegions.getRegionData(fullName);
downloadValidationManager = new DownloadValidationManager(app);
downloadThread = app.getDownloadThread();
mapActivity.getSupportFragmentManager();
@ -52,7 +50,8 @@ public class MapDataMenuController extends MenuController {
@Override
public void buttonPressed() {
if (indexItem != null) {
downloadValidationManager.startDownload(mapActivity, indexItem);
new DownloadValidationManager(getMapActivity().getMyApplication())
.startDownload(getMapActivity(), indexItem);
}
}
};

View file

@ -18,7 +18,7 @@ public class OsmBugMenuController extends MenuController {
private OsmEditingPlugin plugin;
private OpenStreetNote bug;
public OsmBugMenuController(OsmandApplication app, final MapActivity mapActivity, PointDescription pointDescription, final OpenStreetNote bug) {
public OsmBugMenuController(OsmandApplication app, MapActivity mapActivity, PointDescription pointDescription, final OpenStreetNote bug) {
super(new MenuBuilder(app), pointDescription, mapActivity);
plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
this.bug = bug;

View file

@ -1,7 +1,6 @@
package net.osmand.plus.mapcontextmenu.controllers;
import android.graphics.drawable.Drawable;
import android.util.Log;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandApplication;