Search in sources :

Example 31 with WallpaperManager

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);
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) WallpaperManager(android.app.WallpaperManager) SuppressLint(android.annotation.SuppressLint)

Example 32 with WallpaperManager

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);
}
Also used : Bundle(android.os.Bundle) StartMenuService(com.farmerbb.taskbar.service.StartMenuService) TaskbarPosition(com.farmerbb.taskbar.util.TaskbarPosition) WindowManager(android.view.WindowManager) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) GlobalHelper(com.farmerbb.taskbar.helper.GlobalHelper) NotificationService(com.farmerbb.taskbar.service.NotificationService) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) WallpaperManager(android.app.WallpaperManager) FABWrapper(com.farmerbb.taskbar.util.FABWrapper) ColorStateList(android.content.res.ColorStateList) DisplayInfo(com.farmerbb.taskbar.util.DisplayInfo) JSONException(org.json.JSONException) UIHost(com.farmerbb.taskbar.ui.UIHost) Display(android.view.Display) View(android.view.View) ContextCompat(androidx.core.content.ContextCompat) TargetApi(android.annotation.TargetApi) DesktopIconInfo(com.farmerbb.taskbar.util.DesktopIconInfo) GridLayout(android.widget.GridLayout) DragEvent(android.view.DragEvent) U(com.farmerbb.taskbar.util.U) AppEntry(com.farmerbb.taskbar.util.AppEntry) BroadcastReceiver(android.content.BroadcastReceiver) ViewGroup(android.view.ViewGroup) LauncherHelper(com.farmerbb.taskbar.helper.LauncherHelper) AlertDialog(android.app.AlertDialog) LauncherApps(android.content.pm.LauncherApps) SparseArray(android.util.SparseArray) FreeformHackHelper(com.farmerbb.taskbar.helper.FreeformHackHelper) List(java.util.List) TextView(android.widget.TextView) MenuHelper(com.farmerbb.taskbar.helper.MenuHelper) ActivityNotFoundException(android.content.ActivityNotFoundException) ViewParams(com.farmerbb.taskbar.ui.ViewParams) Context(android.content.Context) GestureDetector(android.view.GestureDetector) StartMenuController(com.farmerbb.taskbar.ui.StartMenuController) Intent(android.content.Intent) ArrayList(java.util.ArrayList) ClipData(android.content.ClipData) SuppressLint(android.annotation.SuppressLint) DisplayHelper(com.farmerbb.taskbar.helper.DisplayHelper) MotionEvent(android.view.MotionEvent) UserHandle(android.os.UserHandle) Build(android.os.Build) Collator(java.text.Collator) UserManager(android.os.UserManager) R(com.farmerbb.taskbar.R) ComponentName(android.content.ComponentName) LayoutInflater(android.view.LayoutInflater) File(java.io.File) Color(android.graphics.Color) Gravity(android.view.Gravity) Callbacks(com.farmerbb.taskbar.util.Callbacks) TaskbarService(com.farmerbb.taskbar.service.TaskbarService) DashboardController(com.farmerbb.taskbar.ui.DashboardController) SharedPreferences(android.content.SharedPreferences) DashboardService(com.farmerbb.taskbar.service.DashboardService) TaskbarController(com.farmerbb.taskbar.ui.TaskbarController) ViewTreeObserver(android.view.ViewTreeObserver) ColorUtils(androidx.core.graphics.ColorUtils) Collections(java.util.Collections) JSONArray(org.json.JSONArray) Constants(com.farmerbb.taskbar.util.Constants) AlertDialog(android.app.AlertDialog) GestureDetector(android.view.GestureDetector) WindowManager(android.view.WindowManager) ImageView(android.widget.ImageView) ViewTreeObserver(android.view.ViewTreeObserver) DisplayInfo(com.farmerbb.taskbar.util.DisplayInfo) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) LauncherApps(android.content.pm.LauncherApps) MotionEvent(android.view.MotionEvent) FrameLayout(android.widget.FrameLayout) WallpaperManager(android.app.WallpaperManager) File(java.io.File) Display(android.view.Display) SuppressLint(android.annotation.SuppressLint)

Example 33 with WallpaperManager

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);
}
Also used : FallbackHome(com.android.settings.FallbackHome) ShadowApplication(org.robolectric.shadows.ShadowApplication) ShadowApplication(org.robolectric.shadows.ShadowApplication) Application(android.app.Application) WallpaperManager(android.app.WallpaperManager) Before(org.junit.Before)

Example 34 with WallpaperManager

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);
}
Also used : ActivityController(org.robolectric.android.controller.ActivityController) WallpaperManager(android.app.WallpaperManager) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 35 with WallpaperManager

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();
        }
    }
}
Also used : IOException(java.io.IOException) WallpaperManager(android.app.WallpaperManager)

Aggregations

WallpaperManager (android.app.WallpaperManager)36 IOException (java.io.IOException)15 Bitmap (android.graphics.Bitmap)11 Intent (android.content.Intent)6 Context (android.content.Context)5 Rect (android.graphics.Rect)5 Bundle (android.os.Bundle)5 WindowManager (android.view.WindowManager)5 SuppressLint (android.annotation.SuppressLint)4 Application (android.app.Application)4 Handler (android.os.Handler)4 DisplayMetrics (android.util.DisplayMetrics)4 Display (android.view.Display)4 Before (org.junit.Before)4 Test (org.junit.Test)4 ShadowApplication (org.robolectric.shadows.ShadowApplication)4 Activity (android.app.Activity)3 ActivityNotFoundException (android.content.ActivityNotFoundException)3 Matrix (android.graphics.Matrix)3 TargetApi (android.annotation.TargetApi)2