import android.widget.FrameLayout;
import com.farmerbb.taskbar.R;
+import com.farmerbb.taskbar.service.DashboardService;
import com.farmerbb.taskbar.service.NotificationService;
+import com.farmerbb.taskbar.service.StartMenuService;
+import com.farmerbb.taskbar.service.TaskbarService;
import com.farmerbb.taskbar.ui.DashboardController;
import com.farmerbb.taskbar.ui.Host;
import com.farmerbb.taskbar.ui.ViewParams;
}
};
+ private BroadcastReceiver restartReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if(taskbarChild != null) taskbarChild.onRecreateHost(HomeActivityDelegate.this);
+ if(startMenuChild != null) startMenuChild.onRecreateHost(HomeActivityDelegate.this);
+ if(dashboardChild != null) dashboardChild.onRecreateHost(HomeActivityDelegate.this);
+ }
+ };
+
private BroadcastReceiver freeformToggleReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
lbm.registerReceiver(killReceiver, new IntentFilter("com.farmerbb.taskbar.KILL_HOME_ACTIVITY"));
lbm.registerReceiver(forceTaskbarStartReceiver, new IntentFilter("com.farmerbb.taskbar.FORCE_TASKBAR_RESTART"));
+ lbm.registerReceiver(restartReceiver, new IntentFilter("com.farmerbb.taskbar.RESTART"));
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("com.farmerbb.taskbar.UPDATE_FREEFORM_CHECKBOX");
protected void onResume() {
super.onResume();
- if(bootToFreeform()) {
+ if(U.canBootToFreeform(this)) {
if(U.launcherIsDefault(this))
startFreeformHack();
else {
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));
- if(U.canDrawOverlays(this)) {
- if(!bootToFreeform()) {
+ if(U.canDrawOverlays(this, true)) {
+ if(!U.canBootToFreeform(this)) {
final LauncherHelper helper = LauncherHelper.getInstance();
helper.setOnHomeScreen(true);
null);
}
- private boolean bootToFreeform() {
- SharedPreferences pref = U.getSharedPreferences(this);
- return U.hasFreeformSupport(this)
- && pref.getBoolean("freeform_hack", false)
- && !U.isOverridingFreeformHack(this);
- }
-
private void startTaskbar() {
SharedPreferences pref = U.getSharedPreferences(this);
if(pref.getBoolean("first_run", true)) {
null);
}
- // We always start the Taskbar and Start Menu services, even if the app isn't normally running
+ // 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));
+
taskbarChild = new TaskbarController(this);
startMenuChild = new StartMenuController(this);
dashboardChild = new DashboardController(this);
super.onStop();
SharedPreferences pref = U.getSharedPreferences(this);
- if(!bootToFreeform()) {
+ if(!U.canBootToFreeform(this)) {
LauncherHelper.getInstance().setOnHomeScreen(false);
if(U.shouldCollapse(this, true))
else
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));
- // Stop the Taskbar and Start Menu services if they should normally not be active
- if(!pref.getBoolean("taskbar_active", false) || pref.getBoolean("is_hidden", false)) {
- taskbarChild.onDestroyHost(this);
- startMenuChild.onDestroyHost(this);
- dashboardChild.onDestroyHost(this);
+ if(taskbarChild != null) taskbarChild.onDestroyHost(this);
+ if(startMenuChild != null) startMenuChild.onDestroyHost(this);
+ if(dashboardChild != null) dashboardChild.onDestroyHost(this);
+
+ IconCache.getInstance(this).clearCache();
- IconCache.getInstance(this).clearCache();
+ // Stop using HomeActivityDelegate as UI host and restart services if needed
+ if(pref.getBoolean("taskbar_active", false)
+ && !pref.getBoolean("is_hidden", false)) {
+ startService(new Intent(this, TaskbarService.class));
+ startService(new Intent(this, StartMenuService.class));
+ startService(new Intent(this, DashboardService.class));
}
}
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
lbm.unregisterReceiver(killReceiver);
lbm.unregisterReceiver(forceTaskbarStartReceiver);
+ lbm.unregisterReceiver(restartReceiver);
lbm.unregisterReceiver(freeformToggleReceiver);
}
private void killHomeActivity() {
LauncherHelper.getInstance().setOnHomeScreen(false);
- // Stop the Taskbar and Start Menu services if they should normally not be active
- SharedPreferences pref = U.getSharedPreferences(this);
- if(!pref.getBoolean("taskbar_active", false) || pref.getBoolean("is_hidden", false)) {
- taskbarChild.onDestroyHost(this);
- startMenuChild.onDestroyHost(this);
- dashboardChild.onDestroyHost(this);
+ if(taskbarChild != null) taskbarChild.onDestroyHost(this);
+ if(startMenuChild != null) startMenuChild.onDestroyHost(this);
+ if(dashboardChild != null) dashboardChild.onDestroyHost(this);
- IconCache.getInstance(this).clearCache();
+ IconCache.getInstance(this).clearCache();
+
+ U.stopFreeformHack(this);
- U.stopFreeformHack(this);
+ // Stop using HomeActivityDelegate as UI host and restart services if needed
+ SharedPreferences pref = U.getSharedPreferences(this);
+ if(pref.getBoolean("taskbar_active", false)
+ && !pref.getBoolean("is_hidden", false)) {
+ startService(new Intent(this, TaskbarService.class));
+ startService(new Intent(this, StartMenuService.class));
+ startService(new Intent(this, DashboardService.class));
}
finish();
import android.app.AlertDialog;
import android.app.AppOpsManager;
import android.app.Service;
-import android.app.admin.DevicePolicyManager;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import com.farmerbb.taskbar.R;
import com.farmerbb.taskbar.activity.ContextMenuActivity;
import com.farmerbb.taskbar.activity.DummyActivity;
+import com.farmerbb.taskbar.activity.HomeActivityDelegate;
import com.farmerbb.taskbar.activity.InvisibleActivityFreeform;
import com.farmerbb.taskbar.activity.ShortcutActivity;
import com.farmerbb.taskbar.activity.StartTaskbarActivity;
&& Settings.Global.getInt(context.getContentResolver(), "force_resizable_activities", 0) != 0));
}
+ public static boolean canBootToFreeform(Context context) {
+ SharedPreferences pref = getSharedPreferences(context);
+ return hasFreeformSupport(context)
+ && pref.getBoolean("freeform_hack", false)
+ && !isOverridingFreeformHack(context);
+ }
+
public static boolean isSamsungDevice() {
return Build.MANUFACTURER.equalsIgnoreCase("Samsung");
}
- public static boolean isNvidiaDevice() {
+ private static boolean isNvidiaDevice() {
return Build.MANUFACTURER.equalsIgnoreCase("NVIDIA");
}
public static boolean isServiceRunning(Context context, Class<? extends Service> cls) {
+ if(LauncherHelper.getInstance().isOnHomeScreen()
+ && (cls.equals(TaskbarService.class)
+ || cls.equals(StartMenuService.class)
+ || cls.equals(DashboardService.class)))
+ return true;
+
return isServiceRunning(context, cls.getName());
}
return pref.getInt("accent_color", context.getResources().getInteger(R.integer.translucent_white));
}
- @TargetApi(Build.VERSION_CODES.M)
public static boolean canDrawOverlays(Context context) {
- return Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Settings.canDrawOverlays(context);
+ return canDrawOverlays(context, false);
+ }
+
+ @TargetApi(Build.VERSION_CODES.M)
+ public static boolean canDrawOverlays(Context context, boolean forHomeScreen) {
+ return (forHomeScreen && !canBootToFreeform(context))
+ || Build.VERSION.SDK_INT < Build.VERSION_CODES.M
+ || Settings.canDrawOverlays(context);
}
public static boolean isGame(Context context, String packageName) {
stopTaskbarService(context, false);
startTaskbarService(context, false);
}
+
+ LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.RESTART"));
}
public static void restartNotificationService(Context context) {