Skip to content

Commit

Permalink
TrackRecordingActivity: added setting for fullscreen.
Browse files Browse the repository at this point in the history
Fixes #342.
  • Loading branch information
dennisguse committed Aug 3, 2020
1 parent 1189a07 commit ebf7b0a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/main/java/de/dennisguse/opentracks/TrackRecordingActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public void onSharedPreferenceChanged(SharedPreferences preferences, String key)
if (PreferencesUtils.isKey(TrackRecordingActivity.this, R.string.stats_keep_screen_on_while_recording_key, key)) {
setScreenOnPolicy();
}
if (PreferencesUtils.isKey(TrackRecordingActivity.this, R.string.stats_fullscreen_while_recording_key, key)) {
setFullscreenPolicy();
}

if (key == null) return;

Expand Down Expand Up @@ -190,12 +193,12 @@ protected void onCreate(Bundle savedInstanceState) {
public void onAttachedToWindow() {
setLockscreenPolicy();
setScreenOnPolicy();
setFullscreenPolicy();
super.onAttachedToWindow();
}

private void setLockscreenPolicy() {
boolean showOnLockScreen = PreferencesUtils.shouldShowStatsOnLockscreen(TrackRecordingActivity.this)
&& PreferencesUtils.isRecording(this);
boolean showOnLockScreen = PreferencesUtils.shouldShowStatsOnLockscreen(TrackRecordingActivity.this);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
setShowWhenLocked(showOnLockScreen);
Expand All @@ -207,8 +210,7 @@ private void setLockscreenPolicy() {
}

private void setScreenOnPolicy() {
boolean keepScreenOn = PreferencesUtils.shouldKeepScreenOn(TrackRecordingActivity.this)
&& PreferencesUtils.isRecording(this);
boolean keepScreenOn = PreferencesUtils.shouldKeepScreenOn(TrackRecordingActivity.this);

if (keepScreenOn) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Expand All @@ -217,6 +219,16 @@ private void setScreenOnPolicy() {
}
}

private void setFullscreenPolicy() {
boolean keepScreenOn = PreferencesUtils.shouldUseFullscreen(TrackRecordingActivity.this);

if (keepScreenOn) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}

@Override
protected void onStart() {
super.onStart();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class IntentDashboardUtils {

private static final String EXTRAS_SHOULD_KEEP_SCREEN_ON = "EXTRAS_SHOULD_KEEP_SCREEN_ON";
private static final String EXTRAS_SHOW_WHEN_LOCKED = "EXTRAS_SHOULD_KEEP_SCREEN_ON";
private static final String EXTRAS_SHOW_FULLSCREEN = "EXTRAS_SHOULD_FULLSCREEN";

private static final int TRACK_URI_INDEX = 0;
private static final int TRACKPOINTS_URI_INDEX = 1;
Expand Down Expand Up @@ -58,6 +59,7 @@ public static void startDashboard(Context context, long[] trackIds) {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(EXTRAS_SHOULD_KEEP_SCREEN_ON, PreferencesUtils.shouldKeepScreenOn(context));
intent.putExtra(EXTRAS_SHOW_WHEN_LOCKED, PreferencesUtils.shouldShowStatsOnLockscreen(context));
intent.putExtra(EXTRAS_SHOW_FULLSCREEN, PreferencesUtils.shouldUseFullscreen(context));

intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
ClipData clipData = ClipData.newRawUri(null, uris.get(TRACK_URI_INDEX));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ public static boolean shouldKeepScreenOn(Context context) {
return getBoolean(context, R.string.stats_keep_screen_on_while_recording_key, DEFAULT);
}

public static boolean shouldUseFullscreen(Context context) {
final boolean DEFAULT = context.getResources().getBoolean(R.bool.stats_fullscreen_while_recording_default);
return getBoolean(context, R.string.stats_fullscreen_while_recording_key, DEFAULT);
}

public static boolean isShowStatsElevation(Context context) {
final boolean STATS_SHOW_ELEVATION = context.getResources().getBoolean(R.bool.stats_show_elevation_default);
return getBoolean(context, R.string.stats_show_grade_elevation_key, STATS_SHOW_ELEVATION);
Expand Down
3 changes: 3 additions & 0 deletions src/main/res/values/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<string name="stats_keep_screen_on_while_recording_key" translatable="false">trackdetail_keep_screen_on_while_recording</string>
<bool name="stats_keep_screen_on_while_recording_default" translatable="false">false</bool>

<string name="stats_fullscreen_while_recording_key" translatable="false">trackdetail_fullscreen_while_recording</string>
<bool name="stats_fullscreen_while_recording_default" translatable="false">false</bool>

<string name="settings_reset_key" translatable="false">settingsReset</string>

<string name="settings_sensor_bluetooth_heart_rate_key" translatable="false">bluetoothSensor</string>
Expand Down
2 changes: 2 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ limitations under the License.
<string name="settings_recording_show_on_lockscreen_while_recording_summary">While recording, show statistics without unlocking the device.</string>
<string name="settings_recording_keep_screen_on_while_recording_title">Keep screen on</string>
<string name="settings_recording_keep_screen_on_while_recording_summary">While recording, keep the screen on.</string>
<string name="settings_recording_fullscreen_on_while_recording_title">Fullscreen</string>
<string name="settings_recording_fullscreen_on_while_recording_summary">While recording, present in fullscreen.</string>
<string name="settings_recording">Recording</string>
<string name="settings_recording_auto_resume_track_timeout_always_summary">Always resume a recording after reboot</string>
<string name="settings_recording_auto_resume_track_timeout_never_summary">Never resume a recording after reboot</string>
Expand Down
5 changes: 5 additions & 0 deletions src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ limitations under the License.
android:key="@string/stats_keep_screen_on_while_recording_key"
android:summary="@string/settings_recording_keep_screen_on_while_recording_summary"
android:title="@string/settings_recording_keep_screen_on_while_recording_title" />
<SwitchPreferenceCompat
android:defaultValue="@bool/stats_fullscreen_while_recording_default"
android:key="@string/stats_fullscreen_while_recording_key"
android:summary="@string/settings_recording_fullscreen_on_while_recording_summary"
android:title="@string/settings_recording_fullscreen_on_while_recording_title" />
<ListPreference
android:defaultValue="@string/voice_frequency_default"
android:entryValues="@array/frequency_values"
Expand Down

0 comments on commit ebf7b0a

Please sign in to comment.