Commit 23b5b9b2 authored by Donald's avatar Donald

clean metedata

parent c8cc290a
......@@ -74,6 +74,6 @@ dependencies {
compile 'org.jetbrains:annotations-java5:15.0'
compile 'com.turingtechnologies.materialscrollbar:lib:10.0.3'
compile 'com.github.chrisbanes:PhotoView:1.3.0'
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.5.0'
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0'
compile 'com.github.Commit451:bypasses:1.0.4'
}
......@@ -52,7 +52,8 @@ public class ImageFragment extends Fragment {
if (PreferenceUtil.getInstance(getContext()).getBoolean(getString(R.string.preference_sub_scaling) , true)) {
SubsamplingScaleImageView imageView = new SubsamplingScaleImageView(getContext());
imageView.setImage(ImageSource.uri(img.getUri()));
imageView.setImage(ImageSource.uri(img.getUri()).tilingEnabled());
imageView.setOrientation(SubsamplingScaleImageView.ORIENTATION_0);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
......
......@@ -172,21 +172,13 @@ public class Media implements Parcelable, Serializable {
details.put(context.getString(R.string.size), StringUtils.humanReadableByteCount(size, true));
// TODO should i add this always?
details.put(context.getString(R.string.orientation), getOrientation() + "");
try {
InputStream stream = getInputStream(context.getContentResolver());
details.put(context.getString(R.string.resolution), MetaDataItem.getResolution(stream));
} catch (Exception e) { e.printStackTrace(); }
File file = getFile();
if(file != null) {
metadata = MetaDataItem.getMetadata(file);
details.put(context.getString(R.string.date), SimpleDateFormat.getDateTimeInstance().format(new Date(getDateModified())));
if (metadata.getDateOriginal() != null)
details.put(context.getString(R.string.date_taken), SimpleDateFormat.getDateTimeInstance().format(metadata.getDateOriginal()));
metadata = MetaDataItem.getMetadata(getInputStream(context.getContentResolver()));
details.put(context.getString(R.string.resolution), metadata.getResolution());
details.put(context.getString(R.string.date), SimpleDateFormat.getDateTimeInstance().format(new Date(dateModified)));
Date dateOriginal = metadata.getDateOriginal();
if (dateOriginal != null )
details.put(context.getString(R.string.date_taken), SimpleDateFormat.getDateTimeInstance().format(dateOriginal));
String tmp;
if ((tmp = metadata.getCameraInfo()) != null)
......@@ -196,7 +188,8 @@ public class Media implements Parcelable, Serializable {
GeoLocation location;
if ((location = metadata.getLocation()) != null)
details.put(context.getString(R.string.location), location.toDMSString());
} catch (Exception e) {
e.printStackTrace();
}
return details;
......
......@@ -2,7 +2,6 @@ package org.horaapps.leafpic.model;
import android.graphics.BitmapFactory;
import android.support.annotation.NonNull;
import android.util.Log;
import com.drew.imaging.ImageMetadataReader;
import com.drew.imaging.ImageProcessingException;
......@@ -14,7 +13,6 @@ import com.drew.metadata.exif.ExifSubIFDDirectory;
import com.drew.metadata.exif.GpsDirectory;
import com.drew.metadata.xmp.XmpDirectory;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;
......@@ -29,75 +27,55 @@ import java.util.TimeZone;
class MetaDataItem {
// private static Set<Class<?>> usefullDirectories = new HashSet<Class<?>>();
private static final int ORIENTATION_NORMAL = 1;
private static final int ORIENTATION_ROTATE_180 = 3;
private static final int ORIENTATION_ROTATE_90 = 6; // rotate 90 cw to right it
private static final int ORIENTATION_ROTATE_270 = 8; // rotate 270 to right it
// static {
// usefullDirectories.add(ExifIFD0Directory.class);
// usefullDirectories.add(ExifSubIFDDirectory.class);
// usefullDirectories.add(GpsDirectory.class);
// usefullDirectories.add(XmpDirectory.class);
// }
private String make = null;
private String model = null;
private String fNumber = null;
private String iso = null;
private String exposureTime = null;
private String make = null, model = null, fNumber = null, iso = null, exposureTime;
private Date dateOriginal = null;
private GeoLocation location = null;
private int orientation = -1;
private int orientation = -1, height = -1, width = -1;
static MetaDataItem getMetadata(@NonNull File file) {
return new MetaDataItem(file);
static MetaDataItem getMetadata(@NonNull InputStream in) throws ImageProcessingException, IOException {
return new MetaDataItem(in, true);
}
static String getResolution(InputStream stream) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(stream, null, options);
private MetaDataItem(InputStream in) throws ImageProcessingException, IOException {
Metadata metadata = ImageMetadataReader.readMetadata(in);
handleDirectoryBase(metadata.getFirstDirectoryOfType(ExifIFD0Directory.class));
ExifSubIFDDirectory dir = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
if(dir != null) {
dateOriginal = dir.getDateOriginal(TimeZone.getDefault());
handleDirectoryBase(dir);
}
XmpDirectory dir1 = metadata.getFirstDirectoryOfType(XmpDirectory.class);
if(dir1 != null) {
if (dir1.containsTag(XmpDirectory.TAG_DATETIME_ORIGINAL))
dateOriginal = dir1.getDate(XmpDirectory.TAG_DATETIME_ORIGINAL);
return String.format(Locale.getDefault(),"%dx%d", options.outWidth, options.outHeight);
if (dir1.containsTag(XmpDirectory.TAG_MAKE))
make = dir1.getString(XmpDirectory.TAG_MAKE);
if (dir1.containsTag(XmpDirectory.TAG_MODEL))
model = dir1.getString(XmpDirectory.TAG_MODEL);
if (dir1.containsTag(XmpDirectory.TAG_F_NUMBER))
fNumber = dir1.getString(XmpDirectory.TAG_F_NUMBER);
}
GpsDirectory d = metadata.getFirstDirectoryOfType(GpsDirectory.class);
if(d != null) location = d.getGeoLocation();
}
private MetaDataItem(File stream) {
try {
Metadata metadata = ImageMetadataReader.readMetadata(stream);
// TODO: 21/08/16 should I switch to ExifInterface or to any other lib?
handleDirectoryBase(metadata.getFirstDirectoryOfType(ExifIFD0Directory.class));
ExifSubIFDDirectory dir = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
if(dir != null) {
dateOriginal = dir.getDateOriginal(TimeZone.getDefault());
handleDirectoryBase(dir);
}
XmpDirectory dir1 = metadata.getFirstDirectoryOfType(XmpDirectory.class);
if(dir1 != null) {
if (dir1.containsTag(XmpDirectory.TAG_DATETIME_ORIGINAL))
dateOriginal = dir1.getDate(XmpDirectory.TAG_DATETIME_ORIGINAL);
if (dir1.containsTag(XmpDirectory.TAG_MAKE))
make = dir1.getString(XmpDirectory.TAG_MAKE);
if (dir1.containsTag(XmpDirectory.TAG_MODEL))
model = dir1.getString(XmpDirectory.TAG_MODEL);
if (dir1.containsTag(XmpDirectory.TAG_F_NUMBER))
fNumber = dir1.getString(XmpDirectory.TAG_F_NUMBER);
}
GpsDirectory d = metadata.getFirstDirectoryOfType(GpsDirectory.class);
if(d != null) location = d.getGeoLocation();
} catch (ImageProcessingException e) {
Log.wtf("asd", "logMainTags: ImageProcessingException", e);
} catch (IOException e) {
Log.wtf("asd", "logMainTags: IOException", e);
private MetaDataItem(InputStream in, boolean resolution) throws ImageProcessingException, IOException {
this(in);
if(resolution) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(in, null, options);
width = options.outWidth;
height = options.outHeight;
}
}
......@@ -120,6 +98,12 @@ class MetaDataItem {
}
}
public String getResolution() {
if (width != -1 && -1 != height)
return String.format(Locale.getDefault(),"%dx%d", width, height);
else return "¿x?";
}
public int getOrientation() {
return orientation;
}
......
package org.horaapps.leafpic.util;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
......@@ -21,8 +22,10 @@ import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.drew.lang.GeoLocation;
import org.horaapps.leafpic.R;
......@@ -118,22 +121,27 @@ public class AlertDialogsHelper {
final GeoLocation location;
if ((location = f.getGeoLocation()) != null) {
PreferenceUtil SP = PreferenceUtil.getInstance(activity.getApplicationContext());
StaticMapProvider staticMapProvider = StaticMapProvider.fromValue(
SP.getInt(activity.getString(R.string.preference_map_provider), StaticMapProvider.GOOGLE_MAPS.getValue()));
PreferenceUtil.getInt(activity, activity.getString(R.string.preference_map_provider), StaticMapProvider.GOOGLE_MAPS.getValue()));
Glide.with(activity.getApplicationContext())
.load(staticMapProvider.getUrl(location))
.asBitmap()
.centerCrop()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.animate(org.horaapps.leafpic.R.anim.fade_in)
.into(imgMap);
imgMap.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String uri = String.format(Locale.ENGLISH, "geo:%f,%f?z=%d", location.getLatitude(), location.getLongitude(), 17);
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(uri)));
try {
activity.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(String.format(Locale.ENGLISH, "geo:%f,%f?z=%d", location.getLatitude(), location.getLongitude(), 17))));
} catch (ActivityNotFoundException e) {
Toast.makeText(activity, R.string.no_app_to_perform, Toast.LENGTH_SHORT).show();
}
}
});
......
......@@ -31,6 +31,10 @@ public class PreferenceUtil {
return getInstance(context).getBoolean(key, defValue);
}
public static int getInt(Context context, String key, int defValue) {
return getInstance(context).getInt(key, defValue);
}
public SharedPreferences.Editor getEditor() {
return SP.edit();
}
......
......@@ -372,4 +372,5 @@ and this could make the media inaccessible from other apps. Use the exclude opti
<string name="no_media_in_this_folder">No media in this folder</string>
<string name="error_occured_open_media">An error occurred opening this media.</string>
<string name="error_thumbnail">Unable to find a thumbnail for the album!</string>
<string name="no_app_to_perform">Unable to found an app to perform this action.</string>
</resources>
......@@ -6,7 +6,7 @@ buildscript {
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0-beta1'
classpath 'com.android.tools.build:gradle:2.3.0-beta3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
......
#Wed Dec 14 22:26:11 CET 2016
#Sun Jan 29 21:20:49 CET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment