2016-09-20 11:51:17 +00:00
|
|
|
/**
|
|
|
|
* MainActivityTrackFragment.java
|
|
|
|
* Implements the track fragment used in the track tab of the main activity
|
|
|
|
* This fragment displays a saved track
|
|
|
|
*
|
|
|
|
* This file is part of
|
|
|
|
* TRACKBOOK - Movement Recorder for Android
|
|
|
|
*
|
2017-01-19 12:36:49 +00:00
|
|
|
* Copyright (c) 2016-17 - Y20K.org
|
2016-09-20 11:51:17 +00:00
|
|
|
* Licensed under the MIT-License
|
|
|
|
* http://opensource.org/licenses/MIT
|
|
|
|
*
|
|
|
|
* Trackbook uses osmdroid - OpenStreetMap-Tools for Android
|
|
|
|
* https://github.com/osmdroid/osmdroid
|
|
|
|
*/
|
|
|
|
|
2016-09-16 15:45:10 +00:00
|
|
|
package org.y20k.trackbook;
|
|
|
|
|
2016-09-29 10:54:57 +00:00
|
|
|
import android.app.Activity;
|
2016-12-19 16:53:20 +00:00
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
2016-09-30 15:32:54 +00:00
|
|
|
import android.location.Location;
|
|
|
|
import android.os.AsyncTask;
|
2016-09-16 15:45:10 +00:00
|
|
|
import android.os.Bundle;
|
2016-12-05 14:10:24 +00:00
|
|
|
import android.support.annotation.NonNull;
|
2016-09-16 15:45:10 +00:00
|
|
|
import android.support.annotation.Nullable;
|
2016-09-29 10:54:57 +00:00
|
|
|
import android.support.design.widget.BottomSheetBehavior;
|
2016-09-16 15:45:10 +00:00
|
|
|
import android.support.v4.app.Fragment;
|
2016-12-19 16:53:20 +00:00
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
2016-09-16 15:45:10 +00:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2017-02-15 14:29:21 +00:00
|
|
|
import android.widget.AdapterView;
|
2017-02-17 08:58:37 +00:00
|
|
|
import android.widget.LinearLayout;
|
2017-02-03 20:12:13 +00:00
|
|
|
import android.widget.Spinner;
|
2016-09-29 10:54:57 +00:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
2016-09-30 15:32:54 +00:00
|
|
|
import org.osmdroid.api.IMapController;
|
|
|
|
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
|
|
|
|
import org.osmdroid.util.GeoPoint;
|
|
|
|
import org.osmdroid.views.MapView;
|
|
|
|
import org.osmdroid.views.overlay.ItemizedIconOverlay;
|
|
|
|
import org.osmdroid.views.overlay.compass.CompassOverlay;
|
|
|
|
import org.osmdroid.views.overlay.compass.InternalCompassOrientationProvider;
|
2016-09-29 10:54:57 +00:00
|
|
|
import org.y20k.trackbook.core.Track;
|
2017-02-03 20:12:13 +00:00
|
|
|
import org.y20k.trackbook.helpers.DropdownAdapter;
|
2016-09-30 15:32:54 +00:00
|
|
|
import org.y20k.trackbook.helpers.LogHelper;
|
|
|
|
import org.y20k.trackbook.helpers.MapHelper;
|
2016-09-29 10:54:57 +00:00
|
|
|
import org.y20k.trackbook.helpers.StorageHelper;
|
2016-09-30 15:32:54 +00:00
|
|
|
import org.y20k.trackbook.helpers.TrackbookKeys;
|
2016-09-16 15:45:10 +00:00
|
|
|
|
2017-02-15 14:29:21 +00:00
|
|
|
import java.io.File;
|
2016-10-05 11:53:31 +00:00
|
|
|
import java.text.DateFormat;
|
2017-01-23 11:32:27 +00:00
|
|
|
import java.util.Locale;
|
2016-10-05 11:53:31 +00:00
|
|
|
|
2016-09-20 11:51:17 +00:00
|
|
|
|
2016-09-16 15:45:10 +00:00
|
|
|
/**
|
2016-09-20 11:51:17 +00:00
|
|
|
* MainActivityTrackFragment class
|
2016-09-16 15:45:10 +00:00
|
|
|
*/
|
2017-02-15 14:29:21 +00:00
|
|
|
public class MainActivityTrackFragment extends Fragment implements AdapterView.OnItemSelectedListener, TrackbookKeys {
|
2016-09-16 15:45:10 +00:00
|
|
|
|
2016-09-20 11:51:17 +00:00
|
|
|
/* Define log tag */
|
|
|
|
private static final String LOG_TAG = MainActivityTrackFragment.class.getSimpleName();
|
|
|
|
|
2016-09-16 15:45:10 +00:00
|
|
|
|
|
|
|
/* Main class variables */
|
2016-09-29 10:54:57 +00:00
|
|
|
private Activity mActivity;
|
2016-09-16 15:45:10 +00:00
|
|
|
private View mRootView;
|
2016-09-30 15:32:54 +00:00
|
|
|
private MapView mMapView;
|
2017-02-17 08:58:37 +00:00
|
|
|
private LinearLayout mOnboardingView;
|
2016-09-30 15:32:54 +00:00
|
|
|
private IMapController mController;
|
|
|
|
private ItemizedIconOverlay mTrackOverlay;
|
2017-02-03 20:12:13 +00:00
|
|
|
private DropdownAdapter mDropdownAdapter;
|
2017-02-17 08:58:37 +00:00
|
|
|
private LinearLayout mTrackManagementLayout;
|
2017-02-03 20:12:13 +00:00
|
|
|
private Spinner mDropdown;
|
2016-09-29 10:54:57 +00:00
|
|
|
private TextView mDistanceView;
|
|
|
|
private TextView mStepsView;
|
|
|
|
private TextView mWaypointsView;
|
|
|
|
private TextView mDurationView;
|
|
|
|
private TextView mRecordingStartView;
|
|
|
|
private TextView mRecordingStopView;
|
|
|
|
private BottomSheetBehavior mStatisticsSheetBehavior;
|
2017-02-15 14:29:21 +00:00
|
|
|
private int mCurrentTrack;
|
2016-09-29 10:54:57 +00:00
|
|
|
private Track mTrack;
|
2016-12-19 16:53:20 +00:00
|
|
|
private BroadcastReceiver mTrackSavedReceiver;
|
2016-09-29 10:54:57 +00:00
|
|
|
|
2016-09-16 15:45:10 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
// action bar has options menu
|
|
|
|
setHasOptionsMenu(true);
|
2016-09-29 10:54:57 +00:00
|
|
|
|
|
|
|
// store activity
|
|
|
|
mActivity = getActivity();
|
2016-12-19 16:53:20 +00:00
|
|
|
|
2017-02-15 14:29:21 +00:00
|
|
|
// get current track
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
mCurrentTrack = savedInstanceState.getInt(INSTANCE_CURRENT_TRACK, 0);
|
|
|
|
} else {
|
|
|
|
mCurrentTrack = 0;
|
|
|
|
}
|
|
|
|
|
2017-02-03 20:12:13 +00:00
|
|
|
// create drop-down adapter
|
|
|
|
mDropdownAdapter = new DropdownAdapter(mActivity);
|
|
|
|
|
2017-01-10 14:57:03 +00:00
|
|
|
// listen for finished save operation
|
2016-12-19 16:53:20 +00:00
|
|
|
mTrackSavedReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
if (intent.hasExtra(EXTRA_SAVE_FINISHED) && intent.getBooleanExtra(EXTRA_SAVE_FINISHED, false)) {
|
2017-01-10 14:57:03 +00:00
|
|
|
LogHelper.v(LOG_TAG, "Save operation detected. Start loading the new track.");
|
2017-02-15 14:29:21 +00:00
|
|
|
|
2017-02-17 08:58:37 +00:00
|
|
|
// update dropdown menu (and load track in onItemSelected)
|
2017-02-15 14:29:21 +00:00
|
|
|
mDropdownAdapter.refresh();
|
|
|
|
mDropdownAdapter.notifyDataSetChanged();
|
2017-02-17 08:58:37 +00:00
|
|
|
mDropdown.setAdapter(mDropdownAdapter);
|
|
|
|
mDropdown.setSelection(0, true);
|
2016-12-19 16:53:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2017-01-10 14:57:03 +00:00
|
|
|
IntentFilter trackSavedReceiverIntentFilter = new IntentFilter(ACTION_TRACK_SAVE);
|
|
|
|
LocalBroadcastManager.getInstance(mActivity).registerReceiver(mTrackSavedReceiver, trackSavedReceiverIntentFilter);
|
2016-12-19 16:53:20 +00:00
|
|
|
|
2016-09-16 15:45:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
|
|
|
|
|
|
// inflate root view from xml
|
|
|
|
mRootView = inflater.inflate(R.layout.fragment_main_track, container, false);
|
|
|
|
|
2017-02-17 08:58:37 +00:00
|
|
|
// get reference to onboarding layout
|
|
|
|
mOnboardingView = (LinearLayout) mRootView.findViewById(R.id.track_tab_onboarding);
|
|
|
|
|
|
|
|
// get reference to basic map
|
2016-09-30 15:32:54 +00:00
|
|
|
mMapView = (MapView) mRootView.findViewById(R.id.track_map);
|
|
|
|
|
|
|
|
// get map controller
|
|
|
|
mController = mMapView.getController();
|
|
|
|
|
|
|
|
// basic map setup
|
|
|
|
mMapView.setTileSource(TileSourceFactory.MAPNIK);
|
|
|
|
mMapView.setTilesScaledToDpi(true);
|
|
|
|
|
|
|
|
// add multi-touch capability
|
|
|
|
mMapView.setMultiTouchControls(true);
|
|
|
|
|
|
|
|
// add compass to map
|
|
|
|
CompassOverlay compassOverlay = new CompassOverlay(mActivity, new InternalCompassOrientationProvider(mActivity), mMapView);
|
|
|
|
compassOverlay.enableCompass();
|
2017-02-15 14:29:21 +00:00
|
|
|
// move the compass overlay down a bit
|
|
|
|
compassOverlay.setCompassCenter(35.0f, 80.0f);
|
2016-09-30 15:32:54 +00:00
|
|
|
mMapView.getOverlays().add(compassOverlay);
|
|
|
|
|
|
|
|
// initiate map state
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
// restore saved instance of map
|
|
|
|
GeoPoint position = new GeoPoint(savedInstanceState.getDouble(INSTANCE_LATITUDE_TRACK_MAP, DEFAULT_LATITUDE), savedInstanceState.getDouble(INSTANCE_LONGITUDE_TRACK_MAP, DEFAULT_LONGITUDE));
|
|
|
|
mController.setCenter(position);
|
|
|
|
mController.setZoom(savedInstanceState.getInt(INSTANCE_ZOOM_LEVEL_MAIN_MAP, 16));
|
|
|
|
} else {
|
|
|
|
mController.setZoom(16);
|
|
|
|
}
|
|
|
|
|
2017-02-03 20:12:13 +00:00
|
|
|
// get views for track selector
|
2017-02-17 08:58:37 +00:00
|
|
|
mTrackManagementLayout = (LinearLayout) mRootView.findViewById(R.id.track_management_layout);
|
2017-02-03 20:12:13 +00:00
|
|
|
mDropdown = (Spinner) mRootView.findViewById(R.id.track_selector);
|
2016-09-30 15:32:54 +00:00
|
|
|
|
2017-02-03 20:12:13 +00:00
|
|
|
// get views for statistics sheet
|
2017-01-20 12:34:37 +00:00
|
|
|
View statisticsView = mRootView.findViewById(R.id.statistics_view);
|
2016-09-29 10:54:57 +00:00
|
|
|
mDistanceView = (TextView) mRootView.findViewById(R.id.statistics_data_distance);
|
|
|
|
mStepsView = (TextView) mRootView.findViewById(R.id.statistics_data_steps);
|
|
|
|
mWaypointsView = (TextView) mRootView.findViewById(R.id.statistics_data_waypoints);
|
|
|
|
mDurationView = (TextView) mRootView.findViewById(R.id.statistics_data_duration);
|
|
|
|
mRecordingStartView = (TextView) mRootView.findViewById(R.id.statistics_data_recording_start);
|
|
|
|
mRecordingStopView = (TextView) mRootView.findViewById(R.id.statistics_data_recording_stop);
|
2016-12-19 16:53:20 +00:00
|
|
|
View mStatisticsSheet = mRootView.findViewById(R.id.statistics_sheet);
|
2016-09-29 10:54:57 +00:00
|
|
|
|
2017-01-10 14:57:03 +00:00
|
|
|
if (savedInstanceState != null) {
|
|
|
|
// get track from saved instance and display map and statistics
|
|
|
|
mTrack = savedInstanceState.getParcelable(INSTANCE_TRACK_TRACK_MAP);
|
|
|
|
displayTrack();
|
|
|
|
} else if (mTrack == null) {
|
2017-02-17 08:58:37 +00:00
|
|
|
// load track and display map and statistics
|
2016-10-05 11:53:31 +00:00
|
|
|
LoadTrackAsyncHelper loadTrackAsyncHelper = new LoadTrackAsyncHelper();
|
|
|
|
loadTrackAsyncHelper.execute();
|
|
|
|
} else {
|
2016-10-25 14:38:27 +00:00
|
|
|
// just display map and statistics
|
2016-10-05 11:53:31 +00:00
|
|
|
displayTrack();
|
|
|
|
}
|
|
|
|
|
|
|
|
// show statistics sheet
|
2016-09-29 10:54:57 +00:00
|
|
|
mStatisticsSheetBehavior = BottomSheetBehavior.from(mStatisticsSheet);
|
2016-12-05 14:10:24 +00:00
|
|
|
mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
|
|
|
mStatisticsSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
|
|
|
|
@Override
|
|
|
|
public void onStateChanged(@NonNull View bottomSheet, int newState) {
|
|
|
|
// react to state change
|
|
|
|
switch (newState) {
|
|
|
|
case BottomSheetBehavior.STATE_EXPANDED:
|
2017-01-25 13:19:50 +00:00
|
|
|
// statistics sheet expanded
|
2016-12-05 14:10:24 +00:00
|
|
|
break;
|
|
|
|
case BottomSheetBehavior.STATE_COLLAPSED:
|
2017-01-25 13:19:50 +00:00
|
|
|
// statistics sheet collapsed
|
2016-12-05 14:10:24 +00:00
|
|
|
mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
|
|
|
break;
|
|
|
|
case BottomSheetBehavior.STATE_HIDDEN:
|
2017-01-25 13:19:50 +00:00
|
|
|
// statistics sheet hidden
|
2016-12-05 14:10:24 +00:00
|
|
|
mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
|
|
|
|
// react to dragging events
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// react to tap on sheet heading
|
2017-01-20 12:34:37 +00:00
|
|
|
statisticsView.setOnClickListener(new View.OnClickListener() {
|
2016-12-05 14:10:24 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
if (mStatisticsSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
|
|
|
|
mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
|
|
|
} else {
|
|
|
|
mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-09-29 10:54:57 +00:00
|
|
|
|
2016-09-16 15:45:10 +00:00
|
|
|
return mRootView;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-15 14:29:21 +00:00
|
|
|
@Override
|
|
|
|
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
|
|
|
super.onViewCreated(view, savedInstanceState);
|
|
|
|
mDropdown.setAdapter(mDropdownAdapter);
|
|
|
|
mDropdown.setOnItemSelectedListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-16 15:45:10 +00:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
2017-02-17 08:58:37 +00:00
|
|
|
// show / hide the onboarding layout
|
|
|
|
switchOnboardingLayout();
|
2016-09-30 15:32:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroyView(){
|
|
|
|
super.onDestroyView();
|
|
|
|
|
|
|
|
// deactivate map
|
|
|
|
mMapView.onDetach();
|
|
|
|
}
|
2016-09-29 10:54:57 +00:00
|
|
|
|
|
|
|
|
2017-01-10 14:57:03 +00:00
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
2017-01-25 13:19:50 +00:00
|
|
|
LogHelper.v(LOG_TAG, "onDestroy called.");
|
2017-01-10 14:57:03 +00:00
|
|
|
|
|
|
|
// remove listener
|
|
|
|
LocalBroadcastManager.getInstance(mActivity).unregisterReceiver(mTrackSavedReceiver);
|
2017-01-25 13:19:50 +00:00
|
|
|
|
|
|
|
super.onDestroy();
|
2017-01-10 14:57:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-15 14:29:21 +00:00
|
|
|
@Override
|
|
|
|
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
|
|
|
|
// update current track
|
|
|
|
mCurrentTrack = i;
|
|
|
|
|
|
|
|
// load track and display map and statistics
|
|
|
|
LoadTrackAsyncHelper loadTrackAsyncHelper = new LoadTrackAsyncHelper();
|
2017-02-17 08:58:37 +00:00
|
|
|
loadTrackAsyncHelper.execute(i);
|
2017-02-15 14:29:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> adapterView) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-30 15:32:54 +00:00
|
|
|
@Override
|
|
|
|
public void onSaveInstanceState(Bundle outState) {
|
|
|
|
outState.putDouble(INSTANCE_LATITUDE_TRACK_MAP, mMapView.getMapCenter().getLatitude());
|
|
|
|
outState.putDouble(INSTANCE_LONGITUDE_TRACK_MAP, mMapView.getMapCenter().getLongitude());
|
|
|
|
outState.putInt(INSTANCE_ZOOM_LEVEL_TRACK_MAP, mMapView.getZoomLevel());
|
|
|
|
outState.putParcelable(INSTANCE_TRACK_TRACK_MAP, mTrack);
|
2017-02-15 14:29:21 +00:00
|
|
|
outState.putInt(INSTANCE_CURRENT_TRACK, mCurrentTrack);
|
2016-09-30 15:32:54 +00:00
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Displays map and statistics for track */
|
|
|
|
private void displayTrack() {
|
|
|
|
GeoPoint position;
|
|
|
|
|
2016-09-29 10:54:57 +00:00
|
|
|
if (mTrack != null) {
|
2016-09-30 15:32:54 +00:00
|
|
|
// set end of track as position
|
|
|
|
Location lastLocation = mTrack.getWayPointLocation(mTrack.getSize() -1);
|
|
|
|
position = new GeoPoint(lastLocation.getLatitude(), lastLocation.getLongitude());
|
|
|
|
|
2017-01-23 11:32:27 +00:00
|
|
|
String recordingStart = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()).format(mTrack.getRecordingStart()) + " " +
|
|
|
|
DateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault()).format(mTrack.getRecordingStart());
|
|
|
|
String recordingStop = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()).format(mTrack.getRecordingStop()) + " " +
|
|
|
|
DateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault()).format(mTrack.getRecordingStop());
|
2016-10-05 11:53:31 +00:00
|
|
|
|
2016-09-30 15:32:54 +00:00
|
|
|
// populate views
|
2016-09-29 10:54:57 +00:00
|
|
|
mDistanceView.setText(mTrack.getTrackDistance());
|
2016-09-30 15:32:54 +00:00
|
|
|
mStepsView.setText(String.valueOf(Math.round(mTrack.getStepCount())));
|
2016-09-29 10:54:57 +00:00
|
|
|
mWaypointsView.setText(String.valueOf(mTrack.getWayPoints().size()));
|
|
|
|
mDurationView.setText(mTrack.getTrackDuration());
|
2016-10-05 11:53:31 +00:00
|
|
|
mRecordingStartView.setText(recordingStart);
|
|
|
|
mRecordingStopView.setText(recordingStop);
|
2016-09-30 15:32:54 +00:00
|
|
|
|
|
|
|
// draw track on map
|
|
|
|
drawTrackOverlay(mTrack);
|
|
|
|
} else {
|
|
|
|
position = new GeoPoint(DEFAULT_LATITUDE, DEFAULT_LONGITUDE);
|
2016-09-29 10:54:57 +00:00
|
|
|
}
|
|
|
|
|
2016-09-30 15:32:54 +00:00
|
|
|
// center map over position
|
|
|
|
mController.setCenter(position);
|
|
|
|
|
2016-09-16 15:45:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-30 15:32:54 +00:00
|
|
|
/* Draws track onto overlay */
|
|
|
|
private void drawTrackOverlay(Track track) {
|
|
|
|
mMapView.getOverlays().remove(mTrackOverlay);
|
|
|
|
mTrackOverlay = MapHelper.createTrackOverlay(mActivity, track, false);
|
|
|
|
mMapView.getOverlays().add(mTrackOverlay);
|
2016-09-16 15:45:10 +00:00
|
|
|
}
|
|
|
|
|
2017-01-10 14:57:03 +00:00
|
|
|
|
2017-02-17 08:58:37 +00:00
|
|
|
/* show the onboarding layout, if no track has been recorded yet */
|
|
|
|
private void switchOnboardingLayout() {
|
|
|
|
if (mDropdownAdapter.isEmpty()){
|
|
|
|
// show onboarding layout
|
|
|
|
mMapView.setVisibility(View.GONE);
|
|
|
|
mOnboardingView.setVisibility(View.VISIBLE);
|
|
|
|
mTrackManagementLayout.setVisibility(View.INVISIBLE);
|
|
|
|
mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
|
|
|
} else {
|
|
|
|
// show normal layout
|
|
|
|
mOnboardingView.setVisibility(View.GONE);
|
|
|
|
mMapView.setVisibility(View.VISIBLE);
|
|
|
|
mTrackManagementLayout.setVisibility(View.VISIBLE);
|
|
|
|
mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-30 15:32:54 +00:00
|
|
|
/**
|
|
|
|
* Inner class: Loads track from external storage using AsyncTask
|
|
|
|
*/
|
2017-02-17 08:58:37 +00:00
|
|
|
private class LoadTrackAsyncHelper extends AsyncTask<Integer, Void, Void> {
|
2016-09-30 15:32:54 +00:00
|
|
|
|
|
|
|
@Override
|
2017-02-17 08:58:37 +00:00
|
|
|
protected Void doInBackground(Integer... ints) {
|
2016-09-30 15:32:54 +00:00
|
|
|
LogHelper.v(LOG_TAG, "Loading track object in background.");
|
2017-02-15 14:29:21 +00:00
|
|
|
|
2017-01-19 12:36:49 +00:00
|
|
|
StorageHelper storageHelper = new StorageHelper(mActivity);
|
2017-02-17 08:58:37 +00:00
|
|
|
if (ints.length > 0) {
|
|
|
|
// get track file from dropdown adapter
|
|
|
|
int item = ints[0];
|
|
|
|
File trackFile = mDropdownAdapter.getItem(item).getTrackFile();
|
|
|
|
LogHelper.v(LOG_TAG, "Loading track number " + item);
|
|
|
|
mTrack = storageHelper.loadTrack(trackFile);
|
2017-02-15 14:29:21 +00:00
|
|
|
} else {
|
|
|
|
// load track object from most current file
|
2017-02-17 08:58:37 +00:00
|
|
|
LogHelper.v(LOG_TAG, "No specific track specified. Loading most current one.");
|
2017-02-15 14:29:21 +00:00
|
|
|
mTrack = storageHelper.loadTrack(FILE_MOST_CURRENT_TRACK);
|
|
|
|
}
|
2016-09-30 15:32:54 +00:00
|
|
|
return null;
|
|
|
|
}
|
2016-09-16 15:45:10 +00:00
|
|
|
|
2016-09-30 15:32:54 +00:00
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Void aVoid) {
|
|
|
|
super.onPostExecute(aVoid);
|
2017-02-15 14:29:21 +00:00
|
|
|
|
|
|
|
// display track on map
|
2016-09-30 15:32:54 +00:00
|
|
|
displayTrack();
|
|
|
|
}
|
2016-09-16 15:45:10 +00:00
|
|
|
}
|
2017-02-03 20:12:13 +00:00
|
|
|
/**
|
|
|
|
* End of inner class
|
|
|
|
*/
|
2016-09-16 15:45:10 +00:00
|
|
|
|
|
|
|
}
|