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