import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
-import android.hardware.display.DisplayManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
private U() {}
- public static final String BASE_APPLICATION_ID = BuildConfig.BASE_APPLICATION_ID;
- public static final String PAID_APPLICATION_ID = BuildConfig.PAID_APPLICATION_ID;
-
private static SharedPreferences pref;
private static Integer cachedRotation;
cancelToast();
ToastInterface toast;
- if(BuildConfig.APPLICATION_ID.equals(BuildConfig.ANDROIDX86_APPLICATION_ID))
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1
+ || BuildConfig.APPLICATION_ID.equals(BuildConfig.ANDROIDX86_APPLICATION_ID))
toast = new ToastFrameworkImpl(context, message, length);
else
toast = new ToastCompatImpl(context, message, length);
SharedPreferences pref = getSharedPreferences(context);
FreeformHackHelper helper = FreeformHackHelper.getInstance();
- boolean specialLaunch = isOPreview() && FreeformHackHelper.getInstance().isInFreeformWorkspace()
+ boolean specialLaunch = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
+ && FreeformHackHelper.getInstance().isInFreeformWorkspace()
&& MenuHelper.getInstance().isContextMenuOpen();
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
if(FreeformHackHelper.getInstance().isInFreeformWorkspace()
- && Build.VERSION.SDK_INT <= Build.VERSION_CODES.N_MR1
- && !isOPreview())
+ && Build.VERSION.SDK_INT <= Build.VERSION_CODES.N_MR1)
intent.addFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME);
if(launchedFromTaskbar) {
context.startActivity(intent, bundle);
} catch (ActivityNotFoundException e) {
launchAndroidForWork(context, intent.getComponent(), bundle, userId);
- } catch (IllegalArgumentException e) { /* Gracefully fail */ }
+ } catch (IllegalArgumentException | SecurityException e) { /* Gracefully fail */ }
} else
launchAndroidForWork(context, intent.getComponent(), bundle, userId);
} else
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.N)
private static void launchMode1(Context context, Intent intent, long userId, ShortcutInfo shortcut, ApplicationType type) {
- DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
- Display display = dm.getDisplay(Display.DEFAULT_DISPLAY);
+ DisplayMetrics metrics = getRealDisplayMetrics(context);
- int width1 = display.getWidth() / 8;
- int width2 = display.getWidth() - width1;
- int height1 = display.getHeight() / 8;
- int height2 = display.getHeight() - height1;
+ int width1 = metrics.widthPixels / 8;
+ int width2 = metrics.widthPixels - width1;
+ int height1 = metrics.heightPixels / 8;
+ int height2 = metrics.heightPixels - height1;
Bundle bundle = getActivityOptions(type).setLaunchBounds(new Rect(
width1,
context.startActivity(intent, bundle);
} catch (ActivityNotFoundException e) {
launchAndroidForWork(context, intent.getComponent(), bundle, userId);
- } catch (IllegalArgumentException e) { /* Gracefully fail */ }
+ } catch (IllegalArgumentException | SecurityException e) { /* Gracefully fail */ }
} else
launchAndroidForWork(context, intent.getComponent(), bundle, userId);
} else
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.N)
private static void launchMode2(Context context, Intent intent, int launchType, long userId, ShortcutInfo shortcut, ApplicationType type) {
- DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
- Display display = dm.getDisplay(Display.DEFAULT_DISPLAY);
-
+ DisplayMetrics metrics = getRealDisplayMetrics(context);
+
int statusBarHeight = getStatusBarHeight(context);
String position = getTaskbarPosition(context);
boolean isLandscape = context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
int left = launchType == RIGHT && isLandscape
- ? display.getWidth() / 2
+ ? metrics.widthPixels / 2
: 0;
int top = launchType == RIGHT && isPortrait
- ? display.getHeight() / 2
+ ? metrics.heightPixels / 2
: statusBarHeight;
int right = launchType == LEFT && isLandscape
- ? display.getWidth() / 2
- : display.getWidth();
+ ? metrics.widthPixels / 2
+ : metrics.widthPixels;
int bottom = launchType == LEFT && isPortrait
- ? display.getHeight() / 2
- : display.getHeight();
+ ? metrics.heightPixels / 2
+ : metrics.heightPixels;
int iconSize = context.getResources().getDimensionPixelSize(R.dimen.icon_size);
context.startActivity(intent, bundle);
} catch (ActivityNotFoundException e) {
launchAndroidForWork(context, intent.getComponent(), bundle, userId);
- } catch (IllegalArgumentException e) { /* Gracefully fail */ }
+ } catch (IllegalArgumentException | SecurityException e) { /* Gracefully fail */ }
} else
launchAndroidForWork(context, intent.getComponent(), bundle, userId);
} else
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.N)
private static void launchMode3(Context context, Intent intent, long userId, ShortcutInfo shortcut, ApplicationType type) {
- DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
- Display display = dm.getDisplay(Display.DEFAULT_DISPLAY);
+ DisplayMetrics metrics = getRealDisplayMetrics(context);
- int width1 = display.getWidth() / 2;
+ int width1 = metrics.widthPixels / 2;
int width2 = context.getResources().getDimensionPixelSize(R.dimen.phone_size_width) / 2;
- int height1 = display.getHeight() / 2;
+ int height1 = metrics.heightPixels / 2;
int height2 = context.getResources().getDimensionPixelSize(R.dimen.phone_size_height) / 2;
Bundle bundle = getActivityOptions(type).setLaunchBounds(new Rect(
context.startActivity(intent, bundle);
} catch (ActivityNotFoundException e) {
launchAndroidForWork(context, intent.getComponent(), bundle, userId);
- } catch (IllegalArgumentException e) { /* Gracefully fail */ }
+ } catch (IllegalArgumentException | SecurityException e) { /* Gracefully fail */ }
} else
launchAndroidForWork(context, intent.getComponent(), bundle, userId);
} else
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.N)
public static void launchAppLowerRight(Context context, Intent intent) {
- DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
- Display display = dm.getDisplay(Display.DEFAULT_DISPLAY);
+ DisplayMetrics metrics = getRealDisplayMetrics(context);
try {
context.startActivity(intent, getActivityOptions(ApplicationType.FREEFORM_HACK).setLaunchBounds(new Rect(
- display.getWidth(),
- display.getHeight(),
- display.getWidth() + 1,
- display.getHeight() + 1
+ metrics.widthPixels,
+ metrics.heightPixels,
+ metrics.widthPixels + 1,
+ metrics.heightPixels + 1
)).toBundle());
- } catch (IllegalArgumentException e) { /* Gracefully fail */ }
+ } catch (IllegalArgumentException | SecurityException e) { /* Gracefully fail */ }
}
public static void checkForUpdates(Context context) {
private static int getMaxNumOfColumns(Context context) {
SharedPreferences pref = getSharedPreferences(context);
- DisplayMetrics metrics = context.getResources().getDisplayMetrics();
+ DisplayMetrics metrics = getRealDisplayMetrics(context);
float baseTaskbarSize = getBaseTaskbarSizeFloat(context) / metrics.density;
int numOfColumns = 0;
stackId = FREEFORM_WORKSPACE_STACK_ID;
break;
case CONTEXT_MENU:
- if(isOPreview()) stackId = FULLSCREEN_WORKSPACE_STACK_ID;
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+ stackId = FULLSCREEN_WORKSPACE_STACK_ID;
}
if(stackId != null) {
}
}
- @TargetApi(Build.VERSION_CODES.M)
- public static boolean isOPreview() {
- return (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) || (Build.VERSION.RELEASE.equals("O") && Build.VERSION.PREVIEW_SDK_INT > 0);
+ public static boolean isChromeOs(Context context) {
+ return context.getPackageManager().hasSystemFeature("org.chromium.arc");
}
public static boolean hasSupportLibrary(Context context) {
.apply();
}
}
+
+ public static DisplayMetrics getRealDisplayMetrics(Context context) {
+ DisplayMetrics metrics = new DisplayMetrics();
+ WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
+ Display disp = wm.getDefaultDisplay();
+
+ SharedPreferences pref = getSharedPreferences(context);
+ if(isChromeOs(context) && !pref.getBoolean("chrome_os_context_menu_fix", false))
+ disp.getRealMetrics(metrics);
+ else
+ disp.getMetrics(metrics);
+
+ return metrics;
+ }
+
+ public static int getOverlayType() {
+ return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
+ ? WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
+ : WindowManager.LayoutParams.TYPE_PHONE;
+ }
}