Skip to content

Commit

Permalink
Misc fixes
Browse files Browse the repository at this point in the history
- NavigationHandlerFragment: fixed tacking of navigation item click to
handle what fragment is selected
- ImageCacheUtils: fixed TAG constant
- PhotoUtils: added generatePhotoTitle method
- NewPhotoObserver: fixed determining of mime type by extension in the
getMimeType. Extension should be in lower case, otherwise null value is
received
- UploaderService: added title generating code to the handleIntent
method (currently commented)
- HorizontalListView: fixed fillListRight method to do not remove most
left view in some cases
- ImageUtils: added new constants for mime datetime
- ImageUtils: added new methods getExifDateTime (2 variations)
  • Loading branch information
httpdispatch committed Jul 12, 2013
1 parent fdff74a commit d247b8d
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public void onClick(View v) {
if (mCurrentPage != mPosition || getSupportFragmentManager()
.getBackStackEntryCount() > 0) {
CommonUtils.debug(TAG, "onNavigationItemSelected");
TrackerUtils.trackNavigationItemSelectedEvent(TAG,
TrackerUtils.trackNavigationItemSelectedEvent(
mClass.getSimpleName(),
NavigationHandlerFragment.this);
if (mOnMenuClickListener != null) {
mOnMenuClickListener.onMenuClick(mPosition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import com.trovebox.android.app.R;
import com.trovebox.android.app.TroveboxApplication;
import com.trovebox.android.app.provider.UploadsUtils;
import com.trovebox.android.app.util.CommonUtils;
import com.trovebox.android.app.util.GuiUtils;
import com.trovebox.android.app.util.LoadingControl;
Expand All @@ -22,7 +21,7 @@
* @author Eugene Popovich
*/
public class ImageCacheUtils {
public static final String TAG = UploadsUtils.class.getSimpleName();
public static final String TAG = ImageCacheUtils.class.getSimpleName();
public static String DISK_CACHE_CLEARED_BROADCAST_ACTION = "com.trovebox.DISK_CACHE_CLEARED";

/**
Expand Down
20 changes: 20 additions & 0 deletions app/src/com/trovebox/android/app/model/utils/PhotoUtils.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@

package com.trovebox.android.app.model.utils;

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Date;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;
Expand All @@ -24,6 +26,7 @@
import com.trovebox.android.app.net.TroveboxResponseUtils;
import com.trovebox.android.app.util.CommonUtils;
import com.trovebox.android.app.util.GuiUtils;
import com.trovebox.android.app.util.ImageUtils;
import com.trovebox.android.app.util.LoadingControl;
import com.trovebox.android.app.util.RunnableWithParameter;
import com.trovebox.android.app.util.SimpleAsyncTaskEx;
Expand Down Expand Up @@ -495,4 +498,21 @@ public static interface PhotoUpdatedHandler
void photoUpdated(Photo photo);
}

/**
* Generate photo title based on its date of creation
*
* @param filePath
* @return
* @throws IOException
*/
public static String generatePhotoTitle(String filePath) throws IOException
{
long createdDate = ImageUtils.getExifDateTime(filePath);
if (createdDate == -1)
{
CommonUtils.debug(TAG, "generatePhotoTitle: createdDate from exif is missing");
createdDate = (new File(filePath)).lastModified();
}
return CommonUtils.formatDateTime(new Date(createdDate));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static String getMimeType(File file)
String extension = MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(file).getPath());
if (extension != null) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension);
type = mime.getMimeTypeFromExtension(extension.toLowerCase());
}
CommonUtils.debug(TAG, "File: %1$s; extension %2$s; MimeType: %3$s",
file.getAbsolutePath(), extension, type);
Expand Down
15 changes: 13 additions & 2 deletions app/src/com/trovebox/android/app/service/UploaderService.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.trovebox.android.app.net.ITroveboxApi;
import com.trovebox.android.app.net.PhotosResponse;
import com.trovebox.android.app.net.ReturnSizes;
import com.trovebox.android.app.net.UploadMetaData;
import com.trovebox.android.app.net.UploadResponse;
import com.trovebox.android.app.net.account.AccountLimitUtils;
import com.trovebox.android.app.provider.PhotoUpload;
Expand Down Expand Up @@ -196,8 +197,17 @@ private void handleIntent(Intent intent) {
final NotificationCompat.Builder builder = CommonUtils
.isIceCreamSandwichOrHigher() ? getStandardUploadNotification(file)
: null;
UploadMetaData metaData = photoUpload.getMetaData();
// String title = metaData.getTitle();
// if (title == null || title.trim().length() == 0)
// {
// CommonUtils.debug(TAG,
// "handleIntent: photo title is empty, generating new one");
// title = PhotoUtils.generatePhotoTitle(filePath);
// metaData.setTitle(title);
// }
UploadResponse uploadResponse = mApi.uploadPhoto(file,
photoUpload.getMetaData(),
metaData,
new ProgressListener()
{
private int mLastProgress = -1;
Expand Down Expand Up @@ -431,7 +441,8 @@ private void showErrorNotification(PhotoUpload photoUpload, File file) {
int icon = R.drawable.icon;
CharSequence titleText = photoUpload.getError() == null ?
getString(R.string.notification_upload_failed_title)
:getString(R.string.notification_upload_failed_title_with_reason, photoUpload.getError());
: getString(R.string.notification_upload_failed_title_with_reason,
photoUpload.getError());
long when = System.currentTimeMillis();
CharSequence contentMessageTitle = getString(R.string.notification_upload_failed_text,
file.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ private void fillListRight(int rightEdge, final int dx) {
int childWidth = child.getMeasuredWidth();
rightEdge += childWidth;
totalWidth += childWidth;
totalWidth = removeNonVisibleItemsFromLeft(totalWidth, getWidth(), viewQueue);
totalWidth = removeNonVisibleItemsFromLeft(totalWidth, getWidth() + childWidth,
viewQueue);
CommonUtils.verbose(TAG,
"rightEdge = %1$d; childWidth = %2$d; rightViewIndex = %3$d"
+ "; count = %4$d; prognosed max width = %5$d",
Expand Down
60 changes: 60 additions & 0 deletions app/src/com/trovebox/android/app/util/ImageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.ExifInterface;
import android.net.Uri;
import android.provider.MediaStore;

public class ImageUtils {
static final String TAG = ImageUtils.class.getSimpleName();

public static final String TAG_DATETIME_ORIGINAL = "DateTimeOriginal";
public static final String TAG_DATETIME_DIGITIZED = "DateTimeDigitized";
public static final String TAG_DATETIME = ExifInterface.TAG_DATETIME;

/**
* decodes image and scales it to reduce memory consumption <br />
* <br />
Expand Down Expand Up @@ -79,4 +88,55 @@ public static String getRealPathFromURI(Context context, Uri imageUri) {
return null;
}
}

/**
* Returns number of milliseconds since Jan. 1, 1970, midnight. Returns -1
* if the date time information if not available.
*
* @param attributeName
* @throws IOException
*/
public static long getExifDateTime(String fileName) throws IOException {
ExifInterface exif = new ExifInterface(fileName);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
long result = getExifDateTime(exif, TAG_DATETIME_ORIGINAL, formatter);
CommonUtils.debug(TAG, "getExifDateTime: getting %1$s", TAG_DATETIME_ORIGINAL);
if (result == -1)
{
CommonUtils.debug(TAG, "getExifDateTime: getting %1$s", TAG_DATETIME_DIGITIZED);
result = getExifDateTime(exif, TAG_DATETIME_DIGITIZED, formatter);
}
if (result == -1)
{
CommonUtils.debug(TAG, "getExifDateTime: getting %1$s", TAG_DATETIME);
result = getExifDateTime(exif, TAG_DATETIME, formatter);
}
return result;
}

/**
* Returns number of milliseconds since Jan. 1, 1970, midnight. Returns -1
* if the date time information if not available.
*
* @param exif
* @param attributeName
* @param formatter
* @return
*/
private static long getExifDateTime(ExifInterface exif, String attributeName,
SimpleDateFormat formatter) {
String dateTimeString = exif.getAttribute(attributeName);
if (dateTimeString == null)
return -1;

ParsePosition pos = new ParsePosition(0);
try {
Date datetime = formatter.parse(dateTimeString, pos);
if (datetime == null)
return -1;
return datetime.getTime();
} catch (IllegalArgumentException ex) {
return -1;
}
}
}

0 comments on commit d247b8d

Please sign in to comment.