1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.gallery3d.util;
18 
19 import android.os.Environment;
20 
21 import com.android.gallery3d.data.LocalAlbum;
22 import com.android.gallery3d.data.LocalMergeAlbum;
23 import com.android.gallery3d.data.MediaSet;
24 import com.android.gallery3d.data.Path;
25 
26 import java.util.Comparator;
27 
28 public class MediaSetUtils {
29     public static final Comparator<MediaSet> NAME_COMPARATOR = new NameComparator();
30 
31     public static final int CAMERA_BUCKET_ID = GalleryUtils.getBucketId(
32             Environment.getExternalStorageDirectory().toString() + "/"
33             + BucketNames.CAMERA);
34     public static final int DOWNLOAD_BUCKET_ID = GalleryUtils.getBucketId(
35             Environment.getExternalStorageDirectory().toString() + "/"
36             + BucketNames.DOWNLOAD);
37     public static final int EDITED_ONLINE_PHOTOS_BUCKET_ID = GalleryUtils.getBucketId(
38             Environment.getExternalStorageDirectory().toString() + "/"
39             + BucketNames.EDITED_ONLINE_PHOTOS);
40     public static final int IMPORTED_BUCKET_ID = GalleryUtils.getBucketId(
41             Environment.getExternalStorageDirectory().toString() + "/"
42             + BucketNames.IMPORTED);
43     public static final int SNAPSHOT_BUCKET_ID = GalleryUtils.getBucketId(
44             Environment.getExternalStorageDirectory().toString() +
45             "/" + BucketNames.SCREENSHOTS);
46 
47     private static final Path[] CAMERA_PATHS = {
48             Path.fromString("/local/all/" + CAMERA_BUCKET_ID),
49             Path.fromString("/local/image/" + CAMERA_BUCKET_ID),
50             Path.fromString("/local/video/" + CAMERA_BUCKET_ID)};
51 
isCameraSource(Path path)52     public static boolean isCameraSource(Path path) {
53         return CAMERA_PATHS[0] == path || CAMERA_PATHS[1] == path
54                 || CAMERA_PATHS[2] == path;
55     }
56 
57     // Sort MediaSets by name
58     public static class NameComparator implements Comparator<MediaSet> {
59         @Override
compare(MediaSet set1, MediaSet set2)60         public int compare(MediaSet set1, MediaSet set2) {
61             int result = set1.getName().compareToIgnoreCase(set2.getName());
62             if (result != 0) return result;
63             return set1.getPath().toString().compareTo(set2.getPath().toString());
64         }
65     }
66 }
67