Merge pull request #4129 from osmandapp/add_quick_actions

Fix #4002
This commit is contained in:
vshcherb 2017-07-17 15:43:11 +02:00 committed by GitHub
commit 199f541244
11 changed files with 491 additions and 206 deletions

View file

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:padding="16dp"
android:text="@string/quick_action_start_stop_navigation_descr"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:scaleType="fitXY"
android:src="@drawable/bg_shadow_list_bottom"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginTop="16dp"
android:scaleType="fitXY"
android:src="@drawable/bg_shadow_list_top"/>
<LinearLayout
android:id="@+id/show_dialog_row"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="?attr/bg_color"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:padding="16dp"
android:text="@string/quick_action_show_navigation_finish_dialog"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/show_dialog_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"/>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:scaleType="fitXY"
android:src="@drawable/bg_shadow_list_bottom"/>
</LinearLayout>

View file

@ -9,6 +9,11 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="quick_action_resume_pause_navigation">Resume/Pause Navigation</string>
<string name="quick_action_resume_pause_navigation_descr">Press this button to pause the navigation, or to resume it if it was already paused.</string>
<string name="quick_action_show_navigation_finish_dialog">Show Finish navigation dialog</string>
<string name="quick_action_start_stop_navigation">Start/Finish Navigation</string>
<string name="quick_action_start_stop_navigation_descr">Press this button to start the navigation, or to stop it if it was already started.</string>
<string name="store_tracks_in_monthly_directories">Store recorded tracks in monthly folders</string>
<string name="store_tracks_in_monthly_directories_descrp">Store recorded tracks in sub-folders per recording month (like 2017-01).</string>
<string name="shared_string_reset">Reset</string>

View file

@ -1,7 +1,6 @@
package net.osmand.plus.dashboard;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
@ -123,7 +122,7 @@ public class DashNavigationFragment extends DashBaseFragment {
} else {
routingHelper.setRoutePlanningMode(true);
routingHelper.setFollowingMode(false);
routingHelper.setPauseNaviation(true);
routingHelper.setPauseNavigation(true);
}
updatePlayButton(routingHelper, map, play);
map.getMapViewTrackingUtilities().switchToRoutePlanningMode();

View file

@ -64,7 +64,7 @@ public class NavigationNotification extends OsmandNotification {
RoutingHelper routingHelper = app.getRoutingHelper();
routingHelper.setRoutePlanningMode(true);
routingHelper.setFollowingMode(false);
routingHelper.setPauseNaviation(true);
routingHelper.setPauseNavigation(true);
}
}, new IntentFilter(OSMAND_PAUSE_NAVIGATION_SERVICE_ACTION));

View file

@ -80,6 +80,10 @@ public class QuickAction {
return isActionEditable;
}
public boolean isActionEnable(OsmandApplication app) {
return true;
}
public String getName(Context context) {
return name == null || name.isEmpty() ? nameRes > 0 ? context.getString(nameRes) : "" : name;
}

View file

