继续
This commit is contained in:
1 parent
70e0aada25
commit
e1edd00fb0
18 files changed
+231
-581
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -29,8 +29,10 @@ public class AppContext extends Application implements UncaughtExceptionHandler
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
Log.i(TAG, "onCreate");
|
||||
|
||||
// TODO Init everything
|
||||
mNetworkThreadPool = new ThreadPool(1, 2);
|
||||
|
||||
Config.init(this);
|
||||
Ui.init(this);
|
||||
Cache.init(this);
|
||||
@@ -41,8 +43,6 @@ public class AppContext extends Application implements UncaughtExceptionHandler
|
||||
mEhClient = new EhClient(this);
|
||||
Download.init(this);
|
||||
|
||||
mNetworkThreadPool = new ThreadPool(1, 2);
|
||||
|
||||
mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
|
||||
Thread.setDefaultUncaughtExceptionHandler(this);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ import android.app.AlertDialog;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.net.Uri;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.util.Log;
|
||||
@@ -47,114 +50,112 @@ public class UpdateHelper {
|
||||
mActivity = activity;
|
||||
}
|
||||
|
||||
public UpdateHelper SetOnCheckUpdateListener(OnCheckUpdateListener listener) {
|
||||
this.listener = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void autoCheckUpdate() {
|
||||
if (Config.getUpdateDate() < Util.getDate())
|
||||
checkUpdate();
|
||||
}
|
||||
|
||||
public void checkUpdate() {
|
||||
ThreadPool threadPool = ((AppContext)(mActivity.getApplicationContext())).getNetworkThreadPool();
|
||||
final AppContext appContext = (AppContext)(mActivity.getApplicationContext());
|
||||
final HttpHelper hp = new HttpHelper(mActivity.getApplicationContext());
|
||||
ThreadPool threadPool = appContext.getNetworkThreadPool();
|
||||
threadPool.submit(new Job<String>() {
|
||||
@Override
|
||||
public String run(JobContext jc) {
|
||||
|
||||
HttpHelper hp = new HttpHelper(mActivity.getApplicationContext());
|
||||
hp.post(UPDATE_API, "")
|
||||
return null;
|
||||
PackageManager pm = appContext.getPackageManager();
|
||||
PackageInfo pi = null;
|
||||
try {
|
||||
pi = pm.getPackageInfo(appContext.getPackageName(), PackageManager.GET_ACTIVITIES);
|
||||
} catch (NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return "NameNotFound";
|
||||
}
|
||||
return hp.post(UPDATE_API, "last\n" + pi.versionName);
|
||||
}
|
||||
}, new FutureListener<String>() {
|
||||
|
||||
@Override
|
||||
public void onFutureDone(Future<String> future) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
EhClient.checkUpdate(new EhClient.OnCheckUpdateListener() {
|
||||
@Override
|
||||
public void onSuccess(String pageContext) {
|
||||
Config.setUpdateDate();
|
||||
String[] items = pageContext.split("\n");
|
||||
if (items.length > 3) {
|
||||
|
||||
if (listener != null)
|
||||
listener.onSuccess(pageContext);
|
||||
|
||||
String newVer = items[0];
|
||||
|
||||
String tempUrl = "";
|
||||
switch (downloadHost) {
|
||||
case GOOGLE:
|
||||
tempUrl = EhClient.UPDATE_URL + items[1];
|
||||
break;
|
||||
case QINIU:
|
||||
tempUrl = EhClient.UPDATE_URI_QINIU + Util.getFileForUrl(items[1]);
|
||||
break;
|
||||
}
|
||||
final String url = tempUrl;
|
||||
final String name = url.substring(url.lastIndexOf('/')+1);
|
||||
updateFileName = name;
|
||||
String size = items[2];
|
||||
String info = items[3];
|
||||
|
||||
AlertDialog dialog = new DialogBuilder(mActivity).setTitle(R.string.update)
|
||||
.setMessage(String.format(mActivity.getString(R.string.update_message), newVer, size, info))
|
||||
.setNegativeButton(android.R.string.cancel, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
((AlertButton)v).dialog.dismiss();
|
||||
}
|
||||
}).setPositiveButton(android.R.string.ok, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
((AlertButton)v).dialog.dismiss();
|
||||
Downloader d = new Downloader();
|
||||
try {
|
||||
d.resetData(Config.getDownloadPath(), name, url);
|
||||
d.setOnDownloadListener(new UpdateListener());
|
||||
new Thread(d).start();
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
String pageContext = future.get();
|
||||
if (pageContext != null) {
|
||||
Config.setUpdateDate();
|
||||
String[] items = pageContext.split("\n");
|
||||
if (items.length > 3) {
|
||||
|
||||
if (listener != null)
|
||||
listener.onSuccess(pageContext);
|
||||
|
||||
String newVer = items[0];
|
||||
|
||||
String tempUrl = "";
|
||||
switch (downloadHost) {
|
||||
case GOOGLE:
|
||||
tempUrl = EhClient.UPDATE_URL + items[1];
|
||||
break;
|
||||
case QINIU:
|
||||
tempUrl = EhClient.UPDATE_URI_QINIU + Util.getFileForUrl(items[1]);
|
||||
break;
|
||||
}
|
||||
final String url = tempUrl;
|
||||
final String name = url.substring(url.lastIndexOf('/')+1);
|
||||
updateFileName = name;
|
||||
String size = items[2];
|
||||
String info = items[3];
|
||||
|
||||
AlertDialog dialog = new DialogBuilder(mActivity).setTitle(R.string.update)
|
||||
.setMessage(String.format(mActivity.getString(R.string.update_message), newVer, size, info))
|
||||
.setNegativeButton(android.R.string.cancel, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
((AlertButton)v).dialog.dismiss();
|
||||
}
|
||||
}
|
||||
}).create();
|
||||
if (!mActivity.isFinishing())
|
||||
dialog.show();
|
||||
} else {
|
||||
if(pageContext.equals("none")) {
|
||||
if (listener != null)
|
||||
listener.onNoUpdate();
|
||||
} else if(pageContext.equals("error")){
|
||||
if (listener != null)
|
||||
listener.onFailure(R.string.em_request_error);
|
||||
}).setPositiveButton(android.R.string.ok, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
((AlertButton)v).dialog.dismiss();
|
||||
Downloader d = new Downloader();
|
||||
try {
|
||||
d.resetData(Config.getDownloadPath(), name, url);
|
||||
d.setOnDownloadListener(new UpdateListener());
|
||||
new Thread(d).start();
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).create();
|
||||
if (!mActivity.isFinishing())
|
||||
dialog.show();
|
||||
} else {
|
||||
if (listener != null)
|
||||
listener.onFailure(R.string.em_host_error);
|
||||
if(pageContext.equals("none")) {
|
||||
if (listener != null)
|
||||
listener.onNoUpdate();
|
||||
} else if(pageContext.equals("error")){
|
||||
if (listener != null)
|
||||
listener.onFailure(appContext.getString(R.string.em_request_error));
|
||||
} else if (pageContext.equals("NameNotFound")){
|
||||
if (listener != null)
|
||||
listener.onFailure("NameNotFound");
|
||||
}else {
|
||||
if (listener != null)
|
||||
listener.onFailure(appContext.getString(R.string.em_host_error));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (listener != null)
|
||||
listener.onFailure(hp.getEMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int eMesgId) {
|
||||
Log.d(TAG, mActivity.getString(eMesgId));
|
||||
if (listener != null)
|
||||
listener.onFailure(eMesgId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public UpdateHelper SetOnCheckUpdateListener(OnCheckUpdateListener listener) {
|
||||
this.listener = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public interface OnCheckUpdateListener {
|
||||
public void onSuccess(String pageContext);
|
||||
public void onNoUpdate();
|
||||
public void onFailure(int eMesgId);
|
||||
public void onFailure(String eMsg);
|
||||
}
|
||||
|
||||
private class UpdateListener implements Downloader.OnDownloadListener {
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.hippo.ehviewer.AppContext;
|
||||
import com.hippo.ehviewer.BeautifyScreen;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.R.id;
|
||||
@@ -23,8 +24,6 @@ import com.hippo.ehviewer.util.Cache;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.ehviewer.util.EhClient;
|
||||
import com.hippo.ehviewer.util.Util;
|
||||
import com.hippo.ehviewer.view.MangaImage;
|
||||
import com.hippo.ehviewer.view.MangaViewPager;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
@@ -51,6 +50,9 @@ import android.widget.Toast;
|
||||
public class MangaActivity extends Activity {
|
||||
private String TAG = "MangaActivity";
|
||||
|
||||
private AppContext mAppContext;
|
||||
private EhClient mEhClient;
|
||||
|
||||
private RelativeLayout mainView;
|
||||
|
||||
private String gid;
|
||||
@@ -122,7 +124,7 @@ public class MangaActivity extends Activity {
|
||||
imageName,
|
||||
imageUrl);
|
||||
} catch (MalformedURLException e) {
|
||||
onFailure(checkFlag, R.string.em_url_format_error);
|
||||
onFailure(checkFlag, mAppContext.getString(R.string.em_url_format_error));
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -176,13 +178,13 @@ public class MangaActivity extends Activity {
|
||||
getPrePage = false;
|
||||
} else if (index == lastPage && nextPageUrl != "last") { // If get nextPage
|
||||
lastPage++;
|
||||
EhClient.getManagaUrl(nextPageUrl, lastPage, new MangaUrlGetListener());
|
||||
mEhClient.getManagaUrl(nextPageUrl, lastPage, new MangaUrlGetListener());
|
||||
mImageSet.changeState(lastPage, ImageSet.STATE_LOADING);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Object checkFlag, int errorMessageId) {
|
||||
public void onFailure(Object checkFlag, String eMsg) {
|
||||
if (stopFlag) {
|
||||
Log.d(TAG, "Stop by stop flag");
|
||||
return;
|
||||
@@ -190,15 +192,15 @@ public class MangaActivity extends Activity {
|
||||
retryTimes++;
|
||||
int targetPage = (Integer)checkFlag;
|
||||
if (retryTimes < maxRetry) {
|
||||
Toast.makeText(MangaActivity.this, getString(errorMessageId) + " " +
|
||||
Toast.makeText(MangaActivity.this, eMsg + " " +
|
||||
String.format(getString(R.string.em_retry_times), retryTimes),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
if (targetPage == firstPage - 1 &&
|
||||
getPrePage == true) {
|
||||
EhClient.getManagaUrl(allPrePageUrl, targetPage, new MangaUrlGetListener());
|
||||
mEhClient.getManagaUrl(allPrePageUrl, targetPage, new MangaUrlGetListener());
|
||||
}
|
||||
else {
|
||||
EhClient.getManagaUrl(allNextPageUrl, targetPage, new MangaUrlGetListener());
|
||||
mEhClient.getManagaUrl(allNextPageUrl, targetPage, new MangaUrlGetListener());
|
||||
}
|
||||
mImageSet.changeState(targetPage, ImageSet.STATE_LOADING);
|
||||
} else {
|
||||
@@ -255,6 +257,9 @@ public class MangaActivity extends Activity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.gl_root_group);
|
||||
|
||||
mAppContext = (AppContext)getApplication();
|
||||
mEhClient = mAppContext.getEhClient();
|
||||
|
||||
int screenOri = Config.getScreenOriMode();
|
||||
if (screenOri != getRequestedOrientation())
|
||||
setRequestedOrientation(screenOri);
|
||||
@@ -307,7 +312,7 @@ public class MangaActivity extends Activity {
|
||||
if (mStop && index == lastPage) {
|
||||
mStop = false;
|
||||
MangaUrlGetListener listener = new MangaUrlGetListener();
|
||||
EhClient.getManagaUrl(allNextPageUrl, lastPage, listener);
|
||||
mEhClient.getManagaUrl(allNextPageUrl, lastPage, listener);
|
||||
mImageSet.changeState(lastPage, ImageSet.STATE_LOADING);
|
||||
}
|
||||
}
|
||||
@@ -317,7 +322,7 @@ public class MangaActivity extends Activity {
|
||||
public void onScrollPage(int index) {
|
||||
if (mStop && index == lastPage) {
|
||||
mStop = false;
|
||||
EhClient.getManagaUrl(allNextPageUrl, lastPage, new MangaUrlGetListener());
|
||||
mEhClient.getManagaUrl(allNextPageUrl, lastPage, new MangaUrlGetListener());
|
||||
mImageSet.changeState(lastPage, ImageSet.STATE_LOADING);
|
||||
}
|
||||
|
||||
@@ -325,7 +330,7 @@ public class MangaActivity extends Activity {
|
||||
&& !allPrePageUrl.equals("first")
|
||||
&& index == firstPage - 1) {
|
||||
getPrePage = true;
|
||||
EhClient.getManagaUrl(allPrePageUrl, firstPage - 1, new MangaUrlGetListener());
|
||||
mEhClient.getManagaUrl(allPrePageUrl, firstPage - 1, new MangaUrlGetListener());
|
||||
mImageSet.changeState(firstPage - 1, ImageSet.STATE_LOADING);
|
||||
}
|
||||
}
|
||||
@@ -346,7 +351,7 @@ public class MangaActivity extends Activity {
|
||||
imagesUrl.set(lastPage, new String[]{url, null});
|
||||
|
||||
// Get image and next page
|
||||
EhClient.getManagaUrl(url, lastPage, new MangaUrlGetListener());
|
||||
mEhClient.getManagaUrl(url, lastPage, new MangaUrlGetListener());
|
||||
mImageSet.changeState(lastPage, ImageSet.STATE_LOADING);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.hippo.ehviewer.activity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.hippo.ehviewer.AppContext;
|
||||
import com.hippo.ehviewer.BeautifyScreen;
|
||||
import com.hippo.ehviewer.ListUrls;
|
||||
import com.hippo.ehviewer.MangaDetail;
|
||||
@@ -58,6 +59,9 @@ public class MangaDetailActivity extends Activity {
|
||||
|
||||
private static final String TAG = "MangaDetailActivity";
|
||||
|
||||
private AppContext mAppContext;
|
||||
private EhClient mEhClient;
|
||||
|
||||
private String url;
|
||||
//private String gid;
|
||||
//private String token;
|
||||
@@ -220,12 +224,12 @@ public class MangaDetailActivity extends Activity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int errorMessageId) {
|
||||
public void onFailure(String eMsg) {
|
||||
// Delete progress bar
|
||||
waitPb.setVisibility(View.GONE);
|
||||
// Show refresh button
|
||||
Toast.makeText(MangaDetailActivity.this,
|
||||
getString(errorMessageId), Toast.LENGTH_SHORT).show();
|
||||
eMsg, Toast.LENGTH_SHORT).show();
|
||||
|
||||
refeshButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
@@ -235,7 +239,7 @@ public class MangaDetailActivity extends Activity {
|
||||
// Refresh
|
||||
public void buttonRefresh(View v) {
|
||||
MangaDetailGetListener listener = new MangaDetailGetListener();
|
||||
EhClient.getManagaDetail(url, mangaDetail, listener);
|
||||
mEhClient.getManagaDetail(url, mangaDetail, listener);
|
||||
// Delete refresh button
|
||||
refeshButton.setVisibility(View.GONE);
|
||||
// Add progressBar
|
||||
@@ -261,7 +265,7 @@ public class MangaDetailActivity extends Activity {
|
||||
}
|
||||
|
||||
MangaDetailGetListener listener = new MangaDetailGetListener();
|
||||
EhClient.getManagaDetail(url, mangaDetail, listener);
|
||||
mEhClient.getManagaDetail(url, mangaDetail, listener);
|
||||
// Delete offensiveView
|
||||
mangaDetailOffensive.setVisibility(View.GONE);
|
||||
// Add progressBar
|
||||
@@ -282,7 +286,7 @@ public class MangaDetailActivity extends Activity {
|
||||
}
|
||||
|
||||
MangaDetailGetListener listener = new MangaDetailGetListener();
|
||||
EhClient.getManagaDetail(url, mangaDetail, listener);
|
||||
mEhClient.getManagaDetail(url, mangaDetail, listener);
|
||||
// Delete offensiveView
|
||||
mangaDetailOffensive.setVisibility(View.GONE);
|
||||
// Add progressBar
|
||||
@@ -387,7 +391,7 @@ public class MangaDetailActivity extends Activity {
|
||||
tempUrl += "/";
|
||||
tempUrl += "?p=" + curPage;
|
||||
|
||||
EhClient.getPageList(tempUrl, curPage,
|
||||
mEhClient.getPageList(tempUrl, curPage,
|
||||
new EhClient.OnGetPageListListener() {
|
||||
@Override
|
||||
public void onSuccess(Object checkFlag, PageList pageList) {
|
||||
@@ -397,11 +401,11 @@ public class MangaDetailActivity extends Activity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Object checkFlag, int errorMessageId) {
|
||||
public void onFailure(Object checkFlag, String eMsg) {
|
||||
int page = (Integer)checkFlag;
|
||||
if (page == curPage) {
|
||||
Toast.makeText(MangaDetailActivity.this,
|
||||
getString(errorMessageId), Toast.LENGTH_SHORT).show();
|
||||
eMsg, Toast.LENGTH_SHORT).show();
|
||||
waitPageList.setVisibility(View.GONE);
|
||||
previewRefreshButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
@@ -440,6 +444,9 @@ public class MangaDetailActivity extends Activity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.detail);
|
||||
|
||||
mAppContext = (AppContext)getApplication();
|
||||
mEhClient = mAppContext.getEhClient();
|
||||
|
||||
int screenOri = Config.getScreenOriMode();
|
||||
if (screenOri != getRequestedOrientation())
|
||||
setRequestedOrientation(screenOri);
|
||||
@@ -512,7 +519,7 @@ public class MangaDetailActivity extends Activity {
|
||||
if (getFromCache)
|
||||
layout(mangaDetail);
|
||||
else
|
||||
EhClient.getManagaDetail(url, mangaDetail, new MangaDetailGetListener());
|
||||
mEhClient.getManagaDetail(url, mangaDetail, new MangaDetailGetListener());
|
||||
}
|
||||
|
||||
private void layout(MangaDetail md) {
|
||||
|
||||
@@ -4,15 +4,15 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import com.hippo.ehviewer.AppContext;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.gallery.GalleryView;
|
||||
import com.hippo.ehviewer.gallery.data.DownloadImageSet;
|
||||
import com.hippo.ehviewer.gallery.data.ImageSet;
|
||||
import com.hippo.ehviewer.gallery.ui.GLRootView;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.ehviewer.util.EhClient;
|
||||
import com.hippo.ehviewer.util.Util;
|
||||
import com.hippo.ehviewer.view.MangaImage;
|
||||
import com.hippo.ehviewer.view.MangaViewPager;
|
||||
|
||||
import android.R.color;
|
||||
import android.annotation.SuppressLint;
|
||||
@@ -46,16 +46,6 @@ public class MangaDownloadActivity extends Activity {
|
||||
private RelativeLayout mainView;
|
||||
private DownloadImageSet mDownloadImageSet;
|
||||
|
||||
class ImageLoadPackage {
|
||||
public MangaImage mMangaImage;
|
||||
public Bitmap mBitmap;
|
||||
|
||||
public ImageLoadPackage(MangaImage mangaImage, Bitmap bitmap) {
|
||||
mMangaImage = mangaImage;
|
||||
mBitmap = bitmap;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.hippo.ehviewer.activity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.hippo.ehviewer.AppContext;
|
||||
import com.hippo.ehviewer.BeautifyScreen;
|
||||
import com.hippo.ehviewer.ImageLoadManager;
|
||||
import com.hippo.ehviewer.ListMangaDetail;
|
||||
@@ -74,6 +75,9 @@ public class MangaListActivity extends Activity {
|
||||
@SuppressWarnings("unused")
|
||||
private static String TAG = "MangaListActivity";
|
||||
|
||||
private AppContext mAppContext;
|
||||
private EhClient mEhClient;
|
||||
|
||||
private DrawerLayout drawer;
|
||||
private GetPaddingRelativeLayout mainLayout;
|
||||
private TagListView listMenu;
|
||||
@@ -161,17 +165,17 @@ public class MangaListActivity extends Activity {
|
||||
waitloginView.setVisibility(View.VISIBLE);
|
||||
String username = ((EditText) loginDialog.findViewById(R.id.username)).getText().toString();
|
||||
String password = ((EditText) loginDialog.findViewById(R.id.password)).getText().toString();
|
||||
EhClient.login(username, password, new EhClient.OnLoginListener() {
|
||||
mEhClient.login(username, password, new EhClient.OnLoginListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
checkLogin(true);
|
||||
}
|
||||
@Override
|
||||
public void onFailure(int errorMessageId) {
|
||||
public void onFailure(String eMsg) {
|
||||
loginButton.setVisibility(View.VISIBLE);
|
||||
waitloginView.setVisibility(View.GONE);
|
||||
Toast.makeText(MangaListActivity.this,
|
||||
getString(errorMessageId),
|
||||
eMsg,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
loginDialog.show();
|
||||
}
|
||||
@@ -828,7 +832,7 @@ public class MangaListActivity extends Activity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Object checkFlag, int errorMessageId) {
|
||||
public void onFailure(Object checkFlag, String eMsg) {
|
||||
MangaListGetPackage getPackage = (MangaListGetPackage)checkFlag;
|
||||
if (getPackage.stamp != lastGetStamp)
|
||||
return;
|
||||
@@ -847,7 +851,7 @@ public class MangaListActivity extends Activity {
|
||||
pullListView.setVisibility(View.GONE);
|
||||
freshButton.setVisibility(View.VISIBLE);
|
||||
Toast.makeText(MangaListActivity.this,
|
||||
getString(errorMessageId), Toast.LENGTH_SHORT)
|
||||
eMsg, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
lmdArray.clear();
|
||||
gmlAdapter.notifyDataSetChanged();
|
||||
@@ -856,7 +860,7 @@ public class MangaListActivity extends Activity {
|
||||
freshButton.setVisibility(View.GONE);
|
||||
Toast.makeText(
|
||||
MangaListActivity.this,
|
||||
getString(errorMessageId),
|
||||
eMsg,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@@ -1024,6 +1028,9 @@ public class MangaListActivity extends Activity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.list);
|
||||
|
||||
mAppContext = (AppContext)getApplication();
|
||||
mEhClient = mAppContext.getEhClient();
|
||||
|
||||
int screenOri = Config.getScreenOriMode();
|
||||
if (screenOri != getRequestedOrientation())
|
||||
setRequestedOrientation(screenOri);
|
||||
@@ -1210,7 +1217,7 @@ public class MangaListActivity extends Activity {
|
||||
listUrls.setPage(0);
|
||||
else
|
||||
listUrls.setPage(firstPage - 1);
|
||||
EhClient.getManagaList(listUrls.getUrl(),
|
||||
mEhClient.getManagaList(listUrls.getUrl(),
|
||||
new MangaListGetPackage((lastGetStamp = System.currentTimeMillis()), listUrls, false, title),
|
||||
new MangaListGetListener());
|
||||
}
|
||||
@@ -1220,7 +1227,7 @@ public class MangaListActivity extends Activity {
|
||||
mListFirst = true;
|
||||
mLoadListOver = false;
|
||||
RefreshPackage rp = (RefreshPackage)obj;
|
||||
EhClient.getManagaList(rp.listUrls.getUrl(),
|
||||
mEhClient.getManagaList(rp.listUrls.getUrl(),
|
||||
new MangaListGetPackage((lastGetStamp = System.currentTimeMillis()),
|
||||
rp.listUrls, true, rp.title),
|
||||
new MangaListGetListener());
|
||||
@@ -1234,7 +1241,7 @@ public class MangaListActivity extends Activity {
|
||||
if (listUrls.setPage(lastPage + 1)) {
|
||||
mListFirst = true;
|
||||
mLoadListOver = false;
|
||||
EhClient.getManagaList(listUrls.getUrl(),
|
||||
mEhClient.getManagaList(listUrls.getUrl(),
|
||||
new MangaListGetPackage((lastGetStamp = System.currentTimeMillis()), listUrls, false, title),
|
||||
new MangaListGetListener());
|
||||
}
|
||||
@@ -1414,7 +1421,7 @@ public class MangaListActivity extends Activity {
|
||||
loginButton.setVisibility(View.GONE);
|
||||
checkLoginButton.setVisibility(View.GONE);
|
||||
waitloginView.setVisibility(View.VISIBLE);
|
||||
EhClient.checkLogin(new EhClient.OnCheckLoginListener() {
|
||||
mEhClient.checkLogin(new EhClient.OnCheckLoginListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
Config.loginNow();
|
||||
@@ -1425,7 +1432,7 @@ public class MangaListActivity extends Activity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int errorMessageId) {
|
||||
public void onFailure(String eMsg) {
|
||||
loginButton.setVisibility(View.VISIBLE);
|
||||
if (Config.isLogin())
|
||||
checkLoginButton.setVisibility(View.VISIBLE);
|
||||
@@ -1433,7 +1440,7 @@ public class MangaListActivity extends Activity {
|
||||
checkLoginButton.setVisibility(View.GONE);
|
||||
waitloginView.setVisibility(View.GONE);
|
||||
Toast.makeText(MangaListActivity.this,
|
||||
getString(errorMessageId),
|
||||
eMsg,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
@@ -1441,11 +1448,11 @@ public class MangaListActivity extends Activity {
|
||||
}
|
||||
|
||||
private void layoutDrawRight() {
|
||||
if (EhClient.isLogin()) { // If have login
|
||||
if (mEhClient.isLogin()) { // If have login
|
||||
loginView.setVisibility(View.GONE);
|
||||
loginOverView.setVisibility(View.VISIBLE);
|
||||
|
||||
usernameText.setText(EhClient.getUsername());
|
||||
usernameText.setText(mEhClient.getUsername());
|
||||
logoutButton.setVisibility(View.VISIBLE);
|
||||
waitlogoutView.setVisibility(View.GONE);
|
||||
} else {
|
||||
@@ -1498,7 +1505,7 @@ public class MangaListActivity extends Activity {
|
||||
public void buttonLogout(View paramView) {
|
||||
logoutButton.setVisibility(View.GONE);
|
||||
waitlogoutView.setVisibility(View.VISIBLE);
|
||||
EhClient.logout(new EhClient.OnLogoutListener() {
|
||||
mEhClient.logout(new EhClient.OnLogoutListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
Toast.makeText(MangaListActivity.this,
|
||||
@@ -1509,9 +1516,9 @@ public class MangaListActivity extends Activity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int errorMessageId) {
|
||||
public void onFailure(String eMsg) {
|
||||
Toast.makeText(MangaListActivity.this,
|
||||
getString(errorMessageId),
|
||||
eMsg,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
logoutButton.setVisibility(View.VISIBLE);
|
||||
waitlogoutView.setVisibility(View.GONE);
|
||||
|
||||
@@ -9,7 +9,6 @@ import com.hippo.ehviewer.UpdateHelper;
|
||||
import com.hippo.ehviewer.util.Cache;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.ehviewer.util.Util;
|
||||
import com.hippo.ehviewer.view.MangaImage;
|
||||
import com.hippo.ehviewer.widget.DialogBuilder;
|
||||
import com.hippo.ehviewer.preference.AutoListPreference;
|
||||
|
||||
@@ -153,30 +152,6 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
pageScalingListPre = (AutoListPreference) screen
|
||||
.findPreference(PAGE_SCALING);
|
||||
pageScalingListPre
|
||||
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference,
|
||||
Object newValue) {
|
||||
MangaImage.setMode(Integer.parseInt((String) newValue));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
final AutoListPreference start_position =
|
||||
(AutoListPreference)screen.findPreference(START_POSITION);
|
||||
start_position.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference,
|
||||
Object newValue) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
});*/
|
||||
|
||||
|
||||
// Connect me !
|
||||
@@ -251,8 +226,8 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
update.setEnabled(true);
|
||||
}
|
||||
@Override
|
||||
public void onFailure(int eMesgId) {
|
||||
update.setSummary(eMesgId);
|
||||
public void onFailure(String eMsg) {
|
||||
update.setSummary(eMsg);
|
||||
update.setEnabled(true);
|
||||
}
|
||||
}).checkUpdate();
|
||||
|
||||
@@ -3,11 +3,13 @@ package com.hippo.ehviewer.service;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.hippo.ehviewer.AppContext;
|
||||
import com.hippo.ehviewer.DownloadInfo;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.activity.DownloadActivity;
|
||||
import com.hippo.ehviewer.util.Download;
|
||||
import com.hippo.ehviewer.util.EhClient;
|
||||
import com.hippo.ehviewer.util.EhClient.DownloadMangaManager;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
@@ -27,16 +29,20 @@ public class DownloadService extends Service {
|
||||
public static final String KEY_INDEX = "index";
|
||||
public static final String KEY_STATE = "state";
|
||||
|
||||
private AppContext mAppContext;
|
||||
|
||||
private ServiceBinder mBinder = null;
|
||||
|
||||
private NotificationManager mNotifyManager;
|
||||
private NotificationCompat.Builder mBuilder;
|
||||
|
||||
private DownloadMangaManager downloadMangaManager;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
Log.d(TAG, "Service onCreate");
|
||||
mAppContext = (AppContext)getApplication();
|
||||
|
||||
mBinder = new ServiceBinder();
|
||||
mNotifyManager = (NotificationManager)
|
||||
@@ -48,8 +54,10 @@ public class DownloadService extends Service {
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(DownloadService.this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
mBuilder.setContentIntent(pendingIntent);
|
||||
|
||||
EhClient.DownloadMangaManager.setDownloadService(this);
|
||||
EhClient.DownloadMangaManager.setOnDownloadMangaListener(new EhClient.OnDownloadMangaListener() {
|
||||
downloadMangaManager = mAppContext.getEhClient().new DownloadMangaManager();
|
||||
|
||||
downloadMangaManager.setDownloadService(this);
|
||||
downloadMangaManager.setOnDownloadMangaListener(new EhClient.OnDownloadMangaListener() {
|
||||
@Override
|
||||
public void onDownloadMangaAllStart() {
|
||||
mBuilder.setContentTitle(getString(R.string.start_download_task))
|
||||
@@ -206,11 +214,11 @@ public class DownloadService extends Service {
|
||||
|| di.status == DownloadInfo.WAITING)
|
||||
return;
|
||||
di.status = DownloadInfo.WAITING;
|
||||
EhClient.DownloadMangaManager.add(di);
|
||||
downloadMangaManager.add(di);
|
||||
}
|
||||
|
||||
public void cancel(String id) {
|
||||
EhClient.DownloadMangaManager.cancel(id);
|
||||
downloadMangaManager.cancel(id);
|
||||
}
|
||||
|
||||
public void notifyUpdate(){
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.hippo.ehviewer.util;
|
||||
|
||||
import com.hippo.ehviewer.view.MangaImage;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ActivityInfo;
|
||||
@@ -46,9 +44,6 @@ public class Config {
|
||||
|
||||
mContext = context;
|
||||
mConfigPre = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||
|
||||
// Init what in config
|
||||
MangaImage.setMode(getPageScalingMode());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,18 +1,28 @@
|
||||
package com.hippo.ehviewer.util;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.CookieHandler;
|
||||
import java.net.CookieManager;
|
||||
import java.net.CookiePolicy;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.apache.http.conn.ConnectTimeoutException;
|
||||
|
||||
import com.hippo.ehviewer.AppContext;
|
||||
import com.hippo.ehviewer.DiskCache;
|
||||
import com.hippo.ehviewer.DownloadInfo;
|
||||
import com.hippo.ehviewer.ListMangaDetail;
|
||||
import com.hippo.ehviewer.ListUrls;
|
||||
@@ -28,6 +38,12 @@ import com.hippo.ehviewer.util.ThreadPool.Job;
|
||||
import com.hippo.ehviewer.util.ThreadPool.JobContext;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Movie;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v4.util.LruCache;
|
||||
import android.util.Log;
|
||||
|
||||
// TODO Stringbuffer to StringBuild
|
||||
@@ -58,18 +74,8 @@ public class EhClient {
|
||||
private String name;
|
||||
private String logoutUrl;
|
||||
|
||||
private Context mContext;
|
||||
private AppContext mAppContext;
|
||||
private ThreadPool mThreadPool;
|
||||
|
||||
public interface OnCheckNetworkListener {
|
||||
public void onSuccess();
|
||||
public void onFailure(String eMsg);
|
||||
}
|
||||
|
||||
public interface OnCheckUpdateListener {
|
||||
public void onSuccess(String pageContext);
|
||||
public void onFailure(String eMsg);
|
||||
}
|
||||
|
||||
public interface OnLogoutListener {
|
||||
public void onSuccess();
|
||||
@@ -109,7 +115,7 @@ public class EhClient {
|
||||
|
||||
public interface OnGetImageListener {
|
||||
public void onSuccess(Object checkFlag, Object res);
|
||||
public void onFailure(String eMsg);
|
||||
public void onFailure(int eMsgId);
|
||||
}
|
||||
|
||||
public interface OnGetGalleryMetadataListener {
|
||||
@@ -122,10 +128,10 @@ public class EhClient {
|
||||
public void onFailure(String eMsg);
|
||||
}
|
||||
|
||||
public EhClient(Context context) {
|
||||
mContext = context;
|
||||
public EhClient(AppContext appContext) {
|
||||
mAppContext = appContext;
|
||||
|
||||
CookieManager cookieManager = new CookieManager(new ShapreCookieStore(mContext), CookiePolicy.ACCEPT_ALL);
|
||||
CookieManager cookieManager = new CookieManager(new ShapreCookieStore(mAppContext), CookiePolicy.ACCEPT_ALL);
|
||||
CookieHandler.setDefault(cookieManager);
|
||||
|
||||
if (Config.isExhentai()) {
|
||||
@@ -136,7 +142,7 @@ public class EhClient {
|
||||
detailHeader = E_HENTAI_DETAIL_HEADER;
|
||||
}
|
||||
|
||||
mThreadPool = ((AppContext)(context.getApplicationContext())).getNetworkThreadPool();
|
||||
mThreadPool = mAppContext.getNetworkThreadPool();
|
||||
}
|
||||
|
||||
public static void setHeader(boolean isExhentai) {
|
||||
@@ -181,13 +187,13 @@ public class EhClient {
|
||||
new String[] { "submit", "Log+me+in" },
|
||||
new String[] { "CookieDate", "1" },
|
||||
new String[] { "temporary_https", "on" }};
|
||||
HttpHelper hp = new HttpHelper(mContext);
|
||||
HttpHelper hp = new HttpHelper(mAppContext);
|
||||
String pageContent = hp.post(loginUrl, args);
|
||||
if (pageContent != null) {
|
||||
if (pageContent.contains("<p>You are now logged in as: "))
|
||||
ok = true;
|
||||
else
|
||||
eMsg = mContext.getString(R.string.em_logout_error);
|
||||
eMsg = mAppContext.getString(R.string.em_logout_error);
|
||||
} else
|
||||
eMsg = hp.getEMsg();
|
||||
}
|
||||
@@ -226,7 +232,7 @@ public class EhClient {
|
||||
@Override
|
||||
public void run() {
|
||||
ok = false;
|
||||
HttpHelper hp = new HttpHelper(mContext);
|
||||
HttpHelper hp = new HttpHelper(mAppContext);
|
||||
String pageContent = hp.get(loginUrl);
|
||||
if (pageContent != null) {
|
||||
Pattern p = Pattern
|
||||
@@ -238,7 +244,7 @@ public class EhClient {
|
||||
name = m.group(1);
|
||||
logoutUrl = StringEscapeUtils.unescapeHtml4(m.group(2));
|
||||
} else
|
||||
eMsg = mContext.getString(R.string.em_check_login_error);
|
||||
eMsg = mAppContext.getString(R.string.em_check_login_error);
|
||||
} else
|
||||
eMsg = hp.getEMsg();
|
||||
}
|
||||
@@ -249,12 +255,18 @@ public class EhClient {
|
||||
mThreadPool.submit(new Job<Object>() {
|
||||
@Override
|
||||
public Object run(JobContext jc) {
|
||||
|
||||
Log.d(TAG, Thread.currentThread().toString());
|
||||
|
||||
task.run();
|
||||
return null;
|
||||
}
|
||||
}, new FutureListener<Object>() {
|
||||
@Override
|
||||
public void onFutureDone(Future<Object> future) {
|
||||
|
||||
Log.d(TAG, Thread.currentThread().toString());
|
||||
|
||||
if (task.ok) {
|
||||
mLogin = true;
|
||||
if (listener != null)
|
||||
@@ -276,13 +288,13 @@ public class EhClient {
|
||||
@Override
|
||||
public void run() {
|
||||
ok = false;
|
||||
HttpHelper hp = new HttpHelper(mContext);
|
||||
HttpHelper hp = new HttpHelper(mAppContext);
|
||||
String pageContent = hp.get(logoutUrl);
|
||||
if (pageContent != null) {
|
||||
if (pageContent.contains("<p>You are now logged out<br />"))
|
||||
ok = true;
|
||||
else
|
||||
eMsg = mContext.getString(R.string.em_logout_error);
|
||||
eMsg = mAppContext.getString(R.string.em_logout_error);
|
||||
} else
|
||||
eMsg = hp.getEMsg();
|
||||
}
|
||||
@@ -331,7 +343,7 @@ public class EhClient {
|
||||
indexPerPage = 25;
|
||||
maxPage = 0;
|
||||
|
||||
HttpHelper hp = new HttpHelper(mContext);
|
||||
HttpHelper hp = new HttpHelper(mAppContext);
|
||||
String pageContent = hp.get(url);
|
||||
|
||||
if (pageContent != null) {
|
||||
@@ -360,7 +372,7 @@ public class EhClient {
|
||||
lmdArray = new ArrayList<ListMangaDetail>();
|
||||
maxPage = -1;
|
||||
} else
|
||||
eMsg = mContext.getString(R.string.em_parser_error);
|
||||
eMsg = mAppContext.getString(R.string.em_parser_error);
|
||||
|
||||
// Get list
|
||||
if (getPageCount) {
|
||||
@@ -410,7 +422,7 @@ public class EhClient {
|
||||
lmdArray.add(lmd);
|
||||
}
|
||||
if (lmdArray == null)
|
||||
eMsg = mContext.getString(R.string.em_parser_error);
|
||||
eMsg = mAppContext.getString(R.string.em_parser_error);
|
||||
}
|
||||
} else
|
||||
eMsg = hp.getEMsg();
|
||||
@@ -510,7 +522,7 @@ public class EhClient {
|
||||
@Override
|
||||
public void run() {
|
||||
ok = false;
|
||||
HttpHelper hp = new HttpHelper(mContext);
|
||||
HttpHelper hp = new HttpHelper(mAppContext);
|
||||
String pageContent = hp.get(url);
|
||||
if (pageContent != null) {
|
||||
Pattern p = Pattern
|
||||
@@ -536,7 +548,7 @@ public class EhClient {
|
||||
if (matcher.find())
|
||||
md.rating = matcher.group(1);
|
||||
else
|
||||
md.rating = mContext.getString(R.string.detail_not_rated);
|
||||
md.rating = mAppContext.getString(R.string.detail_not_rated);
|
||||
md.firstPage = m.group(16);
|
||||
md.previewPerPage = Integer.parseInt(m.group(14).replace(",",
|
||||
""))
|
||||
@@ -559,7 +571,7 @@ public class EhClient {
|
||||
ok = true;
|
||||
md.firstPage = "pining";
|
||||
} else
|
||||
eMsg = mContext.getString(R.string.em_parser_error);
|
||||
eMsg = mAppContext.getString(R.string.em_parser_error);
|
||||
} else
|
||||
eMsg = hp.getEMsg();
|
||||
}
|
||||
@@ -648,12 +660,12 @@ public class EhClient {
|
||||
public void run() {
|
||||
PageList pageList = null;
|
||||
|
||||
HttpHelper hp = new HttpHelper(mContext);
|
||||
HttpHelper hp = new HttpHelper(mAppContext);
|
||||
String pageContent = hp.get(url);
|
||||
if (pageContent != null) {
|
||||
pageList = getPageList(pageContent);
|
||||
if (pageList == null)
|
||||
eMsg = mContext.getString(R.string.em_parser_error);
|
||||
eMsg = mAppContext.getString(R.string.em_parser_error);
|
||||
} else
|
||||
eMsg = hp.getEMsg();
|
||||
}
|
||||
@@ -712,7 +724,7 @@ public class EhClient {
|
||||
public void run() {
|
||||
String[] strs = null;
|
||||
|
||||
HttpHelper hp = new HttpHelper(mContext);
|
||||
HttpHelper hp = new HttpHelper(mAppContext);
|
||||
String pageContent = hp.get(url);
|
||||
if (pageContent != null) {
|
||||
Pattern p = Pattern.compile("<a[^<>]*id=\"prev\"[^<>]*href=\"([^<>\"]+)\"><img[^<>]*/></a>.+<a[^<>]id=\"next\"[^<>]*href=\"([^<>\"]+)\"><img[^<>]*/></a>.+<img[^<>]*src=\"([^<>\"]+?)\"[^<>]*style=\"[^<>\"]*\"[^<>]*/>");
|
||||
@@ -730,7 +742,7 @@ public class EhClient {
|
||||
strs[1] = m.group(2);
|
||||
strs[2] = StringEscapeUtils.unescapeHtml4(m.group(3));
|
||||
} else
|
||||
eMsg = mContext.getString(R.string.em_parser_error);
|
||||
eMsg = mAppContext.getString(R.string.em_parser_error);
|
||||
} else
|
||||
eMsg = hp.getEMsg();
|
||||
}
|
||||
@@ -758,7 +770,7 @@ public class EhClient {
|
||||
}
|
||||
});
|
||||
}
|
||||
/*
|
||||
|
||||
// Get image
|
||||
private static class GetImagePackage {
|
||||
public Object res;
|
||||
@@ -834,8 +846,8 @@ public class EhClient {
|
||||
try {
|
||||
URL url = new URL(this.url);
|
||||
conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setConnectTimeout(TIMEOUT);
|
||||
conn.setRequestProperty("User-Agent", userAgent);
|
||||
conn.setConnectTimeout(5 * 1000);
|
||||
conn.setReadTimeout(5 * 1000);
|
||||
conn.connect();
|
||||
InputStream is = conn.getInputStream();
|
||||
if (diskCache != null) {
|
||||
@@ -906,7 +918,7 @@ public class EhClient {
|
||||
checkFlag, listener)).start();
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
public interface OnDownloadMangaListener {
|
||||
public void onDownloadMangaStart(String id);
|
||||
public void onDownloadMangaStart(String id, int pageSum, int startIndex);
|
||||
@@ -1192,7 +1204,7 @@ public class EhClient {
|
||||
}
|
||||
|
||||
public boolean getFirstPagePageSumForDetail(String detailUrlStr) {
|
||||
HttpHelper hp = new HttpHelper(mContext);
|
||||
HttpHelper hp = new HttpHelper(mAppContext);
|
||||
String pageContent = hp.get(detailUrlStr);
|
||||
if (pageContent == null)
|
||||
return false;
|
||||
@@ -1214,7 +1226,7 @@ public class EhClient {
|
||||
* @return True if get
|
||||
*/
|
||||
public boolean getPageInfoSumForPage(String pageUrlStr) {
|
||||
HttpHelper hp = new HttpHelper(mContext);
|
||||
HttpHelper hp = new HttpHelper(mAppContext);
|
||||
String pageContent = hp.get(pageUrlStr);
|
||||
if (pageContent == null)
|
||||
return false;
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.hippo.ehviewer.util;
|
||||
|
||||
import com.hippo.ehviewer.ListUrls;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.view.OlImageView;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
@@ -80,7 +79,6 @@ public class Ui {
|
||||
|
||||
BITMAP_LAUNCH = BitmapFactory.decodeStream(mContext.getResources().openRawResource(R.drawable.ic_launcher), null, opt);
|
||||
BITMAP_TOUCH = BitmapFactory.decodeStream(mContext.getResources().openRawResource(R.drawable.ic_touch), null, opt);
|
||||
OlImageView.setDefaultImage(BITMAP_LAUNCH, BITMAP_TOUCH);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.zip.InflaterInputStream;
|
||||
import com.hippo.ehviewer.DiskCache;
|
||||
import com.hippo.ehviewer.ListUrls;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.view.OlImageView;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
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,296 +0,0 @@
|
||||
package com.hippo.ehviewer.view;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.PointF;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
||||
// TODO point
|
||||
// TODO when screen is locked and load image, image may not show
|
||||
public class MangaImage extends OlImageView {
|
||||
|
||||
private static ArrayList<WeakReference<MangaImage>> mangaImageList = new ArrayList<WeakReference<MangaImage>>();
|
||||
private static ArrayList<WeakReference<MangaImage>> delList = new ArrayList<WeakReference<MangaImage>>();
|
||||
|
||||
private static final String TAG = "MangaImage";
|
||||
|
||||
public static enum State {
|
||||
NONE, ONE_DOWN, DRAG, ZOOM, POINT
|
||||
};
|
||||
|
||||
public static enum Action {
|
||||
ZOOM_IN, ZOOM_OUT
|
||||
};
|
||||
|
||||
private static final Mode[] sModeArray = {
|
||||
Mode.CENTER, Mode.FIT_WIDTH, Mode.FIT_HEIGHT, Mode.FIT, Mode.SHARED
|
||||
};
|
||||
|
||||
public enum Mode {
|
||||
CENTER(0),
|
||||
FIT_WIDTH(1),
|
||||
FIT_HEIGHT(2),
|
||||
FIT(3),
|
||||
SHARED(4);
|
||||
|
||||
Mode(int ni) {
|
||||
nativeInt = ni;
|
||||
}
|
||||
|
||||
final int nativeInt;
|
||||
};
|
||||
|
||||
private State state;
|
||||
private static Mode mMode = Mode.FIT;
|
||||
|
||||
private static Matrix sharedMatrix = new Matrix();
|
||||
private Matrix matrix = new Matrix();
|
||||
private Matrix preMatrix = new Matrix();
|
||||
private float[] matrixValues = new float[9];
|
||||
private PointF firstPoint = new PointF();
|
||||
private PointF midPoint = new PointF();
|
||||
|
||||
private int aWidth;
|
||||
private int aHeight;
|
||||
private int viewWidth;
|
||||
private int viewHeight;
|
||||
|
||||
public MangaImage(Context context) {
|
||||
super(context);
|
||||
cleanList();
|
||||
mangaImageList.add(new WeakReference<MangaImage>(this));
|
||||
setListener();
|
||||
}
|
||||
|
||||
public MangaImage(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public MangaImage(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
cleanList();
|
||||
mangaImageList.add(new WeakReference<MangaImage>(this));
|
||||
setListener();
|
||||
}
|
||||
|
||||
public static void setMode(int mode) {
|
||||
mMode = sModeArray[mode];
|
||||
for (WeakReference<MangaImage> weakMangaImage : mangaImageList) {
|
||||
MangaImage mangaImage = null;
|
||||
if ((mangaImage = weakMangaImage.get()) != null) {
|
||||
mangaImage.resetMatrix();
|
||||
mangaImage.setImageMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void cleanList() {
|
||||
for (WeakReference<MangaImage> weakMangaImage : mangaImageList) {
|
||||
if (weakMangaImage.get() == null)
|
||||
delList.add(weakMangaImage);
|
||||
}
|
||||
for (WeakReference<MangaImage> weakMangaImage : delList) {
|
||||
mangaImageList.remove(weakMangaImage);
|
||||
}
|
||||
delList.clear();
|
||||
}
|
||||
|
||||
private void setListener() {
|
||||
setOnLoadListener(new OnLoadListener() {
|
||||
@Override
|
||||
public void onLoadCompleted(boolean ok) {
|
||||
if (!ok)
|
||||
return;
|
||||
viewWidth = getWidth();
|
||||
viewHeight = getHeight();
|
||||
setScaleType(ScaleType.MATRIX);
|
||||
resetMatrix();
|
||||
matrix.getValues(matrixValues);
|
||||
aWidth = (int) (getResourceWidth() * matrixValues[Matrix.MSCALE_X]);
|
||||
aHeight = (int) (getResourceHeight() * matrixValues[Matrix.MSCALE_Y]);
|
||||
setImageMatrix();
|
||||
|
||||
state = State.NONE;
|
||||
setOnTouchListener(new MangaImageListener());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setImageMatrix() {
|
||||
setImageMatrix(matrix);
|
||||
}
|
||||
|
||||
private void resetMatrix() {
|
||||
matrix.reset();
|
||||
float scale;
|
||||
int actWidth = getResourceWidth();
|
||||
int actHeight = getResourceHeight();
|
||||
switch (mMode) {
|
||||
case CENTER:
|
||||
matrix.preTranslate((viewWidth - actWidth) / 2f, (viewHeight - actHeight) / 2f);
|
||||
break;
|
||||
case FIT_WIDTH:
|
||||
scale = (float)viewWidth/actWidth;
|
||||
matrix.preScale(scale, scale);
|
||||
matrix.preTranslate((viewWidth - actWidth*scale) / scale / 2f, (viewHeight - actHeight*scale) / scale / 2f);
|
||||
break;
|
||||
case FIT_HEIGHT:
|
||||
scale = (float)viewHeight/actHeight;
|
||||
matrix.preScale(scale, scale);
|
||||
matrix.preTranslate((viewWidth - actWidth*scale) / scale / 2f, (viewHeight - actHeight*scale) / scale / 2f);
|
||||
break;
|
||||
case FIT:
|
||||
float scaleX = (float)viewWidth/actWidth;
|
||||
float scaleY = (float)viewHeight/actHeight;
|
||||
scale = scaleX < scaleY ? scaleX : scaleY;
|
||||
matrix.preScale(scale, scale);
|
||||
matrix.preTranslate((viewWidth - actWidth*scale) / scale / 2f, (viewHeight - actHeight*scale) / scale / 2f);
|
||||
break;
|
||||
case SHARED:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canScroll(int direction) {
|
||||
|
||||
matrix.getValues(matrixValues);
|
||||
int xOffset = (int) matrixValues[Matrix.MTRANS_X];
|
||||
|
||||
if (state == State.ZOOM)
|
||||
return true;
|
||||
|
||||
if (aWidth <= viewWidth) {
|
||||
return false;
|
||||
|
||||
} else if (xOffset == 0 && direction > 0) {
|
||||
return false;
|
||||
|
||||
} else if (xOffset == viewWidth - aWidth && direction < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private class MangaImageListener implements OnTouchListener {
|
||||
float dist = 0f;
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
|
||||
switch (event.getAction() & MotionEvent.ACTION_MASK) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
preMatrix.set(matrix);
|
||||
firstPoint.set(event.getX(), event.getY());
|
||||
state = State.ONE_DOWN;
|
||||
break;
|
||||
case MotionEvent.ACTION_POINTER_DOWN:
|
||||
dist = spacing(event);
|
||||
if (dist > 10f) {
|
||||
preMatrix.set(matrix);
|
||||
midPoint(event);
|
||||
state = State.ZOOM;
|
||||
}
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if (state == State.ONE_DOWN)
|
||||
state = State.DRAG;
|
||||
if (state == State.DRAG) {
|
||||
matrix.set(preMatrix);
|
||||
matrix.postTranslate(event.getX() - firstPoint.x,
|
||||
event.getY() - firstPoint.y);
|
||||
} else if (state == State.ZOOM) {
|
||||
float newDist = spacing(event);
|
||||
if (newDist > 10f) {
|
||||
matrix.set(preMatrix);
|
||||
float tScale = newDist / dist;
|
||||
matrix.postScale(tScale, tScale, midPoint.x, midPoint.y);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
if (state == State.ONE_DOWN)
|
||||
state = State.POINT;
|
||||
else
|
||||
state = State.NONE;
|
||||
break;
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
state = State.NONE;
|
||||
break;
|
||||
case MotionEvent.ACTION_OUTSIDE:
|
||||
state = State.NONE;
|
||||
break;
|
||||
case MotionEvent.ACTION_POINTER_UP:
|
||||
if (event.getActionIndex() == 1) {
|
||||
preMatrix.set(matrix);
|
||||
firstPoint.set(event.getX(0), event.getY(0));
|
||||
state = State.DRAG;
|
||||
} else if (event.getActionIndex() == 0) {
|
||||
preMatrix.set(matrix);
|
||||
firstPoint.set(event.getX(1), event.getY(1));
|
||||
state = State.DRAG;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (state == State.POINT) {
|
||||
Toast.makeText(
|
||||
MangaImage.this.getContext(),
|
||||
"Point : x = " + firstPoint.x + ", y = " + firstPoint.y,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
//int pointAction =
|
||||
state = State.NONE;
|
||||
} else if (state == State.DRAG || state == State.ZOOM) {
|
||||
checkBorder();
|
||||
MangaImage.this.setImageMatrix(matrix);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private float spacing(MotionEvent event) {
|
||||
float x = event.getX(0) - event.getX(1);
|
||||
float y = event.getY(0) - event.getY(1);
|
||||
return (float) Math.sqrt(x * x + y * y);
|
||||
}
|
||||
|
||||
private void midPoint(MotionEvent event) {
|
||||
float x = event.getX(0) + event.getX(1);
|
||||
float y = event.getY(0) + event.getY(1);
|
||||
midPoint.set(x / 2, y / 2);
|
||||
}
|
||||
|
||||
private void checkBorder() {
|
||||
matrix.getValues(matrixValues);
|
||||
aWidth = (int) (MangaImage.this.getResourceWidth() * matrixValues[Matrix.MSCALE_X]);
|
||||
aHeight = (int) (MangaImage.this.getResourceHeight() * matrixValues[Matrix.MSCALE_Y]);
|
||||
viewWidth = MangaImage.this.getWidth();
|
||||
viewHeight = MangaImage.this.getHeight();
|
||||
|
||||
if (aWidth > viewWidth) {
|
||||
if (matrixValues[Matrix.MTRANS_X] > 0)
|
||||
matrixValues[Matrix.MTRANS_X] = 0;
|
||||
else if (matrixValues[Matrix.MTRANS_X] < viewWidth - aWidth)
|
||||
matrixValues[Matrix.MTRANS_X] = viewWidth - aWidth;
|
||||
} else {
|
||||
matrixValues[Matrix.MTRANS_X] = (viewWidth - aWidth) / 2;
|
||||
}
|
||||
if (aHeight > viewHeight) {
|
||||
if (matrixValues[Matrix.MTRANS_Y] > 0)
|
||||
matrixValues[Matrix.MTRANS_Y] = 0;
|
||||
else if (matrixValues[5] < viewHeight - aHeight)
|
||||
matrixValues[Matrix.MTRANS_Y] = viewHeight - aHeight;
|
||||
} else {
|
||||
matrixValues[Matrix.MTRANS_Y] = (viewHeight - aHeight) / 2;
|
||||
}
|
||||
matrix.setValues(matrixValues);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package com.hippo.ehviewer.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.GestureDetector.SimpleOnGestureListener;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
public class MangaViewPager extends ViewPager {
|
||||
private GestureDetector mGestureDetector;
|
||||
public float distanceX;
|
||||
public MangaViewPager(Context context) {
|
||||
super(context);
|
||||
mGestureDetector = new GestureDetector(this.getContext()
|
||||
, new OnScrollListener());
|
||||
}
|
||||
|
||||
public MangaViewPager(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
mGestureDetector = new GestureDetector(this.getContext()
|
||||
, new OnScrollListener());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
|
||||
if (v instanceof MangaImage) {
|
||||
return ((MangaImage) v).canScroll(dx);
|
||||
} else {
|
||||
return super.canScroll(v, checkV, dx, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
boolean re = super.onTouchEvent(event);
|
||||
mGestureDetector.onTouchEvent(event);
|
||||
return re;
|
||||
}
|
||||
|
||||
class OnScrollListener extends SimpleOnGestureListener {
|
||||
@Override
|
||||
public boolean onScroll(MotionEvent e1, MotionEvent e2,
|
||||
float distanceX, float distanceY) {
|
||||
MangaViewPager.this.distanceX = distanceX;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user