diff --git a/app/src/main/java/com/limelight/AppView.java b/app/src/main/java/com/limelight/AppView.java index 673d4a2e..9b069b90 100644 --- a/app/src/main/java/com/limelight/AppView.java +++ b/app/src/main/java/com/limelight/AppView.java @@ -248,13 +248,17 @@ public class AppView extends Activity implements AdapterFragmentCallbacks { uuidString = getIntent().getStringExtra(UUID_EXTRA); - shortcutHelper.reportShortcutUsed(uuidString); + String computerName = getIntent().getStringExtra(NAME_EXTRA); - String labelText = getResources().getString(R.string.title_applist)+" "+getIntent().getStringExtra(NAME_EXTRA); + String labelText = getResources().getString(R.string.title_applist)+" "+computerName; TextView label = (TextView) findViewById(R.id.appListText); setTitle(labelText); label.setText(labelText); + // Add a launcher shortcut for this PC (forced, since this is user interaction) + shortcutHelper.createAppViewShortcut(uuidString, computerName, uuidString, true); + shortcutHelper.reportShortcutUsed(uuidString); + // 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/Game.java b/app/src/main/java/com/limelight/Game.java index bbdf7327..b58efc7d 100644 --- a/app/src/main/java/com/limelight/Game.java +++ b/app/src/main/java/com/limelight/Game.java @@ -24,6 +24,7 @@ import com.limelight.preferences.PreferenceConfiguration; import com.limelight.ui.GameGestures; import com.limelight.ui.StreamView; import com.limelight.utils.Dialog; +import com.limelight.utils.ShortcutHelper; import com.limelight.utils.SpinnerDialog; import android.annotation.SuppressLint; @@ -97,6 +98,8 @@ public class Game extends Activity implements SurfaceHolder.Callback, private boolean grabComboDown = false; private StreamView streamView; + private ShortcutHelper shortcutHelper; + private EnhancedDecoderRenderer decoderRenderer; private WifiManager.WifiLock wifiLock; @@ -123,11 +126,15 @@ public class Game extends Activity implements SurfaceHolder.Callback, public static final String EXTRA_APP_ID = "AppId"; public static final String EXTRA_UNIQUEID = "UniqueId"; public static final String EXTRA_STREAMING_REMOTE = "Remote"; + public static final String EXTRA_PC_UUID = "UUID"; + public static final String EXTRA_PC_NAME = "PcName"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + shortcutHelper = new ShortcutHelper(this); + String locale = PreferenceConfiguration.readPreferences(this).language; if (!locale.equals(PreferenceConfiguration.DEFAULT_LANGUAGE)) { Configuration config = new Configuration(getResources().getConfiguration()); @@ -193,12 +200,18 @@ public class Game extends Activity implements SurfaceHolder.Callback, int appId = Game.this.getIntent().getIntExtra(EXTRA_APP_ID, StreamConfiguration.INVALID_APP_ID); String uniqueId = Game.this.getIntent().getStringExtra(EXTRA_UNIQUEID); boolean remote = Game.this.getIntent().getBooleanExtra(EXTRA_STREAMING_REMOTE, false); + String uuid = Game.this.getIntent().getStringExtra(EXTRA_PC_UUID); + String pcName = Game.this.getIntent().getStringExtra(EXTRA_PC_NAME); if (appId == StreamConfiguration.INVALID_APP_ID) { finish(); return; } + // Add a launcher shortcut for this PC (forced, since this is user interaction) + shortcutHelper.createAppViewShortcut(uuid, pcName, uuid, true); + shortcutHelper.reportShortcutUsed(uuid); + // Initialize the MediaCodec helper before creating the decoder MediaCodecHelper.initializeWithContext(this); diff --git a/app/src/main/java/com/limelight/PcView.java b/app/src/main/java/com/limelight/PcView.java index 5a72bf78..145f0ce0 100644 --- a/app/src/main/java/com/limelight/PcView.java +++ b/app/src/main/java/com/limelight/PcView.java @@ -357,9 +357,6 @@ public class PcView extends Activity implements AdapterFragmentCallbacks { // Invalidate reachability information after pairing to force // a refresh before reading pair state again managerBinder.invalidateStateForComputer(computer.uuid); - - // Add a launcher shortcut for this PC - shortcutHelper.createAppViewShortcut(computer.uuid.toString(), computer); } else { // Should be no other values @@ -612,7 +609,7 @@ public class PcView extends Activity implements AdapterFragmentCallbacks { // Add a launcher shortcut for this PC if (details.pairState == PairState.PAIRED) { - shortcutHelper.createAppViewShortcut(details.uuid.toString(), details); + shortcutHelper.createAppViewShortcut(details.uuid.toString(), details, false); } if (existingEntry != null) { diff --git a/app/src/main/java/com/limelight/utils/ServerHelper.java b/app/src/main/java/com/limelight/utils/ServerHelper.java index 807191cf..0a21e5c0 100644 --- a/app/src/main/java/com/limelight/utils/ServerHelper.java +++ b/app/src/main/java/com/limelight/utils/ServerHelper.java @@ -34,6 +34,8 @@ public class ServerHelper { intent.putExtra(Game.EXTRA_UNIQUEID, managerBinder.getUniqueId()); intent.putExtra(Game.EXTRA_STREAMING_REMOTE, computer.reachability != ComputerDetails.Reachability.LOCAL); + intent.putExtra(Game.EXTRA_PC_UUID, computer.uuid.toString()); + intent.putExtra(Game.EXTRA_PC_NAME, computer.name); return intent; } diff --git a/app/src/main/java/com/limelight/utils/ShortcutHelper.java b/app/src/main/java/com/limelight/utils/ShortcutHelper.java index 215b088f..c02f0c1c 100644 --- a/app/src/main/java/com/limelight/utils/ShortcutHelper.java +++ b/app/src/main/java/com/limelight/utils/ShortcutHelper.java @@ -87,17 +87,17 @@ public class ShortcutHelper { } } - public void createAppViewShortcut(String id, ComputerDetails details) { + public void createAppViewShortcut(String id, String computerName, String computerUuid, boolean forceAdd) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { Intent i = new Intent(context, AppViewShortcutTrampoline.class); - i.putExtra(AppView.NAME_EXTRA, details.name); - i.putExtra(AppView.UUID_EXTRA, details.uuid.toString()); + i.putExtra(AppView.NAME_EXTRA, computerName); + i.putExtra(AppView.UUID_EXTRA, computerUuid); i.setAction(Intent.ACTION_DEFAULT); ShortcutInfo sinfo = new ShortcutInfo.Builder(context, id) .setIntent(i) - .setShortLabel(details.name) - .setLongLabel(details.name) + .setShortLabel(computerName) + .setLongLabel(computerName) .setIcon(Icon.createWithResource(context, R.mipmap.ic_pc_scut)) .build(); @@ -112,12 +112,21 @@ public class ShortcutHelper { // NOTE: This CAN'T be an else on the above if, because it's // possible that we have an existing shortcut but it's not a dynamic one. if (!isExistingDynamicShortcut(id)) { - reapShortcutsForDynamicAdd(); - sm.addDynamicShortcuts(Collections.singletonList(sinfo)); + // To avoid a random carousel of shortcuts popping in and out based on polling status, + // we only add shortcuts if it's not at the limit or the user made a conscious action + // to interact with this PC. + if (forceAdd || sm.getDynamicShortcuts().size() < sm.getMaxShortcutCountPerActivity()) { + reapShortcutsForDynamicAdd(); + sm.addDynamicShortcuts(Collections.singletonList(sinfo)); + } } } } + public void createAppViewShortcut(String id, ComputerDetails details, boolean forceAdd) { + createAppViewShortcut(id, details.name, details.uuid.toString(), forceAdd); + } + public void disableShortcut(String id, CharSequence reason) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { ShortcutInfo sinfo = getInfoForId(id);