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 67f0ba4..58a4cdd 100644 (file)
@@ -34,13 +34,16 @@ 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.ConnectivityManager;
 import android.net.NetworkInfo;
-import android.net.Uri;
 import android.net.wifi.WifiInfo;
 import android.net.wifi.WifiManager;
 import android.os.BatteryManager;
@@ -48,13 +51,14 @@ 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;
@@ -79,7 +83,6 @@ 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;
@@ -91,6 +94,7 @@ 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;
@@ -135,7 +139,7 @@ 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;
@@ -144,16 +148,12 @@ public class TaskbarController implements UIController {
     private boolean sysTrayEnabled = false;
 
     private List<String> currentTaskbarIds = new ArrayList<>();
-    private List<String> currentRunningAppIds = new ArrayList<>();
-    private List<String> prevRunningAppIds = new ArrayList<>();
     private int numOfPinnedApps = -1;
 
     private int cellStrength = -1;
 
-    private View.OnClickListener ocl = view -> {
-        Intent intent = new Intent("com.farmerbb.taskbar.TOGGLE_START_MENU");
-        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
-    };
+    private View.OnClickListener ocl = view ->
+            U.sendBroadcast(context, TaskbarIntent.ACTION_TOGGLE_START_MENU);
 
     private BroadcastReceiver showReceiver = new BroadcastReceiver() {
         @Override
@@ -204,7 +204,11 @@ public class TaskbarController implements UIController {
     private PhoneStateListener listener = new PhoneStateListener() {
         @Override
         public void onSignalStrengthsChanged(SignalStrength signalStrength) {
-            cellStrength = signalStrength.getLevel();
+            try {
+                cellStrength = signalStrength.getLevel();
+            } catch (SecurityException e) {
+                cellStrength = -1;
+            }
         }
     };
 
@@ -245,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;
@@ -312,34 +316,45 @@ public class TaskbarController implements UIController {
 
         switch(pref.getString("start_button_image", U.getDefaultStartButtonImage(context))) {
             case "default":
-                startButton.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.all_apps_button_icon));
-                padding = context.getResources().getDimensionPixelSize(R.dimen.app_drawer_icon_padding);
+                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 = ContextCompat.getDrawable(context, R.drawable.tb_bliss);
                     drawable.setTint(accentColor);
-                } else
-                    drawable = ContextCompat.getDrawable(context, R.mipmap.ic_launcher);
+                } 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);
+                padding = context.getResources().getDimensionPixelSize(R.dimen.tb_app_drawer_icon_padding_alt);
                 break;
             case "custom":
-                File file = new File(context.getFilesDir() + "/images", "custom_image");
+                File file = new File(context.getFilesDir() + "/tb_images", "custom_image");
                 if(file.exists()) {
-                    try {
-                        startButton.setImageURI(Uri.fromFile(file));
-                    } catch (Exception e) {
-                        U.showToastLong(context, R.string.error_reading_custom_start_image);
-                        startButton.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.all_apps_button_icon));
-                    }
+                    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.all_apps_button_icon));
+                    startButton.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.tb_all_apps_button_icon));
 
-                padding = context.getResources().getDimensionPixelSize(R.dimen.app_drawer_icon_padding);
+                padding = context.getResources().getDimensionPixelSize(R.dimen.tb_app_drawer_icon_padding);
                 break;
         }
 
@@ -380,9 +395,8 @@ public class TaskbarController implements UIController {
                 break;
         }
 
-        LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
-        lbm.sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));
-        lbm.sendBroadcast(new Intent("com.farmerbb.taskbar.UPDATE_HOME_SCREEN_MARGINS"));
+        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);
@@ -412,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", context.getResources().getBoolean(R.bool.def_dashboard));
+        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);
@@ -421,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);
 
@@ -542,14 +557,14 @@ public class TaskbarController implements UIController {
         sysTrayEnabled = U.isSystemTrayEnabled(context);
 
         if(sysTrayEnabled) {
-            sysTrayLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.system_tray, null);
+            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.icon_size)
+                    context.getResources().getDimensionPixelSize(R.dimen.tb_icon_size)
             );
 
