From 8cf98181da9f60b4cea43a408d48006a2ce58fa1 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Mon, 17 Feb 2020 19:22:35 +0300 Subject: [PATCH] Added AV widget customization to configure screen --- OsmAnd/res/menu/widget_visibility_menu.xml | 3 +- OsmAnd/res/values/ids.xml | 5 + .../audionotes/AudioVideoNotesPlugin.java | 179 ++++++++++++++---- 3 files changed, 147 insertions(+), 40 deletions(-) diff --git a/OsmAnd/res/menu/widget_visibility_menu.xml b/OsmAnd/res/menu/widget_visibility_menu.xml index ee110585a9..c81c3b4018 100644 --- a/OsmAnd/res/menu/widget_visibility_menu.xml +++ b/OsmAnd/res/menu/widget_visibility_menu.xml @@ -10,7 +10,8 @@ + android:checkableBehavior="none" + android:menuCategory="container"> + + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index 4b08add243..f957ddb0e8 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -65,7 +65,9 @@ import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.settings.BaseSettingsFragment; import net.osmand.plus.views.MapInfoLayer; +import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapTileView; +import net.osmand.plus.views.mapwidgets.MapWidgetRegistry; import net.osmand.plus.views.mapwidgets.TextInfoWidget; import net.osmand.util.Algorithms; import net.osmand.util.GeoPointParserUtil.GeoParsedPoint; @@ -721,34 +723,58 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } } - private void registerWidget(MapActivity activity) { + private void registerWidget(final MapActivity activity) { MapInfoLayer mapInfoLayer = activity.getMapLayers().getMapInfoLayer(); if (mapInfoLayer != null) { - recordControl = new TextInfoWidget(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, 32); + recordControl = new TextInfoWidget(activity) { + + private Boolean cachedRecording; + + @Override + public boolean updateInfo(DrawSettings drawSettings) { + boolean recording = isRecording(); + if (!Algorithms.objectEquals(recording, cachedRecording)) { + cachedRecording = recording; + if (recording) { + setText(app.getString(R.string.shared_string_control_stop), null); + setIcons(R.drawable.widget_icon_av_active, R.drawable.widget_icon_av_active); + } else { + setText(app.getString(R.string.shared_string_control_start), null); + Integer action = AV_DEFAULT_ACTION.get(); + switch (action) { + case AV_DEFAULT_ACTION_VIDEO: + setIcons(R.drawable.widget_av_video_day, R.drawable.widget_av_video_night); + break; + case AV_DEFAULT_ACTION_TAKEPICTURE: + setIcons(R.drawable.widget_av_photo_day, R.drawable.widget_av_photo_night); + break; + case AV_DEFAULT_ACTION_AUDIO: + setIcons(R.drawable.widget_av_audio_day, R.drawable.widget_av_audio_night); + break; + default: + setIcons(R.drawable.widget_icon_av_inactive_day, R.drawable.widget_icon_av_inactive_night); + break; + } + } + } + return false; + }; + }; + recordControl.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (isRecording()) { + stopRecording(mapActivity, false); + } else { + defaultAction(mapActivity); + } + } + }); + mapInfoLayer.registerSideWidget(recordControl, new AudioVideoNotesWidgetState(app), "audionotes", false, 32); mapInfoLayer.recreateControls(); } } - private void setRecordListener(final TextInfoWidget recordPlaceControl, final MapActivity mapActivity) { - recordPlaceControl.setText(app.getString(R.string.shared_string_control_start), ""); - updateWidgetIcon(recordPlaceControl); - recordPlaceControl.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View v) { - defaultAction(mapActivity); - } - }); - } - private void updateWidgetIcon(final TextInfoWidget recordPlaceControl) { recordPlaceControl.setIcons(R.drawable.widget_icon_av_inactive_day, R.drawable.widget_icon_av_inactive_night); @@ -1591,18 +1617,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { mediaRecFile = f; recordingMenu.show(); - updateRecordControl(mapActivity, f); - } - - private void updateRecordControl(final MapActivity mapActivity, final File f) { - recordControl.setText(app.getString(R.string.shared_string_control_stop), ""); - recordControl.setIcons(R.drawable.widget_icon_av_active, R.drawable.widget_icon_av_active); - recordControl.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - stopRecording(mapActivity, false); - } - }); + mapActivity.refreshMap(); } public void stopRecording(final MapActivity mapActivity, boolean restart) { @@ -1610,12 +1625,8 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { if (!restart || !stopMediaRecording(true)) { recordingDone = true; stopMediaRecording(false); - if (recordControl != null) { - setRecordListener(recordControl, mapActivity); - } SHOW_RECORDINGS.set(true); - mapActivity.getMapView().refreshMap(); - updateWidgetIcon(recordControl); + mapActivity.refreshMap(); closeRecordingMenu(); } } @@ -2112,4 +2123,94 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { public DashFragmentData getCardFragment() { return DashAudioVideoNotesFragment.FRAGMENT_DATA; } + + public class AudioVideoNotesWidgetState extends MapWidgetRegistry.WidgetState { + + private static final int AV_WIDGET_STATE_ASK = R.id.av_notes_widget_state_ask; + private static final int AV_WIDGET_STATE_AUDIO = R.id.av_notes_widget_state_audio; + private static final int AV_WIDGET_STATE_VIDEO = R.id.av_notes_widget_state_video; + private static final int AV_WIDGET_STATE_PHOTO = R.id.av_notes_widget_state_photo; + + AudioVideoNotesWidgetState(OsmandApplication ctx) { + super(ctx); + } + + @Override + public int getMenuTitleId() { + Integer action = AV_DEFAULT_ACTION.get(); + switch (action) { + case AV_DEFAULT_ACTION_AUDIO: + return R.string.av_def_action_audio; + case AV_DEFAULT_ACTION_VIDEO: + return R.string.av_def_action_video; + case AV_DEFAULT_ACTION_TAKEPICTURE: + return R.string.av_def_action_picture; + default: + return R.string.map_widget_av_notes; + } + } + + @Override + public int getMenuIconId() { + Integer action = AV_DEFAULT_ACTION.get(); + switch (action) { + case AV_DEFAULT_ACTION_AUDIO: + return R.drawable.ic_action_micro_dark; + case AV_DEFAULT_ACTION_VIDEO: + return R.drawable.ic_action_video_dark; + case AV_DEFAULT_ACTION_TAKEPICTURE: + return R.drawable.ic_action_photo_dark; + default: + return R.drawable.ic_action_photo_dark; + } + } + + @Override + public int getMenuItemId() { + Integer action = AV_DEFAULT_ACTION.get(); + switch (action) { + case AV_DEFAULT_ACTION_AUDIO: + return AV_WIDGET_STATE_AUDIO; + case AV_DEFAULT_ACTION_VIDEO: + return AV_WIDGET_STATE_VIDEO; + case AV_DEFAULT_ACTION_TAKEPICTURE: + return AV_WIDGET_STATE_PHOTO; + default: + return AV_WIDGET_STATE_ASK; + } + } + + @Override + public int[] getMenuTitleIds() { + return new int[]{R.string.av_def_action_choose, R.string.av_def_action_audio, R.string.av_def_action_video, R.string.av_def_action_picture}; + } + + @Override + public int[] getMenuIconIds() { + return new int[]{R.drawable.ic_action_photo_dark, R.drawable.ic_action_micro_dark, R.drawable.ic_action_video_dark, R.drawable.ic_action_photo_dark}; + } + + @Override + public int[] getMenuItemIds() { + return new int[]{AV_WIDGET_STATE_ASK, AV_WIDGET_STATE_AUDIO, AV_WIDGET_STATE_VIDEO, AV_WIDGET_STATE_PHOTO}; + } + + @Override + public void changeState(int stateId) { + switch (stateId) { + case AV_WIDGET_STATE_AUDIO: + AV_DEFAULT_ACTION.set(AV_DEFAULT_ACTION_AUDIO); + break; + case AV_WIDGET_STATE_VIDEO: + AV_DEFAULT_ACTION.set(AV_DEFAULT_ACTION_VIDEO); + break; + case AV_WIDGET_STATE_PHOTO: + AV_DEFAULT_ACTION.set(AV_DEFAULT_ACTION_TAKEPICTURE); + break; + default: + AV_DEFAULT_ACTION.set(AV_DEFAULT_ACTION_CHOOSE); + break; + } + } + } }