はてなハイク・キーワードの検索と入力アプリ
リビジョン | bf1e92d00190bb51818f93cf9ec80873b1949417 (tree) |
---|---|
日時 | 2012-10-29 20:33:25 |
作者 | Kodakana <kodakana@linu...> |
コミッター | Kodakana |
Dialog を DialogFragment に変更。起動時の接続確認を改善。
@@ -1,7 +1,7 @@ | ||
1 | 1 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
2 | 2 | package="org.pulpdust.kigo" |
3 | - android:versionCode="3" | |
4 | - android:versionName="0.51" | |
3 | + android:versionCode="4" | |
4 | + android:versionName="0.55" | |
5 | 5 | android:installLocation="auto" > |
6 | 6 | |
7 | 7 | <uses-sdk |
@@ -1,7 +1,7 @@ | ||
1 | 1 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
2 | 2 | package="org.pulpdust.kigo" |
3 | - android:versionCode="3" | |
4 | - android:versionName="0.51" | |
3 | + android:versionCode="4" | |
4 | + android:versionName="0.55" | |
5 | 5 | android:installLocation="auto" > |
6 | 6 | |
7 | 7 | <uses-sdk |
@@ -1,7 +1,7 @@ | ||
1 | 1 | <resources> |
2 | 2 | |
3 | 3 | <string name="app_name">Kigo</string> |
4 | - <string name="app_ver">0.51</string> | |
4 | + <string name="app_ver">0.55</string> | |
5 | 5 | <string name="app_lic">GNU GPL v3</string> |
6 | 6 | <string name="address">連絡先</string> |
7 | 7 | <string name="app_author">Kodakana<kodakana.hws@gmail.com></string> |
@@ -1,7 +1,7 @@ | ||
1 | 1 | <resources> |
2 | 2 | |
3 | 3 | <string name="app_name">Kigo</string> |
4 | - <string name="app_ver">0.51</string> | |
4 | + <string name="app_ver">0.55</string> | |
5 | 5 | <string name="app_lic">GNU GPL v3</string> |
6 | 6 | <string name="address">Address</string> |
7 | 7 | <string name="app_author">Kodakana<kodakana.hws@gmail.com></string> |
@@ -25,10 +25,13 @@ import android.os.Handler; | ||
25 | 25 | import android.preference.PreferenceManager; |
26 | 26 | import android.app.Activity; |
27 | 27 | import android.app.AlertDialog; |
28 | +import android.app.Dialog; | |
28 | 29 | import android.app.ProgressDialog; |
29 | 30 | import android.content.Context; |
30 | 31 | import android.content.Intent; |
31 | 32 | import android.content.SharedPreferences; |
33 | +import android.support.v4.app.DialogFragment; | |
34 | +import android.support.v4.app.FragmentActivity; | |
32 | 35 | import android.text.ClipboardManager; |
33 | 36 | import android.util.Log; |
34 | 37 | import android.util.Xml; |
@@ -56,23 +59,23 @@ import android.view.inputmethod.EditorInfo; | ||
56 | 59 | import android.widget.AdapterView.OnItemClickListener; |
57 | 60 | import android.widget.AdapterView.OnItemLongClickListener; |
58 | 61 | |
59 | -public class KigoActivity extends Activity { | |
62 | +public class KigoActivity extends FragmentActivity { | |
60 | 63 | static final String TAG = "KigoActivity"; |
61 | 64 | static List<String> lst = new ArrayList<String>(); |
62 | 65 | static ArrayAdapter<String> arryadpt; |
63 | 66 | EditText edttxt; |
64 | 67 | Button bttn; |
65 | 68 | ListView lstvw; |
66 | - HttpResponse res = null; | |
69 | + static HttpResponse res = null; | |
67 | 70 | CharSequence cptxt; |
68 | - String host = "http://h.hatena.ne.jp/"; | |
71 | + static String host = "http://h.hatena.ne.jp/"; | |
69 | 72 | String base = host + "keyword/"; |
70 | 73 | String kpth = "keyword/"; |
71 | 74 | String uri = host + |
72 | 75 | "api/keywords/list.xml?without_related_keywords=true"; |
73 | 76 | String lpth = "api/keywords/list.xml?without_related_keywords=true"; |
74 | 77 | String iuri = host + "api/keywords/show.xml?word="; |
75 | - String ipth = "api/keywords/show.xml?word="; | |
78 | + static String ipth = "api/keywords/show.xml?word="; | |
76 | 79 | String guri; |
77 | 80 | String sbj = ""; |
78 | 81 | String obj; |
@@ -191,7 +194,8 @@ public class KigoActivity extends Activity { | ||
191 | 194 | } |
192 | 195 | }; |
193 | 196 | lstvw.setAdapter(arryadpt); |
194 | - final String save[] = (String[]) getLastNonConfigurationInstance(); | |
197 | +// final String save[] = (String[]) getLastNonConfigurationInstance(); | |
198 | + final String save[] = (String[]) getLastCustomNonConfigurationInstance(); | |
195 | 199 | if (save != null){ |
196 | 200 | if (save[0] != null){ |
197 | 201 | obj = save[0]; |
@@ -200,7 +204,8 @@ public class KigoActivity extends Activity { | ||
200 | 204 | } |
201 | 205 | if (save[1] != null){ buri = save[1]; } |
202 | 206 | if (save[2] != null){ bwrd = save[2]; } |
203 | - } else { | |
207 | + } else if (isConnect(this)){ | |
208 | + { | |
204 | 209 | if (rltd == true){ |
205 | 210 | guri = host + ipth + sbj; |
206 | 211 | reLoad(guri); |
@@ -209,6 +214,10 @@ public class KigoActivity extends Activity { | ||
209 | 214 | goFind(); |
210 | 215 | } |
211 | 216 | } |
217 | + } else { | |
218 | + Toast.makeText(this, R.string.err_no_net, | |
219 | + Toast.LENGTH_SHORT).show(); | |
220 | + } | |
212 | 221 | } |
213 | 222 | public void goFind(){ |
214 | 223 | sbj = edttxt.getText().toString().trim(); |
@@ -275,7 +284,9 @@ public class KigoActivity extends Activity { | ||
275 | 284 | doOpen(cptxt); |
276 | 285 | return true; |
277 | 286 | case R.id.menu_info: |
278 | - echoInfo(cptxt.toString()); | |
287 | + DialogFragment id = InfoDialog.newInstance(this, cptxt.toString()); | |
288 | + id.show(getSupportFragmentManager(), "hoge"); | |
289 | +// echoInfo(cptxt.toString()); | |
279 | 290 | return true; |
280 | 291 | case R.id.menu_relat: |
281 | 292 | // Intent intent = new Intent(gactn2); |
@@ -312,18 +323,34 @@ public class KigoActivity extends Activity { | ||
312 | 323 | return false; |
313 | 324 | } |
314 | 325 | } |
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(){ | |
326 | + public static class InfoDialog extends DialogFragment{ | |
327 | + static Context cx; | |
328 | + public static InfoDialog newInstance(Context c, String w){ | |
329 | + InfoDialog id = new InfoDialog(); | |
330 | + cx = c; | |
331 | + Bundle args = new Bundle(); | |
332 | + args.putString("word", w); | |
333 | + id.setArguments(args); | |
334 | + return id; | |
335 | + } | |
336 | + @Override | |
337 | + public Dialog onCreateDialog(Bundle savedInstanceState){ | |
338 | + return echoInfo(cx, getActivity(), getArguments().getString("word")); | |
339 | + } | |
340 | + } | |
341 | + public static AlertDialog echoInfo(Context context, FragmentActivity av, String word){ | |
342 | +// final Handler handler = new Handler(); | |
343 | + AlertDialog ad = null; | |
344 | +// final Context context = this; | |
345 | +// new Thread(new Runnable(){ | |
346 | +// @Override | |
347 | +// public void run(){ | |
321 | 348 | 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(){ | |
349 | + String turi = host + ipth + URLEncoder.encode(word, "UTF-8").replace("+", "%20"); | |
350 | + final String xml = getHttp(context, turi); | |
351 | +// handler.post(new Runnable(){ | |
352 | +// @Override | |
353 | +// public void run(){ | |
327 | 354 | if (xml != null){ |
328 | 355 | String info[] = exInfo(xml); |
329 | 356 | if(info != null){ |
@@ -331,37 +358,56 @@ public class KigoActivity extends Activity { | ||
331 | 358 | LayoutInflater linflater = |
332 | 359 | (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE); |
333 | 360 | View layout = linflater.inflate(R.layout.info, |
334 | - (ViewGroup) findViewById(R.id.layout_root)); | |
361 | + (ViewGroup) av.findViewById(R.id.layout_root)); | |
335 | 362 | TextView tv1 = (TextView) layout.findViewById(R.id.textView1); |
336 | 363 | TextView tv2 = (TextView) layout.findViewById(R.id.textView2); |
337 | 364 | TextView tv3 = (TextView) layout.findViewById(R.id.textView3); |
338 | 365 | // 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]); | |
366 | + tv1.setText(av.getString(R.string.info_entries) + info[0]); | |
367 | + tv2.setText(av.getString(R.string.info_follows) + info[1]); | |
368 | + tv3.setText(av.getString(R.string.info_title) + info[2]); | |
342 | 369 | // tv4.setText(getString(R.string.info_word) + info[3]); |
343 | 370 | abuilder.setTitle(word); |
344 | 371 | abuilder.setCancelable(true); |
345 | 372 | abuilder.setView(layout); |
346 | - abuilder.show(); | |
373 | + ad = abuilder.create(); | |
347 | 374 | } |
348 | 375 | } else { |
349 | - Toast.makeText(getApplicationContext(), R.string.err_fail_get, | |
350 | - Toast.LENGTH_SHORT).show(); | |
376 | + AlertDialog.Builder empty = new AlertDialog.Builder(context); | |
377 | + LayoutInflater linflater = | |
378 | + (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE); | |
379 | + View layout = linflater.inflate(R.layout.info, | |
380 | + (ViewGroup) av.findViewById(R.id.layout_root)); | |
381 | + TextView tv1 = (TextView) layout.findViewById(R.id.textView1); | |
382 | + tv1.setText(R.string.err_fail_get); | |
383 | + empty.setTitle(word); | |
384 | + empty.setCancelable(true); | |
385 | + empty.setView(layout); | |
386 | + ad = empty.create(); | |
387 | +// Toast.makeText(context, R.string.err_fail_get, | |
388 | +// Toast.LENGTH_SHORT).show(); | |
351 | 389 | } |
352 | - } | |
353 | - }); | |
390 | +// } | |
391 | +// }); | |
354 | 392 | |
355 | 393 | } catch (UnsupportedEncodingException e) { |
356 | 394 | // TODO Auto-generated catch block |
357 | 395 | e.printStackTrace(); |
358 | 396 | } |
359 | - } | |
360 | - }).start(); | |
397 | + return ad; | |
398 | +// } | |
399 | +// }).start(); | |
361 | 400 | } |
362 | 401 | |
363 | - @Override | |
364 | - public Object onRetainNonConfigurationInstance(){ | |
402 | +// @Override | |
403 | +// public Object onRetainNonConfigurationInstance(){ | |
404 | +// final String save[] = new String[3]; | |
405 | +// save[0] = obj; | |
406 | +// save[1] = buri; | |
407 | +// save[2] = bwrd; | |
408 | +// return save; | |
409 | +// } | |
410 | + public Object onRetainCustomNonConfiguratonInstance(){ | |
365 | 411 | final String save[] = new String[3]; |
366 | 412 | save[0] = obj; |
367 | 413 | save[1] = buri; |
@@ -401,12 +447,13 @@ public class KigoActivity extends Activity { | ||
401 | 447 | public void reLoad(final String uri){ |
402 | 448 | // final Getter getter = new Getter(); |
403 | 449 | final Handler handler = new Handler(); |
450 | + final Context c = getApplicationContext(); | |
404 | 451 | new Thread(new Runnable(){ |
405 | 452 | @Override |
406 | 453 | public void run(){ |
407 | 454 | obj = null; |
408 | 455 | // obj = getter.getHttp(uri); |
409 | - obj = getHttp(uri); | |
456 | + obj = getHttp(c, uri); | |
410 | 457 | handler.post(new Runnable(){ |
411 | 458 | @Override |
412 | 459 | public void run(){ |
@@ -433,9 +480,9 @@ public class KigoActivity extends Activity { | ||
433 | 480 | } |
434 | 481 | return false; |
435 | 482 | } |
436 | - public String getHttp(final String uri){ | |
437 | - if (!isConnect(getApplicationContext())){ | |
438 | - Toast.makeText(getApplicationContext(), R.string.err_no_net, | |
483 | + public static String getHttp(Context context, final String uri){ | |
484 | + if (!isConnect(context)){ | |
485 | + Toast.makeText(context, R.string.err_no_net, | |
439 | 486 | Toast.LENGTH_SHORT).show(); |
440 | 487 | return null; |
441 | 488 | } else { |
@@ -485,7 +532,7 @@ public class KigoActivity extends Activity { | ||
485 | 532 | Log.e(TAG, e.getMessage()); |
486 | 533 | } |
487 | 534 | } |
488 | - public String[] exInfo(String xml){ | |
535 | + public static String[] exInfo(String xml){ | |
489 | 536 | try { |
490 | 537 | String ret[] = new String[4]; |
491 | 538 | XmlPullParser xparser = Xml.newPullParser(); |