@ -28,6 +28,8 @@ import net.osmand.plus.quickaction.actions.NavAddDestinationAction;
import net.osmand.plus.quickaction.actions.NavAddFirstIntermediateAction;
import net.osmand.plus.quickaction.actions.NavAutoZoomMapAction;
import net.osmand.plus.quickaction.actions.NavReplaceDestinationAction;
import net.osmand.plus.quickaction.actions.NavResumePauseAction;
import net.osmand.plus.quickaction.actions.NavStartStopAction;
import net.osmand.plus.quickaction.actions.NavVoiceAction;
import net.osmand.plus.quickaction.actions.NewAction;
import net.osmand.plus.quickaction.actions.ShowHideFavoritesAction;
@ -119,6 +121,8 @@ public class QuickActionFactory {
QuickAction addFirstIntermediate = new NavAddFirstIntermediateAction();
QuickAction replaceDestination = new NavReplaceDestinationAction();
QuickAction autoZoomMap = new NavAutoZoomMapAction();
QuickAction startStopNavigation = new NavStartStopAction();
QuickAction resumePauseNavigation = new NavResumePauseAction();
ArrayList<QuickAction> navigationQuickActions = new ArrayList<>();
@ -137,6 +141,12 @@ public class QuickActionFactory {
if (!autoZoomMap.hasInstanceInList(active)) {
navigationQuickActions.add(autoZoomMap);
}
if (!startStopNavigation.hasInstanceInList(active)) {
navigationQuickActions.add(startStopNavigation);
}
if (!resumePauseNavigation.hasInstanceInList(active)) {
navigationQuickActions.add(resumePauseNavigation);
}
if (navigationQuickActions.size() > 0) {
quickActions.add(new QuickAction(0, R.string.quick_action_add_navigation));
@ -216,6 +226,12 @@ public class QuickActionFactory {
case NavAutoZoomMapAction.TYPE:
return new NavAutoZoomMapAction();
case NavStartStopAction.TYPE:
return new NavStartStopAction();
case NavResumePauseAction.TYPE:
return new NavResumePauseAction();
default:
return new QuickAction();
}
@ -291,6 +307,12 @@ public class QuickActionFactory {
case NavAutoZoomMapAction.TYPE:
return new NavAutoZoomMapAction(quickAction);
case NavStartStopAction.TYPE:
return new NavStartStopAction(quickAction);
case NavResumePauseAction.TYPE:
return new NavResumePauseAction(quickAction);
default:
return quickAction;
}
@ -366,6 +388,12 @@ public class QuickActionFactory {
case NavAutoZoomMapAction.TYPE:
return R.drawable.ic_action_search_dark;
case NavStartStopAction.TYPE:
return R.drawable.ic_action_start_navigation;
case NavResumePauseAction.TYPE:
return R.drawable.ic_play_dark;
default:
return R.drawable.ic_action_plus;
}
@ -441,6 +469,12 @@ public class QuickActionFactory {
case NavAutoZoomMapAction.TYPE:
return R.string.quick_action_auto_zoom;
case NavStartStopAction.TYPE:
return R.string.quick_action_start_stop_navigation;
case NavResumePauseAction.TYPE:
return R.string.quick_action_resume_pause_navigation;
default:
return R.string.quick_action_new_action;
}
@ -464,6 +498,8 @@ public class QuickActionFactory {
case NavReplaceDestinationAction.TYPE:
case NavAutoZoomMapAction.TYPE:
case ShowHideOSMBugAction.TYPE:
case NavStartStopAction.TYPE:
case NavResumePauseAction.TYPE:
return false;
default:

View file

@ -254,6 +254,10 @@ public class QuickActionsWidget extends LinearLayout {
}
});
}
if (!action.isActionEnable(application)) {
view.setEnabled(false);
view.setAlpha(0.5f);
}
}
if (land) {

View file

@ -0,0 +1,77 @@
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.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.routing.RoutingHelper;
public class NavResumePauseAction extends QuickAction {
public static final int TYPE = 26;
public NavResumePauseAction() {
super(TYPE);
}
public NavResumePauseAction(QuickAction quickAction) {
super(quickAction);
}
@Override
public void execute(MapActivity activity) {
RoutingHelper routingHelper = activity.getRoutingHelper();
if (routingHelper.isRoutePlanningMode()) {
routingHelper.setRoutePlanningMode(false);
routingHelper.setFollowingMode(true);
} else {
routingHelper.setRoutePlanningMode(true);
routingHelper.setFollowingMode(false);
routingHelper.setPauseNavigation(true);
}
activity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
activity.refreshMap();
}
@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_resume_pause_navigation_descr);
parent.addView(view);
}
@Override
public String getActionText(OsmandApplication application) {
RoutingHelper helper = application.getRoutingHelper();
if (!helper.isRouteCalculated() || helper.isRoutePlanningMode()) {
return application.getString(R.string.continue_navigation);
}
return application.getString(R.string.pause_navigation);
}
@Override
public int getIconRes(Context context) {
if (context instanceof MapActivity) {
RoutingHelper helper = ((MapActivity) context).getRoutingHelper();
if (!helper.isRouteCalculated() || helper.isRoutePlanningMode()) {
return R.drawable.ic_play_dark;
}
return R.drawable.ic_pause;
}
return super.getIconRes(context);
}
@Override
public boolean isActionEnable(OsmandApplication app) {
return app.getRoutingHelper().isRouteCalculated();
}
}

