Update
This commit is contained in:
1 parent
74c1c2144f
commit
4e2caa5b4d
15 files changed
+292
-112
No files matched your search
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.hippo.ehviewer.gallery;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
public interface GalleryProvider {
|
||||
|
||||
/**
|
||||
@@ -71,6 +73,8 @@ public interface GalleryProvider {
|
||||
|
||||
void setPause(boolean pause);
|
||||
|
||||
void releaseBitmap(Bitmap bitmap);
|
||||
|
||||
void addGalleryProviderListener(GalleryProviderListener listener);
|
||||
|
||||
void removeGalleryProviderListener(GalleryProviderListener listener);
|
||||
|
||||
@@ -105,7 +105,10 @@ public class GallerySpider implements GalleryProvider, SpiderQueen.SpiderListene
|
||||
DBUtils.addDirname(galleryBase, dirname);
|
||||
}
|
||||
|
||||
mDownloadDir = Settings.getDownloadPath().createDirectory(dirname);
|
||||
UniFile dir = Settings.getImageDownloadLocation();
|
||||
if (dir != null) {
|
||||
mDownloadDir = dir.createDirectory(dirname);
|
||||
}
|
||||
|
||||
if (mDownloadDir == null) {
|
||||
throw new IOException("Can't get download dir");
|
||||
|
||||
@@ -233,14 +233,6 @@ public class ImageHandler {
|
||||
|
||||
if (mMode == Mode.READ) {
|
||||
osPipe = getReadOutputStreamPipe(index);
|
||||
} else if (mMode == Mode.DOWNLOAD) {
|
||||
// Let download listener to fix filename
|
||||
String filename = getImageFilename(index, "jpg");
|
||||
osPipe = getDownloadOutputStreamPipe(filename);
|
||||
}
|
||||
|
||||
if (osPipe == null) {
|
||||
throw new IOException("Can't create OutputStreamPipe");
|
||||
}
|
||||
|
||||
if (helper.mCancel) {
|
||||
@@ -252,7 +244,15 @@ public class ImageHandler {
|
||||
helper.mRequest = request;
|
||||
request.setHttpClient(httpClient);
|
||||
request.setUrl(url);
|
||||
request.setOSPipe(osPipe);
|
||||
|
||||
if (mMode == Mode.READ) {
|
||||
request.setOSPipe(osPipe);
|
||||
} else if (mMode == Mode.DOWNLOAD) {
|
||||
// Let download listener to fix filename
|
||||
request.setFilename(getImageFilename(index, "jpg"));
|
||||
request.setDir(mDownloadDir);
|
||||
}
|
||||
|
||||
request.setListener(downloadListener);
|
||||
DownloadClient.execute(request);
|
||||
|
||||
@@ -287,7 +287,7 @@ public class ImageHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onFixname(String newFilename, String newExtension, String oldFilename) {
|
||||
public String onFixname(String newFileFirstname, String newExtension, String oldFilename) {
|
||||
String filename;
|
||||
if (TextUtils.isEmpty(newExtension)) {
|
||||
filename = oldFilename;
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.hippo.httpclient.HttpResponse;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.yorozuya.AutoExpandArray;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
import com.hippo.yorozuya.PriorityThread;
|
||||
import com.hippo.yorozuya.PriorityThreadFactory;
|
||||
import com.hippo.yorozuya.Say;
|
||||
|
||||
@@ -567,8 +568,7 @@ public class SpiderQueen implements Runnable {
|
||||
setGetSizeFinished(false);
|
||||
ensureWorker();
|
||||
mRender = new Render();
|
||||
Thread thread = new Thread(mRender, "Render");
|
||||
thread.setPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
||||
Thread thread = new PriorityThread(mRender, "Render", Process.THREAD_PRIORITY_BACKGROUND);
|
||||
thread.start();
|
||||
|
||||
// 7. tell listener pages
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.os.Process;
|
||||
|
||||
import com.hippo.conaco.BitmapPool;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
import com.hippo.yorozuya.PriorityThread;
|
||||
import com.hippo.yorozuya.Say;
|
||||
import com.hippo.yorozuya.SimpleHandler;
|
||||
import com.hippo.yorozuya.StringUtils;
|
||||
@@ -45,8 +46,7 @@ public class ZipGalleryProvider implements GalleryProvider, Runnable {
|
||||
public ZipGalleryProvider(File file) throws IOException {
|
||||
mZipFile = new ZipFile(file);
|
||||
|
||||
Thread thread = new Thread(this);
|
||||
thread.setPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
||||
Thread thread = new PriorityThread(this, "ZipGalleryProvider", Process.THREAD_PRIORITY_BACKGROUND);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,6 @@ public class GalleryPageView extends FrameView {
|
||||
addComponent(mLinearView, lp);
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResourceType")
|
||||
private void updateSeen() {
|
||||
Rect bounds = bounds();
|
||||
Rect parentBounds = mParent.bounds();
|
||||
@@ -63,21 +62,13 @@ public class GalleryPageView extends FrameView {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changeSize, int left, int top, int right, int bottom) {
|
||||
super.onLayout(changeSize, left, top, right, bottom);
|
||||
public void layout(int left, int top, int right, int bottom) {
|
||||
super.layout(left, top, right, bottom);
|
||||
updateSeen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offsetLeftAndRight(int offset) {
|
||||
super.offsetLeftAndRight(offset);
|
||||
updateSeen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offsetTopAndBottom(int offset) {
|
||||
super.offsetTopAndBottom(offset);
|
||||
updateSeen();
|
||||
public boolean isLoaded() {
|
||||
return mImageView.isLoaded();
|
||||
}
|
||||
|
||||
public void setScaleOffset(GalleryView.Scale scale,
|
||||
@@ -92,4 +83,12 @@ public class GalleryPageView extends FrameView {
|
||||
public void scale(float focusX, float focusY, float scale) {
|
||||
mImageView.scale(focusX, focusY, scale);
|
||||
}
|
||||
|
||||
public float getFitScale() {
|
||||
return mImageView.getFitScale();
|
||||
}
|
||||
|
||||
public float getScale() {
|
||||
return mImageView.getScale();
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,14 @@ import android.content.Context;
|
||||
import android.util.SparseArray;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.animation.Interpolator;
|
||||
import android.view.animation.OvershootInterpolator;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.gallery.anim.Animation;
|
||||
import com.hippo.ehviewer.gallery.glrenderer.GLCanvas;
|
||||
import com.hippo.ehviewer.gallery.util.GalleryUtils;
|
||||
import com.hippo.yorozuya.IntArray;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -26,6 +28,17 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
private static final int SEEN = 1;
|
||||
private static final int UNSEEN = 2;
|
||||
|
||||
private static final Interpolator SMOOTH_SCROLLER_INTERPOLATOR = new Interpolator() {
|
||||
|
||||
@Override
|
||||
public float getInterpolation(float t) {
|
||||
t -= 1.0f;
|
||||
return t * t * t * t * t + 1.0f;
|
||||
}
|
||||
};
|
||||
|
||||
private static final Interpolator SMOOTH_SCALER_INTERPOLATOR = new OvershootInterpolator();
|
||||
|
||||
private boolean mEnableRequestLayout = true;
|
||||
|
||||
private GestureRecognizer mGestureRecognizer;
|
||||
@@ -54,23 +67,15 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
private Mode mMode = Mode.NONE;
|
||||
private Mode mLastLayoutMode = Mode.NONE;
|
||||
|
||||
private Scale mScaleMode = Scale.FIT_HEIGHT; // TODO
|
||||
private Scale mScaleMode = Scale.FIT; // TODO
|
||||
private StartPosition mStartPosition = StartPosition.TOP_RIGHT; // TODO
|
||||
private float mLastScale = 2f;
|
||||
private float mLastScale = 1f;
|
||||
|
||||
private int mProgressSpec = MeasureSpec.makeMeasureSpec(48, MeasureSpec.EXACTLY);
|
||||
public int mInterval = 24;
|
||||
|
||||
private SmoothScroller mSmoothScroller;
|
||||
|
||||
private static final Interpolator sInterpolator = new Interpolator() {
|
||||
|
||||
@Override
|
||||
public float getInterpolation(float t) {
|
||||
t -= 1.0f;
|
||||
return t * t * t * t * t + 1.0f;
|
||||
}
|
||||
};
|
||||
private SmoothScaler mSmoothScaler;
|
||||
|
||||
public enum Mode {
|
||||
NONE, // Just a progress view
|
||||
@@ -80,16 +85,11 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
}
|
||||
|
||||
public enum Scale {
|
||||
ORIGIN (0),
|
||||
FIT_WIDTH (1),
|
||||
FIT_HEIGHT (2),
|
||||
FIT (3),
|
||||
FIXED (4);
|
||||
|
||||
Scale(int ni) {
|
||||
nativeInt = ni;
|
||||
}
|
||||
final int nativeInt;
|
||||
ORIGIN,
|
||||
FIT_WIDTH,
|
||||
FIT_HEIGHT,
|
||||
FIT,
|
||||
FIXED
|
||||
}
|
||||
|
||||
public enum StartPosition {
|
||||
@@ -104,7 +104,9 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
mEdgeView = new EdgeView(context);
|
||||
mGestureRecognizer = new GestureRecognizer(context, this);
|
||||
mSmoothScroller = new SmoothScroller();
|
||||
mSmoothScroller.setInterpolator(sInterpolator);
|
||||
mSmoothScroller.setInterpolator(SMOOTH_SCROLLER_INTERPOLATOR);
|
||||
mSmoothScaler = new SmoothScaler();
|
||||
mSmoothScaler.setInterpolator(SMOOTH_SCALER_INTERPOLATOR);
|
||||
|
||||
setBackgroundColor(GalleryUtils.intColorToFloatARGBArray(context.getResources().getColor(R.color.gallery_background)));
|
||||
}
|
||||
@@ -149,6 +151,9 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
}
|
||||
|
||||
public void scrollToPage(int page) {
|
||||
mSmoothScroller.forceStop();
|
||||
mSmoothScaler.forceStop();
|
||||
|
||||
if (page < 0 || page >= mAdapter.getPages()) {
|
||||
return;
|
||||
}
|
||||
@@ -159,14 +164,16 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
}
|
||||
|
||||
public void smoothScrollToPage(int page) {
|
||||
mSmoothScroller.forceStop();
|
||||
mSmoothScaler.forceStop();
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
||||
private void scrollX(int offset) {
|
||||
if (offset == 0 || (mMode != Mode.LEFT_TO_RIGHT && mMode != Mode.RIGHT_TO_LEFT)) {
|
||||
return;
|
||||
}
|
||||
offChildsetLeftAndRight(offset); // TODO Really need it ?
|
||||
|
||||
mLayoutOffset += offset;
|
||||
boolean reverse = mMode == Mode.RIGHT_TO_LEFT;
|
||||
@@ -209,16 +216,66 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
|
||||
@Override
|
||||
public boolean onSingleTapUp(float x, float y) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSingleTapConfirmed(float x, float y) {
|
||||
|
||||
if (mMode == Mode.LEFT_TO_RIGHT || mMode == Mode.RIGHT_TO_LEFT) {
|
||||
|
||||
if (x < getWidth() / 2) {
|
||||
if (mFirstShownIndex > 0) {
|
||||
scrollToPage(mFirstShownIndex - 1);
|
||||
} else {
|
||||
mEdgeView.onPull(getWidth() * 2, EdgeView.LEFT);
|
||||
}
|
||||
} else {
|
||||
if (mFirstShownIndex < mAdapter.getPages() - 1) {
|
||||
scrollToPage(mFirstShownIndex + 1);
|
||||
} else {
|
||||
mEdgeView.onPull(getWidth() * 2, EdgeView.RIGHT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDoubleTap(float x, float y) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDoubleTapConfirmed(float x, float y) {
|
||||
if (mScale) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((mMode == Mode.LEFT_TO_RIGHT || mMode == Mode.RIGHT_TO_LEFT) &&
|
||||
mLayoutOffset == 0) {
|
||||
GalleryPageView page = mPageMap.get(mFirstShownIndex);
|
||||
if (page != null && page.isLoaded()) {
|
||||
float scale = page.getScale();
|
||||
float fitScale = page.getFitScale();
|
||||
float centerScale = (1f + fitScale) / 2;
|
||||
float targetScale;
|
||||
if ((fitScale > 1f && scale > centerScale) ||
|
||||
(fitScale < 1f && scale < centerScale)) {
|
||||
targetScale = 1f;
|
||||
} else {
|
||||
targetScale = fitScale;
|
||||
}
|
||||
mSmoothScaler.startSmoothScaler(page, x, y, scale, targetScale, 500); // TODO
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Try to scroll to make mLayoutOffset == 0
|
||||
private int onScrollX1(int dx, int totalX) {
|
||||
private int onScrollX1(int dx) {
|
||||
int remain;
|
||||
int actualDx;
|
||||
if (mLayoutOffset > 0 && dx > 0) {
|
||||
@@ -246,12 +303,12 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
actualDx = dx;
|
||||
}
|
||||
|
||||
onScrollX2(actualDx, totalX);
|
||||
onScrollX2(actualDx);
|
||||
|
||||
return remain;
|
||||
}
|
||||
|
||||
private int onScrollX2(int dx, int totalX) {
|
||||
private int onScrollX2(int dx) {
|
||||
int remain = 0;
|
||||
if (mMode == Mode.LEFT_TO_RIGHT) {
|
||||
if (mFirstShownIndex == 0 && mLayoutOffset - dx > 0) { // Start
|
||||
@@ -286,11 +343,10 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
|
||||
int dxI = (int) dx;
|
||||
int dyI = (int) dy;
|
||||
int totalXI = (int) totalX;
|
||||
if (mMode == Mode.LEFT_TO_RIGHT || mMode == Mode.RIGHT_TO_LEFT) {
|
||||
int remain = dxI;
|
||||
if (remain != 0 && mLayoutOffset != 0) {
|
||||
remain = onScrollX1(dxI, totalXI);
|
||||
remain = onScrollX1(dxI);
|
||||
}
|
||||
if (remain != 0 && mLayoutOffset == 0) {
|
||||
GalleryPageView page = mPageMap.get(mFirstShownIndex);
|
||||
@@ -300,7 +356,7 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
}
|
||||
}
|
||||
if (remain != 0) {
|
||||
remain = onScrollX2(dxI, totalXI);
|
||||
remain = onScrollX2(dxI);
|
||||
}
|
||||
|
||||
if (remain == 0) {
|
||||
@@ -333,6 +389,10 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
|
||||
@Override
|
||||
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
|
||||
// TODO
|
||||
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -362,8 +422,9 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
mScale = true;
|
||||
|
||||
GalleryPageView page = mPageMap.get(mFirstShownIndex);
|
||||
if (page != null) {
|
||||
if (page != null && page.isLoaded()) {
|
||||
page.scale(focusX, focusY, scale);
|
||||
mLastScale = page.getScale();
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -379,6 +440,7 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
mScale = false;
|
||||
mScroll = false;
|
||||
mSmoothScroller.forceStop();
|
||||
mSmoothScaler.forceStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -435,6 +497,7 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
@Override
|
||||
protected void onLayout(boolean changeSize, int left, int top, int right, int bottom) {
|
||||
mSmoothScroller.forceStop();
|
||||
mSmoothScaler.forceStop();
|
||||
mEdgeView.layout(left, top, right, bottom);
|
||||
|
||||
/* TODO set all seen UNKNOWN_SEEN to setScaleAndOffset
|
||||
@@ -499,7 +562,7 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
}
|
||||
mInvalidAttachedComponent.clear();
|
||||
|
||||
// Fill
|
||||
// Fill TODO better to avoid make load image when stop
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
int widthSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY);
|
||||
@@ -680,11 +743,16 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
}
|
||||
|
||||
mEnableRequestLayout = true;
|
||||
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void render(GLCanvas canvas) {
|
||||
if (mSmoothScroller.calculate(AnimationTime.get())) {
|
||||
long time = AnimationTime.get();
|
||||
boolean invalidate = mSmoothScroller.calculate(time);
|
||||
invalidate |= mSmoothScaler.calculate(time);
|
||||
if (invalidate) {
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@@ -732,6 +800,39 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
public abstract void unbindPage(GalleryPageView view, int index);
|
||||
}
|
||||
|
||||
public class SmoothScaler extends Animation {
|
||||
|
||||
private GalleryPageView mPage;
|
||||
private float mFocusX;
|
||||
private float mFocusY;
|
||||
private float mStartScale;
|
||||
private float mEndScale;
|
||||
private float mLastScale;
|
||||
|
||||
public void startSmoothScaler(GalleryPageView page, float focusX, float focusY,
|
||||
float startScale, float endScale, int duration) {
|
||||
mPage = page;
|
||||
mFocusX = focusX;
|
||||
mFocusY = focusY;
|
||||
mStartScale = startScale;
|
||||
mEndScale = endScale;
|
||||
mLastScale = startScale;
|
||||
setDuration(duration);
|
||||
start();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCalculate(float progress) {
|
||||
float scale = MathUtils.lerp(mStartScale, mEndScale, progress);
|
||||
mPage.scale(mFocusX, mFocusY, scale / mLastScale);
|
||||
mLastScale = scale;
|
||||
if (progress == 1.0f) {
|
||||
mPage = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SmoothScroller extends Animation {
|
||||
|
||||
private int mDx;
|
||||
|
||||
@@ -31,7 +31,9 @@ public class GestureRecognizer {
|
||||
|
||||
public interface Listener {
|
||||
boolean onSingleTapUp(float x, float y);
|
||||
boolean onSingleTapConfirmed(float x, float y);
|
||||
boolean onDoubleTap(float x, float y);
|
||||
boolean onDoubleTapConfirmed(float x, float y);
|
||||
boolean onScroll(float dx, float dy, float totalX, float totalY);
|
||||
boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY);
|
||||
boolean onScaleBegin(float focusX, float focusY);
|
||||
@@ -50,8 +52,10 @@ public class GestureRecognizer {
|
||||
|
||||
public GestureRecognizer(Context context, Listener listener) {
|
||||
mListener = listener;
|
||||
mGestureDetector = new GestureDetectorCompat(context, new MyGestureListener(),
|
||||
MyGestureListener gestureListener = new MyGestureListener();
|
||||
mGestureDetector = new GestureDetectorCompat(context, gestureListener,
|
||||
null /* ignoreMultitouch */);
|
||||
mGestureDetector.setOnDoubleTapListener(gestureListener);
|
||||
mScaleDetector = new ScaleGestureDetector(
|
||||
context, new MyScaleListener());
|
||||
mDownUpDetector = new DownUpDetector(new MyDownUpListener());
|
||||
@@ -82,6 +86,20 @@ public class GestureRecognizer {
|
||||
return mListener.onSingleTapUp(e.getX(), e.getY());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSingleTapConfirmed(MotionEvent e) {
|
||||
return mListener.onSingleTapConfirmed(e.getX(), e.getY());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDoubleTapEvent(MotionEvent e) {
|
||||
if (e.getAction() == MotionEvent.ACTION_UP) {
|
||||
return mListener.onDoubleTapConfirmed(e.getX(), e.getY());
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDoubleTap(MotionEvent e) {
|
||||
return mListener.onDoubleTap(e.getX(), e.getY());
|
||||
|
||||
@@ -26,7 +26,7 @@ public class ScaledImageView extends GLView {
|
||||
private GalleryView.Scale mScaleMode;
|
||||
private GalleryView.StartPosition mStartPosition;
|
||||
private float mLastScale;
|
||||
private float mScale;
|
||||
private float mScale = 1f;
|
||||
|
||||
public void setTiledTexture(TiledTexture tiledTexture) {
|
||||
mTiledTexture = tiledTexture;
|
||||
@@ -277,6 +277,34 @@ public class ScaledImageView extends GLView {
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public float getScale() {
|
||||
return mScale;
|
||||
}
|
||||
|
||||
public float getFitScale() {
|
||||
int screenWidth = getWidth();
|
||||
int screenHeight = getHeight();
|
||||
|
||||
if (mTiledTexture == null || screenWidth == 0 || screenHeight == 0) {
|
||||
return 1f;
|
||||
}
|
||||
|
||||
int imageWidth = mTiledTexture.getWidth();
|
||||
int imageHeight = mTiledTexture.getHeight();
|
||||
|
||||
float scaleX = (float) screenWidth / imageWidth;
|
||||
float scaleY = (float) screenHeight / imageHeight;
|
||||
if (scaleX < scaleY) {
|
||||
return scaleX;
|
||||
} else {
|
||||
return scaleY;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isLoaded() {
|
||||
return mTiledTexture != null;
|
||||
}
|
||||
|
||||
public void setSeen(Rect seen) {
|
||||
mSeen.set(seen);
|
||||
mSeenDirty = true;
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Typeface;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
@@ -30,6 +31,7 @@ import com.hippo.ehviewer.gallery.GalleryProvider;
|
||||
import com.hippo.ehviewer.gallery.GalleryProviderListener;
|
||||
import com.hippo.ehviewer.gallery.GallerySpider;
|
||||
import com.hippo.ehviewer.gallery.ImageHandler;
|
||||
import com.hippo.ehviewer.gallery.ZipGalleryProvider;
|
||||
import com.hippo.ehviewer.gallery.glrenderer.TextTexture;
|
||||
import com.hippo.ehviewer.gallery.glrenderer.TiledTexture;
|
||||
import com.hippo.ehviewer.gallery.ui.GLRootView;
|
||||
@@ -39,11 +41,16 @@ import com.hippo.ehviewer.gallery.ui.GalleryView;
|
||||
import com.hippo.util.SystemUiHelper;
|
||||
import com.hippo.yorozuya.LayoutUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class GalleryActivity extends StatsActivity implements TiledTexture.OnFreeBitmapListener, GalleryProviderListener {
|
||||
|
||||
public static final String ACTION_GALLERY_FROM_GALLERY_BASE = "com.hippo.ehviewer.gallery.action.GALLERY_FROM_GALLERY_BASE";
|
||||
public static final String ACTION_GALLERY_FROM_ARCHIVE = "com.hippo.ehviewer.gallery.action.GALLERY_FROM_ARCHIVE";
|
||||
|
||||
public static final String KEY_GALLERY_BASE = "gallery_base";
|
||||
public static final String KEY_ARCHIVE_URI = "archive_uri";
|
||||
|
||||
private SystemUiHelper mSystemUiHelper;
|
||||
|
||||
@@ -57,9 +64,7 @@ public class GalleryActivity extends StatsActivity implements TiledTexture.OnFre
|
||||
|
||||
private TextTexture mTextTexture;
|
||||
|
||||
private GallerySpider mGallerySpider;
|
||||
|
||||
private GalleryBase mGalleryBase;
|
||||
private GalleryProvider mGalleryProvider;
|
||||
|
||||
private boolean mDieYoung;
|
||||
|
||||
@@ -67,35 +72,47 @@ public class GalleryActivity extends StatsActivity implements TiledTexture.OnFre
|
||||
|
||||
private int mSize;
|
||||
|
||||
private boolean handleIntent(Intent intent) {
|
||||
private boolean getGalleryProvider(Intent intent) {
|
||||
if (intent != null) {
|
||||
mGalleryBase = intent.getParcelableExtra(KEY_GALLERY_BASE);
|
||||
return mGalleryBase != null;
|
||||
} else {
|
||||
return false;
|
||||
String action = intent.getAction();
|
||||
if (ACTION_GALLERY_FROM_GALLERY_BASE.equals(action)) {
|
||||
GalleryBase galleryBase = intent.getParcelableExtra(KEY_GALLERY_BASE);
|
||||
if (galleryBase != null) {
|
||||
try {
|
||||
// TODO get mode
|
||||
mGalleryProvider = GallerySpider.obtain(galleryBase, ImageHandler.Mode.DOWNLOAD);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else if (ACTION_GALLERY_FROM_ARCHIVE.equals(action)) {
|
||||
Uri uri = intent.getParcelableExtra(KEY_ARCHIVE_URI);
|
||||
if (uri != null) {
|
||||
try {
|
||||
// TODO support other archive
|
||||
mGalleryProvider = new ZipGalleryProvider(new File(uri.getPath()));
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (!handleIntent(getIntent())) {
|
||||
if (!getGalleryProvider(getIntent())) {
|
||||
mDieYoung = true;
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
mGallerySpider = GallerySpider.obtain(mGalleryBase, ImageHandler.Mode.DOWNLOAD);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
mDieYoung = true;
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
mGallerySpider.addGalleryProviderListener(this);
|
||||
|
||||
mSystemUiHelper = new SystemUiHelper(this, SystemUiHelper.LEVEL_IMMERSIVE,
|
||||
SystemUiHelper.FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES | SystemUiHelper.FLAG_IMMERSIVE_STICKY);
|
||||
mSystemUiHelper.hide();
|
||||
@@ -122,12 +139,13 @@ public class GalleryActivity extends StatsActivity implements TiledTexture.OnFre
|
||||
mGalleryView.setProgressSize(LayoutUtils.dp2pix(this, 56));
|
||||
mGalleryView.setInterval(LayoutUtils.dp2pix(this, 48));
|
||||
|
||||
mSize = mGallerySpider.size();
|
||||
mSize = mGalleryProvider.size();
|
||||
if (mSize <= 0) {
|
||||
setMode(GalleryView.Mode.NONE);
|
||||
} else {
|
||||
setMode(GalleryView.Mode.LEFT_TO_RIGHT);
|
||||
}
|
||||
mGalleryProvider.addGalleryProviderListener(this);
|
||||
|
||||
glRootView.setContentPane(mGalleryView);
|
||||
}
|
||||
@@ -146,9 +164,15 @@ public class GalleryActivity extends StatsActivity implements TiledTexture.OnFre
|
||||
mTextTexture.recycle();
|
||||
TiledTexture.setOnFreeBitmapListener(null);
|
||||
TiledTexture.freeResources();
|
||||
mGallerySpider.removeGalleryProviderListener(this);
|
||||
GallerySpider.release(mGallerySpider);
|
||||
mGallerySpider = null;
|
||||
mGalleryProvider.removeGalleryProviderListener(this);
|
||||
|
||||
if (mGalleryProvider instanceof GallerySpider) {
|
||||
GallerySpider.release((GallerySpider) mGalleryProvider);
|
||||
} else if (mGalleryProvider instanceof ZipGalleryProvider) {
|
||||
((ZipGalleryProvider) mGalleryProvider).stop();
|
||||
}
|
||||
|
||||
mGalleryProvider = null;
|
||||
}
|
||||
// TODO free all TileTexture in GalleryView
|
||||
}
|
||||
@@ -162,8 +186,8 @@ public class GalleryActivity extends StatsActivity implements TiledTexture.OnFre
|
||||
|
||||
@Override
|
||||
public void onFreeBitmapListener(Bitmap bitmap) {
|
||||
if (mGallerySpider != null) {
|
||||
mGallerySpider.releaseBitmap(bitmap);
|
||||
if (mGalleryProvider != null) {
|
||||
mGalleryProvider.releaseBitmap(bitmap);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,8 +219,8 @@ public class GalleryActivity extends StatsActivity implements TiledTexture.OnFre
|
||||
bindBitmap(page, bitmap);
|
||||
}
|
||||
} else {
|
||||
if (mGallerySpider != null) {
|
||||
mGallerySpider.releaseBitmap(bitmap);
|
||||
if (mGalleryProvider != null) {
|
||||
mGalleryProvider.releaseBitmap(bitmap);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -281,7 +305,7 @@ public class GalleryActivity extends StatsActivity implements TiledTexture.OnFre
|
||||
}
|
||||
|
||||
private void bind(GalleryPageView view, int index) {
|
||||
Object result = mGallerySpider.request(index);
|
||||
Object result = mGalleryProvider.request(index);
|
||||
if (result instanceof Float) {
|
||||
bindPercent(view, (Float) result);
|
||||
} else if (result == GalleryProvider.RESULT_WAIT) {
|
||||
|
||||
@@ -22,7 +22,6 @@ import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.Html;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -151,13 +150,7 @@ public class GalleryDetailScene extends Scene implements View.OnClickListener,
|
||||
|
||||
Conaco conaco = EhApplication.getConaco(getStageActivity());
|
||||
mThumb.load(conaco, EhCacheKeyFactory.getThumbKey(gi.gid), gi.thumb);
|
||||
String title;
|
||||
if (Settings.getJpnTitle()) {
|
||||
title = TextUtils.isEmpty(gi.titleJpn) ? gi.title : gi.titleJpn;
|
||||
} else {
|
||||
title = gi.title;
|
||||
}
|
||||
mTitle.setText(title);
|
||||
mTitle.setText(EhUtils.getSuitableTitle(gi));
|
||||
mUploader.setText(gi.uploader);
|
||||
mCategory.setText(EhUtils.getCategory(gi.category));
|
||||
mCategory.setTextColor(EhUtils.getCategoryColor(gi.category));
|
||||
@@ -281,7 +274,11 @@ public class GalleryDetailScene extends Scene implements View.OnClickListener,
|
||||
|
||||
if (v == mRead) {
|
||||
Intent intent = new Intent(getStageActivity(), GalleryActivity.class);
|
||||
intent.setAction(GalleryActivity.ACTION_GALLERY_FROM_GALLERY_BASE);
|
||||
intent.putExtra(GalleryActivity.KEY_GALLERY_BASE, mGalleryDetail);
|
||||
//intent.setAction(GalleryActivity.ACTION_GALLERY_FROM_ARCHIVE);
|
||||
//intent.putExtra(GalleryActivity.KEY_ARCHIVE_URI,
|
||||
// Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "a.zip")));
|
||||
getStageActivity().startActivity(intent);
|
||||
} else if (v == mDownload) {
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public class DownloadSettingsScene extends PreferenceScene implements Preference
|
||||
imagePreference.setOnClickListener(this);
|
||||
|
||||
String archiveSummary;
|
||||
UniFile archiveDir = Settings.getImageDownloadLocation();
|
||||
UniFile archiveDir = Settings.getArchiveDownloadLocation();
|
||||
if (archiveDir == null) {
|
||||
archiveSummary = resources.getString(R.string.unknown);
|
||||
} else {
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.hippo.httpclient.HttpRequest;
|
||||
import com.hippo.httpclient.HttpResponse;
|
||||
import com.hippo.io.UniFileOutputStreamPipe;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.Utilities;
|
||||
import com.hippo.yorozuya.io.OutputStreamPipe;
|
||||
|
||||
@@ -72,6 +73,7 @@ public class DownloadClient {
|
||||
return;
|
||||
}
|
||||
|
||||
UniFile uniFile = null;
|
||||
OutputStreamPipe osPipe = null;
|
||||
try {
|
||||
// Listener
|
||||
@@ -96,8 +98,8 @@ public class DownloadClient {
|
||||
}
|
||||
request.mFilename = filename;
|
||||
|
||||
// TODO use download file name then rename
|
||||
UniFile uniFile = request.mDir.createDirectory(filename);
|
||||
// Use Temp filename
|
||||
uniFile = request.mDir.createFile(FileUtils.ensureFilename(filename + ".download"));
|
||||
if (uniFile == null) {
|
||||
// Listener
|
||||
if (listener != null) {
|
||||
@@ -118,7 +120,14 @@ public class DownloadClient {
|
||||
|
||||
long receivedSize = transferData(httpResponse.getInputStream(), osPipe.open(), listener);
|
||||
|
||||
// TODO check contentLength == receivedSize
|
||||
if (contentLength > 0 && contentLength != receivedSize) {
|
||||
throw new IOException("contentLength is " + contentLength + ", but receivedSize is " + receivedSize);
|
||||
}
|
||||
|
||||
// Rename
|
||||
if (uniFile != null && request.mFilename != null) {
|
||||
uniFile.renameTo(request.mFilename);
|
||||
}
|
||||
|
||||
// Listener
|
||||
if (listener != null) {
|
||||
@@ -126,11 +135,8 @@ public class DownloadClient {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// remove download failed file
|
||||
if (request.mFilename != null && request.mDir != null) {
|
||||
UniFile file = request.mDir.findFile(request.mFilename);
|
||||
if (file != null) {
|
||||
file.delete();
|
||||
}
|
||||
if (uniFile != null) {
|
||||
uniFile.delete();
|
||||
}
|
||||
|
||||
if (listener != null) {
|
||||
@@ -177,7 +183,7 @@ public class DownloadClient {
|
||||
|
||||
void onStartDownloading();
|
||||
|
||||
String onFixname(String filename, String extension, String oldFilename);
|
||||
String onFixname(String fileFirstname, String extension, String oldFilename);
|
||||
|
||||
void onConnect(long totalSize);
|
||||
|
||||
|
||||
+1
-1
Submodule unifile updated: 532f09d537...29bf622586.
+1
-1
Submodule yorozuya updated: 482a8c4838...8a6459d77e.
Reference in new issue
Block a user