OSDN Git Service

Abstract logic for setting components enabled / disabled
[android-x86/packages-apps-Taskbar.git] / app / src / main / java / com / farmerbb / taskbar / ui / TaskbarController.java
index 94ebe3a..58a4cdd 100644 (file)
@@ -23,6 +23,7 @@ import android.app.AlarmManager;
 import android.app.usage.UsageEvents;
 import android.app.usage.UsageStats;
 import android.app.usage.UsageStatsManager;
+import android.bluetooth.BluetoothAdapter;
 import android.content.ActivityNotFoundException;
 import android.content.BroadcastReceiver;
 import android.content.Context;
@@ -33,21 +34,35 @@ import android.content.pm.LauncherActivityInfo;
 import android.content.pm.LauncherApps;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
 import android.graphics.Color;
 import android.graphics.Point;
 import android.graphics.Typeface;
+import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
-import android.net.Uri;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
+import android.os.BatteryManager;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.PowerManager;
+import android.os.Process;
 import android.os.SystemClock;
 import android.os.UserHandle;
 import android.os.UserManager;
+import android.provider.Settings;
 import android.speech.RecognizerIntent;
-import android.support.v4.content.ContextCompat;
-import android.support.v4.graphics.ColorUtils;
+import androidx.core.content.ContextCompat;
+import androidx.core.graphics.ColorUtils;
+import android.telephony.PhoneStateListener;
+import android.telephony.SignalStrength;
+import android.telephony.TelephonyManager;
+import android.text.format.DateFormat;
 import android.view.Display;
 import android.view.Gravity;
 import android.view.LayoutInflater;
@@ -61,14 +76,16 @@ import android.widget.Button;
 import android.widget.FrameLayout;
 import android.widget.ImageView;
 
+import java.io.File;
 import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 
-import android.support.v4.content.LocalBroadcastManager;
 import android.widget.LinearLayout;
 import android.widget.Space;
+import android.widget.TextView;
 
 import com.farmerbb.taskbar.BuildConfig;
 import com.farmerbb.taskbar.activity.HomeActivityDelegate;
@@ -76,6 +93,8 @@ import com.farmerbb.taskbar.activity.MainActivity;
 import com.farmerbb.taskbar.R;
 import com.farmerbb.taskbar.activity.HomeActivity;
 import com.farmerbb.taskbar.activity.InvisibleActivityFreeform;
+import com.farmerbb.taskbar.activity.SecondaryHomeActivity;
+import com.farmerbb.taskbar.content.TaskbarIntent;
 import com.farmerbb.taskbar.util.AppEntry;
 import com.farmerbb.taskbar.util.DisplayInfo;
 import com.farmerbb.taskbar.util.FreeformHackHelper;