-            if(layoutId == R.layout.taskbar_right) {
+            if(layoutId == R.layout.tb_taskbar_right) {
                 time = sysTrayLayout.findViewById(R.id.time_left);
                 sysTrayParams.gravity = Gravity.START;
             } else {
@@ -560,30 +575,32 @@ public class TaskbarController implements UIController {
             time.setVisibility(View.VISIBLE);
             sysTrayLayout.setLayoutParams(sysTrayParams);
 
-            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.isLibrary(context)) {
+                sysTrayLayout.setOnClickListener(v -> {
+                    U.sendAccessibilityAction(context, AccessibilityService.GLOBAL_ACTION_NOTIFICATIONS);
                     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) {
+                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;
-                });
+
+                        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);
@@ -607,24 +624,17 @@ public class TaskbarController implements UIController {
             U.showHideNavigationBar(context, false);
 
         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();
 
@@ -695,13 +705,10 @@ public class TaskbarController implements UIController {
         List<LauncherActivityInfo> launcherAppCache = new ArrayList<>();
         int maxNumOfEntries = U.getMaxNumOfEntries(context);
         int realNumOfPinnedApps = 0;
-        boolean fullLength = pref.getBoolean("full_length", context.getResources().getBoolean(R.bool.def_full_length));
-
-        if(runningAppsOnly)
-            currentRunningAppIds.clear();
+        boolean fullLength = pref.getBoolean("full_length", context.getResources().getBoolean(R.bool.tb_def_full_length));
 
         PinnedBlockedApps pba = PinnedBlockedApps.getInstance(context);
-        List<AppEntry> pinnedApps = setTimeLastUsedFor(pba.getPinnedApps());
+        List<AppEntry> pinnedApps = pba.getPinnedApps();
         List<AppEntry> blockedApps = pba.getBlockedApps();
         List<String> applicationIdsToRemove = new ArrayList<>();
 
@@ -901,7 +908,6 @@ public class TaskbarController implements UIController {
             }
 
             if(finalApplicationIds.size() != currentTaskbarIds.size()
-                    || (runningAppsOnly && currentRunningAppIds.size() != prevRunningAppIds.size())
                     || numOfPinnedApps != realNumOfPinnedApps)
                 shouldRedrawTaskbar = true;
             else {
@@ -911,26 +917,12 @@ public class TaskbarController implements UIController {
                         break;
                     }
                 }
-
-                if(!shouldRedrawTaskbar && runningAppsOnly) {
-                    for(int i = 0; i < finalApplicationIds.size(); i++) {
-                        if(!currentRunningAppIds.get(i).equals(prevRunningAppIds.get(i))) {
-                            shouldRedrawTaskbar = true;
-                            break;
-                        }
-                    }
-                }
             }
 
             if(shouldRedrawTaskbar) {
                 currentTaskbarIds = finalApplicationIds;
                 numOfPinnedApps = realNumOfPinnedApps;
 
-                if(runningAppsOnly) {
-                    prevRunningAppIds.clear();
-                    prevRunningAppIds.addAll(currentRunningAppIds);
-                }
-
                 UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
 
                 int launcherAppCachePos = -1;
@@ -962,7 +954,7 @@ public class TaskbarController implements UIController {
                     if(numOfEntries > 0 || fullLength) {
                         ViewGroup.LayoutParams params = scrollView.getLayoutParams();
                         DisplayInfo display = U.getDisplayInfo(context, true);
-                        int recentsSize = context.getResources().getDimensionPixelSize(R.dimen.icon_size) * numOfEntries;
+                        int recentsSize = context.getResources().getDimensionPixelSize(R.dimen.tb_icon_size) * numOfEntries;
                         float maxRecentsSize = fullLength ? Float.MAX_VALUE : recentsSize;
 
                         if(U.getTaskbarPosition(context).contains("vertical")) {
@@ -971,7 +963,7 @@ public class TaskbarController implements UIController {
                                     - 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) {
                                 try {
@@ -1002,7 +994,7 @@ public class TaskbarController implements UIController {
                             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) {
                                 try {
@@ -1038,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)
@@ -1078,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(() -> {
@@ -1088,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();
             }
         }
@@ -1133,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));
         }
     }
 
@@ -1168,11 +1192,12 @@ public class TaskbarController implements UIController {
             updateButton(true);
 
             if(clearVariables) {
-                LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));
-                LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_DASHBOARD"));
+                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));
         }
     }
 
@@ -1273,14 +1298,12 @@ public class TaskbarController implements UIController {
         } else if(pref.getBoolean("auto_hide_navbar", false))
             U.showHideNavigationBar(context, true);
 
-        LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
-
-        lbm.unregisterReceiver(showReceiver);
-        lbm.unregisterReceiver(hideReceiver);
-        lbm.unregisterReceiver(tempShowReceiver);
-        lbm.unregisterReceiver(tempHideReceiver);
-        lbm.unregisterReceiver(startMenuAppearReceiver);
-        lbm.unregisterReceiver(startMenuDisappearReceiver);
+        U.unregisterReceiver(context, showReceiver);
+        U.unregisterReceiver(context, hideReceiver);
+        U.unregisterReceiver(context, tempShowReceiver);
+        U.unregisterReceiver(context, tempHideReceiver);
+        U.unregisterReceiver(context, startMenuAppearReceiver);
+        U.unregisterReceiver(context, startMenuDisappearReceiver);
 
         if(sysTrayEnabled) {
             TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
@@ -1306,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);
     }
 
@@ -1332,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);
@@ -1414,15 +1437,6 @@ 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;
     }
 
