Improve detail scene

This commit is contained in:
seven332 committed 2015-07-04 10:49:48 +08:00
1 parent 8d980cd48b
commit 8aa6695e1b
20 files changed
+441 -522

No files matched your search

@@ -11,7 +11,7 @@ import com.hippo.ehviewer.R;
public class UnikeryDrawable extends WrapDrawable implements Unikery {
private int mTaskId;
private int mTaskId = Unikery.INVAILD_ID;
private View mView;
@@ -18,10 +18,10 @@ package com.hippo.ehviewer.client.data;
import java.util.List;
// TODO not extends GalleryInfo
public class GalleryDetail extends GalleryInfo {
public class GalleryDetail {
public int gid;
public String token;
public String thumb;
public String title;
public String titleJpn;
@@ -16,12 +16,9 @@
package com.hippo.ehviewer.client.data;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.regex.Pattern;
public class GalleryInfo implements Parcelable {
public class GalleryInfo {
/**
* ISO 639-1
@@ -98,63 +95,10 @@ public class GalleryInfo implements Parcelable {
*/
public String simpleLanguage;
public static final Creator<GalleryInfo> CREATOR =
new Creator<GalleryInfo>() {
@Override
public GalleryInfo createFromParcel(Parcel source) {
GalleryInfo p = new GalleryInfo();
p.gid = source.readInt();
p.token = source.readString();
p.title = source.readString();
p.posted = source.readString();
p.category = source.readInt();
p.thumb = source.readString();
p.uploader = source.readString();
p.rating = source.readFloat();
p.simpleLanguage = source.readString();
return p;
}
@Override
public GalleryInfo[] newArray(int size) {
return new GalleryInfo[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(gid);
dest.writeString(token);
dest.writeString(title);
dest.writeString(posted);
dest.writeInt(category);
dest.writeString(thumb);
dest.writeString(uploader);
dest.writeFloat(rating);
dest.writeString(simpleLanguage);
}
public GalleryInfo() {
// Empty
}
public GalleryInfo(GalleryInfo gi) {
gid = gi.gid;
token = gi.token;
title = gi.title;
posted = gi.posted;
category = gi.category;
thumb = gi.thumb;
uploader = gi.uploader;
rating = gi.rating;
simpleLanguage = gi.simpleLanguage;
}
@Override
public boolean equals(Object o) {
return o instanceof GalleryInfo && ((GalleryInfo) o).gid == gid;
@@ -50,8 +50,11 @@ public class LargePreviewSet extends PreviewSet {
final Item item = mItemList.get(i);
final int index = i + getStartIndex();
final ViewGroup viewGroup = (ViewGroup) simpleGridLayout.getChildAt(i);
conaco.load((LoadImageView) viewGroup.getChildAt(0),
EhImageKeyFactory.getLargePreviewKey(getGid(), index), item.imageUrl);
LoadImageView imageView = ((LoadImageView) viewGroup.getChildAt(0));
imageView.setRetryType(LoadImageView.RetryType.LONG_CLICK);
imageView.load(conaco, EhImageKeyFactory.getLargePreviewKey(getGid(), index), item.imageUrl);
((TextView) viewGroup.getChildAt(1)).setText(Integer.toString(index + 1));
}
}
@@ -61,7 +64,7 @@ public class LargePreviewSet extends PreviewSet {
int count = simpleGridLayout.getChildCount();
for (int i = 0; i < count; i++) {
final ViewGroup viewGroup = (ViewGroup) simpleGridLayout.getChildAt(i);
conaco.cancel((LoadImageView) viewGroup.getChildAt(0));
((LoadImageView) viewGroup.getChildAt(0)).cancel();
}
}
@@ -16,65 +16,7 @@
package com.hippo.ehviewer.client.data;
import android.os.Parcel;
public class LofiGalleryInfo extends GalleryInfo {
public String[] lofiTags;
public static final Creator<LofiGalleryInfo> CREATOR =
new Creator<LofiGalleryInfo>() {
@Override
public LofiGalleryInfo createFromParcel(Parcel source) {
int length;
LofiGalleryInfo p = new LofiGalleryInfo();
p.gid = source.readInt();
p.token = source.readString();
p.title = source.readString();
p.posted = source.readString();
p.category = source.readInt();
p.thumb = source.readString();
p.uploader = source.readString();
p.rating = source.readFloat();
p.simpleLanguage = source.readString();
length = source.readInt();
p.lofiTags = new String[length];
for (int i = 0; i < length; i++)
p.lofiTags[i] = source.readString();
return p;
}
@Override
public LofiGalleryInfo[] newArray(int size) {
return new LofiGalleryInfo[size];
}
};
public LofiGalleryInfo() {}
public LofiGalleryInfo(GalleryInfo galleryInfo) {
gid = galleryInfo.gid;
token = galleryInfo.token;
title = galleryInfo.title;
posted = galleryInfo.posted;
category = galleryInfo.category;
thumb = galleryInfo.thumb;
uploader = galleryInfo.uploader;
rating = galleryInfo.rating;
simpleLanguage = galleryInfo.simpleLanguage;
lofiTags = new String[0];
}
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
int length = lofiTags == null ? 0 : lofiTags.length;
dest.writeInt(length);
for (int i = 0; i < length; i++)
dest.writeString(lofiTags[i]);
}
}
@@ -23,6 +23,7 @@ import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
@@ -31,6 +32,7 @@ import com.hippo.conaco.BitmapHolder;
import com.hippo.conaco.Conaco;
import com.hippo.conaco.Unikery;
import com.hippo.ehviewer.EhImageKeyFactory;
import com.hippo.ehviewer.R;
import com.hippo.util.Log;
import com.hippo.widget.SimpleGridLayout;
@@ -81,7 +83,7 @@ public class NormalPreviewSet extends PreviewSet {
i++;
}
LoadImageTask loadImageTask = new LoadImageTask(row, imageViews);
LoadImageTask loadImageTask = new LoadImageTask(conaco, row, imageViews);
mLoadImageTasks.add(loadImageTask);
String key;
@@ -96,19 +98,32 @@ public class NormalPreviewSet extends PreviewSet {
@Override
public void cancelLoadTask(SimpleGridLayout simpleGridLayout, Conaco conaco) {
// Cancel load task
for (LoadImageTask loadImageTask : mLoadImageTasks) {
conaco.cancel(loadImageTask);
}
mLoadImageTasks.clear();
//Cancel long click
int count = simpleGridLayout.getChildCount();
for (int i = 0; i < count; i++) {
ViewGroup viewGroup = (ViewGroup) simpleGridLayout.getChildAt(i);
View view = viewGroup.getChildAt(0);
view.setOnLongClickListener(null);
view.setLongClickable(false);
}
}
class LoadImageTask implements Unikery {
private int mTaskId;
private int mTaskId = Unikery.INVAILD_ID;
private Conaco mConaco;
private Row mRow;
private ImageView[] mImageViews;
public LoadImageTask(Row row, ImageView[] imageViews) {
public LoadImageTask(Conaco conaco, Row row, ImageView[] imageViews) {
mConaco = conaco;
mRow = row;
mImageViews = imageViews;
}
@@ -175,8 +190,14 @@ public class NormalPreviewSet extends PreviewSet {
@Override
public void onFailure() {
// TODO
mLoadImageTasks.remove(this);
// Add long click to retry
RetryTask retryTask = new RetryTask(mConaco, mRow, mImageViews);
for (ImageView imageView : mImageViews) {
imageView.setImageResource(R.drawable.retry_load_image);
imageView.setOnLongClickListener(retryTask);
}
}
@Override
@@ -185,6 +206,41 @@ public class NormalPreviewSet extends PreviewSet {
}
}
class RetryTask implements View.OnLongClickListener {
private Conaco mConaco;
private Row mRow;
private ImageView[] mImageViews;
public RetryTask(Conaco conaco, Row row, ImageView[] imageViews) {
mConaco = conaco;
mRow = row;
mImageViews = imageViews;
}
@Override
public boolean onLongClick(View v) {
for (ImageView imageView : mImageViews) {
imageView.setImageDrawable(null);
imageView.setOnLongClickListener(null);
imageView.setLongClickable(false);
}
LoadImageTask loadImageTask = new LoadImageTask(mConaco, mRow, mImageViews);
mLoadImageTasks.add(loadImageTask);
String key;
if (mRow.imageIndex != -1) {
key = EhImageKeyFactory.getNormalPreviewKey(getGid(), mRow.imageIndex);
} else {
key = mRow.imageUrl;
}
mConaco.load(loadImageTask, key, mRow.imageUrl);
return true;
}
}
class Row {
public String imageUrl;
@@ -24,15 +24,24 @@ import java.util.List;
public class CommentScene extends AppbarScene {
public static final String KEY_COMMENTS = "key_comments";
private EasyRecyclerView mRecyclerView;
private CommentAdapter mAdapter;
private List<Comment> mCommentList;
@SuppressWarnings("unchecked")
private void handleAnnouncer(Announcer announcer) {
if (announcer != null) {
mCommentList = (List<Comment>) announcer.getObject();
mAdapter.notifyDataSetChanged();
if (announcer == null) {
finish();
return;
}
Object obj = announcer.getExtra(KEY_COMMENTS);
if (obj instanceof List) {
mCommentList = (List<Comment>) obj;
} else {
finish();
}
}
@@ -49,8 +58,8 @@ public class CommentScene extends AppbarScene {
mRecyclerView = (EasyRecyclerView) findViewById(R.id.recycler_view);
mAdapter = new CommentAdapter();
mRecyclerView.setAdapter(mAdapter);
CommentAdapter adapter = new CommentAdapter();
mRecyclerView.setAdapter(adapter);
mRecyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
LinearDividerItemDecoration.VERTICAL, resources.getColor(R.color.divider_light),
@@ -70,13 +79,6 @@ public class CommentScene extends AppbarScene {
handleAnnouncer(getAnnouncer());
}
@Override
protected void onRestore() {
super.onRestore();
// mCommentList is already setted, nothing to do
}
@Override
public void onIconClick() {
finish();
@@ -53,7 +53,6 @@ import com.hippo.rippleold.RippleSalon;
import com.hippo.scene.Announcer;
import com.hippo.scene.RippleCurtain;
import com.hippo.scene.Scene;
import com.hippo.scene.SimpleCurtain;
import com.hippo.scene.SimpleDialog;
import com.hippo.util.Log;
import com.hippo.util.URLImageGetter;
@@ -69,7 +68,14 @@ import static com.hippo.ehviewer.R.id.no_tags;
public class GalleryDetailScene extends Scene implements View.OnClickListener,
AccurateClick.OnAccurateClickListener {
public static final String KEY_GALLERY_INFO = "gallery_info";
public static final String ACTION_GALLERY_INFO = "action_gallery_info";
public static final String ACTION_GID_TOKEN = "action_gid_token";
public static final String ACTION_URL = "action_url";
public static final String KEY_GALLERY_INFO = "key_gallery_info";
public static final String KEY_GID = "key_gid";
public static final String KEY_TOKEN = "key_token";
public static final String KEY_URL = "key_url";
private FrameLayout mDetailFrameLayout;
@@ -116,63 +122,82 @@ public class GalleryDetailScene extends Scene implements View.OnClickListener,
}
private void handleAnnouncer(Announcer announcer) {
GalleryInfo gi;
if (announcer == null) {
Log.e("No announcer in GalleryDetailScene, finish itself");
finish();
return;
} else if (null != (gi = announcer.getParcelableExtra(KEY_GALLERY_INFO))){
Conaco conaco = EhApplication.getConaco(getStageActivity());
conaco.load(mThumb, EhImageKeyFactory.getThumbKey(gi.gid), gi.thumb);
mTitle.setText(gi.title);
mUploader.setText(gi.uploader);
mCategory.setText(EhUtils.getCategory(gi.category));
mCategory.setTextColor(EhUtils.getCategoryColor(gi.category));
requestGalleryDetail(gi);
}
Context context = getStageActivity();
Resources resources = context.getResources();
String action = announcer.getAction();
if (ACTION_GALLERY_INFO.equals(action)) {
Object obj = announcer.getExtra(KEY_GALLERY_INFO);
if (obj instanceof GalleryInfo) {
GalleryInfo gi = (GalleryInfo) obj;
mViewTransition.showView(1, false);
Conaco conaco = EhApplication.getConaco(getStageActivity());
mThumb.load(conaco, EhImageKeyFactory.getThumbKey(gi.gid), gi.thumb);
mTitle.setText(gi.title);
mUploader.setText(gi.uploader);
mCategory.setText(EhUtils.getCategory(gi.category));
mCategory.setTextColor(EhUtils.getCategoryColor(gi.category));
mRatingText.setFactory(new RatingTextViewFactory());
Drawable favoriteDrawable = resources.getDrawable(R.drawable.ic_heart_theme_primary);
Drawable torrentDrawable = resources.getDrawable(R.drawable.ic_water_pump_theme_primary);
Drawable shareDrawable = resources.getDrawable(R.drawable.ic_share_theme_primary);
Drawable rateDrawable = resources.getDrawable(R.drawable.ic_thumbs_up_down_theme_primary);
int drawableSize = resources.getDimensionPixelOffset(R.dimen.detail_action_size);
favoriteDrawable.setBounds(0, 0, drawableSize, drawableSize);
torrentDrawable.setBounds(0, 0, drawableSize, drawableSize);
shareDrawable.setBounds(0, 0, drawableSize, drawableSize);
rateDrawable.setBounds(0, 0, drawableSize, drawableSize);
mFavorite.setCompoundDrawables(null, favoriteDrawable, null, null);
mTorrent.setCompoundDrawables(null, torrentDrawable, null, null);
mShare.setCompoundDrawables(null, shareDrawable, null, null);
mRate.setCompoundDrawables(null, rateDrawable, null, null);
requestGalleryDetail(gi);
mRead.setOnClickListener(this);
mDownload.setOnClickListener(this);
mFavorite.setOnClickListener(this);
mTorrent.setOnClickListener(this);
mShare.setOnClickListener(this);
mRate.setOnClickListener(this);
Context context = getStageActivity();
Resources resources = context.getResources();
AccurateClick.setOnAccurateClickListener(mInfo, this);
AccurateClick.setOnAccurateClickListener(mComment, this);
mViewTransition.showView(1, false);
RippleSalon.addRipple(mRead, false);
RippleSalon.addRipple(mDownload, false);
RippleSalon.addRipple(mFavorite, false);
RippleSalon.addRipple(mTorrent, false);
RippleSalon.addRipple(mShare, false);
RippleSalon.addRipple(mRate, false);
mRatingText.setFactory(new RatingTextViewFactory());
Drawable favoriteDrawable = resources.getDrawable(R.drawable.ic_heart_theme_primary);
Drawable torrentDrawable = resources.getDrawable(R.drawable.ic_water_pump_theme_primary);
Drawable shareDrawable = resources.getDrawable(R.drawable.ic_share_theme_primary);
Drawable rateDrawable = resources.getDrawable(R.drawable.ic_thumbs_up_down_theme_primary);
int drawableSize = resources.getDimensionPixelOffset(R.dimen.detail_action_size);
favoriteDrawable.setBounds(0, 0, drawableSize, drawableSize);
torrentDrawable.setBounds(0, 0, drawableSize, drawableSize);
shareDrawable.setBounds(0, 0, drawableSize, drawableSize);
rateDrawable.setBounds(0, 0, drawableSize, drawableSize);
mFavorite.setCompoundDrawables(null, favoriteDrawable, null, null);
mTorrent.setCompoundDrawables(null, torrentDrawable, null, null);
mShare.setCompoundDrawables(null, shareDrawable, null, null);
mRate.setCompoundDrawables(null, rateDrawable, null, null);
mRead.setOnClickListener(this);
mDownload.setOnClickListener(this);
mFavorite.setOnClickListener(this);
mTorrent.setOnClickListener(this);
mShare.setOnClickListener(this);
mRate.setOnClickListener(this);
AccurateClick.setOnAccurateClickListener(mInfo, this);
AccurateClick.setOnAccurateClickListener(mComment, this);
RippleSalon.addRipple(mRead, false);
RippleSalon.addRipple(mDownload, false);
RippleSalon.addRipple(mFavorite, false);
RippleSalon.addRipple(mTorrent, false);
RippleSalon.addRipple(mShare, false);
RippleSalon.addRipple(mRate, false);
} else {
Log.e("Can't get GalleryDetail");
finish();
}
} else if (ACTION_GID_TOKEN.equals(action)) {
} else if (ACTION_URL.equals(action)) {
} else {
Log.e("Unkonwn action " + action);
finish();
}
}
@Override
@@ -231,12 +256,7 @@ public class GalleryDetailScene extends Scene implements View.OnClickListener,
return;
}
if (v == mInfo) {
Announcer announcer = new Announcer();
announcer.setObject(mGalleryDetail);
startScene(InfoScene.class, announcer,
new SimpleCurtain(SimpleCurtain.DIRECTION_RIGHT));
} else if (v == mRead) {
if (v == mRead) {
} else if (v == mDownload) {
@@ -261,14 +281,14 @@ public class GalleryDetailScene extends Scene implements View.OnClickListener,
int[] position = new int[2];
ViewUtils.getLocationInAncestor(mInfo, position, getSceneView());
Announcer announcer = new Announcer();
announcer.setObject(mGalleryDetail);
announcer.putExtra(InfoScene.KEY_INFO, mGalleryDetail);
startScene(InfoScene.class, announcer,
new RippleCurtain((int) x + position[0], (int) y + position[1]));
} else if (v == mComment) {
int[] position = new int[2];
ViewUtils.getLocationInAncestor(mComment, position, getSceneView());
Announcer announcer = new Announcer();
announcer.setObject(mGalleryDetail.comments);
announcer.putExtra(CommentScene.KEY_COMMENTS, mGalleryDetail.comments);
startScene(CommentScene.class, announcer,
new RippleCurtain((int) x + position[0], (int) y + position[1]));
}
@@ -658,10 +658,8 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper,
show = true;
} else if (recyclerView.computeVerticalScrollOffset() < mSearchBarOriginalBottom){
show = true;
} else if (mSearchBar.getBottom() > (mSearchBarOriginalBottom - mSearchBarOriginalTop) / 2) {
show = true;
} else {
show = false;
show = mSearchBar.getBottom() > (mSearchBarOriginalBottom - mSearchBarOriginalTop) / 2;
}
}
@@ -722,6 +720,7 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper,
public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) {
GalleryInfo gi = mGalleryListHelper.getDataAt(position);
Announcer announcer = new Announcer();
announcer.setAction(GalleryDetailScene.ACTION_GALLERY_INFO);
announcer.putExtra(GalleryDetailScene.KEY_GALLERY_INFO, gi);
Curtain curtain = new TransitionCurtain(new TransitonHelper(position));
@@ -910,7 +909,7 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper,
GalleryInfo gi = getDataAt(position);
Conaco conaco = EhApplication.getConaco(getStageActivity());
conaco.load(holder.thumb, EhImageKeyFactory.getThumbKey(gi.gid), gi.thumb);
holder.thumb.load(conaco, EhImageKeyFactory.getThumbKey(gi.gid), gi.thumb);
holder.title.setText(gi.title);
holder.uploader.setText(gi.uploader);
@@ -43,6 +43,8 @@ import java.util.List;
public class InfoScene extends AppbarScene implements EasyRecyclerView.OnItemLongClickListener {
public static final String KEY_INFO = "key_info";
private Resources mResources;
private EasyRecyclerView mRecyclerView;
@@ -103,10 +105,17 @@ public class InfoScene extends AppbarScene implements EasyRecyclerView.OnItemLon
}
private void handleAnnouncer(Announcer announcer) {
if (announcer != null) {
GalleryDetail gd = (GalleryDetail) announcer.getObject();
if (announcer == null) {
finish();
return;
}
Object obj = announcer.getExtra(KEY_INFO);
if (obj instanceof GalleryDetail) {
GalleryDetail gd = (GalleryDetail) obj;
addData(R.string.header_key, mResources.getString(R.string.header_value));
addData(R.string.key_gid, Integer.toString(gd.gid));
addData(R.string.key_token, gd.token);
addData(R.string.key_title, gd.title);
addData(R.string.key_title_jpn, gd.titleJpn);
addData(R.string.key_thumb, gd.thumb);
@@ -1,38 +1,143 @@
package com.hippo.ehviewer.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.util.AttributeSet;
import android.view.View;
import com.hippo.conaco.BitmapHolder;
import com.hippo.conaco.Conaco;
import com.hippo.conaco.Unikery;
import com.hippo.ehviewer.R;
import com.hippo.widget.FixedAspectImageView;
public class LoadImageView extends FixedAspectImageView implements Unikery {
public class LoadImageView extends FixedAspectImageView implements Unikery,
View.OnClickListener, View.OnLongClickListener {
private static final int STATE_NONE = 0;
private static final int STATE_LOADING = 1;
private static final int STATE_LOADED = 2;
private static final int STATE_FAILURE = 3;
private static final int RETRY_DRAWABLE = R.drawable.retry_load_image;
private int mTaskId = Unikery.INVAILD_ID;
private int mState = STATE_NONE;
private BitmapHolder mBitmapHolder;
private Conaco mConaco;
private String mKey;
private String mUrl;
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);
}
public LoadImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public LoadImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
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]);
}
a.recycle();
}
public void setRetryType(RetryType retryType) {
if (mRetryType != retryType) {
RetryType oldRetryType = mRetryType;
mRetryType = retryType;
if (mState == STATE_FAILURE) {
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);
}
if (oldRetryType != RetryType.NONE && retryType == RetryType.NONE) {
setImageDrawable(null);
} else if (oldRetryType == RetryType.NONE && retryType != RetryType.NONE) {
setImageResource(RETRY_DRAWABLE);
}
}
}
}
public void load(Conaco conaco, String key, String url) {
mState = STATE_LOADING;
mConaco = conaco;
mKey = key;
mUrl = url;
conaco.load(this, key, url);
}
public void cancel() {
mState = STATE_NONE;
if (mConaco != null) {
mConaco.cancel(this);
// release
mConaco = null;
mKey = null;
mUrl = null;
}
}
@Override
public void setBitmap(BitmapHolder bitmapHolder, Conaco.Source source) {
mState = STATE_LOADED;
// release
mConaco = null;
mKey = null;
mUrl = null;
BitmapHolder oldBitmapHolder = mBitmapHolder;
mBitmapHolder = bitmapHolder;
@@ -55,6 +160,8 @@ public class LoadImageView extends FixedAspectImageView implements Unikery {
@Override
public void setDrawable(Drawable drawable) {
mState = STATE_NONE;
setImageDrawable(drawable);
}
@@ -70,11 +177,37 @@ public class LoadImageView extends FixedAspectImageView implements Unikery {
@Override
public void onFailure() {
mState = STATE_FAILURE;
if (mRetryType == RetryType.CLICK) {
setImageResource(RETRY_DRAWABLE);
setOnClickListener(this);
} else if (mRetryType == RetryType.LONG_CLICK) {
setImageResource(RETRY_DRAWABLE);
setOnLongClickListener(this);
}
}
@Override
public void onCancel() {
// Empty, everything is done in cancel
}
@Override
public void onClick(View v) {
setOnClickListener(null);
setClickable(false);
load(mConaco, mKey, mUrl);
}
@Override
public boolean onLongClick(View v) {
setOnLongClickListener(null);
setLongClickable(false);
load(mConaco, mKey, mUrl);
return true;
}
}
@@ -110,9 +110,11 @@ public final class PreviewLayout extends LinearLayout implements View.OnClickLis
}
private boolean isLargePreview() {
for (PreviewSet previewSet : mPreviewSets) {
if (previewSet != null) {
return previewSet instanceof LargePreviewSet;
if (mPreviewSets != null) {
for (PreviewSet previewSet : mPreviewSets) {
if (previewSet != null) {
return previewSet instanceof LargePreviewSet;
}
}
}
return false;
+68 -309
View File
@@ -16,354 +16,113 @@
package com.hippo.scene;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.io.Serializable;
// TODO Do not copy Intent, set clone stuff and non-clone stuff
public class Announcer {
private @Nullable Bundle mExtras;
private String mAction;
private Object mObject;
private Map<String, Object> mMap = new HashMap<>();
public void setObject(Object object) {
mObject = object;
public void setAction(String action) {
mAction = action;
}
public Object getObject() {
return mObject;
public String getAction() {
return mAction;
}
public boolean getBooleanExtra(String name, boolean defaultValue) {
return mExtras == null ? defaultValue :
mExtras.getBoolean(name, defaultValue);
public void putExtra(String key, Object value) {
mMap.put(key, value);
}
public byte getByteExtra(String name, byte defaultValue) {
return mExtras == null ? defaultValue :
mExtras.getByte(name, defaultValue);
}
public short getShortExtra(String name, short defaultValue) {
return mExtras == null ? defaultValue :
mExtras.getShort(name, defaultValue);
}
public char getCharExtra(String name, char defaultValue) {
return mExtras == null ? defaultValue :
mExtras.getChar(name, defaultValue);
}
public int getIntExtra(String name, int defaultValue) {
return mExtras == null ? defaultValue :
mExtras.getInt(name, defaultValue);
}
public long getLongExtra(String name, long defaultValue) {
return mExtras == null ? defaultValue :
mExtras.getLong(name, defaultValue);
}
public float getFloatExtra(String name, float defaultValue) {
return mExtras == null ? defaultValue :
mExtras.getFloat(name, defaultValue);
}
public double getDoubleExtra(String name, double defaultValue) {
return mExtras == null ? defaultValue :
mExtras.getDouble(name, defaultValue);
}
public String getStringExtra(String name) {
return mExtras == null ? null : mExtras.getString(name);
}
public CharSequence getCharSequenceExtra(String name) {
return mExtras == null ? null : mExtras.getCharSequence(name);
}
public <T extends Parcelable> T getParcelableExtra(String name) {
return mExtras == null ? null : mExtras.<T>getParcelable(name);
}
public Parcelable[] getParcelableArrayExtra(String name) {
return mExtras == null ? null : mExtras.getParcelableArray(name);
}
public Serializable getSerializableExtra(String name) {
return mExtras == null ? null : mExtras.getSerializable(name);
}
public boolean[] getBooleanArrayExtra(String name) {
return mExtras == null ? null : mExtras.getBooleanArray(name);
}
public byte[] getByteArrayExtra(String name) {
return mExtras == null ? null : mExtras.getByteArray(name);
}
public short[] getShortArrayExtra(String name) {
return mExtras == null ? null : mExtras.getShortArray(name);
}
public char[] getCharArrayExtra(String name) {
return mExtras == null ? null : mExtras.getCharArray(name);
}
public int[] getIntArrayExtra(String name) {
return mExtras == null ? null : mExtras.getIntArray(name);
}
public long[] getLongArrayExtra(String name) {
return mExtras == null ? null : mExtras.getLongArray(name);
}
public float[] getFloatArrayExtra(String name) {
return mExtras == null ? null : mExtras.getFloatArray(name);
}
public double[] getDoubleArrayExtra(String name) {
return mExtras == null ? null : mExtras.getDoubleArray(name);
}
public String[] getStringArrayExtra(String name) {
return mExtras == null ? null : mExtras.getStringArray(name);
}
public CharSequence[] getCharSequenceArrayExtra(String name) {
return mExtras == null ? null : mExtras.getCharSequenceArray(name);
}
public Bundle getBundleExtra(String name) {
return mExtras == null ? null : mExtras.getBundle(name);
}
public Bundle getExtras() {
return (mExtras != null)
? new Bundle(mExtras)
: null;
}
public Announcer putExtra(String name, boolean value) {
if (mExtras == null) {
mExtras = new Bundle();
public boolean getBooleanExtra(String key, boolean defaultValue) {
Object obj = mMap.get(key);
if (obj instanceof Boolean) {
return (Boolean) obj;
} else {
return defaultValue;
}
mExtras.putBoolean(name, value);
return this;
}
public Announcer putExtra(String name, byte value) {
if (mExtras == null) {
mExtras = new Bundle();
public byte getByteExtra(String key, byte defaultValue) {
Object obj = mMap.get(key);
if (obj instanceof Byte) {
return (Byte) obj;
} else {
return defaultValue;
}
mExtras.putByte(name, value);
return this;
}
public Announcer putExtra(String name, char value) {
if (mExtras == null) {
mExtras = new Bundle();
public char getCharExtra(String key, char defaultValue) {
Object obj = mMap.get(key);
if (obj instanceof Character) {
return (Character) obj;
} else {
return defaultValue;
}
mExtras.putChar(name, value);
return this;
}
public Announcer putExtra(String name, short value) {
if (mExtras == null) {
mExtras = new Bundle();
public short getShortExtra(String key, short defaultValue) {
Object obj = mMap.get(key);
if (obj instanceof Short) {
return (Short) obj;
} else {
return defaultValue;
}
mExtras.putShort(name, value);
return this;
}
public Announcer putExtra(String name, int value) {
if (mExtras == null) {
mExtras = new Bundle();
public int getIntExtra(String key, int defaultValue) {
Object obj = mMap.get(key);
if (obj instanceof Integer) {
return (Integer) obj;
} else {
return defaultValue;
}
mExtras.putInt(name, value);
return this;
}
public Announcer putExtra(String name, long value) {
if (mExtras == null) {
mExtras = new Bundle();
public long getLongExtra(String key, long defaultValue) {
Object obj = mMap.get(key);
if (obj instanceof Long) {
return (Long) obj;
} else {
return defaultValue;
}
mExtras.putLong(name, value);
return this;
}
public Announcer putExtra(String name, float value) {
if (mExtras == null) {
mExtras = new Bundle();
public float getFloatExtra(String key, float defaultValue) {
Object obj = mMap.get(key);
if (obj instanceof Float) {
return (Float) obj;
} else {
return defaultValue;
}
mExtras.putFloat(name, value);
return this;
}
public Announcer putExtra(String name, double value) {
if (mExtras == null) {
mExtras = new Bundle();
public double getDoubleExtra(String key, double defaultValue) {
Object obj = mMap.get(key);
if (obj instanceof Double) {
return (Double) obj;
} else {
return defaultValue;
}
mExtras.putDouble(name, value);
return this;
}
public Announcer putExtra(String name, String value) {
if (mExtras == null) {
mExtras = new Bundle();
public String getStringExtra(String key, String defaultValue) {
Object obj = mMap.get(key);
if (obj instanceof String) {
return (String) obj;
} else {
return defaultValue;
}
mExtras.putString(name, value);
return this;
}
public Announcer putExtra(String name, CharSequence value) {
if (mExtras == null) {
mExtras = new Bundle();
}
mExtras.putCharSequence(name, value);
return this;
public Object getExtra(String key) {
return mMap.get(key);
}
public Announcer putExtra(String name, Parcelable value) {
if (mExtras == null) {
mExtras = new Bundle();
}
mExtras.putParcelable(name, value);
return this;
}
public Announcer putExtra(String name, Parcelable[] value) {
if (mExtras == null) {
mExtras = new Bundle();
}
mExtras.putParcelableArray(name, value);
return this;
}
public Announcer putExtra(String name, Serializable value) {
if (mExtras == null) {
mExtras = new Bundle();
}
mExtras.putSerializable(name, value);
return this;
}
public Announcer putExtra(String name, boolean[] value) {
if (mExtras == null) {
mExtras = new Bundle();
}
mExtras.putBooleanArray(name, value);
return this;
}
public Announcer putExtra(String name, byte[] value) {
if (mExtras == null) {
mExtras = new Bundle();
}
mExtras.putByteArray(name, value);
return this;
}
public Announcer putExtra(String name, short[] value) {
if (mExtras == null) {
mExtras = new Bundle();
}
mExtras.putShortArray(name, value);
return this;
}
public Announcer putExtra(String name, char[] value) {
if (mExtras == null) {
mExtras = new Bundle();
}
mExtras.putCharArray(name, value);
return this;
}
public Announcer putExtra(String name, int[] value) {
if (mExtras == null) {
mExtras = new Bundle();
}
mExtras.putIntArray(name, value);
return this;
}
public Announcer putExtra(String name, long[] value) {
if (mExtras == null) {
mExtras = new Bundle();
}
mExtras.putLongArray(name, value);
return this;
}
public Announcer putExtra(String name, float[] value) {
if (mExtras == null) {
mExtras = new Bundle();
}
mExtras.putFloatArray(name, value);
return this;
}
public Announcer putExtra(String name, double[] value) {
if (mExtras == null) {
mExtras = new Bundle();
}
mExtras.putDoubleArray(name, value);
return this;
}
public Announcer putExtra(String name, String[] value) {
if (mExtras == null) {
mExtras = new Bundle();
}
mExtras.putStringArray(name, value);
return this;
}
public Announcer putExtra(String name, CharSequence[] value) {
if (mExtras == null) {
mExtras = new Bundle();
}
mExtras.putCharSequenceArray(name, value);
return this;
}
public Announcer putExtra(String name, Bundle value) {
if (mExtras == null) {
mExtras = new Bundle();
}
mExtras.putBundle(name, value);
return this;
}
public Announcer putExtras(Announcer src) {
if (src.mExtras != null) {
if (mExtras == null) {
mExtras = new Bundle(src.mExtras);
} else {
mExtras.putAll(src.mExtras);
}
}
return this;
}
public Announcer putExtras(Bundle extras) {
if (mExtras == null) {
mExtras = new Bundle();
}
mExtras.putAll(extras);
return this;
}
public void removeExtra(String name) {
if (mExtras != null) {
mExtras.remove(name);
if (mExtras.size() == 0) {
mExtras = null;
}
}
public void removeExtra(String key) {
mMap.remove(key);
}
}
@@ -87,6 +87,9 @@ public class SimpleDialogCurtain extends Curtain {
ViewUtils.setVisibility(cushion, View.INVISIBLE);
ViewUtils.setVisibility(frame, View.INVISIBLE);
// TODO addOnGlobalLayoutListener is not reliable
// TODO use isLayoutRequested
// TODO if isLayoutRequested return false, try to use StageView Size
frame.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
+5 -8
View File
@@ -153,8 +153,8 @@ public final class Utils {
* If you want to copy on new thread, use it to know
* success or not.
*/
public static interface OnCopyFileOverListener {
public void onCopyFileOver(boolean success, File src, File dst);
public interface OnCopyFileOverListener {
void onCopyFileOver(boolean success, File src, File dst);
}
/**
@@ -214,8 +214,8 @@ public final class Utils {
* If you want to copy on new thread, use it to know
* success or not.
*/
public static interface OnDeleteFileOverListener {
public void onDeleteFileOver(boolean success, File file);
public interface OnDeleteFileOverListener {
void onDeleteFileOver(boolean success, File file);
}
/**
@@ -632,10 +632,7 @@ public final class Utils {
if (area.length != 4)
throw new IllegalArgumentException(
"area's length should be 4, but it's length is " + area.length);
if (x >= area[0] && x < area[2] && y >= area[1] && y < area[3])
return true;
else
return false;
return x >= area[0] && x < area[2] && y >= area[1] && y < area[3];
}
/**