@@ -96,6 +115,9 @@ public class TaskbarController implements UIController {
     private Space space;
     private FrameLayout dashboardButton;
     private LinearLayout navbarButtons;
+    private LinearLayout sysTrayLayout;
+    private FrameLayout sysTrayParentLayout;
+    private TextView time;
 
     private Handler handler;
     private Handler handler2;
@@ -117,20 +139,21 @@ public class TaskbarController implements UIController {
     private String sortOrder = "false";
     private boolean runningAppsOnly = false;
 
-    private int layoutId = R.layout.taskbar_left;
+    private int layoutId = R.layout.tb_taskbar_left;
     private int currentTaskbarPosition = 0;
     private boolean showHideAutomagically = false;
     private boolean positionIsVertical = false;
     private boolean dashboardEnabled = false;
     private boolean navbarButtonsEnabled = false;
+    private boolean sysTrayEnabled = false;
 
     private List<String> currentTaskbarIds = new ArrayList<>();
     private int numOfPinnedApps = -1;
 
-    private View.OnClickListener ocl = view -> {
-        Intent intent = new Intent("com.farmerbb.taskbar.TOGGLE_START_MENU");
-        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
-    };
+    private int cellStrength = -1;
+
+    private View.OnClickListener ocl = view ->
+            U.sendBroadcast(context, TaskbarIntent.ACTION_TOGGLE_START_MENU);
 
     private BroadcastReceiver showReceiver = new BroadcastReceiver() {
         @Override
@@ -177,6 +200,18 @@ public class TaskbarController implements UIController {
         }
     };
 
+    @TargetApi(Build.VERSION_CODES.M)
+    private PhoneStateListener listener = new PhoneStateListener() {
+        @Override
+        public void onSignalStrengthsChanged(SignalStrength signalStrength) {
+            try {
+                cellStrength = signalStrength.getLevel();
+            } catch (SecurityException e) {
+                cellStrength = -1;
+            }
+        }
+    };
+
     public TaskbarController(Context context) {
         this.context = context;
     }
@@ -186,7 +221,7 @@ public class TaskbarController implements UIController {
     public void onCreateHost(UIHost host) {
         SharedPreferences pref = U.getSharedPreferences(context);
         if(pref.getBoolean("taskbar_active", false) || LauncherHelper.getInstance().isOnHomeScreen()) {
-            if(U.canDrawOverlays(context, host instanceof HomeActivityDelegate))
+            if(U.canDrawOverlays(context))
                 drawTaskbar(host);
             else {
                 pref.edit().putBoolean("taskbar_active", false).apply();
@@ -214,42 +249,42 @@ public class TaskbarController implements UIController {
         // Determine where to show the taskbar on screen
         switch(U.getTaskbarPosition(context)) {
             case "bottom_left":
-                layoutId = R.layout.taskbar_left;
+                layoutId = R.layout.tb_taskbar_left;
                 params.gravity = Gravity.BOTTOM | Gravity.LEFT;
                 positionIsVertical = false;
                 break;
             case "bottom_vertical_left":
-                layoutId = R.layout.taskbar_vertical;
+                layoutId = R.layout.tb_taskbar_vertical;
                 params.gravity = Gravity.BOTTOM | Gravity.LEFT;
                 positionIsVertical = true;
                 break;
             case "bottom_right":
-                layoutId = R.layout.taskbar_right;
+                layoutId = R.layout.tb_taskbar_right;
                 params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
                 positionIsVertical = false;
                 break;
             case "bottom_vertical_right":
-                layoutId = R.layout.taskbar_vertical;
+                layoutId = R.layout.tb_taskbar_vertical;
                 params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
                 positionIsVertical = true;
                 break;
             case "top_left":
-                layoutId = R.layout.taskbar_left;
+                layoutId = R.layout.tb_taskbar_left;
                 params.gravity = Gravity.TOP | Gravity.LEFT;
                 positionIsVertical = false;
                 break;
             case "top_vertical_left":
-                layoutId = R.layout.taskbar_top_vertical;
+                layoutId = R.layout.tb_taskbar_top_vertical;
                 params.gravity = Gravity.TOP | Gravity.LEFT;
                 positionIsVertical = true;
                 break;
             case "top_right":
-                layoutId = R.layout.taskbar_right;
+                layoutId = R.layout.tb_taskbar_right;
                 params.gravity = Gravity.TOP | Gravity.RIGHT;
                 positionIsVertical = false;
                 break;
             case "top_vertical_right":
-                layoutId = R.layout.taskbar_top_vertical;
+                layoutId = R.layout.tb_taskbar_top_vertical;
                 params.gravity = Gravity.TOP | Gravity.RIGHT;
                 positionIsVertical = true;
                 break;
@@ -277,35 +312,50 @@ public class TaskbarController implements UIController {
         space.setOnClickListener(v -> toggleTaskbar(true));
 
         startButton = layout.findViewById(R.id.start_button);
-        int padding;
+        int padding = 0;
 
-        if(pref.getBoolean("app_drawer_icon", false)) {
-            Drawable drawable;
+        switch(pref.getString("start_button_image", U.getDefaultStartButtonImage(context))) {
+            case "default":
+                startButton.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.tb_all_apps_button_icon));
+                padding = context.getResources().getDimensionPixelSize(R.dimen.tb_app_drawer_icon_padding);
+                break;
+            case "app_logo":
+                Drawable drawable;
 
-            if(U.isBlissOs(context)) {
-                drawable = ContextCompat.getDrawable(context, R.drawable.bliss);
-                drawable.setTint(accentColor);
-            } else
-                drawable = ContextCompat.getDrawable(context, R.mipmap.ic_launcher);
+                if(U.isBlissOs(context)) {
+                    drawable = ContextCompat.getDrawable(context, R.drawable.tb_bliss);
+                    drawable.setTint(accentColor);
+                } else {
+                    LauncherApps launcherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);
+                    LauncherActivityInfo info = launcherApps.getActivityList(context.getPackageName(), Process.myUserHandle()).get(0);
+                    drawable = IconCache.getInstance(context).getIcon(context, context.getPackageManager(), info);
+                }
 
-            startButton.setImageDrawable(drawable);
-            padding = context.getResources().getDimensionPixelSize(R.dimen.app_drawer_icon_padding_alt);
-        } else {
-            startButton.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.all_apps_button_icon));
-            padding = context.getResources().getDimensionPixelSize(R.dimen.app_drawer_icon_padding);
-        }
+                startButton.setImageDrawable(drawable);
+                padding = context.getResources().getDimensionPixelSize(R.dimen.tb_app_drawer_icon_padding_alt);
+                break;
+            case "custom":
+                File file = new File(context.getFilesDir() + "/tb_images", "custom_image");
+                if(file.exists()) {
+                    Handler handler = new Handler();
+                    new Thread(() -> {
+                        Bitmap bitmap = BitmapFactory.decodeFile(file.getPath());
+                        handler.post(() -> {
+                            if(bitmap != null) {
+                                BitmapDrawable bitmapDrawable = new BitmapDrawable(context.getResources(), bitmap);
+                                bitmapDrawable.setFilterBitmap(bitmap.getWidth() * bitmap.getHeight() > 2000);
+                                startButton.setImageDrawable(bitmapDrawable);
+                            } else {
+                                U.showToastLong(context, R.string.tb_error_reading_custom_start_image);
+                                startButton.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.tb_all_apps_button_icon));
+                            }
+                        });
+                    }).start();
+                } else
+                    startButton.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.tb_all_apps_button_icon));
 
-        if(pref.getBoolean("app_drawer_icon_custom", true)) {
-            String strPath = "";
-            if (pref.getString("app_drawer_icon_image", "DEFAULT").isEmpty() == false) {
-                try {
-                    strPath = pref.getString("app_drawer_icon_image", "DEFAULT");
-                    startButton.setImageURI(Uri.parse(strPath));
-                    padding = context.getResources().getDimensionPixelSize(R.dimen.app_drawer_icon_padding);
-                } catch (Exception e) {
-                    U.showErrorDialog(this.context, this.context.getResources().getString(R.string.error_reading_custom_start_image));
-                }
-            }
+                padding = context.getResources().getDimensionPixelSize(R.dimen.tb_app_drawer_icon_padding);
+                break;
         }
 
         startButton.setPadding(padding, padding, padding, padding);
@@ -323,7 +373,7 @@ public class TaskbarController implements UIController {
             return false;
         });
 
