Search in sources :

Example 1 with Callbacks

use of com.farmerbb.taskbar.util.Callbacks in project Taskbar by farmerbb.

the class HomeActivityDelegate method startTaskbar.

private void startTaskbar() {
    // Ensure that the freeform hack is started whenever Taskbar starts
    if (U.hasFreeformSupport(this) && U.isFreeformModeEnabled(this) && !FreeformHackHelper.getInstance().isFreeformHackActive()) {
        U.startFreeformHack(this, true);
    }
    SharedPreferences pref = U.getSharedPreferences(this);
    if (pref.getBoolean(PREF_FIRST_RUN, true)) {
        SharedPreferences.Editor editor = pref.edit();
        editor.putBoolean(PREF_FIRST_RUN, false);
        editor.putBoolean(PREF_COLLAPSED, true);
        editor.apply();
        dialog = U.showRecentAppsDialog(U.wrapContext(this), new Callbacks(() -> dialog = U.showErrorDialog(U.wrapContext(this), "GET_USAGE_STATS"), null));
    }
    if (isSecondaryHome) {
        // Stop any currently running services and switch to using HomeActivityDelegate as UI host
        stopService(new Intent(this, TaskbarService.class));
        stopService(new Intent(this, StartMenuService.class));
        stopService(new Intent(this, DashboardService.class));
        taskbarController = new TaskbarController(this);
        startMenuController = new StartMenuController(this);
        dashboardController = new DashboardController(this);
        taskbarController.onCreateHost(this);
        startMenuController.onCreateHost(this);
        dashboardController.onCreateHost(this);
    } else {
        // We always start the Taskbar and Start Menu services, even if the app isn't normally running
        try {
            startService(new Intent(this, TaskbarService.class));
            startService(new Intent(this, StartMenuService.class));
            startService(new Intent(this, DashboardService.class));
        } catch (IllegalStateException ignored) {
        }
    }
    if (pref.getBoolean(PREF_TASKBAR_ACTIVE, false) && !U.isServiceRunning(this, NotificationService.class))
        pref.edit().putBoolean(PREF_TASKBAR_ACTIVE, false).apply();
    // Show the Taskbar temporarily, as nothing else will be visible on screen
    U.newHandler().postDelayed(() -> U.sendBroadcast(this, ACTION_TEMP_SHOW_TASKBAR), 100);
}
Also used : Callbacks(com.farmerbb.taskbar.util.Callbacks) SharedPreferences(android.content.SharedPreferences) StartMenuController(com.farmerbb.taskbar.ui.StartMenuController) DashboardService(com.farmerbb.taskbar.service.DashboardService) DashboardController(com.farmerbb.taskbar.ui.DashboardController) Intent(android.content.Intent) TaskbarService(com.farmerbb.taskbar.service.TaskbarService) StartMenuService(com.farmerbb.taskbar.service.StartMenuService) TaskbarController(com.farmerbb.taskbar.ui.TaskbarController)

Example 2 with Callbacks

use of com.farmerbb.taskbar.util.Callbacks in project Taskbar by farmerbb.

the class DummyActivity method onResume.

