made length display a bit prettier and tap and hold gesture more consistent
This commit is contained in:
parent
a5292bfc0f
commit
dec46976b1
3 changed files with 19 additions and 30 deletions
|
@ -101,6 +101,8 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
|
||||||
private TextView mNegativeElevationView;
|
private TextView mNegativeElevationView;
|
||||||
private Group mElevationDataViews;
|
private Group mElevationDataViews;
|
||||||
private BottomSheetBehavior mStatisticsSheetBehavior;
|
private BottomSheetBehavior mStatisticsSheetBehavior;
|
||||||
|
private int mCurrentLengthUnit;
|
||||||
|
private int mOppositeLengthUnit;
|
||||||
private int mCurrentTrack;
|
private int mCurrentTrack;
|
||||||
private Track mTrack;
|
private Track mTrack;
|
||||||
private BroadcastReceiver mTrackSavedReceiver;
|
private BroadcastReceiver mTrackSavedReceiver;
|
||||||
|
@ -258,7 +260,7 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
|
||||||
// attach listener for taps on elevation views
|
// attach listener for taps on elevation views
|
||||||
attachTapListenerToElevationViews();
|
attachTapListenerToElevationViews();
|
||||||
|
|
||||||
// attach listener for taps on statistics // TODO uncomment
|
// attach listener for taps on statistics
|
||||||
attachTapListenerToStatisticsSheet();
|
attachTapListenerToStatisticsSheet();
|
||||||
|
|
||||||
return mRootView;
|
return mRootView;
|
||||||
|
@ -449,7 +451,7 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
|
||||||
|
|
||||||
/* Switches views in statistic sheet between Metric and Imperial */
|
/* Switches views in statistic sheet between Metric and Imperial */
|
||||||
private void displayOppositeLengthUnits() {
|
private void displayOppositeLengthUnits() {
|
||||||
int oppositeLengthUnit = LengthUnitHelper.getOppositeUnitSystem();
|
int oppositeLengthUnit = LengthUnitHelper.getUnitSystem() * -1;
|
||||||
mDistanceView.setText(LengthUnitHelper.convertDistanceToString(mTrack.getTrackDistance(), oppositeLengthUnit));
|
mDistanceView.setText(LengthUnitHelper.convertDistanceToString(mTrack.getTrackDistance(), oppositeLengthUnit));
|
||||||
mPositiveElevationView.setText(LengthUnitHelper.convertDistanceToString(mTrack.getPositiveElevation(), oppositeLengthUnit));
|
mPositiveElevationView.setText(LengthUnitHelper.convertDistanceToString(mTrack.getPositiveElevation(), oppositeLengthUnit));
|
||||||
mNegativeElevationView.setText(LengthUnitHelper.convertDistanceToString(mTrack.getNegativeElevation(), oppositeLengthUnit));
|
mNegativeElevationView.setText(LengthUnitHelper.convertDistanceToString(mTrack.getNegativeElevation(), oppositeLengthUnit));
|
||||||
|
@ -511,6 +513,8 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
|
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
|
||||||
|
// reset length unit displays
|
||||||
|
displayCurrentLengthUnits();
|
||||||
// react to dragging events
|
// react to dragging events
|
||||||
if (slideOffset < 0.5f) {
|
if (slideOffset < 0.5f) {
|
||||||
mTrackManagementLayout.setVisibility(View.VISIBLE);
|
mTrackManagementLayout.setVisibility(View.VISIBLE);
|
||||||
|
@ -606,20 +610,13 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
|
||||||
mStatisticsView.setOnTouchListener(new View.OnTouchListener() {
|
mStatisticsView.setOnTouchListener(new View.OnTouchListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
// todo describe
|
if(event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||||
if (mStatisticsSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
|
|
||||||
if (event.getAction() == MotionEvent.ACTION_DOWN){
|
|
||||||
displayOppositeLengthUnits();
|
displayOppositeLengthUnits();
|
||||||
return true;
|
|
||||||
} else if (event.getAction() == MotionEvent.ACTION_UP) {
|
} else if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||||
displayCurrentLengthUnits();
|
displayCurrentLengthUnits();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
displayCurrentLengthUnits();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package org.y20k.trackbook.helpers;
|
package org.y20k.trackbook.helpers;
|
||||||
|
|
||||||
|
import java.text.NumberFormat;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -29,7 +30,7 @@ public final class LengthUnitHelper implements TrackbookKeys {
|
||||||
|
|
||||||
/* Converts for the default locale a distance value to a readable string */
|
/* Converts for the default locale a distance value to a readable string */
|
||||||
public static String convertDistanceToString(double distance) {
|
public static String convertDistanceToString(double distance) {
|
||||||
return convertDistanceToString(distance, getUnitSystem(Locale.getDefault()));
|
return convertDistanceToString(distance, getUnitSystem());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,16 +47,18 @@ public final class LengthUnitHelper implements TrackbookKeys {
|
||||||
// set measurement unit
|
// set measurement unit
|
||||||
unit = "m";
|
unit = "m";
|
||||||
}
|
}
|
||||||
return String.format (Locale.ENGLISH, "%.0f", distance) + unit;
|
// format distance according to current locale
|
||||||
|
NumberFormat numberFormat = NumberFormat.getNumberInstance();
|
||||||
|
numberFormat.setMaximumFractionDigits(0);
|
||||||
|
return numberFormat.format(distance) + " " + unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Determines which unit system the device is using (metric or imperial) */
|
/* Determines which unit system the device is using (metric or imperial) */
|
||||||
private static int getUnitSystem(Locale locale) {
|
public static int getUnitSystem() {
|
||||||
// America (US), Liberia (LR), Myanmar(MM) use the imperial system
|
// America (US), Liberia (LR), Myanmar(MM) use the imperial system
|
||||||
List<String> imperialSystemCountries = Arrays.asList("US", "LR", "MM");
|
List<String> imperialSystemCountries = Arrays.asList("US", "LR", "MM");
|
||||||
String countryCode = locale.getCountry();
|
String countryCode = Locale.getDefault().getCountry();
|
||||||
|
|
||||||
if (imperialSystemCountries.contains(countryCode)){
|
if (imperialSystemCountries.contains(countryCode)){
|
||||||
return IMPERIAL;
|
return IMPERIAL;
|
||||||
} else {
|
} else {
|
||||||
|
@ -63,15 +66,4 @@ public final class LengthUnitHelper implements TrackbookKeys {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Returns the opposite unit system based on the current locale */
|
|
||||||
public static int getOppositeUnitSystem() {
|
|
||||||
int unitSystem = getUnitSystem(Locale.getDefault());
|
|
||||||
if (unitSystem == METRIC){
|
|
||||||
return IMPERIAL;
|
|
||||||
} else {
|
|
||||||
return METRIC;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,7 +103,7 @@ public interface TrackbookKeys {
|
||||||
|
|
||||||
/* UNITS */
|
/* UNITS */
|
||||||
int METRIC = 1;
|
int METRIC = 1;
|
||||||
int IMPERIAL = 2;
|
int IMPERIAL = -1;
|
||||||
|
|
||||||
/* FLOATING ACTION BUTTON */
|
/* FLOATING ACTION BUTTON */
|
||||||
int FAB_STATE_DEFAULT = 0;
|
int FAB_STATE_DEFAULT = 0;
|
||||||
|
|
Loading…
Reference in a new issue