Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-11-17 14:45:37 +01:00
commit 171de15682
10 changed files with 197 additions and 55 deletions

View file

@ -346,22 +346,29 @@
</LinearLayout>
<ScrollView
android:id="@+id/context_menu_bottom_scroll"
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/ctx_menu_info_view_bg">
android:foreground="@drawable/bg_contextmenu_shadow"
android:foregroundGravity="top|fill_horizontal">
<LinearLayout
android:id="@+id/context_menu_bottom_view"
<ScrollView
android:id="@+id/context_menu_bottom_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/ctx_menu_info_view_bg"
android:orientation="vertical">
android:layout_height="match_parent"
android:background="?attr/ctx_menu_info_view_bg">
</LinearLayout>
<LinearLayout
android:id="@+id/context_menu_bottom_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/ctx_menu_info_view_bg"
android:orientation="vertical">
</ScrollView>
</LinearLayout>
</ScrollView>
</FrameLayout>
</LinearLayout>

View file

@ -24,6 +24,14 @@
android:background="@android:color/transparent"
android:src="@drawable/ic_action_delete_dark"/>
<ImageButton
android:id="@+id/ok_button"
android:layout_width="?attr/actionBarSize"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="@android:color/transparent"
android:src="@drawable/ic_action_done"/>
<Button
android:id="@+id/save_button"
android:layout_width="wrap_content"
@ -35,6 +43,7 @@
android:background="@android:color/transparent"
android:text="@string/shared_string_save"/>
</android.support.v7.widget.Toolbar>
<LinearLayout

View file

