Add information controls

This commit is contained in:
vshcherb 2014-03-16 17:03:59 +01:00
parent 6357c03012
commit c66ee96dab
18 changed files with 274 additions and 113 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

View file

@ -2,5 +2,6 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/map_btn_info_p" /> <item android:state_pressed="true" android:drawable="@drawable/map_btn_info_p" />
<item android:state_enabled="false" android:drawable="@drawable/map_btn_info_p" /> <item android:state_enabled="false" android:drawable="@drawable/map_btn_info_p" />
<item android:state_checked="true" android:drawable="@drawable/map_btn_info_p" />
<item android:drawable="@drawable/map_btn_info_o" /> <item android:drawable="@drawable/map_btn_info_o" />
</selector> </selector>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/map_btn_signpost_p" />
<item android:state_enabled="false" android:drawable="@drawable/map_btn_signpost_p" />
<item android:drawable="@drawable/map_btn_signpost_o" />
</selector>

View file

@ -4,7 +4,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" > android:orientation="vertical" >
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal"
android:id="@+id/TopBar"/> android:id="@+id/TopBar" android:orientation="horizontal"/>
<ListView <ListView
android:id="@android:id/list" android:id="@android:id/list"
style="@style/OsmandListView" style="@style/OsmandListView"

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal"
android:id="@+id/TopBar"/>
<ListView
android:id="@android:id/list"
style="@style/OsmandListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
</LinearLayout>

View file

