made length display a bit prettier and tap and hold gesture more consistent

master
y20k 2018-04-27 18:28:03 +02:00
parent a5292bfc0f
commit dec46976b1
3 changed files with 19 additions and 30 deletions

View File

@ -101,6 +101,8 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
private TextView mNegativeElevationView;
private Group mElevationDataViews;
private BottomSheetBehavior mStatisticsSheetBehavior;
private int mCurrentLengthUnit;
private int mOppositeLengthUnit;
private int mCurrentTrack;
private Track mTrack;
private BroadcastReceiver mTrackSavedReceiver;
@ -258,7 +260,7 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
// attach listener for taps on elevation views
attachTapListenerToElevationViews();
// attach listener for taps on statistics // TODO uncomment
// attach listener for taps on statistics
attachTapListenerToStatisticsSheet();
return mRootView;
@ -449,7 +451,7 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
/* Switches views in statistic sheet between Metric and Imperial */
private void displayOppositeLengthUnits() {
int oppositeLengthUnit = LengthUnitHelper.getOppositeUnitSystem();
int oppositeLengthUnit = LengthUnitHelper.getUnitSystem() * -1;
mDistanceView.setText(LengthUnitHelper.convertDistanceToString(mTrack.getTrackDistance(), oppositeLengthUnit));
mPositiveElevationView.setText(LengthUnitHelper.convertDistanceToString(mTrack.getPositiveElevation(), oppositeLengthUnit));
mNegativeElevationView.setText(LengthUnitHelper.convertDistanceToString(mTrack.getNegativeElevation(), oppositeLengthUnit));
@ -511,6 +513,8 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
// reset length unit displays
displayCurrentLengthUnits();
// react to dragging events
if (slideOffset < 0.5f) {
mTrackManagementLayout.setVisibility(View.VISIBLE);
@ -606,19 +610,12 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
mStatisticsView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// todo describe
if (mStatisticsSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
if (event.getAction() == MotionEvent.ACTION_DOWN){
displayOppositeLengthUnits();
return true;
} else if (event.getAction() == MotionEvent.ACTION_UP) {
displayCurrentLengthUnits();
return true;
}
} else {
if(event.getAction() == MotionEvent.ACTION_DOWN) {
displayOppositeLengthUnits();
} else if (event.getAction() == MotionEvent.ACTION_UP) {
displayCurrentLengthUnits();
}
return false;
return true;
}
});
}

View File

@ -16,6 +16,7 @@
package org.y20k.trackbook.helpers;
import java.text.NumberFormat;
import java.util.Arrays;
import java.util.List;
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 */
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
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) */
private static int getUnitSystem(Locale locale) {
public static int getUnitSystem() {
// America (US), Liberia (LR), Myanmar(MM) use the imperial system
List<String> imperialSystemCountries = Arrays.asList("US", "LR", "MM");
String countryCode = locale.getCountry();
String countryCode = Locale.getDefault().getCountry();
if (imperialSystemCountries.contains(countryCode)){
return IMPERIAL;
} 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;
}
}
}

View File

@ -103,7 +103,7 @@ public interface TrackbookKeys {
/* UNITS */
int METRIC = 1;
int IMPERIAL = 2;
int IMPERIAL = -1;
/* FLOATING ACTION BUTTON */
int FAB_STATE_DEFAULT = 0;