Added AV widget customization to configure screen
This commit is contained in:
parent
e764ae41cc
commit
8cf98181da
3 changed files with 147 additions and 40 deletions
|
@ -10,7 +10,8 @@
|
|||
<group
|
||||
android:id="@+id/button_group"
|
||||
android:orderInCategory="2"
|
||||
android:checkableBehavior="none">
|
||||
android:checkableBehavior="none"
|
||||
android:menuCategory="container">
|
||||
<item
|
||||
android:id="@+id/action_show"
|
||||
android:icon="@drawable/ic_action_view"
|
||||
|
|
|
@ -11,5 +11,10 @@
|
|||
<!-- Compass control widget ids-->
|
||||
<item name="compass_ruler_control_widget_state_show" type="id"/>
|
||||
<item name="compass_ruler_control_widget_state_hide" type="id"/>
|
||||
<!-- AV notes widget ids-->
|
||||
<item name="av_notes_widget_state_ask" type="id"/>
|
||||
<item name="av_notes_widget_state_audio" type="id"/>
|
||||
<item name="av_notes_widget_state_video" type="id"/>
|
||||
<item name="av_notes_widget_state_photo" type="id"/>
|
||||
|
||||
</resources>
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue