OSDN Git Service

Don't use Display.getSize().
authorOwen Lin <owenlin@google.com>
Wed, 27 Jun 2012 07:28:07 +0000 (15:28 +0800)
committerOwen Lin <owenlin@google.com>
Wed, 27 Jun 2012 07:36:34 +0000 (15:36 +0800)
Change-Id: I9b5c9021bae2b58d2815a909c97104f215d4d2e8

src/com/android/gallery3d/app/Wallpaper.java
src/com/android/gallery3d/util/GalleryUtils.java

index c08c1d7..d64eecd 100644 (file)
 
 package com.android.gallery3d.app;
 
+import android.annotation.TargetApi;
 import android.app.Activity;
 import android.content.Intent;
 import android.graphics.Point;
 import android.net.Uri;
+import android.os.Build;
 import android.os.Bundle;
+import android.view.Display;
 
 /**
  * Wallpaper picker for the gallery application. This just redirects to the
@@ -57,6 +60,18 @@ public class Wallpaper extends Activity {
         }
     }
 
+    @SuppressWarnings("deprecation")
+    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
+    private Point getDefaultDisplaySize(Point size) {
+        Display d = getWindowManager().getDefaultDisplay();
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
+            d.getSize(size);
+        } else {
+            size.set(d.getWidth(), d.getHeight());
+        }
+        return size;
+    }
+
     @SuppressWarnings("fallthrough")
     @Override
     protected void onResume() {
@@ -78,8 +93,7 @@ public class Wallpaper extends Activity {
             case STATE_PHOTO_PICKED: {
                 int width = getWallpaperDesiredMinimumWidth();
                 int height = getWallpaperDesiredMinimumHeight();
-                Point size = new Point();
-                getWindowManager().getDefaultDisplay().getSize(size);
+                Point size = getDefaultDisplaySize(new Point());
                 float spotlightX = (float) size.x / width;
                 float spotlightY = (float) size.y / height;
                 Intent request = new Intent(CropImage.ACTION_CROP)
index 1d70914..1291ee9 100644 (file)
@@ -16,7 +16,6 @@
 
 package com.android.gallery3d.util;
 
-import android.app.Activity;
 import android.content.ActivityNotFoundException;
 import android.content.ComponentName;
 import android.content.Context;
@@ -24,7 +23,6 @@ import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
-import android.content.res.Resources;
 import android.net.Uri;
 import android.os.ConditionVariable;
 import android.os.Environment;