Skip to content

Commit

Permalink
+ fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Moelleken authored and Lars Moelleken committed Nov 1, 2011
1 parent f19fcdb commit cfadbb2
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 96 deletions.
4 changes: 2 additions & 2 deletions res/values/config.xml
Expand Up @@ -16,8 +16,8 @@

<resources>

<integer name="max_resolution">2048</integer>
<integer name="max_resolution_screennail">1024</integer>
<integer name="max_resolution">1024</integer>
<integer name="max_resolution_screennail">512</integer>
<bool name="button_brightness_override">true</bool>

</resources>
8 changes: 4 additions & 4 deletions src/com/cooliris/cache/CacheService.java
Expand Up @@ -764,10 +764,10 @@ public static final byte[] writeBitmapToCache(final DiskCache thumbnailCache, fi
scaleFactor = (float) thumbnailHeight / height;
} else {
// Horizontally constrained.
if(thumbnailWidth != 0)
cropHeight = thumbnailHeight * width / thumbnailWidth;
else
cropHeight = thumbnailHeight * width;
if(thumbnailWidth != 0)
cropHeight = thumbnailHeight * width / thumbnailWidth;
else
cropHeight = thumbnailHeight * width;
cropY = Math.max(0, Math.min(focusY - cropHeight / 2, height - cropHeight));
cropX = 0;
cropWidth = width;
Expand Down
253 changes: 177 additions & 76 deletions src/com/cooliris/media/DetailMode.java
Expand Up @@ -31,6 +31,10 @@
import com.cooliris.app.App;
import com.cooliris.app.Res;

import com.drew.metadata.*;
import com.drew.metadata.exif.*;
import com.drew.imaging.jpeg.*;

public final class DetailMode {
public static CharSequence[] populateDetailModeStrings(Context context, ArrayList<MediaBucket> buckets) {
int numBuckets = buckets.size();
Expand Down Expand Up @@ -96,19 +100,11 @@ private static CharSequence[] populateSetViewDetailModeStrings(Context context,
if (selectedItemsSet.areTimestampsAvailable()) {
long minTimestamp = selectedItemsSet.mMinTimestamp;
long maxTimestamp = selectedItemsSet.mMaxTimestamp;
if (selectedItemsSet.isPicassaSet()) {
minTimestamp -= App.CURRENT_TIME_ZONE.getOffset(minTimestamp);
maxTimestamp -= App.CURRENT_TIME_ZONE.getOffset(maxTimestamp);
}
strings.add(resources.getString(Res.string.start) + ": " + dateTimeFormat.format(new Date(minTimestamp)));
strings.add(resources.getString(Res.string.end) + ": " + dateTimeFormat.format(new Date(maxTimestamp)));
} else if (selectedItemsSet.areAddedTimestampsAvailable()) {
long minTimestamp = selectedItemsSet.mMinAddedTimestamp;
long maxTimestamp = selectedItemsSet.mMaxAddedTimestamp;
if (selectedItemsSet.isPicassaSet()) {
minTimestamp -= App.CURRENT_TIME_ZONE.getOffset(minTimestamp);
maxTimestamp -= App.CURRENT_TIME_ZONE.getOffset(maxTimestamp);
}
strings.add(resources.getString(Res.string.start) + ": " + dateTimeFormat.format(new Date(minTimestamp)));
strings.add(resources.getString(Res.string.end) + ": " + dateTimeFormat.format(new Date(maxTimestamp)));
} else {
Expand Down Expand Up @@ -142,108 +138,213 @@ private static CharSequence[] populateItemViewDetailModeStrings(Context context,
return null;
}
Resources resources = context.getResources();
CharSequence[] strings = new CharSequence[8];
strings[0] = resources.getString(Res.string.title) + ": " + item.mCaption;
strings[1] = resources.getString(Res.string.type) + ": " + item.getDisplayMimeType();
ArrayList<CharSequence> exifItems = new ArrayList<CharSequence>();

exifItems.add(resources.getString(Res.string.title) + ": " + item.mCaption);
exifItems.add(resources.getString(Res.string.type) + ": " + item.getDisplayMimeType());

DateFormat dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);

if (item.mLocaltime == null) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
try {
ExifInterface exif = new ExifInterface(item.mFilePath);
try {
ExifInterface exif = new ExifInterface(item.mFilePath);
String imgSizeX = exif.getAttribute(ExifInterface.TAG_IMAGE_WIDTH);
String imgSizeY = exif.getAttribute(ExifInterface.TAG_IMAGE_LENGTH);

if (imgSizeX != null && imgSizeX.length() > 0 && imgSizeY != null && imgSizeY.length() > 0) {
exifItems.add("Image Size: " + imgSizeX + "x" + imgSizeY);
}

if (item.mLocaltime == null) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
String localtime = exif.getAttribute(ExifInterface.TAG_DATETIME);
if (localtime != null) {
item.mLocaltime = formatter.parse(localtime, new ParsePosition(0));
}
} catch (IOException ex) {
// ignore it.
}
if (item.mLocaltime == null && item.mCaption != null) {
formatter = new SimpleDateFormat("yyyyMMdd'_'HHmmss");
// skip initial IMG_ or VND_
item.mLocaltime = formatter.parse(item.mCaption, new ParsePosition(4));
if (item.mLocaltime == null && item.mCaption != null) {
formatter = new SimpleDateFormat("yyyyMMdd'_'HHmmss");
// skip initial IMG_ or VND_
item.mLocaltime = formatter.parse(item.mCaption, new ParsePosition(4));
}
}
} catch (IOException ex) {
// ignore it.
}

if (item.mLocaltime != null) {
strings[2] = resources.getString(Res.string.taken_on) + ": " + dateTimeFormat.format(item.mLocaltime);
exifItems.add(resources.getString(Res.string.taken_on) + ": " + dateTimeFormat.format(item.mLocaltime));
} else if (item.isDateTakenValid()) {
long dateTaken = item.mDateTakenInMs;
if (item.isPicassaItem()) {
dateTaken -= App.CURRENT_TIME_ZONE.getOffset(dateTaken);
}
strings[2] = resources.getString(Res.string.taken_on) + ": " + dateTimeFormat.format(new Date(dateTaken));
exifItems.add(resources.getString(Res.string.taken_on) + ": " + dateTimeFormat.format(new Date(dateTaken)));
} else if (item.isDateAddedValid()) {
long dateAdded = item.mDateAddedInSec * 1000;
if (item.isPicassaItem()) {
dateAdded -= App.CURRENT_TIME_ZONE.getOffset(dateAdded);
}
// TODO: Make this added_on as soon as translations are ready.
// strings[2] = resources.getString(Res.string.added_on) + ": " +
// DateFormat.format("h:mmaa MMM dd yyyy", dateAdded);
strings[2] = resources.getString(Res.string.taken_on) + ": " + dateTimeFormat.format(new Date(dateAdded));
exifItems.add(resources.getString(Res.string.taken_on) + ": " + dateTimeFormat.format(new Date(dateAdded)));
} else {
strings[2] = resources.getString(Res.string.taken_on) + ": " + resources.getString(Res.string.date_unknown);
exifItems.add(resources.getString(Res.string.taken_on) + ": " + resources.getString(Res.string.date_unknown));
}
MediaSet parentMediaSet = item.mParentMediaSet;
if (parentMediaSet == null) {
strings[3] = resources.getString(Res.string.album) + ":";
exifItems.add(resources.getString(Res.string.album) + ":");
} else {
strings[3] = resources.getString(Res.string.album) + ": " + parentMediaSet.mName;
exifItems.add(resources.getString(Res.string.album) + ": " + parentMediaSet.mName);
}

ReverseGeocoder reverseGeocoder = App.get(context).getReverseGeocoder();
String locationString = item.getReverseGeocodedLocation(reverseGeocoder);
if (locationString == null || locationString.length() == 0) {
locationString = context.getResources().getString(Res.string.location_unknown);
if (locationString != null && locationString.length() > 0) {
exifItems.add(resources.getString(Res.string.location) + ": " + locationString);
}
strings[4] = resources.getString(Res.string.location) + ": " + locationString;

String fileSize;
if (item.mFilePath == null) {
fileSize = context.getResources().getString(Res.string.file_size_unknown);
} else {
File file = new File(item.mFilePath);
long lenght = file.length()/1024;
fileSize = Long.toString(lenght) + " KB";
}
File jpegFile = new File(item.mFilePath);
try {
JpegSegmentReader segmentReader = new JpegSegmentReader(jpegFile);
byte[] exifSegment = segmentReader.readSegment(JpegSegmentReader.SEGMENT_APP1);
Metadata metadata = new Metadata();
new ExifReader(exifSegment).extract(metadata);
Directory exifDir = metadata.getDirectory(ExifDirectory.class);

strings[5] = resources.getString(Res.string.file_size) + ": " + fileSize;
String imageSize;
String camera;
if (item.mFilePath == null) {
imageSize = context.getResources().getString(Res.string.size_unknown);
camera = context.getResources().getString(Res.string.cam_unknown);
} else {
try {
ExifInterface exif = new ExifInterface(item.mFilePath);
String length = exif.getAttribute(ExifInterface.TAG_IMAGE_LENGTH);
String width = exif.getAttribute(ExifInterface.TAG_IMAGE_WIDTH);
String maker = exif.getAttribute(ExifInterface.TAG_MAKE);
String model = exif.getAttribute(ExifInterface.TAG_MODEL);
camera = exif.getAttribute(ExifInterface.TAG_MAKE) + " " + exif.getAttribute(ExifInterface.TAG_MODEL);
if (width.contentEquals("0") || length.contentEquals("0")) {
imageSize = context.getResources().getString(Res.string.size_unknown);
String tag = null;
String str = null;
int idx = 0;

// EXIF - Camera Maker & Model
String maker = exifDir.getString(ExifDirectory.TAG_MAKE).trim();
String model = exifDir.getString(ExifDirectory.TAG_MODEL).trim();
if (maker != null && maker.length() > 0) {
if (model != null && model.length() > 0) {
if (model.contains(maker)) {
str = model;
} else {
str = maker + " " + model;
}
} else {
imageSize = width + " x " + length;
str = maker;
}
if (maker == null || model == null)
{
camera = context.getResources().getString(Res.string.cam_unknown);
} else {
camera = maker + " " + model;
exifItems.add("Camera: " + str);
}

// TODO: EXIF - Lens Model

// EXIF - Focus Length
str = exifDir.getString(ExifDirectory.TAG_FOCAL_LENGTH);
if (str != null && str.length() > 0) {
// EXIF - 35mm Equivalent
String tmp = "Focal Length: " + str + " mm";
String eqv = exifDir.getString(ExifDirectory.TAG_35MM_FILM_EQUIV_FOCAL_LENGTH);
if (eqv != null && eqv.length() > 0) {
tmp += " (35mm equivalent: " + eqv + "mm)";
}

} catch (IOException ex) {
// ignore it.
imageSize = context.getResources().getString(Res.string.size_unknown);
camera = context.getResources().getString(Res.string.cam_unknown);
exifItems.add(tmp);
}

// EXIF - Aperture
str = exifDir.getString(ExifDirectory.TAG_FNUMBER);
if (str != null && str.length() > 0) {
exifItems.add("Aperture: " + "f/" + str);
}

// EXIF - Exposure Time
str = exifDir.getString(ExifDirectory.TAG_EXPOSURE_TIME);
if (str != null && str.length() > 0) {
exifItems.add("Exposure Time: " + str + " s");
}

// EXIF - ISO Speed
str = exifDir.getString(ExifDirectory.TAG_ISO_EQUIVALENT);
if (str != null && str.length() > 0) {
exifItems.add("ISO Speed: " + str);
}

// EXIF - Exposure Bias
str = exifDir.getString(ExifDirectory.TAG_EXPOSURE_BIAS);
if (str != null && str.length() > 0) {
exifItems.add("Exposure Bias: " + str + " eV");
}

// EXIF - Metering Mode
idx = exifDir.getInt(ExifDirectory.TAG_METERING_MODE);
tag = "Metering Mode: ";
switch (idx) {
/**
* Exposure metering method. '0' means unknown, '1' average, '2' center
* weighted average, '3' spot, '4' multi-spot, '5' multi-segment, '6' partial,
* '255' other.
*/
case 0:
exifItems.add(tag + "Unknown");
break;
case 1:
exifItems.add(tag + "Average");
break;
case 2:
exifItems.add(tag + "Center Weighted Average");
break;
case 3:
exifItems.add(tag + "Spot");
break;
case 4:
exifItems.add(tag + "Multi-spot");
break;
case 5:
exifItems.add(tag + "Multi-segment");
break;
case 6:
exifItems.add(tag + "Partial");
break;
case 255:
exifItems.add(tag + "Other");
break;
}

// EXIF - Exposure Program
idx = exifDir.getInt(ExifDirectory.TAG_EXPOSURE_PROGRAM);
tag = "Exposure: ";
switch (idx) {
/**
* Exposure program that the camera used when image was taken. '1'
* means manual control, '2' program normal, '3' aperture priority,
* '4' shutter priority, '5' program creative (slow program), '6'
* program action (high-speed program), '7' portrait mode, '8'
* landscape mode.
*/
case 1:
exifItems.add(tag + "Manual Control");
break;
case 2:
exifItems.add(tag + "Program Normal");
break;
case 3:
exifItems.add(tag + "Aperture Priority");
break;
case 4:
exifItems.add(tag + "Shutter Priority");
break;
case 5:
exifItems.add(tag + "Program Creative (slow program)");
break;
case 6:
exifItems.add(tag + "Program Action (High-speed Program)");
break;
case 7:
exifItems.add(tag + "Portrait Mode");
break;
case 8:
exifItems.add(tag + "Landscape Mode");
break;
}

// TODO: EXIF - White Balance
} catch (Exception ex) {
// ignore it.
}
strings[6] = resources.getString(Res.string.size) + ": " + imageSize;
strings[7] = resources.getString(Res.string.cam) + ": " + camera;


int numStrings = exifItems.size();
CharSequence[] strings = new CharSequence[numStrings];
for (int i = 0; i < numStrings; ++i) {
strings[i] = exifItems.get(i);
}
return strings;
}
}
17 changes: 7 additions & 10 deletions src/com/cooliris/media/Gallery.java
Expand Up @@ -278,20 +278,17 @@ public void onDestroy() {
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mRenderView.unregListener();
if (mRenderView != null) {
mRenderView.shutdown();
mRenderView = null;
}
mRenderView = new RenderView(this);
mRenderView.setRootLayer(mGridLayer);
setContentView(mRenderView);
mRenderView.regListener();

if (mGridLayer != null) {
mGridLayer.markDirty(30);
}
if (mRenderView != null) {
mRenderView.unloadAllTextures();
mRenderView.shutdown();
mRenderView = new RenderView(this);
mRenderView.setRootLayer(mGridLayer);
setContentView(mRenderView);
mRenderView.onResume();
} else {
mRenderView.requestRender();
}
Log.i(TAG, "onConfigurationChanged");
Expand Down
24 changes: 24 additions & 0 deletions src/com/cooliris/media/RenderView.java
Expand Up @@ -292,6 +292,30 @@ public boolean bind(Texture texture) {
return false;
}

public void unloadAllTextures() {
int unloaded = 0;
if (!mActiveTextureList.isEmpty()) {
int[] textureId = new int[1];
DirectLinkedList.Entry<TextureReference> iter = mActiveTextureList.getHead();
while (iter != null) {
final TextureReference textureRef = iter.value;
final Texture texture = textureRef.get();
final GL11 gl = textureRef.gl;
if (texture != null) {
texture.mState = Texture.STATE_UNLOADED;
if (gl != null && gl == mGL) {
textureId[0] = textureRef.textureId;
gl.glDeleteTextures(1, textureId, 0);
unloaded++;
}
}
iter = iter.next;
}
}
mActiveTextureList.clear();
Log.i(TAG, unloaded + " textures unloaded");
}

public void setAlpha(float alpha) {
GL11 gl = mGL;
gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);
Expand Down

0 comments on commit cfadbb2

Please sign in to comment.