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;
import android.content.pm.LauncherApps;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
+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;
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 androidx.localbroadcastmanager.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;
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.util.AppEntry;
import com.farmerbb.taskbar.util.DisplayInfo;
import com.farmerbb.taskbar.util.FreeformHackHelper;
private Space space;
private FrameLayout dashboardButton;
private LinearLayout navbarButtons;
+ private LinearLayout sysTrayLayout;
+ private FrameLayout sysTrayParentLayout;
+ private TextView time;
private Handler handler;
private Handler handler2;
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 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);
}
};
+ @TargetApi(Build.VERSION_CODES.M)
+ private PhoneStateListener listener = new PhoneStateListener() {
+ @Override
+ public void onSignalStrengthsChanged(SignalStrength signalStrength) {
+ cellStrength = signalStrength.getLevel();
+ }
+ };
+
public TaskbarController(Context context) {
this.context = context;
}
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();
// 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;
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);
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;
break;
}
- Intent intent = new Intent("com.farmerbb.taskbar.HIDE_START_MENU");
- LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
+ 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"));
if(altButtonConfig) {
button = layout.findViewById(R.id.hide_taskbar_button_alt);
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);
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);
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"));
handler = new Handler();
thread = new Thread(() -> {
+ updateSystemTray();
updateRecentApps(true);
if(!isRefreshingRecents) {
while(shouldRefreshRecents) {
SystemClock.sleep(refreshInterval);
+ updateSystemTray();
updateRecentApps(false);
if(showHideAutomagically && !positionIsVertical && !MenuHelper.getInstance().isStartMenuOpen())
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));
+
+ if(runningAppsOnly)
+ currentRunningAppIds.clear();
PinnedBlockedApps pba = PinnedBlockedApps.getInstance(context);
- List<AppEntry> pinnedApps = pba.getPinnedApps();
+ List<AppEntry> pinnedApps = setTimeLastUsedFor(pba.getPinnedApps());
List<AppEntry> blockedApps = pba.getBlockedApps();
List<String> applicationIdsToRemove = new ArrayList<>();
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();
}
}
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;
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 */ }
}
}
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();
}
}
if(isShowingRecents && scrollView.getVisibility() == View.GONE)
scrollView.setVisibility(View.INVISIBLE);
+ if(sysTrayEnabled)
+ sysTrayParentLayout.setVisibility(View.VISIBLE);
+
shouldRefreshRecents = true;
startRefreshingRecents();
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();
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) {
+ LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));
+ LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_DASHBOARD"));
+ }
new Handler().post(() -> LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU_SPACE")));
}
lbm.unregisterReceiver(startMenuAppearReceiver);
lbm.unregisterReceiver(startMenuDisappearReceiver);
+ if(sysTrayEnabled) {
+ TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+ manager.listen(listener, PhoneStateListener.LISTEN_NONE);
+ }
+
isFirstStart = true;
}
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);
}
currentTaskbarPosition = 0;
- if(U.canDrawOverlays(context, host instanceof HomeActivityDelegate))
+ if(U.canDrawOverlays(context))
drawTaskbar(host);
else {
SharedPreferences pref = U.getSharedPreferences(context);
}
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);
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)) {
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 -> {
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]);
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);
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 applyTintTo(ContextCompat.getDrawable(context, 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 applyTintTo(ContextCompat.getDrawable(context, 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 applyTintTo(ContextCompat.getDrawable(context, id));
+ }
+
+ private Drawable getBluetoothDrawable() {
+ BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+ if(adapter != null && adapter.isEnabled())
+ return applyTintTo(ContextCompat.getDrawable(context, 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 applyTintTo(ContextCompat.getDrawable(context, R.drawable.tb_airplanemode_active));
+
+ if(cellStrength == -1)
+ return null;
+
+ String cellRes = "tb_signal_cellular_" + cellStrength + "_bar";
+ int id = getResourceIdFor(cellRes);
+
+ return applyTintTo(ContextCompat.getDrawable(context, id));
+ }
+
+ private Drawable applyTintTo(Drawable drawable) {
+ 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);
+ }
}