From 5e68d14273ff365a4840e556051fd6d3ab573615 Mon Sep 17 00:00:00 2001
From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com>
Date: Sun, 24 Jan 2021 19:30:44 +0200
Subject: [PATCH 01/22] Change UI for graph toggle
Change UI for graph toggle (Overview | Altitude | Speed). The same toggle is used in Configure Map -> Terrain.
---
OsmAnd/res/layout/center_button_container.xml | 19 ++++
OsmAnd/res/layout/custom_radio_buttons.xml | 56 +-----------
.../res/layout/gpx_list_item_tab_content.xml | 2 +-
OsmAnd/res/layout/left_button_container.xml | 20 +++++
OsmAnd/res/layout/right_button_container.xml | 19 ++++
OsmAnd/src/net/osmand/plus/UiUtilities.java | 87 +++++++++++++++++++
.../plus/myplaces/GPXItemPagerAdapter.java | 74 +++++++++++-----
.../views/controls/PagerSlidingTabStrip.java | 14 +--
8 files changed, 210 insertions(+), 81 deletions(-)
create mode 100644 OsmAnd/res/layout/center_button_container.xml
create mode 100644 OsmAnd/res/layout/left_button_container.xml
create mode 100644 OsmAnd/res/layout/right_button_container.xml
diff --git a/OsmAnd/res/layout/center_button_container.xml b/OsmAnd/res/layout/center_button_container.xml
new file mode 100644
index 0000000000..8c8fdf1617
--- /dev/null
+++ b/OsmAnd/res/layout/center_button_container.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/custom_radio_buttons.xml b/OsmAnd/res/layout/custom_radio_buttons.xml
index d768e58004..d4bd1c8082 100644
--- a/OsmAnd/res/layout/custom_radio_buttons.xml
+++ b/OsmAnd/res/layout/custom_radio_buttons.xml
@@ -1,6 +1,5 @@
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/gpx_list_item_tab_content.xml b/OsmAnd/res/layout/gpx_list_item_tab_content.xml
index d2ce779b8b..fbe7bf5e1c 100644
--- a/OsmAnd/res/layout/gpx_list_item_tab_content.xml
+++ b/OsmAnd/res/layout/gpx_list_item_tab_content.xml
@@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
-
+
+
+
+
+
+
diff --git a/OsmAnd/res/layout/right_button_container.xml b/OsmAnd/res/layout/right_button_container.xml
new file mode 100644
index 0000000000..bb618949af
--- /dev/null
+++ b/OsmAnd/res/layout/right_button_container.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java
index 94bd3c4bcb..7c9546d93d 100644
--- a/OsmAnd/src/net/osmand/plus/UiUtilities.java
+++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java
@@ -90,6 +90,12 @@ public class UiUtilities {
END,
}
+ public enum CustomRadioButtonTypeGroup {
+ START,
+ CENTER,
+ END,
+ }
+
public UiUtilities(OsmandApplication app) {
this.app = app;
}
@@ -484,6 +490,87 @@ public class UiUtilities {
}
}
+ public static void updateCustomRadioButtonsGroup(Context app, View buttonsView, boolean nightMode,
+ CustomRadioButtonTypeGroup buttonType) {
+ int activeColor = ContextCompat.getColor(app, nightMode
+ ? R.color.active_color_primary_dark
+ : R.color.active_color_primary_light);
+ int inActiveColor = ContextCompat.getColor(app, nightMode
+ ? R.color.text_color_secondary_dark
+ : R.color.text_color_secondary_light);
+ int textColor = ContextCompat.getColor(app, nightMode
+ ? R.color.text_color_primary_dark
+ : R.color.text_color_primary_light);
+ int roundedCorner = AndroidUtils.dpToPx(app, 4);
+ boolean isLayoutRtl = AndroidUtils.isLayoutRtl(app);
+
+ TextView startButtonText = buttonsView.findViewById(R.id.left_button);
+ View startButtonContainer = buttonsView.findViewById(R.id.left_button_container);
+ TextView centerButtonText = buttonsView.findViewById(R.id.center_button);
+ View centerButtonContainer = buttonsView.findViewById(R.id.center_button_container);
+ TextView endButtonText = buttonsView.findViewById(R.id.right_button);
+ View endButtonContainer = buttonsView.findViewById(R.id.right_button_container);
+ GradientDrawable background = new GradientDrawable();
+ background.setColor(UiUtilities.getColorWithAlpha(activeColor, 0.1f));
+ background.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(activeColor, 0.5f));
+ GradientDrawable startButtonSharpCorner = new GradientDrawable();
+ startButtonSharpCorner.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(inActiveColor, 0.5f));
+ GradientDrawable endButtonRoundedCorner = new GradientDrawable();
+ endButtonRoundedCorner.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(inActiveColor, 0.5f));
+ GradientDrawable centerButtonSharpCorner = new GradientDrawable();
+ centerButtonSharpCorner.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(inActiveColor, 0.5f));
+ setStartEndCenterRoundedCorner(roundedCorner, isLayoutRtl, startButtonSharpCorner, endButtonRoundedCorner, centerButtonSharpCorner);
+
+ if (buttonType == CustomRadioButtonTypeGroup.START) {
+ if (isLayoutRtl) {
+ background.setCornerRadii(new float[]{0, 0, roundedCorner, roundedCorner, roundedCorner, roundedCorner, 0, 0});
+ } else {
+ background.setCornerRadii(new float[]{roundedCorner, roundedCorner, 0, 0, 0, 0, roundedCorner, roundedCorner});
+ }
+ endButtonContainer.setBackground(endButtonRoundedCorner);
+ endButtonText.setTextColor(activeColor);
+ centerButtonContainer.setBackground(centerButtonSharpCorner);
+ centerButtonText.setTextColor(activeColor);
+ endButtonText.setTextColor(activeColor);
+ startButtonContainer.setBackgroundDrawable(background);
+ startButtonText.setTextColor(textColor);
+ } else if (buttonType == CustomRadioButtonTypeGroup.CENTER){
+ endButtonContainer.setBackground(endButtonRoundedCorner);
+ endButtonText.setTextColor(activeColor);
+ startButtonContainer.setBackground(startButtonSharpCorner);
+ startButtonText.setTextColor(activeColor);
+ endButtonText.setTextColor(activeColor);
+ centerButtonContainer.setBackgroundDrawable(background);
+ centerButtonText.setTextColor(textColor);
+ } else {
+ if (isLayoutRtl) {
+ background.setCornerRadii(new float[]{roundedCorner, roundedCorner, 0, 0, 0, 0, roundedCorner, roundedCorner});
+ } else {
+ background.setCornerRadii(new float[]{0, 0, roundedCorner, roundedCorner, roundedCorner, roundedCorner, 0, 0});
+ }
+ endButtonContainer.setBackgroundDrawable(background);
+ endButtonText.setTextColor(textColor);
+ startButtonContainer.setBackground(startButtonSharpCorner);
+ startButtonText.setTextColor(activeColor);
+ centerButtonContainer.setBackground(centerButtonSharpCorner);
+ centerButtonText.setTextColor(activeColor);
+ }
+ }
+
+ private static void setStartEndCenterRoundedCorner(int roundedCorner, boolean isLayoutRtl, GradientDrawable startButtonRoundedCorner, GradientDrawable endButtonRoundedCorner, GradientDrawable centerButtonSharpCorner) {
+ if (isLayoutRtl) {
+ startButtonRoundedCorner.setCornerRadii(new float[]{0, 0, roundedCorner, roundedCorner, roundedCorner, roundedCorner, 0, 0});
+ } else {
+ startButtonRoundedCorner.setCornerRadii(new float[]{roundedCorner, roundedCorner, 0, 0, 0, 0, roundedCorner, roundedCorner});
+ }
+ if (isLayoutRtl) {
+ endButtonRoundedCorner.setCornerRadii(new float[]{roundedCorner, roundedCorner, 0, 0, 0, 0, roundedCorner, roundedCorner});
+ } else {
+ endButtonRoundedCorner.setCornerRadii(new float[]{0, 0, roundedCorner, roundedCorner, roundedCorner, roundedCorner, 0, 0});
+ }
+ centerButtonSharpCorner.setCornerRadii(new float[]{0, 0, 0, 0, 0, 0, 0, 0});
+ }
+
public static void setupCompoundButtonDrawable(Context ctx, boolean nightMode, @ColorInt int activeColor, Drawable drawable) {
int inactiveColor = ContextCompat.getColor(ctx, nightMode ? R.color.icon_color_default_dark : R.color.icon_color_default_light);
int[][] states = new int[][]{
diff --git a/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java b/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java
index 81d9ee9d72..8cd70de903 100644
--- a/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java
+++ b/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java
@@ -13,6 +13,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.SwitchCompat;
import androidx.viewpager.widget.PagerAdapter;
+import androidx.viewpager.widget.ViewPager.OnPageChangeListener;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.Entry;
@@ -23,6 +24,7 @@ import com.github.mikephil.charting.listener.ChartTouchListener.ChartGesture;
import com.github.mikephil.charting.listener.OnChartGestureListener;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
+import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.GPXTrackAnalysis;
@@ -78,7 +80,7 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
private boolean chartClicked;
- public GPXItemPagerAdapter(@NonNull PagerSlidingTabStrip tabs,
+ public GPXItemPagerAdapter(@NonNull final PagerSlidingTabStrip tabs,
@NonNull GpxDisplayItem gpxItem,
@NonNull TrackDisplayHelper displayHelper,
@NonNull SegmentActionsListener actionsListener) {
@@ -89,6 +91,34 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
this.actionsListener = actionsListener;
app = (OsmandApplication) tabs.getContext().getApplicationContext();
iconsCache = app.getUIUtilities();
+
+ tabs.setOnPageChangeListener(new OnPageChangeListener() {
+
+ @Override
+ public void onPageSelected(int arg0) {
+ UiUtilities.CustomRadioButtonTypeGroup type;
+ if (arg0 == 0) {
+ type = UiUtilities.CustomRadioButtonTypeGroup.START;
+ } else if (arg0 == 1) {
+ type = UiUtilities.CustomRadioButtonTypeGroup.CENTER;
+ } else {
+ type = UiUtilities.CustomRadioButtonTypeGroup.END;
+ }
+
+ View parent = (View) tabs.getChildAt(0);
+ UiUtilities.updateCustomRadioButtonsGroup(app, parent, false, type);
+ }
+
+ @Override
+ public void onPageScrolled(int arg0, float arg1, int arg2) {
+ }
+
+ @Override
+ public void onPageScrollStateChanged(int arg0) {
+
+ }
+ });
+
fetchTabTypes();
}
@@ -588,7 +618,15 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
@Override
public View getCustomTabView(@NonNull ViewGroup parent, int position) {
- View tab = LayoutInflater.from(parent.getContext()).inflate(R.layout.gpx_tab, parent, false);
+ int layoutId;
+ if (position == 0) {
+ layoutId = R.layout.left_button_container;
+ } else if (position == 1) {
+ layoutId = R.layout.center_button_container;
+ } else {
+ layoutId = R.layout.right_button_container;
+ }
+ View tab = LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false);
tab.setTag(tabTypes[position].name());
deselect(tab);
return tab;
@@ -597,29 +635,25 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
@Override
public void select(View tab) {
GPXTabItemType tabType = GPXTabItemType.valueOf((String) tab.getTag());
- ImageView img = tab.findViewById(R.id.tab_image);
- switch (tabs.getTabSelectionType()) {
- case ALPHA:
- img.setAlpha(tabs.getTabTextSelectedAlpha());
- break;
- case SOLID_COLOR:
- img.setImageDrawable(iconsCache.getPaintedIcon(tabType.getIconId(), tabs.getTextColor()));
- break;
+ UiUtilities.CustomRadioButtonTypeGroup type;
+ if (tabType == GPXTabItemType.GPX_TAB_ITEM_GENERAL) {
+ type = UiUtilities.CustomRadioButtonTypeGroup.START;
+ } else if (tabType == GPXTabItemType.GPX_TAB_ITEM_ALTITUDE) {
+ type = UiUtilities.CustomRadioButtonTypeGroup.CENTER;
+ } else {
+ type = UiUtilities.CustomRadioButtonTypeGroup.END;
}
+ View parent = (View) tab.getParent();
+ UiUtilities.updateCustomRadioButtonsGroup(app,parent , false, type);
+
+ ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) parent.getLayoutParams();
+ int contentPadding = app.getResources().getDimensionPixelSize(R.dimen.content_padding);
+ int containerMargin = app.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_margin_small);
+ AndroidUtils.setMargins(params, contentPadding, containerMargin, contentPadding, containerMargin);
}
@Override
public void deselect(View tab) {
- GPXTabItemType tabType = GPXTabItemType.valueOf((String) tab.getTag());
- ImageView img = tab.findViewById(R.id.tab_image);
- switch (tabs.getTabSelectionType()) {
- case ALPHA:
- img.setAlpha(tabs.getTabTextAlpha());
- break;
- case SOLID_COLOR:
- img.setImageDrawable(iconsCache.getPaintedIcon(tabType.getIconId(), tabs.getTabInactiveTextColor()));
- break;
- }
}
@Override
diff --git a/OsmAnd/src/net/osmand/plus/views/controls/PagerSlidingTabStrip.java b/OsmAnd/src/net/osmand/plus/views/controls/PagerSlidingTabStrip.java
index a92d2c5e0a..e38a8619b0 100644
--- a/OsmAnd/src/net/osmand/plus/views/controls/PagerSlidingTabStrip.java
+++ b/OsmAnd/src/net/osmand/plus/views/controls/PagerSlidingTabStrip.java
@@ -352,13 +352,6 @@ public class PagerSlidingTabStrip extends HorizontalScrollView {
tab_title.setTextColor(pager.getCurrentItem() == i ? tabTextColor : tabInactiveTextColor);
break;
}
- if (pager.getAdapter() instanceof CustomTabProvider) {
- if (pager.getCurrentItem() == i) {
- ((CustomTabProvider) pager.getAdapter()).select(v);
- } else {
- ((CustomTabProvider) pager.getAdapter()).deselect(v);
- }
- }
// setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
// pre-ICS-build
@@ -370,6 +363,13 @@ public class PagerSlidingTabStrip extends HorizontalScrollView {
}
}
}
+ if (pager.getAdapter() instanceof CustomTabProvider) {
+ if (pager.getCurrentItem() == i) {
+ ((CustomTabProvider) pager.getAdapter()).select(v);
+ } else {
+ ((CustomTabProvider) pager.getAdapter()).deselect(v);
+ }
+ }
}
}
From 3c6b065f50e62d4d1f62a3f123db93b70472afc6 Mon Sep 17 00:00:00 2001
From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com>
Date: Sun, 24 Jan 2021 23:36:55 +0200
Subject: [PATCH 02/22] null exeption fix
---
.../res/layout/gpx_list_item_tab_content.xml | 2 +-
OsmAnd/src/net/osmand/plus/UiUtilities.java | 64 +++++++++++++------
.../plus/myplaces/GPXItemPagerAdapter.java | 2 +-
.../plus/myplaces/SegmentGPXAdapter.java | 8 +--
4 files changed, 47 insertions(+), 29 deletions(-)
diff --git a/OsmAnd/res/layout/gpx_list_item_tab_content.xml b/OsmAnd/res/layout/gpx_list_item_tab_content.xml
index fbe7bf5e1c..d2ce779b8b 100644
--- a/OsmAnd/res/layout/gpx_list_item_tab_content.xml
+++ b/OsmAnd/res/layout/gpx_list_item_tab_content.xml
@@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
-
+
{
PagerSlidingTabStrip tabLayout = row.findViewById(R.id.sliding_tabs);
tabLayout.setTabBackground(R.color.color_transparent);
- tabLayout.setIndicatorColorResource(nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light);
- tabLayout.setIndicatorBgColorResource(nightMode ? R.color.divider_color_dark : R.color.divider_color_light);
- tabLayout.setIndicatorHeight(AndroidUtils.dpToPx(context, 1f));
- if (!nightMode) {
- tabLayout.setTextColor(tabLayout.getIndicatorColor());
- tabLayout.setTabInactiveTextColor(ContextCompat.getColor(row.getContext(), R.color.text_color_secondary_light));
- }
+ tabLayout.setIndicatorHeight(AndroidUtils.dpToPx(context, 0));
tabLayout.setTextSize(AndroidUtils.spToPx(context, 12f));
tabLayout.setShouldExpand(true);
WrapContentHeightViewPager pager = row.findViewById(R.id.pager);
From 2cdb8953f6af0c3c679cb2f186a03255b3bf830c Mon Sep 17 00:00:00 2001
From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com>
Date: Sun, 24 Jan 2021 23:54:44 +0200
Subject: [PATCH 03/22] Update UiUtilities.java
---
OsmAnd/src/net/osmand/plus/UiUtilities.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java
index 3890725d8a..43c6ca94c5 100644
--- a/OsmAnd/src/net/osmand/plus/UiUtilities.java
+++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java
@@ -560,7 +560,7 @@ public class UiUtilities {
endButtonContainer.setBackground(endButtonRoundedCorner);
endButtonText.setTextColor(activeColor);
} else {
- endButtonRoundedCorner.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(inActiveColor, 0.5f));
+ endButtonRoundedCorner.setColor(UiUtilities.getColorWithAlpha(activeColor, 0.1f));
centerButtonContainer.setBackgroundDrawable(endButtonRoundedCorner);
centerButtonText.setTextColor(textColor);
}
From 0bc61f85c1d3d387df504e62fdb0f5f1c4f6341d Mon Sep 17 00:00:00 2001
From: Skalii
Date: Thu, 28 Jan 2021 01:48:44 +0200
Subject: [PATCH 04/22] fix saving correct icon and background type of
waypoints after saving current recording track
---
.../plus/activities/SavingTrackHelper.java | 137 ++++++++++--------
1 file changed, 75 insertions(+), 62 deletions(-)
diff --git a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java
index ff7039702e..b06d3bb1a5 100644
--- a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java
+++ b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java
@@ -38,10 +38,10 @@ import java.util.Locale;
import java.util.Map;
public class SavingTrackHelper extends SQLiteOpenHelper {
-
+
public final static String DATABASE_NAME = "tracks"; //$NON-NLS-1$
- public final static int DATABASE_VERSION = 6;
-
+ public final static int DATABASE_VERSION = 7;
+
public final static String TRACK_NAME = "track"; //$NON-NLS-1$
public final static String TRACK_COL_DATE = "date"; //$NON-NLS-1$
public final static String TRACK_COL_LAT = "lat"; //$NON-NLS-1$
@@ -50,7 +50,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
public final static String TRACK_COL_SPEED = "speed"; //$NON-NLS-1$
public final static String TRACK_COL_HDOP = "hdop"; //$NON-NLS-1$
public final static String TRACK_COL_HEADING = "heading"; //$NON-NLS-1$
-
+
public final static String POINT_NAME = "point"; //$NON-NLS-1$
public final static String POINT_COL_DATE = "date"; //$NON-NLS-1$
public final static String POINT_COL_LAT = "lat"; //$NON-NLS-1$
@@ -59,7 +59,9 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
public final static String POINT_COL_CATEGORY = "category"; //$NON-NLS-1$
public final static String POINT_COL_DESCRIPTION = "description"; //$NON-NLS-1$
public final static String POINT_COL_COLOR = "color"; //$NON-NLS-1$
-
+ public final static String POINT_COL_ICON = "icon"; //$NON-NLS-1$
+ public final static String POINT_COL_BACKGROUND = "background"; //$NON-NLS-1$
+
public final static float NO_HEADING = -1.0f;
public final static Log log = PlatformUtil.getLog(SavingTrackHelper.class);
@@ -76,8 +78,8 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
private SelectedGpxFile currentTrack;
private int points;
private int trkPoints = 0;
-
- public SavingTrackHelper(OsmandApplication ctx){
+
+ public SavingTrackHelper(OsmandApplication ctx) {
super(ctx, DATABASE_NAME, null, DATABASE_VERSION);
this.ctx = ctx;
this.currentTrack = new SelectedGpxFile();
@@ -88,11 +90,11 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
prepareCurrentTrackForRecording();
updateScript = "INSERT INTO " + TRACK_NAME + " (" + TRACK_COL_LAT + ", " + TRACK_COL_LON + ", "
- + TRACK_COL_ALTITUDE + ", " + TRACK_COL_SPEED + ", " + TRACK_COL_HDOP + ", "
- + TRACK_COL_DATE + ", " + TRACK_COL_HEADING + ")"
+ + TRACK_COL_ALTITUDE + ", " + TRACK_COL_SPEED + ", " + TRACK_COL_HDOP + ", "
+ + TRACK_COL_DATE + ", " + TRACK_COL_HEADING + ")"
+ " VALUES (?, ?, ?, ?, ?, ?, ?)"; //$NON-NLS-1$ //$NON-NLS-2$
- insertPointsScript = "INSERT INTO " + POINT_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?)"; //$NON-NLS-1$ //$NON-NLS-2$
+ insertPointsScript = "INSERT INTO " + POINT_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; //$NON-NLS-1$ //$NON-NLS-2$
}
@Override
@@ -100,19 +102,19 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
createTableForTrack(db);
createTableForPoints(db);
}
-
- private void createTableForTrack(SQLiteDatabase db){
+
+ private void createTableForTrack(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TRACK_NAME + " (" + TRACK_COL_LAT + " double, " + TRACK_COL_LON + " double, " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ TRACK_COL_ALTITUDE + " double, " + TRACK_COL_SPEED + " double, " //$NON-NLS-1$ //$NON-NLS-2$
+ TRACK_COL_HDOP + " double, " + TRACK_COL_DATE + " long, "
+ TRACK_COL_HEADING + " float )"); //$NON-NLS-1$ //$NON-NLS-2$
}
-
- private void createTableForPoints(SQLiteDatabase db){
+
+ private void createTableForPoints(SQLiteDatabase db) {
try {
db.execSQL("CREATE TABLE " + POINT_NAME + " (" + POINT_COL_LAT + " double, " + POINT_COL_LON + " double, " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ POINT_COL_DATE + " long, " + POINT_COL_DESCRIPTION + " text, " + POINT_COL_NAME + " text, "
- + POINT_COL_CATEGORY + " text, " + POINT_COL_COLOR + " long" + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ + POINT_COL_CATEGORY + " text, " + POINT_COL_COLOR + " long, " + POINT_COL_ICON + " text, " + POINT_COL_BACKGROUND + " text )"); //$NON-NLS-1$ //$NON-NLS-2$
} catch (RuntimeException e) {
// ignore if already exists
}
@@ -120,25 +122,29 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- if(oldVersion < 2){
+ if (oldVersion < 2) {
createTableForPoints(db);
}
- if(oldVersion < 3){
+ if (oldVersion < 3) {
db.execSQL("ALTER TABLE " + TRACK_NAME + " ADD " + TRACK_COL_HDOP + " double");
}
- if(oldVersion < 4){
- db.execSQL("ALTER TABLE " + POINT_NAME + " ADD " + POINT_COL_NAME + " text");
- db.execSQL("ALTER TABLE " + POINT_NAME + " ADD " + POINT_COL_CATEGORY + " text");
+ if (oldVersion < 4) {
+ db.execSQL("ALTER TABLE " + POINT_NAME + " ADD " + POINT_COL_NAME + " text");
+ db.execSQL("ALTER TABLE " + POINT_NAME + " ADD " + POINT_COL_CATEGORY + " text");
}
- if(oldVersion < 5){
- db.execSQL("ALTER TABLE " + POINT_NAME + " ADD " + POINT_COL_COLOR + " long");
+ if (oldVersion < 5) {
+ db.execSQL("ALTER TABLE " + POINT_NAME + " ADD " + POINT_COL_COLOR + " long");
}
- if(oldVersion < 6){
- db.execSQL("ALTER TABLE " + TRACK_NAME + " ADD " + TRACK_COL_HEADING + " float");
+ if (oldVersion < 6) {
+ db.execSQL("ALTER TABLE " + TRACK_NAME + " ADD " + TRACK_COL_HEADING + " float");
+ }
+ if (oldVersion < 7) {
+ db.execSQL("ALTER TABLE " + POINT_NAME + " ADD " + POINT_COL_ICON + " text");
+ db.execSQL("ALTER TABLE " + POINT_NAME + " ADD " + POINT_COL_BACKGROUND + " text");
}
}
-
-
+
+
public long getLastTrackPointTime() {
long res = 0;
try {
@@ -146,7 +152,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
if (db != null) {
try {
Cursor query = db.rawQuery("SELECT " + TRACK_COL_DATE + " FROM " + TRACK_NAME + " ORDER BY " + TRACK_COL_DATE + " DESC", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- if(query.moveToFirst()) {
+ if (query.moveToFirst()) {
res = query.getLong(0);
}
query.close();
@@ -154,11 +160,11 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
db.close();
}
}
- } catch(RuntimeException e) {
+ } catch (RuntimeException e) {
}
return res;
}
-
+
public synchronized boolean hasDataToSave() {
try {
SQLiteDatabase db = getWritableDatabase();
@@ -172,11 +178,11 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
}
q = db.query(false, POINT_NAME, new String[]{POINT_COL_LAT, POINT_COL_LON}, null, null, null, null, null, null);
has = q.moveToFirst();
- while(has) {
- if(q.getDouble(0) != 0 || q.getDouble(1) != 0) {
+ while (has) {
+ if (q.getDouble(0) != 0 || q.getDouble(1) != 0) {
break;
}
- if(!q.moveToNext()) {
+ if (!q.moveToNext()) {
has = false;
break;
}
@@ -189,7 +195,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
db.close();
}
}
- } catch(RuntimeException e) {
+ } catch (RuntimeException e) {
return false;
}
@@ -294,7 +300,8 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
private void collectDBPoints(SQLiteDatabase db, Map dataTracks) {
Cursor query = db.rawQuery("SELECT " + POINT_COL_LAT + "," + POINT_COL_LON + "," + POINT_COL_DATE + "," //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + POINT_COL_DESCRIPTION + "," + POINT_COL_NAME + "," + POINT_COL_CATEGORY + "," + POINT_COL_COLOR + " FROM " + POINT_NAME+" ORDER BY " + POINT_COL_DATE +" ASC", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + POINT_COL_DESCRIPTION + "," + POINT_COL_NAME + "," + POINT_COL_CATEGORY + "," + POINT_COL_COLOR + ","
+ + POINT_COL_ICON + "," + POINT_COL_BACKGROUND + " FROM " + POINT_NAME + " ORDER BY " + POINT_COL_DATE + " ASC", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if (query.moveToFirst()) {
do {
WptPt pt = new WptPt();
@@ -309,18 +316,20 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
if (color != 0) {
pt.setColor(color);
}
+ pt.setIconName(query.getString(7));
+ pt.setBackgroundType(query.getString(8));
// check if name is extension (needed for audio/video plugin & josm integration)
- if(pt.name != null && pt.name.length() > 4 && pt.name.charAt(pt.name.length() - 4) == '.') {
+ if (pt.name != null && pt.name.length() > 4 && pt.name.charAt(pt.name.length() - 4) == '.') {
pt.link = pt.name;
}
-
+
String date = DateFormat.format("yyyy-MM-dd", time).toString(); //$NON-NLS-1$
GPXFile gpx;
if (dataTracks.containsKey(date)) {
gpx = dataTracks.get(date);
} else {
- gpx = new GPXFile(Version.getFullVersion(ctx));
+ gpx = new GPXFile(Version.getFullVersion(ctx));
dataTracks.put(date, gpx);
}
ctx.getSelectedGpxHelper().addPoint(pt, gpx);
@@ -329,10 +338,10 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
}
query.close();
}
-
+
private void collectDBTracks(SQLiteDatabase db, Map dataTracks) {
Cursor query = db.rawQuery("SELECT " + TRACK_COL_LAT + "," + TRACK_COL_LON + "," + TRACK_COL_ALTITUDE + "," //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + TRACK_COL_SPEED + "," + TRACK_COL_HDOP + "," + TRACK_COL_DATE + "," + TRACK_COL_HEADING + " FROM " + TRACK_NAME +" ORDER BY " + TRACK_COL_DATE +" ASC", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + TRACK_COL_SPEED + "," + TRACK_COL_HDOP + "," + TRACK_COL_DATE + "," + TRACK_COL_HEADING + " FROM " + TRACK_NAME + " ORDER BY " + TRACK_COL_DATE + " ASC", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
long previousTime = 0;
long previousInterval = 0;
TrkSegment segment = null;
@@ -351,14 +360,14 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
pt.heading = heading == NO_HEADING ? Float.NaN : heading;
long currentInterval = Math.abs(time - previousTime);
boolean newInterval = pt.lat == 0 && pt.lon == 0;
-
+
if (track != null && !newInterval && (!ctx.getSettings().AUTO_SPLIT_RECORDING.get() || currentInterval < 6 * 60 * 1000 || currentInterval < 10 * previousInterval)) {
// 6 minute - same segment
segment.points.add(pt);
} else if (track != null && (ctx.getSettings().AUTO_SPLIT_RECORDING.get() && currentInterval < 2 * 60 * 60 * 1000)) {
// 2 hour - same track
segment = new TrkSegment();
- if(!newInterval) {
+ if (!newInterval) {
segment.points.add(pt);
}
track.segments.add(segment);
@@ -367,10 +376,10 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
track = new Track();
segment = new TrkSegment();
track.segments.add(segment);
- if(!newInterval) {
+ if (!newInterval) {
segment.points.add(pt);
}
- String date = new SimpleDateFormat("yyyy-MM-dd", Locale.US).format(new Date(time));; //$NON-NLS-1$
+ String date = new SimpleDateFormat("yyyy-MM-dd", Locale.US).format(new Date(time)); //$NON-NLS-1$
if (dataTracks.containsKey(date)) {
GPXFile gpx = dataTracks.get(date);
gpx.tracks.add(track);
@@ -411,14 +420,14 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
dataTracks.remove(date);
}
}
-
+
public void startNewSegment() {
lastTimeUpdated = 0;
lastPoint = null;
- execWithClose(updateScript, new Object[] { 0, 0, 0, 0, 0, System.currentTimeMillis(), NO_HEADING});
+ execWithClose(updateScript, new Object[]{0, 0, 0, 0, 0, System.currentTimeMillis(), NO_HEADING});
addTrackPoint(null, true, System.currentTimeMillis());
}
-
+
public void updateLocation(net.osmand.Location location, Float heading) {
// use because there is a bug on some devices with location.getTime()
long locationTime = System.currentTimeMillis();
@@ -459,12 +468,12 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
ctx.getNotificationHelper().refreshNotification(NotificationType.GPX);
}
}
-
+
public void insertData(double lat, double lon, double alt, double speed, double hdop, long time, float heading,
- OsmandSettings settings) {
+ OsmandSettings settings) {
// * 1000 in next line seems to be wrong with new IntervalChooseDialog
// if (time - lastTimeUpdated > settings.SAVE_TRACK_INTERVAL.get() * 1000) {
- execWithClose(updateScript, new Object[] { lat, lon, alt, speed, hdop, time, heading });
+ execWithClose(updateScript, new Object[]{lat, lon, alt, speed, hdop, time, heading});
boolean newSegment = false;
if (lastPoint == null || (time - lastTimeUpdated) > 180 * 1000) {
lastPoint = new LatLon(lat, lon);
@@ -485,7 +494,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
addTrackPoint(pt, newSegment, time);
trkPoints++;
}
-
+
private void addTrackPoint(WptPt pt, boolean newSegment, long time) {
List points = currentTrack.getModifiablePointsToDisplay();
Track track = currentTrack.getModifiableGpxFile().tracks.get(0);
@@ -511,12 +520,12 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
}
public WptPt insertPointData(double lat, double lon, long time, String description, String name, String category,
- int color) {
+ int color) {
return insertPointData(lat, lon, time, description, name, category, color, null, null);
}
public WptPt insertPointData(double lat, double lon, long time, String description, String name, String category,
- int color, String iconName, String backgroundName) {
+ int color, String iconName, String backgroundName) {
final WptPt pt = new WptPt(lat, lon, time, Double.NaN, 0, Double.NaN);
pt.name = name;
pt.category = category;
@@ -529,7 +538,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
ctx.getSelectedGpxHelper().addPoint(pt, currentTrack.getModifiableGpxFile());
currentTrack.getModifiableGpxFile().modifiedTime = time;
points++;
- execWithClose(insertPointsScript, new Object[] { lat, lon, time, description, name, category, color });
+ execWithClose(insertPointsScript, new Object[]{lat, lon, time, description, name, category, color, iconName, backgroundName});
return pt;
}
@@ -538,7 +547,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
}
public void updatePointData(WptPt pt, double lat, double lon, long time, String description, String name,
- String category, int color, String iconName, String iconBackground) {
+ String category, int color, String iconName, String iconBackground) {
currentTrack.getModifiableGpxFile().modifiedTime = time;
List