はてなハイク・キーワードの検索と入力アプリ
リビジョン | b076b7fb5d7c844ff47ee128988e28da2af16731 (tree) |
---|---|
日時 | 2012-09-05 20:45:35 |
作者 | Kodakana <kodakana@linu...> |
コミッター | Kodakana |
コンテキストメニュー及びそこから実行される各機能を追加。項目をタップしたときの動作をコピー/送信から選択できるようにした。送信用テンプレートの設定を追加。
@@ -1,7 +1,7 @@ | ||
1 | 1 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
2 | 2 | package="org.pulpdust.kigo" |
3 | 3 | android:versionCode="1" |
4 | - android:versionName="0.1" | |
4 | + android:versionName="0.2" | |
5 | 5 | android:installLocation="auto" > |
6 | 6 | |
7 | 7 | <uses-sdk |
@@ -26,6 +26,10 @@ | ||
26 | 26 | <action android:name="org.pulpdust.kigo.action.PICK_KEYWORD" /> |
27 | 27 | <category android:name="android.intent.category.DEFAULT" /> |
28 | 28 | </intent-filter> |
29 | + <intent-filter> | |
30 | + <action android:name="org.pulpdust.kigo.action.PICK_RELATED" /> | |
31 | + <category android:name="android.intent.category.DEFAULT" /> | |
32 | + </intent-filter> | |
29 | 33 | </activity> |
30 | 34 | <activity android:name=".KigoPrefs"></activity> |
31 | 35 | </application> |
@@ -1,7 +1,7 @@ | ||
1 | 1 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
2 | 2 | package="org.pulpdust.kigo" |
3 | 3 | android:versionCode="1" |
4 | - android:versionName="0.1" | |
4 | + android:versionName="0.2" | |
5 | 5 | android:installLocation="auto" > |
6 | 6 | |
7 | 7 | <uses-sdk |
@@ -26,6 +26,10 @@ | ||
26 | 26 | <action android:name="org.pulpdust.kigo.action.PICK_KEYWORD" /> |
27 | 27 | <category android:name="android.intent.category.DEFAULT" /> |
28 | 28 | </intent-filter> |
29 | + <intent-filter> | |
30 | + <action android:name="org.pulpdust.kigo.action.PICK_RELATED" /> | |
31 | + <category android:name="android.intent.category.DEFAULT" /> | |
32 | + </intent-filter> | |
29 | 33 | </activity> |
30 | 34 | <activity android:name=".KigoPrefs"></activity> |
31 | 35 | </application> |
@@ -11,39 +11,72 @@ public final class R { | ||
11 | 11 | public static final class array { |
12 | 12 | public static final int font_size_labels=0x7f050001; |
13 | 13 | public static final int font_size_values=0x7f050000; |
14 | + public static final int tap_b_l=0x7f050003; | |
15 | + public static final int tap_b_v=0x7f050002; | |
14 | 16 | } |
15 | 17 | public static final class attr { |
16 | 18 | } |
19 | + public static final class dimen { | |
20 | + public static final int info_margin=0x7f060000; | |
21 | + } | |
17 | 22 | public static final class drawable { |
18 | 23 | public static final int ic_action_search=0x7f020000; |
19 | 24 | public static final int ic_launcher=0x7f020001; |
20 | 25 | } |
21 | 26 | public static final class id { |
22 | - public static final int button1=0x7f090001; | |
23 | - public static final int editText1=0x7f090000; | |
24 | - public static final int listView1=0x7f090002; | |
25 | - public static final int menu_settings=0x7f090003; | |
27 | + public static final int button1=0x7f0a0001; | |
28 | + public static final int editText1=0x7f0a0000; | |
29 | + public static final int layout_root=0x7f0a0003; | |
30 | + public static final int listView1=0x7f0a0002; | |
31 | + public static final int menu_copy=0x7f0a0008; | |
32 | + public static final int menu_info=0x7f0a000b; | |
33 | + public static final int menu_open=0x7f0a000a; | |
34 | + public static final int menu_relat=0x7f0a000c; | |
35 | + public static final int menu_send=0x7f0a0009; | |
36 | + public static final int menu_settings=0x7f0a0007; | |
37 | + public static final int textView1=0x7f0a0004; | |
38 | + public static final int textView2=0x7f0a0005; | |
39 | + public static final int textView3=0x7f0a0006; | |
26 | 40 | } |
27 | 41 | public static final class layout { |
28 | 42 | public static final int activity_kigo=0x7f030000; |
29 | - public static final int list_item=0x7f030001; | |
43 | + public static final int info=0x7f030001; | |
44 | + public static final int list_item=0x7f030002; | |
30 | 45 | } |
31 | 46 | public static final class menu { |
32 | - public static final int activity_kigo=0x7f080000; | |
47 | + public static final int activity_kigo=0x7f090000; | |
48 | + public static final int main_context=0x7f090001; | |
33 | 49 | } |
34 | 50 | public static final class string { |
35 | - public static final int app_name=0x7f060000; | |
36 | - public static final int button_find=0x7f060004; | |
37 | - public static final int err_no_net=0x7f060006; | |
38 | - public static final int hello_world=0x7f060001; | |
39 | - public static final int hint_word=0x7f060005; | |
40 | - public static final int menu_settings=0x7f060002; | |
41 | - public static final int on_load=0x7f060007; | |
42 | - public static final int pref_font=0x7f060008; | |
43 | - public static final int title_activity_kigo=0x7f060003; | |
51 | + public static final int app_name=0x7f070000; | |
52 | + public static final int bcc=0x7f07000f; | |
53 | + public static final int button_find=0x7f070004; | |
54 | + public static final int cc=0x7f07000e; | |
55 | + public static final int err_fail_get=0x7f070007; | |
56 | + public static final int err_no_net=0x7f070006; | |
57 | + public static final int hello_world=0x7f070001; | |
58 | + public static final int hint_word=0x7f070005; | |
59 | + public static final int info_entries=0x7f070015; | |
60 | + public static final int info_follows=0x7f070016; | |
61 | + public static final int info_title=0x7f070017; | |
62 | + public static final int info_word=0x7f070018; | |
63 | + public static final int menu_copy=0x7f070010; | |
64 | + public static final int menu_info=0x7f070012; | |
65 | + public static final int menu_open=0x7f070011; | |
66 | + public static final int menu_relat=0x7f070013; | |
67 | + public static final int menu_send=0x7f070014; | |
68 | + public static final int menu_settings=0x7f070002; | |
69 | + public static final int on_load=0x7f070008; | |
70 | + public static final int pref_cat_app=0x7f070009; | |
71 | + public static final int pref_cat_templ=0x7f07000c; | |
72 | + public static final int pref_font=0x7f07000a; | |
73 | + public static final int pref_tap=0x7f07000b; | |
74 | + public static final int relateds=0x7f070019; | |
75 | + public static final int title_activity_kigo=0x7f070003; | |
76 | + public static final int to=0x7f07000d; | |
44 | 77 | } |
45 | 78 | public static final class style { |
46 | - public static final int AppTheme=0x7f070000; | |
79 | + public static final int AppTheme=0x7f080000; | |
47 | 80 | } |
48 | 81 | public static final class xml { |
49 | 82 | public static final int prefs=0x7f040000; |
@@ -0,0 +1,38 @@ | ||
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
3 | + android:id="@+id/layout_root" | |
4 | + android:layout_width="match_parent" | |
5 | + android:layout_height="match_parent" | |
6 | + android:orientation="vertical" > | |
7 | + | |
8 | + <TextView | |
9 | + android:id="@+id/textView1" | |
10 | + android:layout_width="match_parent" | |
11 | + android:layout_height="wrap_content" | |
12 | + android:layout_marginLeft="@dimen/info_margin" | |
13 | + android:layout_marginRight="@dimen/info_margin" | |
14 | + android:textAppearance="?android:attr/textAppearanceMedium" /> | |
15 | + | |
16 | + <TextView | |
17 | + android:id="@+id/textView2" | |
18 | + android:layout_width="match_parent" | |
19 | + android:layout_height="wrap_content" | |
20 | + android:layout_marginLeft="@dimen/info_margin" | |
21 | + android:layout_marginRight="@dimen/info_margin" | |
22 | + android:textAppearance="?android:attr/textAppearanceMedium" /> | |
23 | + | |
24 | + <TextView | |
25 | + android:id="@+id/textView3" | |
26 | + android:layout_width="match_parent" | |
27 | + android:layout_height="wrap_content" | |
28 | + android:layout_marginLeft="@dimen/info_margin" | |
29 | + android:layout_marginRight="@dimen/info_margin" | |
30 | + android:textAppearance="?android:attr/textAppearanceMedium" /> | |
31 | + | |
32 | +<!-- <TextView --> | |
33 | +<!-- android:id="@+id/textView4" --> | |
34 | +<!-- android:layout_width="match_parent" --> | |
35 | +<!-- android:layout_height="wrap_content" --> | |
36 | +<!-- android:textAppearance="?android:attr/textAppearanceMedium" /> --> | |
37 | + | |
38 | +</LinearLayout> | |
\ No newline at end of file |
@@ -0,0 +1,14 @@ | ||
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<menu xmlns:android="http://schemas.android.com/apk/res/android" > | |
3 | + <item android:id="@+id/menu_copy" | |
4 | + android:title="@string/menu_copy" /> | |
5 | + <item android:id="@+id/menu_send" | |
6 | + android:title="@string/menu_send" /> | |
7 | + <item android:id="@+id/menu_open" | |
8 | + android:title="@string/menu_open" /> | |
9 | + <item android:id="@+id/menu_info" | |
10 | + android:title="@string/menu_info" /> | |
11 | + <item android:id="@+id/menu_relat" | |
12 | + android:title="@string/menu_relat" /> | |
13 | + | |
14 | +</menu> | |
\ No newline at end of file |
@@ -32,5 +32,13 @@ | ||
32 | 32 | <item>30</item> |
33 | 33 | <item>32</item> |
34 | 34 | </string-array> |
35 | + <string-array name="tap_b_v"> | |
36 | + <item>0</item> | |
37 | + <item>1</item> | |
38 | + </string-array> | |
39 | + <string-array name="tap_b_l"> | |
40 | + <item>Copy</item> | |
41 | + <item>Send</item> | |
42 | + </string-array> | |
35 | 43 | |
36 | 44 | </resources> |
\ No newline at end of file |
@@ -0,0 +1,4 @@ | ||
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<resources> | |
3 | + <dimen name="info_margin">4dip</dimen> | |
4 | +</resources> |
@@ -7,7 +7,24 @@ | ||
7 | 7 | <string name="button_find">Find</string> |
8 | 8 | <string name="hint_word">Find a Topic</string> |
9 | 9 | <string name="err_no_net">Network is Disabled.</string> |
10 | + <string name="err_fail_get">Failed to Get from API.</string> | |
10 | 11 | <string name="on_load">Now Loading…</string> |
12 | + <string name="pref_cat_app">Application Settings</string> | |
11 | 13 | <string name="pref_font">Font Size</string> |
14 | + <string name="pref_tap">Tap Behavior</string> | |
15 | + <string name="pref_cat_templ">Send To Template</string> | |
16 | + <string name="to">To:</string> | |
17 | + <string name="cc">CC:</string> | |
18 | + <string name="bcc">BCC:</string> | |
19 | + <string name="menu_copy">Copy</string> | |
20 | + <string name="menu_open">Open</string> | |
21 | + <string name="menu_info">Info</string> | |
22 | + <string name="menu_relat">Relateds</string> | |
23 | + <string name="menu_send">Send</string> | |
24 | + <string name="info_entries"><b>Entries</b>: </string> | |
25 | + <string name="info_follows"><b>Followers</b>: </string> | |
26 | + <string name="info_title"><b>Title</b>: </string> | |
27 | + <string name="info_word"><b>Word</b>: </string> | |
28 | + <string name="relateds">Related Keywords</string> | |
12 | 29 | |
13 | 30 | </resources> |
\ No newline at end of file |
@@ -1,5 +1,12 @@ | ||
1 | 1 | <?xml version="1.0" encoding="utf-8"?> |
2 | 2 | <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > |
3 | + <PreferenceCategory android:title="@string/pref_cat_app"> | |
4 | + <ListPreference | |
5 | + android:key="tap_b" | |
6 | + android:title="@string/pref_tap" | |
7 | + android:entries="@array/tap_b_l" | |
8 | + android:entryValues="@array/tap_b_v" | |
9 | + android:defaultValue="0" /> | |
3 | 10 | <ListPreference |
4 | 11 | android:key="font_size" |
5 | 12 | android:title="@string/pref_font" |
@@ -7,6 +14,17 @@ | ||
7 | 14 | android:entryValues="@array/font_size_values" |
8 | 15 | android:dialogTitle="@string/pref_font" |
9 | 16 | android:defaultValue="16" /> |
10 | - | |
17 | + </PreferenceCategory> | |
18 | + <PreferenceCategory android:title="@string/pref_cat_templ"> | |
19 | + <EditTextPreference | |
20 | + android:key="send_to" | |
21 | + android:title="@string/to" /> | |
22 | + <EditTextPreference | |
23 | + android:key="cc" | |
24 | + android:title="@string/cc" /> | |
25 | + <EditTextPreference | |
26 | + android:key="bcc" | |
27 | + android:title="@string/bcc" /> | |
28 | + </PreferenceCategory> | |
11 | 29 | |
12 | 30 | </PreferenceScreen> |
\ No newline at end of file |
@@ -2,8 +2,10 @@ package org.pulpdust.kigo; | ||
2 | 2 | |
3 | 3 | import java.io.ByteArrayOutputStream; |
4 | 4 | import java.io.StringReader; |
5 | +import java.io.UnsupportedEncodingException; | |
5 | 6 | import java.util.ArrayList; |
6 | 7 | import java.util.List; |
8 | +import java.net.URLEncoder; | |
7 | 9 | |
8 | 10 | import org.apache.http.HttpResponse; |
9 | 11 | import org.apache.http.HttpStatus; |
@@ -14,9 +16,11 @@ import org.xmlpull.v1.XmlPullParser; | ||
14 | 16 | |
15 | 17 | import android.net.ConnectivityManager; |
16 | 18 | import android.net.NetworkInfo; |
19 | +import android.net.Uri; | |
17 | 20 | import android.os.Bundle; |
18 | 21 | import android.preference.PreferenceManager; |
19 | 22 | import android.app.Activity; |
23 | +import android.app.AlertDialog; | |
20 | 24 | import android.app.ProgressDialog; |
21 | 25 | import android.content.Context; |
22 | 26 | import android.content.Intent; |
@@ -24,8 +28,12 @@ import android.content.SharedPreferences; | ||
24 | 28 | import android.text.ClipboardManager; |
25 | 29 | import android.util.Log; |
26 | 30 | import android.util.Xml; |
31 | +import android.view.ContextMenu; | |
32 | +import android.view.ContextMenu.ContextMenuInfo; | |
27 | 33 | import android.view.KeyEvent; |
34 | +import android.view.LayoutInflater; | |
28 | 35 | import android.view.Menu; |
36 | +import android.view.MenuInflater; | |
29 | 37 | import android.view.MenuItem; |
30 | 38 | import android.view.View; |
31 | 39 | import android.view.ViewGroup; |
@@ -42,6 +50,7 @@ import android.widget.TextView; | ||
42 | 50 | import android.view.View.OnClickListener; |
43 | 51 | import android.view.inputmethod.EditorInfo; |
44 | 52 | import android.widget.AdapterView.OnItemClickListener; |
53 | +import android.widget.AdapterView.OnItemLongClickListener; | |
45 | 54 | |
46 | 55 | public class KigoActivity extends Activity { |
47 | 56 | static final String TAG = "KigoActivity"; |
@@ -51,62 +60,96 @@ public class KigoActivity extends Activity { | ||
51 | 60 | Button bttn; |
52 | 61 | ListView lstvw; |
53 | 62 | HttpResponse res; |
54 | - String uri = | |
55 | - "http://h.hatena.ne.jp/api/keywords/list.xml?without_related_keywords=true"; | |
63 | + CharSequence cptxt; | |
64 | + String host = "http://h.hatena.ne.jp/"; | |
65 | + String base = host + "keyword/"; | |
66 | + String uri = host + | |
67 | + "api/keywords/list.xml?without_related_keywords=true"; | |
68 | + String iuri = host + "api/keywords/show.xml?word="; | |
69 | + String guri; | |
56 | 70 | String sbj = ""; |
57 | 71 | String obj; |
72 | + String bwrd = ""; | |
73 | + String buri; | |
58 | 74 | String gactn = "org.pulpdust.kigo.action.PICK_KEYWORD"; |
75 | + String gactn2 = "org.pulpdust.kigo.action.PICK_RELATED"; | |
59 | 76 | String gextr = "org.pulpdust.kigo.extra.WORD"; |
77 | + String[] send_to = new String[1]; | |
78 | + String[] cc = new String[1]; | |
79 | + String[] bcc = new String[1]; | |
80 | + int tpbhvr; | |
60 | 81 | int fntsz = 12; |
61 | 82 | boolean prvd; |
83 | + boolean rltd; | |
84 | + | |
62 | 85 | |
63 | 86 | @Override |
64 | 87 | public void onCreate(Bundle savedInstanceState) { |
65 | 88 | super.onCreate(savedInstanceState); |
66 | 89 | if (gactn.equals(getIntent().getAction())){ |
67 | 90 | prvd = true; |
91 | + rltd = false; | |
92 | + sbj = getIntent().getStringExtra(gextr); | |
93 | + } else if (gactn2.equals(getIntent().getAction())){ | |
94 | + prvd = false; | |
95 | + rltd = true; | |
68 | 96 | sbj = getIntent().getStringExtra(gextr); |
69 | 97 | } else { |
70 | 98 | prvd = false; |
99 | + rltd = false; | |
71 | 100 | } |
72 | 101 | readPrefs(); |
73 | 102 | requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); |
74 | 103 | setContentView(R.layout.activity_kigo); |
75 | 104 | edttxt = (EditText) findViewById(R.id.editText1); |
76 | - if (sbj != null){ | |
77 | - edttxt.setText(sbj); | |
78 | - } | |
79 | - edttxt.setOnEditorActionListener(new OnEditorActionListener(){ | |
80 | - @Override | |
81 | - public boolean onEditorAction(TextView v, int aid, KeyEvent kev) { | |
82 | - if (aid == EditorInfo.IME_ACTION_SEARCH){ | |
83 | - sbj = edttxt.getText().toString().trim(); | |
84 | - reLoad(); | |
85 | - } | |
86 | - return true; | |
87 | - } | |
105 | + if (rltd == true){ | |
106 | + edttxt.setVisibility(View.GONE); | |
107 | + } else { | |
108 | + if (sbj != null){ | |
109 | + edttxt.setText(sbj); | |
110 | + } else { | |
111 | + sbj = ""; | |
112 | + } | |
113 | + edttxt.setOnEditorActionListener(new OnEditorActionListener(){ | |
114 | + @Override | |
115 | + public boolean onEditorAction(TextView v, int aid, KeyEvent kev) { | |
116 | + if (aid == EditorInfo.IME_ACTION_SEARCH){ | |
117 | + sbj = edttxt.getText().toString().trim(); | |
118 | + guri = uri + "&word=" + sbj; | |
119 | + reLoad(guri); | |
120 | + } | |
121 | + return true; | |
122 | + } | |
88 | 123 | |
89 | - }); | |
90 | - edttxt.setOnKeyListener(new OnKeyListener(){ | |
91 | - @Override | |
92 | - public boolean onKey(View v, int kcd, KeyEvent kev) { | |
93 | - if (kev.getAction() == KeyEvent.ACTION_UP && | |
94 | - kcd == KeyEvent.KEYCODE_ENTER){ | |
95 | - sbj = edttxt.getText().toString().trim(); | |
96 | - reLoad(); | |
97 | - return true; | |
98 | - } | |
99 | - return false; | |
100 | - } | |
101 | - }); | |
124 | + }); | |
125 | + edttxt.setOnKeyListener(new OnKeyListener(){ | |
126 | + @Override | |
127 | + public boolean onKey(View v, int kcd, KeyEvent kev) { | |
128 | + if (kev.getAction() == KeyEvent.ACTION_UP && | |
129 | + kcd == KeyEvent.KEYCODE_ENTER){ | |
130 | + sbj = edttxt.getText().toString().trim(); | |
131 | + guri = uri + "&word=" + sbj; | |
132 | + reLoad(guri); | |
133 | + return true; | |
134 | + } | |
135 | + return false; | |
136 | + } | |
137 | + }); | |
138 | + } | |
102 | 139 | bttn = (Button) findViewById(R.id.button1); |
103 | - bttn.setOnClickListener(new OnClickListener(){ | |
104 | - public void onClick(View v){ | |
105 | - sbj = edttxt.getText().toString().trim(); | |
106 | - reLoad(); | |
107 | - } | |
108 | - }); | |
140 | + if (rltd == true){ | |
141 | + bttn.setVisibility(View.GONE); | |
142 | + } else { | |
143 | + bttn.setOnClickListener(new OnClickListener(){ | |
144 | + public void onClick(View v){ | |
145 | + sbj = edttxt.getText().toString().trim(); | |
146 | + guri = uri + "&word=" + sbj; | |
147 | + reLoad(guri); | |
148 | + } | |
149 | + }); | |
150 | + } | |
109 | 151 | lstvw = (ListView) findViewById(R.id.listView1); |
152 | + registerForContextMenu(lstvw); | |
110 | 153 | lstvw.setOnItemClickListener(new OnItemClickListener(){ |
111 | 154 | @Override |
112 | 155 | public void onItemClick(AdapterView<?> av, View v, int pos, |
@@ -117,14 +160,23 @@ public class KigoActivity extends Activity { | ||
117 | 160 | setResult(RESULT_OK, intent); |
118 | 161 | finish(); |
119 | 162 | } else { |
120 | - ClipboardManager clipbd = (ClipboardManager) | |
121 | - getSystemService(Context.CLIPBOARD_SERVICE); | |
122 | - clipbd.setText(((TextView) v).getText()); | |
123 | - Toast.makeText(getApplicationContext(), ((TextView) v).getText(), | |
124 | - Toast.LENGTH_SHORT).show(); | |
163 | + if (tpbhvr == 0){ | |
164 | + doCopy(((TextView) v).getText()); | |
165 | + } else if (tpbhvr == 1){ | |
166 | + sendTo(((TextView) v).getText()); | |
167 | + } | |
125 | 168 | } |
126 | 169 | } |
127 | 170 | }); |
171 | + lstvw.setOnItemLongClickListener(new OnItemLongClickListener(){ | |
172 | + @Override | |
173 | + public boolean onItemLongClick(AdapterView<?> av, View v, | |
174 | + int pos, long id) { | |
175 | + cptxt = ((TextView) v).getText(); | |
176 | + openContextMenu(lstvw); | |
177 | + return true; | |
178 | + } | |
179 | + }); | |
128 | 180 | arryadpt = new ArrayAdapter<String>(this, R.layout.list_item, lst){ |
129 | 181 | @Override |
130 | 182 | public View getView(int pos, View v, ViewGroup vg){ |
@@ -134,31 +186,195 @@ public class KigoActivity extends Activity { | ||
134 | 186 | } |
135 | 187 | }; |
136 | 188 | lstvw.setAdapter(arryadpt); |
137 | - final String save = (String) getLastNonConfigurationInstance(); | |
189 | + final String save[] = (String[]) getLastNonConfigurationInstance(); | |
138 | 190 | if (save != null){ |
139 | - obj = save; | |
191 | + if (save[0] != null){ | |
192 | + obj = save[0]; | |
140 | 193 | arryadpt.clear(); |
141 | - xmlBaker(save); | |
142 | - } else { | |
143 | - reLoad(); | |
194 | + xmlBaker(obj); | |
195 | + } | |
196 | + if (save[1] != null){ buri = save[1]; } | |
197 | + if (save[2] != null){ bwrd = save[2]; } | |
198 | + } else { | |
199 | + if (rltd == true){ | |
200 | + guri = iuri + sbj; | |
201 | + } else { | |
202 | + guri = uri + "&word=" + sbj; | |
203 | + } | |
204 | + reLoad(guri); | |
144 | 205 | } |
145 | 206 | } |
207 | + public void doCopy(CharSequence text){ | |
208 | + ClipboardManager clipbd = (ClipboardManager) | |
209 | + getSystemService(Context.CLIPBOARD_SERVICE); | |
210 | + clipbd.setText(text); | |
211 | + Toast.makeText(getApplicationContext(), text, | |
212 | + Toast.LENGTH_SHORT).show(); | |
213 | + } | |
214 | + @Override | |
215 | + public void onCreateContextMenu(ContextMenu cm, View v, | |
216 | + ContextMenuInfo cmi){ | |
217 | + super.onCreateContextMenu(cm, v, cmi); | |
218 | + cm.setHeaderTitle(cptxt); | |
219 | + MenuInflater minflater = getMenuInflater(); | |
220 | + minflater.inflate(R.menu.main_context, cm); | |
221 | + } | |
222 | + public void sendTo(CharSequence subject){ | |
223 | + Uri suri = Uri.parse("mailto:"); | |
224 | + if (!send_to[0].equals("")){ | |
225 | + suri = Uri.parse("mailto:" + send_to[0]); | |
226 | + } | |
227 | + | |
228 | + Intent intent = new Intent(Intent.ACTION_SENDTO, suri); | |
229 | + if (!cc[0].equals("")){ | |
230 | + intent.putExtra(Intent.EXTRA_CC, cc); | |
231 | + } | |
232 | + if (!bcc[0].equals("")){ | |
233 | + intent.putExtra(Intent.EXTRA_BCC, bcc); | |
234 | + } | |
235 | + intent.putExtra(Intent.EXTRA_SUBJECT, subject); | |
236 | + startActivity(intent); | |
237 | + } | |
238 | + @Override | |
239 | + public boolean onContextItemSelected(MenuItem mi){ | |
240 | + switch (mi.getItemId()){ | |
241 | + case R.id.menu_copy: | |
242 | + doCopy(cptxt); | |
243 | + return true; | |
244 | + case R.id.menu_send: | |
245 | + sendTo(cptxt); | |
246 | + return true; | |
247 | + case R.id.menu_open: | |
248 | + String openuri; | |
249 | + try { | |
250 | + openuri = base + URLEncoder.encode(cptxt.toString(), "UTF-8"); | |
251 | + Intent sendi = new Intent(Intent.ACTION_VIEW, Uri.parse(openuri)); | |
252 | + startActivity(sendi); | |
253 | + } catch (UnsupportedEncodingException e) { | |
254 | + // TODO Auto-generated catch block | |
255 | + e.printStackTrace(); | |
256 | + } | |
257 | + return true; | |
258 | + case R.id.menu_info: | |
259 | + echoInfo(cptxt.toString()); | |
260 | + return true; | |
261 | + case R.id.menu_relat: | |
262 | +// Intent intent = new Intent(gactn2); | |
263 | +// intent.setClassName("org.pulpdust.kigo", "org.pulpdust.kigo.KigoActivity"); | |
264 | +// intent.putExtra(gextr, cptxt); | |
265 | +// intent.removeCategory(Intent.CATEGORY_DEFAULT); | |
266 | +// intent.addCategory(Intent.CATEGORY_LAUNCHER); | |
267 | +// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_MULTIPLE_TASK); | |
268 | +// try { | |
269 | +// startActivity(intent); | |
270 | +// return true; | |
271 | +// } catch (ActivityNotFoundException e){ | |
272 | +// Log.e(TAG, e.getMessage()); | |
273 | +// return false; | |
274 | +// } | |
275 | + try { | |
276 | + if (!rltd){ | |
277 | + bwrd = sbj; | |
278 | + buri = guri; | |
279 | + rltd = true; | |
280 | + } | |
281 | + guri = iuri + URLEncoder.encode(cptxt.toString(), "UTF-8"); | |
282 | + edttxt.setVisibility(View.GONE); | |
283 | + bttn.setVisibility(View.GONE); | |
284 | + setTitle(getString(R.string.app_name) + " - " + getString(R.string.relateds)); | |
285 | + reLoad(guri); | |
286 | + return true; | |
287 | + } catch (UnsupportedEncodingException e) { | |
288 | + // TODO Auto-generated catch block | |
289 | + e.printStackTrace(); | |
290 | + return false; | |
291 | + } | |
292 | + default: | |
293 | + return false; | |
294 | + } | |
295 | + } | |
296 | + public void echoInfo(String word){ | |
297 | + try { | |
298 | + String turi = iuri + URLEncoder.encode(word.toString(), "UTF-8"); | |
299 | + String xml = getHttp(turi); | |
300 | + if (xml != null){ | |
301 | + String info[] = exInfo(xml); | |
302 | + if(info != null){ | |
303 | + Context context = this; | |
304 | + AlertDialog.Builder abuilder = new AlertDialog.Builder(context); | |
305 | + LayoutInflater linflater = | |
306 | + (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE); | |
307 | + View layout = linflater.inflate(R.layout.info, | |
308 | + (ViewGroup) findViewById(R.id.layout_root)); | |
309 | + TextView tv1 = (TextView) layout.findViewById(R.id.textView1); | |
310 | + TextView tv2 = (TextView) layout.findViewById(R.id.textView2); | |
311 | + TextView tv3 = (TextView) layout.findViewById(R.id.textView3); | |
312 | +// TextView tv4 = (TextView) layout.findViewById(R.id.textView4); | |
313 | + tv1.setText(getString(R.string.info_entries) + info[0]); | |
314 | + tv2.setText(getString(R.string.info_follows) + info[1]); | |
315 | + tv3.setText(getString(R.string.info_title) + info[2]); | |
316 | +// tv4.setText(getString(R.string.info_word) + info[3]); | |
317 | + abuilder.setTitle(word); | |
318 | + abuilder.setCancelable(true); | |
319 | + abuilder.setView(layout); | |
320 | + abuilder.show(); | |
321 | + } | |
322 | + } else { | |
323 | + Toast.makeText(getApplicationContext(), R.string.err_fail_get, | |
324 | + Toast.LENGTH_SHORT).show(); | |
325 | + } | |
326 | + | |
327 | + } catch (UnsupportedEncodingException e) { | |
328 | + // TODO Auto-generated catch block | |
329 | + e.printStackTrace(); | |
330 | + } | |
331 | + } | |
332 | + | |
146 | 333 | @Override |
147 | 334 | public Object onRetainNonConfigurationInstance(){ |
148 | - final String save = obj; | |
335 | + final String save[] = new String[3]; | |
336 | + save[0] = obj; | |
337 | + save[1] = buri; | |
338 | + save[2] = bwrd; | |
149 | 339 | return save; |
150 | 340 | } |
151 | - public void reLoad(){ | |
152 | - if (!isConnect(getApplicationContext())){ | |
153 | - Toast.makeText(getApplicationContext(), R.string.err_no_net, | |
154 | - Toast.LENGTH_SHORT).show(); | |
155 | - } else { | |
341 | + @Override | |
342 | + public boolean dispatchKeyEvent(KeyEvent kev){ | |
343 | + if (kev.getAction() == KeyEvent.ACTION_DOWN){ | |
344 | + switch (kev.getKeyCode()){ | |
345 | + case KeyEvent.KEYCODE_BACK: | |
346 | + if (rltd){ | |
347 | + guri = buri; | |
348 | + sbj = bwrd; | |
349 | + buri = null; | |
350 | + bwrd = ""; | |
351 | + edttxt.setVisibility(View.VISIBLE); | |
352 | + bttn.setVisibility(View.VISIBLE); | |
353 | + rltd = false; | |
354 | + setTitle(R.string.app_name); | |
355 | + reLoad(guri); | |
356 | + return true; | |
357 | + } | |
358 | + default: | |
359 | + return super.dispatchKeyEvent(kev); | |
360 | + } | |
361 | + } else { | |
362 | + return super.dispatchKeyEvent(kev); | |
363 | + } | |
364 | + } | |
365 | + public void reLoad(String uri){ | |
156 | 366 | ProgressDialog pdialog = ProgressDialog.show(this, "", |
157 | 367 | getString(R.string.on_load), true); |
158 | 368 | arryadpt.clear(); |
159 | - getHttp(uri + "&word=" + sbj); | |
369 | + obj = null; | |
370 | + obj = getHttp(uri); | |
371 | + if (obj != null){ | |
372 | + xmlBaker(obj); | |
373 | + } else { | |
374 | + Toast.makeText(getApplicationContext(), R.string.err_fail_get, | |
375 | + Toast.LENGTH_SHORT).show(); | |
376 | + } | |
160 | 377 | pdialog.dismiss(); |
161 | - } | |
162 | 378 | } |
163 | 379 | public static boolean isConnect(Context c){ |
164 | 380 | ConnectivityManager cmanager = (ConnectivityManager) |
@@ -169,28 +385,35 @@ public class KigoActivity extends Activity { | ||
169 | 385 | } |
170 | 386 | return false; |
171 | 387 | } |
172 | - public void getHttp(String uri){ | |
173 | - HttpClient client = new DefaultHttpClient(); | |
174 | - HttpGet req = new HttpGet(uri.toString()); | |
175 | - try { | |
176 | - res = client.execute(req); | |
177 | - } catch (Exception e){ | |
178 | - Log.e(TAG, e.getMessage()); | |
179 | - return; | |
180 | - } | |
181 | - int status = res.getStatusLine().getStatusCode(); | |
182 | - if (HttpStatus.SC_OK == status){ | |
183 | - try { | |
184 | - ByteArrayOutputStream baop = new ByteArrayOutputStream(); | |
185 | - res.getEntity().writeTo(baop); | |
186 | - obj = baop.toString(); | |
187 | - xmlBaker(baop.toString()); | |
188 | - } catch (Exception e){ | |
189 | - Log.e(TAG, e.getMessage()); | |
190 | - } | |
191 | - } else { | |
192 | - Log.d(TAG, "HTTP" + status); | |
193 | - } | |
388 | + public String getHttp(String uri){ | |
389 | + if (!isConnect(getApplicationContext())){ | |
390 | + Toast.makeText(getApplicationContext(), R.string.err_no_net, | |
391 | + Toast.LENGTH_SHORT).show(); | |
392 | + return null; | |
393 | + } else { | |
394 | + HttpClient client = new DefaultHttpClient(); | |
395 | + HttpGet req = new HttpGet(uri.toString()); | |
396 | + try { | |
397 | + res = client.execute(req); | |
398 | + } catch (Exception e){ | |
399 | + Log.e(TAG, e.getMessage()); | |
400 | + return null; | |
401 | + } | |
402 | + int status = res.getStatusLine().getStatusCode(); | |
403 | + if (HttpStatus.SC_OK == status){ | |
404 | + try { | |
405 | + ByteArrayOutputStream baop = new ByteArrayOutputStream(); | |
406 | + res.getEntity().writeTo(baop); | |
407 | + return baop.toString(); | |
408 | + } catch (Exception e){ | |
409 | + Log.e(TAG, e.getMessage()); | |
410 | + return null; | |
411 | + } | |
412 | + } else { | |
413 | + Log.d(TAG, "HTTP" + status); | |
414 | + return null; | |
415 | + } | |
416 | + } | |
194 | 417 | } |
195 | 418 | public void xmlBaker(String xml){ |
196 | 419 | try{ |
@@ -200,10 +423,38 @@ public class KigoActivity extends Activity { | ||
200 | 423 | while ((evt = parser.next()) != XmlPullParser.END_DOCUMENT){ |
201 | 424 | if (evt == XmlPullParser.START_TAG && "word".equals(parser.getName())){ |
202 | 425 | arryadpt.add(parser.nextText()); |
426 | + } else if (evt == XmlPullParser.START_TAG && "related_keywords".equals(parser.getName())){ | |
427 | + arryadpt.add(parser.nextText()); | |
428 | + } | |
429 | + } | |
430 | + } catch (Exception e){ | |
431 | + Log.e(TAG, e.getMessage()); | |
432 | + } | |
433 | + } | |
434 | + public String[] exInfo(String xml){ | |
435 | + try { | |
436 | + String ret[] = new String[4]; | |
437 | + XmlPullParser xparser = Xml.newPullParser(); | |
438 | + xparser.setInput(new StringReader(xml)); | |
439 | + int evt; | |
440 | + while ((evt = xparser.next()) != XmlPullParser.END_DOCUMENT){ | |
441 | + if (evt == XmlPullParser.START_TAG && "entry_count".equals(xparser.getName())){ | |
442 | + ret[0] = xparser.nextText(); | |
443 | + } | |
444 | + if (evt == XmlPullParser.START_TAG && "followers_count".equals(xparser.getName())){ | |
445 | + ret[1] = xparser.nextText(); | |
446 | + } | |
447 | + if (evt == XmlPullParser.START_TAG && "title".equals(xparser.getName())){ | |
448 | + ret[2] = xparser.nextText(); | |
449 | + } | |
450 | + if (evt == XmlPullParser.START_TAG && "word".equals(xparser.getName())){ | |
451 | + ret[3] = xparser.nextText(); | |
203 | 452 | } |
204 | 453 | } |
454 | + return ret; | |
205 | 455 | } catch (Exception e){ |
206 | 456 | Log.e(TAG, e.getMessage()); |
457 | + return null; | |
207 | 458 | } |
208 | 459 | } |
209 | 460 |
@@ -231,12 +482,16 @@ public class KigoActivity extends Activity { | ||
231 | 482 | switch (requestCode){ |
232 | 483 | case 2: |
233 | 484 | readPrefs(); |
234 | - reLoad(); | |
485 | + reLoad(guri); | |
235 | 486 | break; |
236 | 487 | } |
237 | 488 | } |
238 | 489 | public void readPrefs(){ |
239 | 490 | SharedPreferences sprefs = PreferenceManager.getDefaultSharedPreferences(this); |
491 | + tpbhvr = Integer.parseInt(sprefs.getString("tap_b", "0")); | |
240 | 492 | fntsz = Integer.parseInt(sprefs.getString("font_size", "16")); |
493 | + send_to[0] = sprefs.getString("send_to", ""); | |
494 | + cc[0] = sprefs.getString("cc", ""); | |
495 | + bcc[0] = sprefs.getString("bcc", ""); | |
241 | 496 | } |
242 | 497 | } |