Browse files

for sync, DO NOT BUILD.

  • Loading branch information...
1 parent bb2b251 commit 8bae77696e605393ef3d110c5e766fe99fe84f0d @mariotaku committed Nov 22, 2012
View
83 src/org/mariotaku/twidere/activity/ImageViewerActivity.java
@@ -20,10 +20,9 @@
package org.mariotaku.twidere.activity;
import static org.mariotaku.twidere.util.Utils.copyStream;
-import static org.mariotaku.twidere.util.Utils.getBrowserUserAgent;
import static org.mariotaku.twidere.util.Utils.getBestCacheDir;
-import static org.mariotaku.twidere.util.Utils.getHttpClient;
-import static org.mariotaku.twidere.util.Utils.getProxy;
+import static org.mariotaku.twidere.util.Utils.getImageLoaderHttpClient;
+import static org.mariotaku.twidere.util.Utils.getRedirectedHttpResponse;
import static org.mariotaku.twidere.util.Utils.isRedirected;
import static org.mariotaku.twidere.util.Utils.parseString;
import static org.mariotaku.twidere.util.Utils.showErrorToast;
@@ -37,13 +36,11 @@
import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.R;
-import org.mariotaku.twidere.app.TwidereApplication;
import org.mariotaku.twidere.util.BitmapDecodeHelper;
import org.mariotaku.twidere.util.GetExternalCacheDirAccessor;
import org.mariotaku.twidere.view.ImageViewer;
import twitter4j.TwitterException;
-import twitter4j.http.HostAddressResolver;
import twitter4j.http.HttpClientWrapper;
import twitter4j.http.HttpResponse;
import android.content.ActivityNotFoundException;
@@ -70,9 +67,6 @@
private ImageButton mRefreshStopSaveButton;
private boolean mImageLoaded;
private File mImageFile;
- private String mUserAgent;
-
- private HostAddressResolver mResolver;
@Override
public void onClick(final View view) {
@@ -140,7 +134,7 @@ public void onContentChanged() {
mProgress.setVisibility(View.VISIBLE);
mRefreshStopSaveButton.setImageResource(R.drawable.ic_menu_stop);
final Uri uri = args != null ? (Uri) args.getParcelable(INTENT_KEY_URI) : null;
- return new ImageLoader(this, mResolver, uri, mUserAgent);
+ return new ImageLoader(this, uri);
}
@Override
@@ -169,9 +163,7 @@ public void onLoadFinished(final Loader<ImageLoader.Result> loader, final ImageL
@Override
protected void onCreate(final Bundle icicle) {
- mResolver = TwidereApplication.getInstance(this).getHostAddressResolver();
super.onCreate(icicle);
- mUserAgent = getBrowserUserAgent(this);
setContentView(R.layout.image_viewer);
loadImage(true);
}
@@ -246,30 +238,27 @@ private void stopLoading() {
private static final String CACHE_DIR_NAME = "cached_images";
- private final Uri uri;
+ private final Uri mUri;
+ private final Context mContext;
+ private final HttpClientWrapper mClient;
- private final Context context;
- private final String user_agent;
- private final HostAddressResolver resolver;
private File mCacheDir;
- public ImageLoader(final Context context, final HostAddressResolver resolver, final Uri uri,
- final String user_agent) {
+ public ImageLoader(final Context context, final Uri uri) {
super(context);
- this.context = context;
- this.resolver = resolver;
- this.uri = uri;
- this.user_agent = user_agent;
+ this.mContext = context;
+ this.mUri = uri;
+ mClient = getImageLoaderHttpClient(context);
init();
}
@Override
public Result loadInBackground() {
- if (uri == null) return new Result(null, null, null);
- final String scheme = uri.getScheme();
+ if (mUri == null) return new Result(null, null, null);
+ final String scheme = mUri.getScheme();
if ("http".equals(scheme) || "https".equals(scheme)) {
- final String url = parseString(uri.toString());
+ final String url = parseString(mUri.toString());
if (url == null) return new Result(null, null, null);
if (mCacheDir == null || !mCacheDir.exists()) {
init();
@@ -279,39 +268,23 @@ public Result loadInBackground() {
// from SD cache
final Bitmap cached_bitmap = decodeFile(cache_file);
if (cached_bitmap != null) return new Result(cached_bitmap, cache_file, null);
-
- int response_code = -1;
// from web
try {
- Bitmap bitmap = null;
- final HttpClientWrapper client = getHttpClient(10000, true, getProxy(context), resolver, user_agent);
- int retry_count = 0;
- String request_url = url;
- HttpResponse resp = client.get(request_url, request_url);
+ final HttpResponse resp = getRedirectedHttpResponse(mClient, url);
if (resp == null) return null;
- while (resp != null && isRedirected(resp.getStatusCode())) {
- resp = client.get(request_url, request_url);
- if (resp == null) return null;
- request_url = resp.getResponseHeader("Location");
- if (request_url == null) return null;
- }
- if (resp != null && response_code == 200) {
- final InputStream is = resp.asStream();
- final OutputStream os = new FileOutputStream(cache_file);
- copyStream(is, os);
- os.close();
- bitmap = decodeFile(cache_file);
- if (bitmap == null) {
- // The file is corrupted, so we remove it from
- // cache.
- if (cache_file.isFile()) {
- cache_file.delete();
- }
- } else
- return new Result(bitmap, cache_file, null);
- } else {
- // TODO show error message.
+ final InputStream is = resp.asStream();
+ final OutputStream os = new FileOutputStream(cache_file);
+ copyStream(is, os);
+ os.close();
+ final Bitmap bitmap = decodeFile(cache_file);
+ if (bitmap == null) {
+ // The file is corrupted, so we remove it from
+ // cache.
+ if (cache_file.isFile()) {
+ cache_file.delete();
+ }
}
+ return new Result(bitmap, cache_file, null);
} catch (final FileNotFoundException e) {
init();
} catch (final IOException e) {
@@ -320,7 +293,7 @@ public Result loadInBackground() {
return new Result(null, null, e);
}
} else if ("file".equals(scheme)) {
- final File file = new File(uri.getPath());
+ final File file = new File(mUri.getPath());
return new Result(decodeFile(file), file, null);
}
return new Result(null, null, null);
@@ -360,7 +333,7 @@ private String getURLFilename(final String url) {
private void init() {
/* Find the dir to save cached images. */
- mCacheDir = getBestCacheDir(context, CACHE_DIR_NAME);
+ mCacheDir = getBestCacheDir(mContext, CACHE_DIR_NAME);
if (mCacheDir != null && !mCacheDir.exists()) {
mCacheDir.mkdirs();
}
View
2 src/org/mariotaku/twidere/activity/SignInActivity.java
@@ -508,7 +508,7 @@ public AbstractUserCredentialsLoader(final Context context, final Configuration
int analyseUserProfileColor(final User user) throws TwitterException {
final HttpClientWrapper client = new HttpClientWrapper(conf);
- final HttpResponse conn = client.get(user.getProfileImageURL().toString(), null);
+ final HttpResponse conn = client.get(user.getProfileImageUrlHttps().toString(), null);
final Bitmap bm = BitmapFactory.decodeStream(conn.asStream());
return ColorAnalyser.analyse(bm);
}
View
2 src/org/mariotaku/twidere/fragment/UserListDetailsFragment.java
@@ -153,7 +153,7 @@ public void changeUserList(final long account_id, final UserList user_list) {
linkify.setOnLinkClickListener(new OnLinkClickHandler(getActivity(), account_id));
linkify.addAllLinks();
mDescriptionView.setMovementMethod(LinkMovementMethod.getInstance());
- final String profile_image_url_string = parseString(user.getProfileImageURL());
+ final String profile_image_url_string = parseString(user.getProfileImageUrlHttps());
final boolean hires_profile_image = getResources().getBoolean(R.bool.hires_profile_image);
mProfileImageLoader.displayImage(
hires_profile_image ? getBiggerTwitterProfileImage(profile_image_url_string)
View
4 src/org/mariotaku/twidere/model/ParcelableDirectMessage.java
@@ -97,8 +97,8 @@ public ParcelableDirectMessage(final DirectMessage message, final long account_i
recipient_name = recipient != null ? recipient.getName() : null;
sender_screen_name = sender != null ? sender.getScreenName() : null;
recipient_screen_name = recipient != null ? recipient.getScreenName() : null;
- sender_profile_image_url_string = sender != null ? parseString(sender.getProfileImageURL()) : null;
- recipient_profile_image_url_string = recipient != null ? parseString(recipient.getProfileImageURL()) : null;
+ sender_profile_image_url_string = sender != null ? parseString(sender.getProfileImageUrlHttps()) : null;
+ recipient_profile_image_url_string = recipient != null ? parseString(recipient.getProfileImageUrlHttps()) : null;
}
public ParcelableDirectMessage(final Parcel in) {
View
2 src/org/mariotaku/twidere/model/ParcelableStatus.java
@@ -179,7 +179,7 @@ public ParcelableStatus(Status status, final long account_id, final boolean is_g
user_id = user != null ? user.getId() : -1;
name = user != null ? user.getName() : null;
screen_name = user != null ? user.getScreenName() : null;
- profile_image_url_string = user != null ? parseString(user.getProfileImageURL()) : null;
+ profile_image_url_string = user != null ? parseString(user.getProfileImageUrlHttps()) : null;
is_protected = user != null ? user.isProtected() : false;
is_verified = user != null ? user.isVerified() : false;
final MediaEntity[] medias = status.getMediaEntities();
View
2 src/org/mariotaku/twidere/model/ParcelableUser.java
@@ -95,7 +95,7 @@ public ParcelableUser(final User user, final long account_id, final long positio
screen_name = user.getScreenName();
description = user.getDescription();
location = user.getLocation();
- profile_image_url_string = parseString(user.getProfileImageURL());
+ profile_image_url_string = parseString(user.getProfileImageUrlHttps());
profile_banner_url_string = user.getProfileBannerImageUrl();
url_string = parseString(user.getURL());
is_follow_request_sent = user.isFollowRequestSent();
View
2 src/org/mariotaku/twidere/model/ParcelableUserList.java
@@ -85,7 +85,7 @@ public ParcelableUserList(final UserList list, final long account_id, final long
user_id = user.getId();
user_name = user.getName();
user_screen_name = user.getScreenName();
- user_profile_image_url_string = parseString(user.getProfileImageURL());
+ user_profile_image_url_string = parseString(user.getProfileImageUrlHttps());
}
@Override
View
28 src/org/mariotaku/twidere/util/ImageLoaderHttpClient.java
@@ -0,0 +1,28 @@
+package org.mariotaku.twidere.util;
+
+import android.content.Context;
+import twitter4j.http.HostAddressResolver;
+import org.mariotaku.twidere.app.TwidereApplication;
+import org.apache.http.HttpResponse;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.HostnameVerifier;
+
+public class ImageLoaderHttpClient {
+
+ private final HostAddressResolver mResolver;
+
+ public ImageLoaderHttpClient(final Context context) {
+ mResolver = TwidereApplication.getInstance(context).getHostAddressResolver();
+ }
+
+ public InputStream getAsStream(final String urlString) throws IOException {
+ final URL url = new URL(urlString);
+ final HttpsURLConnection conn = url.openConnection();
+ conn.setSSLSocketFactory();
+ }
+}
View
70 src/org/mariotaku/twidere/util/TrustAllSSLSocketFactory.java
@@ -0,0 +1,70 @@
+package org.mariotaku.twidere.util;
+
+import java.io.IOException;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.security.KeyManagementException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+
+
+public final class TrustAllSSLSocketFactory extends SSLSocketFactory {
+
+ final SSLContext sslContext;
+
+ TrustAllSSLSocketFactory() throws KeyManagementException, NoSuchAlgorithmException {
+ super();
+
+ final TrustManager tm = new X509TrustManager() {
+ @Override
+ public void checkClientTrusted(final X509Certificate[] chain, final String authType) {
+ }
+
+ @Override
+ public void checkServerTrusted(final X509Certificate[] chain, final String authType) {
+ }
+
+ @Override
+ public X509Certificate[] getAcceptedIssuers() {
+ return new X509Certificate[0];
+ }
+ };
+ sslContext = SSLContext.getInstance("TLS");
+ sslContext.init(null, new TrustManager[] { tm }, null);
+ }
+
+ @Override
+ public Socket createSocket() throws IOException {
+ return sslContext.getSocketFactory().createSocket();
+ }
+
+ @Override
+ public Socket createSocket(final Socket socket, final String host, final int port, final boolean autoClose)
+ throws IOException, UnknownHostException {
+ return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
+ }
+
+ public static SSLSocketFactory getInstance() {
+ try {
+ final KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
+ trustStore.load(null, null);
+ final SSLSocketFactory factory = new TrustAllSSLSocketFactory();
+ factory.setHostnameVerifier(ALLOW_ALL_HOSTNAME_VERIFIER);
+ return factory;
+ } catch (final KeyStoreException e) {
+ } catch (final KeyManagementException e) {
+ } catch (final NoSuchAlgorithmException e) {
+ } catch (final CertificateException e) {
+ } catch (final IOException e) {
+ }
+ return null;
+ }
+}
View
94 src/org/mariotaku/twidere/util/TwidereHostAddressResolver.java
@@ -29,6 +29,7 @@
import org.mariotaku.twidere.Constants;
import org.xbill.DNS.AAAARecord;
import org.xbill.DNS.ARecord;
+import org.xbill.DNS.CNAMERecord;
import org.xbill.DNS.DClass;
import org.xbill.DNS.Message;
import org.xbill.DNS.Name;
@@ -42,17 +43,21 @@
import android.content.Context;
import android.content.SharedPreferences;
import org.apache.http.conn.util.InetAddressUtils;
+import android.util.Log;
+import java.util.Arrays;
public class TwidereHostAddressResolver implements Constants, HostAddressResolver {
+ private static final String RESOLVER_LOGTAG = "TwidereHostAddressResolver";
+
private static final String DEFAULT_DNS_SERVER_ADDRESS = "8.8.8.8";
private final SharedPreferences mHostMapping, mPreferences;
- private final LinkedHashMap<String, String> mHostCache = new LinkedHashMap<String, String>(512, 0.75f, false);
+ private final HostCache mHostCache = new HostCache(512);
private final boolean mLocalMappingOnly;
private final String mDNSAddress;
- private Resolver mResolver;
+ private Resolver mDNS;
public TwidereHostAddressResolver(final Context context) {
this(context, false);
@@ -67,24 +72,36 @@ public TwidereHostAddressResolver(final Context context, final boolean local_onl
}
void init() throws UnknownHostException {
- mResolver = !mLocalMappingOnly ? new SimpleResolver(mDNSAddress) : null;
- if (mResolver != null) {
- mResolver.setTCP(true);
+ mDNS = !mLocalMappingOnly ? new SimpleResolver(mDNSAddress) : null;
+ if (mDNS != null) {
+ mDNS.setTCP(true);
}
}
static boolean isValidIpAddress(final String address) {
- return !isEmpty(address) || InetAddressUtils.isIPv4Address(address) || InetAddressUtils.isIPv6Address(address)
- || InetAddressUtils.isIPv6HexCompressedAddress(address) || InetAddressUtils.isIPv6StdAddress(address);
+ return !isEmpty(address);
}
@Override
public String resolve(final String host) throws IOException {
if (host == null) return null;
// First, I'll try to load address cached.
- if (mHostCache.containsKey(host)) return mHostCache.get(host);
+ if (mHostCache.containsKey(host)) {
+ if (DEBUG) {
+ Log.d(RESOLVER_LOGTAG, "Got cached address " + mHostCache.get(host) + " for host " + host);
+ }
+ return mHostCache.get(host);
+ }
// Then I'll try to load from custom host mapping.
// Stupid way to find top domain, but really fast.
+ if (mHostMapping.contains(host)) {
+ final String host_addr = mHostMapping.getString(host, null);
+ mHostCache.put(host, host_addr);
+ if (DEBUG) {
+ Log.d(RESOLVER_LOGTAG, "Got mapped address " + host_addr + " for host " + host);
+ }
+ return host_addr;
+ }
final String[] host_segments = host.split("\\.");
final int host_segments_length = host_segments.length;
if (host_segments_length > 2) {
@@ -93,23 +110,20 @@ public String resolve(final String host) throws IOException {
if (mHostMapping.contains(top_domain)) {
final String host_addr = mHostMapping.getString(top_domain, null);
mHostCache.put(top_domain, host_addr);
- return host_addr;
- }
- } else {
- if (mHostMapping.contains(host)) {
- final String host_addr = mHostMapping.getString(host, null);
- mHostCache.put(host, host_addr);
+ if (DEBUG) {
+ Log.d(RESOLVER_LOGTAG, "Got mapped address (top domain) " + host_addr + " for host " + host);
+ }
return host_addr;
}
}
if (!mLocalMappingOnly) {
init();
}
// Use TCP DNS Query if enabled.
- if (mResolver != null && mPreferences.getBoolean(PREFERENCE_KEY_TCP_DNS_QUERY, false)) {
+ if (mDNS != null && mPreferences.getBoolean(PREFERENCE_KEY_TCP_DNS_QUERY, false)) {
final Name name = new Name(host);
final Record query = Record.newRecord(name, Type.A, DClass.IN);
- final Message response = mResolver.send(Message.newQuery(query));
+ final Message response = mDNS.send(Message.newQuery(query));
final Record[] records = response.getSectionArray(Section.ANSWER);
if (records == null || records.length < 1) throw new IOException("Could not find " + host);
String host_addr = null;
@@ -119,34 +133,52 @@ public String resolve(final String host) throws IOException {
final InetAddress ipv4_addr = ((ARecord) record).getAddress();
if (ipv4_addr.isReachable(300)) {
host_addr = ipv4_addr.getHostAddress();
- mHostCache.put(host, host_addr);
- break;
}
} else if (record instanceof AAAARecord) {
final InetAddress ipv6_addr = ((AAAARecord) record).getAddress();
if (ipv6_addr.isReachable(300)) {
host_addr = ipv6_addr.getHostAddress();
- mHostCache.put(host, host_addr);
- break;
}
}
+ if (mHostCache.put(host, host_addr) != null) {
+ if (DEBUG) {
+ Log.d(RESOLVER_LOGTAG, "Resolved address " + host_addr + " for host " + host);
+ }
+ return host_addr;
+ }
}
// No address is reachable, but I believe the IP is correct.
- if (host_addr == null) {
- final Record record = records[0];
- if (record instanceof ARecord) {
- final InetAddress ipv4_addr = ((ARecord) record).getAddress();
- host_addr = ipv4_addr.getHostAddress();
- mHostCache.put(host, host_addr);
- } else if (record instanceof AAAARecord) {
- final InetAddress ipv6_addr = ((AAAARecord) record).getAddress();
- host_addr = ipv6_addr.getHostAddress();
- mHostCache.put(host, host_addr);
- }
+ final Record record = records[0];
+ if (record instanceof ARecord) {
+ final InetAddress ipv4_addr = ((ARecord) record).getAddress();
+ host_addr = ipv4_addr.getHostAddress();
+ } else if (record instanceof AAAARecord) {
+ final InetAddress ipv6_addr = ((AAAARecord) record).getAddress();
+ host_addr = ipv6_addr.getHostAddress();
+ } else if (record instanceof CNAMERecord) {
+ return resolve(((CNAMERecord) record).getTarget().toString());
+ }
+ mHostCache.put(host, host_addr);
+ if (DEBUG) {
+ Log.d(RESOLVER_LOGTAG, "Resolved address " + host_addr + " for host " + host);
}
return host_addr;
}
+ if (DEBUG) {
+ Log.w(RESOLVER_LOGTAG, "Resolve address " + host + " failed, using original host");
+ }
return host;
}
+ private static class HostCache extends LinkedHashMap<String, String> {
+
+ HostCache(final int initialCapacity) {
+ super(initialCapacity);
+ }
+
+ public String put(final String key, final String value) {
+ if (value == null) return value;
+ return super.put(key, value);
+ }
+ }
}
View
66 src/org/mariotaku/twidere/util/Utils.java
@@ -138,6 +138,7 @@
import twitter4j.conf.ConfigurationBuilder;
import twitter4j.http.HostAddressResolver;
import twitter4j.http.HttpClientWrapper;
+import twitter4j.http.HttpResponse;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentValues;
@@ -941,16 +942,6 @@ public static Twitter getDefaultTwitterInstance(final Context context, final boo
return getTwitterInstance(context, getDefaultAccountId(context), include_entities, use_httpclient);
}
- public static HttpClientWrapper getImageLoaderHttpClient(final Context context) {
- if (context == null) return null;
- final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME,
- Context.MODE_PRIVATE);
- final int timeout_millis = prefs.getInt(PREFERENCE_KEY_CONNECTION_TIMEOUT, 10000);
- final Proxy proxy = getProxy(context);
- final HostAddressResolver resolver = TwidereApplication.getInstance(context).getHostAddressResolver();
- return getHttpClient(timeout_millis, true, proxy, resolver, null);
- }
-
public static HttpClientWrapper getHttpClient(final int timeout_millis, final boolean ignore_ssl_error,
final Proxy proxy, final HostAddressResolver resolver, final String user_agent) {
final ConfigurationBuilder cb = new ConfigurationBuilder();
@@ -971,6 +962,18 @@ public static HttpClientWrapper getHttpClient(final int timeout_millis, final bo
return new HttpClientWrapper(cb.build());
}
+ public static HttpClientWrapper getImageLoaderHttpClient(final Context context) {
+ if (context == null) return null;
+ final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME,
+ Context.MODE_PRIVATE);
+ final int timeout_millis = prefs.getInt(PREFERENCE_KEY_CONNECTION_TIMEOUT, 10000) * 1000;
+ final Proxy proxy = getProxy(context);
+ final String user_agent = getBrowserUserAgent(context);
+ //final HostAddressResolver resolver = TwidereApplication.getInstance(context).getHostAddressResolver();
+ final HostAddressResolver resolver = null;
+ return getHttpClient(timeout_millis, true, proxy, resolver, user_agent);
+ }
+
public static String getImagePathFromUri(final Context context, final Uri uri) {
if (context == null || uri == null) return null;
@@ -1245,6 +1248,39 @@ public static String getQuoteStatus(final Context context, final String screen_n
return quote_format.replace(FORMAT_PATTERN_NAME, screen_name).replace(FORMAT_PATTERN_TEXT, text);
}
+ public static HttpResponse getRedirectedHttpResponse(final HttpClientWrapper client, final String url) throws TwitterException {
+ if (true) return client.get(url, url);
+ if (url == null) return null;
+ final ArrayList<String> urls = new ArrayList<String>();
+ urls.add(url);
+ HttpResponse resp;
+ try {
+ resp = client.get(url, url);
+ } catch (TwitterException te) {
+ if (isRedirected(te.getStatusCode())){
+ resp = te.getHttpResponse();
+ } else {
+ throw te;
+ }
+ }
+ while (resp != null && isRedirected(resp.getStatusCode())) {
+ final String request_url = resp.getResponseHeader("Location");
+ if (request_url == null) return null;
+ if (urls.contains(request_url)) throw new TwitterException("Too many redirects");
+ urls.add(request_url);
+ try {
+ resp = client.get(request_url, request_url);
+ } catch (TwitterException te) {
+ if (isRedirected(te.getStatusCode())){
+ resp = te.getHttpResponse();
+ } else {
+ throw te;
+ }
+ }
+ }
+ return resp;
+ }
+
public static String getShareStatus(final Context context, final String title, final String text) {
if (context == null) return null;
String share_format = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE).getString(
@@ -1685,7 +1721,7 @@ public static ContentValues makeAccountContentValues(final Configuration conf, f
values.put(Accounts.ACCOUNT_ID, user.getId());
values.put(Accounts.SCREEN_NAME, user.getScreenName());
values.put(Accounts.NAME, user.getName());
- values.put(Accounts.PROFILE_IMAGE_URL, user.getProfileImageURL().toString());
+ values.put(Accounts.PROFILE_IMAGE_URL, user.getProfileImageUrlHttps().toString());
values.put(Accounts.USER_COLOR, color);
values.put(Accounts.IS_ACTIVATED, 1);
values.put(Accounts.REST_BASE_URL, conf.getRestBaseURL());
@@ -1711,7 +1747,7 @@ public static ContentValues makeCachedUserContentValues(final User user) {
values.put(CachedUsers.USER_ID, user.getId());
values.put(CachedUsers.NAME, user.getName());
values.put(CachedUsers.SCREEN_NAME, user.getScreenName());
- values.put(CachedUsers.PROFILE_IMAGE_URL, user.getProfileImageURL().toString());
+ values.put(CachedUsers.PROFILE_IMAGE_URL, user.getProfileImageUrlHttps().toString());
return values;
}
@@ -1733,8 +1769,8 @@ public static ContentValues makeDirectMessageContentValues(final DirectMessage m
values.put(DirectMessages.SENDER_SCREEN_NAME, sender.getScreenName());
values.put(DirectMessages.RECIPIENT_NAME, recipient.getName());
values.put(DirectMessages.RECIPIENT_SCREEN_NAME, recipient.getScreenName());
- final URL sender_profile_image_url = sender.getProfileImageURL();
- final URL recipient_profile_image_url = recipient.getProfileImageURL();
+ final URL sender_profile_image_url = sender.getProfileImageUrlHttps();
+ final URL recipient_profile_image_url = recipient.getProfileImageUrlHttps();
if (sender_profile_image_url != null) {
values.put(DirectMessages.SENDER_PROFILE_IMAGE_URL, sender_profile_image_url.toString());
}
@@ -1762,7 +1798,7 @@ public static ContentValues makeStatusContentValues(Status status, final long ac
final User user = status.getUser();
if (user != null) {
final long user_id = user.getId();
- final String profile_image_url = user.getProfileImageURL().toString();
+ final String profile_image_url = user.getProfileImageUrlHttps().toString();
final String name = user.getName(), screen_name = user.getScreenName();
values.put(Statuses.USER_ID, user_id);
values.put(Statuses.NAME, name);
View
6 src/org/mariotaku/twidere/util/httpclient/HttpClientImpl.java
@@ -211,13 +211,11 @@ public void shutdown() {
final TrustManager tm = new X509TrustManager() {
@Override
- public void checkClientTrusted(final X509Certificate[] chain, final String authType)
- throws CertificateException {
+ public void checkClientTrusted(final X509Certificate[] chain, final String authType) {
}
@Override
- public void checkServerTrusted(final X509Certificate[] chain, final String authType)
- throws CertificateException {
+ public void checkServerTrusted(final X509Certificate[] chain, final String authType) {
}
@Override
View
14 src/org/mariotaku/twidere/util/imageloader/DiskLruCache.java
@@ -183,7 +183,13 @@ public Bitmap get(String key) {
if (BuildConfig.DEBUG) {
Log.d(TAG, "Disk cache hit");
}
- return BitmapFactory.decodeFile(file);
+ try {
+ final RandomAccessFile raf = new RandomAccessFile(file, "r");
+ return BitmapFactory.decodeFileDescriptor(raf.getFD());
+ } catch (IOException e) {
+ Log.e(TAG, "getBitmap - " + e);
+ }
+// return BitmapFactory.decodeFile(file);
} else {
final String existingFile = createFilePath(mCacheDir, key);
if (new File(existingFile).exists()) {
@@ -195,8 +201,9 @@ public Bitmap get(String key) {
final RandomAccessFile raf = new RandomAccessFile(existingFile, "r");
return BitmapFactory.decodeFileDescriptor(raf.getFD());
} catch (IOException e) {
- e.printStackTrace();
+ Log.e(TAG, "getBitmap - " + e);
}
+// return BitmapFactory.decodeFile(existingFile);
}
}
return null;
@@ -346,7 +353,8 @@ private boolean writeBitmapToFile(Bitmap bitmap, String file)
OutputStream out = null;
try {
final RandomAccessFile raf = new RandomAccessFile(file, "rw");
- out = new BufferedOutputStream(new FileOutputStream(raf.getFD()), ImageLoaderUtils.IO_BUFFER_SIZE);
+ out = new FileOutputStream(raf.getFD());
+ //out = new BufferedOutputStream(new FileOutputStream(file), ImageLoaderUtils.IO_BUFFER_SIZE);
return bitmap.compress(mCompressFormat, mCompressQuality, out);
} finally {
if (out != null) {
View
18 src/org/mariotaku/twidere/util/imageloader/ImageFetcher.java
@@ -18,6 +18,7 @@
import static org.mariotaku.twidere.util.Utils.copyStream;
import static org.mariotaku.twidere.util.Utils.getImageLoaderHttpClient;
+import static org.mariotaku.twidere.util.Utils.getRedirectedHttpResponse;
import static org.mariotaku.twidere.util.Utils.isRedirected;
import org.mariotaku.twidere.BuildConfig;
@@ -150,26 +151,19 @@ public File downloadBitmap(Context context, String urlString) {
}
//ImageLoaderUtils.disableConnectionReuseIfNecessary();
- BufferedOutputStream out = null;
+ FileOutputStream out = null;
try {
- String request_url = urlString;
- HttpResponse resp = mClient.get(request_url, request_url);
+ final HttpResponse resp = getRedirectedHttpResponse(mClient, urlString);
if (resp == null) return null;
- while (resp != null && isRedirected(resp.getStatusCode())) {
- resp = mClient.get(request_url, request_url);
- if (resp == null) return null;
- request_url = resp.getResponseHeader("Location");
- if (request_url == null) return null;
- }
- final InputStream in = new BufferedInputStream(resp.asStream(), ImageLoaderUtils.IO_BUFFER_SIZE);
- out = new BufferedOutputStream(new FileOutputStream(cacheFile), ImageLoaderUtils.IO_BUFFER_SIZE);
+ final InputStream in = resp.asStream();
+ out = new FileOutputStream(cacheFile);
copyStream(in, out);
return cacheFile;
} catch (final IOException e) {
Log.e(TAG, "Error in downloadBitmap - " + e);
} catch (final TwitterException e) {
-
+ Log.e(TAG, "Error in downloadBitmap - " + e.getMessage());
} finally {
if (out != null) {
try {
View
1 src/org/mariotaku/twidere/util/imageloader/ImageLoaderUtils.java
@@ -30,7 +30,6 @@
* Class containing some static utility methods.
*/
public class ImageLoaderUtils {
- public static final int IO_BUFFER_SIZE = 8 * 1024;
private ImageLoaderUtils() {};
View
4 src/org/mariotaku/twidere/util/imageloader/ImageWorker.java
@@ -380,10 +380,6 @@ private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
new ColorDrawable(Color.TRANSPARENT),
new BitmapDrawable(mContext.getResources(), bitmap)
});
- // Set background to loading bitmap
- //imageView.setBackgroundDrawable(
- // new BitmapDrawable(mContext.getResources(), mLoadingBitmap));
-
imageView.setImageDrawable(td);
td.startTransition(FADE_IN_TIME);
} else {

0 comments on commit 8bae776

Please sign in to comment.