use of com.farmerbb.taskbar.util.DisplayInfo in project Taskbar by farmerbb.
the class InvisibleActivityAlt method onCreate.
@SuppressLint("HardwareIds")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean powerButtonWarning = getIntent().hasExtra("power_button_warning");
DisplayInfo display = U.getDisplayInfo(this);
setContentView(R.layout.tb_incognito);
LinearLayout layout = findViewById(R.id.incognitoLayout);
layout.setLayoutParams(new FrameLayout.LayoutParams(display.width, display.height));
if (!MenuHelper.getInstance().isStartMenuOpen() && !powerButtonWarning)
finish();
if (powerButtonWarning)
U.newHandler().postDelayed(() -> {
if (FreeformHackHelper.getInstance().isInFreeformWorkspace()) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.tb_power_button_warning_title).setMessage(R.string.tb_power_button_warning_message).setPositiveButton(R.string.tb_action_i_understand, (dialog, which) -> {
SharedPreferences pref = U.getSharedPreferences(this);
pref.edit().putString(PREF_POWER_BUTTON_WARNING, Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID)).apply();
finish();
});
AlertDialog dialog = builder.create();
dialog.show();
dialog.setCancelable(false);
}
}, 100);
}
use of com.farmerbb.taskbar.util.DisplayInfo in project Taskbar by farmerbb.
the class TouchAbsorberActivity method onCreate.
@SuppressLint("HardwareIds")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tb_incognito);
DisplayInfo display = U.getDisplayInfo(this);
LinearLayout layout = findViewById(R.id.incognitoLayout);
layout.setLayoutParams(new FrameLayout.LayoutParams(display.width, display.height));
U.registerReceiver(this, finishReceiver, ACTION_FINISH_FREEFORM_ACTIVITY);
FreeformHackHelper.getInstance().setTouchAbsorberActive(true);
U.sendBroadcast(this, ACTION_TOUCH_ABSORBER_STATE_CHANGED);
lastStartTime = System.currentTimeMillis();
}
use of com.farmerbb.taskbar.util.DisplayInfo in project Taskbar by farmerbb.
the class HomeActivityDelegate method onCreate.
@SuppressLint("RestrictedApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences pref = U.getSharedPreferences(this);
isSecondaryHome = this instanceof SecondaryHomeActivity;
if (isSecondaryHome) {
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
isTaskVirtualDisplay = display.getName().startsWith("TaskVirtualDisplay");
if (display.getDisplayId() == Display.DEFAULT_DISPLAY || (!U.isDesktopModeActive(this) && !U.isLibrary(this))) {
finish();
return;
}
if (pref.getBoolean(PREF_DIM_SCREEN, false) && U.launcherIsDefault(this) && !GlobalHelper.getInstance().isOnMainActivity()) {
Intent homeIntent = new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory(Intent.CATEGORY_HOME);
homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(homeIntent);
}
}
shouldDelayFreeformHack = true;
hits = 0;
WindowManager.LayoutParams params = getWindow().getAttributes();
if (U.applyDisplayCutoutModeTo(params))
getWindow().setAttributes(params);
layout = new FrameLayout(this) {
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
WallpaperManager wallpaperManager = (WallpaperManager) getSystemService(WALLPAPER_SERVICE);
wallpaperManager.setWallpaperOffsets(getWindowToken(), 0.5f, 0.5f);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
DisplayInfo display = U.getDisplayInfo(HomeActivityDelegate.this);
if (display.width > 0 && display.height > 0) {
try {
wallpaperManager.suggestDesiredDimensions(display.width, display.height);
} catch (IllegalArgumentException ignored) {
}
}
}
boolean shouldStartFreeformHack = shouldDelayFreeformHack && hits > 0;
shouldDelayFreeformHack = false;
if (shouldStartFreeformHack)
startFreeformHack();
}
};
isWallpaperEnabled = !isTaskVirtualDisplay && (isSecondaryHome || U.isChromeOs(this));
if (isWallpaperEnabled) {
wallpaper = new ImageView(this);
wallpaper.setScaleType(ImageView.ScaleType.CENTER_CROP);
layout.addView(wallpaper);
}
isDesktopIconsEnabled = !isTaskVirtualDisplay && U.isDesktopIconsEnabled(this);
if (isDesktopIconsEnabled) {
layout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
layout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
if (savedInstanceState != null)
iconArrangeMode = savedInstanceState.getBoolean("icon_arrange_mode");
initDesktopIcons();
}
});
} else if (!isTaskVirtualDisplay) {
layout.setOnClickListener(view1 -> U.sendBroadcast(this, ACTION_HIDE_START_MENU));
layout.setOnLongClickListener(view2 -> {
if (!U.isFreeformModeEnabled(this))
setWallpaper();
return false;
});
layout.setOnGenericMotionListener((view3, motionEvent) -> {
if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY && !U.isFreeformModeEnabled(this))
setWallpaper();
return false;
});
}
layout.setFitsSystemWindows(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && isDesktopIconsEnabled && !U.isLibrary(this)) {
detector = new GestureDetector(this, new GestureDetector.OnGestureListener() {
@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return false;
}
@Override
public void onLongPress(MotionEvent e) {
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return false;
}
@Override
public boolean onDown(MotionEvent e) {
return false;
}
});
detector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
@Override
public boolean onDoubleTap(MotionEvent e) {
if (!pref.getBoolean(PREF_DONT_SHOW_DOUBLE_TAP_DIALOG, false) && !isSecondaryHome) {
if (pref.getBoolean(PREF_DOUBLE_TAP_TO_SLEEP, false)) {
U.lockDevice(HomeActivityDelegate.this);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(U.wrapContext(HomeActivityDelegate.this));
builder.setTitle(R.string.tb_double_tap_to_sleep).setMessage(R.string.tb_enable_double_tap_to_sleep).setNegativeButton(pref.getBoolean(PREF_DOUBLE_TAP_DIALOG_SHOWN, false) ? R.string.tb_action_dont_show_again : R.string.tb_action_cancel, (dialog, which) -> pref.edit().putBoolean(pref.getBoolean(PREF_DOUBLE_TAP_DIALOG_SHOWN, false) ? PREF_DONT_SHOW_DOUBLE_TAP_DIALOG : PREF_DOUBLE_TAP_DIALOG_SHOWN, true).apply()).setPositiveButton(R.string.tb_action_ok, (dialog, which) -> {
pref.edit().putBoolean(PREF_DOUBLE_TAP_TO_SLEEP, true).apply();
U.lockDevice(HomeActivityDelegate.this);
});
AlertDialog dialog = builder.create();
dialog.show();
}
}
return false;
}
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
return false;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
return false;
}
});
}
if ((this instanceof HomeActivity || isSecondaryHome || U.isLauncherPermanentlyEnabled(this))) {
setContentView(layout);
if (isWallpaperEnabled) {
File file = new File(getFilesDir() + "/tb_images", "desktop_wallpaper");
if (file.exists()) {
U.applyCustomImage(this, "desktop_wallpaper", wallpaper, null);
getWindow().setNavigationBarColor(Color.BLACK);
}
}
pref.edit().putBoolean(PREF_LAUNCHER, !isSecondaryHome).putBoolean(PREF_DESKTOP_MODE, U.isDesktopModeSupported(this) && isSecondaryHome).apply();
} else
killHomeActivity();
updateWindowFlags();
U.registerReceiver(this, killReceiver, ACTION_KILL_HOME_ACTIVITY);
U.registerReceiver(this, forceTaskbarStartReceiver, ACTION_FORCE_TASKBAR_RESTART);
U.registerReceiver(this, freeformToggleReceiver, ACTION_UPDATE_FREEFORM_CHECKBOX, ACTION_TOUCH_ABSORBER_STATE_CHANGED, ACTION_FREEFORM_PREF_CHANGED);
if (isSecondaryHome)
U.registerReceiver(this, restartReceiver, ACTION_RESTART);
if (isWallpaperEnabled) {
U.registerReceiver(this, removeDesktopWallpaperReceiver, ACTION_REMOVE_DESKTOP_WALLPAPER);
U.registerReceiver(this, wallpaperChangeRequestReceiver, ACTION_WALLPAPER_CHANGE_REQUESTED);
}
if (isDesktopIconsEnabled) {
U.registerReceiver(this, refreshDesktopIconsReceiver, ACTION_REFRESH_DESKTOP_ICONS);
U.registerReceiver(this, iconArrangeModeReceiver, ACTION_ENTER_ICON_ARRANGE_MODE);
U.registerReceiver(this, sortDesktopIconsReceiver, ACTION_SORT_DESKTOP_ICONS);
U.registerReceiver(this, updateMarginsReceiver, ACTION_UPDATE_HOME_SCREEN_MARGINS);
LauncherApps launcherApps = (LauncherApps) getSystemService(LAUNCHER_APPS_SERVICE);
launcherApps.registerCallback(callback);
}
U.initPrefs(this);
}
use of com.farmerbb.taskbar.util.DisplayInfo in project Taskbar by farmerbb.
the class DesktopModeFragment method updateAdditionalSettings.
private void updateAdditionalSettings(boolean desktopModeEnabled) {
finishedLoadingPrefs = false;
boolean enabled = desktopModeEnabled && U.hasWriteSecureSettingsPermission(getActivity()) && U.isDesktopModeActive(getActivity());
findPreference(PREF_DISPLAY_DENSITY).setEnabled(enabled);
if (U.isShowHideNavbarSupported()) {
findPreference(PREF_AUTO_HIDE_NAVBAR_DESKTOP_MODE).setEnabled(enabled);
findPreference(PREF_AUTO_HIDE_NAVBAR_DESKTOP_MODE).setOnPreferenceClickListener(this);
}
SharedPreferences pref = U.getSharedPreferences(getActivity());
DisplayInfo info = U.getExternalDisplayInfo(getActivity());
String densityPrefValue = info.currentDensity == info.defaultDensity ? "reset" : Integer.toString(info.currentDensity);
pref.edit().putString(PREF_DISPLAY_DENSITY, densityPrefValue).apply();
String[] noDefaultList = getResources().getStringArray(R.array.tb_pref_display_density_list_alt);
String[] noDefaultValues = getResources().getStringArray(R.array.tb_pref_display_density_list_values_alt);
boolean useNoDefault = false;
for (int i = 0; i < noDefaultValues.length; i++) {
if (info.defaultDensity == Integer.parseInt(noDefaultValues[i])) {
noDefaultList[i] = getString(R.string.tb_density_default, info.defaultDensity);
noDefaultValues[i] = "reset";
useNoDefault = true;
break;
}
}
ListPreference densityPref = ((ListPreference) findPreference(PREF_DISPLAY_DENSITY));
if (useNoDefault) {
densityPref.setEntries(noDefaultList);
densityPref.setEntryValues(noDefaultValues);
} else {
densityPref.setEntries(R.array.tb_pref_display_density_list);
densityPref.setEntryValues(R.array.tb_pref_display_density_list_values);
}
densityPref.setValue(densityPrefValue);
bindPreferenceSummaryToValue(densityPref);
if (densityPref.getSummary() == null || densityPref.getSummary().equals(""))
densityPref.setSummary(getString(R.string.tb_density_custom, info.currentDensity));
finishedLoadingPrefs = true;
}
use of com.farmerbb.taskbar.util.DisplayInfo in project Taskbar by farmerbb.
the class ContextMenuActivity method onPostCreate.
@SuppressLint("RtlHardcoded")
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
U.sendBroadcast(this, ACTION_CONTEXT_MENU_APPEARING);
MenuHelper.getInstance().setContextMenuOpen(true);
Bundle args = getIntent().getBundleExtra("args");
entry = (AppEntry) args.getSerializable("app_entry");
desktopIcon = (DesktopIconInfo) args.getSerializable("desktop_icon");
showStartMenu = args.getBoolean("launched_from_start_menu", false);
isStartButton = entry == null && args.getBoolean("is_start_button", false);
isOverflowMenu = entry == null && args.getBoolean("is_overflow_menu", false);
contextMenuFix = args.containsKey(EXTRA_CONTEXT_MENU_FIX);
showQuitOption = !args.getBoolean("dont_show_quit", false);
// Determine where to position the dialog on screen
WindowManager.LayoutParams params = getWindow().getAttributes();
if (args.containsKey("x") && args.containsKey("y"))
U.applyDisplayCutoutModeTo(params);
DisplayInfo display = U.getDisplayInfo(this);
int statusBarHeight = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0)
statusBarHeight = getResources().getDimensionPixelSize(resourceId);
int contextMenuWidth = getResources().getDimensionPixelSize(R.dimen.tb_context_menu_width);
if (showStartMenu || desktopIcon != null) {
int x = args.getInt("x", 0);
int y = args.getInt("y", 0);
int offsetResourceId = isOverflowMenu ? R.dimen.tb_context_menu_offset_overflow : R.dimen.tb_context_menu_offset;
int offset = getResources().getDimensionPixelSize(offsetResourceId);
switch(TaskbarPosition.getTaskbarPosition(this)) {
case POSITION_BOTTOM_LEFT:
case POSITION_BOTTOM_VERTICAL_LEFT:
params.gravity = Gravity.BOTTOM | Gravity.LEFT;
params.x = x;
params.y = display.height - y - offset;
break;
case POSITION_BOTTOM_RIGHT:
case POSITION_BOTTOM_VERTICAL_RIGHT:
params.gravity = Gravity.BOTTOM | Gravity.LEFT;
params.x = x - contextMenuWidth + offset + offset;
params.y = display.height - y - offset;
break;
case POSITION_TOP_LEFT:
case POSITION_TOP_VERTICAL_LEFT:
params.gravity = Gravity.TOP | Gravity.LEFT;
params.x = x;
params.y = y - offset + statusBarHeight;
break;
case POSITION_TOP_RIGHT:
case POSITION_TOP_VERTICAL_RIGHT:
params.gravity = Gravity.TOP | Gravity.LEFT;
params.x = x - contextMenuWidth + offset + offset;
params.y = y - offset + statusBarHeight;
break;
}
} else {
U.sendBroadcast(this, ACTION_HIDE_START_MENU);
int x = args.getInt("x", display.width);
int y = args.getInt("y", display.height);
int offset = getResources().getDimensionPixelSize(R.dimen.tb_icon_size);
switch(TaskbarPosition.getTaskbarPosition(this)) {
case POSITION_BOTTOM_LEFT:
params.gravity = Gravity.BOTTOM | Gravity.LEFT;
params.x = isStartButton ? 0 : x;
params.y = offset;
break;
case POSITION_BOTTOM_VERTICAL_LEFT:
params.gravity = Gravity.BOTTOM | Gravity.LEFT;
params.x = offset;
params.y = display.height - y - (isStartButton ? 0 : offset);
break;
case POSITION_BOTTOM_RIGHT:
params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
params.x = display.width - x;
params.y = offset;
break;
case POSITION_BOTTOM_VERTICAL_RIGHT:
params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
params.x = offset;
params.y = display.height - y - (isStartButton ? 0 : offset);
break;
case POSITION_TOP_LEFT:
params.gravity = Gravity.TOP | Gravity.LEFT;
params.x = isStartButton ? 0 : x;
params.y = offset;
break;
case POSITION_TOP_VERTICAL_LEFT:
params.gravity = Gravity.TOP | Gravity.LEFT;
params.x = offset;
params.y = isStartButton ? 0 : y - statusBarHeight;
break;
case POSITION_TOP_RIGHT:
params.gravity = Gravity.TOP | Gravity.RIGHT;
params.x = display.width - x;
params.y = offset;
break;
case POSITION_TOP_VERTICAL_RIGHT:
params.gravity = Gravity.TOP | Gravity.RIGHT;
params.x = offset;
params.y = isStartButton ? 0 : y - statusBarHeight;
break;
}
if (!TaskbarPosition.isVertical(this) && (params.x > display.width / 2))
params.x = params.x - contextMenuWidth + offset;
}
params.width = getResources().getDimensionPixelSize(R.dimen.tb_context_menu_width);
params.dimAmount = 0;
if (U.isChromeOs(this) && TaskbarPosition.isBottom(this)) {
SharedPreferences pref = U.getSharedPreferences(this);
if (U.getChromeOsContextMenuFix(this) && !pref.getBoolean(PREF_HAS_CAPTION, false))
params.y = params.y - getResources().getDimensionPixelSize(R.dimen.tb_caption_offset);
}
getWindow().setAttributes(params);
if (U.isChromeOs(this) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1 && U.getCurrentApiVersion() < 30.0f) {
getWindow().setElevation(0);
}
View view = findViewById(android.R.id.list);
if (view != null)
view.setPadding(0, 0, 0, 0);
generateMenu();
U.registerReceiver(this, dashboardOrStartMenuAppearingReceiver, ACTION_START_MENU_APPEARING, ACTION_DASHBOARD_APPEARING);
U.registerReceiver(this, finishReceiver, ACTION_HIDE_CONTEXT_MENU);
}
Aggregations