1 package com.cooliris.media;
3 import java.text.DateFormat;
4 import java.util.ArrayList;
7 import android.content.Context;
8 import android.content.res.Resources;;
10 public final class DetailMode {
11 public static CharSequence[] populateDetailModeStrings(Context context, ArrayList<MediaBucket> buckets) {
12 int numBuckets = buckets.size();
13 if (MediaBucketList.isSetSelection(buckets) && numBuckets == 1) {
14 // If just 1 set was selected, save the trouble of processing the items in the set again.
15 // We have already processed details for that set.
16 return populateSetViewDetailModeStrings(context, MediaBucketList.getFirstSetSelection(buckets), 1);
17 } else if (MediaBucketList.isSetSelection(buckets) || MediaBucketList.isMultipleItemSelection(buckets)) {
18 // Cycle through the items and add them to the selection items set.
19 MediaSet selectedItemsSet = new MediaSet();
20 for (int i = 0; i < numBuckets; i++) {
21 MediaBucket bucket = buckets.get(i);
22 ArrayList<MediaItem> currItems = null;
24 if (MediaBucketList.isSetSelection(bucket)) {
25 MediaSet currSet = bucket.mediaSet;
26 if (currSet != null) {
27 currItems = currSet.getItems();
28 numCurrItems = currSet.getNumItems();
31 currItems = bucket.mediaItems;
32 numCurrItems = currItems.size();
34 if (currItems != null) {
35 for (int j = 0; j < numCurrItems; j++) {
36 selectedItemsSet.addItem(currItems.get(j));
40 return populateSetViewDetailModeStrings(context, selectedItemsSet, numBuckets);
42 return populateItemViewDetailModeStrings(context, MediaBucketList.getFirstItemSelection(buckets));
46 private static CharSequence[] populateSetViewDetailModeStrings(Context context, MediaSet selectedItemsSet, int numOriginalSets) {
47 if (selectedItemsSet == null) {
50 Resources resources = context.getResources();
51 ArrayList<CharSequence> strings = new ArrayList<CharSequence>();
53 // Number of albums selected.
54 if (numOriginalSets == 1) {
55 strings.add("1 " + resources.getString(R.string.album_selected));
57 strings.add(Integer.toString(numOriginalSets) + " " + resources.getString(R.string.albums_selected));
60 // Number of items selected.
61 int numItems = selectedItemsSet.mNumItemsLoaded;
63 strings.add("1 " + resources.getString(R.string.item_selected));
65 strings.add(Integer.toString(numItems) + " " + resources.getString(R.string.items_selected));
68 DateFormat dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.SHORT);
70 // Start and end times of the selected items.
71 if (selectedItemsSet.areTimestampsAvailable()) {
72 long minTimestamp = selectedItemsSet.mMinTimestamp;
73 long maxTimestamp = selectedItemsSet.mMaxTimestamp;
74 if (selectedItemsSet.isPicassaSet()) {
75 minTimestamp -= Gallery.CURRENT_TIME_ZONE.getOffset(minTimestamp);
76 maxTimestamp -= Gallery.CURRENT_TIME_ZONE.getOffset(maxTimestamp);
78 strings.add(resources.getString(R.string.start) + ": " + dateTimeFormat.format(new Date(minTimestamp)));
79 strings.add(resources.getString(R.string.end) + ": " + dateTimeFormat.format(new Date(maxTimestamp)));
80 } else if (selectedItemsSet.areAddedTimestampsAvailable()) {
81 long minTimestamp = selectedItemsSet.mMinAddedTimestamp;
82 long maxTimestamp = selectedItemsSet.mMaxAddedTimestamp;
83 if (selectedItemsSet.isPicassaSet()) {
84 minTimestamp -= Gallery.CURRENT_TIME_ZONE.getOffset(minTimestamp);
85 maxTimestamp -= Gallery.CURRENT_TIME_ZONE.getOffset(maxTimestamp);
87 strings.add(resources.getString(R.string.start) + ": " + dateTimeFormat.format(new Date(minTimestamp)));
88 strings.add(resources.getString(R.string.end) + ": " + dateTimeFormat.format(new Date(maxTimestamp)));
90 strings.add(resources.getString(R.string.start) + ": " + resources.getString(R.string.date_unknown));
91 strings.add(resources.getString(R.string.end) + ": " + resources.getString(R.string.date_unknown));
94 // The location of the selected items.
95 String locationString = null;
96 if (selectedItemsSet.mLatLongDetermined) {
97 locationString = selectedItemsSet.mReverseGeocodedLocation;
98 if (locationString == null) {
99 // Try computing the location if it does not exist.
100 ReverseGeocoder reverseGeocoder = ((Gallery) context).getReverseGeocoder();
101 locationString = reverseGeocoder.computeMostGranularCommonLocation(selectedItemsSet);
104 if (locationString != null && locationString.length() > 0) {
105 strings.add(resources.getString(R.string.location) + ": " + locationString);
107 int numStrings = strings.size();
108 CharSequence[] stringsArr = new CharSequence[numStrings];
109 for (int i = 0; i < numStrings; ++i) {
110 stringsArr[i] = strings.get(i);
115 private static CharSequence[] populateItemViewDetailModeStrings(Context context, MediaItem item) {
119 Resources resources = context.getResources();
120 CharSequence[] strings = new CharSequence[5];
121 strings[0] = resources.getString(R.string.title) + ": " + item.mCaption;
122 strings[1] = resources.getString(R.string.type) + ": " + item.getDisplayMimeType();
124 DateFormat dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.SHORT);
126 if (item.isDateTakenValid()) {
127 long dateTaken = item.mDateTakenInMs;
128 if (item.isPicassaItem()) {
129 dateTaken -= Gallery.CURRENT_TIME_ZONE.getOffset(dateTaken);
131 strings[2] = resources.getString(R.string.taken_on) + ": " + dateTimeFormat.format(new Date(dateTaken));
132 } else if (item.isDateAddedValid()) {
133 long dateAdded = item.mDateAddedInSec * 1000;
134 if (item.isPicassaItem()) {
135 dateAdded -= Gallery.CURRENT_TIME_ZONE.getOffset(dateAdded);
137 // TODO: Make this added_on as soon as translations are ready.
138 //strings[2] = resources.getString(R.string.added_on) + ": " + DateFormat.format("h:mmaa MMM dd yyyy", dateAdded);
139 strings[2] = resources.getString(R.string.taken_on) + ": " + dateTimeFormat.format(new Date(dateAdded));
141 strings[2] = resources.getString(R.string.taken_on) + ": " + resources.getString(R.string.date_unknown);
143 MediaSet parentMediaSet = item.mParentMediaSet;
144 if (parentMediaSet == null) {
145 strings[3] = resources.getString(R.string.album) + ":";
147 strings[3] = resources.getString(R.string.album) + ": " + parentMediaSet.mName;
149 ReverseGeocoder reverseGeocoder = ((Gallery) context).getReverseGeocoder();
150 String locationString = item.getReverseGeocodedLocation(reverseGeocoder);
151 if (locationString == null || locationString.length() == 0) {
152 locationString = context.getResources().getString(R.string.location_unknown);
154 strings[4] = resources.getString(R.string.location) + ": " + locationString;