state of night mode is now remebered corrextly
parent
616741725a
commit
fd8dad3c74
|
@ -339,8 +339,7 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
|
||||||
case RESULT_EXPORT_DIALOG:
|
case RESULT_EXPORT_DIALOG:
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
// User chose EXPORT
|
// User chose EXPORT
|
||||||
ExportHelper exportHelper = new ExportHelper(mActivity);
|
ExportHelper.exportToGpx(mActivity, mTrack);
|
||||||
exportHelper.exportToGpx(mTrack);
|
|
||||||
} else if (resultCode == Activity.RESULT_CANCELED){
|
} else if (resultCode == Activity.RESULT_CANCELED){
|
||||||
// User chose CANCEL
|
// User chose CANCEL
|
||||||
LogHelper.v(LOG_TAG, "Export to GPX: User chose CANCEL.");
|
LogHelper.v(LOG_TAG, "Export to GPX: User chose CANCEL.");
|
||||||
|
@ -536,11 +535,8 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
|
||||||
String recordingStartDate = df.format(mTrack.getRecordingStart());
|
String recordingStartDate = df.format(mTrack.getRecordingStart());
|
||||||
String dialogMessage;
|
String dialogMessage;
|
||||||
|
|
||||||
// create an ExportHelper
|
|
||||||
final ExportHelper exportHelper = new ExportHelper(mActivity);
|
|
||||||
|
|
||||||
// get text elements for delete dialog
|
// get text elements for delete dialog
|
||||||
if (exportHelper.gpxFileExists(mTrack)) {
|
if (ExportHelper.gpxFileExists(mTrack)) {
|
||||||
// CASE: OVERWRITE - GPX file exists
|
// CASE: OVERWRITE - GPX file exists
|
||||||
dialogTitle = R.string.dialog_export_title_overwrite;
|
dialogTitle = R.string.dialog_export_title_overwrite;
|
||||||
dialogMessage = getString(R.string.dialog_export_content_overwrite) + " (" + recordingStartDate + " | " + mTrack.getTrackDistanceString() + ")";
|
dialogMessage = getString(R.string.dialog_export_content_overwrite) + " (" + recordingStartDate + " | " + mTrack.getTrackDistanceString() + ")";
|
||||||
|
|
|
@ -38,69 +38,59 @@ import java.util.TimeZone;
|
||||||
/**
|
/**
|
||||||
* ExportHelper class
|
* ExportHelper class
|
||||||
*/
|
*/
|
||||||
public class ExportHelper implements TrackbookKeys {
|
public final class ExportHelper implements TrackbookKeys {
|
||||||
|
|
||||||
/* Define log tag */
|
/* Define log tag */
|
||||||
private static final String LOG_TAG = ExportHelper.class.getSimpleName();
|
private static final String LOG_TAG = ExportHelper.class.getSimpleName();
|
||||||
|
|
||||||
|
|
||||||
/* Main class variables */
|
|
||||||
// private final Track mTrack;
|
|
||||||
private final Context mContext;
|
|
||||||
private final File mFolder;
|
|
||||||
|
|
||||||
|
|
||||||
/* Constructor */
|
|
||||||
public ExportHelper(Context context) {
|
|
||||||
mContext = context;
|
|
||||||
mFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Checks if a GPX file for given track is already present */
|
/* Checks if a GPX file for given track is already present */
|
||||||
public boolean gpxFileExists(Track track) {
|
public static boolean gpxFileExists(Track track) {
|
||||||
return createFile(track).exists();
|
File folder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
|
||||||
|
return createFile(track, folder).exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Exports given track to GPX */
|
/* Exports given track to GPX */
|
||||||
public boolean exportToGpx(Track track) {
|
public static boolean exportToGpx(Context context, Track track) {
|
||||||
|
// get "Download" folder
|
||||||
|
File folder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
|
||||||
|
|
||||||
// create "Download" folder if necessary
|
// create "Download" folder if necessary
|
||||||
if (mFolder != null && !mFolder.exists()) {
|
if (folder != null && !folder.exists()) {
|
||||||
LogHelper.v(LOG_TAG, "Creating new folder: " + mFolder.toString());
|
LogHelper.v(LOG_TAG, "Creating new folder: " + folder.toString());
|
||||||
mFolder.mkdirs();
|
folder.mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
// get file for given track
|
// get file for given track
|
||||||
File gpxFile = createFile(track);
|
File gpxFile = createFile(track, folder);
|
||||||
|
|
||||||
// get GPX string representation for given track
|
// get GPX string representation for given track
|
||||||
String gpxString = createGpxString(track);
|
String gpxString = createGpxString(track);
|
||||||
|
|
||||||
// write GPX file
|
// write GPX file
|
||||||
if (writeGpxToFile(gpxString, gpxFile)) {
|
if (writeGpxToFile(gpxString, gpxFile)) {
|
||||||
String toastMessage = mContext.getResources().getString(R.string.toast_message_export_success) + " " + gpxFile.toString();
|
String toastMessage = context.getResources().getString(R.string.toast_message_export_success) + " " + gpxFile.toString();
|
||||||
Toast.makeText(mContext, toastMessage, Toast.LENGTH_LONG).show();
|
Toast.makeText(context, toastMessage, Toast.LENGTH_LONG).show();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
String toastMessage = mContext.getResources().getString(R.string.toast_message_export_fail) + " " + gpxFile.toString();
|
String toastMessage = context.getResources().getString(R.string.toast_message_export_fail) + " " + gpxFile.toString();
|
||||||
Toast.makeText(mContext, toastMessage, Toast.LENGTH_LONG).show();
|
Toast.makeText(context, toastMessage, Toast.LENGTH_LONG).show();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Return a GPX filepath for a given track */
|
/* Return a GPX filepath for a given track */
|
||||||
private File createFile(Track track) {
|
private static File createFile(Track track, File folder) {
|
||||||
Date recordingStart = track.getRecordingStart();
|
Date recordingStart = track.getRecordingStart();
|
||||||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US);
|
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US);
|
||||||
return new File(mFolder, dateFormat.format(recordingStart) + FILE_TYPE_GPX_EXTENSION);
|
return new File(folder, dateFormat.format(recordingStart) + FILE_TYPE_GPX_EXTENSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Writes given GPX string to Download folder */
|
/* Writes given GPX string to Download folder */
|
||||||
private boolean writeGpxToFile (String gpxString, File gpxFile) {
|
private static boolean writeGpxToFile (String gpxString, File gpxFile) {
|
||||||
// write track
|
// write track
|
||||||
try (BufferedWriter bw = new BufferedWriter(new FileWriter(gpxFile))) {
|
try (BufferedWriter bw = new BufferedWriter(new FileWriter(gpxFile))) {
|
||||||
LogHelper.v(LOG_TAG, "Saving track to external storage: " + gpxFile.toString());
|
LogHelper.v(LOG_TAG, "Saving track to external storage: " + gpxFile.toString());
|
||||||
|
@ -114,7 +104,7 @@ public class ExportHelper implements TrackbookKeys {
|
||||||
|
|
||||||
|
|
||||||
/* Creates GPX formatted string */
|
/* Creates GPX formatted string */
|
||||||
private String createGpxString(Track track) {
|
private static String createGpxString(Track track) {
|
||||||
String gpxString;
|
String gpxString;
|
||||||
|
|
||||||
// add header
|
// add header
|
||||||
|
@ -134,7 +124,7 @@ public class ExportHelper implements TrackbookKeys {
|
||||||
|
|
||||||
|
|
||||||
/* Creates Track */
|
/* Creates Track */
|
||||||
private String addTrack(Track track) {
|
private static String addTrack(Track track) {
|
||||||
StringBuilder gpxTrack = new StringBuilder("");
|
StringBuilder gpxTrack = new StringBuilder("");
|
||||||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US);
|
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US);
|
||||||
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
|
|
@ -31,7 +31,6 @@ import android.view.View;
|
||||||
*/
|
*/
|
||||||
public final class NightModeHelper implements TrackbookKeys {
|
public final class NightModeHelper implements TrackbookKeys {
|
||||||
|
|
||||||
|
|
||||||
/* Define log tag */
|
/* Define log tag */
|
||||||
private static final String LOG_TAG = NightModeHelper.class.getSimpleName();
|
private static final String LOG_TAG = NightModeHelper.class.getSimpleName();
|
||||||
|
|
||||||
|
@ -62,21 +61,21 @@ public final class NightModeHelper implements TrackbookKeys {
|
||||||
int currentNightModeState = getCurrentNightModeState(activity);
|
int currentNightModeState = getCurrentNightModeState(activity);
|
||||||
LogHelper.i(LOG_TAG, "Saved state of Night Mode = " + savedNightModeState + " || current state of Night Mode = " + currentNightModeState + " || NO=16 & YES=32"); // todo remove
|
LogHelper.i(LOG_TAG, "Saved state of Night Mode = " + savedNightModeState + " || current state of Night Mode = " + currentNightModeState + " || NO=16 & YES=32"); // todo remove
|
||||||
if (savedNightModeState != -1 && savedNightModeState != currentNightModeState) {
|
if (savedNightModeState != -1 && savedNightModeState != currentNightModeState) {
|
||||||
// switch (savedNightModeState) {
|
switch (savedNightModeState) {
|
||||||
// case Configuration.UI_MODE_NIGHT_NO:
|
case Configuration.UI_MODE_NIGHT_NO:
|
||||||
// // turn off night mode
|
// turn off night mode
|
||||||
// deactivateNightMode(activity);
|
deactivateNightMode(activity);
|
||||||
// break;
|
break;
|
||||||
// case Configuration.UI_MODE_NIGHT_YES:
|
case Configuration.UI_MODE_NIGHT_YES:
|
||||||
// // turn on night mode
|
// turn on night mode
|
||||||
// activateNightMode(activity);
|
activateNightMode(activity);
|
||||||
// break;
|
break;
|
||||||
// case Configuration.UI_MODE_NIGHT_UNDEFINED:
|
case Configuration.UI_MODE_NIGHT_UNDEFINED:
|
||||||
// // turn off night mode
|
// turn off night mode
|
||||||
// deactivateNightMode(activity);
|
deactivateNightMode(activity);
|
||||||
// break;
|
break;
|
||||||
// }
|
}
|
||||||
// activity.recreate(); // todo check if necessary
|
activity.recreate(); // todo check if necessary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,23 +88,32 @@ public final class NightModeHelper implements TrackbookKeys {
|
||||||
|
|
||||||
/* Activates Night Mode */
|
/* Activates Night Mode */
|
||||||
private static void activateNightMode(Activity activity) {
|
private static void activateNightMode(Activity activity) {
|
||||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
|
saveNightModeState(activity, Configuration.UI_MODE_NIGHT_YES);
|
||||||
|
|
||||||
|
// revert to normal status bar
|
||||||
View decorView = activity.getWindow().getDecorView();
|
View decorView = activity.getWindow().getDecorView();
|
||||||
decorView.setSystemUiVisibility(0);
|
decorView.setSystemUiVisibility(0);
|
||||||
saveNightModeState(activity, Configuration.UI_MODE_NIGHT_NO);
|
|
||||||
|
// switch to Nighh Mode
|
||||||
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Deactivates Night Mode */
|
/* Deactivates Night Mode */
|
||||||
private static void deactivateNightMode(Activity activity) {
|
private static void deactivateNightMode(Activity activity) {
|
||||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
|
// save the new state
|
||||||
|
saveNightModeState(activity, Configuration.UI_MODE_NIGHT_NO);
|
||||||
|
|
||||||
|
// switch to white status bar - if possible
|
||||||
View decorView = activity.getWindow().getDecorView();
|
View decorView = activity.getWindow().getDecorView();
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||||
} else {
|
} else {
|
||||||
decorView.setSystemUiVisibility(0);
|
decorView.setSystemUiVisibility(0);
|
||||||
}
|
}
|
||||||
saveNightModeState(activity, Configuration.UI_MODE_NIGHT_YES);
|
|
||||||
|
// switch to Day Mode
|
||||||
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ import org.y20k.trackbook.core.Track;
|
||||||
/**
|
/**
|
||||||
* NotificationHelper class
|
* NotificationHelper class
|
||||||
*/
|
*/
|
||||||
public class NotificationHelper implements TrackbookKeys {
|
public final class NotificationHelper implements TrackbookKeys {
|
||||||
|
|
||||||
/* Define log tag */
|
/* Define log tag */
|
||||||
private static final String LOG_TAG = NotificationHelper.class.getSimpleName();
|
private static final String LOG_TAG = NotificationHelper.class.getSimpleName();
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
android:layout_width="@dimen/bottom_sheet_width"
|
android:layout_width="@dimen/bottom_sheet_width"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
android:background="@color/statistic_sheet_background_expanded"
|
android:background="@color/statistic_sheet_background_collapsed"
|
||||||
app:behavior_hideable="false"
|
app:behavior_hideable="false"
|
||||||
app:behavior_peekHeight="54dp"
|
app:behavior_peekHeight="54dp"
|
||||||
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
|
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
|
||||||
|
|
Loading…
Reference in New Issue