Add save as track dialog
This commit is contained in:
parent
fe195a238d
commit
dbfd5bb288
9 changed files with 353 additions and 5 deletions
|
@ -40,7 +40,7 @@
|
||||||
<uses-feature android:name="com.sec.feature.spen_usp" android:required="false"/>
|
<uses-feature android:name="com.sec.feature.spen_usp" android:required="false"/>
|
||||||
|
|
||||||
<uses-sdk android:targetSdkVersion="21" android:minSdkVersion="9"
|
<uses-sdk android:targetSdkVersion="21" android:minSdkVersion="9"
|
||||||
tools:overrideLibrary="com.getkeepsafe.taptargetview"/>
|
tools:overrideLibrary="com.getkeepsafe.taptargetview, studio.carbonylgroup.textfieldboxes"/>
|
||||||
|
|
||||||
<supports-screens android:resizeable="true" android:smallScreens="true" android:normalScreens="true" android:largeScreens="true"
|
<supports-screens android:resizeable="true" android:smallScreens="true" android:normalScreens="true" android:largeScreens="true"
|
||||||
android:xlargeScreens="true" android:anyDensity="true" />
|
android:xlargeScreens="true" android:anyDensity="true" />
|
||||||
|
|
|
@ -32,4 +32,5 @@
|
||||||
<string name="default_changeset_reopen">Reopen</string>
|
<string name="default_changeset_reopen">Reopen</string>
|
||||||
<string name="items_modified">items modified</string>
|
<string name="items_modified">items modified</string>
|
||||||
<string name="osmand_unlimited">OsmAnd Unlimited</string>
|
<string name="osmand_unlimited">OsmAnd Unlimited</string>
|
||||||
|
<string name="markers">Markers</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -0,0 +1,101 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:background="?attr/bg_color"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:id="@+id/marker_save_as_track_scroll_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/content_linear_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingBottom="@dimen/bottom_sheet_content_padding_small">
|
||||||
|
|
||||||
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
|
android:id="@+id/save_as_track_title"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/bottom_sheet_title_height"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:paddingEnd="@dimen/bottom_sheet_content_padding"
|
||||||
|
android:paddingLeft="@dimen/bottom_sheet_content_padding"
|
||||||
|
android:paddingRight="@dimen/bottom_sheet_content_padding"
|
||||||
|
android:paddingStart="@dimen/bottom_sheet_content_padding"
|
||||||
|
android:text="@string/marker_save_as_track"
|
||||||
|
android:textAppearance="@style/TextAppearance.ListItemTitle"
|
||||||
|
osmand:typeface="@string/font_roboto_medium"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/bottom_sheet_descr_height"
|
||||||
|
android:paddingEnd="@dimen/bottom_sheet_content_padding"
|
||||||
|
android:paddingLeft="@dimen/bottom_sheet_content_padding"
|
||||||
|
android:paddingRight="@dimen/bottom_sheet_content_padding"
|
||||||
|
android:paddingStart="@dimen/bottom_sheet_content_padding"
|
||||||
|
android:text="@string/marker_save_as_track_descr"
|
||||||
|
android:textColor="?android:textColorSecondary"
|
||||||
|
android:textSize="@dimen/default_desc_text_size"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:background="?attr/dashboard_divider"/>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/close_button"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_height="@dimen/bottom_sheet_cancel_button_height"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="@string/shared_string_cancel"
|
||||||
|
android:textAllCaps="true"
|
||||||
|
android:textColor="?attr/color_dialog_buttons"
|
||||||
|
android:textSize="@dimen/default_desc_text_size"
|
||||||
|
android:textStyle="bold"/>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="1dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="?attr/dashboard_divider"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/save_button"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_height="@dimen/bottom_sheet_cancel_button_height"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="@string/shared_string_save"
|
||||||
|
android:textAllCaps="true"
|
||||||
|
android:textColor="?attr/color_dialog_buttons"
|
||||||
|
android:textSize="@dimen/default_desc_text_size"
|
||||||
|
android:textStyle="bold"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
22
OsmAnd/res/layout/markers_track_name_edit_text.xml
Normal file
22
OsmAnd/res/layout/markers_track_name_edit_text.xml
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<?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="wrap_content">
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputLayout
|
||||||
|
android:paddingEnd="@dimen/bottom_sheet_content_padding"
|
||||||
|
android:paddingLeft="@dimen/bottom_sheet_content_padding"
|
||||||
|
android:paddingRight="@dimen/bottom_sheet_content_padding"
|
||||||
|
android:paddingStart="@dimen/bottom_sheet_content_padding"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/shared_string_name">
|
||||||
|
|
||||||
|
<android.support.design.widget.TextInputEditText
|
||||||
|
android:id="@+id/name_edit_text"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
23
OsmAnd/res/layout/markers_track_name_text_field_box.xml
Normal file
23
OsmAnd/res/layout/markers_track_name_text_field_box.xml
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<studio.carbonylgroup.textfieldboxes.TextFieldBoxes
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingEnd="@dimen/bottom_sheet_content_padding"
|
||||||
|
android:paddingLeft="@dimen/bottom_sheet_content_padding"
|
||||||
|
android:paddingRight="@dimen/bottom_sheet_content_padding"
|
||||||
|
android:paddingStart="@dimen/bottom_sheet_content_padding"
|
||||||
|
osmand:labelText="@string/shared_string_name">
|
||||||
|
|
||||||
|
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
|
||||||
|
android:id="@+id/name_edit_text"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
|
</studio.carbonylgroup.textfieldboxes.TextFieldBoxes>
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -9,6 +9,9 @@
|
||||||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
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
|
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="is_saved">is saved</string>
|
||||||
|
<string name="marker_save_as_track_descr">OsmAnd will save all your markers to a separate file, you can enter filename:</string>
|
||||||
|
<string name="marker_save_as_track">Save as track</string>
|
||||||
<string name="move_to_history">Move to history</string>
|
<string name="move_to_history">Move to history</string>
|
||||||
<string name="group_will_be_removed_after_restart">Group will be removed after restart</string>
|
<string name="group_will_be_removed_after_restart">Group will be removed after restart</string>
|
||||||
<string name="show_guide_line">Show guide line</string>
|
<string name="show_guide_line">Show guide line</string>
|
||||||
|
|
|
@ -829,13 +829,11 @@ public class MapMarkersHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generateGpx() {
|
public String generateGpx(String fileName) {
|
||||||
final File dir = ctx.getAppPath(IndexConstants.GPX_INDEX_DIR + "/map markers");
|
final File dir = ctx.getAppPath(IndexConstants.GPX_INDEX_DIR + "/map markers");
|
||||||
if (!dir.exists()) {
|
if (!dir.exists()) {
|
||||||
dir.mkdirs();
|
dir.mkdirs();
|
||||||
}
|
}
|
||||||
Date date = new Date();
|
|
||||||
String fileName = DateFormat.format("yyyy-MM-dd", date).toString() + "_" + new SimpleDateFormat("HH-mm_EEE", Locale.US).format(date);
|
|
||||||
File fout = new File(dir, fileName + ".gpx");
|
File fout = new File(dir, fileName + ".gpx");
|
||||||
int ind = 1;
|
int ind = 1;
|
||||||
while (fout.exists()) {
|
while (fout.exists()) {
|
||||||
|
@ -851,6 +849,7 @@ public class MapMarkersHelper {
|
||||||
file.addPoint(wpt);
|
file.addPoint(wpt);
|
||||||
}
|
}
|
||||||
GPXUtilities.writeGpxFile(fout, file, ctx);
|
GPXUtilities.writeGpxFile(fout, file, ctx);
|
||||||
|
return fout.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeHistoryMarkersFromGroups() {
|
private void removeHistoryMarkersFromGroups() {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.osmand.plus.mapmarkers;
|
package net.osmand.plus.mapmarkers;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
@ -16,6 +17,8 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import net.osmand.IndexConstants;
|
||||||
|
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||||
import net.osmand.plus.LockableViewPager;
|
import net.osmand.plus.LockableViewPager;
|
||||||
import net.osmand.plus.MapMarkersHelper;
|
import net.osmand.plus.MapMarkersHelper;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
@ -23,11 +26,14 @@ import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.OsmandSettings.MapMarkersOrderByMode;
|
import net.osmand.plus.OsmandSettings.MapMarkersOrderByMode;
|
||||||
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.TrackActivity;
|
||||||
import net.osmand.plus.dashboard.DashboardOnMap;
|
import net.osmand.plus.dashboard.DashboardOnMap;
|
||||||
import net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.MarkerOptionsFragmentListener;
|
import net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.MarkerOptionsFragmentListener;
|
||||||
import net.osmand.plus.mapmarkers.OrderByBottomSheetDialogFragment.OrderByFragmentListener;
|
import net.osmand.plus.mapmarkers.OrderByBottomSheetDialogFragment.OrderByFragmentListener;
|
||||||
|
import net.osmand.plus.mapmarkers.SaveAsTrackBottomSheetDialogFragment.MarkerSaveAsTrackFragmentListener;
|
||||||
import net.osmand.plus.mapmarkers.ShowDirectionBottomSheetDialogFragment.ShowDirectionFragmentListener;
|
import net.osmand.plus.mapmarkers.ShowDirectionBottomSheetDialogFragment.ShowDirectionFragmentListener;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -92,6 +98,10 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
|
||||||
if (orderByFragment != null) {
|
if (orderByFragment != null) {
|
||||||
((OrderByBottomSheetDialogFragment) orderByFragment).setListener(createOrderByFragmentListener());
|
((OrderByBottomSheetDialogFragment) orderByFragment).setListener(createOrderByFragmentListener());
|
||||||
}
|
}
|
||||||
|
Fragment saveAsTrackFragment = fragmentManager.findFragmentByTag(SaveAsTrackBottomSheetDialogFragment.TAG);
|
||||||
|
if (saveAsTrackFragment != null) {
|
||||||
|
((SaveAsTrackBottomSheetDialogFragment) saveAsTrackFragment).setListener(createSaveAsTrackFragmentListener());
|
||||||
|
}
|
||||||
|
|
||||||
View mainView = inflater.inflate(R.layout.fragment_map_markers_dialog, container);
|
View mainView = inflater.inflate(R.layout.fragment_map_markers_dialog, container);
|
||||||
|
|
||||||
|
@ -201,7 +211,9 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveAsNewTrackOnClick() {
|
public void saveAsNewTrackOnClick() {
|
||||||
mapActivity.getMyApplication().getMapMarkersHelper().generateGpx();
|
SaveAsTrackBottomSheetDialogFragment fragment = new SaveAsTrackBottomSheetDialogFragment();
|
||||||
|
fragment.setListener(createSaveAsTrackFragmentListener());
|
||||||
|
fragment.show(mapActivity.getSupportFragmentManager(), SaveAsTrackBottomSheetDialogFragment.TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -240,6 +252,33 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MarkerSaveAsTrackFragmentListener createSaveAsTrackFragmentListener() {
|
||||||
|
return new MarkerSaveAsTrackFragmentListener() {
|
||||||
|
|
||||||
|
final MapActivity mapActivity = getMapActivity();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveGpx(final String fileName) {
|
||||||
|
final String gpxPath = mapActivity.getMyApplication().getMapMarkersHelper().generateGpx(fileName);
|
||||||
|
snackbar = Snackbar.make(viewPager, fileName + " " + getString(R.string.is_saved) + ".", Snackbar.LENGTH_LONG)
|
||||||
|
.setAction(R.string.shared_string_show, new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
Intent intent = new Intent(mapActivity, getMyApplication().getAppCustomization().getTrackActivity());
|
||||||
|
intent.putExtra(TrackActivity.TRACK_FILE_NAME, gpxPath);
|
||||||
|
intent.putExtra(TrackActivity.OPEN_POINTS_TAB, true);
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
View snackBarView = snackbar.getView();
|
||||||
|
TextView tv = (TextView) snackBarView.findViewById(android.support.design.R.id.snackbar_action);
|
||||||
|
tv.setTextColor(ContextCompat.getColor(mapActivity, R.color.color_dialog_buttons_dark));
|
||||||
|
snackbar.show();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private OrderByFragmentListener createOrderByFragmentListener() {
|
private OrderByFragmentListener createOrderByFragmentListener() {
|
||||||
return new OrderByFragmentListener() {
|
return new OrderByFragmentListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,160 @@
|
||||||
|
package net.osmand.plus.mapmarkers;
|
||||||
|
|
||||||
|
import android.os.Build;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.text.format.DateFormat;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.ContextThemeWrapper;
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.view.ViewTreeObserver;
|
||||||
|
import android.view.Window;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
|
import net.osmand.AndroidUtils;
|
||||||
|
import net.osmand.IndexConstants;
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.activities.MapActivity;
|
||||||
|
import net.osmand.plus.base.BottomSheetDialogFragment;
|
||||||
|
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import studio.carbonylgroup.textfieldboxes.ExtendedEditText;
|
||||||
|
|
||||||
|
import static net.osmand.plus.helpers.GpxImportHelper.GPX_SUFFIX;
|
||||||
|
|
||||||
|
public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragment {
|
||||||
|
|
||||||
|
public final static String TAG = "SaveAsTrackBottomSheetDialogFragment";
|
||||||
|
|
||||||
|
private boolean portrait;
|
||||||
|
private MarkerSaveAsTrackFragmentListener listener;
|
||||||
|
|
||||||
|
public void setListener(MarkerSaveAsTrackFragmentListener listener) {
|
||||||
|
this.listener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
MapActivity mapActivity = (MapActivity) getActivity();
|
||||||
|
portrait = AndroidUiHelper.isOrientationPortrait(getActivity());
|
||||||
|
boolean nightMode = !getMyApplication().getSettings().isLightContent();
|
||||||
|
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||||
|
|
||||||
|
final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_save_as_track_bottom_sheet_dialog, container);
|
||||||
|
LinearLayout contentLayout = (LinearLayout) mainView.findViewById(R.id.content_linear_layout);
|
||||||
|
int layoutRes;
|
||||||
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||||
|
layoutRes = R.layout.markers_track_name_text_field_box;
|
||||||
|
} else {
|
||||||
|
layoutRes = R.layout.markers_track_name_edit_text;
|
||||||
|
}
|
||||||
|
contentLayout.addView(getLayoutInflater().inflate(layoutRes, contentLayout, false), 2);
|
||||||
|
if (portrait) {
|
||||||
|
AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
|
||||||
|
}
|
||||||
|
|
||||||
|
final File dir = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR + "/map markers");
|
||||||
|
if (!dir.exists()) {
|
||||||
|
dir.mkdirs();
|
||||||
|
}
|
||||||
|
Date date = new Date();
|
||||||
|
final String suggestedName = mapActivity.getString(R.string.markers) + "_" + DateFormat.format("dd_MM_yyyy", date).toString();
|
||||||
|
String displayedName = suggestedName;
|
||||||
|
File fout = new File(dir, suggestedName + GPX_SUFFIX);
|
||||||
|
int ind = 1;
|
||||||
|
while (fout.exists()) {
|
||||||
|
displayedName = suggestedName + "_" + (++ind);
|
||||||
|
fout = new File(dir, displayedName + GPX_SUFFIX);
|
||||||
|
}
|
||||||
|
final EditText nameEditText = (EditText) mainView.findViewById(R.id.name_edit_text);
|
||||||
|
nameEditText.setText(displayedName);
|
||||||
|
nameEditText.requestFocus();
|
||||||
|
|
||||||
|
mainView.findViewById(R.id.save_button).setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
if (listener != null) {
|
||||||
|
listener.saveGpx(nameEditText.getText().toString());
|
||||||
|
}
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mainView.findViewById(R.id.close_button).setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
final int screenHeight = AndroidUtils.getScreenHeight(getActivity());
|
||||||
|
final int statusBarHeight = AndroidUtils.getStatusBarHeight(getActivity());
|
||||||
|
final int navBarHeight = AndroidUtils.getNavBarHeight(getActivity());
|
||||||
|
|
||||||
|
mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||||
|
|
||||||
|
boolean dimensSet;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGlobalLayout() {
|
||||||
|
if (!dimensSet) {
|
||||||
|
final View scrollView = mainView.findViewById(R.id.marker_save_as_track_scroll_view);
|
||||||
|
int scrollViewHeight = scrollView.getHeight();
|
||||||
|
int dividerHeight = AndroidUtils.dpToPx(getContext(), 1);
|
||||||
|
int cancelButtonHeight = getContext().getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height);
|
||||||
|
int spaceForScrollView = screenHeight - statusBarHeight - navBarHeight - dividerHeight - cancelButtonHeight;
|
||||||
|
if (scrollViewHeight > spaceForScrollView) {
|
||||||
|
scrollView.getLayoutParams().height = spaceForScrollView;
|
||||||
|
scrollView.requestLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!portrait) {
|
||||||
|
if (screenHeight - statusBarHeight - mainView.getHeight()
|
||||||
|
>= AndroidUtils.dpToPx(getActivity(), 8)) {
|
||||||
|
AndroidUtils.setBackground(getActivity(), mainView, false,
|
||||||
|
R.drawable.bg_bottom_sheet_topsides_landscape_light, R.drawable.bg_bottom_sheet_topsides_landscape_dark);
|
||||||
|
} else {
|
||||||
|
AndroidUtils.setBackground(getActivity(), mainView, false,
|
||||||
|
R.drawable.bg_bottom_sheet_sides_landscape_light, R.drawable.bg_bottom_sheet_sides_landscape_dark);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dimensSet = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Window window = getDialog().getWindow();
|
||||||
|
WindowManager.LayoutParams params = window.getAttributes();
|
||||||
|
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||||
|
params.gravity = Gravity.BOTTOM;
|
||||||
|
window.setAttributes(params);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return mainView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
super.onStart();
|
||||||
|
if (!portrait) {
|
||||||
|
final Window window = getDialog().getWindow();
|
||||||
|
WindowManager.LayoutParams params = window.getAttributes();
|
||||||
|
params.width = getActivity().getResources().getDimensionPixelSize(R.dimen.landscape_bottom_sheet_dialog_fragment_width);
|
||||||
|
window.setAttributes(params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MarkerSaveAsTrackFragmentListener {
|
||||||
|
void saveGpx(String fileName);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue