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 17 package com.android.gallery3d.data; 18 19 import com.android.gallery3d.app.GalleryApp; 20 21 public class SecureSource extends MediaSource { 22 private GalleryApp mApplication; 23 private static PathMatcher mMatcher = new PathMatcher(); 24 private static final int SECURE_ALBUM = 0; 25 private static final int SECURE_UNLOCK = 1; 26 27 static { 28 mMatcher.add("/secure/all/*", SECURE_ALBUM); 29 mMatcher.add("/secure/unlock", SECURE_UNLOCK); 30 } 31 32 public SecureSource(GalleryApp context) { 33 super("secure"); 34 mApplication = context; 35 } 36 37 public static boolean isSecurePath(String path) { 38 return (SECURE_ALBUM == mMatcher.match(Path.fromString(path))); 39 } 40 41 @Override 42 public MediaObject createMediaObject(Path path) { 43 switch (mMatcher.match(path)) { 44 case SECURE_ALBUM: { 45 DataManager dataManager = mApplication.getDataManager(); 46 MediaItem unlock = (MediaItem) dataManager.getMediaObject( 47 "/secure/unlock"); 48 return new SecureAlbum(path, mApplication, unlock); 49 } 50 case SECURE_UNLOCK: 51 return new UnlockImage(path, mApplication); 52 default: 53 throw new RuntimeException("bad path: " + path); 54 } 55 } 56 } 57