Use jitpack libraries

This commit is contained in:
seven332 committed 2016-04-30 19:03:59 +08:00
1 parent d186a6ac3b
commit e3113083bc
136 files changed
+473 -21172

No files matched your search

@@ -24,6 +24,9 @@ import android.support.v7.graphics.drawable.DrawableWrapper;
import com.hippo.yorozuya.MathUtils;
/**
* Show a part of the original drawable
*/
public class PreciselyClipDrawable extends DrawableWrapper {
private final boolean mClip;
@@ -16,26 +16,59 @@
package com.hippo.drawable;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.widget.TextView;
import android.util.Log;
import com.hippo.conaco.Conaco;
import com.hippo.conaco.ConacoTask;
import com.hippo.conaco.Unikery;
import com.hippo.conaco.ValueHolder;
import com.hippo.image.ImageBitmap;
import com.hippo.image.ImageDrawable;
import com.hippo.image.RecycledException;
import com.hippo.widget.ObservedTextView;
public class UnikeryDrawable extends WrapDrawable implements Unikery<Bitmap> {
public class UnikeryDrawable extends WrapDrawable implements Unikery<ImageBitmap>,
ObservedTextView.OnWindowAttachListener {
private static final String TAG = UnikeryDrawable.class.getSimpleName();
private int mTaskId = Unikery.INVALID_ID;
private final TextView mTextView;
private final ObservedTextView mTextView;
private final Conaco<ImageBitmap> mConaco;
private String mUrl;
private ValueHolder<Bitmap> mHolder;
public UnikeryDrawable(TextView textView) {
public UnikeryDrawable(ObservedTextView textView, Conaco<ImageBitmap> conaco) {
mTextView = textView;
mTextView.setOnWindowAttachListener(this);
mConaco = conaco;
}
@Override
public void onAttachedToWindow() {
load(mUrl);
}
@Override
public void onDetachedFromWindow() {
mConaco.cancel(this);
clearDrawable();
}
public void load(String url) {
if (url != null) {
mUrl = url;
mConaco.load(new ConacoTask.Builder<ImageBitmap>().setUnikery(this).setUrl(url).setKey(url));
}
}
private void clearDrawable() {
Drawable drawable = getDrawable();
if (drawable instanceof ImageDrawable) {
((ImageDrawable) drawable).recycle();
}
setDrawable(null);
}
@Override
@@ -54,9 +87,7 @@ public class UnikeryDrawable extends WrapDrawable implements Unikery<Bitmap> {
updateBounds();
if (drawable != null) {
// mTextView.requestLayout() not work!
CharSequence cs = mTextView.getText();
mTextView.setText(cs);
invalidateSelf();
}
}
@@ -71,49 +102,41 @@ public class UnikeryDrawable extends WrapDrawable implements Unikery<Bitmap> {
}
@Override
public void onMiss(Conaco.Source source) {
public void invalidateSelf() {
CharSequence cs = mTextView.getText();
mTextView.setText(cs);
}
@Override
public void onRequest() {
}
public void onMiss(int source) {}
@Override
public void onProgress(long singleReceivedSize, long receivedSize, long totalSize) {
}
public void onRequest() {}
private void removeDrawableAndHolder() {
// Remove drawable
setDrawable(null);
@Override
public void onProgress(long singleReceivedSize, long receivedSize, long totalSize) {}
// Remove holder
if (mHolder != null) {
mHolder.release(this);
mHolder = null;
@Override
public void onWait() {}
@Override
public boolean onGetValue(@NonNull ImageBitmap value, int source) {
ImageDrawable drawable;
try {
drawable = new ImageDrawable(value);
} catch (RecycledException e) {
Log.d(TAG, "The ImageBitmap is recycled", e);
return false;
}
}
@Override
public boolean onGetObject(@NonNull ValueHolder<Bitmap> holder, Conaco.Source source) {
holder.obtain(this);
removeDrawableAndHolder();
mHolder = holder;
Drawable drawable = new BitmapDrawable(mTextView.getResources(), holder.getValue());
clearDrawable();
setDrawable(drawable);
drawable.start();
return true;
}
@Override
public void onSetDrawable(Drawable drawable) {
removeDrawableAndHolder();
setDrawable(drawable);
}
@Override
public void onFailure() {
// Empty
@@ -22,7 +22,6 @@ import android.content.ComponentCallbacks2;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.os.Debug;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@@ -41,6 +40,7 @@ import com.hippo.ehviewer.client.data.GalleryDetail;
import com.hippo.ehviewer.download.DownloadManager;
import com.hippo.ehviewer.spider.SpiderDen;
import com.hippo.ehviewer.ui.CommonOperations;
import com.hippo.image.ImageBitmap;
import com.hippo.network.StatusCodeException;
import com.hippo.okhttp.CookieDB;
import com.hippo.scene.SceneApplication;
@@ -79,8 +79,8 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
private EhCookieStore mEhCookieStore;
private EhClient mEhClient;
private OkHttpClient mOkHttpClient;
private BitmapHelper mBitmapHelper;
private Conaco<Bitmap> mConaco;
private ImageBitmapHelper mImageBitmapHelper;
private Conaco<ImageBitmap> mConaco;
private LruCache<Long, GalleryDetail> mGalleryDetailCache;
private SimpleDiskCache mSpiderInfoCache;
private DownloadManager mDownloadManager;
@@ -194,7 +194,7 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
public void clearMemoryCache() {
if (null != mConaco) {
mConaco.clearMemoryCache();
mConaco.getBeerBelly().clearMemory();
}
if (null != mGalleryDetailCache) {
mGalleryDetailCache.evictAll();
@@ -275,12 +275,12 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
}
@NonNull
public static BitmapHelper getBitmapHelper(@NonNull Context context) {
public static ImageBitmapHelper getImageBitmapHelper(@NonNull Context context) {
EhApplication application = ((EhApplication) context.getApplicationContext());
if (application.mBitmapHelper == null) {
application.mBitmapHelper = new BitmapHelper();
if (application.mImageBitmapHelper == null) {
application.mImageBitmapHelper = new ImageBitmapHelper();
}
return application.mBitmapHelper;
return application.mImageBitmapHelper;
}
private static int getMemoryCacheMaxSize(Context context) {
@@ -291,17 +291,17 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
}
@NonNull
public static Conaco<Bitmap> getConaco(@NonNull Context context) {
public static Conaco<ImageBitmap> getConaco(@NonNull Context context) {
EhApplication application = ((EhApplication) context.getApplicationContext());
if (application.mConaco == null) {
Conaco.Builder<Bitmap> builder = new Conaco.Builder<>();
Conaco.Builder<ImageBitmap> builder = new Conaco.Builder<>();
builder.hasMemoryCache = true;
builder.memoryCacheMaxSize = getMemoryCacheMaxSize(context);
builder.hasDiskCache = true;
builder.diskCacheDir = new File(context.getCacheDir(), "thumb");
builder.diskCacheMaxSize = 80 * 1024 * 1024; // 80MB
builder.okHttpClient = getOkHttpClient(context);
builder.objectHelper = getBitmapHelper(context);
builder.objectHelper = getImageBitmapHelper(context);
builder.debug = DEBUG_CONACO;
application.mConaco = builder.build();
}
@@ -47,7 +47,7 @@ import com.hippo.util.SqlUtils;
import com.hippo.yorozuya.FileUtils;
import com.hippo.yorozuya.IOUtils;
import com.hippo.yorozuya.ObjectUtils;
import com.hippo.yorozuya.sparse.SparseJLArray;
import com.hippo.yorozuya.collect.SparseJLArray;
import java.io.File;
import java.io.FileInputStream;
@@ -16,25 +16,31 @@
package com.hippo.ehviewer;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.hippo.conaco.ValueHelper;
import com.hippo.conaco.ValueHolder;
import com.hippo.yorozuya.io.InputStreamPipe;
import com.hippo.image.Image;
import com.hippo.image.ImageBitmap;
import com.hippo.streampipe.InputStreamPipe;
import java.io.IOException;
public class BitmapHelper implements ValueHelper<Bitmap> {
public class ImageBitmapHelper implements ValueHelper<ImageBitmap> {
private static final int MAX_CACHE_SIZE = 512 * 512;
@Nullable
@Override
public Bitmap decode(@NonNull InputStreamPipe isPipe) {
public ImageBitmap decode(@NonNull InputStreamPipe isPipe) {
try {
isPipe.obtain();
return BitmapFactory.decodeStream(isPipe.open());
Image image = Image.decode(isPipe.open(), false);
if (image != null) {
return new ImageBitmap(image);
} else {
return null;
}
} catch (OutOfMemoryError e) {
return null;
} catch (IOException e) {
@@ -46,15 +52,26 @@ public class BitmapHelper implements ValueHelper<Bitmap> {
}
@Override
public int sizeOf(@NonNull String key, @NonNull Bitmap value) {
return value.getByteCount();
public int sizeOf(@NonNull String key, @NonNull ImageBitmap value) {
return value.getWidth() * value.getHeight() * 4;
}
@Override
public void onRemove(@NonNull String key, @NonNull ValueHolder<Bitmap> oldValue) {}
public void onAddToMemoryCache(@NonNull ImageBitmap oldValue) {
oldValue.obtain();
}
@Override
public boolean useMemoryCache(@NonNull String key, ValueHolder<Bitmap> holder) {
return true;
public void onRemoveFromMemoryCache(@NonNull String key, @NonNull ImageBitmap oldValue) {
oldValue.release();
}
@Override
public boolean useMemoryCache(@NonNull String key, ImageBitmap value) {
if (value != null) {
return value.getWidth() * value.getHeight() <= MAX_CACHE_SIZE;
} else {
return true;
}
}
}
@@ -22,8 +22,8 @@ import android.os.AsyncTask;
import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.client.data.GalleryInfo;
import com.hippo.ehviewer.client.exception.CancelledException;
import com.hippo.yorozuya.PriorityThreadFactory;
import com.hippo.yorozuya.SimpleHandler;
import com.hippo.yorozuya.thread.PriorityThreadFactory;
import java.io.File;
import java.util.List;
@@ -21,7 +21,7 @@ import android.os.Parcelable;
import com.hippo.ehviewer.client.EhCacheKeyFactory;
import com.hippo.widget.LoadImageView;
import com.hippo.yorozuya.IntList;
import com.hippo.yorozuya.collect.IntList;
import java.util.ArrayList;
@@ -19,7 +19,7 @@ package com.hippo.ehviewer.client.data;
import android.os.Parcel;
import com.hippo.widget.LoadImageView;
import com.hippo.yorozuya.IntList;
import com.hippo.yorozuya.collect.IntList;
import java.util.ArrayList;
@@ -28,12 +28,12 @@ import com.hippo.ehviewer.dao.DownloadLabel;
import com.hippo.ehviewer.spider.SpiderQueen;
import com.hippo.image.Image;
import com.hippo.yorozuya.ConcurrentPool;
import com.hippo.yorozuya.LongList;
import com.hippo.yorozuya.MathUtils;
import com.hippo.yorozuya.ObjectUtils;
import com.hippo.yorozuya.SimpleHandler;
import com.hippo.yorozuya.sparse.SparseIJArray;
import com.hippo.yorozuya.sparse.SparseJLArray;
import com.hippo.yorozuya.collect.LongList;
import com.hippo.yorozuya.collect.SparseIJArray;
import com.hippo.yorozuya.collect.SparseJLArray;
import java.util.ArrayList;
import java.util.Collections;
@@ -40,10 +40,10 @@ import com.hippo.ehviewer.ui.scene.DownloadsScene;
import com.hippo.scene.StageActivity;
import com.hippo.util.ReadableTime;
import com.hippo.yorozuya.FileUtils;
import com.hippo.yorozuya.LongList;
import com.hippo.yorozuya.SimpleHandler;
import com.hippo.yorozuya.sparse.SparseJBArray;
import com.hippo.yorozuya.sparse.SparseJLArray;
import com.hippo.yorozuya.collect.LongList;
import com.hippo.yorozuya.collect.SparseJBArray;
import com.hippo.yorozuya.collect.SparseJLArray;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -28,8 +28,8 @@ import com.hippo.image.Image;
import com.hippo.unifile.UniFile;
import com.hippo.yorozuya.FileUtils;
import com.hippo.yorozuya.IOUtils;
import com.hippo.yorozuya.PriorityThread;
import com.hippo.yorozuya.StringUtils;
import com.hippo.yorozuya.thread.PriorityThread;
import java.io.File;
import java.io.FilenameFilter;
@@ -26,8 +26,8 @@ import com.hippo.ehviewer.R;
import com.hippo.ehviewer.gallery.gl.GalleryPageView;
import com.hippo.image.Image;
import com.hippo.unifile.UniFile;
import com.hippo.yorozuya.PriorityThread;
import com.hippo.yorozuya.StringUtils;
import com.hippo.yorozuya.thread.PriorityThread;
import java.io.File;
import java.io.FileNotFoundException;
@@ -184,8 +184,8 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
@Override
public void onAttach(GalleryView.Adapter adapter) {
AssertUtils.assertEquals("The PagerLayoutManager is attached", mAdapter, null);
AssertUtils.assertNotEquals("The adapter is null", adapter, null);
AssertUtils.assertNull("The PagerLayoutManager is attached", mAdapter);
AssertUtils.assertNotNull("The adapter is null", adapter);
mAdapter = adapter;
// Reset parameters
resetParameters();
@@ -232,7 +232,7 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
@Override
public GalleryView.Adapter onDetach() {
AssertUtils.assertNotEquals("The PagerLayoutManager is not attached", mAdapter, null);
AssertUtils.assertNotNull("The PagerLayoutManager is not attached", mAdapter);
// Cancel all animations
cancelAllAnimations();
@@ -293,7 +293,7 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
public void onFill() {
GalleryView.Adapter adapter = mAdapter;
GalleryView galleryView = mGalleryView;
AssertUtils.assertNotEquals("The PagerLayoutManager is not attached", adapter, null);
AssertUtils.assertNotNull("The PagerLayoutManager is not attached", adapter);
int width = galleryView.getWidth();
int height = galleryView.getHeight();
@@ -703,7 +703,7 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
@Override
public void onDataChanged() {
AssertUtils.assertNotEquals("The PagerLayoutManager is not attached", mAdapter, null);
AssertUtils.assertNotNull("The PagerLayoutManager is not attached", mAdapter);
// Cancel all animations
cancelAllAnimations();
@@ -112,8 +112,8 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
@Override
public void onAttach(GalleryView.Adapter adapter) {
AssertUtils.assertEquals("The ScrollLayoutManager is attached", mAdapter, null);
AssertUtils.assertNotEquals("The iterator is null", adapter, null);
AssertUtils.assertNull("The ScrollLayoutManager is attached", mAdapter);
AssertUtils.assertNotNull("The iterator is null", adapter);
mAdapter = adapter;
// Reset parameters
resetParameters();
@@ -151,7 +151,7 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
@Override
public GalleryView.Adapter onDetach() {
AssertUtils.assertNotEquals("The PagerLayoutManager is not attached", mAdapter, null);
AssertUtils.assertNotNull("The PagerLayoutManager is not attached", mAdapter);
// Cancel all animations
cancelAllAnimations();
@@ -396,7 +396,7 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
public void onFill() {
GalleryView.Adapter adapter = mAdapter;
GalleryView galleryView = mGalleryView;
AssertUtils.assertNotEquals("The PagerLayoutManager is not attached", adapter, null);
AssertUtils.assertNotNull("The PagerLayoutManager is not attached", adapter);
int size = adapter.size();
String errorStr = adapter.getError();
@@ -831,7 +831,7 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
@Override
public void onDataChanged() {
AssertUtils.assertNotEquals("The PagerLayoutManager is not attached", mAdapter, null);
AssertUtils.assertNotNull("The PagerLayoutManager is not attached", mAdapter);
// Cancel all animations
cancelAllAnimations();
@@ -30,14 +30,14 @@ import com.hippo.ehviewer.client.data.GalleryInfo;
import com.hippo.ehviewer.gallery.GalleryProvider;
import com.hippo.io.UniFileInputStreamPipe;
import com.hippo.io.UniFileOutputStreamPipe;
import com.hippo.streampipe.InputStreamPipe;
import com.hippo.streampipe.OutputStreamPipe;
import com.hippo.unifile.FilenameFilter;
import com.hippo.unifile.UniFile;
import com.hippo.yorozuya.FileUtils;
import com.hippo.yorozuya.IOUtils;
import com.hippo.yorozuya.MathUtils;
import com.hippo.yorozuya.Utilities;
import com.hippo.yorozuya.io.InputStreamPipe;
import com.hippo.yorozuya.io.OutputStreamPipe;
import java.io.File;
import java.io.IOException;
@@ -48,18 +48,18 @@ import com.hippo.ehviewer.client.parser.GalleryPageUrlParser;
import com.hippo.ehviewer.gallery.GalleryProvider;
import com.hippo.ehviewer.gallery.gl.GalleryPageView;
import com.hippo.image.Image;
import com.hippo.streampipe.InputStreamPipe;
import com.hippo.streampipe.OutputStreamPipe;
import com.hippo.unifile.UniFile;
import com.hippo.util.ExceptionUtils;
import com.hippo.yorozuya.IOUtils;
import com.hippo.yorozuya.MathUtils;
import com.hippo.yorozuya.OSUtils;
import com.hippo.yorozuya.PriorityThread;
import com.hippo.yorozuya.PriorityThreadFactory;
import com.hippo.yorozuya.StringUtils;
import com.hippo.yorozuya.Utilities;
import com.hippo.yorozuya.io.InputStreamPipe;
import com.hippo.yorozuya.io.OutputStreamPipe;
import com.hippo.yorozuya.sparse.SparseJLArray;
import com.hippo.yorozuya.collect.SparseJLArray;
import com.hippo.yorozuya.thread.PriorityThread;
import com.hippo.yorozuya.thread.PriorityThreadFactory;
import java.io.IOException;
import java.io.InputStream;
@@ -86,10 +86,10 @@ import com.hippo.widget.LoadImageView;
import com.hippo.widget.recyclerview.AutoStaggeredGridLayoutManager;
import com.hippo.yorozuya.AssertUtils;
import com.hippo.yorozuya.FileUtils;
import com.hippo.yorozuya.LongList;
import com.hippo.yorozuya.ObjectUtils;
import com.hippo.yorozuya.ResourcesUtils;
import com.hippo.yorozuya.ViewUtils;
import com.hippo.yorozuya.collect.LongList;
import java.util.ArrayList;
import java.util.LinkedList;
@@ -74,14 +74,15 @@ import com.hippo.util.TextUrl;
import com.hippo.view.ViewTransition;
import com.hippo.widget.FabLayout;
import com.hippo.widget.LinkifyTextView;
import com.hippo.widget.ObservedTextView;
import com.hippo.yorozuya.AnimationUtils;
import com.hippo.yorozuya.AssertUtils;
import com.hippo.yorozuya.IntList;
import com.hippo.yorozuya.LayoutUtils;
import com.hippo.yorozuya.ResourcesUtils;
import com.hippo.yorozuya.SimpleAnimatorListener;
import com.hippo.yorozuya.StringUtils;
import com.hippo.yorozuya.ViewUtils;
import com.hippo.yorozuya.collect.IntList;
import java.util.ArrayList;
import java.util.List;
@@ -616,7 +617,7 @@ public final class GalleryCommentsScene extends ToolbarScene
return new CommentHolder(mInflater.inflate(R.layout.item_gallery_comment, parent, false));
}
public CharSequence generateComment(Context context, TextView textView, GalleryComment comment) {
public CharSequence generateComment(Context context, ObservedTextView textView, GalleryComment comment) {
SpannableStringBuilder ssb = Html.fromHtml(comment.comment, new URLImageGetter(textView,
EhApplication.getConaco(context)), null);
@@ -96,6 +96,7 @@ import com.hippo.util.ReadableTime;
import com.hippo.view.ViewTransition;
import com.hippo.widget.AutoWrapLayout;
import com.hippo.widget.LoadImageView;
import com.hippo.widget.ObservedTextView;
import com.hippo.widget.ProgressView;
import com.hippo.widget.ProgressiveRatingBar;
import com.hippo.widget.SimpleGridAutoSpanLayout;
@@ -869,7 +870,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
user.setText(comment.user);
TextView time = (TextView) v.findViewById(R.id.time);
time.setText(ReadableTime.getTimeAgo(comment.time));
TextView c = (TextView) v.findViewById(R.id.comment);
ObservedTextView c = (ObservedTextView) v.findViewById(R.id.comment);
c.setMaxLines(5);
c.setText(Html.fromHtml(comment.comment,
new URLImageGetter(c, EhApplication.getConaco(context)), null));
@@ -22,14 +22,14 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.text.TextUtils;
import android.util.Log;
import com.hippo.util.SqlUtils;
import com.hippo.yorozuya.Say;
import java.util.LinkedList;
import java.util.List;
public class SearchDatabase {
public final class SearchDatabase {
private static final String TAG = SearchDatabase.class.getSimpleName();
@@ -41,7 +41,7 @@ public class SearchDatabase {
private static final int MAX_HISTORY = 100;
private SQLiteDatabase mDatabase;
private final SQLiteDatabase mDatabase;
private static SearchDatabase sInstance;
@@ -127,11 +127,10 @@ public class SearchDatabase {
}
mDatabase.delete(TABLE_SUGGESTIONS, selection, null);
} catch (RuntimeException e) {
Say.e(TAG, "truncateHistory", e);
Log.e(TAG, "truncateHistory", e);
}
}
/**
* Builds the database. This version has extra support for using the version field
* as a mode flags field, and configures the database columns depending on the mode bits
@@ -24,8 +24,8 @@ import android.opengl.GLUtils;
import android.opengl.Matrix;
import android.util.Log;
import com.hippo.yorozuya.IntArray;
import com.hippo.yorozuya.MathUtils;
import com.hippo.yorozuya.collect.IntList;
import java.nio.Buffer;
import java.nio.ByteBuffer;
@@ -166,7 +166,7 @@ public class GLES20Canvas implements GLCanvas {
// Keep track of restore state
private float[] mMatrices = new float[INITIAL_RESTORE_STATE_SIZE * MATRIX_SIZE];
private float[] mAlphas = new float[INITIAL_RESTORE_STATE_SIZE];
private IntArray mSaveFlags = new IntArray();
private final IntList mSaveFlags = new IntList();
private int mCurrentAlphaIndex = 0;
private int mCurrentMatrixIndex = 0;
@@ -176,20 +176,20 @@ public class GLES20Canvas implements GLCanvas {
private int mHeight;
// Projection matrix
private float[] mProjectionMatrix = new float[MATRIX_SIZE];
private final float[] mProjectionMatrix = new float[MATRIX_SIZE];
// Screen size for when we aren't bound to a texture
private int mScreenWidth;
private int mScreenHeight;
// GL programs
private int mDrawProgram;
private int mTextureProgram;
private int mOesTextureProgram;
private int mMeshProgram;
private final int mDrawProgram;
private final int mTextureProgram;
private final int mOesTextureProgram;
private final int mMeshProgram;
// GL buffer containing BOX_COORDINATES
private int mBoxCoordinates;
private final int mBoxCoordinates;
// Handle indices -- common
private static final int INDEX_POSITION = 0;
@@ -268,8 +268,8 @@ public class GLES20Canvas implements GLCanvas {
new UniformShaderParameter(ALPHA_UNIFORM), // INDEX_ALPHA
};
private final IntArray mUnboundTextures = new IntArray();
private final IntArray mDeleteBuffers = new IntArray();
private final IntList mUnboundTextures = new IntList();
private final IntList mDeleteBuffers = new IntList();
// Keep track of statistics for debugging
private int mCountDrawMesh = 0;
@@ -279,10 +279,10 @@ public class GLES20Canvas implements GLCanvas {
// Buffer for framebuffer IDs -- we keep track so we can switch the attached
// texture.
private int[] mFrameBuffer = new int[1];
private final int[] mFrameBuffer = new int[1];
// Bound textures.
private ArrayList<RawTexture> mTargetTextures = new ArrayList<RawTexture>();
private final ArrayList<RawTexture> mTargetTextures = new ArrayList<>();
// Temporary variables used within calculations
private final float[] mTempMatrix = new float[32];
@@ -492,7 +492,7 @@ public class GLES20Canvas implements GLCanvas {
@Override
public void restore() {
int restoreFlags = mSaveFlags.removeLast();
int restoreFlags = mSaveFlags.removeAt(mSaveFlags.size() - 1);
boolean restoreAlpha = (restoreFlags & SAVE_FLAG_ALPHA) == SAVE_FLAG_ALPHA;
if (restoreAlpha) {
mCurrentAlphaIndex--;
@@ -869,7 +869,7 @@ public class GLES20Canvas implements GLCanvas {
@Override
public void deleteRecycledResources() {
synchronized (mUnboundTextures) {
IntArray ids = mUnboundTextures;
IntList ids = mUnboundTextures;
if (mUnboundTextures.size() > 0) {
mGLId.glDeleteTextures(null, ids.size(), ids.getInternalArray(), 0);
ids.clear();
@@ -25,8 +25,8 @@ import android.support.annotation.NonNull;
import com.hippo.gl.annotation.RenderThread;
import com.hippo.gl.view.GLRoot;
import com.hippo.image.Image;
import com.hippo.yorozuya.PVLock;
import com.hippo.yorozuya.PriorityThreadFactory;
import com.hippo.yorozuya.thread.PVLock;
import com.hippo.yorozuya.thread.PriorityThreadFactory;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -18,7 +18,7 @@ package com.hippo.gl.util;
import android.graphics.Color;
import com.hippo.yorozuya.AssertUtils;
import com.hippo.yorozuya.AssertError;
public class GalleryUtils {
@@ -51,6 +51,8 @@ public class GalleryUtils {
}
public static void assertInRenderThread() {
AssertUtils.assertEquals("Should not do this in render thread", sCurrentThread, Thread.currentThread());
if (sCurrentThread != Thread.currentThread()) {
throw new AssertError("Should not do this in render thread");
}
}
}
@@ -23,20 +23,20 @@ import com.hippo.gl.glrenderer.GLCanvas;
import com.hippo.gl.glrenderer.MovableTextTexture;
import com.hippo.gl.view.GLView;
import com.hippo.gl.view.Gravity;
import com.hippo.yorozuya.ArrayUtils;
import com.hippo.yorozuya.collect.CollectionUtils;
public class GLMovableTextView extends GLView {
MovableTextTexture mTextTexture;
private String mText = "";
private int[] mIndexes = ArrayUtils.EMPTY_INT_ARRAY;
private int[] mIndexes = CollectionUtils.EMPTY_INT_ARRAY;
private int mGravity = Gravity.NO_GRAVITY;
private void generateIndexes() {
if (mTextTexture == null || TextUtils.isEmpty(mText)) {
mIndexes = ArrayUtils.EMPTY_INT_ARRAY;
mIndexes = CollectionUtils.EMPTY_INT_ARRAY;
} else {
mIndexes = mTextTexture.getTextIndexes(mText);
}
@@ -18,8 +18,8 @@ package com.hippo.io;
import android.support.annotation.NonNull;
import com.hippo.streampipe.InputStreamPipe;
import com.hippo.yorozuya.IOUtils;
import com.hippo.yorozuya.io.InputStreamPipe;
import java.io.File;
import java.io.FileInputStream;
@@ -28,7 +28,7 @@ import java.io.InputStream;
public class FileInputStreamPipe implements InputStreamPipe {
private File mFile;
private final File mFile;
private InputStream mIs;
public FileInputStreamPipe(File file) {
@@ -18,8 +18,8 @@ package com.hippo.io;
import android.support.annotation.NonNull;
import com.hippo.streampipe.OutputStreamPipe;
import com.hippo.yorozuya.IOUtils;
import com.hippo.yorozuya.io.OutputStreamPipe;
import java.io.File;
import java.io.FileOutputStream;
@@ -28,7 +28,7 @@ import java.io.OutputStream;
public class FileOutputStreamPipe implements OutputStreamPipe {
private File mFile;
private final File mFile;
private OutputStream mOs;
public FileOutputStreamPipe(File file) {
@@ -18,16 +18,16 @@ package com.hippo.io;
import android.support.annotation.NonNull;
import com.hippo.streampipe.InputStreamPipe;
import com.hippo.unifile.UniFile;
import com.hippo.yorozuya.IOUtils;
import com.hippo.yorozuya.io.InputStreamPipe;
import java.io.IOException;
import java.io.InputStream;
public class UniFileInputStreamPipe implements InputStreamPipe {
private UniFile mFile;
private final UniFile mFile;
private InputStream mIs;
public UniFileInputStreamPipe(UniFile file) {
@@ -18,17 +18,16 @@ package com.hippo.io;
import android.support.annotation.NonNull;
import com.hippo.streampipe.OutputStreamPipe;
import com.hippo.unifile.UniFile;
import com.hippo.yorozuya.IOUtils;
import com.hippo.yorozuya.io.OutputStreamPipe;
import java.io.IOException;
import java.io.OutputStream;
public class UniFileOutputStreamPipe implements OutputStreamPipe {
private UniFile mUniFile;
private final UniFile mUniFile;
private OutputStream mOs;
public UniFileOutputStreamPipe(UniFile uniFile) {
@@ -25,7 +25,7 @@ import android.support.v4.app.FragmentActivity;
import android.view.View;
import com.hippo.ehviewer.R;
import com.hippo.yorozuya.IntList;
import com.hippo.yorozuya.collect.IntList;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -16,28 +16,27 @@
package com.hippo.text;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.widget.TextView;
import com.hippo.conaco.Conaco;
import com.hippo.conaco.ConacoTask;
import com.hippo.drawable.UnikeryDrawable;
import com.hippo.image.ImageBitmap;
import com.hippo.widget.ObservedTextView;
public class URLImageGetter implements Html.ImageGetter {
private final TextView mTextView;
private final Conaco<Bitmap> mConaco;
private final ObservedTextView mTextView;
private final Conaco<ImageBitmap> mConaco;
public URLImageGetter(TextView textView, Conaco<Bitmap> conaco) {
public URLImageGetter(ObservedTextView textView, Conaco<ImageBitmap> conaco) {
mTextView = textView;
mConaco = conaco;
}
@Override
public Drawable getDrawable(String source) {
UnikeryDrawable drawable = new UnikeryDrawable(mTextView);
mConaco.load(new ConacoTask.Builder<Bitmap>().setUnikery(drawable).setUrl(source).setKey(source));
UnikeryDrawable drawable = new UnikeryDrawable(mTextView, mConaco);
drawable.load(source);
return drawable;
}
}
@@ -22,12 +22,13 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.annotation.NonNull;
import com.hippo.streampipe.InputStreamPipe;
import com.hippo.yorozuya.MathUtils;
import com.hippo.yorozuya.io.InputStreamPipe;
import java.io.IOException;
public class BitmapUtils {
public final class BitmapUtils {
private BitmapUtils() {}
public static Context sContext;
@@ -41,9 +41,9 @@ import com.hippo.util.DrawableManager;
import com.hippo.util.ExceptionUtils;
import com.hippo.view.ViewTransition;
import com.hippo.yorozuya.IntIdGenerator;
import com.hippo.yorozuya.IntList;
import com.hippo.yorozuya.LayoutUtils;
import com.hippo.yorozuya.ResourcesUtils;
import com.hippo.yorozuya.collect.IntList;
import java.util.ArrayList;
import java.util.List;
@@ -23,9 +23,8 @@ import android.text.Spanned;
import android.text.style.ClickableSpan;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.TextView;
public class LinkifyTextView extends TextView {
public class LinkifyTextView extends ObservedTextView {
private ClickableSpan mCurrentSpan;
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Hippo Seven
* Copyright 2015-2016 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,32 +18,48 @@ package com.hippo.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.support.annotation.DrawableRes;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import com.hippo.conaco.Conaco;
import com.hippo.conaco.ConacoTask;
import com.hippo.conaco.DataContainer;
import com.hippo.conaco.Unikery;
import com.hippo.conaco.ValueHolder;
import com.hippo.drawable.PreciselyClipDrawable;
import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.R;
import com.hippo.image.ImageBitmap;
import com.hippo.image.ImageDrawable;
import com.hippo.image.RecycledException;
public class LoadImageView extends FixedAspectImageView implements Unikery<Bitmap>,
View.OnClickListener, View.OnLongClickListener {
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
public class LoadImageView extends FixedAspectImageView implements Unikery<ImageBitmap>,
View.OnClickListener, View.OnLongClickListener, Animatable {
private static final String TAG = LoadImageView.class.getSimpleName();
@IntDef({RETRY_TYPE_NONE, RETRY_TYPE_CLICK, RETRY_TYPE_LONG_CLICK})
@Retention(RetentionPolicy.SOURCE)
private @interface RetryType {}
public static final int RETRY_TYPE_NONE = 0;
public static final int RETRY_TYPE_CLICK = 1;
public static final int RETRY_TYPE_LONG_CLICK = 2;
private int mTaskId = Unikery.INVALID_ID;
private Conaco<Bitmap> mConaco;
private Conaco<ImageBitmap> mConaco;
private String mKey;
private String mUrl;
@@ -55,49 +71,29 @@ public class LoadImageView extends FixedAspectImageView implements Unikery<Bitma
private int mClipWidth = Integer.MIN_VALUE;
private int mClipHeight = Integer.MIN_VALUE;
private ValueHolder<Bitmap> mHolder;
private int mRetryType;
private boolean mFailed;
private RetryType mRetryType = RetryType.NONE;
private static final RetryType[] sRetryTypeArray = {
RetryType.NONE,
RetryType.CLICK,
RetryType.LONG_CLICK
};
public enum RetryType {
NONE (0),
CLICK (1),
LONG_CLICK (2);
RetryType(int ni) {
nativeInt = ni;
}
final int nativeInt;
}
public LoadImageView(Context context) {
super(context);
init(context, null, 0, 0);
}
public LoadImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
init(context, attrs, 0, 0);
}
public LoadImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
public LoadImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context, attrs, defStyle, 0);
}
private void init(Context context, AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LoadImageView);
final int index = a.getInt(R.styleable.LoadImageView_retryType, -1);
if (index >= 0) {
setRetryType(sRetryTypeArray[index]);
}
@SuppressWarnings("WrongConstant")
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LoadImageView, defStyleAttr, defStyleRes);
setRetryType(a.getInt(R.styleable.LoadImageView_retryType, 0));
a.recycle();
if (!isInEditMode()) {
@@ -105,11 +101,23 @@ public class LoadImageView extends FixedAspectImageView implements Unikery<Bitma
}
}
@Override
public void setTaskId(int id) {
mTaskId = id;
}
@Override
public int getTaskId() {
return mTaskId;
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (!mFailed) { // Restore if not failed
if (mFailed) {
onFailure();
} else {
load(mKey, mUrl, mContainer, mUseNetwork);
}
}
@@ -117,45 +125,73 @@ public class LoadImageView extends FixedAspectImageView implements Unikery<Bitma
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
// Cancel
mConaco.cancel(this);
// Clear drawable
clearDrawable();
}
public void setRetryType(RetryType retryType) {
if (mRetryType != retryType) {
RetryType oldRetryType = mRetryType;
mRetryType = retryType;
if (mFailed) {
if (oldRetryType == RetryType.CLICK) {
setOnClickListener(null);
setClickable(false);
} else if (oldRetryType == RetryType.LONG_CLICK) {
setOnLongClickListener(null);
setLongClickable(false);
}
if (retryType == RetryType.CLICK) {
setOnClickListener(this);
} else if (retryType == RetryType.LONG_CLICK) {
setOnLongClickListener(this);
}
private ImageDrawable getImageDrawable() {
Drawable drawable = getDrawable();
if (drawable instanceof TransitionDrawable) {
TransitionDrawable transitionDrawable = (TransitionDrawable) drawable;
if (transitionDrawable.getNumberOfLayers() == 2) {
drawable = transitionDrawable.getDrawable(1);
}
}
if (drawable instanceof PreciselyClipDrawable) {
drawable = ((PreciselyClipDrawable) drawable).getWrappedDrawable();
}
if (drawable instanceof ImageDrawable) {
return (ImageDrawable) drawable;
} else {
return null;
}
}
private void cancelRetryType() {
if (mRetryType == RetryType.CLICK) {
private void clearDrawable() {
// Recycle ImageDrawable
ImageDrawable imageDrawable = getImageDrawable();
if (imageDrawable != null) {
imageDrawable.recycle();
}
// Set drawable null
setImageDrawable(null);
}
private void clearRetry() {
if (mRetryType == RETRY_TYPE_CLICK) {
setOnClickListener(null);
setClickable(false);
} else if (mRetryType == RetryType.LONG_CLICK) {
} else if (mRetryType == RETRY_TYPE_LONG_CLICK) {
setOnLongClickListener(null);
setLongClickable(false);
}
}
public void load(String key, String url) {
load(key, url, null, true);
public void setRetryType(@RetryType int retryType) {
if (mRetryType != retryType) {
int oldRetryType = mRetryType;
mRetryType = retryType;
if (mFailed) {
if (oldRetryType == RETRY_TYPE_CLICK) {
setOnClickListener(null);
setClickable(false);
} else if (oldRetryType == RETRY_TYPE_LONG_CLICK) {
setOnLongClickListener(null);
setLongClickable(false);
}
if (retryType == RETRY_TYPE_CLICK) {
setOnClickListener(this);
} else if (retryType == RETRY_TYPE_LONG_CLICK) {
setOnLongClickListener(this);
}
}
}
}
public void setClip(int offsetX, int offsetY, int clipWidth, int clipHeight) {
@@ -172,28 +208,28 @@ public class LoadImageView extends FixedAspectImageView implements Unikery<Bitma
mClipHeight = Integer.MIN_VALUE;
}
public void load(String key, String url) {
load(key, url, null, true);
}
public void load(String key, String url, boolean useNetwork) {
load(key, url, null, useNetwork);
}
public void load(String key, String url, DataContainer container, boolean useNetwork) {
if (url == null || (key == null && container == null)) {
return;
}
mFailed = false;
cancelRetryType();
if (url == null) {
return;
}
if (key == null && container == null) {
return;
}
clearRetry();
mKey = key;
mUrl = url;
mContainer = container;
mUseNetwork = useNetwork;
ConacoTask.Builder<Bitmap> builder = new ConacoTask.Builder<Bitmap>()
ConacoTask.Builder<ImageBitmap> builder = new ConacoTask.Builder<ImageBitmap>()
.setUnikery(this)
.setKey(key)
.setUrl(url)
@@ -217,66 +253,45 @@ public class LoadImageView extends FixedAspectImageView implements Unikery<Bitma
mKey = null;
mUrl = null;
mContainer = null;
removeDrawableAndHolder();
clearDrawable();
}
@Override
public void setTaskId(int id) {
mTaskId = id;
}
@Override
public int getTaskId() {
return mTaskId;
}
private void removeDrawableAndHolder() {
// Remove drawable
setImageDrawable(null);
// Remove holder
if (mHolder != null) {
mHolder.release(this);
mHolder = null;
public void onMiss(int source) {
if (source == Conaco.SOURCE_MEMORY) {
clearDrawable();
}
}
@Override
public void onMiss(Conaco.Source source) {
if (source == Conaco.Source.MEMORY) {
removeDrawableAndHolder();
public void onRequest() {}
@Override
public void onProgress(long singleReceivedSize, long receivedSize, long totalSize) {}
@Override
public void onWait() {
clearDrawable();
}
@Override
public boolean onGetValue(@NonNull ImageBitmap value, int source) {
Drawable drawable;
try {
drawable = new ImageDrawable(value);
} catch (RecycledException e) {
// The image might be recycled because it is removed from memory cache.
Log.d(TAG, "The image is recycled", e);
return false;
}
}
@Override
public void onRequest() {
}
@Override
public void onProgress(long singleReceivedSize, long receivedSize, long totalSize) {
}
@Override
public boolean onGetObject(@NonNull ValueHolder<Bitmap> holder, Conaco.Source source) {
// Release
mKey = null;
mUrl = null;
mContainer = null;
holder.obtain(this);
removeDrawableAndHolder();
mHolder = holder;
Bitmap bitmap = holder.getValue();
Drawable drawable = new BitmapDrawable(getResources(), bitmap);
clearDrawable();
if (Integer.MIN_VALUE != mOffsetX) {
drawable = new PreciselyClipDrawable(drawable, mOffsetX, mOffsetY, mClipWidth, mClipHeight);
}
if ((source == Conaco.Source.DISK || source == Conaco.Source.NETWORK)) {
if ((source == Conaco.SOURCE_DISK || source == Conaco.SOURCE_NETWORK)) {
Drawable[] layers = new Drawable[2];
layers[0] = new ColorDrawable(Color.TRANSPARENT);
layers[1] = drawable;
@@ -290,23 +305,14 @@ public class LoadImageView extends FixedAspectImageView implements Unikery<Bitma
return true;
}
@Override
public void onSetDrawable(Drawable drawable) {
mKey = null;
mUrl = null;
mContainer = null;
removeDrawableAndHolder();
setImageDrawable(drawable);
}
@Override
public void onFailure() {
mFailed = true;
removeDrawableAndHolder();
clearDrawable();
setImageDrawable(getContext().getResources().getDrawable(R.drawable.image_failed));
if (mRetryType == RetryType.CLICK) {
if (mRetryType == RETRY_TYPE_CLICK) {
setOnClickListener(this);
} else if (mRetryType == RetryType.LONG_CLICK) {
} else if (mRetryType == RETRY_TYPE_LONG_CLICK) {
setOnLongClickListener(this);
} else {
// Can't retry, so release
@@ -319,11 +325,32 @@ public class LoadImageView extends FixedAspectImageView implements Unikery<Bitma
@Override
public void onCancel() {
mFailed = false;
cancelRetryType();
// release
mKey = null;
mUrl = null;
mContainer = null;
}
@Override
public void start() {
ImageDrawable drawable = getImageDrawable();
if (drawable != null) {
drawable.start();
}
}
@Override
public void stop() {
ImageDrawable drawable = getImageDrawable();
if (drawable != null) {
drawable.stop();
}
}
@Override
public boolean isRunning() {
ImageDrawable drawable = getImageDrawable();
if (drawable != null) {
return drawable.isRunning();
} else {
return false;
}
}
@Override
@@ -0,0 +1,65 @@
/*
* Copyright 2016 Hippo Seven
*
* 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.
*/
package com.hippo.widget;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
public class ObservedTextView extends TextView {
private OnWindowAttachListener mOnWindowAttachListener;
public ObservedTextView(Context context) {
super(context);
}
public ObservedTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ObservedTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (mOnWindowAttachListener != null) {
mOnWindowAttachListener.onAttachedToWindow();
}
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
if (mOnWindowAttachListener != null) {
mOnWindowAttachListener.onDetachedFromWindow();
}
}
public void setOnWindowAttachListener(OnWindowAttachListener onWindowAttachListener) {
mOnWindowAttachListener = onWindowAttachListener;
}
public interface OnWindowAttachListener {
void onAttachedToWindow();
void onDetachedFromWindow();
}
}