Skip to content

Commit

Permalink
ANDROID: Push a dynamic shortcut when starting a game
Browse files Browse the repository at this point in the history
This allows users to fast recall the last games with a long press on the
launcher icon.
This also allows users to pin these shortcuts without having to go by
the widgets selector (which is not implemented in some launchers).
  • Loading branch information
lephilousophe committed Jul 21, 2024
1 parent 85c52f7 commit ecd4de8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,9 @@ protected void setCurrentGame(String target) {
ScummVMActivity.this, ScummVMActivity.class);
setIntent(intent);
Log.d(ScummVM.LOG_TAG, "Current activity Intent is: " + data);
if (target != null) {
ShortcutCreatorActivity.pushShortcut(ScummVMActivity.this, target, intent);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,37 @@ public class ShortcutCreatorActivity extends Activity {

private IconsCache _cache;

static void pushShortcut(Context context, String gameId, Intent intent) {
Map<String, Map<String, String>> parsedIniMap;
try (FileReader reader = new FileReader(new File(context.getFilesDir(), "scummvm.ini"))) {
parsedIniMap = INIParser.parse(reader);
} catch(FileNotFoundException ignored) {
parsedIniMap = null;
} catch(IOException ignored) {
parsedIniMap = null;
}

if (parsedIniMap == null) {
return;
}

Game game = Game.loadGame(parsedIniMap, gameId);
if (game == null) {
return;
}

FileInputStream defaultStream = openFile(new File(context.getFilesDir(), "gui-icons.dat"));

File iconsPath = INIParser.getPath(parsedIniMap, "scummvm", "iconspath",
new File(context.getFilesDir(), "icons"));
FileInputStream[] packsStream = openFiles(context, iconsPath, "gui-icons.*\\.dat");

IconsCache cache = new IconsCache(context, defaultStream, packsStream);
final Drawable icon = cache.getGameIcon(game);

CompatHelpers.ShortcutCreator.pushDynamicShortcut(context, game.getTarget(), intent, game.getDescription(), icon, R.drawable.ic_no_game_icon);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down

0 comments on commit ecd4de8

Please sign in to comment.