use of android.app.WallpaperManager in project xDrip by NightscoutFoundation.
the class LockScreenWallPaper method setBitmap.
@SuppressLint("WrongConstant")
public static void setBitmap(final Bitmap bitmap) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
try {
final WallpaperManager wallpaperManager = WallpaperManager.getInstance(xdrip.getAppContext());
final Bitmap wallpaper = BitmapUtil.getTiled(bitmap, getScreenWidth(), getScreenHeight(), isLockScreenBitmapTiled(), Pref.getString(NumberWallPreview.ViewModel.PREF_numberwall_background, null));
wallpaperManager.setBitmap(wallpaper, null, false, FLAG_LOCK);
wallpaper.recycle();
} catch (Exception e) {
UserError.Log.e(TAG, "Failed to set wallpaper: " + e);
}
}
}
use of android.app.WallpaperManager 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 android.app.WallpaperManager in project android_packages_apps_Settings by omnirom.
the class FallbackHomeActivityTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
final Application application = RuntimeEnvironment.application;
WallpaperManager wallpaperManager = WallpaperManager.getInstance(application);
ShadowApplication shadowApplication = Shadows.shadowOf(application);
shadowApplication.setSystemService(Context.WALLPAPER_SERVICE, wallpaperManager);
mController = Robolectric.buildActivity(FallbackHome.class);
}
use of android.app.WallpaperManager in project android_packages_apps_Settings by omnirom.
the class FallbackHomeActivityTest method wallpaperColorsChangedListener_ensured_removed.
@Test
@Config(shadows = ShadowWallpaperManager.class)
public void wallpaperColorsChangedListener_ensured_removed() {
// onCreate adds the first color listener by WallpaperManager returning null colors
ActivityController controller = mController.setup();
ShadowWallpaperManager shadowManager = Shadow.extract(RuntimeEnvironment.application.getSystemService(WallpaperManager.class));
assertThat(shadowManager.size()).isEqualTo(1);
// Assert onDestroy will remove the original listener
controller.destroy();
assertThat(shadowManager.size()).isEqualTo(0);
}
use of android.app.WallpaperManager in project apps-android-commons by commons-app.
the class ImageUtils method setWallpaper.
private static void setWallpaper(Context context, Bitmap bitmap) {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
try {
wallpaperManager.setBitmap(bitmap);
ViewUtil.showLongToast(context, context.getString(R.string.wallpaper_set_successfully));
if (progressDialogWallpaper != null && progressDialogWallpaper.isShowing()) {
progressDialogWallpaper.dismiss();
}
} catch (IOException e) {
Timber.e(e, "Error setting wallpaper");
ViewUtil.showLongToast(context, context.getString(R.string.wallpaper_set_unsuccessfully));
if (progressDialogWallpaper != null) {
progressDialogWallpaper.cancel();
}
}
}
Aggregations