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 com.android.gallery3d.data.MediaSet;
20import com.android.gallery3d.data.MtpContext;
21import com.android.gallery3d.data.Path;
22
23import android.os.Environment;
24
25import java.util.Comparator;
26
27public class MediaSetUtils {
28    public static final Comparator<MediaSet> NAME_COMPARATOR = new NameComparator();
29
30    public static final int CAMERA_BUCKET_ID = GalleryUtils.getBucketId(
31            Environment.getExternalStorageDirectory().toString() + "/DCIM/Camera");
32    public static final int DOWNLOAD_BUCKET_ID = GalleryUtils.getBucketId(
33            Environment.getExternalStorageDirectory().toString() + "/download");
34    public static final int IMPORTED_BUCKET_ID = GalleryUtils.getBucketId(
35            Environment.getExternalStorageDirectory().toString() + "/"
36            + MtpContext.NAME_IMPORTED_FOLDER);
37
38    private static final Path[] CAMERA_PATHS = {
39            Path.fromString("/local/all/" + CAMERA_BUCKET_ID),
40            Path.fromString("/local/image/" + CAMERA_BUCKET_ID),
41            Path.fromString("/local/video/" + CAMERA_BUCKET_ID)};
42
43    public static boolean isCameraSource(Path path) {
44        return CAMERA_PATHS[0] == path || CAMERA_PATHS[1] == path
45                || CAMERA_PATHS[2] == path;
46    }
47
48    // Sort MediaSets by name
49    public static class NameComparator implements Comparator<MediaSet> {
50        public int compare(MediaSet set1, MediaSet set2) {
51            int result = set1.getName().compareToIgnoreCase(set2.getName());
52            if (result != 0) return result;
53            return set1.getPath().toString().compareTo(set2.getPath().toString());
54        }
55    }
56}
57