Merge pull request #6681 from osmandapp/quickaction_fix_3.3

Issue Fix - Quick Action:#6508
This commit is contained in:
vshcherb 2019-03-18 15:50:46 +01:00 committed by GitHub
commit 5341defd89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 66 deletions

View file

@ -11,6 +11,7 @@
Thx - Hardy
-->
<string name="quick_action_day_night_mode">%s mode</string>
<string name="avoid_pt_types_descr">Select a public transport types you want to avoid during navigation:</string>
<string name="avoid_pt_types">Avoid transport types…</string>
<string name="shared_string_walk">Walk</string>

View file

@ -7,6 +7,7 @@ import android.view.ViewGroup;
import android.widget.TextView;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.DayNightMode;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction;
@ -20,23 +21,10 @@ public class DayNightModeAction extends QuickAction {
@Override
public void execute(MapActivity activity) {
switch (activity.getMyApplication().getSettings().DAYNIGHT_MODE.get()){
case DAY: {
if (activity.getMyApplication().getDaynightHelper().isNightMode()) {
activity.getMyApplication().getSettings().DAYNIGHT_MODE.set(OsmandSettings.DayNightMode.DAY);
} else {
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;
}
}
}
@ -44,33 +32,28 @@ public class DayNightModeAction extends QuickAction {
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;
}
}
}
if (context instanceof MapActivity
&& ((MapActivity) context).getMyApplication().getDaynightHelper().isNightMode()) {
return R.drawable.ic_action_map_day;
}
return R.drawable.ic_action_map_night;
}
@Override
public String getActionText(OsmandApplication application) {
return application.getSettings().DAYNIGHT_MODE.get().toHumanString(application) + " Mode";
if (application.getDaynightHelper().isNightMode()) {
return String.format(application.getString(R.string.quick_action_day_night_mode),
DayNightMode.DAY.toHumanString(application));
} else {
return String.format(application.getString(R.string.quick_action_day_night_mode),
DayNightMode.NIGHT.toHumanString(application));
}
}
}

View file

@ -73,6 +73,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
private boolean isLayerOn;
private boolean nightMode;
private boolean currentWidgetState;
public MapQuickActionLayer(MapActivity activity, ContextMenuLayer contextMenuLayer) {
this.mapActivity = activity;
@ -204,6 +205,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
* @return true, if state was changed
*/
public boolean setLayerState(boolean showWidget) {
currentWidgetState = showWidget;
if (isWidgetVisible() == showWidget) // check if state change is needed
return false;
@ -372,14 +374,14 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
@Override
public void onDraw(Canvas canvas, RotatedTileBox box, DrawSettings settings) {
boolean nightMode = settings != null && settings.isNightMode();
boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
if (isInMovingMarkerMode()) {
canvas.translate(box.getCenterPixelX() - contextMarker.getWidth() / 2, box.getCenterPixelY() - contextMarker.getHeight());
contextMarker.draw(canvas);
}
if (this.nightMode != nightMode) {
this.nightMode = nightMode;
updateQuickActionButton(isWidgetVisible());
updateQuickActionButton(currentWidgetState);
}
setupQuickActionBtnVisibility();
}