Harden reconnect and WakeLock, add live status UI on the overview.
Android CI / build (push) Canceled after 0s
Android CI / build (push) Canceled after 0s
Fixes flaky Hyperion reconnects and 1h WakeLock cutoffs, disables verbose DEBUG logging, and shows server/FPS/capture stats plus credit in the main status card. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
063a068620
commit
982702cde1
14 files changed
+460
-76
No files matched your search
@@ -0,0 +1,65 @@
|
||||
package com.hyperion.grabber;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hyperion.grabber.common.HyperionScreenService;
|
||||
import com.hyperion.grabber.common.R;
|
||||
import com.hyperion.grabber.common.util.Preferences;
|
||||
|
||||
/**
|
||||
* Formats and applies grabber status text on the main overview screen.
|
||||
*/
|
||||
public final class GrabberStatusHelper {
|
||||
private GrabberStatusHelper() {}
|
||||
|
||||
public static void applyBroadcast(TextView target, Intent intent) {
|
||||
if (target == null || intent == null) return;
|
||||
String text = intent.getStringExtra(HyperionScreenService.BROADCAST_STATUS_TEXT);
|
||||
if (text != null && !text.isEmpty()) {
|
||||
target.setText(text);
|
||||
target.setVisibility(TextView.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void applyFromPreferences(TextView target, Context context) {
|
||||
if (target == null || context == null) return;
|
||||
target.setText(formatFromPreferences(context));
|
||||
target.setVisibility(TextView.VISIBLE);
|
||||
}
|
||||
|
||||
public static String formatFromPreferences(Context context) {
|
||||
Preferences prefs = new Preferences(context);
|
||||
boolean wled = prefs.getBoolean(R.string.pref_key_wled_enabled);
|
||||
String host = prefs.getString(R.string.pref_key_host, null);
|
||||
int port = prefs.getInt(R.string.pref_key_port, -1);
|
||||
int fps = prefs.getInt(R.string.pref_key_framerate);
|
||||
int ledX = prefs.getInt(R.string.pref_key_x_led);
|
||||
int ledY = prefs.getInt(R.string.pref_key_y_led);
|
||||
String priority = prefs.getString(R.string.pref_key_priority, "100");
|
||||
boolean avg = prefs.getBoolean(R.string.pref_key_use_avg_color);
|
||||
String wledIp = prefs.getString(R.string.pref_key_wled_ip, null);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (wled) {
|
||||
sb.append("WLED ").append(wledIp != null && !wledIp.isEmpty() ? wledIp : "—").append(":4048\n");
|
||||
} else if (host != null && !host.isEmpty() && port > 0) {
|
||||
sb.append(context.getString(R.string.status_server))
|
||||
.append(" ").append(host).append(':').append(port).append('\n');
|
||||
} else {
|
||||
sb.append(context.getString(R.string.status_not_configured)).append('\n');
|
||||
}
|
||||
sb.append(context.getString(R.string.status_state))
|
||||
.append(" ").append(context.getString(R.string.status_state_off)).append('\n');
|
||||
sb.append(context.getString(R.string.status_target_fps)).append(" ").append(fps).append('\n');
|
||||
sb.append(context.getString(R.string.status_leds)).append(" ")
|
||||
.append(ledX).append('×').append(ledY).append('\n');
|
||||
sb.append(context.getString(R.string.status_priority)).append(" ").append(priority);
|
||||
if (avg) {
|
||||
sb.append(" · ").append(context.getString(R.string.status_avg_color));
|
||||
}
|
||||
sb.append('\n').append(context.getString(R.string.credit_modified_by));
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,7 @@ public class MainActivity extends AppCompatActivity implements ImageView.OnClick
|
||||
private Intent mPendingProjectionData = null;
|
||||
private int mPendingResultCode = 0;
|
||||
private int mPermissionDeniedCount = 0;
|
||||
private String mLastToastError = null;
|
||||
|
||||
private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
@@ -51,12 +52,16 @@ public class MainActivity extends AppCompatActivity implements ImageView.OnClick
|
||||
mRecorderRunning = checked;
|
||||
String error = intent.getStringExtra(HyperionScreenService.BROADCAST_ERROR);
|
||||
|
||||
if (error != null &&
|
||||
if (error != null && !error.equals(mLastToastError) &&
|
||||
(Build.VERSION.SDK_INT < Build.VERSION_CODES.N ||
|
||||
!HyperionGrabberTileService.isListening())) {
|
||||
mLastToastError = error;
|
||||
Toast.makeText(getBaseContext(), error, Toast.LENGTH_LONG).show();
|
||||
} else if (error == null) {
|
||||
mLastToastError = null;
|
||||
}
|
||||
setImageViews(checked, checked);
|
||||
GrabberStatusHelper.applyBroadcast(findViewById(R.id.statusInfoText), intent);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -85,6 +90,7 @@ public class MainActivity extends AppCompatActivity implements ImageView.OnClick
|
||||
}
|
||||
|
||||
setImageViews(mRecorderRunning, false);
|
||||
GrabberStatusHelper.applyFromPreferences(findViewById(R.id.statusInfoText), this);
|
||||
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(
|
||||
mMessageReceiver, new IntentFilter(HyperionScreenService.BROADCAST_FILTER));
|
||||
@@ -99,6 +105,10 @@ public class MainActivity extends AppCompatActivity implements ImageView.OnClick
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (!mRecorderRunning) {
|
||||
GrabberStatusHelper.applyFromPreferences(findViewById(R.id.statusInfoText), this);
|
||||
}
|
||||
checkForInstance();
|
||||
}
|
||||
|
||||
private void requestNotificationPermission() {
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.hyperion.grabber.common.BootActivity;
|
||||
import com.hyperion.grabber.common.HyperionScreenService;
|
||||
import com.hyperion.grabber.common.util.MediaProjectionHelper;
|
||||
import com.hyperion.grabber.common.util.Preferences;
|
||||
import com.hyperion.grabber.GrabberStatusHelper;
|
||||
import com.hyperion.grabber.R;
|
||||
|
||||
public class MainActivity extends LeanbackActivity implements ImageView.OnClickListener,
|
||||
@@ -45,6 +46,7 @@ public class MainActivity extends LeanbackActivity implements ImageView.OnClickL
|
||||
private boolean mRecorderRunning = false;
|
||||
private static MediaProjectionManager mMediaProjectionManager;
|
||||
private int mPermissionDeniedCount = 0;
|
||||
private String mLastToastError = null;
|
||||
|
||||
private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
@@ -53,10 +55,14 @@ public class MainActivity extends LeanbackActivity implements ImageView.OnClickL
|
||||
mRecorderRunning = checked;
|
||||
String error = intent.getStringExtra(BROADCAST_ERROR);
|
||||
|
||||
if (error != null) {
|
||||
if (error != null && !error.equals(mLastToastError)) {
|
||||
mLastToastError = error;
|
||||
Toast.makeText(getBaseContext(), error, Toast.LENGTH_SHORT).show();
|
||||
} else if (error == null) {
|
||||
mLastToastError = null;
|
||||
}
|
||||
setImageViews(checked, true);
|
||||
GrabberStatusHelper.applyBroadcast(findViewById(R.id.statusInfoText), intent);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -138,6 +144,7 @@ public class MainActivity extends LeanbackActivity implements ImageView.OnClickL
|
||||
ib.setFocusable(true);
|
||||
|
||||
setImageViews(mRecorderRunning, false);
|
||||
GrabberStatusHelper.applyFromPreferences(findViewById(R.id.statusInfoText), this);
|
||||
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(
|
||||
mMessageReceiver, new IntentFilter(BROADCAST_FILTER));
|
||||
@@ -146,6 +153,15 @@ public class MainActivity extends LeanbackActivity implements ImageView.OnClickL
|
||||
checkForInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (!mRecorderRunning) {
|
||||
GrabberStatusHelper.applyFromPreferences(findViewById(R.id.statusInfoText), this);
|
||||
}
|
||||
checkForInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int id = view.getId();
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<corners android:radius="16dp" />
|
||||
<solid android:color="#CC1A1A1A" />
|
||||
</shape>
|
||||
@@ -11,6 +11,30 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/statusInfoText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="48dp"
|
||||
android:layout_marginTop="36dp"
|
||||
android:layout_marginEnd="48dp"
|
||||
android:background="@drawable/status_card_background"
|
||||
android:fontFamily="monospace"
|
||||
android:includeFontPadding="false"
|
||||
android:lineSpacingExtra="3dp"
|
||||
android:maxWidth="520dp"
|
||||
android:paddingStart="20dp"
|
||||
android:paddingTop="14dp"
|
||||
android:paddingEnd="20dp"
|
||||
android:paddingBottom="14dp"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="15sp"
|
||||
android:visibility="visible"
|
||||
app:layout_constrainedWidth="true"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="Server: 10.0.50.2:19400\nStatus: Sendet\nSende-FPS: 28.4 / 30" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/grabberStartedText"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -82,4 +106,3 @@
|
||||
app:srcCompat="@drawable/ic_settings_black_72dp" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
Reference in new issue
Block a user