Home | History | Annotate | Download | only in data
      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 ComboSource extends MediaSource {
     22     private static final int COMBO_ALBUMSET = 0;
     23     private static final int COMBO_ALBUM = 1;
     24     private GalleryApp mApplication;
     25     private PathMatcher mMatcher;
     26 
     27     public ComboSource(GalleryApp application) {
     28         super("combo");
     29         mApplication = application;
     30         mMatcher = new PathMatcher();
     31         mMatcher.add("/combo/*", COMBO_ALBUMSET);
     32         mMatcher.add("/combo/*/*", COMBO_ALBUM);
     33     }
     34 
     35     // The only path we accept is "/combo/{set1, set2, ...} and /combo/item/{set1, set2, ...}"
     36     @Override
     37     public MediaObject createMediaObject(Path path) {
     38         String[] segments = path.split();
     39         if (segments.length < 2) {
     40             throw new RuntimeException("bad path: " + path);
     41         }
     42 
     43         DataManager dataManager = mApplication.getDataManager();
     44         switch (mMatcher.match(path)) {
     45             case COMBO_ALBUMSET:
     46                 return new ComboAlbumSet(path, mApplication,
     47                         dataManager.getMediaSetsFromString(segments[1]));
     48 
     49             case COMBO_ALBUM:
     50                 return new ComboAlbum(path,
     51                         dataManager.getMediaSetsFromString(segments[2]), segments[1]);
     52         }
     53         return null;
     54     }
     55 }
     56