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 FilterSource extends MediaSource { 22 private static final String TAG = "FilterSource"; 23 private static final int FILTER_BY_MEDIATYPE = 0; 24 25 private GalleryApp mApplication; 26 private PathMatcher mMatcher; 27 28 public FilterSource(GalleryApp application) { 29 super("filter"); 30 mApplication = application; 31 mMatcher = new PathMatcher(); 32 mMatcher.add("/filter/mediatype/*/*", FILTER_BY_MEDIATYPE); 33 } 34 35 // The name we accept is: 36 // /filter/mediatype/k/{set} 37 // where k is the media type we want. 38 @Override 39 public MediaObject createMediaObject(Path path) { 40 int matchType = mMatcher.match(path); 41 int mediaType = mMatcher.getIntVar(0); 42 String setsName = mMatcher.getVar(1); 43 DataManager dataManager = mApplication.getDataManager(); 44 MediaSet[] sets = dataManager.getMediaSetsFromString(setsName); 45 switch (matchType) { 46 case FILTER_BY_MEDIATYPE: 47 return new FilterSet(path, dataManager, sets[0], mediaType); 48 default: 49 throw new RuntimeException("bad path: " + path); 50 } 51 } 52 } 53