OSDN Git Service

Update to using new crop intent
authorMichael Jurka <mikejurka@google.com>
Wed, 11 Sep 2013 22:05:02 +0000 (00:05 +0200)
committerMichael Jurka <mikejurka@google.com>
Fri, 13 Sep 2013 16:16:54 +0000 (18:16 +0200)
Also, unify WallpaperCropActivity so it's
identical to the system default version (mainly
removing Launcher dependencies)

Change-Id: I1ebc390bce23de62d76daced6f8cb44d57e4ac0c

AndroidManifest.xml
res/values/strings.xml
res/values/styles.xml
src/com/android/launcher3/WallpaperCropActivity.java
src/com/android/launcher3/Workspace.java

index 996bef7..14fb044 100644 (file)
 
         <activity
             android:name="com.android.launcher3.WallpaperPickerActivity"
-            android:theme="@style/Theme.WallpaperPicker"
+            android:theme="@style/Theme.WallpaperCropper"
             android:label="@string/pick_wallpaper"
             android:icon="@mipmap/ic_launcher_wallpaper"
             android:finishOnCloseSystemDialogs="true"
             android:process=":wallpaper_chooser">
             <intent-filter>
-                <action android:name="android.intent.action.CROP_AND_SET_WALLPAPER" />
+                <action android:name="android.intent.action.SET_WALLPAPER" />
                 <category android:name="android.intent.category.DEFAULT" />
-                <data android:mimeType="image/*" />
             </intent-filter>
         </activity>
 
         <activity
             android:name="com.android.launcher3.WallpaperCropActivity"
-            android:theme="@style/Theme.WallpaperPicker"
-            android:label="@string/pick_wallpaper"
+            android:theme="@style/Theme.WallpaperCropper"
+            android:label="@string/crop_wallpaper"
             android:icon="@mipmap/ic_launcher_wallpaper"
             android:finishOnCloseSystemDialogs="true"
             android:process=":wallpaper_chooser">
             <intent-filter>
-                <action android:name="com.android.launcher3.action.CROP_AND_SET_WALLPAPER" />
+                <action android:name="android.service.wallpaper.CROP_AND_SET_WALLPAPER" />
                 <category android:name="android.intent.category.DEFAULT" />
+                <data android:mimeType="image/*" />
             </intent-filter>
         </activity>
 
index bd803c6..e04902a 100644 (file)
@@ -45,6 +45,8 @@
     <string name="gallery">Gallery</string>
     <!-- Option in "Select wallpaper from" dialog box -->
     <string name="pick_wallpaper">Wallpapers</string>
+    <!-- Title of activity for cropping wallpapers -->
+    <string name="crop_wallpaper">Crop wallpaper</string>
     <!-- Displayed when user selects a shortcut for an app that was uninstalled [CHAR_LIMIT=none]-->
     <string name="activity_not_found">App isn\'t installed.</string>
     <!--  Labels for the tabs in the customize drawer -->
index 6eb044c..618bb47 100644 (file)
 -->
 
 <resources>
-    <style name="Theme.WallpaperPicker" parent="@android:style/Theme.Holo">
-        <item name="android:actionBarStyle">@style/WallpaperPickerActionBar</item>
+    <style name="Theme.WallpaperCropper" parent="@android:style/Theme.Holo">
+        <item name="android:actionBarStyle">@style/WallpaperCropperActionBar</item>
         <item name="android:windowFullscreen">true</item>
         <item name="android:windowActionBarOverlay">true</item>
     </style>
 
-    <style name="WallpaperPickerActionBar" parent="android:style/Widget.Holo.ActionBar">
+    <style name="WallpaperCropperActionBar" parent="android:style/Widget.Holo.ActionBar">
         <item name="android:displayOptions">showCustom</item>
         <item name="android:background">#88000000</item>
     </style>
index dee9fe9..f5a6b80 100644 (file)
@@ -22,6 +22,7 @@ import android.app.WallpaperManager;
 import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
+import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.Bitmap.CompressFormat;
@@ -100,6 +101,10 @@ public class WallpaperCropActivity extends Activity {
                 });
     }
 
+    public static String getSharedPreferencesKey() {
+        return WallpaperCropActivity.class.getName();
+    }
+
     // As a ratio of screen height, the total distance we want the parallax effect to span
     // horizontally
     private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
@@ -145,7 +150,7 @@ public class WallpaperCropActivity extends Activity {
         // for the intended
         // parallax effects
         final int defaultWidth, defaultHeight;
-        if (LauncherAppState.isScreenLarge(res)) {
+        if (isScreenLarge(res)) {
             defaultWidth = (int) (maxDim * wallpaperTravelToScreenWidthRatio(maxDim, minDim));
             defaultHeight = maxDim;
         } else {
@@ -200,6 +205,11 @@ public class WallpaperCropActivity extends Activity {
         cropTask.execute();
     }
 
+    private static boolean isScreenLarge(Resources res) {
+        Configuration config = res.getConfiguration();
+        return config.smallestScreenWidthDp >= 720;
+    }
+
     protected void cropImageAndSetWallpaper(Uri uri,
             OnBitmapCroppedHandler onBitmapCroppedHandler, final boolean finishActivityWhenDone) {
      // Get the crop
@@ -216,7 +226,7 @@ public class WallpaperCropActivity extends Activity {
         int maxDim = Math.max(maxDims.x, maxDims.y);
         final int minDim = Math.min(minDims.x, minDims.y);
         int defaultWidth;
-        if (LauncherAppState.isScreenLarge(getResources())) {
+        if (isScreenLarge(getResources())) {
             defaultWidth = (int) (maxDim *
                     wallpaperTravelToScreenWidthRatio(maxDim, minDim));
         } else {
@@ -564,7 +574,7 @@ public class WallpaperCropActivity extends Activity {
     }
 
     protected void updateWallpaperDimensions(int width, int height) {
-        String spKey = LauncherAppState.getSharedPreferencesKey();
+        String spKey = getSharedPreferencesKey();
         SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
         SharedPreferences.Editor editor = sp.edit();
         if (width != 0 && height != 0) {
index 3f63d74..9f4fa8a 100644 (file)
@@ -30,6 +30,7 @@ import android.appwidget.AppWidgetProviderInfo;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
+import android.content.SharedPreferences;
 import android.content.res.Resources;
 import android.content.res.TypedArray;
 import android.graphics.Bitmap;
@@ -977,8 +978,10 @@ public class Workspace extends SmoothPagedView
     };
 
     protected void setWallpaperDimension() {
+        String spKey = WallpaperCropActivity.getSharedPreferencesKey();
+        SharedPreferences sp = mLauncher.getSharedPreferences(spKey, Context.MODE_PRIVATE);
         WallpaperPickerActivity.suggestWallpaperDimension(mLauncher.getResources(),
-                mLauncher.getSharedPrefs(), mLauncher.getWindowManager(), mWallpaperManager);
+                sp, mLauncher.getWindowManager(), mWallpaperManager);
     }