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.data; 18 19 import com.android.gallery3d.app.GalleryApp; 20 21 class ClusterSource extends MediaSource { 22 static final int CLUSTER_ALBUMSET_TIME = 0; 23 static final int CLUSTER_ALBUMSET_LOCATION = 1; 24 static final int CLUSTER_ALBUMSET_TAG = 2; 25 static final int CLUSTER_ALBUMSET_SIZE = 3; 26 static final int CLUSTER_ALBUMSET_FACE = 4; 27 28 static final int CLUSTER_ALBUM_TIME = 0x100; 29 static final int CLUSTER_ALBUM_LOCATION = 0x101; 30 static final int CLUSTER_ALBUM_TAG = 0x102; 31 static final int CLUSTER_ALBUM_SIZE = 0x103; 32 static final int CLUSTER_ALBUM_FACE = 0x104; 33 34 GalleryApp mApplication; 35 PathMatcher mMatcher; 36 ClusterSource(GalleryApp application)37 public ClusterSource(GalleryApp application) { 38 super("cluster"); 39 mApplication = application; 40 mMatcher = new PathMatcher(); 41 mMatcher.add("/cluster/*/time", CLUSTER_ALBUMSET_TIME); 42 mMatcher.add("/cluster/*/location", CLUSTER_ALBUMSET_LOCATION); 43 mMatcher.add("/cluster/*/tag", CLUSTER_ALBUMSET_TAG); 44 mMatcher.add("/cluster/*/size", CLUSTER_ALBUMSET_SIZE); 45 mMatcher.add("/cluster/*/face", CLUSTER_ALBUMSET_FACE); 46 47 mMatcher.add("/cluster/*/time/*", CLUSTER_ALBUM_TIME); 48 mMatcher.add("/cluster/*/location/*", CLUSTER_ALBUM_LOCATION); 49 mMatcher.add("/cluster/*/tag/*", CLUSTER_ALBUM_TAG); 50 mMatcher.add("/cluster/*/size/*", CLUSTER_ALBUM_SIZE); 51 mMatcher.add("/cluster/*/face/*", CLUSTER_ALBUM_FACE); 52 } 53 54 // The names we accept are: 55 // /cluster/{set}/time /cluster/{set}/time/k 56 // /cluster/{set}/location /cluster/{set}/location/k 57 // /cluster/{set}/tag /cluster/{set}/tag/encoded_tag 58 // /cluster/{set}/size /cluster/{set}/size/min_size 59 @Override createMediaObject(Path path)60 public MediaObject createMediaObject(Path path) { 61 int matchType = mMatcher.match(path); 62 String setsName = mMatcher.getVar(0); 63 DataManager dataManager = mApplication.getDataManager(); 64 MediaSet[] sets = dataManager.getMediaSetsFromString(setsName); 65 switch (matchType) { 66 case CLUSTER_ALBUMSET_TIME: 67 case CLUSTER_ALBUMSET_LOCATION: 68 case CLUSTER_ALBUMSET_TAG: 69 case CLUSTER_ALBUMSET_SIZE: 70 case CLUSTER_ALBUMSET_FACE: 71 return new ClusterAlbumSet(path, mApplication, sets[0], matchType); 72 case CLUSTER_ALBUM_TIME: 73 case CLUSTER_ALBUM_LOCATION: 74 case CLUSTER_ALBUM_TAG: 75 case CLUSTER_ALBUM_SIZE: 76 case CLUSTER_ALBUM_FACE: { 77 MediaSet parent = dataManager.getMediaSet(path.getParent()); 78 // The actual content in the ClusterAlbum will be filled later 79 // when the reload() method in the parent is run. 80 return new ClusterAlbum(path, dataManager, parent); 81 } 82 default: 83 throw new RuntimeException("bad path: " + path); 84 } 85 } 86 } 87