@ -631,11 +631,31 @@ public class GPXUtilities {
return false;
}
public WptPt addWptPt(double lat, double lon, long time, String description, String name, String category, int color) {
double latAdjusted = Double.parseDouble(latLonFormat.format(lat));
double lonAdjusted = Double.parseDouble(latLonFormat.format(lon));
final WptPt pt = new WptPt(latAdjusted, lonAdjusted, time, Double.NaN, 0, Double.NaN);
pt.name = name;
pt.category = category;
pt.desc = description;
if (color != 0) {
pt.setColor(color);
}
points.add(pt);
modifiedTime = System.currentTimeMillis();
return pt;
}
public void updateWptPt(WptPt pt, double lat, double lon, long time, String description, String name, String category, int color) {
int index = points.indexOf(pt);
pt.lat = lat;
pt.lon = lon;
double latAdjusted = Double.parseDouble(latLonFormat.format(lat));
double lonAdjusted = Double.parseDouble(latLonFormat.format(lon));
pt.lat = latAdjusted;
pt.lon = lonAdjusted;
pt.time = time;
pt.desc = description;
pt.name = name;
@ -647,9 +667,11 @@ public class GPXUtilities {
if (index != -1) {
points.set(index, pt);
}
modifiedTime = System.currentTimeMillis();
}
public boolean deleteWptPt(WptPt pt) {
modifiedTime = System.currentTimeMillis();
return points.remove(pt);
}

View file

@ -27,6 +27,8 @@ import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.GPXTrackAnalysis;
import net.osmand.plus.GPXUtilities.TrkSegment;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
@ -169,6 +171,23 @@ public class GpxUiHelper {
return null;
}
public static AlertDialog selectSingleGPXFile(final Activity activity,
final boolean showCurrentGpx, final CallbackWithObject<GPXFile[]> callbackWithObject) {
OsmandApplication app = (OsmandApplication) activity.getApplication();
final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
final List<String> list = getSortedGPXFilenames(dir, false);
if (!list.isEmpty() || showCurrentGpx) {
if (showCurrentGpx) {
list.add(0, activity.getString(R.string.shared_string_currently_recording_track));
}
final ContextMenuAdapter adapter = createGpxContextMenuAdapter(activity, list, null, false,
showCurrentGpx);
return createDialog(activity, showCurrentGpx, false, callbackWithObject, list, adapter);
}
return null;
}
private static ContextMenuAdapter createGpxContextMenuAdapter(Activity activity, List<String> allGpxList,
List<String> selectedGpxList, boolean multipleChoice,
boolean showCurrentTrack) {
@ -342,7 +361,14 @@ public class GpxUiHelper {
if (showCurrentGpx && position == 0) {
callbackWithObject.processResult(null);
} else {
loadGPXFileInDifferentThread(activity, callbackWithObject, dir, null, list.get(position));
String fileName = list.get(position);
SelectedGpxFile selectedGpxFile =
app.getSelectedGpxHelper().getSelectedFileByName(fileName);
if (selectedGpxFile != null) {
callbackWithObject.processResult(new GPXFile[]{selectedGpxFile.getGpxFile()});
} else {
loadGPXFileInDifferentThread(activity, callbackWithObject, dir, null, fileName);
}
}
}
}

View file

@ -1,16 +1,21 @@
package net.osmand.plus.mapcontextmenu;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.LinearLayout;
import net.osmand.CallbackWithObject;
import net.osmand.IndexConstants;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.mapcontextmenu.MenuController.MenuState;
import net.osmand.plus.mapcontextmenu.MenuController.MenuType;
import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController;
@ -24,7 +29,9 @@ import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.util.MapUtils;
import java.io.File;
import java.lang.ref.WeakReference;
import java.util.List;
public class MapContextMenu extends MenuTitleController {
@ -398,7 +405,15 @@ public class MapContextMenu extends MenuTitleController {
if (pointDescription.isWpt() || title.equals(addressNotKnownStr)) {
title = "";
}
getWptPtPointEditor().add(latLon, title);
final File dir = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR);
final List<String> list = GpxUiHelper.getSortedGPXFilenames(dir, false);
if (list.isEmpty()) {
GPXFile gpxFile = mapActivity.getMyApplication().getSavingTrackHelper().getCurrentGpx();
getWptPtPointEditor().add(gpxFile, latLon, title);
} else {
addNewWptToGPXFile(title);
}
}
}
@ -408,6 +423,24 @@ public class MapContextMenu extends MenuTitleController {
}
}
public AlertDialog addNewWptToGPXFile(final String title) {
CallbackWithObject<GPXFile[]> callbackWithObject = new CallbackWithObject<GPXFile[]>() {
@Override
public boolean processResult(GPXFile[] result) {
GPXFile gpxFile;
if (result != null && result.length > 0) {
gpxFile = result[0];
} else {
gpxFile = mapActivity.getMyApplication().getSavingTrackHelper().getCurrentGpx();
}
getWptPtPointEditor().add(gpxFile, latLon, title);
return true;
}
};
return GpxUiHelper.selectSingleGPXFile(mapActivity, true, callbackWithObject);
}
public void setBaseFragmentVisibility(boolean visible) {
WeakReference<MapContextMenuFragment> fragmentRef = findMenuFragment();
if (fragmentRef != null) {

View file

@ -47,7 +47,6 @@ import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.util.Algorithms;
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
import static net.osmand.plus.mapcontextmenu.MenuBuilder.SHADOW_HEIGHT_BOTTOM_DP;
import static net.osmand.plus.mapcontextmenu.MenuBuilder.SHADOW_HEIGHT_TOP_DP;
@ -685,7 +684,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
menuTitleHeight = menuTopShadowHeight + menuTopShadowAllHeight + dy;
menuBottomViewHeight = view.findViewById(R.id.context_menu_bottom_view).getHeight();
menuFullHeightMax = menuTitleHeight + (menuBottomViewHeight > 0 ? menuBottomViewHeight : -dpToPx(SHADOW_HEIGHT_BOTTOM_DP));
menuFullHeightMax = menuTitleHeight + menuBottomViewHeight;
if (origMarkerX == 0 && origMarkerY == 0) {
origMarkerX = view.getWidth() / 2;
@ -802,7 +801,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
int posY = 0;
switch (destinationState) {
case MenuState.HEADER_ONLY:
posY = viewHeight - (menuTitleHeight - dpToPx(SHADOW_HEIGHT_BOTTOM_DP));
posY = viewHeight - menuTitleHeight;
break;
case MenuState.HALF_SCREEN:
posY = viewHeight - menuFullHeightMax;

View file

@ -31,7 +31,6 @@ import static android.util.TypedValue.COMPLEX_UNIT_DIP;
public class MenuBuilder {
public static final float SHADOW_HEIGHT_TOP_DP = 16f;
public static final float SHADOW_HEIGHT_BOTTOM_DP = 6f;
protected OsmandApplication app;
protected LinkedList<PlainMenuItem> plainMenuItems;

View file

@ -65,7 +65,7 @@ public abstract class PointEditorFragment extends Fragment {
}
});
Button saveButton = (Button)toolbar.findViewById(R.id.save_button);
Button saveButton = (Button) toolbar.findViewById(R.id.save_button);
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -73,7 +73,15 @@ public abstract class PointEditorFragment extends Fragment {
}
});
ImageButton deleteButton = (ImageButton)toolbar.findViewById(R.id.delete_button);
ImageButton okButton = (ImageButton) toolbar.findViewById(R.id.ok_button);
okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
savePressed();
}
});
ImageButton deleteButton = (ImageButton) toolbar.findViewById(R.id.delete_button);
deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -82,6 +90,7 @@ public abstract class PointEditorFragment extends Fragment {
});
if (getEditor().isNew()) {
okButton.setVisibility(View.GONE);
deleteButton.setVisibility(View.GONE);
} else {
saveButton.setVisibility(View.GONE);
@ -152,11 +161,10 @@ public abstract class PointEditorFragment extends Fragment {
@Override
public void onDestroyView() {
if (!wasSaved() && !getEditor().isNew()) {
save(false);
}
// if (!wasSaved() && !getEditor().isNew()) {
// save(false);
// }
super.onDestroyView();
getActivity().findViewById(R.id.MapHudButtonsOverlay).setVisibility(View.VISIBLE);
}

View file

@ -1,13 +1,16 @@
package net.osmand.plus.mapcontextmenu.editors;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.activities.MapActivity;
public class WptPtEditor extends PointEditor {
private GPXFile gpxFile;
private WptPt wpt;
private boolean gpxSelected;
public static final String TAG = "WptPtEditorFragment";
@ -20,15 +23,29 @@ public class WptPtEditor extends PointEditor {
return TAG;
}
public GPXFile getGpxFile() {
return gpxFile;
}
public boolean isGpxSelected() {
return gpxSelected;
}
public WptPt getWptPt() {
return wpt;
}
public void add(LatLon latLon, String title) {
public void add(GPXFile gpxFile, LatLon latLon, String title) {
if (latLon == null) {
return;
}
isNew = true;
this.gpxFile = gpxFile;
SelectedGpxFile selectedGpxFile =
mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpxFile.path);
gpxSelected = selectedGpxFile != null;
wpt = new WptPt(latLon.getLatitude(), latLon.getLongitude(),
System.currentTimeMillis(), Double.NaN, 0, Double.NaN);
wpt.name = title;
@ -40,6 +57,12 @@ public class WptPtEditor extends PointEditor {
return;
}
isNew = false;
SelectedGpxFile selectedGpxFile =
mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedGPXFile(wpt);
if (selectedGpxFile != null) {
gpxSelected = true;
gpxFile = selectedGpxFile.getGpxFile();
}
this.wpt = wpt;
WptPtEditorFragment.showInstance(mapActivity);
}

View file

@ -13,7 +13,6 @@ import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
@ -29,7 +28,6 @@ public class WptPtEditorFragment extends PointEditorFragment {
private WptPt wpt;
private SavingTrackHelper savingTrackHelper;
private GpxSelectionHelper selectedGpxHelper;
private SelectedGpxFile selectedGpxFile;
private boolean saved;
private int color;
@ -47,7 +45,6 @@ public class WptPtEditorFragment extends PointEditorFragment {
super.onCreate(savedInstanceState);
wpt = editor.getWptPt();
selectedGpxFile = selectedGpxHelper.getSelectedGPXFile(wpt);
int defaultColor = getResources().getColor(R.color.gpx_color_point);
color = wpt.getColor(defaultColor);
}
@ -104,12 +101,6 @@ public class WptPtEditorFragment extends PointEditorFragment {
menu.update(latLon, wpt.getPointDescription(getMapActivity()), wpt);
}
if (editor.isNew() && selectedGpxFile == null) {
selectedGpxHelper.setGpxFileToDisplay(savingTrackHelper.getCurrentGpx());
} else if (selectedGpxFile != null) {
selectedGpxHelper.setGpxFileToDisplay(selectedGpxFile.getGpxFile());
}
saved = true;
}
@ -120,22 +111,37 @@ public class WptPtEditorFragment extends PointEditorFragment {
if (color != 0) {
wpt.setColor(color);
}
wpt = savingTrackHelper.insertPointData(wpt.getLatitude(), wpt.getLongitude(), System.currentTimeMillis(), description, name, category, color);
}
private boolean isCurrentTrack() {
return selectedGpxFile != null && selectedGpxFile.isShowCurrentTrack();
GPXFile gpx = editor.getGpxFile();
if (gpx != null) {
if (gpx.showCurrentTrack) {
wpt = savingTrackHelper.insertPointData(wpt.getLatitude(), wpt.getLongitude(),
System.currentTimeMillis(), description, name, category, color);
if (!editor.isGpxSelected()) {
selectedGpxHelper.setGpxFileToDisplay(gpx);
}
} else {
wpt = gpx.addWptPt(wpt.getLatitude(), wpt.getLongitude(),
System.currentTimeMillis(), description, name, category, color);
new SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).execute();
}
}
}
private void doUpdateWpt(String name, String category, String description) {
if (isCurrentTrack()) {
savingTrackHelper.updatePointData(wpt, wpt.getLatitude(), wpt.getLongitude(),
System.currentTimeMillis(), description, name, category, color);
} else if (selectedGpxFile != null) {
GPXFile gpx = selectedGpxFile.getModifiableGpxFile();
gpx.updateWptPt(wpt, wpt.getLatitude(), wpt.getLongitude(),
System.currentTimeMillis(), description, name, category, color);
new SaveGpxAsyncTask(getMyApplication(), gpx).execute();
GPXFile gpx = editor.getGpxFile();
if (gpx != null) {
if (gpx.showCurrentTrack) {
savingTrackHelper.updatePointData(wpt, wpt.getLatitude(), wpt.getLongitude(),
System.currentTimeMillis(), description, name, category, color);
if (!editor.isGpxSelected()) {
selectedGpxHelper.setGpxFileToDisplay(gpx);
}
} else {
gpx.updateWptPt(wpt, wpt.getLatitude(), wpt.getLongitude(),
System.currentTimeMillis(), description, name, category, color);
new SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).execute();
}
}
}
@ -148,12 +154,14 @@ public class WptPtEditorFragment extends PointEditorFragment {
@Override
public void onClick(DialogInterface dialog, int which) {
if (isCurrentTrack()) {
savingTrackHelper.deletePointData(wpt);
} else {
GPXFile gpx = selectedGpxFile.getModifiableGpxFile();
gpx.deleteWptPt(wpt);
new SaveGpxAsyncTask(getMyApplication(), gpx).execute();
GPXFile gpx = editor.getGpxFile();
if (gpx != null) {
if (gpx.showCurrentTrack) {
savingTrackHelper.deletePointData(wpt);
} else {
gpx.deleteWptPt(wpt);
new SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).execute();
}
}
saved = true;
@ -212,13 +220,14 @@ public class WptPtEditorFragment extends PointEditorFragment {
}
private static class SaveGpxAsyncTask extends AsyncTask<Void, Void, Void> {
private final OsmandApplication app;
private final GPXFile gpx;
private final boolean gpxSelected;
public SaveGpxAsyncTask(OsmandApplication app, GPXFile gpx) {
public SaveGpxAsyncTask(OsmandApplication app, GPXFile gpx, boolean gpxSelected) {
this.app = app;
this.gpx = gpx;
this.gpxSelected = gpxSelected;
}
@Override
@ -226,5 +235,12 @@ public class WptPtEditorFragment extends PointEditorFragment {
GPXUtilities.writeGpxFile(new File(gpx.path), gpx, app);
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
if (!gpxSelected) {
app.getSelectedGpxHelper().setGpxFileToDisplay(gpx);
}
}
}
}