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 public class FilterSource extends MediaSource {
     22     @SuppressWarnings("unused")
     23     private static final String TAG = "FilterSource";
     24     private static final int FILTER_BY_MEDIATYPE = 0;
     25     private static final int FILTER_BY_DELETE = 1;
     26     private static final int FILTER_BY_EMPTY = 2;
     27     private static final int FILTER_BY_EMPTY_ITEM = 3;
     28     private static final int FILTER_BY_CAMERA_SHORTCUT = 4;
     29     private static final int FILTER_BY_CAMERA_SHORTCUT_ITEM = 5;
     30 
     31     public static final String FILTER_EMPTY_ITEM = "/filter/empty_prompt";
     32     public static final String FILTER_CAMERA_SHORTCUT = "/filter/camera_shortcut";
     33     private static final String FILTER_CAMERA_SHORTCUT_ITEM = "/filter/camera_shortcut_item";
     34 
     35     private GalleryApp mApplication;
     36     private PathMatcher mMatcher;
     37     private MediaItem mEmptyItem;
     38     private MediaItem mCameraShortcutItem;
     39 
     40     public FilterSource(GalleryApp application) {
     41         super("filter");
     42         mApplication = application;
     43         mMatcher = new PathMatcher();
     44         mMatcher.add("/filter/mediatype/*/*", FILTER_BY_MEDIATYPE);
     45         mMatcher.add("/filter/delete/*", FILTER_BY_DELETE);
     46         mMatcher.add("/filter/empty/*", FILTER_BY_EMPTY);
     47         mMatcher.add(FILTER_EMPTY_ITEM, FILTER_BY_EMPTY_ITEM);
     48         mMatcher.add(FILTER_CAMERA_SHORTCUT, FILTER_BY_CAMERA_SHORTCUT);
     49         mMatcher.add(FILTER_CAMERA_SHORTCUT_ITEM, FILTER_BY_CAMERA_SHORTCUT_ITEM);
     50 
     51         mEmptyItem = new EmptyAlbumImage(Path.fromString(FILTER_EMPTY_ITEM),
     52                 mApplication);
     53         mCameraShortcutItem = new CameraShortcutImage(
     54                 Path.fromString(FILTER_CAMERA_SHORTCUT_ITEM), mApplication);
     55     }
     56 
     57     // The name we accept are:
     58     // /filter/mediatype/k/{set}    where k is the media type we want.
     59     // /filter/delete/{set}
     60     @Override
     61     public MediaObject createMediaObject(Path path) {
     62         int matchType = mMatcher.match(path);
     63         DataManager dataManager = mApplication.getDataManager();
     64         switch (matchType) {
     65             case FILTER_BY_MEDIATYPE: {
     66                 int mediaType = mMatcher.getIntVar(0);
     67                 String setsName = mMatcher.getVar(1);
     68                 MediaSet[] sets = dataManager.getMediaSetsFromString(setsName);
     69                 return new FilterTypeSet(path, dataManager, sets[0], mediaType);
     70             }
     71             case FILTER_BY_DELETE: {
     72                 String setsName = mMatcher.getVar(0);
     73                 MediaSet[] sets = dataManager.getMediaSetsFromString(setsName);
     74                 return new FilterDeleteSet(path, sets[0]);
     75             }
     76             case FILTER_BY_EMPTY: {
     77                 String setsName = mMatcher.getVar(0);
     78                 MediaSet[] sets = dataManager.getMediaSetsFromString(setsName);
     79                 return new FilterEmptyPromptSet(path, sets[0], mEmptyItem);
     80             }
     81             case FILTER_BY_EMPTY_ITEM: {
     82                 return mEmptyItem;
     83             }
     84             case FILTER_BY_CAMERA_SHORTCUT: {
     85                 return new SingleItemAlbum(path, mCameraShortcutItem);
     86             }
     87             case FILTER_BY_CAMERA_SHORTCUT_ITEM: {
     88                 return mCameraShortcutItem;
     89             }
     90             default:
     91                 throw new RuntimeException("bad path: " + path);
     92         }
     93     }
     94 }
     95