1 /* 2 * Copyright (C) 2013 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.camera.data; 18 19 import android.app.Activity; 20 import android.content.Context; 21 import android.net.Uri; 22 import android.view.View; 23 24 import com.android.camera.ui.FilmStripView; 25 26 /** 27 * A {@link LocalDataAdapter} which puts a {@link LocalData} fixed at the last 28 * position. It's done by combining a {@link LocalData} and another 29 * {@link LocalDataAdapter}. 30 */ 31 public class FixedLastDataAdapter extends AbstractLocalDataAdapterWrapper { 32 33 private LocalData mLastData; 34 private Listener mListener; 35 36 /** 37 * Constructor. 38 * 39 * @param wrappedAdapter The {@link LocalDataAdapter} to be wrapped. 40 * @param lastData The {@link LocalData} to be placed at the last position. 41 */ 42 public FixedLastDataAdapter( 43 LocalDataAdapter wrappedAdapter, 44 LocalData lastData) { 45 super(wrappedAdapter); 46 if (lastData == null) { 47 throw new AssertionError("data is null"); 48 } 49 mLastData = lastData; 50 } 51 52 @Override 53 public void setListener(Listener listener) { 54 super.setListener(listener); 55 mListener = listener; 56 } 57 58 @Override 59 public LocalData getLocalData(int dataID) { 60 int totalNumber = mAdapter.getTotalNumber(); 61 62 if (dataID < totalNumber) { 63 return mAdapter.getLocalData(dataID); 64 } else if (dataID == totalNumber) { 65 return mLastData; 66 } 67 68 return null; 69 } 70 71 @Override 72 public void removeData(Context context, int dataID) { 73 if (dataID < mAdapter.getTotalNumber()) { 74 mAdapter.removeData(context, dataID); 75 } 76 } 77 78 @Override 79 public int findDataByContentUri(Uri uri) { 80 return mAdapter.findDataByContentUri(uri); 81 } 82 83 @Override 84 public void updateData(final int pos, LocalData data) { 85 int totalNumber = mAdapter.getTotalNumber(); 86 87 if (pos < totalNumber) { 88 mAdapter.updateData(pos, data); 89 } else if (pos == totalNumber) { 90 mLastData = data; 91 if (mListener != null) { 92 mListener.onDataUpdated(new UpdateReporter() { 93 @Override 94 public boolean isDataRemoved(int dataID) { 95 return false; 96 } 97 98 @Override 99 public boolean isDataUpdated(int dataID) { 100 return (dataID == pos); 101 } 102 }); 103 } 104 } 105 } 106 107 @Override 108 public int getTotalNumber() { 109 return mAdapter.getTotalNumber() + 1; 110 } 111 112 @Override 113 public View getView(Activity activity, int dataID) { 114 int totalNumber = mAdapter.getTotalNumber(); 115 116 if (dataID < totalNumber) { 117 return mAdapter.getView(activity, dataID); 118 } else if (dataID == totalNumber) { 119 return mLastData.getView(activity, 120 mSuggestedWidth, mSuggestedHeight, null, null); 121 } 122 123 return null; 124 } 125 126 @Override 127 public FilmStripView.ImageData getImageData(int dataID) { 128 int totalNumber = mAdapter.getTotalNumber(); 129 130 if (dataID < totalNumber) { 131 return mAdapter.getImageData(dataID); 132 } else if (dataID == totalNumber) { 133 return mLastData; 134 } 135 return null; 136 } 137 138 @Override 139 public boolean canSwipeInFullScreen(int dataID) { 140 int totalNumber = mAdapter.getTotalNumber(); 141 142 if (dataID < totalNumber) { 143 return mAdapter.canSwipeInFullScreen(dataID); 144 } else if (dataID == totalNumber) { 145 return mLastData.canSwipeInFullScreen(); 146 } 147 return false; 148 } 149 } 150 151