2 * Copyright (C) 2013 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.ingest.adapter;
19 import com.android.gallery3d.R;
20 import com.android.gallery3d.ingest.data.IngestObjectInfo;
21 import com.android.gallery3d.ingest.data.MtpDeviceIndex;
22 import com.android.gallery3d.ingest.data.MtpDeviceIndex.SortOrder;
23 import com.android.gallery3d.ingest.ui.MtpFullscreenView;
25 import android.annotation.TargetApi;
26 import android.content.Context;
27 import android.os.Build;
28 import androidx.viewpager.widget.PagerAdapter;
29 import android.view.LayoutInflater;
30 import android.view.View;
31 import android.view.ViewGroup;
34 * Adapter for full-screen MTP pager.
36 @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
37 public class MtpPagerAdapter extends PagerAdapter {
39 private LayoutInflater mInflater;
40 private int mGeneration = 0;
41 private CheckBroker mBroker;
42 private MtpDeviceIndex mModel;
43 private SortOrder mSortOrder = SortOrder.DESCENDING;
45 private MtpFullscreenView mReusableView = null;
47 public MtpPagerAdapter(Context context, CheckBroker broker) {
49 mInflater = LayoutInflater.from(context);
53 public void setMtpDeviceIndex(MtpDeviceIndex index) {
55 notifyDataSetChanged();
59 public int getCount() {
60 return mModel != null ? mModel.sizeWithoutLabels() : 0;
64 public void notifyDataSetChanged() {
66 super.notifyDataSetChanged();
69 public int translatePositionWithLabels(int position) {
73 return mModel.getPositionWithoutLabelsFromPosition(position, mSortOrder);
77 public void finishUpdate(ViewGroup container) {
79 super.finishUpdate(container);
83 public boolean isViewFromObject(View view, Object object) {
84 return view == object;
88 public void destroyItem(ViewGroup container, int position, Object object) {
89 MtpFullscreenView v = (MtpFullscreenView) object;
90 container.removeView(v);
91 mBroker.unregisterOnCheckedChangeListener(v);
96 public Object instantiateItem(ViewGroup container, int position) {
98 if (mReusableView != null) {
100 mReusableView = null;
102 v = (MtpFullscreenView) mInflater.inflate(R.layout.ingest_fullsize, container, false);
104 IngestObjectInfo i = mModel.getWithoutLabels(position, mSortOrder);
105 v.getImageView().setMtpDeviceAndObjectInfo(mModel.getDevice(), i, mGeneration);
106 v.setPositionAndBroker(position, mBroker);
107 container.addView(v);