优化列表

This commit is contained in:
seven332 committed 2014-05-06 16:45:09 +08:00
1 parent 9615aa0b7c
commit 8158bae9d5
18 files changed
+153 -1806

No files matched your search

+20 -20
View File
@@ -1,20 +1,20 @@
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
+1 -1
View File
@@ -22,7 +22,7 @@
android:layout_width="fill_parent"
android:layout_height="@dimen/detail_thumb_height" >
<com.hippo.ehviewer.view.OlImageView
<com.hippo.ehviewer.widget.LoadImageView
android:id="@+id/detail_cover"
android:layout_width="@dimen/detail_thumb_width"
android:layout_height="@dimen/detail_thumb_height"
+27
View File
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:fitsSystemWindows="true">
<TextView android:id="@android:id/title" style="?android:attr/windowTitleStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/dialog_title_height"
android:paddingStart="16dip"
android:paddingEnd="16dip"
android:gravity="center_vertical|start"
android:textColor="@android:color/white" />
<View android:id="@+id/titleDivider"
android:layout_width="match_parent"
android:layout_height="2dip"
android:background="@android:color/holo_blue_light" />
<FrameLayout
android:layout_width="match_parent" android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:foreground="?android:attr/windowContentOverlay">
<FrameLayout android:id="@android:id/content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</LinearLayout>
+1 -1
View File
@@ -5,7 +5,7 @@
android:layout_height="wrap_content"
android:orientation="horizontal" >
<com.hippo.ehviewer.view.OlImageView
<com.hippo.ehviewer.widget.LoadImageView
android:id="@+id/thumb"
android:layout_width="67dp"
android:layout_height="wrap_content"
+2
View File
@@ -3,6 +3,8 @@
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="dialog_title_height">64dip</dimen>
<dimen name="shadow_width">12dp</dimen>
<dimen name="menu_offset">240dp</dimen>
+5
View File
@@ -18,6 +18,11 @@
<!-- No action bar shadow -->
<!-- item name="android:windowContentOverlay">@drawable/shadow</item -->
<!-- Dialog -->
<!-- item name="@android:dialogTitleDecorLayout">@layout/dialog_title</item -->
<!-- item name="@android:searchViewVoiceIcon">@android:drawable/ic_voice_search_api_holo_light</item -->
</style>
<style name="AppTheme.NoActionBar">
+2 -1
View File
@@ -2,4 +2,5 @@
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_name"
android:hint="@string/advance_search_left" />
android:hint="@string/advance_search_left"
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" />
+10 -5
View File
@@ -19,9 +19,8 @@ import com.hippo.ehviewer.util.Log;
public class ImageGeterManager {
private static final String TAG = "ImageGeterManager";
private static final int WAIT = 0x0;
private static final int TOUCH = 0x1;
private static final int CONTEXT = 0x2;
private static final int CACHE = 0x0;
private static final int DOWNLOAD = 0x1;
private class LoadTask {
public String url;
@@ -55,7 +54,10 @@ public class ImageGeterManager {
LoadTask task = (LoadTask)msg.obj;
switch (msg.what) {
case Constants.TRUE:
task.listener.onGetImageSuccess(task.key, task.bitmap);
if (msg.arg1 == CACHE)
task.listener.onGetImageFromCacheSuccess(task.key, task.bitmap);
else if (msg.arg1 == DOWNLOAD)
task.listener.onGetImageFromDownloadSuccess(task.key, task.bitmap);
break;
case Constants.FALSE:
task.listener.onGetImageFail(task.key);
@@ -118,6 +120,7 @@ public class ImageGeterManager {
} else {
Message msg = new Message();
msg.what = Constants.TRUE;
msg.arg1 = CACHE;
msg.obj = curLoadTask;
mHandler.sendMessage(msg);
}
@@ -177,6 +180,7 @@ public class ImageGeterManager {
msg.what = Constants.FALSE;
} else {
msg.what = Constants.TRUE;
msg.arg1 = DOWNLOAD;
}
mHandler.sendMessage(msg);
}
@@ -189,7 +193,8 @@ public class ImageGeterManager {
* @return False if you wanna stop get
*/
boolean onGetImage(String key);
void onGetImageSuccess(String key, Bitmap bmp);
void onGetImageFromCacheSuccess(String key, Bitmap bmp);
void onGetImageFromDownloadSuccess(String key, Bitmap bmp);
void onGetImageFail(String key);
}
}
@@ -6,7 +6,9 @@ import java.util.List;
import org.apache.commons.lang3.StringEscapeUtils;
import com.hippo.ehviewer.AppContext;
import com.hippo.ehviewer.BeautifyScreen;
import com.hippo.ehviewer.ImageGeterManager;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.ehclient.EhClient;
import com.hippo.ehviewer.service.DownloadService;
@@ -17,8 +19,8 @@ import com.hippo.ehviewer.util.Download;
import com.hippo.ehviewer.util.Util;
import com.hippo.ehviewer.view.AlertButton;
import com.hippo.ehviewer.view.DownloadItemLayout;
import com.hippo.ehviewer.view.OlImageView;
import com.hippo.ehviewer.widget.DialogBuilder;
import com.hippo.ehviewer.widget.LoadImageView;
import android.app.Activity;
import android.app.AlertDialog;
@@ -55,6 +57,9 @@ public class DownloadActivity extends Activity {
private DownloadServiceConnection mServiceConn = new DownloadServiceConnection();
private AppContext mAppContext;
private ImageGeterManager mImageGeterManager;
private List<DownloadInfo> mDownloadInfos;
private DlAdapter mDlAdapter;
private int longClickItemIndex;
@@ -143,12 +148,13 @@ public class DownloadActivity extends Activity {
view.downloadSize = di.downloadSize;
view.isWait = false;
OlImageView thumb = (OlImageView)view
LoadImageView thumb = (LoadImageView)view
.findViewById(R.id.thumb);
thumb.setUrl(di.thumb);
thumb.setKey(String.valueOf(di.gid));
thumb.setCache(Cache.memoryCache, Cache.cpCache);
thumb.loadImage(true);
if (thumb.getDrawable() != null)
thumb.setImageDrawable(null);
thumb.setLoadInfo(di.thumb, di.gid);
mImageGeterManager.add(di.thumb, di.gid,
new LoadImageView.SimpleImageGetListener(thumb), true);
TextView title = (TextView)view.findViewById(R.id.title);
title.setText(di.title);
@@ -199,12 +205,13 @@ public class DownloadActivity extends Activity {
view.downloadSize = di.downloadSize;
view.isWait = false;
OlImageView thumb = (OlImageView)view
LoadImageView thumb = (LoadImageView)view
.findViewById(R.id.thumb);
thumb.setUrl(di.thumb);
thumb.setKey(String.valueOf(di.gid));
thumb.setCache(Cache.memoryCache, Cache.cpCache);
thumb.loadImage(true);
if (thumb.getDrawable() != null)
thumb.setImageDrawable(null);
thumb.setLoadInfo(di.thumb, di.gid);
mImageGeterManager.add(di.thumb, di.gid,
new LoadImageView.SimpleImageGetListener(thumb), true);
TextView title = (TextView)view.findViewById(R.id.title);
title.setText(di.title);
@@ -355,6 +362,9 @@ public class DownloadActivity extends Activity {
super.onCreate(savedInstanceState);
setContentView(R.layout.download);
mAppContext = (AppContext)getApplication();
mImageGeterManager = mAppContext.getImageGeterManager();
int screenOri = Config.getScreenOriMode();
if (screenOri != getRequestedOrientation())
setRequestedOrientation(screenOri);
@@ -120,6 +120,9 @@ public class FavouriteActivity extends Activity{
LoadImageView thumb = (LoadImageView)convertView.findViewById(R.id.cover);
if (!String.valueOf(lmd.gid).equals(thumb.getKey())) {
if (thumb.getDrawable() != null)
thumb.setImageDrawable(null);
thumb.setLoadInfo(lmd.thumb, String.valueOf(lmd.gid));
mImageGeterManager.add(lmd.thumb, String.valueOf(lmd.gid),
new LoadImageView.SimpleImageGetListener(thumb), true);
@@ -17,10 +17,10 @@ import com.hippo.ehviewer.util.Config;
import com.hippo.ehviewer.util.Ui;
import com.hippo.ehviewer.util.Util;
import com.hippo.ehviewer.view.AlertButton;
import com.hippo.ehviewer.view.OlImageView;
import com.hippo.ehviewer.widget.AutoWrapLayout;
import com.hippo.ehviewer.widget.ButtonsDialogBuilder;
import com.hippo.ehviewer.widget.DialogBuilder;
import com.hippo.ehviewer.widget.LoadImageView;
import android.app.Activity;
import android.app.AlertDialog;
@@ -608,11 +608,11 @@ public class MangaDetailActivity extends Activity {
setTitle(String.valueOf(mangaDetail.gid));
OlImageView coverImage = (OlImageView) findViewById(R.id.detail_cover);
coverImage.setUrl(mangaDetail.thumb);
coverImage.setKey(String.valueOf(mangaDetail.gid));
coverImage.setCache(Cache.memoryCache, Cache.cpCache);
coverImage.loadImage(false);
LoadImageView coverImage = (LoadImageView) findViewById(R.id.detail_cover);
coverImage.setLoadInfo(mangaDetail.thumb, String.valueOf(mangaDetail.gid));
mAppContext.getImageGeterManager().add(mangaDetail.thumb,
String.valueOf(mangaDetail.gid),
new LoadImageView.SimpleImageGetListener(coverImage), true);
TextView title = (TextView) findViewById(R.id.detail_title);
title.setText(mangaDetail.title);
@@ -985,6 +985,8 @@ public class MangaListActivity extends SlidingActivity {
final LoadImageView thumb = (LoadImageView)convertView.findViewById(R.id.cover);
if (!String.valueOf(lmd.gid).equals(thumb.getKey())) {
if (thumb.getDrawable() != null)
thumb.setImageDrawable(null);
thumb.setLoadInfo(lmd.thumb, String.valueOf(lmd.gid));
mImageGeterManager.add(lmd.thumb, String.valueOf(lmd.gid),
new LoadImageView.SimpleImageGetListener(thumb), true);
@@ -1357,8 +1359,10 @@ public class MangaListActivity extends SlidingActivity {
mFswPaddingRight = paddingRight;
mFswPaddingBottom = paddingBottom;
itemListMenu.setPadding(itemListMenu.getPaddingLeft(), paddingTop,
itemListMenu.setPadding(itemListMenu.getPaddingLeft(), mFswPaddingTop,
itemListMenu.getPaddingRight(), itemListMenu.getPaddingBottom());
tagListMenu.setPadding(tagListMenu.getPaddingLeft(), tagListMenu.getPaddingTop(),
tagListMenu.getPaddingRight(), mFswPaddingBottom);
}
});
mHlv.setFooterString(getString(R.string.footer_loading),
@@ -1453,8 +1457,7 @@ public class MangaListActivity extends SlidingActivity {
});
// Make search view custom look
int searchTextID = searchView.getContext().
getResources().getIdentifier("android:id/search_src_text", null, null);
int searchTextID = mResources.getIdentifier("android:id/search_src_text", null, null);
if (searchTextID > 0) {
AutoCompleteTextView searchText =
(AutoCompleteTextView)searchView.findViewById(searchTextID);
@@ -1464,8 +1467,7 @@ public class MangaListActivity extends SlidingActivity {
}
}
int removeImageID = searchView.getContext().
getResources().getIdentifier("android:id/search_close_btn", null, null);
int removeImageID = mResources.getIdentifier("android:id/search_close_btn", null, null);
if (removeImageID > 0) {
ImageView removeImage =
(ImageView)searchView.findViewById(removeImageID);
@@ -1473,6 +1475,13 @@ public class MangaListActivity extends SlidingActivity {
removeImage.setImageResource(R.drawable.ic_action_remove);
}
int voiceImageID = mResources.getIdentifier("android:id/search_voice_btn", null, null);
if (voiceImageID > 0) {
ImageView removeImage =
(ImageView)searchView.findViewById(removeImageID);
}
return true;
}
+9
View File
@@ -3,6 +3,7 @@ package com.hippo.ehviewer.util;
import com.hippo.ehviewer.ListUrls;
import com.hippo.ehviewer.R;
import com.readystatesoftware.systembartint.SystemBarTintManager;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
@@ -10,7 +11,10 @@ import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Movie;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
@@ -44,6 +48,8 @@ public class Ui {
public static int MISC_BG_COLOR;
public static int UNKNOWN_BG_COLOR;
public static Drawable transparentDrawable;
private static boolean mInit = false;
/**
@@ -78,6 +84,9 @@ public class Ui {
ASIAN_PORN_BG_COLOR = mResources.getColor(R.color.asian_porn_bg);
MISC_BG_COLOR = mResources.getColor(R.color.misc_bg);
UNKNOWN_BG_COLOR = mResources.getColor(R.color.unknown_bg);
// init drawable
transparentDrawable = new ColorDrawable(Color.TRANSPARENT);
}
/**
@@ -1,19 +0,0 @@
package com.hippo.ehviewer.view;
import android.content.Context;
import android.util.AttributeSet;
public class CoverImageView extends OlImageView{
public CoverImageView(Context context) {
super(context);
}
public CoverImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CoverImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
}
@@ -1,203 +0,0 @@
package com.hippo.ehviewer.view;
import com.hippo.ehviewer.DiskCache;
import com.hippo.ehviewer.ehclient.EhClient;
import com.hippo.ehviewer.util.Util;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Movie;
import android.support.v4.util.LruCache;
import android.util.AttributeSet;
import com.hippo.ehviewer.util.Log;
import android.view.View;
public class OlImageView extends SuperImageView {
private static String TAG = "OlImageView";
private String url = null;
private String key = null;
public static final int STATUS_NON_LOADED = 0x0;
public static final int STATUS_LOADING = 0x1;
public static final int STATUS_LOADED = 0x2;
public static final int STATUS_LOAD_FAIL = 0x3;
private int status = STATUS_NON_LOADED;
public static final int LOAD_FAILED = 0x0;
public static final int LOAD_SUCCESSDE = 0x1;
private LruCache<String, Bitmap> memoryCache = null;
private DiskCache diskCache = null;
private static Bitmap waitBitmap;
private static Bitmap refreshBitmap;
private OnLoadListener onLoadListener = null;
public interface OnLoadListener {
void onLoadCompleted(boolean ok);
}
public void setOnLoadListener(OnLoadListener listener) {
onLoadListener = listener;
}
public OlImageView(Context context) {
super(context);
}
public OlImageView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public OlImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public void setWaitMovie() {
setImageBitmap(waitBitmap);
}
public void setUrl(String s) {
url = s;
key = url;
status = STATUS_NON_LOADED;
}
public String getUrl() {
return url;
}
public void setKey(String s) {
key = s;
}
public String getKey() {
return key;
}
public void setCache(LruCache<String, Bitmap> memoryCache,
DiskCache diskCache) {
this.memoryCache = memoryCache;
this.diskCache = diskCache;
}
/**
* If load from cache fail, will not set status flag as STATUS_LOAD_FAIL
* @return
*/
public boolean loadFromCache() {
synchronized (this) {
if (status == STATUS_LOADED)
return true;
if (status == STATUS_LOADING || url == null || key == null)
return false;
int type = Util.getResourcesType(url);
Object res = null;
// Check in memory
if (type == Util.BITMAP && memoryCache != null
&& (res = memoryCache.get(key)) != null) {
status = STATUS_LOADED;
setImageBitmap((Bitmap) res);
return true;
}
// If not find in memory cache or do not have memory cache
// Check disk cache
if (diskCache != null && (res = diskCache.get(key, type)) != null) {
status = STATUS_LOADED;
if (res instanceof Bitmap) {
setImageBitmap((Bitmap) res);
if (memoryCache != null)
memoryCache.put(key, (Bitmap) res);
} else
OlImageView.this.setImageMovie((Movie) res);
return true;
}
setImageBitmap(waitBitmap);
return false;
}
}
/**
* Load image for url
* @param froce If True, will get image even status is fail
* @return
*/
public boolean loadImage(boolean froce) {
if (status == STATUS_LOADED)
return true;
if (status == STATUS_LOADING || url == null || key == null)
return false;
if (!froce && status == STATUS_LOAD_FAIL)
return false;
load();
return true;
}
public boolean reloadImage() {
if ((status == STATUS_LOADED
|| status == STATUS_LOAD_FAIL
|| status == STATUS_NON_LOADED)
&& url != null && key != null) {
load();
return true;
}
else
return false;
}
private void load() {
status = STATUS_LOADING;
setImageBitmap(waitBitmap);
int type = Util.getResourcesType(url);
synchronized (this) {
// If can't find download
EhClient.getImage(url, key, type, memoryCache, diskCache, null,
new EhClient.OnGetImageListener() {
@Override
public void onSuccess(Object checkFlag, Object res) {
if (res instanceof Bitmap) {
OlImageView.this.setImageBitmap((Bitmap) res);
} else
OlImageView.this.setImageMovie((Movie) res);
OlImageView.this.status = STATUS_LOADED;
if (onLoadListener != null)
onLoadListener.onLoadCompleted(true);
}
@Override
public void onFailure(int errorMessageId) {
OlImageView.this.setImageBitmap(refreshBitmap);
OlImageView.this.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
setImageBitmap(waitBitmap);
loadImage(true);
setClickable(false);
}
});
OlImageView.this.status = STATUS_LOAD_FAIL;
if (onLoadListener != null)
onLoadListener.onLoadCompleted(false);
}
});
}
}
public static void setDefaultImage(Bitmap waitBitmap, Bitmap refreshBitmap) {
OlImageView.waitBitmap = waitBitmap;
OlImageView.refreshBitmap = refreshBitmap;
}
public int getStatus() {
return status;
}
}
File diff suppressed because it is too large. Load diff
@@ -189,7 +189,8 @@ public class HfListView extends PullToRefreshLayout
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if (firstVisibleItem + visibleItemCount == totalItemCount
&& !isAnyRefreshing() && totalItemCount > 1)
&& !isAnyRefreshing() && totalItemCount > 1
&& footerState != FOOTER_FAIL)
footerRefresh();
}
@@ -95,24 +95,21 @@ public class LoadImageView extends ImageView {
* @param bmp
*/
public void setContextImage(Bitmap bmp) {
Drawable oldDrawable = getDrawable();
if (oldDrawable == null) { // Just set alpha animation
Drawable drawable = new BitmapDrawable(getContext().getResources(), bmp);
setImageDrawable(drawable);
AlphaAnimation aa = new AlphaAnimation(0.0f,1.0f);
aa.setDuration(DURATION);
startAnimation(aa);
} else { // If exists previous drawable, use TransitionDrawable
if (oldDrawable instanceof TransitionDrawable)
oldDrawable = ((TransitionDrawable)oldDrawable).getDrawable(1);
Drawable[] layers = new Drawable[2];
layers[0] = oldDrawable;
layers[1] = new BitmapDrawable(getContext().getResources(), bmp);
TransitionDrawable transitionDrawable = new TransitionDrawable(layers);
setImageDrawable(transitionDrawable);
transitionDrawable.startTransition(DURATION);
}
Drawable[] layers = new Drawable[2];
layers[0] = Ui.transparentDrawable;
layers[1] = new BitmapDrawable(getContext().getResources(), bmp);
TransitionDrawable transitionDrawable = new TransitionDrawable(layers);
setImageDrawable(transitionDrawable);
transitionDrawable.startTransition(DURATION);
// I get no idea which is better
/*
setImageBitmap(bmp);
AlphaAnimation aa = new AlphaAnimation(0.0f,1.0f);
aa.setDuration(DURATION);
startAnimation(aa);
*/
}
public static void setImageGeterManager(ImageGeterManager i) {
@@ -128,23 +125,32 @@ public class LoadImageView extends ImageView {
mLiv = liv;
}
public boolean isVaild(String key) {
return key.equals(mLiv.getKey())
&& mLiv.getParent() != null;
}
@Override
public boolean onGetImage(String key) {
return key.equals(mLiv.getKey());
return isVaild(key);
}
@Override
public void onGetImageFail(String key) {
if (key.equals(mLiv.getKey())) {
if (isVaild(key)) {
mLiv.setTouchImage();
mLiv.setOnClick();
}
}
@Override
public void onGetImageSuccess(String key, Bitmap bmp) {
if (key.equals(mLiv.getKey())) {
mLiv.setImageDrawable(null);
public void onGetImageFromCacheSuccess(String key, Bitmap bmp) {
if (isVaild(key))
mLiv.setImageBitmap(bmp);
}
@Override
public void onGetImageFromDownloadSuccess(String key, Bitmap bmp) {
if (isVaild(key))
mLiv.setContextImage(bmp);
}
}
}
}