Search in sources :

Example 26 with WallpaperManager

use of android.app.WallpaperManager in project android_packages_apps_Gallery2 by LineageOS.

the class Wallpaper method onResume.

@SuppressWarnings("fallthrough")
@Override
protected void onResume() {
    super.onResume();
    Intent intent = getIntent();
    switch(mState) {
        case STATE_INIT:
            {
                mPickedItem = intent.getData();
                if (mPickedItem == null) {
                    Intent request = new Intent(Intent.ACTION_GET_CONTENT).setClass(this, DialogPicker.class).setType(IMAGE_TYPE);
                    startActivityForResult(request, STATE_PHOTO_PICKED);
                    return;
                }
                mState = STATE_PHOTO_PICKED;
            // fall-through
            }
        case STATE_PHOTO_PICKED:
            {
                Intent cropAndSetWallpaperIntent;
                boolean fromScreenColor = false;
                // Do this for screencolor select and crop image to preview.
                Bundle extras = intent.getExtras();
                if (extras != null) {
                    fromScreenColor = extras.getBoolean(KEY_FROM_SCREENCOLOR, false);
                }
                if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) && (!fromScreenColor)) {
                    WallpaperManager wpm = WallpaperManager.getInstance(getApplicationContext());
                    try {
                        cropAndSetWallpaperIntent = wpm.getCropAndSetWallpaperIntent(mPickedItem);
                        startActivity(cropAndSetWallpaperIntent);
                        finish();
                        return;
                    } catch (ActivityNotFoundException anfe) {
                    // ignored; fallthru to existing crop activity
                    } catch (IllegalArgumentException iae) {
                    // ignored; fallthru to existing crop activity
                    }
                }
                int width, height;
                float spotlightX, spotlightY;
                if (fromScreenColor) {
                    width = extras.getInt(KEY_ASPECT_X, 0);
                    height = extras.getInt(KEY_ASPECT_Y, 0);
                    spotlightX = extras.getFloat(KEY_SPOTLIGHT_X, 0);
                    spotlightY = extras.getFloat(KEY_SPOTLIGHT_Y, 0);
                } else {
                    width = getWallpaperDesiredMinimumWidth();
                    height = getWallpaperDesiredMinimumHeight();
                    Point size = getDefaultDisplaySize(new Point());
                    spotlightX = (float) size.x / width;
                    spotlightY = (float) size.y / height;
                }
                // Don't set wallpaper from screencolor.
                cropAndSetWallpaperIntent = new Intent(CropActivity.CROP_ACTION).setClass(this, CropActivity.class).setDataAndType(mPickedItem, IMAGE_TYPE).addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT).putExtra(CropExtras.KEY_OUTPUT_X, width).putExtra(CropExtras.KEY_OUTPUT_Y, height).putExtra(CropExtras.KEY_ASPECT_X, width).putExtra(CropExtras.KEY_ASPECT_Y, height).putExtra(CropExtras.KEY_SPOTLIGHT_X, spotlightX).putExtra(CropExtras.KEY_SPOTLIGHT_Y, spotlightY).putExtra(CropExtras.KEY_SCALE, true).putExtra(CropExtras.KEY_SCALE_UP_IF_NEEDED, true).putExtra(CropExtras.KEY_SET_AS_WALLPAPER, !fromScreenColor);
                startActivity(cropAndSetWallpaperIntent);
                finish();
            }
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) Bundle(android.os.Bundle) Intent(android.content.Intent) Point(android.graphics.Point) CropActivity(com.android.gallery3d.filtershow.crop.CropActivity) WallpaperManager(android.app.WallpaperManager) IllegalArgumentException(java.lang.IllegalArgumentException)

Example 27 with WallpaperManager

use of android.app.WallpaperManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

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 28 with WallpaperManager

use of android.app.WallpaperManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

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

Example 29 with WallpaperManager

use of android.app.WallpaperManager in project Fairphone by Kwamecorp.

the class WallpaperChooserDialogFragment method selectWallpaper.

private void selectWallpaper(int position) {
    try {
        WallpaperManager wpm = (WallpaperManager) getActivity().getSystemService(Context.WALLPAPER_SERVICE);
        wpm.setResource(mImages.get(position));
        Activity activity = getActivity();
        activity.setResult(Activity.RESULT_OK);
        activity.finish();
    } catch (IOException e) {
        Log.e(TAG, "Failed to set wallpaper: " + e);
    }
}
Also used : Activity(android.app.Activity) IOException(java.io.IOException) WallpaperManager(android.app.WallpaperManager)

Example 30 with WallpaperManager

use of android.app.WallpaperManager in project Fairphone by Kwamecorp.

the class UserInitializeReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    final Resources resources = context.getResources();
    // Context.getPackageName() may return the "original" package name,
    // com.android.launcher2; Resources needs the real package name,
    // com.android.launcher. So we ask Resources for what it thinks the
    // package name should be.
    final String packageName = resources.getResourcePackageName(R.array.wallpapers);
    ArrayList<Integer> list = new ArrayList<Integer>();
    addWallpapers(resources, packageName, R.array.wallpapers, list);
    addWallpapers(resources, packageName, R.array.extra_wallpapers, list);
    WallpaperManager wpm = (WallpaperManager) context.getSystemService(Context.WALLPAPER_SERVICE);
    for (int i = 1; i < list.size(); i++) {
        int resid = list.get(i);
        if (!wpm.hasResourceWallpaper(resid)) {
            try {
                wpm.setResource(resid);
            } catch (IOException e) {
            }
            return;
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Resources(android.content.res.Resources) 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