Skip to content

Commit

Permalink
feat: 优化性能数据显示
Browse files Browse the repository at this point in the history
  • Loading branch information
qiin2333 committed Jul 7, 2024
1 parent 626472a commit ec6ae3c
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 17 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ android {
buildTypes {
debug {
applicationIdSuffix ".debug"
resValue "string", "app_label", "Moonlight (Debug)"
resValue "string", "app_label_root", "Moonlight (Root Debug)"
resValue "string", "app_label", "月光-威力加强版"
resValue "string", "app_label_root", "月光-威力加强版"

minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
Expand Down Expand Up @@ -146,4 +146,5 @@ dependencies {
implementation 'com.github.cgutman:ShieldControllerExtensions:1.0.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.github.ZeyuKeithFu:KeyboardHeaderLayout:v1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
}
5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="com.android.providers.tv.permission.READ_EPG_DATA"/>
<uses-permission android:name="com.android.providers.tv.permission.WRITE_EPG_DATA"/>

Expand Down
31 changes: 21 additions & 10 deletions app/src/main/java/com/limelight/Game.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.limelight;


import com.limelight.binding.PlatformBinding;
import com.limelight.binding.audio.AndroidAudioRenderer;
import com.limelight.binding.input.ControllerHandler;
Expand Down Expand Up @@ -76,16 +75,12 @@
import android.view.View.OnTouchListener;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodInfo;
import android.widget.FrameLayout;
import android.view.inputmethod.InputMethodManager;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ArrayAdapter;

import androidx.interpolator.view.animation.LinearOutSlowInInterpolator;

import java.io.ByteArrayInputStream;
import java.lang.reflect.InvocationTargetException;
Expand All @@ -98,6 +93,7 @@
import java.util.List;
import java.util.Arrays;
import java.util.Locale;
import java.util.Optional;


public class Game extends Activity implements SurfaceHolder.Callback,
Expand Down Expand Up @@ -2748,8 +2744,7 @@ public void onPerfUpdate(final String text) {
}
if (s.contains(getResources().getString(R.string.perf_overlay_decoder).substring(0, 5))) {
decoderInfo = s.toLowerCase().replaceFirst(".*\\.(avc|hevc|av1).*", "$1").toUpperCase();
decoderInfo += " with HDR ";
decoderInfo += prefConfig.enableHdr? "On" : "Off";
decoderInfo += prefConfig.enableHdr? " HDR" : "";
}
if (s.contains(getResources().getString(R.string.perf_overlay_renderingfps).substring(0, 5))) {
renderFpsInfo = s;
Expand All @@ -2766,7 +2761,8 @@ public void onPerfUpdate(final String text) {
+ " M/s " + s.replaceFirst("\\D*(\\d+) ms \\(\\D*(\\d+) ms\\)", "$1 ± $2 ms");
}
if (s.contains(getResources().getString(R.string.perf_overlay_dectime).substring(0, 7))) {
decodeLatencyInfo = s;
float decodeTime = Float.parseFloat(s.replaceFirst(".*\\s(\\d+\\.\\d+)\\sms", "$1"));
decodeLatencyInfo = (decodeTime < 12 ? "\uD83C\uDFAE " : "\uD83E\uDD75 ") + decodeTime + " ms";
}
if (s.contains(getResources().getString(R.string.perf_overlay_hostprocessinglatency).substring(0, 6))) {
hostLatencyInfo = s;
Expand All @@ -2776,7 +2772,7 @@ public void onPerfUpdate(final String text) {
String finalResInfo = resInfo;
String finalDecoderInfo = decoderInfo;
String finalRenderFpsInfo = renderFpsInfo.replaceFirst(".*\\s(\\d+\\.\\d+)\\sFPS", "$1 fps");
String finalDecodeLatencyInfo = decodeLatencyInfo.replaceFirst(".*\\s(\\d+\\.\\d+\\sms)", "\uD83C\uDFAE $1");
String finalDecodeLatencyInfo = decodeLatencyInfo;
String finalNetworkLatencyInfo = networkLatencyInfo;
String finalHostLatencyInfo = hostLatencyInfo.replaceFirst("^.*?:", "\uD83D\uDDA5\uFE0F ");
runOnUiThread(new Runnable() {
Expand Down Expand Up @@ -2856,6 +2852,21 @@ public void togglePerformanceOverlay() {
performanceOverlayView.setVisibility(requestedPerformanceOverlayVisibility);
}

public void imeSwitch() {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
List<InputMethodInfo> mInputMethodProperties = imm.getInputMethodList();
Optional<InputMethodInfo> hackersInput = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
hackersInput = mInputMethodProperties.stream().filter(m -> m.getId().startsWith("org.pocketworkstation.pckeyboard")).findFirst();
}
imm.showInputMethodPicker();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (!hackersInput.isPresent()) {
Toast.makeText(Game.this, "杂鱼~❤ 还不快装黑客键盘(hacker's keyboard", Toast.LENGTH_LONG).show();
}
}
}

private static byte getModifier(short key) {
switch (key) {
case KeyboardTranslator.VK_LSHIFT:
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/limelight/GameMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ private void showMenu() {

options.add(new MenuOption(getString(R.string.game_menu_toggle_performance_overlay), () -> game.togglePerformanceOverlay()));
options.add(new MenuOption(getString(R.string.game_menu_send_keys), () -> showSpecialKeysMenu()));
options.add(new MenuOption(getString(R.string.game_menu_switch_ime), () -> game.imeSwitch()));
options.add(new MenuOption(getString(R.string.game_menu_disconnect), () -> game.disconnect()));
options.add(new MenuOption(getString(R.string.game_menu_cancel), null));

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_game.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
android:layout_gravity="center"
android:orientation="horizontal"
android:paddingBottom="32dp"
android:paddingRight="16dp">
android:layout_marginStart="4dp">

<Button
android:id="@+id/btnWin"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
<!-- In Game menu -->
<string name="game_menu_toggle_keyboard">屏幕键盘</string>
<string name="game_menu_toggle_performance_overlay">性能监控图层</string>
<string name="game_menu_switch_ime">切换输入法(获取更多操作)</string>
<string name="game_menu_toggle_mouse_on">手柄模拟鼠标-打开</string>
<string name="game_menu_toggle_mouse_off">手柄模拟鼠标-关闭</string>
<string name="game_menu_disconnect">结束串流</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
<!-- In Game menu -->
<string name="game_menu_toggle_keyboard">Toggle On-screen Keyboard</string>
<string name="game_menu_toggle_performance_overlay">Toggle Performance Overlay</string>
<string name="game_menu_switch_ime">IME Switch</string>
<string name="game_menu_toggle_mouse_on">Enable Controller Mouse Emulation</string>
<string name="game_menu_toggle_mouse_off">Disable Controller Mouse Emulation</string>
<string name="game_menu_disconnect">Disconnect</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/nonRoot/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

<!-- Non-root application name -->
<!-- FIXME: We should set extractNativeLibs=false but this breaks installation on the Fire TV 3 -->
<application android:label="@string/app_label" />
<application android:label="月光-威力加强版" />
</manifest>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.3.0'
classpath 'com.android.tools.build:gradle:8.5.0'
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit ec6ae3c

Please sign in to comment.