Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Snapcast/src/main/java/de/badaix/snapcast/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,15 @@ public void onAutoStartChanged(boolean autoStart) {
Settings.getInstance(this).put("hide_offline", item.isChecked());
groupListFragment.setHideOffline(item.isChecked());
return true;
} else if (id == R.id.action_prevent_screen_off) {
item.setChecked(!item.isChecked());
Settings.getInstance(this).put("prevent_screen_off", item.isChecked());
// Update the wake lock setting in the SnapclientService
if (snapclientService != null) {
boolean fullWakeLock = item.isChecked(); // true = FULL_WAKE_LOCK, false = PARTIAL_WAKE_LOCK
snapclientService.updateWakeLock(fullWakeLock);
}
return true;
} else if (id == R.id.action_refresh) {
if (host.trim().isEmpty()) {
showWarning(getString(R.string.host_empty));
Expand All @@ -242,7 +251,6 @@ public void onAutoStartChanged(boolean autoStart) {
Intent intent = new Intent(this, AboutActivity.class);
startActivity(intent);
}

return super.onOptionsItemSelected(item);
}

Expand Down
31 changes: 27 additions & 4 deletions Snapcast/src/main/java/de/badaix/snapcast/SnapclientService.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,17 @@ private void start(String host, int port) {
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);

PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
boolean preventScreenOff = Settings.getInstance(getApplicationContext()).getBoolean("prevent_screen_off", false);

UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) {
Log.d(TAG, "Running on a TV Device");
// Set the wake lock type based on the setting
if (preventScreenOff) {
Log.d(TAG, "Using FULL_WAKE_LOCK due to setting");
wakeLock = powerManager.newWakeLock(FULL_WAKE_LOCK, "snapcast:SnapcastFullWakeLock");
} else {
Log.d(TAG, "Running on a non-TV Device");
Log.d(TAG, "Using PARTIAL_WAKE_LOCK due to setting");
wakeLock = powerManager.newWakeLock(PARTIAL_WAKE_LOCK, "snapcast:SnapcastPartialWakeLock");
}
wakeLock = powerManager.newWakeLock(PARTIAL_WAKE_LOCK, "snapcast:SnapcastPartialWakeLock");

wakeLock.acquire();

Expand Down Expand Up @@ -381,6 +383,27 @@ private void stop() {
listener.onPlayerStop(this);
}

public void updateWakeLock(boolean useFullWakeLock) {
try {
if (wakeLock != null && wakeLock.isHeld()) {
wakeLock.release();
}

PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
if (useFullWakeLock) {
Log.d(TAG, "Switching to FULL_WAKE_LOCK");
wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "snapcast:SnapcastFullWakeLock");
} else {
Log.d(TAG, "Switching to PARTIAL_WAKE_LOCK");
wakeLock = powerManager.newWakeLock(PARTIAL_WAKE_LOCK, "snapcast:SnapcastPartialWakeLock");
}

wakeLock.acquire();
} catch (Exception e) {
e.printStackTrace();
}
}

public interface SnapclientListener {
void onPlayerStart(SnapclientService snapclientService);

Expand Down
6 changes: 6 additions & 0 deletions Snapcast/src/main/res/menu/menu_snapcast.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@
android:orderInCategory="100"
android:title="@string/action_hide_offline"
app:showAsAction="never" />
<item
android:id="@+id/action_prevent_screen_off"
android:checkable="true"
android:orderInCategory="100"
android:title="@string/action_prevent_screen_off"
app:showAsAction="never" />
</menu>
1 change: 1 addition & 0 deletions Snapcast/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<string name="action_scan">Suche nach Server</string>
<string name="action_refresh">Aktualisiere Client-Liste</string>
<string name="action_hide_offline">Verstecke offline Clients</string>
<string name="action_prevent_screen_off">Bildschirm ausschalten verhindern</string>

<string name="title_activity_client_settings">Client Einstellungen</string>
<string name="client_name">Name</string>
Expand Down
2 changes: 2 additions & 0 deletions Snapcast/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="action_scan">サーバーのスキャン</string>
<string name="action_refresh">クライアント一覧の更新</string>
<string name="action_hide_offline">オフラインのクライアントを非表示</string>
<string name="action_prevent_screen_off">画面がオフになるのを防ぐ</string>


<string name="title_activity_client_settings">クライアント設定</string>
<string name="client_name">名前</string>
Expand Down
1 change: 1 addition & 0 deletions Snapcast/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<string name="action_scan">Scan for server</string>
<string name="action_refresh">Refresh client list</string>
<string name="action_hide_offline">Hide offline clients</string>
<string name="action_prevent_screen_off">Prevent screen from turning off</string>
<string name="action_bar_failed">Cannot set ActionBar!</string>

<string name="title_activity_client_settings">Client settings</string>
Expand Down