OSDN Git Service

Use framework toasts on Android 7.1+ instead of 8.0+
[android-x86/packages-apps-Taskbar.git] / app / src / main / java / com / farmerbb / taskbar / util / U.java
index f65e18e..febae19 100644 (file)
@@ -186,7 +186,8 @@ public class U {
         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);
@@ -247,7 +248,8 @@ public class U {
         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
@@ -299,8 +301,7 @@ public class U {
         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) {
@@ -364,7 +365,7 @@ public class U {
                     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
@@ -395,7 +396,7 @@ public class U {
                     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
@@ -455,7 +456,7 @@ public class U {
                     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
@@ -486,7 +487,7 @@ public class U {
                     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
@@ -531,7 +532,7 @@ public class U {
                     metrics.widthPixels + 1,
                     metrics.heightPixels + 1
             )).toBundle());
-        } catch (IllegalArgumentException e) { /* Gracefully fail */ }
+        } catch (IllegalArgumentException | SecurityException e) { /* Gracefully fail */ }
     }
 
     public static void checkForUpdates(Context context) {
@@ -891,7 +892,8 @@ public class U {
                 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) {
@@ -918,11 +920,6 @@ public class U {
         }
     }
 
-    @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");
     }
@@ -1073,4 +1070,10 @@ public class U {
 
         return metrics;
     }
+
+    public static int getOverlayType() {
+        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
+                ? WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
+                : WindowManager.LayoutParams.TYPE_PHONE;
+    }
 }