添加 charset 识别

This commit is contained in:
seven332 committed 2014-04-06 13:45:52 +08:00
1 parent be3d3189ec
commit def283de08
11 files changed
+208178 -5

No files matched your search

@@ -6,7 +6,9 @@ import android.graphics.Color;
import android.graphics.Movie;
import android.graphics.Rect;
import android.graphics.RectF;
import com.hippo.ehviewer.util.Log;
import android.view.MotionEvent;
import com.hippo.ehviewer.R;
@@ -293,8 +295,23 @@ public class GalleryView extends GLView {
// TODO Mask to reduce brightness
//canvas.fillRect(0, 0, mWidth, mHeight, MASK_COLOR);
if (hasMovie)
invalidate();
// TODO
if (hasMovie) {
Log.d(TAG, "hasMovie");
new Thread() {
@Override
public void run() {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
invalidate();
}
}
}.start();
}
}
private void resetSizePosition() {
+27 -2
View File
@@ -12,6 +12,8 @@ import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLEncoder;
import java.net.UnknownHostException;
import java.util.List;
import java.util.Map;
import java.util.zip.GZIPInputStream;
import org.apache.http.conn.ConnectTimeoutException;
@@ -27,6 +29,7 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.util.LruCache;
import com.hippo.ehviewer.util.Log;
/**
@@ -38,6 +41,9 @@ import com.hippo.ehviewer.util.Log;
public class HttpHelper {
private static final String TAG = "HttpHelper";
private static String DEFAULT_CHARSET = "utf-8";
private static String CHARSET_KEY = "charset=";
private Context mContext;
private Exception mException;
@@ -89,8 +95,27 @@ public class HttpHelper {
is = new GZIPInputStream(is);
baos = new ByteArrayOutputStream();
Util.copy(is, baos, Constant.BUFFER_SIZE);
// TODO charset
pageContext = baos.toString("utf-8");
// Get charset
String charset = null;
List<String> contentType = conn.getHeaderFields().get("Content-Type");
if (contentType != null) {
for (String item : contentType) {
if (item == null)
continue;
int index = -1;
if ((index = item.indexOf(CHARSET_KEY)) != -1) {
charset = item.substring(index + CHARSET_KEY.length());
break;
}
}
}
// Use default charset
if (charset == null) {
charset = DEFAULT_CHARSET;
}
pageContext = baos.toString(charset);
} catch (IOException e) {
throw e;
} finally {