检测已存在磁盘中的图片,删除页面缓存

This commit is contained in:
seven332 committed 2014-04-01 00:43:42 +08:00
1 parent 83395619e7
commit 644d3d6402
12 files changed
+62 -160

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hippo.ehviewer"
android:versionCode="10"
android:versionName="0.3.0" >
android:versionName="0.3.5" >
<uses-sdk
android:minSdkVersion="14"
+1 -1
View File
@@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hippo.ehviewer"
android:versionCode="10"
android:versionName="0.3.0" >
android:versionName="0.3.5" >
<uses-sdk
android:minSdkVersion="14"
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
-17
View File
@@ -38,23 +38,6 @@
android:key="preference_clear_cp_cache"
android:title="@string/preference_clear_cp_cache" />
<EditTextPreference
android:defaultValue="256"
android:inputType="number"
android:key="preference_page_cache"
android:title="@string/preference_page_cache" />
<Preference
android:key="preference_clear_page_cache"
android:title="@string/preference_clear_page_cache" />
<CheckBoxPreference
android:defaultValue="false"
android:key="preference_auto_page_cache"
android:summaryOff="@string/preference_auto_page_cache_summary_off"
android:summaryOn="@string/preference_auto_page_cache_summary_on"
android:title="@string/preference_auto_page_cache" />
</PreferenceCategory>
<!--
@@ -1,6 +1,8 @@
package com.hippo.ehviewer.activity;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.regex.Matcher;
@@ -27,6 +29,7 @@ import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
@@ -84,27 +87,24 @@ public class MangaActivity extends Activity {
}
retryTimes = 0;
final int targetPage = (Integer)checkFlag;
//
final int index = (Integer)checkFlag;
final String prePageUrl = arg[0];
final String nextPageUrl = arg[1];
final String imageUrl = arg[2];
Log.d(TAG, "targetPage = " + targetPage);
Log.d(TAG, "firstPage = " + firstPage);
Log.d(TAG, "lastPage = " + lastPage);
if (targetPage == firstPage - 1 || (targetPage == firstPage && allPrePageUrl == null))
if (index == firstPage - 1 || (index == firstPage && allPrePageUrl == null))
allPrePageUrl = prePageUrl;
if (targetPage == lastPage)
if (index == lastPage)
allNextPageUrl = nextPageUrl;
if (targetPage != firstPage - 1 && (targetPage == firstPage && allPrePageUrl == null) && targetPage != lastPage) {
if (index != firstPage - 1 && (index == firstPage && allPrePageUrl == null) && index != lastPage) {
Log.e(TAG, "targetPage != firstPage - 1 && (targetPage == firstPage && allPrePageUrl == null) && targetPage != lastPage");
}
final String imageName = String.format("%05d", index + 1) + "." + Util.getExtension(imageUrl);
try {
mDownloader.resetData(mFolder.getPath(),
String.format("%05d", targetPage + 1) + "." + Util.getExtension(imageUrl),
imageName,
imageUrl);
} catch (MalformedURLException e) {
onFailure(checkFlag, R.string.em_url_format_error);
@@ -115,25 +115,56 @@ public class MangaActivity extends Activity {
new Thread() {
@Override
public void run() {
mImageSet.changeState(targetPage, ImageSet.STATE_LOADING);
mDownloader.run();
if (mDownloader.getStatus() == Downloader.COMPLETED) {
mImageSet.changeState(targetPage, ImageSet.STATE_LOADED);
// First check is it in disk and ok
if (testImage(mFolder.getPath(), imageName)) {
onGetImage(index, Downloader.COMPLETED, nextPageUrl);
} else {
mImageSet.changeState(targetPage, ImageSet.STATE_FAIL);
}
if (targetPage == firstPage - 1 &&
getPrePage == true) { // If get prePage
firstPage--;
getPrePage = false;
} else if (nextPageUrl != "last") { // If get nextPage
lastPage++;
EhClient.getManagaUrl(nextPageUrl, lastPage, new MangaUrlGetListener());
mImageSet.changeState(index, ImageSet.STATE_LOADING);
mDownloader.run();
onGetImage(index, mDownloader.getStatus(), nextPageUrl);
}
}
}.start();
}
// TODO only test bitmap here
private boolean testImage(String path, String name) {
boolean isImage = false;
File file = new File(path, name);
FileInputStream fis = null;
try {
// Just test bound might error
fis = new FileInputStream(file);
Bitmap bmp = BitmapFactory.decodeStream(fis);
if (bmp != null) {
bmp.recycle();
isImage = true;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
if (fis != null)
Util.closeStreamQuietly(fis);
}
return isImage;
}
private void onGetImage(int index, int state, String nextPageUrl) {
if (state == Downloader.COMPLETED) {
mImageSet.changeState(index, ImageSet.STATE_LOADED);
} else {
mImageSet.changeState(index, ImageSet.STATE_FAIL);
}
if (index == firstPage - 1 &&
getPrePage == true) { // If get prePage
firstPage--;
getPrePage = false;
} else if (nextPageUrl != "last") { // If get nextPage
lastPage++;
EhClient.getManagaUrl(nextPageUrl, lastPage, new MangaUrlGetListener());
}
}
@Override
public void onFailure(Object checkFlag, int errorMessageId) {
if (stopFlag) {
@@ -1403,9 +1403,6 @@ public class MangaListActivity extends Activity {
protected void onDestroy() {
super.onDestroy();
unbindService(mServiceConn);
if (Config.isAutoPageCache()) {
Cache.pageCache.clear();
}
}
private void checkUpdate() {
@@ -42,9 +42,6 @@ public class SettingsActivity extends PreferenceActivity {
private static final String CP_CACHE = "preference_cp_cache";
private static final String CLEAR_CP_CACHE = "preference_clear_cp_cache";
private static final String PAGE_CACHE = "preference_page_cache";
//private static final String START_POSITION = "preference_start_position";
private static final String CLEAR_PAGE_CACHE = "preference_clear_page_cache";
private static final String PAGE_SCALING = "preference_page_scaling";
private static final String AUTHOR = "preference_author";
private static final String SCREEN_ORI = "preference_screen_ori";
@@ -157,65 +154,6 @@ public class SettingsActivity extends PreferenceActivity {
}
});
pageCachePre = (EditTextPreference) screen.findPreference(PAGE_CACHE);
pageCachePre
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference,
Object newValue) {
int pageCacheSize = 0;
try {
int pageCacheSizeInMB = Integer
.parseInt((String) newValue);
if (pageCacheSizeInMB > 1024) {
Toast.makeText(mContext,
getString(R.string.cache_large),
Toast.LENGTH_SHORT).show();
return false;
}
pageCacheSize = pageCacheSizeInMB * 1024 * 1024;
} catch (Exception e) {
Toast.makeText(mContext,
getString(R.string.input_error),
Toast.LENGTH_SHORT).show();
return false;
}
if (pageCacheSize <= 0 && Cache.pageCache != null) {
Cache.pageCache.clear();
Cache.pageCache.close();
Cache.pageCache = null;
} else if (Cache.pageCache == null) {
try {
Cache.pageCache = new DiskCache(
SettingsActivity.this.getApplication()
.getApplicationContext(),
Cache.pageCachePath, pageCacheSize);
} catch (Exception e) {
Toast.makeText(mContext,
getString(R.string.create_cache_error),
Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
} else
Cache.pageCache.setMaxSize(pageCacheSize);
updatePageCacheSummary();
return true;
}
});
clearPageCachePre = (Preference) screen
.findPreference(CLEAR_PAGE_CACHE);
updatePageCacheSummary();
clearPageCachePre
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Cache.pageCache.clear();
updatePageCacheSummary();
return true;
}
});
pageScalingListPre = (AutoListPreference) screen
.findPreference(PAGE_SCALING);
pageScalingListPre
@@ -348,18 +286,4 @@ public class SettingsActivity extends PreferenceActivity {
clearCpCachePre.setEnabled(false);
}
}
private void updatePageCacheSummary() {
if (Cache.pageCache != null) {
clearPageCachePre.setSummary(String.format(
getString(R.string.preference_cache_summary),
Cache.pageCache.size() / 1024 / 1024f,
Cache.pageCache.maxSize() / 1024 / 1024));
clearPageCachePre.setEnabled(true);
} else {
clearPageCachePre
.setSummary(getString(R.string.preference_cache_summary_no));
clearPageCachePre.setEnabled(false);
}
}
}
@@ -138,16 +138,17 @@ public class ImageSet {
Log.d(TAG, imageData.fileName);
File file = new File(mFolder, imageData.fileName);
FileInputStream fis = null;
try {
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inPreferredConfig = Bitmap.Config.ARGB_8888;
FileInputStream fis = new FileInputStream(file);
fis = new FileInputStream(file);
bmp = BitmapFactory.decodeStream(fis, null, opt);
fis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fis != null)
Util.closeStreamQuietly(fis);
}
return bmp;
}
-13
View File
@@ -17,9 +17,7 @@ public class Cache {
private static Context mContext;
public static final String cpCachePath = "/EhViewer/cache/cover";
public static final String pageCachePath = "/EhViewer/cache/page";
public static DiskCache cpCache = null;
public static DiskCache pageCache = null;
public static LruCache<String, Bitmap> memoryCache = null;
public static LruCache<String, MangaDetail> mdCache = null;
@@ -49,17 +47,6 @@ public class Cache {
} catch (Exception e) {
e.printStackTrace();
}
try {
int pageCacheSize = Config.getPageDiskCacheSize() * 1024 * 1024;
if (pageCacheSize <= 0)
pageCache = null;
else
pageCache = new DiskCache(mContext, pageCachePath,
pageCacheSize);
} catch (Exception e) {
e.printStackTrace();
}
}
//final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
-21
View File
@@ -20,9 +20,6 @@ public class Config {
private static final String CP_CACHE = "preference_cp_cache";
private static final String CP_CACHE_DEFAULT = "25";
private static final String PAGE_CACHE = "preference_page_cache";
private static final String PAGE_CACHE_DEFAULT = "256";
private static final String AUTO_PAGE_CACHE = "preference_auto_page_cache";
private static final String PAGE_SCALING = "preference_page_scaling";
private static final String PAGE_SCALING_DEFAULT = "3";
private static final String START_POSITION = "preference_start_position";
@@ -129,24 +126,6 @@ public class Config {
}
}
/**
* Get page cache size in MB
*
* @return
*/
public static int getPageDiskCacheSize() {
try {
return Integer.parseInt(mConfigPre.getString(PAGE_CACHE, PAGE_CACHE_DEFAULT));
} catch (Exception e) {
mConfigPre.edit().putString(PAGE_CACHE, PAGE_CACHE_DEFAULT).apply();
return 256;
}
}
public static boolean isAutoPageCache() {
return mConfigPre.getBoolean(AUTO_PAGE_CACHE, false);
}
public static int getPageScalingMode() {
int pageScalingMode = 3;
try {