Few small tweaks

This commit is contained in:
Mario Danic 2017-01-20 19:50:46 +01:00 committed by AndyScherzinger
parent f5c40a1cfa
commit 90d8513061
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
3 changed files with 30 additions and 27 deletions

View file

@ -45,8 +45,8 @@
<third_parties.michaelOrtiz.TouchImageViewCustom
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/zero"
android:layout_centerInParent="true"
android:contentDescription="@string/preview_image_description"

View file

@ -22,12 +22,17 @@ package com.owncloud.android.ui.preview;
import android.accounts.Account;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -156,27 +161,6 @@ public class PreviewImageFragment extends FileFragment {
mRelativeLayout = (RelativeLayout) view.findViewById(R.id.top);
mImageView.setVisibility(View.GONE);
mImageView.setOnTouchImageViewListener(new TouchImageViewCustom.OnTouchImageViewListener() {
@Override
public void onMove() {
if (!weZoomedAlready && mImageView.isZoomed()) {
weZoomedAlready = true;
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
mImageView.setLayoutParams(layoutParams);
mRelativeLayout.invalidate();
} else if (!mImageView.isZoomed()) {
weZoomedAlready = false;
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
mImageView.setLayoutParams(layoutParams);
mRelativeLayout.invalidate();
}
}
});
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
@ -548,12 +532,23 @@ public class PreviewImageFragment extends FileFragment {
if (result.ocFile.getMimetype().equalsIgnoreCase("image/png")) {
Drawable backrepeat = getResources().getDrawable(R.drawable.backrepeat);
imageView.setBackground(backrepeat);
Resources r = getResources();
Drawable[] layers = new Drawable[2];
layers[0] = r.getDrawable(R.drawable.backrepeat);
Drawable d = new BitmapDrawable(getResources(), bitmap);
layers[1] = d;
LayerDrawable layerDrawable = new LayerDrawable(layers);
layerDrawable.setLayerHeight(0, (int) convertDpToPixel(bitmap.getHeight(), getActivity()));
layerDrawable.setLayerHeight(1, (int) convertDpToPixel(bitmap.getHeight(), getActivity()));
layerDrawable.setLayerWidth(0, (int) convertDpToPixel(bitmap.getWidth(), getActivity()));
layerDrawable.setLayerWidth(1, (int) convertDpToPixel(bitmap.getWidth(), getActivity()));
imageView.setImageDrawable(layerDrawable);
}
if (result.ocFile.getMimetype().equalsIgnoreCase("image/gif")) {
imageView.setGIFImageFromStoragePath(result.ocFile.getStoragePath());
} else {
} else if (!result.ocFile.getMimetype().equalsIgnoreCase("image/png")){
imageView.setImageBitmap(bitmap);
}
@ -610,6 +605,14 @@ public class PreviewImageFragment extends FileFragment {
container.finish();
}
private static float convertDpToPixel(float dp, Context context){
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
float px = dp * ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
return px;
}
public TouchImageViewCustom getImageView() {
return mImageView;
}

View file

@ -10,8 +10,6 @@
package third_parties.michaelOrtiz;
import com.owncloud.android.ui.preview.ImageViewCustom;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Configuration;
@ -37,6 +35,8 @@ import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.OverScroller;
import android.widget.Scroller;
import com.owncloud.android.ui.preview.ImageViewCustom;
/**
* Extends Android ImageView to include pinch zooming, panning, fling and double tap zoom.
*/