@@ -1465,7 +1479,6 @@ public class TaskbarController implements UIController {
                 try {
                     Field field = ActivityManager.RecentTaskInfo.class.getField("firstActiveTime");
                     newEntry.setLastTimeUsed(field.getLong(recentTaskInfo));
-                    currentRunningAppIds.add(packageName);
                 } catch (Exception e) {
                     newEntry.setLastTimeUsed(i);
                 }
@@ -1477,31 +1490,6 @@ public class TaskbarController implements UIController {
         return entries;
     }
 
-    @SuppressWarnings("deprecation")
-    @TargetApi(Build.VERSION_CODES.M)
-    private List<AppEntry> setTimeLastUsedFor(List<AppEntry> pinnedApps) {
-        if(!runningAppsOnly || pinnedApps.size() == 0)
-            return pinnedApps;
-
-        ActivityManager mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
-        List<ActivityManager.RecentTaskInfo> recentTasks = mActivityManager.getRecentTasks(Integer.MAX_VALUE, 0);
-
-        for(AppEntry entry : pinnedApps) {
-            for(ActivityManager.RecentTaskInfo task : recentTasks) {
-                if(task.id != -1 && task.baseActivity.getPackageName().equals(entry.getPackageName())) {
-                    try {
-                        Field field = ActivityManager.RecentTaskInfo.class.getField("firstActiveTime");
-                        entry.setLastTimeUsed(field.getLong(task));
-                        currentRunningAppIds.add(entry.getPackageName());
-                        break;
-                    } catch (Exception e) { /* Gracefully fail */ }
-                }
-            }
-        }
-
-        return pinnedApps;
-    }
-
     @TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
     private List<AppEntry> getAppEntriesUsingUsageStats() {
         UsageStatsManager mUsageStatsManager = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE);
@@ -1558,7 +1546,7 @@ public class TaskbarController implements UIController {
             ImageView cellular = sysTrayLayout.findViewById(R.id.cellular);
             cellular.setImageDrawable(getCellularDrawable());
 
-            time.setText(context.getString(R.string.systray_clock,
+            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));
@@ -1604,10 +1592,10 @@ public class TaskbarController implements UIController {
         else
             charging = "";
 
-        String batRes = "ic_battery_" + charging + batDrawable + "_black_24dp";
+        String batRes = "tb_battery_" + charging + batDrawable;
         int id = getResourceIdFor(batRes);
 
-        return applyTintTo(ContextCompat.getDrawable(context, id));
+        return getDrawableForSysTray(id);
     }
 
     @TargetApi(Build.VERSION_CODES.M)
@@ -1616,7 +1604,7 @@ public class TaskbarController implements UIController {
 
         NetworkInfo ethernet = manager.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET);
         if(ethernet != null && ethernet.isConnected())
-            return applyTintTo(ContextCompat.getDrawable(context, R.drawable.ic_settings_ethernet_black_24dp));
+            return getDrawableForSysTray(R.drawable.tb_settings_ethernet);
 
         NetworkInfo wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
         if(wifi == null || !wifi.isConnected())
@@ -1628,16 +1616,16 @@ public class TaskbarController implements UIController {
         WifiInfo wifiInfo = wifiManager.getConnectionInfo();
         int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);
 
-        String wifiRes = "ic_signal_wifi_" + level + "_bar_black_24dp";
+        String wifiRes = "tb_signal_wifi_" + level + "_bar";
         int id = getResourceIdFor(wifiRes);
 
-        return applyTintTo(ContextCompat.getDrawable(context, id));
+        return getDrawableForSysTray(id);
     }
 
     private Drawable getBluetoothDrawable() {
         BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
         if(adapter != null && adapter.isEnabled())
-            return applyTintTo(ContextCompat.getDrawable(context, R.drawable.ic_bluetooth_black_24dp));
+            return getDrawableForSysTray(R.drawable.tb_bluetooth);
 
         return null;
     }
@@ -1645,18 +1633,23 @@ public class TaskbarController implements UIController {
     @TargetApi(Build.VERSION_CODES.M)
     private Drawable getCellularDrawable() {
         if(Settings.Global.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0)
-            return applyTintTo(ContextCompat.getDrawable(context, R.drawable.ic_airplanemode_active_black_24dp));
+            return getDrawableForSysTray(R.drawable.tb_airplanemode_active);
 
         if(cellStrength == -1)
             return null;
 
-        String cellRes = "ic_signal_cellular_" + cellStrength + "_bar_black_24dp";
+        String cellRes = "tb_signal_cellular_" + cellStrength + "_bar";
         int id = getResourceIdFor(cellRes);
 
-        return applyTintTo(ContextCompat.getDrawable(context, id));
+        return getDrawableForSysTray(id);
     }
-    
-    private Drawable applyTintTo(Drawable drawable) {
+
+    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));
@@ -1664,7 +1657,7 @@ public class TaskbarController implements UIController {
     }
 
     private int getResourceIdFor(String name) {
-        String packageName = context.getResources().getResourcePackageName(R.mipmap.ic_launcher);
+        String packageName = context.getResources().getResourcePackageName(R.drawable.tb_dummy);
         return context.getResources().getIdentifier(name, "drawable", packageName);
     }
 }