MediaSetUtils.java revision 7eea4d3ac59aa88d327fc0d58f5e4052f43c54c9
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
17package com.android.gallery3d.util;
18
19import android.os.Environment;
20
21import com.android.gallery3d.data.LocalAlbum;
22import com.android.gallery3d.data.LocalMergeAlbum;
23import com.android.gallery3d.data.MediaSet;
24import com.android.gallery3d.data.Path;
25
26import java.util.Comparator;
27
28public 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() + "/DCIM/Camera");
33    public static final int DOWNLOAD_BUCKET_ID = GalleryUtils.getBucketId(
34            Environment.getExternalStorageDirectory().toString() + "/"
35            + BucketNames.DOWNLOAD);
36    public static final int IMPORTED_BUCKET_ID = GalleryUtils.getBucketId(
37            Environment.getExternalStorageDirectory().toString() + "/"
38            + BucketNames.IMPORTED);
39    public static final int SNAPSHOT_BUCKET_ID = GalleryUtils.getBucketId(
40            Environment.getExternalStorageDirectory().toString() +
41            "/Pictures/Screenshots");
42
43    private static final Path[] CAMERA_PATHS = {
44            Path.fromString("/local/all/" + CAMERA_BUCKET_ID),
45            Path.fromString("/local/image/" + CAMERA_BUCKET_ID),
46            Path.fromString("/local/video/" + CAMERA_BUCKET_ID)};
47
48    public static boolean isCameraSource(Path path) {
49        return CAMERA_PATHS[0] == path || CAMERA_PATHS[1] == path
50                || CAMERA_PATHS[2] == path;
51    }
52
53    // Sort MediaSets by name
54    public static class NameComparator implements Comparator<MediaSet> {
55        @Override
56        public int compare(MediaSet set1, MediaSet set2) {
57            int result = set1.getName().compareToIgnoreCase(set2.getName());
58            if (result != 0) return result;
59            return set1.getPath().toString().compareTo(set2.getPath().toString());
60        }
61    }
62}
63