import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
+import android.content.pm.ApplicationInfo;
import android.content.pm.LauncherActivityInfo;
import android.content.pm.LauncherApps;
import android.content.pm.PackageManager;
import com.farmerbb.taskbar.receiver.LockDeviceReceiver;
import com.farmerbb.taskbar.service.PowerMenuService;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
public static final int HIDDEN = 0;
public static final int TOP_APPS = 1;
+ // From android.app.ActivityManager.StackId
+ private static final int FULLSCREEN_WORKSPACE_STACK_ID = 1;
+ private static final int FREEFORM_WORKSPACE_STACK_ID = 2;
+
public static SharedPreferences getSharedPreferences(Context context) {
if(pref == null) pref = context.getSharedPreferences(BuildConfig.APPLICATION_ID + "_preferences", Context.MODE_PRIVATE);
return pref;
SharedPreferences pref = getSharedPreferences(context);
FreeformHackHelper helper = FreeformHackHelper.getInstance();
- boolean openInFullscreen = pref.getBoolean("open_in_fullscreen", true);
boolean freeformHackActive = openInNewWindow
? helper.isInFreeformWorkspace()
- : (openInFullscreen
- ? helper.isInFreeformWorkspace()
- : helper.isFreeformHackActive());
+ : helper.isFreeformHackActive();
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
&& pref.getBoolean("freeform_hack", false)
if(!shouldDelay)
continueLaunchingApp(context, packageName, componentName, userId,
windowSize, launchedFromTaskbar, openInNewWindow, shortcut);
- } else if(helper.isInFreeformWorkspace() || !openInFullscreen)
+ } else
continueLaunchingApp(context, packageName, componentName, userId,
windowSize, launchedFromTaskbar, openInNewWindow, shortcut);
}
} else switch(windowSize) {
case "standard":
if(FreeformHackHelper.getInstance().isInFreeformWorkspace()) {
+ Bundle bundle = getActivityOptions(isGame(context, packageName)).toBundle();
if(shortcut == null) {
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
if(userId == userManager.getSerialNumberForUser(Process.myUserHandle())) {
try {
- context.startActivity(intent);
+ context.startActivity(intent, bundle);
} catch (ActivityNotFoundException e) {
- launchAndroidForWork(context, intent.getComponent(), null, userId);
+ launchAndroidForWork(context, intent.getComponent(), bundle, userId);
} catch (IllegalArgumentException e) { /* Gracefully fail */ }
} else
- launchAndroidForWork(context, intent.getComponent(), null, userId);
+ launchAndroidForWork(context, intent.getComponent(), bundle, userId);
} else
- launchShortcut(context, shortcut, null);
+ launchShortcut(context, shortcut, bundle);
} else
- launchMode1(context, intent, 1, userId, shortcut);
+ launchMode1(context, intent, 1, userId, shortcut, isGame(context, packageName));
break;
case "large":
- launchMode1(context, intent, 2, userId, shortcut);
+ launchMode1(context, intent, 2, userId, shortcut, isGame(context, packageName));
break;
case "fullscreen":
- launchMode2(context, intent, FULLSCREEN, userId, shortcut);
+ launchMode2(context, intent, FULLSCREEN, userId, shortcut, isGame(context, packageName));
break;
case "half_left":
- launchMode2(context, intent, LEFT, userId, shortcut);
+ launchMode2(context, intent, LEFT, userId, shortcut, isGame(context, packageName));
break;
case "half_right":
- launchMode2(context, intent, RIGHT, userId, shortcut);
+ launchMode2(context, intent, RIGHT, userId, shortcut, isGame(context, packageName));
break;
case "phone_size":
- launchMode3(context, intent, userId, shortcut);
+ launchMode3(context, intent, userId, shortcut, isGame(context, packageName));
break;
}
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.N)
- private static void launchMode1(Context context, Intent intent, int factor, long userId, ShortcutInfo shortcut) {
+ private static void launchMode1(Context context, Intent intent, int factor, long userId, ShortcutInfo shortcut, Boolean isGame) {
DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
Display display = dm.getDisplay(Display.DEFAULT_DISPLAY);
int height1 = display.getHeight() / (4 * factor);
int height2 = display.getHeight() - height1;
- Bundle bundle = ActivityOptions.makeBasic().setLaunchBounds(new Rect(
+ Bundle bundle = getActivityOptions(isGame).setLaunchBounds(new Rect(
width1,
height1,
width2,
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.N)
- private static void launchMode2(Context context, Intent intent, int launchType, long userId, ShortcutInfo shortcut) {
+ private static void launchMode2(Context context, Intent intent, int launchType, long userId, ShortcutInfo shortcut, Boolean isGame) {
DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
Display display = dm.getDisplay(Display.DEFAULT_DISPLAY);
} else if(isLandscape || (launchType != RIGHT && isPortrait))
top = top + iconSize;
- Bundle bundle = ActivityOptions.makeBasic().setLaunchBounds(new Rect(
+ Bundle bundle = getActivityOptions(isGame).setLaunchBounds(new Rect(
left,
top,
right,
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.N)
- private static void launchMode3(Context context, Intent intent, long userId, ShortcutInfo shortcut) {
+ private static void launchMode3(Context context, Intent intent, long userId, ShortcutInfo shortcut, Boolean isGame) {
DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
Display display = dm.getDisplay(Display.DEFAULT_DISPLAY);
int height1 = display.getHeight() / 2;
int height2 = context.getResources().getDimensionPixelSize(R.dimen.phone_size_height) / 2;
- Bundle bundle = ActivityOptions.makeBasic().setLaunchBounds(new Rect(
+ Bundle bundle = getActivityOptions(isGame).setLaunchBounds(new Rect(
width1 - width2,
height1 - height2,
width1 + width2,
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
long userId = userManager.getSerialNumberForUser(Process.myUserHandle());
- launchMode2(context, intent, FULLSCREEN, userId, null);
+ launchMode2(context, intent, FULLSCREEN, userId, null, null);
}
@SuppressWarnings("deprecation")
DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
Display display = dm.getDisplay(Display.DEFAULT_DISPLAY);
try {
- context.startActivity(intent, ActivityOptions.makeBasic().setLaunchBounds(new Rect(
+ context.startActivity(intent, getActivityOptions(false).setLaunchBounds(new Rect(
display.getWidth(),
display.getHeight(),
display.getWidth() + 1,
public static boolean canDrawOverlays(Context context) {
return Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Settings.canDrawOverlays(context);
}
+
+ public static boolean isGame(Context context, String packageName) {
+ SharedPreferences pref = getSharedPreferences(context);
+ if(pref.getBoolean("launch_games_fullscreen", true)) {
+ PackageManager pm = context.getPackageManager();
+
+ try {
+ ApplicationInfo info = pm.getApplicationInfo(packageName, 0);
+ return (info.flags & ApplicationInfo.FLAG_IS_GAME) != 0;
+ } catch (PackageManager.NameNotFoundException e) {
+ return false;
+ }
+ } else
+ return false;
+ }
+
+ @TargetApi(Build.VERSION_CODES.M)
+ private static ActivityOptions getActivityOptions(Boolean isGame) {
+ ActivityOptions options = ActivityOptions.makeBasic();
+
+ if(isGame != null) {
+ try {
+ Method method = ActivityOptions.class.getMethod("setLaunchStackId", int.class);
+ method.invoke(options, isGame ? FULLSCREEN_WORKSPACE_STACK_ID : FREEFORM_WORKSPACE_STACK_ID);
+ } catch (Exception e) { /* Gracefully fail */ }
+ }
+
+ return options;
+ }
}
<string name="pref_title_invisible_button">Hide button while Taskbar is collapsed</string>
<string name="pref_title_freeform_mode_help">Help & instructions for freeform mode</string>
<string name="freeform_help_dialog_title">Help & instructions</string>
- <string name="freeform_help_dialog_message"><b>About freeform mode</b>\n\nTaskbar lets you launch apps in freeform floating windows on Android 7.0+ (Nougat). No root access is required. Simply follow these steps to configure your device for launching apps in freeform mode:\n\n<b>1.</b> Check the box for \"Freeform window support\" inside the Taskbar app\n\n<b>2.</b> Follow the directions that appear in the pop-up to enable the proper settings on your device\n\n<b>3.</b> With Taskbar turned on, go to your device\'s recent apps page\n\n<b>4.</b> Clear all recent apps, then go back to the (empty) recent apps page\n\n<b>5.</b> Press Taskbar\'s start button and select an app to launch it in a freeform window\n\n<b>Troubleshooting</b>\n\n<i>• Apps still launch full-screen</i>\n\nIf an app is launched that is already loaded into memory, Taskbar will bring it into the foreground. In order to launch the app into freeform mode, it has to be launched from a fresh state.\n\nSwipe the app away from recents, and then re-launch it from the recent apps page using Taskbar. If this doesn\'t work, then long-press the app icon, select \"App info\", and then force stop the app.\n\nNote that Taskbar can only initiate freeform mode from your device\'s recent apps page, from the home screen, or from the freeform workspace itself. Launching apps from within another full-screen app will also launch it into full-screen mode, unless freeform mode has already been initiated since Taskbar was last turned on and the \"Open windows from fullscreen apps\" option is enabled.\n\n<i>• Apps that are maximized cannot be restored into a window</i>\n\nIf you press the Maximize button on an app\'s title bar, Android will bring the app out of freeform mode and into full-screen mode. As mentioned above, Taskbar can only launch apps into freeform windows if they are launched from a fresh state.\n\nTo fix this, you can maximize windows by tapping or clicking just outside the app\'s window frame. This will expand the window to fill all the available space while keeping it in the freeform window workspace.\n\n<b>Enabling full system-level freeform window support</b>\n\nIf you have access to a computer with the Android SDK installed, you can enable support for freeform mode at the system level by running the following adb shell command:\n\nsettings put global enable_freeform_support 1\n\nReboot your device after running the above command, and a new button will appear for app entries in your device\'s recent apps page to enter/exit freeform mode for a given app. (Note that the button currently does not work on Android 7.1.2)</string>
+ <string name="freeform_help_dialog_message"><b>About freeform mode</b>\n\nTaskbar lets you launch apps in freeform floating windows on Android 7.0+ (Nougat). No root access is required. Simply follow these steps to configure your device for launching apps in freeform mode:\n\n<b>1.</b> Check the box for \"Freeform window support\" inside the Taskbar app\n\n<b>2.</b> Follow the directions that appear in the pop-up to enable the proper settings on your device\n\n<b>3.</b> Go to your device\'s recent apps page and clear all recent apps\n\n<b>4.</b> Select an app using Taskbar to launch it in a freeform window\n\n<b>Troubleshooting</b>\n\n<i>• Apps still launch fullscreen</i>\n\nIf an app is launched that is already loaded into memory, Taskbar will bring it into the foreground. In order to launch the app into freeform mode, it has to be launched from a fresh state.\n\nSwipe the app away from recents, and then re-launch it from the recent apps page using Taskbar. If this doesn\'t work, then long-press the app icon, select \"App info\", and then force stop the app.\n\n<i>• Apps that are maximized cannot be restored into a window</i>\n\nIf you press the Maximize button on an app\'s title bar, Android will bring the app out of freeform mode and into fullscreen mode. As mentioned above, Taskbar can only launch apps into freeform windows if they are launched from a fresh state.\n\nTo fix this, you can maximize windows by tapping or clicking just outside the app\'s window frame. This will expand the window to fill all the available space while keeping it in the freeform window workspace.\n\n<b>Enabling full system-level freeform window support</b>\n\nIf you have access to a computer with the Android SDK installed, you can enable support for freeform mode at the system level by running the following adb shell command:\n\nsettings put global enable_freeform_support 1\n\nReboot your device after running the above command, and a new button will appear for app entries in your device\'s recent apps page to enter/exit freeform mode for a given app. (Note that the button currently does not work on Android 7.1.2)</string>
<string name="action_developer_options">Open Developer Options</string>
<string name="action_close">Close</string>
<string name="already_top_app">%1$s can\'t be selected because it is on the top apps list</string>
<string name="alt_button_config">Alternative position for collapse button</string>
- <string name="pref_title_open_in_fullscreen">Open windows from fullscreen apps</string>
- <string name="pref_description_open_in_fullscreen">Requires freeform mode to be initiated at least once after Taskbar starts. When unchecked, freeform windows will only open while in the freeform workspace.</string>
<string name="pref_title_save_window_sizes">Save window sizes for apps</string>
<string name="pref_description_save_window_sizes">When opening new windows from the context menu</string>
<string name="hide_taskbar_disclaimer">Does not apply to apps in freeform mode</string>
<string name="transparent_start_menu">Transparent start menu</string>
+ <string name="launch_games_fullscreen_title">Launch games fullscreen</string>
+ <string name="launch_games_fullscreen_message">If an application declares itself to be a game, disallow it from launching in freeform mode</string>
+
</resources>