Mercurial > 510Connectbot
annotate src/com/five_ten_sg/connectbot/HostEditorActivity.java @ 233:2626bf2a8cea
delay testChanged() by 10ms for async transports
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 10 Jul 2014 10:44:09 -0700 |
parents | 37665a94fc39 |
children | 071eccdff8ea |
rev | line source |
---|---|
0 | 1 /* |
2 * ConnectBot: simple, powerful, open-source SSH client for Android | |
3 * Copyright 2007 Kenny Root, Jeffrey Sharkey | |
4 * | |
5 * Licensed under the Apache License, Version 2.0 (the "License"); | |
6 * you may not use this file except in compliance with the License. | |
7 * You may obtain a copy of the License at | |
8 * | |
9 * http://www.apache.org/licenses/LICENSE-2.0 | |
10 * | |
11 * Unless required by applicable law or agreed to in writing, software | |
12 * distributed under the License is distributed on an "AS IS" BASIS, | |
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 * See the License for the specific language governing permissions and | |
15 * limitations under the License. | |
16 */ | |
17 | |
18 package com.five_ten_sg.connectbot; | |
19 | |
20 import java.nio.charset.Charset; | |
21 import java.util.Arrays; | |
22 import java.util.HashMap; | |
23 import java.util.LinkedList; | |
24 import java.util.List; | |
127
69db8af9508d
host editor database values override summary text only if non-empty
Carl Byington <carl@five-ten-sg.com>
parents:
123
diff
changeset
|
25 import java.util.HashMap; |
0 | 26 import java.util.Map; |
27 import java.util.Map.Entry; | |
28 import java.util.Set; | |
29 | |
30 import com.five_ten_sg.connectbot.bean.HostBean; | |
31 import com.five_ten_sg.connectbot.service.TerminalBridge; | |
32 import com.five_ten_sg.connectbot.service.TerminalManager; | |
33 import com.five_ten_sg.connectbot.util.HostDatabase; | |
34 import com.five_ten_sg.connectbot.util.PubkeyDatabase; | |
35 import android.content.ComponentName; | |
36 import android.content.ContentValues; | |
37 import android.content.Context; | |
38 import android.content.Intent; | |
39 import android.content.ServiceConnection; | |
40 import android.content.SharedPreferences; | |
41 import android.content.SharedPreferences.OnSharedPreferenceChangeListener; | |
42 import android.database.Cursor; | |
43 import android.database.sqlite.SQLiteDatabase; | |
44 import android.os.Bundle; | |
45 import android.os.IBinder; | |
46 import android.preference.CheckBoxPreference; | |
47 import android.preference.ListPreference; | |
48 import android.preference.Preference; | |
49 import android.preference.PreferenceActivity; | |
50 import android.util.Log; | |
51 | |
52 public class HostEditorActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener { | |
53 public class CursorPreferenceHack implements SharedPreferences { | |
54 protected final String table; | |
55 protected final long id; | |
56 | |
57 protected Map<String, String> values = new HashMap<String, String>(); | |
58 | |
59 public CursorPreferenceHack(String table, long id) { | |
60 this.table = table; | |
61 this.id = id; | |
62 cacheValues(); | |
63 } | |
64 | |
65 protected final void cacheValues() { | |
66 // fill a cursor and cache the values locally | |
67 // this makes sure we dont have any floating cursor to dispose later | |
68 SQLiteDatabase db = hostdb.getReadableDatabase(); | |
69 Cursor cursor = db.query(table, null, "_id = ?", | |
70 new String[] { String.valueOf(id) }, null, null, null); | |
71 | |
72 if (cursor.moveToFirst()) { | |
73 for (int i = 0; i < cursor.getColumnCount(); i++) { | |
74 String key = cursor.getColumnName(i); | |
75 | |
76 if (key.equals(HostDatabase.FIELD_HOST_HOSTKEY)) continue; | |
77 | |
78 String value = cursor.getString(i); | |
79 values.put(key, value); | |
80 } | |
81 } | |
82 | |
83 cursor.close(); | |
84 db.close(); | |
85 } | |
86 | |
87 public boolean contains(String key) { | |
88 return values.containsKey(key); | |
89 } | |
90 | |
91 public class Editor implements SharedPreferences.Editor { | |
92 | |
93 private ContentValues update = new ContentValues(); | |
94 | |
95 public SharedPreferences.Editor clear() { | |
96 Log.d(this.getClass().toString(), "clear()"); | |
97 update = new ContentValues(); | |
98 return this; | |
99 } | |
100 | |
101 public boolean commit() { | |
102 //Log.d(this.getClass().toString(), "commit() changes back to database"); | |
103 SQLiteDatabase db = hostdb.getWritableDatabase(); | |
104 db.update(table, update, "_id = ?", new String[] { String.valueOf(id) }); | |
105 db.close(); | |
106 // make sure we refresh the parent cached values | |
107 cacheValues(); | |
108 | |
109 // and update any listeners | |
110 for (OnSharedPreferenceChangeListener listener : listeners) { | |
111 listener.onSharedPreferenceChanged(CursorPreferenceHack.this, null); | |
112 } | |
113 | |
114 return true; | |
115 } | |
116 | |
117 // Gingerbread compatibility | |
118 public void apply() { | |
119 commit(); | |
120 } | |
121 | |
122 public android.content.SharedPreferences.Editor putBoolean(String key, boolean value) { | |
123 return this.putString(key, Boolean.toString(value)); | |
124 } | |
125 | |
126 public android.content.SharedPreferences.Editor putFloat(String key, float value) { | |
127 return this.putString(key, Float.toString(value)); | |
128 } | |
129 | |
130 public android.content.SharedPreferences.Editor putInt(String key, int value) { | |
131 return this.putString(key, Integer.toString(value)); | |
132 } | |
133 | |
134 public android.content.SharedPreferences.Editor putLong(String key, long value) { | |
135 return this.putString(key, Long.toString(value)); | |
136 } | |
137 | |
138 public android.content.SharedPreferences.Editor putString(String key, String value) { | |
139 //Log.d(this.getClass().toString(), String.format("Editor.putString(key=%s, value=%s)", key, value)); | |
140 update.put(key, value); | |
141 return this; | |
142 } | |
143 | |
144 public android.content.SharedPreferences.Editor remove(String key) { | |
145 //Log.d(this.getClass().toString(), String.format("Editor.remove(key=%s)", key)); | |
146 update.remove(key); | |
147 return this; | |
148 } | |
149 | |
150 public android.content.SharedPreferences.Editor putStringSet(String key, Set<String> value) { | |
151 throw new UnsupportedOperationException("HostEditor Prefs do not support Set<String>"); | |
152 } | |
153 } | |
154 | |
155 | |
156 public Editor edit() { | |
157 //Log.d(this.getClass().toString(), "edit()"); | |
158 return new Editor(); | |
159 } | |
160 | |
161 public Map<String, ?> getAll() { | |
162 return values; | |
163 } | |
164 | |
165 public boolean getBoolean(String key, boolean defValue) { | |
166 return Boolean.valueOf(this.getString(key, Boolean.toString(defValue))); | |
167 } | |
168 | |
169 public float getFloat(String key, float defValue) { | |
170 return Float.valueOf(this.getString(key, Float.toString(defValue))); | |
171 } | |
172 | |
173 public int getInt(String key, int defValue) { | |
174 return Integer.valueOf(this.getString(key, Integer.toString(defValue))); | |
175 } | |
176 | |
177 public long getLong(String key, long defValue) { | |
178 return Long.valueOf(this.getString(key, Long.toString(defValue))); | |
179 } | |
180 | |
181 public String getString(String key, String defValue) { | |
182 //Log.d(this.getClass().toString(), String.format("getString(key=%s, defValue=%s)", key, defValue)); | |
183 if (!values.containsKey(key)) return defValue; | |
184 | |
185 return values.get(key); | |
186 } | |
187 | |
188 public Set<String> getStringSet(String key, Set<String> defValue) { | |
189 throw new ClassCastException("HostEditor Prefs do not support Set<String>"); | |
190 } | |
191 | |
192 protected List<OnSharedPreferenceChangeListener> listeners = new LinkedList<OnSharedPreferenceChangeListener>(); | |
193 | |
194 public void registerOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener listener) { | |
195 listeners.add(listener); | |
196 } | |
197 | |
198 public void unregisterOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener listener) { | |
199 listeners.remove(listener); | |
200 } | |
201 | |
202 } | |
203 | |
204 @Override | |
205 public SharedPreferences getSharedPreferences(String name, int mode) { | |
206 //Log.d(this.getClass().toString(), String.format("getSharedPreferences(name=%s)", name)); | |
207 return this.pref; | |
208 } | |
209 | |
210 protected static final String TAG = "ConnectBot.HostEditorActivity"; | |
211 | |
212 protected HostDatabase hostdb = null; | |
213 private PubkeyDatabase pubkeydb = null; | |
214 | |
215 private CursorPreferenceHack pref; | |
216 private ServiceConnection connection; | |
130
2a0b10fd128d
host editor database values override summary text only if non-empty
Carl Byington <carl@five-ten-sg.com>
parents:
129
diff
changeset
|
217 private Map<String, CharSequence> summaries = new HashMap<String, CharSequence>(); |
0 | 218 |
219 private HostBean host; | |
83
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
220 private boolean enableSSHFeatures; |
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
221 private boolean enable5250Features; |
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
222 private boolean enableAsyncFeatures; |
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
223 |
0 | 224 protected TerminalBridge hostBridge; |
225 | |
226 @Override | |
227 public void onCreate(Bundle icicle) { | |
228 super.onCreate(icicle); | |
229 long hostId = this.getIntent().getLongExtra(Intent.EXTRA_TITLE, -1); | |
230 // TODO: we could pass through a specific ContentProvider uri here | |
231 //this.getPreferenceManager().setSharedPreferencesName(uri); | |
232 this.hostdb = new HostDatabase(this); | |
233 this.pubkeydb = new PubkeyDatabase(this); | |
234 host = hostdb.findHostById(hostId); | |
83
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
235 enableSSHFeatures = host.isSSH(); |
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
236 enable5250Features = host.is5250(); |
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
237 enableAsyncFeatures = host.isAsync(); |
0 | 238 connection = new ServiceConnection() { |
239 public void onServiceConnected(ComponentName className, IBinder service) { | |
240 TerminalManager bound = ((TerminalManager.TerminalBinder) service).getService(); | |
241 hostBridge = bound.getConnectedBridge(host); | |
242 } | |
243 public void onServiceDisconnected(ComponentName name) { | |
244 hostBridge = null; | |
245 } | |
246 }; | |
247 this.pref = new CursorPreferenceHack(HostDatabase.TABLE_HOSTS, hostId); | |
248 this.pref.registerOnSharedPreferenceChangeListener(this); | |
249 this.addPreferencesFromResource(R.xml.host_prefs); | |
127
69db8af9508d
host editor database values override summary text only if non-empty
Carl Byington <carl@five-ten-sg.com>
parents:
123
diff
changeset
|
250 // get all the text summaries |
69db8af9508d
host editor database values override summary text only if non-empty
Carl Byington <carl@five-ten-sg.com>
parents:
123
diff
changeset
|
251 getSummaries(); |
83
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
252 // disable all preferences that are not applicable to this host |
88
1c22e6a7efff
convert ctrl keys to virtual keys; use proper android home directory
Carl Byington <carl@five-ten-sg.com>
parents:
83
diff
changeset
|
253 findPreference(HostDatabase.FIELD_HOST_PUBKEYID).setEnabled(enableSSHFeatures); |
83
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
254 findPreference(HostDatabase.FIELD_HOST_USEAUTHAGENT).setEnabled(enableSSHFeatures); |
89
bb27518ac2e9
convert ctrl keys to virtual keys; use proper android home directory
Carl Byington <carl@five-ten-sg.com>
parents:
88
diff
changeset
|
255 findPreference(HostDatabase.FIELD_HOST_POSTLOGIN).setEnabled(!enable5250Features); |
83
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
256 findPreference(HostDatabase.FIELD_HOST_COMPRESSION).setEnabled(enableSSHFeatures); |
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
257 findPreference(HostDatabase.FIELD_HOST_HTTPPROXY).setEnabled(enableAsyncFeatures); |
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
258 findPreference(HostDatabase.FIELD_HOST_WANTSESSION).setEnabled(enableSSHFeatures); |
123
446dbcf606eb
add more 5250 config items; ignore drawing outside the screen
Carl Byington <carl@five-ten-sg.com>
parents:
118
diff
changeset
|
259 findPreference(HostDatabase.FIELD_HOST_USERNAME).setEnabled(enableSSHFeatures || enable5250Features); |
83
4ccfde0bc506
disable host config items that are not applicable to the host protocol
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
260 findPreference(HostDatabase.FIELD_HOST_EMULATION).setEnabled(!enable5250Features); |
123
446dbcf606eb
add more 5250 config items; ignore drawing outside the screen
Carl Byington <carl@five-ten-sg.com>
parents:
118
diff
changeset
|
261 findPreference(HostDatabase.CATEGORY_5250).setEnabled(enable5250Features); |
446dbcf606eb
add more 5250 config items; ignore drawing outside the screen
Carl Byington <carl@five-ten-sg.com>
parents:
118
diff
changeset
|
262 findPreference(HostDatabase.CATEGORY_X11).setEnabled(enableSSHFeatures); |
0 | 263 // add all existing pubkeys to our listpreference for user to choose from |
264 // TODO: may be an issue here when this activity is recycled after adding a new pubkey | |
265 // TODO: should consider moving into onStart, but we dont have a good way of resetting the listpref after filling once | |
88
1c22e6a7efff
convert ctrl keys to virtual keys; use proper android home directory
Carl Byington <carl@five-ten-sg.com>
parents:
83
diff
changeset
|
266 ListPreference pubkeyPref = (ListPreference)findPreference(HostDatabase.FIELD_HOST_PUBKEYID); |
0 | 267 List<CharSequence> pubkeyNicks = new LinkedList<CharSequence> (Arrays.asList(pubkeyPref.getEntries())); |
268 pubkeyNicks.addAll(pubkeydb.allValues(PubkeyDatabase.FIELD_PUBKEY_NICKNAME)); | |
269 pubkeyPref.setEntries(pubkeyNicks.toArray(new CharSequence[pubkeyNicks.size()])); | |
270 List<CharSequence> pubkeyIds = new LinkedList<CharSequence> (Arrays.asList(pubkeyPref.getEntryValues())); | |
271 pubkeyIds.addAll(pubkeydb.allValues("_id")); | |
272 pubkeyPref.setEntryValues(pubkeyIds.toArray(new CharSequence[pubkeyIds.size()])); | |
273 // Populate the character set encoding list with all available | |
88
1c22e6a7efff
convert ctrl keys to virtual keys; use proper android home directory
Carl Byington <carl@five-ten-sg.com>
parents:
83
diff
changeset
|
274 final ListPreference charsetPref = (ListPreference)findPreference(HostDatabase.FIELD_HOST_ENCODING); |
0 | 275 |
276 if (CharsetHolder.isInitialized()) { | |
277 initCharsetPref(charsetPref); | |
278 } | |
279 else { | |
280 String[] currentCharsetPref = new String[1]; | |
281 currentCharsetPref[0] = charsetPref.getValue(); | |
282 charsetPref.setEntryValues(currentCharsetPref); | |
283 charsetPref.setEntries(currentCharsetPref); | |
284 new Thread(new Runnable() { | |
285 public void run() { | |
286 initCharsetPref(charsetPref); | |
287 } | |
288 }).start(); | |
289 } | |
290 | |
291 this.updateSummaries(); | |
292 } | |
293 | |
294 @Override | |
295 public void onStart() { | |
296 super.onStart(); | |
297 bindService(new Intent(this, TerminalManager.class), connection, Context.BIND_AUTO_CREATE); | |
298 | |
299 if (this.hostdb == null) | |
300 this.hostdb = new HostDatabase(this); | |
301 | |
302 if (this.pubkeydb == null) | |
303 this.pubkeydb = new PubkeyDatabase(this); | |
304 } | |
305 | |
306 @Override | |
307 public void onStop() { | |
308 super.onStop(); | |
309 unbindService(connection); | |
310 | |
311 if (this.hostdb != null) { | |
312 this.hostdb.close(); | |
313 this.hostdb = null; | |
314 } | |
315 | |
316 if (this.pubkeydb != null) { | |
317 this.pubkeydb.close(); | |
318 this.pubkeydb = null; | |
319 } | |
320 } | |
321 | |
127
69db8af9508d
host editor database values override summary text only if non-empty
Carl Byington <carl@five-ten-sg.com>
parents:
123
diff
changeset
|
322 private void getSummaries() { |
69db8af9508d
host editor database values override summary text only if non-empty
Carl Byington <carl@five-ten-sg.com>
parents:
123
diff
changeset
|
323 // get all the original text summaries |
0 | 324 for (String key : this.pref.values.keySet()) { |
127
69db8af9508d
host editor database values override summary text only if non-empty
Carl Byington <carl@five-ten-sg.com>
parents:
123
diff
changeset
|
325 Preference pref = this.findPreference(key); |
69db8af9508d
host editor database values override summary text only if non-empty
Carl Byington <carl@five-ten-sg.com>
parents:
123
diff
changeset
|
326 if (pref == null) continue; |
69db8af9508d
host editor database values override summary text only if non-empty
Carl Byington <carl@five-ten-sg.com>
parents:
123
diff
changeset
|
327 if (pref instanceof CheckBoxPreference) continue; |
130
2a0b10fd128d
host editor database values override summary text only if non-empty
Carl Byington <carl@five-ten-sg.com>
parents:
129
diff
changeset
|
328 CharSequence value = pref.getSummary(); |
127
69db8af9508d
host editor database values override summary text only if non-empty
Carl Byington <carl@five-ten-sg.com>
parents:
123
diff
changeset
|
329 summaries.put(key, value); |
128
377357365d68
host editor database values override summary text only if non-empty
Carl Byington <carl@five-ten-sg.com>
parents:
127
diff
changeset
|
330 } |
127
69db8af9508d
host editor database values override summary text only if non-empty
Carl Byington <carl@five-ten-sg.com>
parents:
123
diff
changeset
|
331 } |
118
9c0aaf27ce28
host editor database values override summary text
Carl Byington <carl@five-ten-sg.com>
parents:
117
diff
changeset
|
332 |
127
69db8af9508d
host editor database values override summary text only if non-empty
Carl Byington <carl@five-ten-sg.com>
parents:
123
diff
changeset
|
333 private void updateSummaries() { |
69db8af9508d
host editor database values override summary text only if non-empty
Carl Byington <carl@five-ten-sg.com>
parents:
123
diff
changeset
|
334 // for all text preferences, set hint as current database value if it is non-empty |
69db8af9508d
host editor database values override summary text only if non-empty
Carl Byington <carl@five-ten-sg.com>
parents:
123
diff
changeset
|
335 for (String key : this.pref.values.keySet()) { |
0 | 336 Preference pref = this.findPreference(key); |
337 if (pref == null) continue; | |
338 if (pref instanceof CheckBoxPreference) continue; | |
339 CharSequence value = this.pref.getString(key, ""); | |
340 | |
341 if (key.equals(HostDatabase.FIELD_HOST_PUBKEYID)) { | |
342 try { | |
127
69db8af9508d
host editor database values override summary text only if non-empty
Carl Byington <carl@five-ten-sg.com>
parents:
123
diff
changeset
|
343 int pubkeyId = Integer.parseInt(value.toString()); |
0 | 344 |
345 if (pubkeyId >= 0) | |
346 pref.setSummary(pubkeydb.getNickname(pubkeyId)); | |
347 else if (pubkeyId == HostDatabase.PUBKEYID_ANY) | |
348 pref.setSummary(R.string.list_pubkeyids_any); | |
349 else if (pubkeyId == HostDatabase.PUBKEYID_NEVER) | |
350 pref.setSummary(R.string.list_pubkeyids_none); | |
351 | |
352 continue; | |
353 } | |
354 catch (NumberFormatException nfe) { | |
355 // Fall through. | |
356 } | |
357 } | |
137
37665a94fc39
listpref value may be null
Carl Byington <carl@five-ten-sg.com>
parents:
131
diff
changeset
|
358 else if ((pref instanceof ListPreference) && (value != null)) { |
0 | 359 ListPreference listPref = (ListPreference) pref; |
131
adf9ca45675b
host editor database values override summary text only if non-empty
Carl Byington <carl@five-ten-sg.com>
parents:
130
diff
changeset
|
360 int entryIndex = listPref.findIndexOfValue(value.toString()); |
127
69db8af9508d
host editor database values override summary text only if non-empty
Carl Byington <carl@five-ten-sg.com>
parents:
123
diff
changeset
|
361 if (entryIndex >= 0) value = listPref.getEntries()[entryIndex]; |
0 | 362 } |
363 | |
129
50e1dead04a1
host editor database values override summary text only if non-empty
Carl Byington <carl@five-ten-sg.com>
parents:
128
diff
changeset
|
364 if ((value == null) || (value.length() == 0)) value = summaries.get(key); |
118
9c0aaf27ce28
host editor database values override summary text
Carl Byington <carl@five-ten-sg.com>
parents:
117
diff
changeset
|
365 pref.setSummary(value); |
0 | 366 } |
367 } | |
368 | |
369 private void initCharsetPref(final ListPreference charsetPref) { | |
370 charsetPref.setEntryValues(CharsetHolder.getCharsetIds()); | |
371 charsetPref.setEntries(CharsetHolder.getCharsetNames()); | |
372 } | |
373 | |
374 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { | |
375 // update values on changed preference | |
376 this.updateSummaries(); | |
377 | |
378 // Our CursorPreferenceHack always send null keys, so try to set charset anyway | |
379 if (hostBridge != null) | |
380 hostBridge.setCharset(sharedPreferences | |
381 .getString(HostDatabase.FIELD_HOST_ENCODING, HostDatabase.ENCODING_DEFAULT)); | |
382 } | |
383 | |
384 public static class CharsetHolder { | |
385 private static boolean initialized = false; | |
386 | |
387 private static CharSequence[] charsetIds; | |
388 private static CharSequence[] charsetNames; | |
389 | |
390 public static CharSequence[] getCharsetNames() { | |
391 if (charsetNames == null) | |
392 initialize(); | |
393 | |
394 return charsetNames; | |
395 } | |
396 | |
397 public static CharSequence[] getCharsetIds() { | |
398 if (charsetIds == null) | |
399 initialize(); | |
400 | |
401 return charsetIds; | |
402 } | |
403 | |
404 private synchronized static void initialize() { | |
405 if (initialized) | |
406 return; | |
407 | |
408 List<CharSequence> charsetIdsList = new LinkedList<CharSequence>(); | |
409 List<CharSequence> charsetNamesList = new LinkedList<CharSequence>(); | |
410 | |
411 for (Entry<String, Charset> entry : Charset.availableCharsets().entrySet()) { | |
412 Charset c = entry.getValue(); | |
413 | |
414 if (c.canEncode() && c.isRegistered()) { | |
415 String key = entry.getKey(); | |
416 | |
417 if (key.startsWith("cp")) { | |
418 // Custom CP437 charset changes | |
419 charsetIdsList.add("CP437"); | |
420 charsetNamesList.add("CP437"); | |
421 } | |
422 | |
423 charsetIdsList.add(entry.getKey()); | |
424 charsetNamesList.add(c.displayName()); | |
425 } | |
426 } | |
427 | |
428 charsetIds = charsetIdsList.toArray(new CharSequence[charsetIdsList.size()]); | |
429 charsetNames = charsetNamesList.toArray(new CharSequence[charsetNamesList.size()]); | |
430 initialized = true; | |
431 } | |
432 | |
433 public static boolean isInitialized() { | |
434 return initialized; | |
435 } | |
436 } | |
437 } |