はてなハイク・キーワードの検索と入力アプリ
Revision | ffd83955cf64b0fd61952f169678ec05d22f644d (tree) |
---|---|
Zeit | 2012-10-09 20:07:43 |
Autor | Kodakana <kodakana@linu...> |
Commiter | Kodakana |
targetSdkVersion を14に変更。Honeycomb で Holo、ICS 以降で DeviceDefault テーマが使用されるように指定。Http Get 処理をスレッド化。
@@ -1,18 +1,19 @@ | ||
1 | 1 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
2 | 2 | package="org.pulpdust.kigo" |
3 | - android:versionCode="1" | |
4 | - android:versionName="0.4" | |
3 | + android:versionCode="2" | |
4 | + android:versionName="0.5" | |
5 | 5 | android:installLocation="auto" > |
6 | 6 | |
7 | 7 | <uses-sdk |
8 | 8 | android:minSdkVersion="4" |
9 | - android:targetSdkVersion="8" /> | |
9 | + android:targetSdkVersion="14" /> | |
10 | 10 | <uses-permission android:name="android.permission.INTERNET"/> |
11 | 11 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> |
12 | 12 | |
13 | 13 | <application |
14 | 14 | android:icon="@drawable/ic_launcher" |
15 | - android:label="@string/app_name"> | |
15 | + android:label="@string/app_name" | |
16 | + android:theme="@style/AppTheme"> | |
16 | 17 | <activity |
17 | 18 | android:name=".KigoActivity" |
18 | 19 | android:label="@string/title_activity_kigo" |
@@ -1,18 +1,19 @@ | ||
1 | 1 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
2 | 2 | package="org.pulpdust.kigo" |
3 | - android:versionCode="1" | |
4 | - android:versionName="0.4" | |
3 | + android:versionCode="2" | |
4 | + android:versionName="0.5" | |
5 | 5 | android:installLocation="auto" > |
6 | 6 | |
7 | 7 | <uses-sdk |
8 | 8 | android:minSdkVersion="4" |
9 | - android:targetSdkVersion="8" /> | |
9 | + android:targetSdkVersion="14" /> | |
10 | 10 | <uses-permission android:name="android.permission.INTERNET"/> |
11 | 11 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> |
12 | 12 | |
13 | 13 | <application |
14 | 14 | android:icon="@drawable/ic_launcher" |
15 | - android:label="@string/app_name"> | |
15 | + android:label="@string/app_name" | |
16 | + android:theme="@style/AppTheme"> | |
16 | 17 | <activity |
17 | 18 | android:name=".KigoActivity" |
18 | 19 | android:label="@string/title_activity_kigo" |
@@ -0,0 +1,3 @@ | ||
1 | +# cache for current jar dependecy. DO NOT EDIT. | |
2 | +# format is <lastModified> <length> <SHA-1> <path> | |
3 | +# Encoding is UTF-8 |
@@ -11,4 +11,4 @@ | ||
11 | 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt |
12 | 12 | |
13 | 13 | # Project target. |
14 | -target=android-8 | |
14 | +target=android-14 |
@@ -0,0 +1,3 @@ | ||
1 | +[Dolphin] | |
2 | +Timestamp=2012,10,5,23,54,32 | |
3 | +ViewMode=1 |
@@ -0,0 +1,4 @@ | ||
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<resources> | |
3 | + <style name="AppTheme" parent="@android:style/Theme.Holo" /> | |
4 | +</resources> | |
\ No newline at end of file |
@@ -0,0 +1,4 @@ | ||
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<resources> | |
3 | + <style name="AppTheme" parent="@android:style/Theme.DeviceDefault" /> | |
4 | +</resources> | |
\ No newline at end of file |
@@ -1,5 +1,5 @@ | ||
1 | 1 | <resources> |
2 | 2 | |
3 | - <style name="AppTheme" parent="android:Theme.Light" /> | |
3 | + <style name="AppTheme" parent="android:Theme" /> | |
4 | 4 | |
5 | 5 | </resources> |
\ No newline at end of file |
@@ -1,14 +1,17 @@ | ||
1 | 1 | package org.pulpdust.kigo; |
2 | 2 | |
3 | 3 | import java.io.ByteArrayOutputStream; |
4 | +import java.io.IOException; | |
4 | 5 | import java.io.StringReader; |
5 | 6 | import java.io.UnsupportedEncodingException; |
6 | 7 | import java.util.ArrayList; |
7 | 8 | import java.util.List; |
8 | 9 | import java.net.URLEncoder; |
10 | +import java.lang.Thread; | |
9 | 11 | |
10 | 12 | import org.apache.http.HttpResponse; |
11 | 13 | import org.apache.http.HttpStatus; |
14 | +import org.apache.http.client.ClientProtocolException; | |
12 | 15 | import org.apache.http.client.HttpClient; |
13 | 16 | import org.apache.http.client.methods.HttpGet; |
14 | 17 | import org.apache.http.impl.client.DefaultHttpClient; |
@@ -18,6 +21,7 @@ import android.net.ConnectivityManager; | ||
18 | 21 | import android.net.NetworkInfo; |
19 | 22 | import android.net.Uri; |
20 | 23 | import android.os.Bundle; |
24 | +import android.os.Handler; | |
21 | 25 | import android.preference.PreferenceManager; |
22 | 26 | import android.app.Activity; |
23 | 27 | import android.app.AlertDialog; |
@@ -59,7 +63,7 @@ public class KigoActivity extends Activity { | ||
59 | 63 | EditText edttxt; |
60 | 64 | Button bttn; |
61 | 65 | ListView lstvw; |
62 | - HttpResponse res; | |
66 | + HttpResponse res = null; | |
63 | 67 | CharSequence cptxt; |
64 | 68 | String host = "http://h.hatena.ne.jp/"; |
65 | 69 | String base = host + "keyword/"; |
@@ -104,7 +108,7 @@ public class KigoActivity extends Activity { | ||
104 | 108 | loadSave(); |
105 | 109 | } |
106 | 110 | readPrefs(); |
107 | - requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); | |
111 | +// requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); | |
108 | 112 | setContentView(R.layout.activity_kigo); |
109 | 113 | edttxt = (EditText) findViewById(R.id.editText1); |
110 | 114 | if (rltd == true){ |
@@ -308,41 +312,52 @@ public class KigoActivity extends Activity { | ||
308 | 312 | return false; |
309 | 313 | } |
310 | 314 | } |
311 | - public void echoInfo(String word){ | |
312 | - try { | |
313 | - String turi = host + ipth + URLEncoder.encode(word.toString(), "UTF-8").replace("+", "%20"); | |
314 | - String xml = getHttp(turi); | |
315 | - if (xml != null){ | |
316 | - String info[] = exInfo(xml); | |
317 | - if(info != null){ | |
318 | - Context context = this; | |
319 | - AlertDialog.Builder abuilder = new AlertDialog.Builder(context); | |
320 | - LayoutInflater linflater = | |
321 | - (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE); | |
322 | - View layout = linflater.inflate(R.layout.info, | |
323 | - (ViewGroup) findViewById(R.id.layout_root)); | |
324 | - TextView tv1 = (TextView) layout.findViewById(R.id.textView1); | |
325 | - TextView tv2 = (TextView) layout.findViewById(R.id.textView2); | |
326 | - TextView tv3 = (TextView) layout.findViewById(R.id.textView3); | |
327 | -// TextView tv4 = (TextView) layout.findViewById(R.id.textView4); | |
328 | - tv1.setText(getString(R.string.info_entries) + info[0]); | |
329 | - tv2.setText(getString(R.string.info_follows) + info[1]); | |
330 | - tv3.setText(getString(R.string.info_title) + info[2]); | |
331 | -// tv4.setText(getString(R.string.info_word) + info[3]); | |
332 | - abuilder.setTitle(word); | |
333 | - abuilder.setCancelable(true); | |
334 | - abuilder.setView(layout); | |
335 | - abuilder.show(); | |
336 | - } | |
337 | - } else { | |
338 | - Toast.makeText(getApplicationContext(), R.string.err_fail_get, | |
339 | - Toast.LENGTH_SHORT).show(); | |
340 | - } | |
341 | - | |
342 | - } catch (UnsupportedEncodingException e) { | |
343 | - // TODO Auto-generated catch block | |
344 | - e.printStackTrace(); | |
345 | - } | |
315 | + public void echoInfo(final String word){ | |
316 | + final Handler handler = new Handler(); | |
317 | + final Context context = this; | |
318 | + new Thread(new Runnable(){ | |
319 | + @Override | |
320 | + public void run(){ | |
321 | + try { | |
322 | + String turi = host + ipth + URLEncoder.encode(word.toString(), "UTF-8").replace("+", "%20"); | |
323 | + final String xml = getHttp(turi); | |
324 | + handler.post(new Runnable(){ | |
325 | + @Override | |
326 | + public void run(){ | |
327 | + if (xml != null){ | |
328 | + String info[] = exInfo(xml); | |
329 | + if(info != null){ | |
330 | + AlertDialog.Builder abuilder = new AlertDialog.Builder(context); | |
331 | + LayoutInflater linflater = | |
332 | + (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE); | |
333 | + View layout = linflater.inflate(R.layout.info, | |
334 | + (ViewGroup) findViewById(R.id.layout_root)); | |
335 | + TextView tv1 = (TextView) layout.findViewById(R.id.textView1); | |
336 | + TextView tv2 = (TextView) layout.findViewById(R.id.textView2); | |
337 | + TextView tv3 = (TextView) layout.findViewById(R.id.textView3); | |
338 | +// TextView tv4 = (TextView) layout.findViewById(R.id.textView4); | |
339 | + tv1.setText(getString(R.string.info_entries) + info[0]); | |
340 | + tv2.setText(getString(R.string.info_follows) + info[1]); | |
341 | + tv3.setText(getString(R.string.info_title) + info[2]); | |
342 | +// tv4.setText(getString(R.string.info_word) + info[3]); | |
343 | + abuilder.setTitle(word); | |
344 | + abuilder.setCancelable(true); | |
345 | + abuilder.setView(layout); | |
346 | + abuilder.show(); | |
347 | + } | |
348 | + } else { | |
349 | + Toast.makeText(getApplicationContext(), R.string.err_fail_get, | |
350 | + Toast.LENGTH_SHORT).show(); | |
351 | + } | |
352 | + } | |
353 | + }); | |
354 | + | |
355 | + } catch (UnsupportedEncodingException e) { | |
356 | + // TODO Auto-generated catch block | |
357 | + e.printStackTrace(); | |
358 | + } | |
359 | + } | |
360 | + }).start(); | |
346 | 361 | } |
347 | 362 | |
348 | 363 | @Override |
@@ -383,19 +398,31 @@ public class KigoActivity extends Activity { | ||
383 | 398 | return super.dispatchKeyEvent(kev); |
384 | 399 | } |
385 | 400 | } |
386 | - public void reLoad(String uri){ | |
387 | - ProgressDialog pdialog = ProgressDialog.show(this, "", | |
388 | - getString(R.string.on_load), true); | |
389 | - arryadpt.clear(); | |
390 | - obj = null; | |
391 | - obj = getHttp(uri); | |
392 | - if (obj != null){ | |
393 | - xmlBaker(obj); | |
394 | - } else { | |
395 | - Toast.makeText(getApplicationContext(), R.string.err_fail_get, | |
396 | - Toast.LENGTH_SHORT).show(); | |
397 | - } | |
398 | - pdialog.dismiss(); | |
401 | + public void reLoad(final String uri){ | |
402 | +// final Getter getter = new Getter(); | |
403 | + final Handler handler = new Handler(); | |
404 | + new Thread(new Runnable(){ | |
405 | + @Override | |
406 | + public void run(){ | |
407 | + obj = null; | |
408 | +// obj = getter.getHttp(uri); | |
409 | + obj = getHttp(uri); | |
410 | + handler.post(new Runnable(){ | |
411 | + @Override | |
412 | + public void run(){ | |
413 | + arryadpt.clear(); | |
414 | + if (obj != null){ | |
415 | + xmlBaker(obj); | |
416 | + } else { | |
417 | + Toast.makeText(getApplicationContext(), R.string.err_fail_get, | |
418 | + Toast.LENGTH_SHORT).show(); | |
419 | + } | |
420 | + | |
421 | + } | |
422 | + }); | |
423 | + | |
424 | + } | |
425 | + }).start(); | |
399 | 426 | } |
400 | 427 | public static boolean isConnect(Context c){ |
401 | 428 | ConnectivityManager cmanager = (ConnectivityManager) |
@@ -406,16 +433,22 @@ public class KigoActivity extends Activity { | ||
406 | 433 | } |
407 | 434 | return false; |
408 | 435 | } |
409 | - public String getHttp(String uri){ | |
436 | + public String getHttp(final String uri){ | |
410 | 437 | if (!isConnect(getApplicationContext())){ |
411 | 438 | Toast.makeText(getApplicationContext(), R.string.err_no_net, |
412 | 439 | Toast.LENGTH_SHORT).show(); |
413 | 440 | return null; |
414 | 441 | } else { |
415 | - HttpClient client = new DefaultHttpClient(); | |
416 | - HttpGet req = new HttpGet(uri.toString()); | |
417 | 442 | try { |
418 | - res = client.execute(req); | |
443 | + HttpClient client = new DefaultHttpClient(); | |
444 | + HttpGet req = new HttpGet(uri.toString()); | |
445 | + res = client.execute(req); | |
446 | + } catch (ClientProtocolException e){ | |
447 | + Log.e(TAG, e.getMessage()); | |
448 | + return null; | |
449 | + } catch (IOException e){ | |
450 | + Log.e(TAG, e.getMessage()); | |
451 | + return null; | |
419 | 452 | } catch (Exception e){ |
420 | 453 | Log.e(TAG, e.getMessage()); |
421 | 454 | return null; |