diff --git a/app/src/main/java/com/limelight/ShortcutTrampoline.java b/app/src/main/java/com/limelight/ShortcutTrampoline.java index 262e9587..7c4b8942 100644 --- a/app/src/main/java/com/limelight/ShortcutTrampoline.java +++ b/app/src/main/java/com/limelight/ShortcutTrampoline.java @@ -23,16 +23,12 @@ import java.util.UUID; public class ShortcutTrampoline extends Activity { private String uuidString; - private String appIdString; - private String appNameString; + private NvApp app; private ArrayList intentStack = new ArrayList<>(); private ComputerDetails computer; private SpinnerDialog blockingLoadSpinner; - public final static String APP_NAME_EXTRA = "AppName"; - public final static String APP_ID_EXTRA = "AppId"; - private ComputerManagerService.ComputerManagerBinder managerBinder; private final ServiceConnection serviceConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder binder) { @@ -103,10 +99,9 @@ public class ShortcutTrampoline extends Activity { if (details.state == ComputerDetails.State.ONLINE && details.pairState == PairingManager.PairState.PAIRED) { // Launch game if provided app ID, otherwise launch app view - if (appIdString != null && appIdString.length() > 0) { - if (details.runningGameId == 0 || details.runningGameId == Integer.parseInt(appIdString)) { - intentStack.add(ServerHelper.createStartIntent(ShortcutTrampoline.this, - new NvApp(appNameString, Integer.parseInt(appIdString), false), details, managerBinder)); + if (app != null) { + if (details.runningGameId == 0 || details.runningGameId == app.getAppId()) { + intentStack.add(ServerHelper.createStartIntent(ShortcutTrampoline.this, app, details, managerBinder)); // Close this activity finish(); @@ -116,8 +111,7 @@ public class ShortcutTrampoline extends Activity { } else { // Create the start intent immediately, so we can safely unbind the managerBinder // below before we return. - final Intent startIntent = ServerHelper.createStartIntent(ShortcutTrampoline.this, - new NvApp(appNameString, Integer.parseInt(appIdString), false), details, managerBinder); + final Intent startIntent = ServerHelper.createStartIntent(ShortcutTrampoline.this, app, details, managerBinder); UiHelper.displayQuitConfirmationDialog(ShortcutTrampoline.this, new Runnable() { @Override @@ -200,7 +194,7 @@ public class ShortcutTrampoline extends Activity { } }; - protected boolean validateInput() { + protected boolean validateInput(String uuidString, String appIdString) { // Validate UUID if (uuidString == null) { Dialog.displayDialog(ShortcutTrampoline.this, @@ -242,13 +236,16 @@ public class ShortcutTrampoline extends Activity { UiHelper.notifyNewRootView(this); + String appIdString = getIntent().getStringExtra(Game.EXTRA_APP_ID); uuidString = getIntent().getStringExtra(AppView.UUID_EXTRA); - appIdString = getIntent().getStringExtra(APP_ID_EXTRA); - // Optional - may be null - appNameString = getIntent().getStringExtra(APP_NAME_EXTRA); + if (validateInput(uuidString, appIdString)) { + if (appIdString != null && !appIdString.isEmpty()) { + app = new NvApp(getIntent().getStringExtra(Game.EXTRA_APP_NAME), + Integer.parseInt(appIdString), + getIntent().getBooleanExtra(Game.EXTRA_APP_HDR, false)); + } - if (validateInput()) { // Bind to the computer manager service bindService(new Intent(this, ComputerManagerService.class), serviceConnection, Service.BIND_AUTO_CREATE); diff --git a/app/src/main/java/com/limelight/utils/ServerHelper.java b/app/src/main/java/com/limelight/utils/ServerHelper.java index 09b5a6a6..7a75fb9f 100644 --- a/app/src/main/java/com/limelight/utils/ServerHelper.java +++ b/app/src/main/java/com/limelight/utils/ServerHelper.java @@ -4,8 +4,10 @@ import android.app.Activity; import android.content.Intent; import android.widget.Toast; +import com.limelight.AppView; import com.limelight.Game; import com.limelight.R; +import com.limelight.ShortcutTrampoline; import com.limelight.binding.PlatformBinding; import com.limelight.computers.ComputerManagerService; import com.limelight.nvstream.http.ComputerDetails; @@ -25,6 +27,25 @@ public class ServerHelper { return computer.activeAddress; } + public static Intent createPcShortcutIntent(Activity parent, ComputerDetails computer) { + Intent i = new Intent(parent, ShortcutTrampoline.class); + i.putExtra(AppView.NAME_EXTRA, computer.name); + i.putExtra(AppView.UUID_EXTRA, computer.uuid); + i.setAction(Intent.ACTION_DEFAULT); + return i; + } + + public static Intent createAppShortcutIntent(Activity parent, ComputerDetails computer, NvApp app) { + Intent i = new Intent(parent, ShortcutTrampoline.class); + i.putExtra(AppView.NAME_EXTRA, computer.name); + i.putExtra(AppView.UUID_EXTRA, computer.uuid); + i.putExtra(Game.EXTRA_APP_NAME, app.getAppName()); + i.putExtra(Game.EXTRA_APP_ID, ""+app.getAppId()); + i.putExtra(Game.EXTRA_APP_HDR, app.isHdrSupported()); + i.setAction(Intent.ACTION_DEFAULT); + return i; + } + public static Intent createStartIntent(Activity parent, NvApp app, ComputerDetails computer, ComputerManagerService.ComputerManagerBinder managerBinder) { Intent intent = new Intent(parent, Game.class); diff --git a/app/src/main/java/com/limelight/utils/ShortcutHelper.java b/app/src/main/java/com/limelight/utils/ShortcutHelper.java index 6c07af57..7510e516 100644 --- a/app/src/main/java/com/limelight/utils/ShortcutHelper.java +++ b/app/src/main/java/com/limelight/utils/ShortcutHelper.java @@ -97,13 +97,8 @@ public class ShortcutHelper { public void createAppViewShortcut(ComputerDetails computer, boolean forceAdd, boolean newlyPaired) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { - Intent i = new Intent(context, ShortcutTrampoline.class); - i.putExtra(AppView.NAME_EXTRA, computer.name); - i.putExtra(AppView.UUID_EXTRA, computer.uuid); - i.setAction(Intent.ACTION_DEFAULT); - ShortcutInfo sinfo = new ShortcutInfo.Builder(context, computer.uuid) - .setIntent(i) + .setIntent(ServerHelper.createPcShortcutIntent(context, computer)) .setShortLabel(computer.name) .setLongLabel(computer.name) .setIcon(Icon.createWithResource(context, R.mipmap.ic_pc_scut)) @@ -149,13 +144,6 @@ public class ShortcutHelper { public boolean createPinnedGameShortcut(ComputerDetails computer, NvApp app, Bitmap iconBits) { if (sm.isRequestPinShortcutSupported()) { Icon appIcon; - Intent i = new Intent(context, ShortcutTrampoline.class); - - i.putExtra(AppView.NAME_EXTRA, computer.name); - i.putExtra(AppView.UUID_EXTRA, computer.uuid); - i.putExtra(ShortcutTrampoline.APP_NAME_EXTRA, app.getAppName()); - i.putExtra(ShortcutTrampoline.APP_ID_EXTRA, ""+app.getAppId()); - i.setAction(Intent.ACTION_DEFAULT); if (iconBits != null) { appIcon = Icon.createWithAdaptiveBitmap(iconBits); @@ -164,7 +152,7 @@ public class ShortcutHelper { } ShortcutInfo sInfo = new ShortcutInfo.Builder(context, getShortcutIdForGame(computer, app)) - .setIntent(i) + .setIntent(ServerHelper.createAppShortcutIntent(context, computer, app)) .setShortLabel(app.getAppName() + " (" + computer.name + ")") .setIcon(appIcon) .build(); diff --git a/app/src/main/java/com/limelight/utils/TvChannelHelper.java b/app/src/main/java/com/limelight/utils/TvChannelHelper.java index 095fde07..7b0203e4 100644 --- a/app/src/main/java/com/limelight/utils/TvChannelHelper.java +++ b/app/src/main/java/com/limelight/utils/TvChannelHelper.java @@ -65,15 +65,11 @@ public class TvChannelHelper { return; } - Intent i = new Intent(context, ShortcutTrampoline.class); - i.putExtra(AppView.NAME_EXTRA, computer.name); - i.putExtra(AppView.UUID_EXTRA, computer.uuid); - i.setAction(Intent.ACTION_DEFAULT); ChannelBuilder builder = new ChannelBuilder() .setType(TvContract.Channels.TYPE_PREVIEW) .setDisplayName(computer.name) .setInternalProviderId(computer.uuid) - .setAppLinkIntent(i); + .setAppLinkIntent(ServerHelper.createPcShortcutIntent(context, computer)); Long channelId = getChannelId(computer.uuid); if (channelId != null) { @@ -125,28 +121,19 @@ public class TvChannelHelper { return; } - PreviewProgramBuilder builder = new PreviewProgramBuilder(); - Intent i = new Intent(context, ShortcutTrampoline.class); - - i.putExtra(AppView.NAME_EXTRA, computer.name); - i.putExtra(AppView.UUID_EXTRA, computer.uuid); - i.putExtra(ShortcutTrampoline.APP_NAME_EXTRA, app.getAppName()); - i.putExtra(ShortcutTrampoline.APP_ID_EXTRA, ""+app.getAppId()); - i.setAction(Intent.ACTION_DEFAULT); - - Uri resourceURI = PosterContentProvider.createBoxArtUri(computer.uuid, ""+app.getAppId()); Long channelId = getChannelId(computer.uuid); if (channelId == null) { return; } - builder.setChannelId(channelId) + PreviewProgramBuilder builder = new PreviewProgramBuilder() + .setChannelId(channelId) .setType(TYPE_GAME) .setTitle(app.getAppName()) .setPosterArtAspectRatio(ASPECT_RATIO_MOVIE_POSTER) - .setPosterArtUri(resourceURI) - .setIntent(i) + .setPosterArtUri(PosterContentProvider.createBoxArtUri(computer.uuid, ""+app.getAppId())) + .setIntent(ServerHelper.createAppShortcutIntent(context, computer, app)) .setInternalProviderId(""+app.getAppId()) // Weight should increase each time we run the game .setWeight((int)((System.currentTimeMillis() - 1500000000000L) / 1000));