1 package tim.prune.data;
3 import java.util.ArrayList;
6 * Class to hold a list of Media, either Photos or Audio files
8 public abstract class MediaList
10 /** list of media objects */
11 protected ArrayList<MediaObject> _media = null;
23 * @param inList ArrayList containing media objects
25 protected MediaList(ArrayList<MediaObject> inList)
29 _media = new ArrayList<MediaObject>();
34 * @return the number of media in the list
36 public int getNumMedia() {
41 * Add an object to the list
42 * @param inObject object to add
44 public void addMedia(MediaObject inObject)
46 if (inObject != null) {
52 * Add an object to the list at a specified index (used for undo)
53 * @param inObject object to add
54 * @param inIndex index at which to add
56 public void addMedia(MediaObject inObject, int inIndex)
58 if (inObject != null) {
59 _media.add(inIndex, inObject);
65 * Remove the selected media from the list
66 * @param inIndex index number to remove
68 public void deleteMedia(int inIndex)
70 // Maybe throw exception if this fails?
71 _media.remove(inIndex);
76 * Checks if the specified object is already in the list
77 * @param inMedia media object to check
78 * @return true if it's already in the list
80 public boolean contains(MediaObject inMedia) {
81 return (getMediaIndex(inMedia) > -1);
86 * Get the index of the given media
87 * @param inMedia object to check
88 * @return index of this object in the list, or -1 if not found
90 public int getMediaIndex(MediaObject inMedia)
92 // Check if we need to check
93 final int num = getNumMedia();
94 if (num <= 0 || inMedia == null)
97 for (int i=0; i<num; i++)
99 MediaObject m = _media.get(i);
100 if (m != null && m.equals(inMedia)) {
110 * Get the media at the given index
111 * @param inIndex index number, starting at 0
112 * @return specified object
114 public MediaObject getMedia(int inIndex)
116 if (inIndex < 0 || inIndex >= getNumMedia()) return null;
117 return _media.get(inIndex);
122 * Crop the list to the specified size
123 * @param inIndex previous size
125 public void cropTo(int inIndex)
134 // delete to previous size
135 while (_media.size() > inIndex) {
136 _media.remove(_media.size()-1);
143 * @return array of file names
145 public String[] getNameList()
147 final int num = getNumMedia();
148 String[] names = new String[num];
149 for (int i=0; i<num; i++) {
150 names[i] = getMedia(i).getName();
157 * @return true if list contains correlated media
159 public boolean hasCorrelatedMedia()
161 for (MediaObject m : _media) {
162 if (m.getDataPoint() != null) {
170 * @return true if list contains uncorrelated media
172 public boolean hasUncorrelatedMedia()
174 for (MediaObject m : _media) {
175 if (m.getDataPoint() == null && m.hasTimestamp()) {
184 * Remove all correlated media from the list
186 public void removeCorrelatedMedia()
188 if (getNumMedia() > 0)
190 // Construct new list to copy into
191 ArrayList<MediaObject> listCopy = new ArrayList<MediaObject>();
193 for (MediaObject m : _media)
195 // Copy media if it has no point
198 if (m.getDataPoint() == null)
204 // Switch reference to new list
210 * @return true if any of the media objects have Files
212 public boolean hasMediaWithFile()
214 for (MediaObject m: _media) {
215 if (m.getFile() != null) {
223 * @return clone of list contents
225 public abstract MediaList cloneList();
228 * Restore contents from other MediaList
229 * @param inOther MediaList with cloned contents
231 public void restore(MediaList inOther)
234 if (inOther != null && inOther.getNumMedia() > 0)
236 // Copy contents from other list
237 _media.addAll(inOther._media);