• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 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 package com.android.gallery3d.data;
17 
18 import com.android.gallery3d.app.GalleryApp;
19 
20 public class SnailSource extends MediaSource {
21     @SuppressWarnings("unused")
22     private static final String TAG = "SnailSource";
23     private static final int SNAIL_ALBUM = 0;
24     private static final int SNAIL_ITEM = 1;
25 
26     private GalleryApp mApplication;
27     private PathMatcher mMatcher;
28     private static int sNextId;
29 
SnailSource(GalleryApp application)30     public SnailSource(GalleryApp application) {
31         super("snail");
32         mApplication = application;
33         mMatcher = new PathMatcher();
34         mMatcher.add("/snail/set/*", SNAIL_ALBUM);
35         mMatcher.add("/snail/item/*", SNAIL_ITEM);
36     }
37 
38     // The only path we accept is "/snail/set/id" and "/snail/item/id"
39     @Override
createMediaObject(Path path)40     public MediaObject createMediaObject(Path path) {
41         DataManager dataManager = mApplication.getDataManager();
42         switch (mMatcher.match(path)) {
43             case SNAIL_ALBUM:
44                 String itemPath = "/snail/item/" + mMatcher.getVar(0);
45                 SnailItem item =
46                         (SnailItem) dataManager.getMediaObject(itemPath);
47                 return new SnailAlbum(path, item);
48             case SNAIL_ITEM: {
49                 int id = mMatcher.getIntVar(0);
50                 return new SnailItem(path);
51             }
52         }
53         return null;
54     }
55 
56     // Registers a new SnailAlbum containing a SnailItem and returns the id of
57     // them. You can obtain the Path of the SnailAlbum and SnailItem associated
58     // with the id by getSetPath and getItemPath().
newId()59     public static synchronized int newId() {
60         return sNextId++;
61     }
62 
getSetPath(int id)63     public static Path getSetPath(int id) {
64         return Path.fromString("/snail/set").getChild(id);
65     }
66 
getItemPath(int id)67     public static Path getItemPath(int id) {
68         return Path.fromString("/snail/item").getChild(id);
69     }
70 }
71