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.ConnectivityManager;
import android.net.NetworkInfo;
-import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.BatteryManager;
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 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.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.FeatureFlags;
import com.farmerbb.taskbar.util.FreeformHackHelper;
import com.farmerbb.taskbar.util.IconCache;
import com.farmerbb.taskbar.util.LauncherHelper;
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;
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;
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;
}
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;
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 = FeatureFlags.SYSTEM_TRAY && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !positionIsVertical;
+ sysTrayEnabled = U.isSystemTrayEnabled(context);
if(sysTrayEnabled) {
- sysTrayLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.system_tray, null);
- sysTrayLayout.setLayoutParams(new FrameLayout.LayoutParams(
+ 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.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;
+ });
+ }
+ }
- ((FrameLayout) layout.findViewById(R.id.add_systray_here)).addView(sysTrayLayout);
+ 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);
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();
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(!shouldRedrawTaskbar && runningAppsOnly) {
- for(int i = 0; i < finalApplicationIds.size(); i++) {
+ for(int i = 0; i < currentRunningAppIds.size(); i++) {
if(!currentRunningAppIds.get(i).equals(prevRunningAppIds.get(i))) {
shouldRedrawTaskbar = true;
break;
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")) {
- 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) {
try {
} 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) {
try {
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();
}
}
scrollView.setVisibility(View.INVISIBLE);
if(sysTrayEnabled)
- sysTrayLayout.setVisibility(View.VISIBLE);
+ sysTrayParentLayout.setVisibility(View.VISIBLE);
shouldRefreshRecents = true;
startRefreshingRecents();
scrollView.setVisibility(View.GONE);
if(sysTrayEnabled)
- sysTrayLayout.setVisibility(View.GONE);
+ 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")));
}
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)) {
}
private void updateSystemTray() {
- if(sysTrayLayout == null || isScreenOff()) return;
-
- int accentColor = U.getAccentColor(context);
+ if(!sysTrayEnabled || isScreenOff()) return;
handler.post(() -> {
ImageView battery = sysTrayLayout.findViewById(R.id.battery);
battery.setImageDrawable(getBatteryDrawable());
- battery.setColorFilter(accentColor);
ImageView wifi = sysTrayLayout.findViewById(R.id.wifi);
wifi.setImageDrawable(getWifiDrawable());
- wifi.setColorFilter(accentColor);
ImageView bluetooth = sysTrayLayout.findViewById(R.id.bluetooth);
bluetooth.setImageDrawable(getBluetoothDrawable());
- bluetooth.setColorFilter(accentColor);
ImageView cellular = sysTrayLayout.findViewById(R.id.cellular);
cellular.setImageDrawable(getCellularDrawable());
- cellular.setColorFilter(accentColor);
- TextView time = sysTrayLayout.findViewById(R.id.time);
- 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(accentColor);
+ time.setTextColor(U.getAccentColor(context));
});
}
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)
+ if(batLevel < 10 && !isCharging)
batDrawable = "alert";
- else if(batLevel <= 20)
+ else if(batLevel < 25)
batDrawable = "20";
- else if(batLevel <= 30)
+ else if(batLevel < 40)
batDrawable = "30";
- else if(batLevel <= 50)
+ else if(batLevel < 55)
batDrawable = "50";
- else if(batLevel <= 60)
+ else if(batLevel < 70)
batDrawable = "60";
- else if(batLevel <= 80)
+ else if(batLevel < 85)
batDrawable = "80";
- else if(batLevel <= 90)
+ else if(batLevel < 95)
batDrawable = "90";
else
batDrawable = "full";
String charging;
- if(bm.isCharging())
+ if(isCharging)
charging = "charging_";
else
charging = "";
- String batRes = "ic_battery_" + charging + batDrawable + "_black_24dp";
- int id = context.getResources().getIdentifier(batRes, "drawable", BuildConfig.APPLICATION_ID);
+ String batRes = "tb_battery_" + charging + batDrawable;
+ int id = getResourceIdFor(batRes);
- return ContextCompat.getDrawable(context, id);
+ return applyTintTo(ContextCompat.getDrawable(context, id));
}
@TargetApi(Build.VERSION_CODES.M)
NetworkInfo ethernet = manager.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET);
if(ethernet != null && ethernet.isConnected())
- return ContextCompat.getDrawable(context, R.drawable.ic_settings_ethernet_black_24dp);
+ return applyTintTo(ContextCompat.getDrawable(context, R.drawable.tb_settings_ethernet));
NetworkInfo wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if(wifi == null || !wifi.isConnected())
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);
- String wifiRes = "ic_signal_wifi_" + level + "_bar_black_24dp";
- int id = context.getResources().getIdentifier(wifiRes, "drawable", BuildConfig.APPLICATION_ID);
+ String wifiRes = "tb_signal_wifi_" + level + "_bar";
+ int id = getResourceIdFor(wifiRes);
- return ContextCompat.getDrawable(context, id);
+ return applyTintTo(ContextCompat.getDrawable(context, id));
}
private Drawable getBluetoothDrawable() {
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if(adapter != null && adapter.isEnabled())
- return ContextCompat.getDrawable(context, R.drawable.ic_bluetooth_black_24dp);
+ 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 ContextCompat.getDrawable(context, R.drawable.ic_airplanemode_active_black_24dp);
+ return applyTintTo(ContextCompat.getDrawable(context, R.drawable.tb_airplanemode_active));
if(cellStrength == -1)
return null;
- String cellRes = "ic_signal_cellular_" + cellStrength + "_bar_black_24dp";
- int id = context.getResources().getIdentifier(cellRes, "drawable", BuildConfig.APPLICATION_ID);
+ 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;
+ }
- return ContextCompat.getDrawable(context, id);
+ private int getResourceIdFor(String name) {
+ String packageName = context.getResources().getResourcePackageName(R.drawable.tb_dummy);
+ return context.getResources().getIdentifier(name, "drawable", packageName);
}
}