View file

@ -0,0 +1,91 @@
package net.osmand.plus.quickaction.actions;
import android.content.Context;
import android.support.v7.widget.SwitchCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.other.DestinationReachedMenu;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.routing.RoutingHelper;
public class NavStartStopAction extends QuickAction {
public static final int TYPE = 25;
private static final String KEY_DIALOG = "dialog";
public NavStartStopAction() {
super(TYPE);
}
public NavStartStopAction(QuickAction quickAction) {
super(quickAction);
}
@Override
public void execute(MapActivity activity) {
RoutingHelper helper = activity.getRoutingHelper();
if (helper.isPauseNavigation() || helper.isFollowingMode()) {
if (Boolean.valueOf(getParams().get(KEY_DIALOG))) {
DestinationReachedMenu.show(activity);
} else {
activity.getMapLayers().getMapControlsLayer().stopNavigation();
}
} else {
activity.getMapLayers().getMapControlsLayer().doRoute(false);
}
}
@Override
public void drawUI(ViewGroup parent, MapActivity activity) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.quick_action_start_stop_navigation, parent, false);
final SwitchCompat showDialogSwitch = (SwitchCompat) view.findViewById(R.id.show_dialog_switch);
if (!getParams().isEmpty()) {
showDialogSwitch.setChecked(Boolean.valueOf(getParams().get(KEY_DIALOG)));
}
view.findViewById(R.id.show_dialog_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showDialogSwitch.setChecked(!showDialogSwitch.isChecked());
}
});
parent.addView(view);
}
@Override
public boolean fillParams(View root, MapActivity activity) {
getParams().put(KEY_DIALOG, Boolean
.toString(((SwitchCompat) root.findViewById(R.id.show_dialog_switch)).isChecked()));
return true;
}
@Override
public String getActionText(OsmandApplication application) {
RoutingHelper helper = application.getRoutingHelper();
if (helper.isPauseNavigation() || helper.isFollowingMode()) {
return application.getString(R.string.cancel_navigation);
}
return application.getString(R.string.follow);
}
@Override
public int getIconRes(Context context) {
if (context instanceof MapActivity) {
RoutingHelper helper = ((MapActivity) context).getRoutingHelper();
if (helper.isPauseNavigation() || helper.isFollowingMode()) {
return R.drawable.ic_action_target;
}
return R.drawable.ic_action_start_navigation;
}
return super.getIconRes(context);
}
}

View file

@ -119,7 +119,7 @@ public class RoutingHelper {
return lastRouteCalcErrorShort;
}
public void setPauseNaviation(boolean b) {
public void setPauseNavigation(boolean b) {
this.isPauseNavigation = b;
if (b) {
if (app.getNavigationService() != null) {

View file

@ -350,7 +350,7 @@ public class MapControlsLayer extends OsmandMapLayer {
}
}
protected void clickRouteCancel() {
public void stopNavigation() {
mapRouteInfoMenu.hide();
if (mapActivity.getRoutingHelper().isFollowingMode()) {
mapActivity.getMapActions().stopNavigationActionConfirm();
@ -359,6 +359,10 @@ public class MapControlsLayer extends OsmandMapLayer {
}
}
protected void clickRouteCancel() {
stopNavigation();
}
protected void clickRouteGo() {
if (app.getTargetPointsHelper().getPointToNavigate() != null) {
mapRouteInfoMenu.hide();