Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 276e6c7a authored by Michael Jurka's avatar Michael Jurka Committed by Android (Google) Code Review
Browse files

Merge "Add new intent/method for cropping and setting wallpapers" into klp-dev

parents 750ce3ac e8d1bf7a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -4364,6 +4364,7 @@ package android.app {
    method public void clear() throws java.io.IOException;
    method public void clearWallpaperOffsets(android.os.IBinder);
    method public void forgetLoadedWallpaper();
    method public android.content.Intent getCropAndSetWallpaperIntent(android.net.Uri);
    method public int getDesiredMinimumHeight();
    method public int getDesiredMinimumWidth();
    method public android.graphics.drawable.Drawable getDrawable();
@@ -4381,6 +4382,7 @@ package android.app {
    method public void setWallpaperOffsets(android.os.IBinder, float, float);
    method public void suggestDesiredDimensions(int, int);
    field public static final java.lang.String ACTION_CHANGE_LIVE_WALLPAPER = "android.service.wallpaper.CHANGE_LIVE_WALLPAPER";
    field public static final java.lang.String ACTION_CROP_AND_SET_WALLPAPER = "android.service.wallpaper.CROP_AND_SET_WALLPAPER";
    field public static final java.lang.String ACTION_LIVE_WALLPAPER_CHOOSER = "android.service.wallpaper.LIVE_WALLPAPER_CHOOSER";
    field public static final java.lang.String COMMAND_DROP = "android.home.drop";
    field public static final java.lang.String COMMAND_SECONDARY_TAP = "android.wallpaper.secondaryTap";
+47 −3
Original line number Diff line number Diff line
@@ -16,8 +16,11 @@

package android.app;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@@ -30,7 +33,7 @@ import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Binder;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
@@ -41,13 +44,13 @@ import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.ViewRootImpl;
import android.view.WindowManager;
import android.view.WindowManagerGlobal;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * Provides access to the system wallpaper. With WallpaperManager, you can
@@ -61,6 +64,15 @@ public class WallpaperManager {
    private float mWallpaperXStep = -1;
    private float mWallpaperYStep = -1;

    /**
     * Activity Action: Show settings for choosing wallpaper. Do not use directly to construct
     * an intent; instead, use {@link #getCropAndSetWallpaperIntent}.
     * <p>Input:  {@link Intent#getData} is the URI of the image to crop and set as wallpaper.
     * <p>Output: RESULT_OK if user decided to crop/set the wallpaper, RESULT_CANCEL otherwise
     */
    public static final String ACTION_CROP_AND_SET_WALLPAPER =
            "android.service.wallpaper.CROP_AND_SET_WALLPAPER";

    /**
     * Launch an activity for the user to pick the current global live
     * wallpaper.
@@ -464,6 +476,38 @@ public class WallpaperManager {
        }
    }

    /**
     * Gets an Intent that will launch an activity that crops the given
     * image and sets the device's wallpaper. If there is a default HOME activity
     * that supports cropping wallpapers, it will be preferred as the default.
     * Use this method instead of directly creating a {@link Intent#CROP_AND_SET_WALLPAPER}
     * intent.
     */
    public Intent getCropAndSetWallpaperIntent(Uri imageUri) {
        final PackageManager packageManager = mContext.getPackageManager();
        Intent cropAndSetWallpaperIntent =
                new Intent(ACTION_CROP_AND_SET_WALLPAPER, imageUri);
        cropAndSetWallpaperIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

        // Find out if the default HOME activity supports CROP_AND_SET_WALLPAPER
        Intent homeIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME);
        ResolveInfo resolvedHome = packageManager.resolveActivity(homeIntent,
                PackageManager.MATCH_DEFAULT_ONLY);
        if (resolvedHome != null) {
            cropAndSetWallpaperIntent.setPackage(resolvedHome.activityInfo.packageName);

            List<ResolveInfo> cropAppList = packageManager.queryIntentActivities(
                    cropAndSetWallpaperIntent, 0);
            if (cropAppList.size() > 0) {
                return cropAndSetWallpaperIntent;
            }
        }

        // fallback crop activity
        cropAndSetWallpaperIntent.setPackage("com.android.wallpapercropper");
        return cropAndSetWallpaperIntent;
    }

    /**
     * Change the current system wallpaper to the bitmap in the given resource.
     * The resource is opened as a raw data stream and copied into the
+19 −0
Original line number Diff line number Diff line
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_JAVA_LIBRARIES := telephony-common
LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4

LOCAL_PACKAGE_NAME := WallpaperCropper
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true

LOCAL_PROGUARD_FLAG_FILES := proguard.flags

include $(BUILD_PACKAGE)

include $(call all-makefiles-under,$(LOCAL_PATH))
+19 −0
Original line number Diff line number Diff line
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.android.wallpapercropper" >
        <uses-permission android:name="android.permission.SET_WALLPAPER" />
        <uses-permission android:name="android.permission.SET_WALLPAPER_HINTS" />

        <application android:requiredForAllUsers="true">
        <activity
            android:name="WallpaperCropActivity"
            android:theme="@style/Theme.WallpaperCropper"
            android:label="@string/crop_wallpaper"
            android:finishOnCloseSystemDialogs="true">
            <intent-filter>
                <action android:name="android.service.wallpaper.CROP_AND_SET_WALLPAPER" />
                <data android:mimeType="image/*" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        </application>
</manifest>
+0 −0

Empty file added.

Loading