Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

同步基线代码 #1439

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
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
8 changes: 8 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ android {
path "src/main/jni/Android.mk"
}
}

sourceSets {
main {
jniLibs.srcDirs = ['src/main/libs']
}
}
}

dependencies {
Expand All @@ -142,4 +148,6 @@ dependencies {
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
implementation 'org.jmdns:jmdns:3.5.9'
implementation 'com.github.cgutman:ShieldControllerExtensions:1.0.1'
implementation group: 'commons-io', name: 'commons-io', version: '2.17.0'

}
209 changes: 184 additions & 25 deletions app/src/main/java/com/limelight/AppView.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
package com.limelight;

import java.io.IOException;
import java.io.StringReader;
import java.util.HashSet;
import java.util.List;

import com.limelight.computers.ComputerManagerListener;
import com.limelight.computers.ComputerManagerService;
import com.limelight.grid.AppGridAdapter;
import com.limelight.nvstream.http.ComputerDetails;
import com.limelight.nvstream.http.NvApp;
import com.limelight.nvstream.http.NvHTTP;
import com.limelight.nvstream.http.PairingManager;
import com.limelight.preferences.PreferenceConfiguration;
import com.limelight.ui.AdapterFragment;
import com.limelight.ui.AdapterFragmentCallbacks;
import com.limelight.utils.CacheHelper;
import com.limelight.utils.Dialog;
import com.limelight.utils.ServerHelper;
import com.limelight.utils.ShortcutHelper;
import com.limelight.utils.SpinnerDialog;
import com.limelight.utils.UiHelper;

import android.app.Activity;
import android.app.Service;
import android.content.ComponentName;
Expand All @@ -30,26 +8,66 @@
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ToggleButton;

import com.limelight.computers.ComputerManagerListener;
import com.limelight.computers.ComputerManagerService;
import com.limelight.grid.AppGridAdapter;
import com.limelight.nvstream.http.ComputerDetails;
import com.limelight.nvstream.http.NvApp;
import com.limelight.nvstream.http.NvHTTP;
import com.limelight.nvstream.http.PairingManager;
import com.limelight.preferences.PreferenceConfiguration;
import com.limelight.preferences.StreamSettings;
import com.limelight.ui.AdapterFragment;
import com.limelight.ui.AdapterFragmentCallbacks;
import com.limelight.utils.CacheHelper;
import com.limelight.utils.Dialog;
import com.limelight.utils.ServerHelper;
import com.limelight.utils.ShortcutHelper;
import com.limelight.utils.SpinnerDialog;
import com.limelight.utils.StringUtils;
import com.limelight.utils.UiHelper;

import com.limelight.iperf3.cmd.CmdCallback;
import com.limelight.iperf3.cmd.Iperf3Cmd;

import org.xmlpull.v1.XmlPullParserException;

public class AppView extends Activity implements AdapterFragmentCallbacks {
import java.io.IOException;
import java.io.StringReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

public class AppView extends Activity implements AdapterFragmentCallbacks, AdapterView.OnItemSelectedListener {

public static final String TAG_IPERF_TEST = "IPERF_TEST";

private AppGridAdapter appGridAdapter;
private String uuidString;
private ShortcutHelper shortcutHelper;
Expand All @@ -63,6 +81,8 @@ public class AppView extends Activity implements AdapterFragmentCallbacks {
private boolean inForeground;
private boolean showHiddenApps;
private HashSet<Integer> hiddenAppIds = new HashSet<>();
private TextView tvNetworkSpeed;
private String computerIpAddress;

private final static int START_OR_RESUME_ID = 1;
private final static int QUIT_ID = 2;
Expand All @@ -77,6 +97,7 @@ public class AppView extends Activity implements AdapterFragmentCallbacks {
public final static String UUID_EXTRA = "UUID";
public final static String NEW_PAIR_EXTRA = "NewPair";
public final static String SHOW_HIDDEN_APPS_EXTRA = "ShowHiddenApps";
public final static String IP_ADDRESS = "IpAddress";

private ComputerManagerService.ComputerManagerBinder managerBinder;
private final ServiceConnection serviceConnection = new ServiceConnection() {
Expand Down Expand Up @@ -309,6 +330,7 @@ protected void onCreate(Bundle savedInstanceState) {
}

String computerName = getIntent().getStringExtra(NAME_EXTRA);
computerIpAddress = getIntent().getStringExtra(IP_ADDRESS);

TextView label = findViewById(R.id.appListText);
setTitle(computerName);
Expand All @@ -317,6 +339,26 @@ protected void onCreate(Bundle savedInstanceState) {
// Bind to the computer manager service
bindService(new Intent(this, ComputerManagerService.class), serviceConnection,
Service.BIND_AUTO_CREATE);

// Setup the list view
ImageButton settingsButton = findViewById(R.id.settingsButton);

settingsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(AppView.this, StreamSettings.class));
}
});

// 加载常用分辨率
loadPopularResolutions();

// 测速
tvNetworkSpeed = findViewById(R.id.tv_network_speed);
startIperf();
tvNetworkSpeed.setOnClickListener(v -> {
startIperf();
});
}

private void updateHiddenApps(boolean hideImmediately) {
Expand Down Expand Up @@ -645,6 +687,123 @@ public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
listView.requestFocus();
}

/**
* 加载常用分辨率
*/
private void loadPopularResolutions() {
// 反选设置的分辨率和帧率
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(AppView.this);
String curSettingsResolution = prefs.getString(PreferenceConfiguration.RESOLUTION_PREF_STRING, PreferenceConfiguration.DEFAULT_RESOLUTION);
String curSettingsFpg = prefs.getString(PreferenceConfiguration.FPS_PREF_STRING, PreferenceConfiguration.DEFAULT_FPS);

Spinner spinner = findViewById(R.id.spinner);
String[] popularResolutions = getResources().getStringArray(R.array.popular_resolutions);
String curResolution = String.format("%s %sHz", curSettingsResolution.replace("x", " "), curSettingsFpg);
String[] fullPopularResolutions;
int curResolutionIndex = -1;
for (int i = 0; i < popularResolutions.length; i++) {
if(popularResolutions[i].equals(curResolution)) {
curResolutionIndex = i;
break;
}
}
if(curResolutionIndex >= 0) {
fullPopularResolutions = popularResolutions;
} else {
curResolutionIndex = 0;
fullPopularResolutions = new String[popularResolutions.length + 1];
fullPopularResolutions[0] = curResolution;
System.arraycopy(popularResolutions, 0, fullPopularResolutions, 1, popularResolutions.length);
}
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(
this,
R.layout.spinner_item_nv_layout,
R.id.spinner_item,
fullPopularResolutions);
adapter.setDropDownViewResource(R.layout.spinner_item_nv_layout);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
spinner.setSelection(curResolutionIndex);
}

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String[] selected = parent.getItemAtPosition(position).toString().replace("Hz", "").split(" ");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(AppView.this);
prefs.edit().putString(PreferenceConfiguration.RESOLUTION_PREF_STRING, String.format("%sx%s", selected[0], selected[1])).apply();
prefs.edit().putString(PreferenceConfiguration.FPS_PREF_STRING, selected[2]).apply();
}

@Override
public void onNothingSelected(AdapterView<?> parent) {
// Do nothing
}
// 加载常用分辨率--------------------------------------------------------

public void startIperf() {
tvNetworkSpeed.setText("Loading...");
setTextBySpeed(tvNetworkSpeed, -1);
new Iperf3Cmd(this, new CmdCallback() {
@Override
public void onRawOutput(String rawOutputLine) {
}

@Override
public void onConnecting(String destHost, int destPort) {
Log.d(TAG_IPERF_TEST, "onConnecting: " + destHost + " " + destPort);
}

@Override
public void onConnected(String localAddr, int localPort, String destAddr, int destPort) {
Log.d(TAG_IPERF_TEST, "onConnected: " + localAddr + " " + localPort + " " + destAddr + " " + destPort);
}

@Override
public void onInterval(double timeStart, double timeEnd, double transfer, double bitrate) {
Log.d(TAG_IPERF_TEST, "onInterval: " + timeStart + " " + timeEnd + " " + transfer + " " + bitrate);
runOnUiThread(() -> {
long speed = (long)(bitrate * 1024 * 1024 * 1.024);
tvNetworkSpeed.setText(StringUtils.bps2BpsStr(StringUtils.preferNum(speed)));
setTextBySpeed(tvNetworkSpeed, speed);
});
}

@Override
public void onResult(double timeStart, double timeEnd, double transfer, double bitrate) {
Log.d(TAG_IPERF_TEST, "onResult: " + timeStart + " " + timeEnd + " " + transfer + " " + bitrate);
runOnUiThread(() -> {
long speed = (long)(bitrate * 1024 * 1024 * 1.024);
tvNetworkSpeed.setText(StringUtils.bps2BpsStr(StringUtils.preferNum((long)(bitrate * 1024 * 1024 * 1.024))));
setTextBySpeed(tvNetworkSpeed, speed);
});
}

@Override
public void onError(String errMsg) {
Log.d(TAG_IPERF_TEST, "onError: " + errMsg);
runOnUiThread(() -> {
// Toast.makeText(AppView.this, errMsg, Toast.LENGTH_SHORT).show();
tvNetworkSpeed.setText("RETRY");
setTextBySpeed(tvNetworkSpeed, 0);
});
}
}).exec(new String[] {"-c", computerIpAddress, "-R", "-f", "m", "--tmp-template", getCacheDir().getAbsolutePath() + "/iperf3.XXXXXX"});
}

private void setTextBySpeed(TextView view, long speed) {
int color;
if(speed > 500 * 1000 * 1000) {
color = R.color.green_nvidia;
} else if (speed > 100 * 1000 * 1000) {
color = R.color.yellow;
} else if (speed >= 0) {
color = R.color.red;
} else {
color = R.color.grey;
}
view.setTextColor(getResources().getColor(color));
}

public static class AppObject {
public final NvApp app;
public boolean isRunning;
Expand Down
16 changes: 13 additions & 3 deletions app/src/main/java/com/limelight/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.limelight.nvstream.http.ComputerDetails;
import com.limelight.nvstream.http.NvApp;
import com.limelight.nvstream.http.NvHTTP;
import com.limelight.nvstream.input.ControllerPacket;
import com.limelight.nvstream.input.KeyboardPacket;
import com.limelight.nvstream.input.MouseButtonPacket;
import com.limelight.nvstream.jni.MoonBridge;
Expand Down Expand Up @@ -52,6 +51,7 @@
import android.content.res.Configuration;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.hardware.input.InputManager;
import android.media.AudioManager;
import android.net.ConnectivityManager;
Expand Down Expand Up @@ -369,7 +369,7 @@ public boolean onCapturedPointer(View view, MotionEvent motionEvent) {
}

// Check if the user has enabled performance stats overlay
if (prefConfig.enablePerfOverlay) {
if (prefConfig.enablePerfOverlay || prefConfig.enableMinPerfOverlay) {
performanceOverlayView.setVisibility(View.VISIBLE);
}

Expand Down Expand Up @@ -613,7 +613,7 @@ public void onConfigurationChanged(Configuration newConfig) {
virtualController.show();
}

if (prefConfig.enablePerfOverlay) {
if (prefConfig.enablePerfOverlay || prefConfig.enableMinPerfOverlay) {
performanceOverlayView.setVisibility(View.VISIBLE);
}

Expand Down Expand Up @@ -2646,6 +2646,16 @@ public void run() {
});
}

@Override
public void onMinPerfUpdate(final String text) {
runOnUiThread(new Runnable() {
@Override
public void run() {
performanceOverlayView.setText(text);
}
});
}

@Override
public void onUsbPermissionPromptStarting() {
// Disable PiP auto-enter while the USB permission prompt is on-screen. This prevents
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/com/limelight/PcView.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class PcView extends Activity implements AdapterFragmentCallbacks {
private ShortcutHelper shortcutHelper;
private ComputerManagerService.ComputerManagerBinder managerBinder;
private boolean freezeUpdates, runningPolling, inForeground, completeOnCreateCalled;
private long createStartTime;
private final ServiceConnection serviceConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder binder) {
final ComputerManagerService.ComputerManagerBinder localBinder =
Expand Down Expand Up @@ -231,6 +232,7 @@ public void onDrawFrame(GL10 gl10) {

private void completeOnCreate() {
completeOnCreateCalled = true;
createStartTime = System.currentTimeMillis();

shortcutHelper = new ShortcutHelper(this);

Expand Down Expand Up @@ -258,6 +260,12 @@ public void notifyComputerUpdated(final ComputerDetails details) {
@Override
public void run() {
updateComputer(details);
if(System.currentTimeMillis() - createStartTime < 5000 &&
details.state == ComputerDetails.State.ONLINE &&
details.pairState == PairState.PAIRED) {
createStartTime = 0;
doAppList(details, false, false);
}
}
});

Expand Down Expand Up @@ -597,6 +605,7 @@ private void doAppList(ComputerDetails computer, boolean newlyPaired, boolean sh
i.putExtra(AppView.UUID_EXTRA, computer.uuid);
i.putExtra(AppView.NEW_PAIR_EXTRA, newlyPaired);
i.putExtra(AppView.SHOW_HIDDEN_APPS_EXTRA, showHiddenGames);
i.putExtra(AppView.IP_ADDRESS, computer.activeAddress.address);
startActivity(i);
}

Expand Down
Loading