OSDN Git Service

Fix incorrect usage of getComponentEnabledSetting()
[android-x86/packages-apps-Gallery2.git] / src / com / android / gallery3d / util / GalleryUtils.java
index 547e2dd..9a78fcd 100644 (file)
@@ -37,7 +37,7 @@ import android.util.Log;
 import android.view.WindowManager;
 
 import com.android.gallery3d.R;
-import com.android.gallery3d.app.Gallery;
+import com.android.gallery3d.app.GalleryActivity;
 import com.android.gallery3d.app.PackagesMonitor;
 import com.android.gallery3d.common.ApiHelper;
 import com.android.gallery3d.data.DataManager;
@@ -46,6 +46,7 @@ import com.android.gallery3d.ui.TiledScreenNail;
 import com.android.gallery3d.util.ThreadPool.CancelListener;
 import com.android.gallery3d.util.ThreadPool.JobContext;
 
+import java.io.File;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Locale;
@@ -94,14 +95,6 @@ public class GalleryUtils {
         TiledScreenNail.setMaxSide(maxPixels / 2);
     }
 
-    public static boolean isHighResolution(Context context) {
-        DisplayMetrics metrics = new DisplayMetrics();
-        WindowManager wm = (WindowManager)
-                context.getSystemService(Context.WINDOW_SERVICE);
-        wm.getDefaultDisplay().getMetrics(metrics);
-        return metrics.heightPixels > 2048 ||  metrics.widthPixels > 2048;
-    }
-
     public static float[] intColorToFloatARGBArray(int from) {
         return new float[] {
             Color.alpha(from) / 255f,
@@ -246,8 +239,8 @@ public class GalleryUtils {
         int state = pm.getComponentEnabledSetting(name);
         sCameraAvailableInitialized = true;
         sCameraAvailable =
-            (state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)
-             || (state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
+           (state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)
+           || (state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
         return sCameraAvailable;
     }
 
@@ -259,7 +252,9 @@ public class GalleryUtils {
     }
 
     public static void startGalleryActivity(Context context) {
-        Intent intent = new Intent(context, Gallery.class);
+        Intent intent = new Intent(context, GalleryActivity.class)
+                .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
+                | Intent.FLAG_ACTIVITY_NEW_TASK);
         context.startActivity(intent);
     }
 
@@ -315,6 +310,26 @@ public class GalleryUtils {
         return path.toLowerCase().hashCode();
     }
 
+    // Return the local path that matches the given bucketId. If no match is
+    // found, return null
+    public static String searchDirForPath(File dir, int bucketId) {
+        File[] files = dir.listFiles();
+        if (files != null) {
+            for (File file : files) {
+                if (file.isDirectory()) {
+                    String path = file.getAbsolutePath();
+                    if (GalleryUtils.getBucketId(path) == bucketId) {
+                        return path;
+                    } else {
+                        path = searchDirForPath(file, bucketId);
+                        if (path != null) return path;
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
     // Returns a (localized) string for the given duration (in seconds).
     public static String formatDuration(final Context context, int duration) {
         int h = duration / 3600;