import java.util.Date;
import java.util.List;
-import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import android.widget.LinearLayout;
import android.widget.Space;
import android.widget.TextView;
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;
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
private PhoneStateListener listener = new PhoneStateListener() {
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
- cellStrength = signalStrength.getLevel();
+ try {
+ cellStrength = signalStrength.getLevel();
+ } catch (SecurityException e) {
+ cellStrength = -1;
+ }
}
};
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);
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);
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();
int realNumOfPinnedApps = 0;
boolean fullLength = pref.getBoolean("full_length", context.getResources().getBoolean(R.bool.tb_def_full_length));
- if(runningAppsOnly)
- currentRunningAppIds.clear();
-
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<>();
}
if(finalApplicationIds.size() != currentTaskbarIds.size()
- || (runningAppsOnly && currentRunningAppIds.size() != prevRunningAppIds.size())
|| numOfPinnedApps != realNumOfPinnedApps)
shouldRedrawTaskbar = true;
else {
break;
}
}
-
- if(!shouldRedrawTaskbar && runningAppsOnly) {
- for(int i = 0; i < currentRunningAppIds.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;
taskbar.addView(getView(entries, i));
}
+ if(runningAppsOnly)
+ updateRunningAppIndicators(pinnedApps, usageStatsList, entries);
+
isShowingRecents = true;
if(shouldRefreshRecents && scrollView.getVisibility() != View.VISIBLE) {
if(firstRefresh)
scrollView.setVisibility(View.GONE);
}
});
- }
+ } else if(runningAppsOnly)
+ handler.post(() -> updateRunningAppIndicators(pinnedApps, usageStatsList, entries));
} else if(firstRefresh || currentTaskbarIds.size() > 0) {
currentTaskbarIds.clear();
handler.post(() -> {
}
}
+ 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);
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));
}
}
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));
}
}
} 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);
});
}
- 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;
}
try {
Field field = ActivityManager.RecentTaskInfo.class.getField("firstActiveTime");
newEntry.setLastTimeUsed(field.getLong(recentTaskInfo));
- currentRunningAppIds.add(packageName);
} catch (Exception e) {
newEntry.setLastTimeUsed(i);
}
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);
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));