From 913e125968cb1cd9195eb7f3a9b38849ed670eb5 Mon Sep 17 00:00:00 2001 From: Skalii Date: Mon, 22 Mar 2021 04:40:26 +0200 Subject: [PATCH] add static graphs --- OsmAnd/res/layout/gpx_item_altitude.xml | 1 + OsmAnd/res/layout/gpx_item_general.xml | 1 + OsmAnd/res/layout/gpx_item_speed.xml | 1 + .../res/layout/gpx_list_item_tab_content.xml | 4 +- OsmAnd/res/layout/trip_recording_fragment.xml | 8 +- .../TripRecordingBottomFragment.java | 142 ++++++++- .../plus/myplaces/GPXItemPagerAdapter.java | 289 +++++++++++------- .../plus/track/GpxBlockStatisticsBuilder.java | 252 +++++++++++---- .../net/osmand/plus/track/OverviewCard.java | 4 +- .../views/controls/PagerSlidingTabStrip.java | 16 +- 10 files changed, 522 insertions(+), 196 deletions(-) diff --git a/OsmAnd/res/layout/gpx_item_altitude.xml b/OsmAnd/res/layout/gpx_item_altitude.xml index 9dd2037878..699e6812ea 100644 --- a/OsmAnd/res/layout/gpx_item_altitude.xml +++ b/OsmAnd/res/layout/gpx_item_altitude.xml @@ -273,6 +273,7 @@ diff --git a/OsmAnd/res/layout/gpx_item_general.xml b/OsmAnd/res/layout/gpx_item_general.xml index 962bbbe9f5..fe90a5c031 100644 --- a/OsmAnd/res/layout/gpx_item_general.xml +++ b/OsmAnd/res/layout/gpx_item_general.xml @@ -291,6 +291,7 @@ diff --git a/OsmAnd/res/layout/gpx_item_speed.xml b/OsmAnd/res/layout/gpx_item_speed.xml index d5bc1d3edb..785c8109ef 100644 --- a/OsmAnd/res/layout/gpx_item_speed.xml +++ b/OsmAnd/res/layout/gpx_item_speed.xml @@ -275,6 +275,7 @@ diff --git a/OsmAnd/res/layout/gpx_list_item_tab_content.xml b/OsmAnd/res/layout/gpx_list_item_tab_content.xml index ac7918d06a..5fa3d3ab29 100644 --- a/OsmAnd/res/layout/gpx_list_item_tab_content.xml +++ b/OsmAnd/res/layout/gpx_list_item_tab_content.xml @@ -4,7 +4,9 @@ android:layout_height="wrap_content" android:orientation="vertical"> - + + android:layout_marginBottom="@dimen/context_menu_padding_margin_small" /> + + 0) { - DateFormat tf = SimpleDateFormat.getTimeInstance(DateFormat.SHORT); - DateFormat df = SimpleDateFormat.getDateInstance(DateFormat.MEDIUM); + }); + if (analysis.timeSpan > 0) { + DateFormat tf = SimpleDateFormat.getTimeInstance(DateFormat.SHORT); + DateFormat df = SimpleDateFormat.getDateInstance(DateFormat.MEDIUM); - Date start = new Date(analysis.startTime); - ((TextView) view.findViewById(R.id.start_time_text)).setText(tf.format(start)); - ((TextView) view.findViewById(R.id.start_date_text)).setText(df.format(start)); - Date end = new Date(analysis.endTime); - ((TextView) view.findViewById(R.id.end_time_text)).setText(tf.format(end)); - ((TextView) view.findViewById(R.id.end_date_text)).setText(df.format(end)); - } else { - view.findViewById(R.id.list_divider).setVisibility(View.GONE); - view.findViewById(R.id.start_end_time).setVisibility(View.GONE); + Date start = new Date(analysis.startTime); + ((TextView) view.findViewById(R.id.start_time_text)).setText(tf.format(start)); + ((TextView) view.findViewById(R.id.start_date_text)).setText(df.format(start)); + Date end = new Date(analysis.endTime); + ((TextView) view.findViewById(R.id.end_time_text)).setText(tf.format(end)); + ((TextView) view.findViewById(R.id.end_date_text)).setText(df.format(end)); + } else { + view.findViewById(R.id.list_divider).setVisibility(View.GONE); + view.findViewById(R.id.start_end_time).setVisibility(View.GONE); + } } } else { chart.setVisibility(View.GONE); @@ -412,17 +463,19 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid view.findViewById(R.id.start_end_time).setVisibility(View.GONE); } updateJoinGapsInfo(view, position); - view.findViewById(R.id.analyze_on_map).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - openAnalyzeOnMap(GPXTabItemType.GPX_TAB_ITEM_GENERAL); + if (!onlyGraphs) { + view.findViewById(R.id.analyze_on_map).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + openAnalyzeOnMap(GPXTabItemType.GPX_TAB_ITEM_GENERAL); + } + }); + TextView overflowMenu = view.findViewById(R.id.overflow_menu); + if (!gpxItem.group.getTrack().generalTrack) { + setupOptionsPopupMenu(overflowMenu, true); + } else { + overflowMenu.setVisibility(View.GONE); } - }); - TextView overflowMenu = view.findViewById(R.id.overflow_menu); - if (!gpxItem.group.getTrack().generalTrack) { - setupOptionsPopupMenu(overflowMenu, true); - } else { - overflowMenu.setVisibility(View.GONE); } } @@ -598,7 +651,7 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid @Override public void tabStylesUpdated(View tabsContainer, int currentPosition) { ViewGroup.MarginLayoutParams params = (MarginLayoutParams) tabsContainer.getLayoutParams(); - params.height = app.getResources().getDimensionPixelSize(R.dimen.dialog_button_height); + params.height = app.getResources().getDimensionPixelSize(!onlyGraphs ? R.dimen.dialog_button_height : R.dimen.context_menu_buttons_bottom_height); tabsContainer.setLayoutParams(params); UiUtilities.updateCustomRadioButtons(app, tabsContainer, nightMode, getCustomRadioButtonType(currentPosition)); } diff --git a/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java b/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java index 09adb88117..1670562eee 100644 --- a/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java +++ b/OsmAnd/src/net/osmand/plus/track/GpxBlockStatisticsBuilder.java @@ -14,6 +14,7 @@ import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.AppCompatImageView; +import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -35,30 +36,44 @@ import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.List; +import static net.osmand.plus.liveupdates.LiveUpdatesFragmentNew.getDefaultIconColorId; + public class GpxBlockStatisticsBuilder { - private static final Log log = PlatformUtil.getLog(GpxBlockStatisticsBuilder.class); - private static final int GENERAL_UPDATE_INTERVAL = 1000; + private static final Log LOG = PlatformUtil.getLog(GpxBlockStatisticsBuilder.class); + private static final int BLOCKS_UPDATE_INTERVAL = 1000; + public static final String INIT_BLOCKS_BASE = "init_blocks_base"; + public static final String INIT_BLOCKS_GENERAL = "init_blocks_general"; + public static final String INIT_BLOCKS_ALTITUDE = "init_blocks_altitude"; + public static final String INIT_BLOCKS_SPEED = "init_blocks_speed"; private final OsmandApplication app; + private final boolean nightMode; + private RecyclerView blocksView; private final SelectedGpxFile selectedGpxFile; + private GPXTrackAnalysis analysis; private BlockStatisticsAdapter adapter; private final List items = new ArrayList<>(); private boolean blocksClickable = true; + private String initBlocksKey = INIT_BLOCKS_BASE; private final Handler handler = new Handler(); private Runnable updatingItems; private boolean updateRunning = false; - public GpxBlockStatisticsBuilder(OsmandApplication app, SelectedGpxFile selectedGpxFile) { + public GpxBlockStatisticsBuilder(OsmandApplication app, SelectedGpxFile selectedGpxFile, boolean nightMode) { this.app = app; this.selectedGpxFile = selectedGpxFile; + this.nightMode = nightMode; } public boolean isUpdateRunning() { @@ -73,6 +88,10 @@ public class GpxBlockStatisticsBuilder { this.blocksView = blocksView; } + public void setInitBlocksKey(String initBlocksKey) { + this.initBlocksKey = initBlocksKey; + } + @Nullable public GpxDisplayItem getDisplayItem(GPXFile gpxFile) { return gpxFile.tracks.size() > 0 ? GpxUiHelper.makeGpxDisplayItem(app, gpxFile) : null; @@ -82,9 +101,9 @@ public class GpxBlockStatisticsBuilder { return selectedGpxFile.getGpxFile(); } - public void initStatBlocks(@Nullable SegmentActionsListener actionsListener, @ColorInt int activeColor, boolean nightMode) { + public void initStatBlocks(@Nullable SegmentActionsListener actionsListener, @ColorInt int activeColor) { initItems(); - adapter = new BlockStatisticsAdapter(getDisplayItem(getGPXFile()), actionsListener, activeColor, nightMode); + adapter = new BlockStatisticsAdapter(getDisplayItem(getGPXFile()), actionsListener, activeColor); adapter.setItems(items); blocksView.setLayoutManager(new LinearLayoutManager(app, LinearLayoutManager.HORIZONTAL, false)); blocksView.setAdapter(adapter); @@ -107,7 +126,7 @@ public class GpxBlockStatisticsBuilder { } AndroidUiHelper.updateVisibility(blocksView, !Algorithms.isEmpty(items)); int interval = app.getSettings().SAVE_GLOBAL_TRACK_INTERVAL.get(); - updateRunning = handler.postDelayed(this, Math.max(GENERAL_UPDATE_INTERVAL, interval)); + updateRunning = handler.postDelayed(this, Math.max(BLOCKS_UPDATE_INTERVAL, interval)); } }; updateRunning = handler.post(updatingItems); @@ -117,65 +136,187 @@ public class GpxBlockStatisticsBuilder { public void initItems() { GPXFile gpxFile = getGPXFile(); GpxDisplayItem gpxDisplayItem = getDisplayItem(gpxFile); - GPXTrackAnalysis analysis = null; boolean withoutGaps = true; if (gpxDisplayItem != null) { analysis = gpxDisplayItem.analysis; withoutGaps = !selectedGpxFile.isJoinSegments() && gpxDisplayItem.isGeneralTrack(); } if (analysis != null) { - float totalDistance = withoutGaps ? analysis.totalDistanceWithoutGaps : analysis.totalDistance; - float timeSpan = withoutGaps ? analysis.timeSpanWithoutGaps : analysis.timeSpan; - String asc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app); - String desc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app); - String avg = OsmAndFormatter.getFormattedSpeed(analysis.avgSpeed, app); - String max = OsmAndFormatter.getFormattedSpeed(analysis.maxSpeed, app); - items.clear(); - prepareData(analysis, app.getString(R.string.distance), OsmAndFormatter.getFormattedDistance(totalDistance, app), - R.drawable.ic_action_track_16, R.color.icon_color_default_light, GPXDataSetType.ALTITUDE, GPXDataSetType.SPEED, ItemType.ITEM_DISTANCE); - prepareData(analysis, app.getString(R.string.altitude_ascent), asc, - R.drawable.ic_action_arrow_up_16, R.color.gpx_chart_red, GPXDataSetType.SLOPE, null, ItemType.ITEM_ALTITUDE); - prepareData(analysis, app.getString(R.string.altitude_descent), desc, - R.drawable.ic_action_arrow_down_16, R.color.gpx_pale_green, GPXDataSetType.ALTITUDE, GPXDataSetType.SLOPE, ItemType.ITEM_ALTITUDE); - prepareData(analysis, app.getString(R.string.average_speed), avg, - R.drawable.ic_action_speed_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null, ItemType.ITEM_SPEED); - prepareData(analysis, app.getString(R.string.max_speed), max, - R.drawable.ic_action_max_speed_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null, ItemType.ITEM_SPEED); - prepareData(analysis, app.getString(R.string.shared_string_time_span), - Algorithms.formatDuration((int) (timeSpan / 1000), app.accessibilityEnabled()), - R.drawable.ic_action_time_span_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null, ItemType.ITEM_TIME); + switch (initBlocksKey) { + case INIT_BLOCKS_GENERAL: { + float totalDistance = withoutGaps ? analysis.totalDistanceWithoutGaps : analysis.totalDistance; + float timeSpan = withoutGaps ? analysis.timeSpanWithoutGaps : analysis.timeSpan; + Date start = new Date(analysis.startTime); + Date end = new Date(analysis.endTime); + prepareDataDistance(totalDistance); + prepareDataTimeSpan(timeSpan); + prepareDataStartTime(start); + prepareDataEndTime(end); + break; + } + case INIT_BLOCKS_ALTITUDE: { + String min = OsmAndFormatter.getFormattedAlt(analysis.minElevation, app); + String max = OsmAndFormatter.getFormattedAlt(analysis.maxElevation, app); + String asc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app); + String desc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app); + prepareDataAverageAltitude(); + prepareDataAltitudeRange(min, max); + prepareDataAscent(asc); + prepareDataDescent(desc); + break; + } + case INIT_BLOCKS_SPEED: { + String avg = OsmAndFormatter.getFormattedSpeed(analysis.avgSpeed, app); + String max = OsmAndFormatter.getFormattedSpeed(analysis.maxSpeed, app); + long timeMoving = withoutGaps ? analysis.timeMovingWithoutGaps : analysis.timeMoving; + float totalDistanceMoving = withoutGaps ? analysis.totalDistanceMovingWithoutGaps : analysis.totalDistanceMoving; + prepareDataAverageSpeed(avg); + prepareDataMaximumSpeed(max); + prepareDataTimeMoving(timeMoving); + prepareDataDistanceCorrected(totalDistanceMoving); + break; + } + default: + case INIT_BLOCKS_BASE: { + float totalDistance = withoutGaps ? analysis.totalDistanceWithoutGaps : analysis.totalDistance; + String asc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app); + String desc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app); + String avg = OsmAndFormatter.getFormattedSpeed(analysis.avgSpeed, app); + String max = OsmAndFormatter.getFormattedSpeed(analysis.maxSpeed, app); + float timeSpan = withoutGaps ? analysis.timeSpanWithoutGaps : analysis.timeSpan; + prepareDataDistance(totalDistance); + prepareDataAscent(asc); + prepareDataDescent(desc); + prepareDataAverageSpeed(avg); + prepareDataMaximumSpeed(max); + prepareDataTimeSpan(timeSpan); + break; + } + } } } - public void prepareData(GPXTrackAnalysis analysis, String title, String value, - @DrawableRes int imageResId, @ColorRes int imageColorId, + public void prepareDataDistance(float totalDistance) { + prepareData(app.getString(R.string.distance), OsmAndFormatter.getFormattedDistance(totalDistance, app), + R.drawable.ic_action_track_16, GPXDataSetType.ALTITUDE, GPXDataSetType.SPEED, ItemType.ITEM_DISTANCE); + } + + public void prepareDataAverageAltitude() { + prepareData(app.getString(R.string.average_altitude), OsmAndFormatter.getFormattedAlt(analysis.avgElevation, app), + R.drawable.ic_action_altitude_average_16, GPXDataSetType.ALTITUDE, null, ItemType.ITEM_ALTITUDE); + } + + public void prepareDataAltitudeRange(String min, String max) { + String pattern = app.getString(R.string.ltr_or_rtl_combine_via_dash); + prepareData(app.getString(R.string.altitude_range), String.format(pattern, min, max), + R.drawable.ic_action_altitude_range_16, GPXDataSetType.ALTITUDE, null, ItemType.ITEM_ALTITUDE); + } + + public void prepareDataAscent(String asc) { + prepareData(app.getString(R.string.altitude_ascent), asc, + R.drawable.ic_action_arrow_up_16, R.color.gpx_chart_red, + GPXDataSetType.SLOPE, null, ItemType.ITEM_ALTITUDE); + } + + public void prepareDataDescent(String desc) { + prepareData(app.getString(R.string.altitude_descent), desc, + R.drawable.ic_action_arrow_down_16, R.color.gpx_pale_green, + GPXDataSetType.ALTITUDE, GPXDataSetType.SLOPE, ItemType.ITEM_ALTITUDE); + } + + public void prepareDataAverageSpeed(String avg) { + prepareData(app.getString(R.string.average_speed), avg, + R.drawable.ic_action_speed_16, GPXDataSetType.SPEED, null, ItemType.ITEM_SPEED); + } + + public void prepareDataMaximumSpeed(String max) { + prepareData(app.getString(R.string.max_speed), max, + R.drawable.ic_action_max_speed_16, GPXDataSetType.SPEED, null, ItemType.ITEM_SPEED); + } + + public void prepareDataTimeMoving(long timeMoving) { + prepareData(app.getString(R.string.shared_string_time_moving), + Algorithms.formatDuration((int) (timeMoving / 1000), app.accessibilityEnabled()), + R.drawable.ic_action_time_span_16, GPXDataSetType.SPEED, null, ItemType.ITEM_TIME_MOVING); + } + + public void prepareDataDistanceCorrected(float totalDistanceMoving) { + prepareData(app.getString(R.string.distance_moving), + OsmAndFormatter.getFormattedDistance(totalDistanceMoving, app), + R.drawable.ic_action_polygom_dark, GPXDataSetType.SPEED, null, ItemType.ITEM_DISTANCE_MOVING); + } + + public void prepareDataTimeSpan(float timeSpan) { + prepareData(app.getString(R.string.shared_string_time_span), + Algorithms.formatDuration((int) (timeSpan / 1000), app.accessibilityEnabled()), + R.drawable.ic_action_time_span_16, GPXDataSetType.SPEED, null, ItemType.ITEM_TIME_SPAN); + } + + public void prepareDataStartTime(Date start) { + DateFormat dtf = SimpleDateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); + prepareData(app.getString(R.string.shared_string_start_time), dtf.format(start), + R.drawable.ic_action_time_start_16, GPXDataSetType.SPEED, null, ItemType.ITEM_TIME); + } + + public void prepareDataEndTime(Date end) { + DateFormat dtf = SimpleDateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); + prepareData(app.getString(R.string.shared_string_end_time), dtf.format(end), + R.drawable.ic_action_time_end_16, GPXDataSetType.SPEED, null, ItemType.ITEM_TIME); + } + + public void prepareData(String title, String value, @DrawableRes int imageResId, GPXDataSetType firstType, GPXDataSetType secondType, ItemType itemType) { - StatBlock statBlock = new StatBlock(title, value, imageResId, imageColorId, firstType, secondType, itemType); - switch (statBlock.itemType) { - case ITEM_DISTANCE: { - if (analysis.totalDistance != 0f) { - items.add(statBlock); + prepareData(title, value, imageResId, getDefaultIconColorId(nightMode), firstType, secondType, itemType); + } + + public void prepareData(String title, String value, @DrawableRes int imageResId, @ColorRes int imageColorId, + GPXDataSetType firstType, GPXDataSetType secondType, ItemType itemType) { + if (analysis != null) { + StatBlock statBlock = new StatBlock(title, value, imageResId, imageColorId, firstType, secondType, itemType); + switch (statBlock.itemType) { + case ITEM_DISTANCE: { + if (analysis.totalDistance != 0f) { + items.add(statBlock); + } + break; } - break; - } - case ITEM_ALTITUDE: { - if (analysis.hasElevationData) { - items.add(statBlock); + case ITEM_DISTANCE_MOVING: { + if (analysis.totalDistanceMoving != 0f) { + items.add(statBlock); + } + break; } - break; - } - case ITEM_SPEED: { - if (analysis.isSpeedSpecified()) { - items.add(statBlock); + case ITEM_ALTITUDE: { + if (analysis.hasElevationData) { + items.add(statBlock); + } + break; } - break; - } - case ITEM_TIME: { - if (analysis.hasSpeedData) { - items.add(statBlock); + case ITEM_SPEED: { + if (analysis.isSpeedSpecified()) { + items.add(statBlock); + } + break; + } + case ITEM_TIME: { + if (analysis.timeSpan > 0) { + items.add(statBlock); + } + break; + } + case ITEM_TIME_SPAN: { + if (analysis.hasSpeedData) { + items.add(statBlock); + } + break; + } + case ITEM_TIME_MOVING: { + if (analysis.isTimeMoving()) { + items.add(statBlock); + } + break; } - break; } } } @@ -203,9 +344,12 @@ public class GpxBlockStatisticsBuilder { public enum ItemType { ITEM_DISTANCE, + ITEM_DISTANCE_MOVING, ITEM_ALTITUDE, ITEM_SPEED, - ITEM_TIME; + ITEM_TIME, + ITEM_TIME_SPAN, + ITEM_TIME_MOVING; } private class BlockStatisticsAdapter extends RecyclerView.Adapter { @@ -215,17 +359,15 @@ public class GpxBlockStatisticsBuilder { private final SegmentActionsListener actionsListener; @ColorInt private final int activeColor; - private final boolean nightMode; private final int minWidthPx; private final int maxWidthPx; private final int textSize; public BlockStatisticsAdapter(GpxDisplayItem displayItem, SegmentActionsListener actionsListener, - @ColorInt int activeColor, boolean nightMode) { + @ColorInt int activeColor) { this.displayItem = displayItem; this.actionsListener = actionsListener; this.activeColor = activeColor; - this.nightMode = nightMode; minWidthPx = AndroidUtils.dpToPx(app, 60f); maxWidthPx = AndroidUtils.dpToPx(app, 120f); textSize = app.getResources().getDimensionPixelSize(R.dimen.default_desc_text_size); @@ -250,7 +392,7 @@ public class GpxBlockStatisticsBuilder { holder.valueText.setText(item.value); holder.valueText.setTextColor(activeColor); holder.titleText.setText(item.title); - holder.titleText.setTextColor(app.getResources().getColor(R.color.text_color_secondary_light)); + holder.titleText.setTextColor(ContextCompat.getColor(app, R.color.text_color_secondary_light)); float letterSpacing = 0.00f; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { letterSpacing = Math.max(holder.valueText.getLetterSpacing(), holder.titleText.getLetterSpacing()); diff --git a/OsmAnd/src/net/osmand/plus/track/OverviewCard.java b/OsmAnd/src/net/osmand/plus/track/OverviewCard.java index 25fa38e04e..2822297f2e 100644 --- a/OsmAnd/src/net/osmand/plus/track/OverviewCard.java +++ b/OsmAnd/src/net/osmand/plus/track/OverviewCard.java @@ -51,7 +51,7 @@ public class OverviewCard extends BaseCard { super(mapActivity); this.actionsListener = actionsListener; this.selectedGpxFile = selectedGpxFile; - blockStatisticsBuilder = new GpxBlockStatisticsBuilder(app, selectedGpxFile); + blockStatisticsBuilder = new GpxBlockStatisticsBuilder(app, selectedGpxFile, nightMode); } @Override @@ -80,7 +80,7 @@ public class OverviewCard extends BaseCard { initEditButton(iconColorDef, iconColorPres); initDirectionsButton(iconColorDef, iconColorPres); } - blockStatisticsBuilder.initStatBlocks(actionsListener, getActiveColor(), nightMode); + blockStatisticsBuilder.initStatBlocks(actionsListener, getActiveColor()); } private GPXFile getGPXFile() { diff --git a/OsmAnd/src/net/osmand/plus/views/controls/PagerSlidingTabStrip.java b/OsmAnd/src/net/osmand/plus/views/controls/PagerSlidingTabStrip.java index f6d5bdd4fd..f79ac0c6b5 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/PagerSlidingTabStrip.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/PagerSlidingTabStrip.java @@ -66,12 +66,17 @@ public class PagerSlidingTabStrip extends HorizontalScrollView { public interface CustomTabProvider { public View getCustomTabView(@NonNull ViewGroup parent, int position); + public void select(View tab); + public void deselect(View tab); + public void tabStylesUpdated(View tabsContainer, int currentPosition); } public interface OnTabReselectedListener { + public void onTabSelected(int position); + public void onTabReselected(int position); } @@ -121,7 +126,7 @@ public class PagerSlidingTabStrip extends HorizontalScrollView { private int underlineHeight = 0; @ColorInt private int underlineColor; - + private int dividerWidth = 0; private int dividerPadding = 0; @@ -197,7 +202,7 @@ public class PagerSlidingTabStrip extends HorizontalScrollView { //In case we have the padding they must be equal so we take the biggest padding = Math.max(paddingLeft, paddingRight); - + // get custom attrs a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip); @@ -221,7 +226,7 @@ public class PagerSlidingTabStrip extends HorizontalScrollView { tabTypefaceSelectedStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTextSelectedStyle, Typeface.NORMAL); tabTextAlpha = a.getFloat(R.styleable.PagerSlidingTabStrip_pstsTextAlpha, HALF_TRANSP); tabTextSelectedAlpha = a.getFloat(R.styleable.PagerSlidingTabStrip_pstsTextSelectedAlpha, OPAQUE); - tabTypeface = FontCache.getRobotoMedium(context); + tabTypeface = FontCache.getRobotoMedium(context); a.recycle(); setMarginBottomTabContainer(); @@ -326,6 +331,9 @@ public class PagerSlidingTabStrip extends HorizontalScrollView { View tab = tabsContainer.getChildAt(pager.getCurrentItem()); notSelected(tab); pager.setCurrentItem(position); + if (tabReselectedListener != null) { + tabReselectedListener.onTabSelected(position); + } } else if (tabReselectedListener != null) { tabReselectedListener.onTabReselected(position); } @@ -470,7 +478,7 @@ public class PagerSlidingTabStrip extends HorizontalScrollView { // draw underline rectPaint.setColor(underlineColor); //underlineColor canvas.drawRect(padding, height - underlineHeight, tabsContainer.getWidth() + padding, height, rectPaint); - + // draw divider if (dividerWidth != 0) { dividerPaint.setStrokeWidth(dividerWidth);