OSDN Git Service

Moar fixes for animation and window size
[android-x86/packages-apps-Taskbar.git] / app / src / main / java / com / farmerbb / taskbar / activity / DummyActivity.java
index e10bcd4..d2640c5 100644 (file)
 
 package com.farmerbb.taskbar.activity;
 
+import android.annotation.SuppressLint;
+import android.annotation.TargetApi;
 import android.app.Activity;
+import android.app.AlertDialog;
 import android.app.admin.DevicePolicyManager;
 import android.content.ActivityNotFoundException;
 import android.content.ComponentName;
@@ -24,11 +27,14 @@ import android.content.SharedPreferences;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
+import android.os.Handler;
 import android.os.UserManager;
+import android.provider.Settings;
 import android.view.View;
 
 import com.farmerbb.taskbar.R;
 import com.farmerbb.taskbar.receiver.LockDeviceReceiver;
+import com.farmerbb.taskbar.util.ApplicationType;
 import com.farmerbb.taskbar.util.FreeformHackHelper;
 import com.farmerbb.taskbar.util.U;
 
@@ -42,6 +48,8 @@ public class DummyActivity extends Activity {
         setContentView(new View(this));
     }
 
+    @SuppressLint("RestrictedApi")
+    @TargetApi(Build.VERSION_CODES.N)
     @Override
     protected void onResume() {
         super.onResume();
@@ -60,28 +68,76 @@ public class DummyActivity extends Activity {
                     startActivity(intent);
                 } catch (ActivityNotFoundException e) { /* Gracefully fail */ }
             } else if(getIntent().hasExtra("device_admin")) {
-                Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
-                intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, new ComponentName(this, LockDeviceReceiver.class));
-                intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, getString(R.string.device_admin_description));
+                AlertDialog.Builder builder = new AlertDialog.Builder(U.wrapContext(this));
+                builder.setTitle(R.string.permission_dialog_title)
+                        .setMessage(R.string.device_admin_disclosure)
+                        .setNegativeButton(R.string.action_cancel, (dialog, which) -> new Handler().post(this::finish))
+                        .setPositiveButton(R.string.action_activate, (dialog, which) -> {
+                            Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
+                            intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, new ComponentName(this, LockDeviceReceiver.class));
+                            intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, getString(R.string.device_admin_description));
 
-                try {
-                    startActivity(intent);
-                } catch (ActivityNotFoundException e) {
-                    U.showToast(this, R.string.lock_device_not_supported);
+                            SharedPreferences pref = U.getSharedPreferences(this);
+                            if(pref.getBoolean("disable_animations", false))
+                                intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
 
-                    finish();
-                }
+                            U.launchApp(this, () -> {
+                                try {
+                                    startActivity(intent, U.getActivityOptionsBundle(this, ApplicationType.APPLICATION));
+                                } catch (ActivityNotFoundException e) {
+                                    U.showToast(this, R.string.lock_device_not_supported);
+
+                                    finish();
+                                }
+                            });
+                        });
+
+                AlertDialog dialog = builder.create();
+                dialog.show();
+                dialog.setCancelable(false);
+            } else if(getIntent().hasExtra("accessibility")) {
+                AlertDialog.Builder builder = new AlertDialog.Builder(U.wrapContext(this));
+                builder.setTitle(R.string.permission_dialog_title)
+                        .setMessage(R.string.enable_accessibility)
+                        .setNegativeButton(R.string.action_cancel, (dialog, which) -> new Handler().post(this::finish))
+                        .setPositiveButton(R.string.action_activate, (dialog, which) -> {
+                            Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
+
+                            SharedPreferences pref = U.getSharedPreferences(this);
+                            if(pref.getBoolean("disable_animations", false))
+                                intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
+
+                            U.launchApp(this, () -> {
+                                try {
+                                    startActivity(intent, U.getActivityOptionsBundle(this, ApplicationType.APPLICATION));
+                                    U.showToastLong(this, R.string.usage_stats_message);
+                                } catch (ActivityNotFoundException e) {
+                                    U.showToast(this, R.string.lock_device_not_supported);
+
+                                    finish();
+                                }
+                            });
+                        });
+
+                AlertDialog dialog = builder.create();
+                dialog.show();
+                dialog.setCancelable(false);
             } else if(getIntent().hasExtra("start_freeform_hack")) {
                 SharedPreferences pref = U.getSharedPreferences(this);
-                if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
+                if(U.hasFreeformSupport(this)
                         && pref.getBoolean("freeform_hack", false)
                         && isInMultiWindowMode()
                         && !FreeformHackHelper.getInstance().isFreeformHackActive()) {
-                    U.startFreeformHack(this, false, false);
+                    U.startFreeformHack(this);
                 }
 
                 finish();
-            } else finish();
+            } else if(getIntent().hasExtra("show_permission_dialog"))
+                U.showPermissionDialog(U.wrapContext(this), null, this::finish);
+            else if(getIntent().hasExtra("show_recent_apps_dialog"))
+                U.showRecentAppsDialog(U.wrapContext(this), null, this::finish);
+            else
+                finish();
         }
     }
 }
\ No newline at end of file