-        refreshInterval = (int) (Float.parseFloat(pref.getString("refresh_frequency", "2")) * 1000);
+        refreshInterval = (int) (Float.parseFloat(pref.getString("refresh_frequency", "1")) * 1000);
         if(refreshInterval == 0)
             refreshInterval = 100;
 
@@ -345,8 +395,8 @@ public class TaskbarController implements UIController {
                 break;
         }
 
-        Intent intent = new Intent("com.farmerbb.taskbar.HIDE_START_MENU");
-        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
+        U.sendBroadcast(context, TaskbarIntent.ACTION_HIDE_START_MENU);
+        U.sendBroadcast(context, TaskbarIntent.ACTION_UPDATE_HOME_SCREEN_MARGINS);
 
         if(altButtonConfig) {
             button = layout.findViewById(R.id.hide_taskbar_button_alt);
@@ -376,7 +426,7 @@ public class TaskbarController implements UIController {
         dashboardButton = layout.findViewById(R.id.dashboard_button);
         navbarButtons = layout.findViewById(R.id.navbar_buttons);
 
-        dashboardEnabled = pref.getBoolean("dashboard", false);
+        dashboardEnabled = pref.getBoolean("dashboard", context.getResources().getBoolean(R.bool.tb_def_dashboard));
         if(dashboardEnabled) {
             layout.findViewById(R.id.square1).setBackgroundColor(accentColor);
             layout.findViewById(R.id.square2).setBackgroundColor(accentColor);
@@ -385,7 +435,8 @@ public class TaskbarController implements UIController {
             layout.findViewById(R.id.square5).setBackgroundColor(accentColor);
             layout.findViewById(R.id.square6).setBackgroundColor(accentColor);
 
-            dashboardButton.setOnClickListener(v -> LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.TOGGLE_DASHBOARD")));
+            dashboardButton.setOnClickListener(v ->
+                    U.sendBroadcast(context, TaskbarIntent.ACTION_TOGGLE_DASHBOARD));
         } else
             dashboardButton.setVisibility(View.GONE);
 
@@ -503,6 +554,63 @@ public class TaskbarController implements UIController {
         if(!navbarButtonsEnabled)
             navbarButtons.setVisibility(View.GONE);
 
+        sysTrayEnabled = U.isSystemTrayEnabled(context);
+
+        if(sysTrayEnabled) {
+            sysTrayLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.tb_system_tray, null);
+
+            FrameLayout.LayoutParams sysTrayParams = new FrameLayout.LayoutParams(
+                    FrameLayout.LayoutParams.WRAP_CONTENT,
+                    context.getResources().getDimensionPixelSize(R.dimen.tb_icon_size)
+            );
+
+            if(layoutId == R.layout.tb_taskbar_right) {
+                time = sysTrayLayout.findViewById(R.id.time_left);
+                sysTrayParams.gravity = Gravity.START;
+            } else {
+                time = sysTrayLayout.findViewById(R.id.time_right);
+                sysTrayParams.gravity = Gravity.END;
+            }
+
+            time.setVisibility(View.VISIBLE);
+            sysTrayLayout.setLayoutParams(sysTrayParams);
+
+            if(!U.isLibrary(context)) {
+                sysTrayLayout.setOnClickListener(v -> {
+                    U.sendAccessibilityAction(context, AccessibilityService.GLOBAL_ACTION_NOTIFICATIONS);
+                    if(U.shouldCollapse(context, false))
+                        hideTaskbar(true);
+                });
+
+                if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+                    sysTrayLayout.setOnLongClickListener(v -> {
+                        U.sendAccessibilityAction(context, AccessibilityService.GLOBAL_ACTION_QUICK_SETTINGS);
+                        if(U.shouldCollapse(context, false))
+                            hideTaskbar(true);
+
+                        return true;
+                    });
+
+                    sysTrayLayout.setOnGenericMotionListener((view, motionEvent) -> {
+                        if(motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS
+                                && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
+                            U.sendAccessibilityAction(context, AccessibilityService.GLOBAL_ACTION_QUICK_SETTINGS);
+                            if (U.shouldCollapse(context, false))
+                                hideTaskbar(true);
+                        }
+                        return true;
+                    });
+                }
+            }
+
+            sysTrayParentLayout = layout.findViewById(R.id.add_systray_here);
+            sysTrayParentLayout.setVisibility(View.VISIBLE);
+            sysTrayParentLayout.addView(sysTrayLayout);
+
+            TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+            manager.listen(listener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
+        }
+
         layout.setBackgroundColor(backgroundTint);
         layout.findViewById(R.id.divider).setBackgroundColor(accentColor);
         button.setTextColor(accentColor);
@@ -515,27 +623,18 @@ public class TaskbarController implements UIController {
         if(pref.getBoolean("auto_hide_navbar", false))
             U.showHideNavigationBar(context, false);
 
-        LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
-
         if(FreeformHackHelper.getInstance().isTouchAbsorberActive()) {
-            lbm.sendBroadcast(new Intent("com.farmerbb.taskbar.FINISH_FREEFORM_ACTIVITY"));
+            U.sendBroadcast(context, TaskbarIntent.ACTION_FINISH_FREEFORM_ACTIVITY);
 
             new Handler().postDelayed(() -> U.startTouchAbsorberActivity(context), 500);
         }
 
-        lbm.unregisterReceiver(showReceiver);
-        lbm.unregisterReceiver(hideReceiver);
-        lbm.unregisterReceiver(tempShowReceiver);
-        lbm.unregisterReceiver(tempHideReceiver);
-        lbm.unregisterReceiver(startMenuAppearReceiver);
-        lbm.unregisterReceiver(startMenuDisappearReceiver);
-
-        lbm.registerReceiver(showReceiver, new IntentFilter("com.farmerbb.taskbar.SHOW_TASKBAR"));
-        lbm.registerReceiver(hideReceiver, new IntentFilter("com.farmerbb.taskbar.HIDE_TASKBAR"));
-        lbm.registerReceiver(tempShowReceiver, new IntentFilter("com.farmerbb.taskbar.TEMP_SHOW_TASKBAR"));
-        lbm.registerReceiver(tempHideReceiver, new IntentFilter("com.farmerbb.taskbar.TEMP_HIDE_TASKBAR"));
-        lbm.registerReceiver(startMenuAppearReceiver, new IntentFilter("com.farmerbb.taskbar.START_MENU_APPEARING"));
-        lbm.registerReceiver(startMenuDisappearReceiver, new IntentFilter("com.farmerbb.taskbar.START_MENU_DISAPPEARING"));
+        U.registerReceiver(context, showReceiver, TaskbarIntent.ACTION_SHOW_TASKBAR);
+        U.registerReceiver(context, hideReceiver, TaskbarIntent.ACTION_HIDE_TASKBAR);
+        U.registerReceiver(context, tempShowReceiver, TaskbarIntent.ACTION_TEMP_SHOW_TASKBAR);
+        U.registerReceiver(context, tempHideReceiver, TaskbarIntent.ACTION_TEMP_HIDE_TASKBAR);
+        U.registerReceiver(context, startMenuAppearReceiver, TaskbarIntent.ACTION_START_MENU_APPEARING);
+        U.registerReceiver(context, startMenuDisappearReceiver, TaskbarIntent.ACTION_START_MENU_DISAPPEARING);
 
         startRefreshingRecents();
 
@@ -555,6 +654,7 @@ public class TaskbarController implements UIController {
 
         handler = new Handler();
         thread = new Thread(() -> {
+            updateSystemTray();
             updateRecentApps(true);
 
             if(!isRefreshingRecents) {
@@ -562,6 +662,7 @@ public class TaskbarController implements UIController {
 
                 while(shouldRefreshRecents) {
                     SystemClock.sleep(refreshInterval);
+                    updateSystemTray();
                     updateRecentApps(false);
 
                     if(showHideAutomagically && !positionIsVertical && !MenuHelper.getInstance().isStartMenuOpen())
@@ -604,7 +705,7 @@ public class TaskbarController implements UIController {
         List<LauncherActivityInfo> launcherAppCache = new ArrayList<>();
         int maxNumOfEntries = U.getMaxNumOfEntries(context);
         int realNumOfPinnedApps = 0;
-        boolean fullLength = pref.getBoolean("full_length", false);
+        boolean fullLength = pref.getBoolean("full_length", context.getResources().getBoolean(R.bool.tb_def_full_length));
 
         PinnedBlockedApps pba = PinnedBlockedApps.getInstance(context);
         List<AppEntry> pinnedApps = pba.getPinnedApps();
@@ -696,6 +797,8 @@ public class TaskbarController implements UIController {
                             if(!(eventCache.getPackageName().contains(BuildConfig.BASE_APPLICATION_ID)
                                     && !eventCache.getClassName().equals(MainActivity.class.getCanonicalName())
                                     && !eventCache.getClassName().equals(HomeActivity.class.getCanonicalName())
+                                    && !eventCache.getClassName().equals(HomeActivityDelegate.class.getCanonicalName())
+                                    && !eventCache.getClassName().equals(SecondaryHomeActivity.class.getCanonicalName())
                                     && !eventCache.getClassName().equals(InvisibleActivityFreeform.class.getCanonicalName())))
                                 currentForegroundApp = eventCache.getPackageName();
                         }
@@ -850,38 +953,72 @@ public class TaskbarController implements UIController {
                 handler.post(() -> {
                     if(numOfEntries > 0 || fullLength) {
                         ViewGroup.LayoutParams params = scrollView.getLayoutParams();
-                        DisplayInfo display = U.getDisplayInfo(context);
-                        int recentsSize = context.getResources().getDimensionPixelSize(R.dimen.icon_size) * numOfEntries;
+                        DisplayInfo display = U.getDisplayInfo(context, true);
+                        int recentsSize = context.getResources().getDimensionPixelSize(R.dimen.tb_icon_size) * numOfEntries;
                         float maxRecentsSize = fullLength ? Float.MAX_VALUE : recentsSize;
 
                         if(U.getTaskbarPosition(context).contains("vertical")) {
-                            int maxScreenSize = display.height
+                            int maxScreenSize = Math.max(0, display.height
                                     - U.getStatusBarHeight(context)
-                                    - U.getBaseTaskbarSize(context);
+                                    - U.getBaseTaskbarSize(context));
 
                             params.height = (int) Math.min(maxRecentsSize, maxScreenSize)
-                                    + context.getResources().getDimensionPixelSize(R.dimen.divider_size);
+                                    + context.getResources().getDimensionPixelSize(R.dimen.tb_divider_size);
 
-                            if(fullLength && U.getTaskbarPosition(context).contains("bottom")) {
+                            if(fullLength) {
                                 try {
-                                    Space whitespace = layout.findViewById(R.id.whitespace);
-                                    ViewGroup.LayoutParams params2 = whitespace.getLayoutParams();
-                                    params2.height = maxScreenSize - recentsSize;
-                                    whitespace.setLayoutParams(params2);
+                                    Space whitespaceTop = layout.findViewById(R.id.whitespace_top);
+                                    Space whitespaceBottom = layout.findViewById(R.id.whitespace_bottom);
+                                    int height = maxScreenSize - recentsSize;
+
+                                    if(pref.getBoolean("centered_icons", false)) {
+                                        ViewGroup.LayoutParams topParams = whitespaceTop.getLayoutParams();
+                                        topParams.height = height / 2;
+                                        whitespaceTop.setLayoutParams(topParams);
+
+                                        ViewGroup.LayoutParams bottomParams = whitespaceBottom.getLayoutParams();
+                                        bottomParams.height = height / 2;
+                                        whitespaceBottom.setLayoutParams(bottomParams);
+                                    } else if(U.getTaskbarPosition(context).contains("bottom")) {
+                                        ViewGroup.LayoutParams topParams = whitespaceTop.getLayoutParams();
+                                        topParams.height = height;
+                                        whitespaceTop.setLayoutParams(topParams);
+                                    } else {
+                                        ViewGroup.LayoutParams bottomParams = whitespaceBottom.getLayoutParams();
+                                        bottomParams.height = height;
+                                        whitespaceBottom.setLayoutParams(bottomParams);
+                                    }
                                 } catch (NullPointerException e) { /* Gracefully fail */ }
                             }
                         } else {
-                            int maxScreenSize = display.width - U.getBaseTaskbarSize(context);
+                            int maxScreenSize = Math.max(0, display.width - U.getBaseTaskbarSize(context));
 
                             params.width = (int) Math.min(maxRecentsSize, maxScreenSize)
-                                    + context.getResources().getDimensionPixelSize(R.dimen.divider_size);
+                                    + context.getResources().getDimensionPixelSize(R.dimen.tb_divider_size);
 
-                            if(fullLength && U.getTaskbarPosition(context).contains("right")) {
+                            if(fullLength) {
                                 try {
-                                    Space whitespace = layout.findViewById(R.id.whitespace);
-                                    ViewGroup.LayoutParams params2 = whitespace.getLayoutParams();
-                                    params2.width = maxScreenSize - recentsSize;
-                                    whitespace.setLayoutParams(params2);
+                                    Space whitespaceLeft = layout.findViewById(R.id.whitespace_left);
+                                    Space whitespaceRight = layout.findViewById(R.id.whitespace_right);
+                                    int width = maxScreenSize - recentsSize;
+
+                                    if(pref.getBoolean("centered_icons", false)) {
+                                        ViewGroup.LayoutParams leftParams = whitespaceLeft.getLayoutParams();
+                                        leftParams.width = width / 2;
+                                        whitespaceLeft.setLayoutParams(leftParams);
+
+                                        ViewGroup.LayoutParams rightParams = whitespaceRight.getLayoutParams();
+                                        rightParams.width = width / 2;
+                                        whitespaceRight.setLayoutParams(rightParams);
+                                    } else if(U.getTaskbarPosition(context).contains("right")) {
+                                        ViewGroup.LayoutParams leftParams = whitespaceLeft.getLayoutParams();
+                                        leftParams.width = width;
+                                        whitespaceLeft.setLayoutParams(leftParams);
+                                    } else {
+                                        ViewGroup.LayoutParams rightParams = whitespaceRight.getLayoutParams();
+                                        rightParams.width = width;
+                                        whitespaceRight.setLayoutParams(rightParams);
+                                    }
                                 } catch (NullPointerException e) { /* Gracefully fail */ }
                             }
                         }
@@ -893,6 +1030,9 @@ public class TaskbarController implements UIController {
                             taskbar.addView(getView(entries, i));
                         }
 
+                        if(runningAppsOnly)
+                            updateRunningAppIndicators(pinnedApps, usageStatsList, entries);
+
                         isShowingRecents = true;
                         if(shouldRefreshRecents && scrollView.getVisibility() != View.VISIBLE) {
                             if(firstRefresh)
@@ -933,7 +1073,8 @@ public class TaskbarController implements UIController {
                         scrollView.setVisibility(View.GONE);
                     }
                 });
-            }
+            } else if(runningAppsOnly)
+                handler.post(() -> updateRunningAppIndicators(pinnedApps, usageStatsList, entries));
         } else if(firstRefresh || currentTaskbarIds.size() > 0) {
             currentTaskbarIds.clear();
             handler.post(() -> {
@@ -943,11 +1084,38 @@ public class TaskbarController implements UIController {
         }
     }
 
+    private void updateRunningAppIndicators(List<AppEntry> pinnedApps, List<AppEntry> usageStatsList, List<AppEntry> entries) {
+        if(taskbar.getChildCount() != entries.size())
+            return;
+
+        List<String> pinnedPackageList = new ArrayList<>();
+        List<String> runningPackageList = new ArrayList<>();
+
+        for(AppEntry entry : pinnedApps)
+            pinnedPackageList.add(entry.getPackageName());
+
+        for(AppEntry entry : usageStatsList)
+            runningPackageList.add(entry.getPackageName());
+
+        for(int i = 0; i < taskbar.getChildCount(); i++) {
+            View convertView = taskbar.getChildAt(i);
+            String packageName = entries.get(i).getPackageName();
+
+            ImageView runningAppIndicator = convertView.findViewById(R.id.running_app_indicator);
+            if(pinnedPackageList.contains(packageName) && !runningPackageList.contains(packageName))
+                runningAppIndicator.setVisibility(View.GONE);
+            else {
+                runningAppIndicator.setVisibility(View.VISIBLE);
+                runningAppIndicator.setColorFilter(U.getAccentColor(context));
+            }
+        }
+    }
+
     private void toggleTaskbar(boolean userInitiated) {
         if(userInitiated && Build.BRAND.equalsIgnoreCase("essential")) {
             SharedPreferences pref = U.getSharedPreferences(context);
             if(!pref.getBoolean("grip_rejection_toast_shown", false)) {
-                U.showToastLong(context, R.string.essential_phone_grip_rejection);
+                U.showToastLong(context, R.string.tb_essential_phone_grip_rejection);
                 pref.edit().putBoolean("grip_rejection_toast_shown", true).apply();
             }
         }
@@ -977,6 +1145,9 @@ public class TaskbarController implements UIController {
             if(isShowingRecents && scrollView.getVisibility() == View.GONE)
                 scrollView.setVisibility(View.INVISIBLE);
 
+            if(sysTrayEnabled)
+                sysTrayParentLayout.setVisibility(View.VISIBLE);
+
             shouldRefreshRecents = true;
             startRefreshingRecents();
 
@@ -985,7 +1156,8 @@ public class TaskbarController implements UIController {
 
             updateButton(false);
 
-            new Handler().post(() -> LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.SHOW_START_MENU_SPACE")));
+            new Handler().post(() ->
+                    U.sendBroadcast(context, TaskbarIntent.ACTION_SHOW_START_MENU_SPACE));
         }
     }
 
@@ -1005,9 +1177,11 @@ public class TaskbarController implements UIController {
             if(navbarButtonsEnabled)
                 navbarButtons.setVisibility(View.GONE);
 
-            if(isShowingRecents) {
+            if(isShowingRecents)
                 scrollView.setVisibility(View.GONE);
-            }
+
+            if(sysTrayEnabled)
+                sysTrayParentLayout.setVisibility(View.GONE);
 
             shouldRefreshRecents = false;
             if(thread != null) thread.interrupt();
@@ -1017,10 +1191,13 @@ public class TaskbarController implements UIController {
 
             updateButton(true);
 
-            LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));
-            LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_DASHBOARD"));
+            if(clearVariables) {
+                U.sendBroadcast(context, TaskbarIntent.ACTION_HIDE_START_MENU);
+                U.sendBroadcast(context, TaskbarIntent.ACTION_HIDE_DASHBOARD);
+            }
 
-            new Handler().post(() -> LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU_SPACE")));
+            new Handler().post(() ->
+                    U.sendBroadcast(context, TaskbarIntent.ACTION_HIDE_START_MENU_SPACE));
         }
     }
 
@@ -1121,14 +1298,17 @@ public class TaskbarController implements UIController {
         } else if(pref.getBoolean("auto_hide_navbar", false))
             U.showHideNavigationBar(context, true);
 
-        LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
+        U.unregisterReceiver(context, showReceiver);
+        U.unregisterReceiver(context, hideReceiver);
+        U.unregisterReceiver(context, tempShowReceiver);
+        U.unregisterReceiver(context, tempHideReceiver);
+        U.unregisterReceiver(context, startMenuAppearReceiver);
+        U.unregisterReceiver(context, startMenuDisappearReceiver);
 
-        lbm.unregisterReceiver(showReceiver);
-        lbm.unregisterReceiver(hideReceiver);
-        lbm.unregisterReceiver(tempShowReceiver);
-        lbm.unregisterReceiver(tempHideReceiver);
-        lbm.unregisterReceiver(startMenuAppearReceiver);
-        lbm.unregisterReceiver(startMenuDisappearReceiver);
+        if(sysTrayEnabled) {
+            TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+            manager.listen(listener, PhoneStateListener.LISTEN_NONE);
+        }
 
         isFirstStart = true;
     }
@@ -1149,7 +1329,7 @@ public class TaskbarController implements UIController {
         SharedPreferences pref = U.getSharedPreferences(context);
         boolean hide = pref.getBoolean("invisible_button", false);
 
-        if(button != null) button.setText(context.getString(isCollapsed ? R.string.right_arrow : R.string.left_arrow));
+        if(button != null) button.setText(context.getString(isCollapsed ? R.string.tb_right_arrow : R.string.tb_left_arrow));
         if(layout != null) layout.setAlpha(isCollapsed && hide ? 0 : 1);
     }
 
@@ -1163,7 +1343,7 @@ public class TaskbarController implements UIController {
 
             currentTaskbarPosition = 0;
 
-            if(U.canDrawOverlays(context, host instanceof HomeActivityDelegate))
+            if(U.canDrawOverlays(context))
                 drawTaskbar(host);
             else {
                 SharedPreferences pref = U.getSharedPreferences(context);
@@ -1175,7 +1355,7 @@ public class TaskbarController implements UIController {
     }
 
     private View getView(List<AppEntry> list, int position) {
-        View convertView = View.inflate(context, R.layout.icon, null);
+        View convertView = View.inflate(context, R.layout.tb_icon, null);
 
         final AppEntry entry = list.get(position);
         final SharedPreferences pref = U.getSharedPreferences(context);
@@ -1183,7 +1363,7 @@ public class TaskbarController implements UIController {
         ImageView imageView = convertView.findViewById(R.id.icon);
         ImageView imageView2 = convertView.findViewById(R.id.shortcut_icon);
         imageView.setImageDrawable(entry.getIcon(context));
-        imageView2.setBackgroundColor(pref.getInt("accent_color", context.getResources().getInteger(R.integer.translucent_white)));
+        imageView2.setBackgroundColor(U.getAccentColor(context));
 
         String taskbarPosition = U.getTaskbarPosition(context);
         if(pref.getBoolean("shortcut_icon", true)) {
@@ -1204,12 +1384,11 @@ public class TaskbarController implements UIController {
         FrameLayout layout = convertView.findViewById(R.id.entry);
         layout.setOnClickListener(view -> U.launchApp(
                 context,
-                entry.getPackageName(),
-                entry.getComponentName(),
-                entry.getUserId(context),
+                entry,
                 null,
                 true,
-                false
+                false,
+                view
         ));
 
         layout.setOnLongClickListener(view -> {
@@ -1258,24 +1437,12 @@ public class TaskbarController implements UIController {
             });
         }
 
-        if(runningAppsOnly) {
-            ImageView runningAppIndicator = convertView.findViewById(R.id.running_app_indicator);
-            if(entry.getLastTimeUsed() > 0) {
-                runningAppIndicator.setVisibility(View.VISIBLE);
-                runningAppIndicator.setColorFilter(U.getAccentColor(context));
-            } else
-                runningAppIndicator.setVisibility(View.GONE);
-        }
-
         return convertView;
     }
 
     private void openContextMenu(AppEntry entry, int[] location) {
         Bundle args = new Bundle();
-        args.putString("package_name", entry.getPackageName());
-        args.putString("app_name", entry.getLabel());
-        args.putString("component_name", entry.getComponentName());
-        args.putLong("user_id", entry.getUserId(context));
+        args.putSerializable("app_entry", entry);
         args.putInt("x", location[0]);
         args.putInt("y", location[1]);
 
@@ -1362,4 +1529,135 @@ public class TaskbarController implements UIController {
         PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
         return !pm.isInteractive();
     }
+
+    private void updateSystemTray() {
+        if(!sysTrayEnabled || isScreenOff()) return;
+
+        handler.post(() -> {
+            ImageView battery = sysTrayLayout.findViewById(R.id.battery);
+            battery.setImageDrawable(getBatteryDrawable());
+
+            ImageView wifi = sysTrayLayout.findViewById(R.id.wifi);
+            wifi.setImageDrawable(getWifiDrawable());
+
+            ImageView bluetooth = sysTrayLayout.findViewById(R.id.bluetooth);
+            bluetooth.setImageDrawable(getBluetoothDrawable());
+
+            ImageView cellular = sysTrayLayout.findViewById(R.id.cellular);
+            cellular.setImageDrawable(getCellularDrawable());
+
+            time.setText(context.getString(R.string.tb_systray_clock,
+                    DateFormat.getTimeFormat(context).format(new Date()),
+                    DateFormat.getDateFormat(context).format(new Date())));
+            time.setTextColor(U.getAccentColor(context));
+        });
+    }
+
+    @TargetApi(Build.VERSION_CODES.M)
+    private Drawable getBatteryDrawable() {
+        BatteryManager bm = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
+        int batLevel = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
+
+        if(batLevel == Integer.MIN_VALUE)
+            return null;
+
+        IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
+        Intent batteryStatus = context.registerReceiver(null, ifilter);
+
+        int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
+        boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
+                status == BatteryManager.BATTERY_STATUS_FULL;
+
+        String batDrawable;
+        if(batLevel < 10 && !isCharging)
+            batDrawable = "alert";
+        else if(batLevel < 25)
+            batDrawable = "20";
+        else if(batLevel < 40)
+            batDrawable = "30";
+        else if(batLevel < 55)
+            batDrawable = "50";
+        else if(batLevel < 70)
+            batDrawable = "60";
+        else if(batLevel < 85)
+            batDrawable = "80";
+        else if(batLevel < 95)
+            batDrawable = "90";
+        else
+            batDrawable = "full";
+
+        String charging;
+        if(isCharging)
+            charging = "charging_";
+        else
+            charging = "";
+
+        String batRes = "tb_battery_" + charging + batDrawable;
+        int id = getResourceIdFor(batRes);
+
+        return getDrawableForSysTray(id);
+    }
+
+    @TargetApi(Build.VERSION_CODES.M)
+    private Drawable getWifiDrawable() {
+        ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+
+        NetworkInfo ethernet = manager.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET);
+        if(ethernet != null && ethernet.isConnected())
+            return getDrawableForSysTray(R.drawable.tb_settings_ethernet);
+
+        NetworkInfo wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
+        if(wifi == null || !wifi.isConnected())
+            return null;
+
+        WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
+        int numberOfLevels = 5;
+
+        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
+        int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);
+
+        String wifiRes = "tb_signal_wifi_" + level + "_bar";
+        int id = getResourceIdFor(wifiRes);
+
+        return getDrawableForSysTray(id);
+    }
+
+    private Drawable getBluetoothDrawable() {
+        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+        if(adapter != null && adapter.isEnabled())
+            return getDrawableForSysTray(R.drawable.tb_bluetooth);
+
+        return null;
+    }
+
+    @TargetApi(Build.VERSION_CODES.M)
+    private Drawable getCellularDrawable() {
+        if(Settings.Global.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0)
+            return getDrawableForSysTray(R.drawable.tb_airplanemode_active);
+
+        if(cellStrength == -1)
+            return null;
+
+        String cellRes = "tb_signal_cellular_" + cellStrength + "_bar";
+        int id = getResourceIdFor(cellRes);
+
+        return getDrawableForSysTray(id);
+    }
+
+    private Drawable getDrawableForSysTray(int id) {
+        Drawable drawable = null;
+        try {
+            drawable = ContextCompat.getDrawable(context, id);
+        } catch (Resources.NotFoundException e) { /* Gracefully fail */ }
+
+        if(drawable == null) return null;
+
+        drawable.setTint(U.getAccentColor(context));
+        return drawable;
+    }
+
+    private int getResourceIdFor(String name) {
+        String packageName = context.getResources().getResourcePackageName(R.drawable.tb_dummy);
+        return context.getResources().getIdentifier(name, "drawable", packageName);
+    }
 }