use of com.farmerbb.taskbar.helper.LauncherHelper in project Taskbar by farmerbb.
the class HomeActivityDelegate method setOnHomeScreen.
private void setOnHomeScreen(boolean value) {
LauncherHelper helper = LauncherHelper.getInstance();
if (isSecondaryHome) {
int displayID = windowManager.getDefaultDisplay().getDisplayId();
if (displayID == Display.DEFAULT_DISPLAY) {
finish();
return;
}
helper.setOnSecondaryHomeScreen(value, displayID);
SharedPreferences pref = U.getSharedPreferences(this);
if (pref.getBoolean(PREF_AUTO_HIDE_NAVBAR_DESKTOP_MODE, false))
U.showHideNavigationBar(this, displayID, !value, 0);
} else
helper.setOnPrimaryHomeScreen(value);
}
use of com.farmerbb.taskbar.helper.LauncherHelper in project Taskbar by farmerbb.
the class ContextMenuActivity method onPreferenceClick.
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.N_MR1)
@Override
public boolean onPreferenceClick(Preference p) {
UserManager userManager = (UserManager) getSystemService(USER_SERVICE);
LauncherApps launcherApps = (LauncherApps) getSystemService(LAUNCHER_APPS_SERVICE);
boolean appIsValid = isStartButton || isOverflowMenu || desktopIcon != null || (entry != null && !launcherApps.getActivityList(entry.getPackageName(), userManager.getUserForSerialNumber(entry.getUserId(this))).isEmpty());
secondaryMenu = false;
if (appIsValid)
switch(p.getKey()) {
case PREF_APP_INFO:
U.launchApp(this, () -> launcherApps.startAppDetailsActivity(ComponentName.unflattenFromString(entry.getComponentName()), userManager.getUserForSerialNumber(entry.getUserId(this)), null, U.getActivityOptionsBundle(this, ApplicationType.APP_PORTRAIT, getListView().getChildAt(p.getOrder()))));
prepareToClose();
break;
case PREF_UNINSTALL:
if (U.hasFreeformSupport(this) && isInMultiWindowMode()) {
Intent intent2 = new Intent(this, DummyActivity.class);
intent2.putExtra("uninstall", entry.getPackageName());
intent2.putExtra("user_id", entry.getUserId(this));
try {
startActivity(intent2);
} catch (IllegalArgumentException ignored) {
}
} else {
Intent intent2 = new Intent(Intent.ACTION_DELETE, Uri.parse("package:" + entry.getPackageName()));
intent2.putExtra(Intent.EXTRA_USER, userManager.getUserForSerialNumber(entry.getUserId(this)));
try {
startActivity(intent2);
} catch (ActivityNotFoundException | IllegalArgumentException ignored) {
}
}
prepareToClose();
break;
case PREF_OPEN_TASKBAR_SETTINGS:
U.launchApp(this, () -> {
Intent intent2 = new Intent(this, MainActivity.class);
intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
LauncherHelper helper = LauncherHelper.getInstance();
if (helper.isOnHomeScreen(this) || helper.isOnSecondaryHomeScreen(this))
U.applyOpenInNewWindow(this, intent2);
try {
startActivity(intent2, U.getActivityOptionsBundle(this, ApplicationType.APP_PORTRAIT, getListView().getChildAt(p.getOrder())));
} catch (IllegalArgumentException ignored) {
}
});
prepareToClose();
break;
case PREF_QUIT_TASKBAR:
Intent quitIntent = new Intent(ACTION_QUIT);
quitIntent.setPackage(getPackageName());
sendBroadcast(quitIntent);
prepareToClose();
break;
case PREF_PIN_APP:
PinnedBlockedApps pba = PinnedBlockedApps.getInstance(this);
if (pba.isPinned(entry.getComponentName()))
pba.removePinnedApp(this, entry.getComponentName());
else {
Intent intent = new Intent();
intent.setComponent(ComponentName.unflattenFromString(entry.getComponentName()));
LauncherActivityInfo appInfo = launcherApps.resolveActivity(intent, userManager.getUserForSerialNumber(entry.getUserId(this)));
if (appInfo != null) {
AppEntry newEntry = new AppEntry(entry.getPackageName(), entry.getComponentName(), entry.getLabel(), IconCache.getInstance(this).getIcon(this, appInfo), true);
newEntry.setUserId(entry.getUserId(this));
pba.addPinnedApp(this, newEntry);
}
}
break;
case PREF_BLOCK_APP:
PinnedBlockedApps pba2 = PinnedBlockedApps.getInstance(this);
if (pba2.isBlocked(entry.getComponentName()))
pba2.removeBlockedApp(this, entry.getComponentName());
else
pba2.addBlockedApp(this, entry);
break;
case PREF_SHOW_WINDOW_SIZES:
generateWindowSizes();
if (U.hasBrokenSetLaunchBoundsApi())
U.showToastLong(this, R.string.tb_window_sizes_not_available);
getListView().setOnItemLongClickListener((parent, view, position, id) -> {
String[] windowSizes = getResources().getStringArray(R.array.tb_pref_window_size_list_values);
SavedWindowSizes.getInstance(this).setWindowSize(this, entry.getPackageName(), windowSizes[position]);
generateWindowSizes();
return true;
});
secondaryMenu = true;
break;
case PREF_WINDOW_SIZE_STANDARD:
case PREF_WINDOW_SIZE_LARGE:
case PREF_WINDOW_SIZE_FULLSCREEN:
case PREF_WINDOW_SIZE_HALF_LEFT:
case PREF_WINDOW_SIZE_HALF_RIGHT:
case PREF_WINDOW_SIZE_PHONE_SIZE:
String windowSize = p.getKey().replace("window_size_", "");
SharedPreferences pref2 = U.getSharedPreferences(this);
if (pref2.getBoolean(PREF_SAVE_WINDOW_SIZES, true)) {
SavedWindowSizes.getInstance(this).setWindowSize(this, entry.getPackageName(), windowSize);
}
U.launchApp(U.getDisplayContext(this), entry, windowSize, false, true, getListView().getChildAt(p.getOrder()));
if (U.hasBrokenSetLaunchBoundsApi())
U.cancelToast();
prepareToClose();
break;
case PREF_APP_SHORTCUTS:
getPreferenceScreen().removeAll();
generateShortcuts();
secondaryMenu = true;
break;
case PREF_SHORTCUT_1:
case PREF_SHORTCUT_2:
case PREF_SHORTCUT_3:
case PREF_SHORTCUT_4:
case PREF_SHORTCUT_5:
U.startShortcut(U.getDisplayContext(this), entry, shortcuts.get(Integer.parseInt(p.getKey().replace("shortcut_", "")) - 1), getListView().getChildAt(p.getOrder()));
prepareToClose();
break;
case PREF_START_MENU_APPS:
Intent intent = U.getThemedIntent(this, SelectAppActivity.class);
if (U.hasFreeformSupport(this) && U.isFreeformModeEnabled(this) && isInMultiWindowMode()) {
intent.putExtra("no_shadow", true);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
U.startActivityMaximized(U.getDisplayContext(this), intent);
} else {
try {
startActivity(intent);
} catch (IllegalArgumentException ignored) {
}
}
prepareToClose();
break;
case PREF_VOLUME:
AudioManager audio = (AudioManager) getSystemService(AUDIO_SERVICE);
audio.adjustSuggestedStreamVolume(AudioManager.ADJUST_SAME, AudioManager.USE_DEFAULT_STREAM_TYPE, AudioManager.FLAG_SHOW_UI);
if (LauncherHelper.getInstance().isOnSecondaryHomeScreen(this)) {
U.showToast(this, R.string.tb_opening_volume_control);
U.sendBroadcast(this, ACTION_UNDIM_SCREEN);
}
prepareToClose();
break;
case PREF_FILE_MANAGER:
U.launchApp(this, () -> {
Intent fileManagerIntent;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1)
fileManagerIntent = new Intent(Intent.ACTION_VIEW);
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
fileManagerIntent = new Intent("android.provider.action.BROWSE");
else {
fileManagerIntent = new Intent("android.provider.action.BROWSE_DOCUMENT_ROOT");
fileManagerIntent.setComponent(ComponentName.unflattenFromString("com.android.documentsui/.DocumentsActivity"));
}
fileManagerIntent.addCategory(Intent.CATEGORY_DEFAULT);
fileManagerIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
fileManagerIntent.setData(Uri.parse("content://com.android.externalstorage.documents/root/primary"));
try {
startActivity(fileManagerIntent, U.getActivityOptionsBundle(this, ApplicationType.APP_PORTRAIT, getListView().getChildAt(p.getOrder())));
} catch (ActivityNotFoundException e) {
U.showToast(this, R.string.tb_lock_device_not_supported);
} catch (IllegalArgumentException ignored) {
}
});
prepareToClose();
break;
case PREF_SYSTEM_SETTINGS:
U.launchApp(this, () -> {
Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS);
settingsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivity(settingsIntent, U.getActivityOptionsBundle(this, ApplicationType.APP_PORTRAIT, getListView().getChildAt(p.getOrder())));
} catch (ActivityNotFoundException e) {
U.showToast(this, R.string.tb_lock_device_not_supported);
} catch (IllegalArgumentException ignored) {
}
});
prepareToClose();
break;
case PREF_LOCK_DEVICE:
U.lockDevice(this);
prepareToClose();
break;
case PREF_POWER_MENU:
U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_POWER_DIALOG, () -> {
if (LauncherHelper.getInstance().isOnSecondaryHomeScreen(this)) {
U.showToast(this, R.string.tb_opening_power_menu);
U.sendBroadcast(this, ACTION_UNDIM_SCREEN);
}
});
prepareToClose();
break;
case PREF_ADD_ICON_TO_DESKTOP:
Intent intent2 = U.getThemedIntent(this, DesktopIconSelectAppActivity.class);
intent2.putExtra("desktop_icon", desktopIcon);
if (U.hasFreeformSupport(this) && U.isFreeformModeEnabled(this) && isInMultiWindowMode()) {
intent2.putExtra("no_shadow", true);
intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
U.startActivityMaximized(U.getDisplayContext(this), intent2);
} else {
try {
startActivity(intent2);
} catch (IllegalArgumentException ignored) {
}
}
prepareToClose();
break;
case PREF_ARRANGE_ICONS:
U.sendBroadcast(this, ACTION_ENTER_ICON_ARRANGE_MODE);
break;
case PREF_SORT_BY_NAME:
U.sendBroadcast(this, ACTION_SORT_DESKTOP_ICONS);
break;
case PREF_CHANGE_WALLPAPER:
if (LauncherHelper.getInstance().isOnSecondaryHomeScreen(this)) {
generateWallpaperOptions();
secondaryMenu = true;
} else if (U.isChromeOs(this)) {
U.sendBroadcast(this, ACTION_WALLPAPER_CHANGE_REQUESTED);
} else {
changeWallpaper();
prepareToClose();
}
break;
case PREF_REMOVE_DESKTOP_ICON:
try {
SharedPreferences pref5 = U.getSharedPreferences(this);
JSONArray jsonIcons = new JSONArray(pref5.getString(PREF_DESKTOP_ICONS, "[]"));
int iconToRemove = -1;
for (int i = 0; i < jsonIcons.length(); i++) {
DesktopIconInfo info = DesktopIconInfo.fromJson(jsonIcons.getJSONObject(i));
if (info != null && info.column == desktopIcon.column && info.row == desktopIcon.row) {
iconToRemove = i;
break;
}
}
if (iconToRemove > -1) {
jsonIcons.remove(iconToRemove);
pref5.edit().putString(PREF_DESKTOP_ICONS, jsonIcons.toString()).apply();
U.sendBroadcast(this, ACTION_REFRESH_DESKTOP_ICONS);
}
} catch (JSONException ignored) {
}
break;
case PREF_CHANGE_WALLPAPER_GLOBAL:
changeWallpaper();
prepareToClose();
break;
case PREF_CHANGE_WALLPAPER_DESKTOP:
U.sendBroadcast(this, ACTION_WALLPAPER_CHANGE_REQUESTED);
break;
case PREF_REMOVE_DESKTOP_WALLPAPER:
U.sendBroadcast(this, ACTION_REMOVE_DESKTOP_WALLPAPER);
break;
}
if (!secondaryMenu)
finish();
return true;
}
use of com.farmerbb.taskbar.helper.LauncherHelper in project Taskbar by farmerbb.
the class UIController method init.
protected void init(Context context, UIHost host, Runnable runnable) {
SharedPreferences pref = U.getSharedPreferences(context);
LauncherHelper helper = LauncherHelper.getInstance();
boolean shouldProceed;
if (helper.isOnSecondaryHomeScreen(context))
shouldProceed = host instanceof SecondaryHomeActivity;
else
shouldProceed = true;
if (shouldProceed && (pref.getBoolean(PREF_TASKBAR_ACTIVE, false) || helper.isOnHomeScreen(context))) {
if (U.canDrawOverlays(context))
runnable.run();
else {
pref.edit().putBoolean(PREF_TASKBAR_ACTIVE, false).apply();
host.terminate();
}
} else
host.terminate();
}
use of com.farmerbb.taskbar.helper.LauncherHelper in project Taskbar by farmerbb.
the class DesktopModeFragment method onPreferenceClick.
@Override
public boolean onPreferenceClick(final Preference p) {
switch(p.getKey()) {
case PREF_DESKTOP_MODE:
boolean isChecked = ((CheckBoxPreference) p).isChecked();
if (isChecked && !U.isDesktopModePrefEnabled(getActivity())) {
try {
Settings.Global.putInt(getActivity().getContentResolver(), "enable_freeform_support", 1);
Settings.Global.putInt(getActivity().getContentResolver(), "force_desktop_mode_on_external_displays", 1);
U.showToastLong(getActivity(), R.string.tb_reboot_required);
} catch (Exception e) {
((CheckBoxPreference) p).setChecked(false);
isChecked = false;
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.tb_desktop_mode_dialog_title).setMessage(R.string.tb_desktop_mode_dialog_message).setPositiveButton(R.string.tb_action_developer_options, (dialogInterface, i) -> {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
try {
startActivity(intent);
isConfiguringDeveloperOptions = true;
} catch (ActivityNotFoundException e1) {
intent = new Intent(Settings.ACTION_DEVICE_INFO_SETTINGS);
try {
startActivity(intent);
U.showToastLong(getActivity(), R.string.tb_enable_developer_options);
} catch (ActivityNotFoundException ignored) {
}
}
});
AlertDialog dialog = builder.create();
dialog.show();
dialog.setCancelable(false);
}
}
handleDesktopModePrefChange(isChecked);
break;
case PREF_SET_LAUNCHER_DEFAULT:
configureHomeApp();
break;
case PREF_PRIMARY_LAUNCHER:
Intent intent = new Intent(getActivity(), HSLConfigActivity.class);
intent.putExtra("return_to_settings", true);
startActivity(intent);
break;
case PREF_AUTO_HIDE_NAVBAR_DESKTOP_MODE:
LauncherHelper helper = LauncherHelper.getInstance();
if (helper.isOnSecondaryHomeScreen(getActivity()))
U.showHideNavigationBar(getActivity(), helper.getSecondaryDisplayId(), !((CheckBoxPreference) p).isChecked(), 0);
break;
case PREF_DIM_SCREEN:
if (!((CheckBoxPreference) p).isChecked())
U.sendBroadcast(getActivity(), ACTION_FINISH_DIM_SCREEN_ACTIVITY);
break;
case PREF_ENABLE_ADDITIONAL_SETTINGS:
updateAdditionalSettings = true;
startActivity(U.getThemedIntent(getActivity(), EnableAdditionalSettingsActivity.class));
break;
case PREF_DESKTOP_MODE_IME_FIX:
U.setComponentEnabled(getActivity(), DisableKeyboardService.class, true);
try {
startActivity(new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS));
} catch (ActivityNotFoundException ignored) {
}
break;
}
return super.onPreferenceClick(p);
}
use of com.farmerbb.taskbar.helper.LauncherHelper in project Taskbar by farmerbb.
the class TaskbarController method toggleTaskbar.
private void toggleTaskbar(boolean userInitiated) {
if (userInitiated && Build.BRAND.equalsIgnoreCase("essential")) {
SharedPreferences pref = U.getSharedPreferences(context);
LauncherHelper helper = LauncherHelper.getInstance();
if (!pref.getBoolean(PREF_GRIP_REJECTION_TOAST_SHOWN, false) && !helper.isOnSecondaryHomeScreen(context)) {
U.showToastLong(context, R.string.tb_essential_phone_grip_rejection);
pref.edit().putBoolean(PREF_GRIP_REJECTION_TOAST_SHOWN, true).apply();
}
}
if (startButton.getVisibility() == View.GONE)
showTaskbar(true);
else
hideTaskbar(true);
}
Aggregations