@ -43,6 +43,7 @@ public class SQLiteTileSource implements ITileSource {
static final int tileSize = 256; static final int tileSize = 256;
private ClientContext ctx; private ClientContext ctx;
private boolean onlyReadonlyAvailable = false;
@ -143,7 +144,13 @@ public class SQLiteTileSource implements ITileSource {
protected SQLiteConnection getDatabase(){ protected SQLiteConnection getDatabase(){
if((db == null || db.isClosed()) && file.exists() ){ if((db == null || db.isClosed()) && file.exists() ){
try {
onlyReadonlyAvailable = false;
db = ctx.getSQLiteAPI().openByAbsolutePath(file.getAbsolutePath(), false); db = ctx.getSQLiteAPI().openByAbsolutePath(file.getAbsolutePath(), false);
} catch(RuntimeException e) {
onlyReadonlyAvailable = true;
db = ctx.getSQLiteAPI().openByAbsolutePath(file.getAbsolutePath(), true);
}
try { try {
SQLiteCursor cursor = db.rawQuery("SELECT * FROM info", null); SQLiteCursor cursor = db.rawQuery("SELECT * FROM info", null);
if(cursor.moveToFirst()) { if(cursor.moveToFirst()) {
@ -205,9 +212,11 @@ public class SQLiteTileSource implements ITileSource {
} }
private void addInfoColumn(String columnName, String value) { private void addInfoColumn(String columnName, String value) {
if(!onlyReadonlyAvailable) {
db.execSQL("alter table info add column "+columnName+" TEXT"); db.execSQL("alter table info add column "+columnName+" TEXT");
db.execSQL("update info set "+columnName+" = '"+value+"'"); db.execSQL("update info set "+columnName+" = '"+value+"'");
} }
}
private boolean hasTimeColumn() { private boolean hasTimeColumn() {
SQLiteCursor cursor; SQLiteCursor cursor;
@ -339,7 +348,7 @@ public class SQLiteTileSource implements ITileSource {
*/ */
public synchronized void insertImage(int x, int y, int zoom, File fileToSave) throws IOException { public synchronized void insertImage(int x, int y, int zoom, File fileToSave) throws IOException {
SQLiteConnection db = getDatabase(); SQLiteConnection db = getDatabase();
if (db == null || db.isReadOnly()) { if (db == null || db.isReadOnly() || onlyReadonlyAvailable) {
return; return;
} }
if (exists(x, y, zoom)) { if (exists(x, y, zoom)) {
@ -384,7 +393,7 @@ public class SQLiteTileSource implements ITileSource {
@Override @Override
public boolean couldBeDownloadedFromInternet() { public boolean couldBeDownloadedFromInternet() {
if(getDatabase() == null || getDatabase().isReadOnly()){ if(getDatabase() == null || getDatabase().isReadOnly() || onlyReadonlyAvailable){
return false; return false;
} }
return urlTemplate != null; return urlTemplate != null;

View file

@ -22,6 +22,7 @@ import net.osmand.data.LatLon;
import net.osmand.data.QuadRect; import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.map.ITileSource; import net.osmand.map.ITileSource;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper;
@ -382,7 +383,9 @@ public class MapActivityActions implements DialogProvider {
adapter.item(R.string.context_menu_item_destination_point).icons(R.drawable.ic_action_flag_dark, adapter.item(R.string.context_menu_item_destination_point).icons(R.drawable.ic_action_flag_dark,
R.drawable.ic_action_flag_light).reg(); R.drawable.ic_action_flag_light).reg();
} }
if(!mapActivity.getRoutingHelper().isFollowingMode()) {
adapter.item(R.string.context_menu_item_directions_from).icons(R.drawable.ic_action_gdirections_dark, R.drawable.ic_action_gdirections_light).reg(); adapter.item(R.string.context_menu_item_directions_from).icons(R.drawable.ic_action_gdirections_dark, R.drawable.ic_action_gdirections_light).reg();
}
adapter.item(R.string.context_menu_item_search).icons(R.drawable.ic_action_search_dark, adapter.item(R.string.context_menu_item_search).icons(R.drawable.ic_action_search_dark,
R.drawable.ic_action_search_light).reg(); R.drawable.ic_action_search_light).reg();
adapter.item(R.string.context_menu_item_share_location).icons( adapter.item(R.string.context_menu_item_share_location).icons(
@ -433,9 +436,20 @@ public class MapActivityActions implements DialogProvider {
Location loc = new Location("map"); Location loc = new Location("map");
loc.setLatitude(latitude); loc.setLatitude(latitude);
loc.setLongitude(longitude); loc.setLongitude(longitude);
ApplicationMode mode = settings.DEFAULT_APPLICATION_MODE.get();
if(mode == ApplicationMode.DEFAULT) {
mode = ApplicationMode.CAR;
}
OsmandApplication app = mapActivity.getMyApplication();
app.getSettings().APPLICATION_MODE.set(mode);
app.getRoutingHelper().setAppMode(mode);
// save application mode controls
settings.FOLLOW_THE_ROUTE.set(false);
settings.FOLLOW_THE_GPX_ROUTE.set(null);
app.getRoutingHelper().setFollowingMode(false);
app.getRoutingHelper().setFinalAndCurrentLocation(targets.getPointToNavigate(), targets.getIntermediatePoints(), loc, null);
String name = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObjectName(); String name = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObjectName();
new NavigateAction(mapActivity). // TODO use as point name
getDirections(loc, name, DirectionDialogStyle.create().gpxRouteEnabled().routeFromMapPoint());
} }
} else if (standardId == R.string.context_menu_item_intermediate_point || } else if (standardId == R.string.context_menu_item_intermediate_point ||
standardId == R.string.context_menu_item_destination_point) { standardId == R.string.context_menu_item_destination_point) {

View file

@ -20,6 +20,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.routing.RouteProvider.GPXRouteParams; import net.osmand.plus.routing.RouteProvider.GPXRouteParams;
import net.osmand.plus.routing.RouteProvider.RouteService; import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.plus.routing.RouteProvider.GPXRouteParams.GPXRouteParamsBuilder; import net.osmand.plus.routing.RouteProvider.GPXRouteParams.GPXRouteParamsBuilder;
import net.osmand.plus.views.OsmandMapTileView;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.AlertDialog.Builder; import android.app.AlertDialog.Builder;
@ -132,6 +133,27 @@ public class NavigateAction {
return true; return true;
} }
public View createDialogView() {
final View view = mapActivity.getLayoutInflater().inflate(R.layout.calculate_route, null);
OsmandMapTileView mapView = mapActivity.getMapView();
Location loc = new Location("map");
loc.setLatitude(mapView.getLatitude());
loc.setLongitude(mapView.getLongitude());
String name = null;
DirectionDialogStyle style = DirectionDialogStyle.create();
final Spinner fromSpinner = setupFromSpinner(loc, name, view, style);
final List<LatLon> toList = new ArrayList<LatLon>();
final Spinner toSpinner = setupToSpinner(loc, name, view, toList, style);
String via = generateViaDescription();
if(via.length() == 0){
((TextView) view.findViewById(R.id.ViaView)).setVisibility(View.GONE);
} else {
((TextView) view.findViewById(R.id.ViaView)).setVisibility(View.VISIBLE);
((TextView) view.findViewById(R.id.ViaView)).setText(via);
}
return view;
}
public void getDirections(final Location mapView, String name, DirectionDialogStyle style) { public void getDirections(final Location mapView, String name, DirectionDialogStyle style) {
final Location current = getLastKnownLocation(); final Location current = getLastKnownLocation();
Builder builder = new AlertDialog.Builder(mapActivity); Builder builder = new AlertDialog.Builder(mapActivity);

View file

@ -39,28 +39,18 @@ public class NativeOsmandLibrary extends NativeLibrary {
System.loadLibrary("gnustl_shared"); System.loadLibrary("gnustl_shared");
log.debug("Loading native cpufeatures_proxy..."); //$NON-NLS-1$ log.debug("Loading native cpufeatures_proxy..."); //$NON-NLS-1$
System.loadLibrary("cpufeatures_proxy"); System.loadLibrary("cpufeatures_proxy");
if(android.os.Build.VERSION.SDK_INT >= 8) { if (android.os.Build.VERSION.SDK_INT >= 8) {
log.debug("Loading jnigraphics, since Android >= 2.2 ..."); //$NON-NLS-1$ log.debug("Loading jnigraphics, since Android >= 2.2 ..."); //$NON-NLS-1$
System.loadLibrary("jnigraphics"); System.loadLibrary("jnigraphics");
} }
final String libCpuSuffix = cpuHasNeonSupport() ? "_neon" : ""; final String libCpuSuffix = cpuHasNeonSupport() ? "_neon" : "";
log.debug("Loading native libraries..."); //$NON-NLS-1$ log.debug("Loading native libraries..."); //$NON-NLS-1$
try {
loadNewCore(libCpuSuffix);
log.debug("Creating NativeOsmandLibrary instance..."); //$NON-NLS-1$
library = new NativeOsmandLibrary(true);
isNativeSupported = true;
} catch(Error e) {
log.error("Failed to load new native library", e); //$NON-NLS-1$
}
if(!isNativeSupported) {
loadOldCore(libCpuSuffix); loadOldCore(libCpuSuffix);
log.debug("Creating NativeOsmandLibrary instance..."); //$NON-NLS-1$ log.debug("Creating NativeOsmandLibrary instance..."); //$NON-NLS-1$
library = new NativeOsmandLibrary(false); library = new NativeOsmandLibrary(false);
log.debug("Initializing rendering rules storage..."); //$NON-NLS-1$ log.debug("Initializing rendering rules storage..."); //$NON-NLS-1$
NativeOsmandLibrary.initRenderingRulesStorage(storage); NativeOsmandLibrary.initRenderingRulesStorage(storage);
isNativeSupported = true; isNativeSupported = true;
}
} catch (Throwable e) { } catch (Throwable e) {
log.error("Failed to load native library", e); //$NON-NLS-1$ log.error("Failed to load native library", e); //$NON-NLS-1$
} }
@ -74,17 +64,6 @@ public class NativeOsmandLibrary extends NativeLibrary {
System.loadLibrary("osmand" + libCpuSuffix); System.loadLibrary("osmand" + libCpuSuffix);
} }
private static void loadNewCore(final String libCpuSuffix) {
// System.loadLibrary("Qt5Core" + libCpuSuffix);
// System.loadLibrary("Qt5Network" + libCpuSuffix);
// System.loadLibrary("Qt5Concurrent" + libCpuSuffix);
// System.loadLibrary("Qt5Sql" + libCpuSuffix);
// System.loadLibrary("Qt5Xml" + libCpuSuffix);
// System.loadLibrary("OsmAndCore" + libCpuSuffix);
// System.loadLibrary("OsmAndCoreUtils" + libCpuSuffix);
System.loadLibrary("OsmAndJNI" + libCpuSuffix);
}
public static boolean isSupported() public static boolean isSupported()
{ {
return isNativeSupported != null && isNativeSupported; return isNativeSupported != null && isNativeSupported;

View file

@ -749,7 +749,10 @@ public class RoutingHelper {
} }
lastTimeEvaluatedRoute = System.currentTimeMillis(); lastTimeEvaluatedRoute = System.currentTimeMillis();
} }
}
public void recalculateRouteDueToSettingsChange() {
recalculateRouteInBackground(lastFixedLocation, finalLocation, intermediatePoints, currentGPXRoute, null);
} }
private void recalculateRouteInBackground(final Location start, final LatLon end, final List<LatLon> intermediates, final GPXRouteParams gpxRoute, final RouteCalculationResult previousRoute){ private void recalculateRouteInBackground(final Location start, final LatLon end, final List<LatLon> intermediates, final GPXRouteParams gpxRoute, final RouteCalculationResult previousRoute){

View file

@ -416,7 +416,7 @@ public class MapInfoLayer extends OsmandMapLayer {
} }
}; };
Builder b = new AlertDialog.Builder(map); Builder b = new AlertDialog.Builder(map);
View confirmDialog = view.inflate(view.getContext(), R.layout.configuration_dialog, null); View confirmDialog = View.inflate(view.getContext(), R.layout.configuration_dialog, null);
final ListView lv = (ListView) confirmDialog.findViewById(android.R.id.list); final ListView lv = (ListView) confirmDialog.findViewById(android.R.id.list);
NavigateAction.prepareAppModeView(map, selected, true, NavigateAction.prepareAppModeView(map, selected, true,
(ViewGroup) confirmDialog.findViewById(R.id.TopBar), true, (ViewGroup) confirmDialog.findViewById(R.id.TopBar), true,

View file

@ -454,7 +454,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
Canvas canvas = holder.lockCanvas(); Canvas canvas = holder.lockCanvas();
if (canvas != null) { if (canvas != null) {
try { try {
final float ratioy = mapPosition == OsmandSettings.BOTTOM_CONSTANT ? 0.8f : 0.5f; final float ratioy = mapPosition == OsmandSettings.BOTTOM_CONSTANT ? 0.9f : 0.5f;
final int cy = (int) (ratioy * getHeight()); final int cy = (int) (ratioy * getHeight());
if(currentViewport.getPixWidth() != getWidth() || currentViewport.getPixHeight() != getHeight() || if(currentViewport.getPixWidth() != getWidth() || currentViewport.getPixHeight() != getHeight() ||
currentViewport.getCenterPixelY() != cy) { currentViewport.getCenterPixelY() != cy) {

View file

@ -1,23 +1,35 @@
package net.osmand.plus.views.controls; package net.osmand.plus.views.controls;
import java.util.HashSet;
import java.util.Set;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.actions.NavigateAction;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Handler; import android.os.Handler;
import android.view.Gravity;
import android.view.View; import android.view.View;
import android.widget.Button; import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ListView;
public class MapAppModeControl extends MapControls { public class MapAppModeControl extends MapControls {
private Button settingsAppModeButton; private ImageButton settingsAppModeButton;
private OsmandSettings settings; private OsmandSettings settings;
private Drawable drawable;
private int cachedId; private int cachedId;
private Dialog dialog;
public MapAppModeControl(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) { public MapAppModeControl(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
@ -27,14 +39,71 @@ public class MapAppModeControl extends MapControls {
@Override @Override
public void showControls(FrameLayout parent) { public void showControls(FrameLayout parent) {
settingsAppModeButton = addButton(parent, R.string.routing_preferences_descr, R.drawable.map_btn_plain); settingsAppModeButton = addImageButton(parent, R.string.routing_preferences_descr, R.drawable.map_btn_plain);
cachedId = 0;
settingsAppModeButton.setOnClickListener(new View.OnClickListener() { settingsAppModeButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
// TODO if(dialog != null) {
dialog.hide();
dialog = null;
settingsAppModeButton.setBackgroundResource(R.drawable.map_btn_plain);
} else {
dialog = showDialog();
dialog.show();
settingsAppModeButton.setBackgroundResource(R.drawable.map_btn_plain_p);
dialog.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dlg) {
settingsAppModeButton.setBackgroundResource(R.drawable.map_btn_plain);
dialog = null;
} }
}); });
} }
}
});
}
private Dialog showDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
View ll = createLayout();
builder.setView(ll);
Dialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(true);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.BOTTOM;
lp.y = (int) (settingsAppModeButton.getBottom() - settingsAppModeButton.getTop() + scaleCoefficient * 5);
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setAttributes(lp);
return dialog;
}
private View createLayout() {
View settingsDlg = View.inflate(mapActivity, R.layout.plan_route_settings, null);
final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
ApplicationMode am = settings.APPLICATION_MODE.get();
final ListView lv = (ListView) settingsDlg.findViewById(android.R.id.list);
final Set<ApplicationMode> selected = new HashSet<ApplicationMode>();
selected.add(am);
NavigateAction.prepareAppModeView(mapActivity, selected, false,
(ViewGroup) settingsDlg.findViewById(R.id.TopBar), true,
new View.OnClickListener() {
@Override
public void onClick(View v) {
if(selected.size() > 0) {
settings.APPLICATION_MODE.set(selected.iterator().next());
mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
//listAdapter.notifyDataSetChanged();
}
}
});
return settingsDlg;
}
@Override @Override
public void hideControls(FrameLayout layout) { public void hideControls(FrameLayout layout) {
@ -43,24 +112,12 @@ public class MapAppModeControl extends MapControls {
mapActivity.accessibleContent.remove(settingsAppModeButton); mapActivity.accessibleContent.remove(settingsAppModeButton);
} }
@SuppressWarnings("deprecation")
@Override @Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) { public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
int id = settings.getApplicationMode().getIconId(); int id = settings.getApplicationMode().getSmallIcon(settingsAppModeButton.isPressed() || dialog != null);
if(cachedId != id && settingsAppModeButton.getLeft() > 0) { if(cachedId != id && settingsAppModeButton.getLeft() > 0) {
cachedId = id; cachedId = id;
// drawable = mapActivity.getResources().getDrawable(id); settingsAppModeButton.setImageResource(id);
// int h = drawable.getMinimumHeight() / 2;
// int w = drawable.getMinimumWidth() / 2;
// int cx = (settingsAppModeButton.getLeft() + settingsAppModeButton.getRight()) / 2;
// int cy = (settingsAppModeButton.getTop() + settingsAppModeButton.getBottom()) / 2;
// drawable.setBounds(cx - w, cy - h, cx + w, cy + h);
settingsAppModeButton.setBackgroundDrawable(new LayerDrawable(new Drawable[] {
mapActivity.getResources().getDrawable(R.drawable.map_btn_plain), drawable }));
} }
if(drawable != null) {
drawable.draw(canvas);
}
} }
} }

View file

@ -12,6 +12,7 @@ import android.view.Gravity;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageButton;
public abstract class MapControls { public abstract class MapControls {
@ -47,6 +48,13 @@ public abstract class MapControls {
this.vmargin = vmargin; this.vmargin = vmargin;
} }
protected ImageButton addImageButton(FrameLayout parent, int stringId, int resourceId) {
Context ctx = mapActivity;
ImageButton button = new ImageButton(ctx);
applyAttributes(ctx, parent, button, stringId, resourceId, 0);
return button;
}
protected Button addButton(FrameLayout parent, int stringId, int resourceId) { protected Button addButton(FrameLayout parent, int stringId, int resourceId) {
return addButton(parent, stringId, resourceId, 0); return addButton(parent, stringId, resourceId, 0);
} }
@ -54,6 +62,13 @@ public abstract class MapControls {
protected Button addButton(FrameLayout parent, int stringId, int resourceId, int extraMargin) { protected Button addButton(FrameLayout parent, int stringId, int resourceId, int extraMargin) {
Context ctx = mapActivity; Context ctx = mapActivity;
Button button = new Button(ctx); Button button = new Button(ctx);
applyAttributes(ctx, parent, button, stringId, resourceId, extraMargin);
return button;
}
private void applyAttributes(Context ctx, FrameLayout parent, View button, int stringId, int resourceId,
int extraMargin) {
button.setContentDescription(ctx.getString(stringId)); button.setContentDescription(ctx.getString(stringId));
button.setBackgroundResource(resourceId); button.setBackgroundResource(resourceId);
Drawable d = ctx.getResources().getDrawable(resourceId); Drawable d = ctx.getResources().getDrawable(resourceId);
@ -72,7 +87,6 @@ public abstract class MapControls {
parent.addView(button, params); parent.addView(button, params);
button.setEnabled(true); button.setEnabled(true);
mapActivity.accessibleContent.add(button); mapActivity.accessibleContent.add(button);
return button;
} }
protected void removeButton(FrameLayout layout, View b) { protected void removeButton(FrameLayout layout, View b) {

View file

@ -2,25 +2,31 @@ package net.osmand.plus.views.controls;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ClientContext; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.ShowRouteInfoActivity; import net.osmand.plus.activities.ShowRouteInfoActivity;
import net.osmand.plus.activities.actions.NavigateAction;
import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.plus.routing.RouteDirectionInfo;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener; import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener;
import net.osmand.plus.views.ContextMenuLayer; import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent; import android.content.Intent;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Handler; import android.os.Handler;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button; import android.widget.Button;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.LinearLayout; import android.widget.LinearLayout;
@ -32,9 +38,10 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio
private final ContextMenuLayer contextMenu; private final ContextMenuLayer contextMenu;
private final RoutingHelper routingHelper; private final RoutingHelper routingHelper;
private OsmandMapTileView mapView; private OsmandMapTileView mapView;
private View next; private ImageButton next;
private View prev; private ImageButton prev;
private View info; private ImageButton info;
private Dialog dialog;
public MapRouteInfoControl(ContextMenuLayer contextMenu, public MapRouteInfoControl(ContextMenuLayer contextMenu,
@ -43,19 +50,66 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio
this.contextMenu = contextMenu; this.contextMenu = contextMenu;
routingHelper = mapActivity.getRoutingHelper(); routingHelper = mapActivity.getRoutingHelper();
mapView = mapActivity.getMapView(); mapView = mapActivity.getMapView();
routingHelper.addListener(this);
} }
@Override @Override
public void showControls(FrameLayout parent) { public void showControls(FrameLayout parent) {
infoButton = addButton(parent, R.string.info_button, R.drawable.map_btn_info); infoButton = addButton(parent, R.string.info_button, R.drawable.map_btn_signpost);
controlVisible = true; controlVisible = true;
infoButton.setOnClickListener(new View.OnClickListener() { infoButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
// TODO if(dialog != null) {
dialog.hide();
dialog = null;
infoButton.setBackgroundResource(R.drawable.map_btn_signpost);
} else {
dialog = showDialog();
dialog.show();
infoButton.setBackgroundResource(R.drawable.map_btn_signpost_p);
dialog.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dlg) {
infoButton.setBackgroundResource(R.drawable.map_btn_signpost);
dialog = null;
} }
}); });
} }
}
});
}
private Dialog showDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
LinearLayout lmain = new LinearLayout(mapActivity);
lmain.setOrientation(LinearLayout.VERTICAL);
boolean addButtons = routingHelper.isRouteCalculated();
if(addButtons) {
LinearLayout buttons = createButtonsLayout(scaleCoefficient);
lmain.addView(buttons);
}
View lv = new NavigateAction(mapActivity).createDialogView();
lv.setId(R.id.MainLayout);
lmain.addView(lv);
if(addButtons) {
attachListeners(lmain);
}
builder.setView(lmain);
Dialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(true);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.BOTTOM;
lp.y = (int) (infoButton.getBottom() - infoButton.getTop() + scaleCoefficient * 5);
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setAttributes(lp);
return dialog;
}
public static int getDirectionInfo() { public static int getDirectionInfo() {
return directionInfo; return directionInfo;
@ -83,43 +137,35 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio
return width ; return width ;
} }
// public RouteInfoLayer(RoutingHelper routingHelper, MapActivity activity, ContextMenuLayer contextMenu){ private LinearLayout createButtonsLayout(float density) {
// createLayout(activity, activity.getMapView().getDensity()); LinearLayout ll = new LinearLayout(mapActivity);
// this.routingHelper = routingHelper; ll.setGravity(Gravity.CENTER);
// this.contextMenu = contextMenu;
// routingHelper.addListener(this);
// attachListeners(activity.getMyApplication());
// updateVisibility();
//
// activity.accessibleContent.add(prev);
// activity.accessibleContent.add(next);
// activity.accessibleContent.add(info);
// }
private void createLayout(MapActivity activity, float density) {
FrameLayout fl = (FrameLayout) activity.getMapView().getParent();
LinearLayout ll = new LinearLayout(activity);
ll.setOrientation(LinearLayout.HORIZONTAL); ll.setOrientation(LinearLayout.HORIZONTAL);
ll.setPadding(0, 0, (int) (density * 15), (int) (density * 50)); ll.setPadding((int) (density * 10), (int) (density * 5), (int) (density * 10), (int) (density * 5));
fl.addView(ll, new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.BOTTOM | Gravity.CENTER)); prev = new ImageButton(mapActivity);
prev = new ImageButton(activity); prev.setContentDescription(mapActivity.getString(R.string.previous_button));
prev.setContentDescription(activity.getString(R.string.previous_button)); prev.setImageResource(R.drawable.ax_1_navigation_previous_item_light);
prev.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.ax_1_navigation_previous_item_light)); prev.setAdjustViewBounds(true);
prev.setBackgroundResource(R.drawable.map_btn_plain);
ll.addView(prev); ll.addView(prev);
info = new ImageButton(activity); info = new ImageButton(mapActivity);
info.setContentDescription(activity.getString(R.string.info_button)); info.setContentDescription(mapActivity.getString(R.string.info_button));
info.setPadding((int) (density * 8), 0, 0, 0); info.setBackgroundResource(R.drawable.map_btn_plain);
info.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.ax_2_action_about_light)); info.setAdjustViewBounds(true);
info.setImageResource(R.drawable.ax_2_action_about_light);
ll.addView(info); ll.addView(info);
next = new ImageButton(activity); next = new ImageButton(mapActivity);
next.setContentDescription(activity.getString(R.string.next_button)); next.setContentDescription(mapActivity.getString(R.string.next_button));
next.setPadding((int) (density * 8), 0, 0, 0); next.setBackgroundResource(R.drawable.map_btn_plain);
next.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.ax_1_navigation_next_item_light)); next.setAdjustViewBounds(true);
next.setImageResource(R.drawable.ax_1_navigation_next_item_light);
ll.addView(next); ll.addView(next);
return ll;
} }
private void attachListeners(final ClientContext ctx) { private void attachListeners(final View mainView) {
final OsmandApplication ctx = mapActivity.getMyApplication();
prev.setOnClickListener(new View.OnClickListener(){ prev.setOnClickListener(new View.OnClickListener(){
@Override @Override
@ -127,6 +173,7 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio
if(routingHelper.getRouteDirections() != null && directionInfo > 0){ if(routingHelper.getRouteDirections() != null && directionInfo > 0){
directionInfo--; directionInfo--;
if(routingHelper.getRouteDirections().size() > directionInfo){ if(routingHelper.getRouteDirections().size() > directionInfo){
mainView.findViewById(R.id.MainLayout).setVisibility(View.GONE);
RouteDirectionInfo info = routingHelper.getRouteDirections().get(directionInfo); RouteDirectionInfo info = routingHelper.getRouteDirections().get(directionInfo);
net.osmand.Location l = routingHelper.getLocationFromRouteDirection(info); net.osmand.Location l = routingHelper.getLocationFromRouteDirection(info);
contextMenu.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), info.getDescriptionRoute(ctx)); contextMenu.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), info.getDescriptionRoute(ctx));
@ -138,10 +185,10 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio
}); });
next.setOnClickListener(new View.OnClickListener(){ next.setOnClickListener(new View.OnClickListener(){
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if(routingHelper.getRouteDirections() != null && directionInfo < routingHelper.getRouteDirections().size() - 1){ if(routingHelper.getRouteDirections() != null && directionInfo < routingHelper.getRouteDirections().size() - 1){
mainView.findViewById(R.id.MainLayout).setVisibility(View.GONE);
directionInfo++; directionInfo++;
RouteDirectionInfo info = routingHelper.getRouteDirections().get(directionInfo); RouteDirectionInfo info = routingHelper.getRouteDirections().get(directionInfo);
net.osmand.Location l = routingHelper.getLocationFromRouteDirection(info); net.osmand.Location l = routingHelper.getLocationFromRouteDirection(info);
@ -162,30 +209,24 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio
}); });
} }
public boolean isVisible(){ public boolean isVisibleButtons(){
return routingHelper.isRouteCalculated() && !routingHelper.isFollowingMode(); return routingHelper.isRouteCalculated() && !routingHelper.isFollowingMode();
} }
private void updateVisibility(){
int vis = isVisible() ? View.VISIBLE : View.INVISIBLE;
prev.setVisibility(vis);
next.setVisibility(vis);
info.setVisibility(vis);
}
@Override @Override
public void newRouteIsCalculated(boolean newRoute) { public void newRouteIsCalculated(boolean newRoute) {
directionInfo = -1; directionInfo = -1;
updateVisibility();
mapView.refreshMap(); mapView.refreshMap();
} }
@Override @Override
public void routeWasCancelled() { public void routeWasCancelled() {
directionInfo = -1; directionInfo = -1;
updateVisibility(); if(dialog != null) {
dialog.hide();
dialog = null;
}
} }
} }