Add a Quit Steam button

This commit is contained in:
Cameron Gutman 2014-06-30 01:14:46 -07:00
parent 8f43b95129
commit ddf9284ece
3 changed files with 113 additions and 35 deletions

View File

@ -37,21 +37,22 @@ or to a theme attribute in the form "<code>?[<i>package</i>:][<i>type</i>:]<i>na
public static final int ouya_icon=0x7f020002;
}
public static final class id {
public static final int autoDec=0x7f080006;
public static final int bitrateLabel=0x7f08000c;
public static final int bitrateSeekBar=0x7f08000d;
public static final int config1080p30Selected=0x7f08000a;
public static final int config1080p60Selected=0x7f08000b;
public static final int config720p30Selected=0x7f080008;
public static final int config720p60Selected=0x7f080009;
public static final int decoderConfigGroup=0x7f080003;
public static final int hardwareDec=0x7f080007;
public static final int autoDec=0x7f080004;
public static final int bitrateLabel=0x7f08000b;
public static final int bitrateSeekBar=0x7f08000c;
public static final int config1080p30Selected=0x7f080009;
public static final int config1080p60Selected=0x7f08000a;
public static final int config720p30Selected=0x7f080007;
public static final int config720p60Selected=0x7f080008;
public static final int decoderConfigGroup=0x7f080001;
public static final int hardwareDec=0x7f080005;
public static final int hostTextView=0x7f080000;
public static final int pairButton=0x7f080002;
public static final int softwareDec=0x7f080005;
public static final int statusButton=0x7f080001;
public static final int streamConfigGroup=0x7f080004;
public static final int surfaceView=0x7f08000e;
public static final int pairButton=0x7f080006;
public static final int quitButton=0x7f08000e;
public static final int softwareDec=0x7f080003;
public static final int statusButton=0x7f08000d;
public static final int streamConfigGroup=0x7f080002;
public static final int surfaceView=0x7f08000f;
}
public static final class layout {
public static final int activity_connection=0x7f030000;

View File

@ -24,26 +24,6 @@
android:inputType="textNoSuggestions"
android:hint="IP address of GeForce PC" />
<Button
android:id="@+id/statusButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/hostTextView"
android:layout_centerHorizontal="true"
android:text="Start Streaming Steam!" >
<requestFocus />
</Button>
<Button
android:id="@+id/pairButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/statusButton"
android:layout_centerHorizontal="true"
android:text="Pair with PC" />
<RadioGroup
android:id="@+id/decoderConfigGroup"
android:layout_width="fill_parent"
@ -128,6 +108,35 @@
android:layout_alignParentLeft="true"
android:layout_below="@+id/decoderConfigGroup"
android:layout_toLeftOf="@+id/bitrateLabel" />
<Button
android:id="@+id/pairButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/statusButton"
android:layout_below="@+id/statusButton"
android:layout_marginRight="114dp"
android:text="Pair with PC" />
<Button
android:id="@+id/statusButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/hostTextView"
android:layout_centerHorizontal="true"
android:text="Start Streaming Steam!" >
<requestFocus />
</Button>
<Button
android:id="@+id/quitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/streamConfigGroup"
android:layout_alignLeft="@+id/statusButton"
android:layout_marginLeft="122dp"
android:text="Quit Steam" />
</RelativeLayout>

View File

@ -29,7 +29,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
public class Connection extends Activity {
private Button statusButton, pairButton;
private Button statusButton, pairButton, quitButton;
private TextView hostText;
private SharedPreferences prefs;
private RadioButton rbutton720p30, rbutton720p60, rbutton1080p30, rbutton1080p60;
@ -69,6 +69,7 @@ public class Connection extends Activity {
this.statusButton = (Button) findViewById(R.id.statusButton);
this.pairButton = (Button) findViewById(R.id.pairButton);
this.quitButton = (Button) findViewById(R.id.quitButton);
this.hostText = (TextView) findViewById(R.id.hostTextView);
this.rbutton720p30 = (RadioButton) findViewById(R.id.config720p30Selected);
this.rbutton720p60 = (RadioButton) findViewById(R.id.config720p60Selected);
@ -244,6 +245,73 @@ public class Connection extends Activity {
}
});
this.quitButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (Connection.this.hostText.getText().length() == 0) {
Toast.makeText(Connection.this, "Please enter the target PC's IP address in the text box at the top of the screen.", Toast.LENGTH_LONG).show();
return;
}
Toast.makeText(Connection.this, "Trying to quit Steam...", Toast.LENGTH_SHORT).show();
new Thread(new Runnable() {
@Override
public void run() {
String macAddress;
try {
macAddress = NvConnection.getMacAddressString();
} catch (SocketException e) {
e.printStackTrace();
return;
}
if (macAddress == null) {
LimeLog.severe("Couldn't find a MAC address");
return;
}
NvHTTP httpConn;
String message;
try {
httpConn = new NvHTTP(InetAddress.getByName(hostText.getText().toString()),
macAddress, PlatformBinding.getDeviceName(), PlatformBinding.getCryptoProvider(Connection.this));
if (httpConn.getPairState() == PairingManager.PairState.PAIRED) {
if (httpConn.getCurrentGame() != 0) {
if (httpConn.quitApp()) {
message = "Successfully closed Steam";
}
else {
message = "Failed to close Steam";
}
}
else {
message = "Steam is not running";
}
}
else {
message = "Device not paired with computer";
}
} catch (UnknownHostException e) {
message = "Failed to resolve host";
} catch (FileNotFoundException e) {
message = "GFE returned an HTTP 404 error. Make sure your PC is running a supported GPU. Using remote desktop software can also cause this error. "
+ "Try rebooting your machine or reinstalling GFE.";
} catch (Exception e) {
message = e.getMessage();
}
final String toastMessage = message;
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(Connection.this, toastMessage, Toast.LENGTH_LONG).show();
}
});
}
}).start();
}
});
this.pairButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {