Feature request (Quick action: Day/night mode #6330 )
This commit is contained in:
parent
5c94138b93
commit
713a3b9d4b
4 changed files with 98 additions and 1 deletions
|
@ -2886,6 +2886,10 @@
|
|||
<string name="quick_action_add_poi_descr">Tapping this action button adds a POI in the middle of the screen.</string>
|
||||
<string name="quick_action_navigation_voice_descr">Tapping this action button disables or enables voice guidance during navigation.</string>
|
||||
<string name="quick_action_add_parking_descr">Tapping this action button adds a parking location in the middle of the screen.</string>
|
||||
<string name="quick_action_switch_day_night_descr">Tapping this action button switch between Day and Night modes for OsmAnd</string>
|
||||
<string name="quick_action_switch_day_mode">Day Mode</string>
|
||||
<string name="quick_action_switch_night_mode">Night Mode</string>
|
||||
<string name="quick_action_day_night_switch_mode">Switch Day/Night mode</string>
|
||||
<string name="quick_action_interim_dialog">Show an interim dialog</string>
|
||||
<string name="favorite_autofill_toast_text">" is saved to "</string>
|
||||
<string name="favorite_empty_place_name">Place</string>
|
||||
|
|
|
@ -35,6 +35,7 @@ import net.osmand.plus.quickaction.actions.NewAction;
|
|||
import net.osmand.plus.quickaction.actions.ShowHideFavoritesAction;
|
||||
import net.osmand.plus.quickaction.actions.ShowHideOSMBugAction;
|
||||
import net.osmand.plus.quickaction.actions.ShowHidePoiAction;
|
||||
import net.osmand.plus.quickaction.actions.DayNightModeAction;
|
||||
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
@ -116,6 +117,9 @@ public class QuickActionFactory {
|
|||
quickActions.add(new MapUnderlayAction());
|
||||
}
|
||||
|
||||
quickActions.add(new DayNightModeAction());
|
||||
|
||||
|
||||
QuickAction voice = new NavVoiceAction();
|
||||
QuickAction addDestination = new NavAddDestinationAction();
|
||||
QuickAction addFirstIntermediate = new NavAddFirstIntermediateAction();
|
||||
|
@ -232,6 +236,9 @@ public class QuickActionFactory {
|
|||
case NavResumePauseAction.TYPE:
|
||||
return new NavResumePauseAction();
|
||||
|
||||
case DayNightModeAction.TYPE:
|
||||
return new DayNightModeAction();
|
||||
|
||||
default:
|
||||
return new QuickAction();
|
||||
}
|
||||
|
@ -313,6 +320,9 @@ public class QuickActionFactory {
|
|||
case NavResumePauseAction.TYPE:
|
||||
return new NavResumePauseAction(quickAction);
|
||||
|
||||
case DayNightModeAction.TYPE:
|
||||
return new DayNightModeAction(quickAction);
|
||||
|
||||
default:
|
||||
return quickAction;
|
||||
}
|
||||
|
@ -394,6 +404,9 @@ public class QuickActionFactory {
|
|||
case NavResumePauseAction.TYPE:
|
||||
return R.drawable.ic_play_dark;
|
||||
|
||||
case DayNightModeAction.TYPE:
|
||||
return R.drawable.ic_action_map_day;
|
||||
|
||||
default:
|
||||
return R.drawable.ic_action_plus;
|
||||
}
|
||||
|
@ -457,6 +470,9 @@ public class QuickActionFactory {
|
|||
case MapUnderlayAction.TYPE:
|
||||
return R.string.quick_action_map_underlay;
|
||||
|
||||
case DayNightModeAction.TYPE:
|
||||
return R.string.quick_action_day_night_switch_mode;
|
||||
|
||||
case NavAddDestinationAction.TYPE:
|
||||
return R.string.quick_action_add_destination;
|
||||
|
||||
|
@ -500,6 +516,7 @@ public class QuickActionFactory {
|
|||
case ShowHideOSMBugAction.TYPE:
|
||||
case NavStartStopAction.TYPE:
|
||||
case NavResumePauseAction.TYPE:
|
||||
case DayNightModeAction.TYPE:
|
||||
return false;
|
||||
|
||||
default:
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
package net.osmand.plus.quickaction.actions;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.quickaction.QuickAction;
|
||||
|
||||
public class DayNightModeAction extends QuickAction {
|
||||
public static final int TYPE = 27;
|
||||
|
||||
public DayNightModeAction() {super(TYPE);}
|
||||
|
||||
public DayNightModeAction(QuickAction quickAction) {super(quickAction);}
|
||||
|
||||
@Override
|
||||
public void execute(MapActivity activity) {
|
||||
switch (activity.getMyApplication().getSettings().DAYNIGHT_MODE.get()){
|
||||
case DAY: {
|
||||
activity.getMyApplication().getSettings().DAYNIGHT_MODE.set(OsmandSettings.DayNightMode.NIGHT);
|
||||
break;
|
||||
}
|
||||
case NIGHT: {
|
||||
activity.getMyApplication().getSettings().DAYNIGHT_MODE.set(OsmandSettings.DayNightMode.DAY);
|
||||
break;
|
||||
}
|
||||
case AUTO: {
|
||||
activity.getMyApplication().getSettings().DAYNIGHT_MODE.set(OsmandSettings.DayNightMode.DAY);
|
||||
break;
|
||||
}
|
||||
case SENSOR: {
|
||||
activity.getMyApplication().getSettings().DAYNIGHT_MODE.set(OsmandSettings.DayNightMode.DAY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawUI(ViewGroup parent, MapActivity activity) {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.quick_action_with_text, parent, false);
|
||||
|
||||
((TextView) view.findViewById(R.id.text))
|
||||
.setText(R.string.quick_action_switch_day_night_descr);
|
||||
|
||||
parent.addView(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconRes(Context context) {
|
||||
if(context instanceof MapActivity) {
|
||||
switch (((MapActivity) context).getMyApplication().getSettings().DAYNIGHT_MODE.get()) {
|
||||
case NIGHT: {
|
||||
return R.drawable.ic_action_map_night;
|
||||
}
|
||||
case AUTO: {
|
||||
return R.drawable.ic_action_map_sunst;
|
||||
}
|
||||
case SENSOR: {
|
||||
return R.drawable.ic_action_map_light_sensor;
|
||||
}
|
||||
}
|
||||
}
|
||||
return R.drawable.ic_action_map_day;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActionText(OsmandApplication application) {
|
||||
return application.getSettings().DAYNIGHT_MODE.get().toHumanString(application) + " Mode";
|
||||
}
|
||||
}
|
|
@ -420,8 +420,8 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
|||
|
||||
@Override
|
||||
public void onActionSelected(QuickAction action) {
|
||||
QuickActionFactory.produceAction(action).execute(mapActivity);
|
||||
setLayerState(false);
|
||||
QuickActionFactory.produceAction(action).execute(mapActivity);
|
||||
}
|
||||
|
||||
public PointF getMovableCenterPoint(RotatedTileBox tb) {
|
||||
|
|
Loading…
Reference in a new issue