Fix all compile errors in Zoom.java and ShareActivity.java

This commit is contained in:
misaochan 2018-05-29 18:12:17 +10:00
parent c885c31cc5
commit 56592b3bcd
2 changed files with 52 additions and 34 deletions

View file

@ -2,27 +2,23 @@ package fr.free.nrw.commons.upload;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapRegionDecoder;
import android.graphics.Point;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.design.widget.FloatingActionButton;
@ -30,7 +26,6 @@ import android.support.design.widget.Snackbar;
import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.BitmapCompat;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
@ -68,7 +63,6 @@ import fr.free.nrw.commons.modifications.ModifierSequenceDao;
import fr.free.nrw.commons.modifications.TemplateRemoveModifier;
import fr.free.nrw.commons.mwapi.CategoryApi;
import fr.free.nrw.commons.mwapi.MediaWikiApi;
import io.reactivex.schedulers.Schedulers;
import fr.free.nrw.commons.utils.ViewUtil;
import timber.log.Timber;
@ -524,7 +518,27 @@ public class ShareActivity
e.printStackTrace();
}
ZoomUtils.zoomImageUtil(thumbView, startBounds, input);
Zoom zoomObj = new Zoom(thumbView, startBounds, input, imageuri, this.getContentResolver());
Bitmap scaledImage = zoomObj.createScaledImage();
// Load the high-resolution "zoomed-in" image.
expandedImageView.setImageBitmap(scaledImage);
float startScale = zoomObj.adjustStartEndBounds(finalBounds, globalOffset);
// Hide the thumbnail and show the zoomed-in view. When the animation
// begins, it will position the zoomed-in view in the place of the
// thumbnail.
thumbView.setAlpha(0f);
expandedImageView.setVisibility(View.VISIBLE);
zoomOutButton.setVisibility(View.VISIBLE);
zoomInButton.setVisibility(View.GONE);
// Set the pivot point for SCALE_X and SCALE_Y transformations
// to the top-left corner of the zoomed-in view (the default
// is the center of the view).
expandedImageView.setPivotX(0f);
expandedImageView.setPivotY(0f);
// Construct and run the parallel animation of the four translation and
// scale properties (X, Y, SCALE_X, and SCALE_Y).

View file

@ -1,19 +1,38 @@
package fr.free.nrw.commons.upload;
import android.content.ContentResolver;
import android.graphics.Bitmap;
import android.graphics.BitmapRegionDecoder;
import android.graphics.Point;
import android.graphics.Rect;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v4.graphics.BitmapCompat;
import android.view.View;
import android.widget.FrameLayout;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
public class ZoomUtils {
public class Zoom {
static void zoomImageUtil(View thumbView, Rect startBounds, InputStream input) {
private View thumbView;
private Rect startBounds;
private InputStream input;
private Uri imageUri;
private ContentResolver contentResolver;
private FrameLayout flContainer;
public Zoom(View thumbView, Rect startBounds, InputStream input, Uri imageUri, ContentResolver contentResolver) {
this.thumbView = thumbView;
this.startBounds = startBounds;
this.input = input;
this.imageUri = imageUri;
this.contentResolver = contentResolver;
}
Bitmap createScaledImage() {
Bitmap scaled = null;
BitmapRegionDecoder decoder = null;
@ -28,24 +47,23 @@ public class ZoomUtils {
System.gc();
Runtime rt = Runtime.getRuntime();
long maxMemory = rt.freeMemory();
bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageuri);
int bitmapByteCount= BitmapCompat.getAllocationByteCount(bitmap);
bitmap = MediaStore.Images.Media.getBitmap(contentResolver, imageUri);
int bitmapByteCount = BitmapCompat.getAllocationByteCount(bitmap);
long height = bitmap.getHeight();
long width = bitmap.getWidth();
long calHeight = (long) ((height * maxMemory)/(bitmapByteCount * 1.1));
long calWidth = (long) ((width * maxMemory)/(bitmapByteCount * 1.1));
scaled = Bitmap.createScaledBitmap(bitmap,(int) Math.min(width,calWidth), (int) Math.min(height,calHeight), true);
long calHeight = (long) ((height * maxMemory) / (bitmapByteCount * 1.1));
long calWidth = (long) ((width * maxMemory) / (bitmapByteCount * 1.1));
scaled = Bitmap.createScaledBitmap(bitmap, (int) Math.min(width, calWidth), (int) Math.min(height, calHeight), true);
} catch (IOException e) {
} catch (NullPointerException e){
} catch (NullPointerException e) {
scaled = bitmap;
}
// Load the high-resolution "zoomed-in" image.
expandedImageView.setImageBitmap(scaled);
return scaled;
}
float adjustStartEndBounds(Rect finalBounds, Point globalOffset) {
// Calculate the starting and ending bounds for the zoomed-in image.
// This step involves lots of math. Yay, math.
// The start bounds are the global visible rectangle of the thumbnail,
// and the final bounds are the global visible rectangle of the container
// view. Also set the container view's offset as the origin for the
@ -77,20 +95,6 @@ public class ZoomUtils {
startBounds.top -= deltaHeight;
startBounds.bottom += deltaHeight;
}
// Hide the thumbnail and show the zoomed-in view. When the animation
// begins, it will position the zoomed-in view in the place of the
// thumbnail.
thumbView.setAlpha(0f);
expandedImageView.setVisibility(View.VISIBLE);
zoomOutButton.setVisibility(View.VISIBLE);
zoomInButton.setVisibility(View.GONE);
// Set the pivot point for SCALE_X and SCALE_Y transformations
// to the top-left corner of the zoomed-in view (the default
// is the center of the view).
expandedImageView.setPivotX(0f);
expandedImageView.setPivotY(0f);
return startScale;
}
}