set a zoomed image view to fulfill whole free space

This commit is contained in:
contrudar 2016-10-06 17:46:53 +03:00
parent 7203a5849e
commit 387b2fb0c9
4 changed files with 6 additions and 128 deletions

View File

@ -216,7 +216,7 @@ public class PDFPage {
info.bgColor = Color.WHITE;
}
image = Bitmap.createBitmap(width, height, Config.RGB_565);
image = Bitmap.createBitmap(width, height, Config.ARGB_8888);
renderer = new PDFRenderer(this, info, image);
// if (cache != null) {

View File

@ -7,9 +7,6 @@ import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
@ -45,7 +42,6 @@ import com.sun.pdfview.decrypt.PDFPassword;
import com.sun.pdfview.font.PDFFont;
import net.sf.andpdf.nio.ByteBuffer;
import net.sf.andpdf.pdfviewer.gui.FullScrollView;
import net.sf.andpdf.refs.HardReference;
import java.io.IOException;
@ -434,7 +430,7 @@ public class PdfViewerFragment extends Fragment {
dialogFragment.show(getFragmentManager(), dialogFragment.getClass().getName() + ";" + DIALOG_FRAGMENT_TAG_MARK);
}
private class GraphView extends FullScrollView {
private class GraphView extends FrameLayout {
public Bitmap mBi;
public ImageView pdfZoomedImageView;
public PhotoViewAttacher photoViewAttacher;
@ -463,6 +459,7 @@ public class PdfViewerFragment extends Fragment {
linearLayout.gravity = Gravity.CENTER;
pdfZoomedImageView = new ImageView(context);
pdfZoomedImageView.setLayoutParams(linearLayout);
pdfZoomedImageView.setBackgroundColor(getContext().getResources().getColor(R.color.zoomed_image_view_background));
photoViewAttacher = new PhotoViewAttacher(pdfZoomedImageView);
setPageBitmap(null);
@ -650,8 +647,7 @@ public class PdfViewerFragment extends Fragment {
}
}
Bitmap bitmap = mPdfPage.getImage(calculatedWidth, calculatedHeight, null, true, true);
//bitmap = getBitmapWithoutQualityLose(bitmap, maxWidthToPopulate, maxHeightToPopulate);
final Bitmap bitmap = mPdfPage.getImage(calculatedWidth, calculatedHeight, null, true, true);
mGraphView.setPageBitmap(bitmap);
mGraphView.updateImage();
} catch (Throwable e) {
@ -662,26 +658,6 @@ public class PdfViewerFragment extends Fragment {
}
@NonNull
public Bitmap getBitmapWithoutQualityLose(@NonNull final Bitmap bitmap, int newWidth, int newHeight) {
final Bitmap scaledBitmap = Bitmap.createBitmap(newWidth, newHeight, Bitmap.Config.ARGB_8888);
float ratioX = newWidth / (float) bitmap.getWidth();
float ratioY = newHeight / (float) bitmap.getHeight();
float middleX = newWidth / 2.0f;
float middleY = newHeight / 2.0f;
final Matrix scaleMatrix = new Matrix();
scaleMatrix.setScale(ratioX, ratioY, middleX, middleY);
final Canvas canvas = new Canvas(scaledBitmap);
canvas.setMatrix(scaleMatrix);
canvas.drawBitmap(bitmap, middleX - bitmap.getWidth() / 2, middleY - bitmap.getHeight() / 2, new Paint(Paint.FILTER_BITMAP_FLAG));
return scaledBitmap;
}
private void hideProgressBar() {
if (progress != null) {
progress.dismiss();

View File

@ -1,100 +0,0 @@
package net.sf.andpdf.pdfviewer;
/*
* Copyright (c) 2015 RoboSwag (Gavriil Sitnikov, Vsevolod Ivanov)
*
* This file is part of RoboSwag library.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.Display;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import java.util.concurrent.atomic.AtomicInteger;
public final class UiUtils {
private UiUtils() {
}
/**
* Utilities methods related to metrics.
*/
public static class OfMetrics {
private static final int MAX_METRICS_TRIES_COUNT = 5;
/**
* Returns right metrics with non-zero height/width.
* It is common bug when metrics are calling at {@link Application#onCreate()} method and it returns metrics with zero height/width.
*
* @param context {@link Context} of metrics;
* @return {@link DisplayMetrics}.
*/
@SuppressWarnings("BusyWait")
@NonNull
public static DisplayMetrics getDisplayMetrics(@NonNull final Context context) {
DisplayMetrics result = context.getResources().getDisplayMetrics();
// it is needed to avoid bug with invalid metrics when user restore application from other application
int metricsTryNumber = 0;
while (metricsTryNumber < MAX_METRICS_TRIES_COUNT && (result.heightPixels <= 0 || result.widthPixels <= 0)) {
try {
Thread.sleep(500);
} catch (final InterruptedException ignored) {
return result;
}
result = context.getResources().getDisplayMetrics();
metricsTryNumber++;
}
return result;
}
/**
* Simply converts DP to pixels.
*
* @param context {@link Context} of metrics;
* @param sizeInDp Size in DP;
* @return Size in pixels.
*/
public static float dpToPixels(@NonNull final Context context, final float sizeInDp) {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, sizeInDp, getDisplayMetrics(context));
}
private OfMetrics() {
}
}
}

View File

@ -4,4 +4,6 @@
<drawable name="black">#000000</drawable>
<drawable name="blue">#000000FF</drawable>
<drawable name="violet">#9370DB</drawable>
<color name="zoomed_image_view_background">#1d2022</color>
</resources>