unit switch tap gesture only for imperial unit devices

This commit is contained in:
y20k 2018-04-30 17:02:53 +02:00
parent dec46976b1
commit 6af7859937
7 changed files with 53 additions and 37 deletions

View file

@ -445,7 +445,7 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
} else { } else {
// point to the on main onboarding layout // point to the on main onboarding layout
setContentView(R.layout.activity_main_onboarding); setContentView(R.layout.main_onboarding);
// show the okay button and attach listener // show the okay button and attach listener
Button okayButton = (Button) findViewById(R.id.button_okay); Button okayButton = (Button) findViewById(R.id.button_okay);

View file

@ -100,9 +100,8 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
private TextView mPositiveElevationView; private TextView mPositiveElevationView;
private TextView mNegativeElevationView; private TextView mNegativeElevationView;
private Group mElevationDataViews; private Group mElevationDataViews;
private Group mStatisticsHeaderViews;
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;
@ -225,6 +224,7 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
mPositiveElevationView = (TextView) mRootView.findViewById(R.id.statistics_data_positive_elevation); mPositiveElevationView = (TextView) mRootView.findViewById(R.id.statistics_data_positive_elevation);
mNegativeElevationView = (TextView) mRootView.findViewById(R.id.statistics_data_negative_elevation); mNegativeElevationView = (TextView) mRootView.findViewById(R.id.statistics_data_negative_elevation);
mElevationDataViews = (Group) mRootView.findViewById(R.id.elevation_data); mElevationDataViews = (Group) mRootView.findViewById(R.id.elevation_data);
mStatisticsHeaderViews = (Group) mRootView.findViewById(R.id.statistics_header);
// display map and statistics // display map and statistics
@ -245,23 +245,17 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
mStatisticsSheetBehavior = BottomSheetBehavior.from(mStatisticsSheet); mStatisticsSheetBehavior = BottomSheetBehavior.from(mStatisticsSheet);
mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
mStatisticsSheetBehavior.setBottomSheetCallback(getStatisticsSheetCallback()); mStatisticsSheetBehavior.setBottomSheetCallback(getStatisticsSheetCallback());
// todo attach listener to title and (i)icon
// mStatisticsView.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// if (mStatisticsSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
// mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
// } else {
// mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
// }
// }
// });
// attach listener for taps on elevation views // attach listener for taps on elevation views
attachTapListenerToElevationViews(); attachTapListenerToElevationViews();
// attach listener for taps on statistics // attach listener for taps on statistics sheet header
attachTapListenerToStatisticHeaderViews();
// attach listener for taps on statistics - for US and other states plagued by Imperial units
if (LengthUnitHelper.getUnitSystem() == IMPERIAL) {
attachTapListenerToStatisticsSheet(); attachTapListenerToStatisticsSheet();
}
return mRootView; return mRootView;
} }
@ -605,6 +599,24 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
} }
/* Add tap listener to statistic header views */
private void attachTapListenerToStatisticHeaderViews() {
int referencedIds[] = mStatisticsHeaderViews.getReferencedIds();
for (int id : referencedIds) {
mRootView.findViewById(id).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mStatisticsSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
} else {
mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
}
});
}
}
/* Add tap listener to statistics sheet */ /* Add tap listener to statistics sheet */
private void attachTapListenerToStatisticsSheet() { private void attachTapListenerToStatisticsSheet() {
mStatisticsView.setOnTouchListener(new View.OnTouchListener() { mStatisticsView.setOnTouchListener(new View.OnTouchListener() {

View file

@ -21,10 +21,10 @@
android:contentDescription="@string/descr_map_last_track" /> android:contentDescription="@string/descr_map_last_track" />
<!-- OPTIONAL ONBOARDING --> <!-- OPTIONAL ONBOARDING -->
<include layout="@layout/fragment_main_track_onboarding" /> <include layout="@layout/track_onboarding" />
<!-- TRACK MANAGEMENT --> <!-- TRACK MANAGEMENT -->
<include layout="@layout/fragment_main_track_management" /> <include layout="@layout/track_management" />
</RelativeLayout> </RelativeLayout>
@ -44,7 +44,7 @@
android:layout_height="match_parent"> android:layout_height="match_parent">
<!-- STATISTICS --> <!-- STATISTICS -->
<include layout="@layout/fragment_main_track_statistics" /> <include layout="@layout/track_statistics" />
</ScrollView> </ScrollView>

View file

@ -2,10 +2,10 @@
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/statistics_view" android:id="@+id/statistics_view"
android:clickable="true"
android:focusable="true"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="match_parent"
android:clickable="true"
android:focusable="true">
<android.support.constraint.Group <android.support.constraint.Group
android:id="@+id/elevation_data" android:id="@+id/elevation_data"
@ -13,6 +13,12 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:constraint_referenced_ids="statistics_p_positive_elevation, statistics_data_positive_elevation, statistics_p_negative_elevation, statistics_data_negative_elevation, statistics_p_max_altitude, statistics_data_max_altitude, statistics_p_min_altitude, statistics_data_min_altitude" /> app:constraint_referenced_ids="statistics_p_positive_elevation, statistics_data_positive_elevation, statistics_p_negative_elevation, statistics_data_negative_elevation, statistics_p_max_altitude, statistics_data_max_altitude, statistics_p_min_altitude, statistics_data_min_altitude" />
<android.support.constraint.Group
android:id="@+id/statistics_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="statistics_headline, statistics_icon" />
<TextView <TextView
android:id="@+id/statistics_headline" android:id="@+id/statistics_headline"
android:layout_width="0dp" android:layout_width="0dp"
@ -73,9 +79,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:contentDescription="@string/descr_statistics_sheet_p_steps" android:contentDescription="@string/descr_statistics_sheet_p_steps"
android:text="@string/statistics_sheet_p_steps"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@color/statistic_sheet_text" android:textColor="@color/statistic_sheet_text"
android:text="@string/statistics_sheet_p_steps"
app:layout_constraintStart_toStartOf="@+id/statistics_p_distance" app:layout_constraintStart_toStartOf="@+id/statistics_p_distance"
app:layout_constraintTop_toBottomOf="@+id/statistics_p_distance" /> app:layout_constraintTop_toBottomOf="@+id/statistics_p_distance" />
@ -98,9 +104,9 @@
android:layout_height="0dp" android:layout_height="0dp"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:contentDescription="@string/descr_statistics_sheet_p_waypoints" android:contentDescription="@string/descr_statistics_sheet_p_waypoints"
android:text="@string/statistics_sheet_p_waypoints"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@color/statistic_sheet_text" android:textColor="@color/statistic_sheet_text"
android:text="@string/statistics_sheet_p_waypoints"
app:layout_constraintStart_toStartOf="@+id/statistics_p_steps" app:layout_constraintStart_toStartOf="@+id/statistics_p_steps"
app:layout_constraintTop_toBottomOf="@+id/statistics_p_steps" /> app:layout_constraintTop_toBottomOf="@+id/statistics_p_steps" />
@ -123,9 +129,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:contentDescription="@string/descr_statistics_sheet_p_duration" android:contentDescription="@string/descr_statistics_sheet_p_duration"
android:text="@string/statistics_sheet_p_duration"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@color/statistic_sheet_text" android:textColor="@color/statistic_sheet_text"
android:text="@string/statistics_sheet_p_duration"
app:layout_constraintStart_toStartOf="@+id/statistics_p_waypoints" app:layout_constraintStart_toStartOf="@+id/statistics_p_waypoints"
app:layout_constraintTop_toBottomOf="@+id/statistics_p_waypoints" /> app:layout_constraintTop_toBottomOf="@+id/statistics_p_waypoints" />
@ -148,9 +154,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:contentDescription="@string/descr_statistics_sheet_p_recording_start" android:contentDescription="@string/descr_statistics_sheet_p_recording_start"
android:text="@string/statistics_sheet_p_recording_start"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@color/statistic_sheet_text" android:textColor="@color/statistic_sheet_text"
android:text="@string/statistics_sheet_p_recording_start"
app:layout_constraintStart_toStartOf="@+id/statistics_p_duration" app:layout_constraintStart_toStartOf="@+id/statistics_p_duration"
app:layout_constraintTop_toBottomOf="@+id/statistics_p_duration" /> app:layout_constraintTop_toBottomOf="@+id/statistics_p_duration" />
@ -173,9 +179,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:contentDescription="@string/descr_statistics_sheet_p_recording_end" android:contentDescription="@string/descr_statistics_sheet_p_recording_end"
android:text="@string/statistics_sheet_p_recording_stop"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@color/statistic_sheet_text" android:textColor="@color/statistic_sheet_text"
android:text="@string/statistics_sheet_p_recording_stop"
app:layout_constraintStart_toStartOf="@+id/statistics_p_recording_start" app:layout_constraintStart_toStartOf="@+id/statistics_p_recording_start"
app:layout_constraintTop_toBottomOf="@+id/statistics_p_recording_start" /> app:layout_constraintTop_toBottomOf="@+id/statistics_p_recording_start" />
@ -198,9 +204,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:contentDescription="@string/descr_statistics_sheet_p_positive_elevation" android:contentDescription="@string/descr_statistics_sheet_p_positive_elevation"
android:text="@string/statistics_sheet_p_positive_elevation"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@color/statistic_sheet_text" android:textColor="@color/statistic_sheet_text"
android:text="@string/statistics_sheet_p_positive_elevation"
app:layout_constraintStart_toStartOf="@+id/statistics_p_recording_stop" app:layout_constraintStart_toStartOf="@+id/statistics_p_recording_stop"
app:layout_constraintTop_toBottomOf="@+id/statistics_p_recording_stop" /> app:layout_constraintTop_toBottomOf="@+id/statistics_p_recording_stop" />
@ -209,9 +215,9 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:text="@string/statistics_sheet_p_default_data"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@color/statistic_sheet_text" android:textColor="@color/statistic_sheet_text"
android:text="@string/statistics_sheet_p_default_data"
app:layout_constraintBottom_toBottomOf="@+id/statistics_p_positive_elevation" app:layout_constraintBottom_toBottomOf="@+id/statistics_p_positive_elevation"
app:layout_constraintStart_toEndOf="@+id/statistics_p_positive_elevation" app:layout_constraintStart_toEndOf="@+id/statistics_p_positive_elevation"
app:layout_constraintTop_toTopOf="@+id/statistics_p_positive_elevation" /> app:layout_constraintTop_toTopOf="@+id/statistics_p_positive_elevation" />
@ -222,9 +228,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:contentDescription="@string/descr_statistics_sheet_p_negative_elevation" android:contentDescription="@string/descr_statistics_sheet_p_negative_elevation"
android:text="@string/statistics_sheet_p_negative_elevation"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@color/statistic_sheet_text" android:textColor="@color/statistic_sheet_text"
android:text="@string/statistics_sheet_p_negative_elevation"
app:layout_constraintStart_toStartOf="@+id/statistics_p_positive_elevation" app:layout_constraintStart_toStartOf="@+id/statistics_p_positive_elevation"
app:layout_constraintTop_toBottomOf="@+id/statistics_p_positive_elevation" /> app:layout_constraintTop_toBottomOf="@+id/statistics_p_positive_elevation" />
@ -233,9 +239,9 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:text="@string/statistics_sheet_p_default_data"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@color/statistic_sheet_text" android:textColor="@color/statistic_sheet_text"
android:text="@string/statistics_sheet_p_default_data"
app:layout_constraintBottom_toBottomOf="@+id/statistics_p_negative_elevation" app:layout_constraintBottom_toBottomOf="@+id/statistics_p_negative_elevation"
app:layout_constraintStart_toEndOf="@+id/statistics_p_negative_elevation" app:layout_constraintStart_toEndOf="@+id/statistics_p_negative_elevation"
app:layout_constraintTop_toTopOf="@+id/statistics_p_negative_elevation" /> app:layout_constraintTop_toTopOf="@+id/statistics_p_negative_elevation" />
@ -246,9 +252,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:contentDescription="@string/descr_statistics_sheet_p_max_altitude" android:contentDescription="@string/descr_statistics_sheet_p_max_altitude"
android:text="@string/statistics_sheet_p_max_altitude"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@color/statistic_sheet_text" android:textColor="@color/statistic_sheet_text"
android:text="@string/statistics_sheet_p_max_altitude"
app:layout_constraintStart_toStartOf="@+id/statistics_p_negative_elevation" app:layout_constraintStart_toStartOf="@+id/statistics_p_negative_elevation"
app:layout_constraintTop_toBottomOf="@+id/statistics_p_negative_elevation" /> app:layout_constraintTop_toBottomOf="@+id/statistics_p_negative_elevation" />
@ -257,9 +263,9 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:text="@string/statistics_sheet_p_default_data"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@color/statistic_sheet_text" android:textColor="@color/statistic_sheet_text"
android:text="@string/statistics_sheet_p_default_data"
app:layout_constraintBottom_toBottomOf="@+id/statistics_p_max_altitude" app:layout_constraintBottom_toBottomOf="@+id/statistics_p_max_altitude"
app:layout_constraintStart_toEndOf="@+id/statistics_p_max_altitude" app:layout_constraintStart_toEndOf="@+id/statistics_p_max_altitude"
app:layout_constraintTop_toTopOf="@+id/statistics_p_max_altitude" /> app:layout_constraintTop_toTopOf="@+id/statistics_p_max_altitude" />
@ -268,13 +274,11 @@
android:id="@+id/statistics_p_min_altitude" android:id="@+id/statistics_p_min_altitude"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:contentDescription="@string/descr_statistics_sheet_p_min_altitude" android:contentDescription="@string/descr_statistics_sheet_p_min_altitude"
android:text="@string/statistics_sheet_p_min_altitude"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@color/statistic_sheet_text" android:textColor="@color/statistic_sheet_text"
android:text="@string/statistics_sheet_p_min_altitude"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@+id/statistics_p_max_altitude" app:layout_constraintStart_toStartOf="@+id/statistics_p_max_altitude"
app:layout_constraintTop_toBottomOf="@+id/statistics_p_max_altitude" /> app:layout_constraintTop_toBottomOf="@+id/statistics_p_max_altitude" />
@ -283,9 +287,9 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:text="@string/statistics_sheet_p_default_data"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@color/statistic_sheet_text" android:textColor="@color/statistic_sheet_text"
android:text="@string/statistics_sheet_p_default_data"
app:layout_constraintBottom_toBottomOf="@+id/statistics_p_min_altitude" app:layout_constraintBottom_toBottomOf="@+id/statistics_p_min_altitude"
app:layout_constraintStart_toEndOf="@+id/statistics_p_min_altitude" app:layout_constraintStart_toEndOf="@+id/statistics_p_min_altitude"
app:layout_constraintTop_toTopOf="@+id/statistics_p_min_altitude" /> app:layout_constraintTop_toTopOf="@+id/statistics_p_min_altitude" />