@SuppressLint("RestrictedApi")
@TargetApi(Build.VERSION_CODES.N)
@Override
protected void onResume() {
    super.onResume();
    if (shouldFinish)
        finish();
    else {
        shouldFinish = true;
        if (getIntent().hasExtra("uninstall")) {
            UserManager userManager = (UserManager) getSystemService(USER_SERVICE);
            Intent intent = new Intent(Intent.ACTION_DELETE, Uri.parse("package:" + getIntent().getStringExtra("uninstall")));
            intent.putExtra(Intent.EXTRA_USER, userManager.getUserForSerialNumber(getIntent().getLongExtra("user_id", 0)));
            try {
                startActivity(intent);
            } catch (ActivityNotFoundException ignored) {
            }
        } else if (getIntent().hasExtra("accessibility")) {
            AlertDialog.Builder builder = new AlertDialog.Builder(U.wrapContext(this));
            builder.setTitle(R.string.tb_permission_dialog_title).setMessage(R.string.tb_enable_accessibility).setNegativeButton(R.string.tb_action_cancel, (dialog, which) -> U.newHandler().post(this::finish)).setPositiveButton(R.string.tb_action_activate, (dialog, which) -> {
                Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
                SharedPreferences pref = U.getSharedPreferences(this);
                if (pref.getBoolean(PREF_DISABLE_ANIMATIONS, false))
                    intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                U.launchApp(this, () -> {
                    try {
                        startActivity(intent, U.getActivityOptionsBundle(this, ApplicationType.APP_PORTRAIT, null));
                        U.showToast(this, getString(R.string.tb_usage_stats_message, U.getAppName(this)), Toast.LENGTH_LONG);
                    } catch (ActivityNotFoundException e) {
                        U.showToast(this, R.string.tb_lock_device_not_supported);
                        finish();
                    }
                });
            });
            AlertDialog dialog = builder.create();
            dialog.show();
            dialog.setCancelable(false);
        } else if (getIntent().hasExtra(EXTRA_START_FREEFORM_HACK)) {
            if (U.hasFreeformSupport(this) && U.isFreeformModeEnabled(this) && !FreeformHackHelper.getInstance().isFreeformHackActive()) {
                U.startFreeformHack(this, true);
            }
            finish();
        } else if (getIntent().hasExtra(EXTRA_SHOW_PERMISSION_DIALOG))
            U.showPermissionDialog(U.wrapContext(this), new Callbacks(null, this::finish));
        else if (getIntent().hasExtra(EXTRA_SHOW_RECENT_APPS_DIALOG))
            U.showRecentAppsDialog(U.wrapContext(this), new Callbacks(null, this::finish));
        else if (!finishOnPause)
            finish();
    }
}
Also used : AlertDialog(android.app.AlertDialog) UserManager(android.os.UserManager) Bundle(android.os.Bundle) ApplicationType(com.farmerbb.taskbar.util.ApplicationType) R(com.farmerbb.taskbar.R) Uri(android.net.Uri) U(com.farmerbb.taskbar.util.U) Intent(android.content.Intent) AlertDialog(android.app.AlertDialog) Callbacks(com.farmerbb.taskbar.util.Callbacks) FreeformHackHelper(com.farmerbb.taskbar.helper.FreeformHackHelper) SuppressLint(android.annotation.SuppressLint) SharedPreferences(android.content.SharedPreferences) ActivityNotFoundException(android.content.ActivityNotFoundException) Toast(android.widget.Toast) View(android.view.View) Settings(android.provider.Settings) Build(android.os.Build) Activity(android.app.Activity) TargetApi(android.annotation.TargetApi) Constants(com.farmerbb.taskbar.util.Constants) Callbacks(com.farmerbb.taskbar.util.Callbacks) ActivityNotFoundException(android.content.ActivityNotFoundException) SharedPreferences(android.content.SharedPreferences) UserManager(android.os.UserManager) Intent(android.content.Intent) SuppressLint(android.annotation.SuppressLint) TargetApi(android.annotation.TargetApi)

Aggregations

Intent (android.content.Intent)2 SharedPreferences (android.content.SharedPreferences)2 Callbacks (com.farmerbb.taskbar.util.Callbacks)2 SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 Activity (android.app.Activity)1 AlertDialog (android.app.AlertDialog)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Uri (android.net.Uri)1 Build (android.os.Build)1 Bundle (android.os.Bundle)1 UserManager (android.os.UserManager)1 Settings (android.provider.Settings)1 View (android.view.View)1 Toast (android.widget.Toast)1 R (com.farmerbb.taskbar.R)1 FreeformHackHelper (com.farmerbb.taskbar.helper.FreeformHackHelper)1 DashboardService (com.farmerbb.taskbar.service.DashboardService)1 StartMenuService (com.farmerbb.taskbar.service.StartMenuService)1 TaskbarService (com.farmerbb.taskbar.service.TaskbarService)1