2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.gallery3d.data;
19 import com.android.gallery3d.app.GalleryApp;
21 class MtpSource extends MediaSource {
22 private static final String TAG = "MtpSource";
24 private static final int MTP_DEVICESET = 0;
25 private static final int MTP_DEVICE = 1;
26 private static final int MTP_ITEM = 2;
28 GalleryApp mApplication;
30 MtpContext mMtpContext;
32 public MtpSource(GalleryApp application) {
34 mApplication = application;
35 mMatcher = new PathMatcher();
36 mMatcher.add("/mtp", MTP_DEVICESET);
37 mMatcher.add("/mtp/*", MTP_DEVICE);
38 mMatcher.add("/mtp/item/*/*", MTP_ITEM);
39 mMtpContext = new MtpContext(mApplication.getAndroidContext());
43 public MediaObject createMediaObject(Path path) {
44 switch (mMatcher.match(path)) {
46 return new MtpDeviceSet(path, mApplication, mMtpContext);
49 int deviceId = mMatcher.getIntVar(0);
50 return new MtpDevice(path, mApplication, deviceId, mMtpContext);
53 int deviceId = mMatcher.getIntVar(0);
54 int objectId = mMatcher.getIntVar(1);
55 return new MtpImage(path, mApplication, deviceId, objectId, mMtpContext);
58 throw new RuntimeException("bad path: " + path);
68 public void resume() {