Mercurial > 510Connectbot
annotate src/com/five_ten_sg/connectbot/HostEditorActivity.java @ 128:377357365d68
host editor database values override summary text only if non-empty
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 19 Jun 2014 09:42:09 -0700 |
parents | 69db8af9508d |
children | 50e1dead04a1 |
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>(); | |
127
69db8af9508d
host editor database values override summary text only if non-empty
Carl Byington <carl@five-ten-sg.com>
parents:
123
diff
changeset
|
58 protected Map<String, CharSequence> summaries = new HashMap<String, CharSequence>(); |
0 | 59 |
60 public CursorPreferenceHack(String table, long id) { | |
61 this.table = table; | |
62 this.id = id; | |
63 cacheValues(); | |
64 } | |
65 | |
66 protected final void cacheValues() { | |
67 // fill a cursor and cache the values locally | |
68 // this makes sure we dont have any floating cursor to dispose later | |
69 SQLiteDatabase db = hostdb.getReadableDatabase(); | |
70 Cursor cursor = db.query(table, null, "_id = ?", | |
71 new String[] { String.valueOf(id) }, null, null, null); | |
72 | |
73 if (cursor.moveToFirst()) { | |
74 for (int i = 0; i < cursor.getColumnCount(); i++) { | |
75 String key = cursor.getColumnName(i); | |
76 | |
77 if (key.equals(HostDatabase.FIELD_HOST_HOSTKEY)) continue; | |
78 | |
79 String value = cursor.getString(i); | |
80 values.put(key, value); | |
81 } | |
82 } | |
83 | |
84 cursor.close(); | |
85 db.close(); | |
86 } | |
87 | |
88 public boolean contains(String key) { | |
89 return values.containsKey(key); | |
90 } | |
91 | |
92 public class Editor implements SharedPreferences.Editor { | |
93 | |
94 private ContentValues update = new ContentValues(); | |
95 | |
96 public SharedPreferences.Editor clear() { | |
97 Log.d(this.getClass().toString(), "clear()"); | |
98 update = new ContentValues(); | |
99 return this; | |
100 } | |
101 | |
102 public boolean commit() { | |
103 //Log.d(this.getClass().toString(), "commit() changes back to database"); | |
104 SQLiteDatabase db = hostdb.getWritableDatabase(); | |
105 db.update(table, update, "_id = ?", new String[] { String.valueOf(id) }); | |
106 db.close(); | |
107 // make sure we refresh the parent cached values | |
108 cacheValues(); | |
109 | |
110 // and update any listeners | |
111 for (OnSharedPreferenceChangeListener listener : listeners) { | |
112 listener.onSharedPreferenceChanged(CursorPreferenceHack.this, null); | |
113 } | |
114 | |
115 return true; | |
116 } | |
117 | |
118 // Gingerbread compatibility | |
119 public void apply() { | |
120 commit(); | |
121 } | |
122 | |
123 public android.content.SharedPreferences.Editor putBoolean(String key, boolean value) { | |
124 return this.putString(key, Boolean.toString(value)); | |
125 } | |
126 | |
127 public android.content.SharedPreferences.Editor putFloat(String key, float value) { | |
128 return this.putString(key, Float.toString(value)); | |
129 } | |
130 | |
131 public android.content.SharedPreferences.Editor putInt(String key, int value) { | |
132 return this.putString(key, Integer.toString(value)); | |
133 } | |
134 | |
135 public android.content.SharedPreferences.Editor putLong(String key, long value) { | |
136 return this.putString(key, Long.toString(value)); | |
137 } | |
138 | |
139 public android.content.SharedPreferences.Editor putString(String key, String value) { | |
140 //Log.d(this.getClass().toString(), String.format("Editor.putString(key=%s, value=%s)", key, value)); | |
141 update.put(key, value); | |
142 return this; | |
143 } | |
144 | |
145 public android.content.SharedPreferences.Editor remove(String key) { | |
146 //Log.d(this.getClass().toString(), String.format("Editor.remove(key=%s)", key)); | |
147 update.remove(key); | |
148 return this; | |
149 } | |
150 | |
151 public android.content.SharedPreferences.Editor putStringSet(String key, Set<String> value) { | |
152 throw new UnsupportedOperationException("HostEditor Prefs do not support Set<String>"); | |
153 } | |
154 } | |
155 | |
156 | |
157 public Editor edit() { | |
158 //Log.d(this.getClass().toString(), "edit()"); | |
159 return new Editor(); | |
160 } | |
161 | |
162 public Map<String, ?> getAll() { | |
163 return values; | |
164 } | |
165 | |
166 public boolean getBoolean(String key, boolean defValue) { | |
167 return Boolean.valueOf(this.getString(key, Boolean.toString(defValue))); | |
168 } | |
169 | |
170 public float getFloat(String key, float defValue) { | |
171 return Float.valueOf(this.getString(key, Float.toString(defValue))); | |
172 } | |
173 | |
174 public int getInt(String key, int defValue) { | |
175 return Integer.valueOf(this.getString(key, Integer.toString(defValue))); | |
176 } | |
177 | |
178 public long getLong(String key, long defValue) { | |
179 return Long.valueOf(this.getString(key, Long.toString(defValue))); | |
180 } | |
181 | |
182 public String getString(String key, String defValue) { | |
183 //Log.d(this.getClass().toString(), String.format("getString(key=%s, defValue=%s)", key, defValue)); | |
184 if (!values.containsKey(key)) return defValue; | |
185 | |
186 return values.get(key); | |
187 } | |
188 | |
189 public Set<String> getStringSet(String key, Set<String> defValue) { | |
190 throw new ClassCastException("HostEditor Prefs do not support Set<String>"); | |
191 } | |
192 | |
193 protected List<OnSharedPreferenceChangeListener> listeners = new LinkedList<OnSharedPreferenceChangeListener>(); | |
194 | |
195 public void registerOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener listener) { | |
196 listeners.add(listener); | |
197 } | |
198 | |
199 public void unregisterOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener listener) { | |
200 listeners.remove(listener); | |
201 } | |
202 | |
203 } | |
204 | |
205 @Override | |
206 public SharedPreferences getSharedPreferences(String name, int mode) { | |
207 //Log.d(this.getClass().toString(), String.format("getSharedPreferences(name=%s)", name)); | |
208 return this.pref; | |
209 } | |
210 | |
211 protected static final String TAG = "ConnectBot.HostEditorActivity"; | |
212 | |
213 protected HostDatabase hostdb = null; | |
214 private PubkeyDatabase pubkeydb = null; | |
215 | |
216 private CursorPreferenceHack pref; | |
217 private ServiceConnection connection; | |
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; |
69db8af9508d
host editor database values override summary text only if non-empty
Carl Byington <carl@five-ten-sg.com>
parents:
123
diff
changeset
|
328 CharSequence value = this.pref.getSummary(key, ""); |
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 } | |
358 else if (pref instanceof ListPreference) { | |
359 ListPreference listPref = (ListPreference) pref; | |
127
69db8af9508d
host editor database values override summary text only if non-empty
Carl Byington <carl@five-ten-sg.com>
parents:
123
diff
changeset
|
360 int entryIndex = listPref.findIndexOfValue(value); |
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 | |
127
69db8af9508d
host editor database values override summary text only if non-empty
Carl Byington <carl@five-ten-sg.com>
parents:
123
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 } |