diff options
author | Koushik Dutta <koushd@gmail.com> | 2013-03-23 11:26:53 -0700 |
---|---|---|
committer | Koushik Dutta <koushd@gmail.com> | 2013-03-23 11:26:53 -0700 |
commit | a26eb862f12ea82d55fe9ca794366e57c0173aec (patch) | |
tree | d695705194f3f633d70a176a9c81fd5cc2337cde /AndroidAsyncSample | |
parent | a9f3cb26f3065b7c931857ad4a117face4e68ad1 (diff) | |
download | AndroidAsync-a26eb862f12ea82d55fe9ca794366e57c0173aec.tar.gz AndroidAsync-a26eb862f12ea82d55fe9ca794366e57c0173aec.tar.bz2 AndroidAsync-a26eb862f12ea82d55fe9ca794366e57c0173aec.zip |
rename refactor some classes. minor stats and fixes for cache code.
Diffstat (limited to 'AndroidAsyncSample')
-rw-r--r-- | AndroidAsyncSample/src/com/koushikdutta/async/sample/MainActivity.java | 58 |
1 files changed, 10 insertions, 48 deletions
diff --git a/AndroidAsyncSample/src/com/koushikdutta/async/sample/MainActivity.java b/AndroidAsyncSample/src/com/koushikdutta/async/sample/MainActivity.java index 4b2fe88..2f23cc4 100644 --- a/AndroidAsyncSample/src/com/koushikdutta/async/sample/MainActivity.java +++ b/AndroidAsyncSample/src/com/koushikdutta/async/sample/MainActivity.java @@ -46,50 +46,7 @@ public class MainActivity extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - new Thread() { - public void run() { - try { - HttpResponseCache cache; - try { - File httpCacheDir = new File(getCacheDir(), "http"); - long httpCacheSize = 10 * 1024 * 1024; // 10 MiB - cache = HttpResponseCache.install(httpCacheDir, httpCacheSize); - } - catch (IOException e) { - Log.i("cache", "HTTP response cache installation failed:" + e); - return; - } - URL url = new URL("https://desksms.appspot.com"); - URLConnection conn = url.openConnection(); - for (String header: conn.getRequestProperties().keySet()) { - System.out.println(header + ": "); - for (String value: conn.getRequestProperties().get(header)) { - System.out.println(value); - } - } - for (String header: conn.getHeaderFields().keySet()) { - System.out.println(header + ": " + conn.getHeaderField(header)); - } - InputStream in = conn.getInputStream(); - int count = 0; - while (in.read() != -1) { - count++; - } - in.close(); - System.out.println("count: " + count); - - System.out.println("cache count: " + cache.getHitCount()); - System.out.println("network count: " + cache.getNetworkCount()); - } - catch (Exception e) { - e.printStackTrace(); - } - }; - }.start(); - - if (cacher == null) { - try { cacher = ResponseCacheMiddleware.addCache(AsyncHttpClient.getDefaultInstance(), getFileStreamPath("asynccache"), 1024 * 1024 * 10); cacher.setCaching(false); @@ -142,7 +99,6 @@ public class MainActivity extends Activity { e.printStackTrace(); return; } - System.out.println(result.getAbsolutePath()); Bitmap bitmap = BitmapFactory.decodeFile(filename); result.delete(); if (bitmap == null) @@ -173,7 +129,6 @@ public class MainActivity extends Activity { e.printStackTrace(); return; } - System.out.println(result.getAbsolutePath()); Bitmap bitmap = BitmapFactory.decodeFile(filename); result.delete(); if (bitmap == null) @@ -199,8 +154,15 @@ public class MainActivity extends Activity { chart.setImageBitmap(null); getFile(rommanager, "https://raw.github.com/koush/AndroidAsync/master/rommanager.png", getFileStreamPath(randomFile()).getAbsolutePath()); -// getFile(tether, "https://raw.github.com/koush/AndroidAsync/master/tether.png", getFileStreamPath(randomFile()).getAbsolutePath()); -// getFile(desksms, "https://raw.github.com/koush/AndroidAsync/master/desksms.png", getFileStreamPath(randomFile()).getAbsolutePath()); -// getChartFile(); + getFile(tether, "https://raw.github.com/koush/AndroidAsync/master/tether.png", getFileStreamPath(randomFile()).getAbsolutePath()); + getFile(desksms, "https://raw.github.com/koush/AndroidAsync/master/desksms.png", getFileStreamPath(randomFile()).getAbsolutePath()); + getChartFile(); + + Log.i(LOGTAG, "cache hit: " + cacher.getCacheHitCount()); + Log.i(LOGTAG, "cache store: " + cacher.getCacheStoreCount()); + Log.i(LOGTAG, "conditional cache hit: " + cacher.getConditionalCacheHitCount()); + Log.i(LOGTAG, "network: " + cacher.getNetworkCount()); } + + private static final String LOGTAG = "AsyncSample"; } |