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();
}
}
}
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);
}
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);
}
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);
}
}
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;
}
}
}
Aggregations