1 package org.connectbot.util; 2 3 import android.content.Context; 4 import android.preference.ListPreference; 5 import android.util.AttributeSet; 6 7 import java.nio.charset.Charset; 8 import java.util.LinkedList; 9 import java.util.List; 10 import java.util.Map.Entry; 11 12 public class EncodingPreference extends ListPreference { 13 EncodingPreference(Context context, AttributeSet attrs)14 public EncodingPreference(Context context, AttributeSet attrs) { 15 super(context, attrs); 16 17 List<CharSequence> charsetIdsList = new LinkedList<CharSequence>(); 18 List<CharSequence> charsetNamesList = new LinkedList<CharSequence>(); 19 20 for (Entry<String, Charset> entry : Charset.availableCharsets().entrySet()) { 21 Charset c = entry.getValue(); 22 if (c.canEncode() && c.isRegistered()) { 23 String key = entry.getKey(); 24 if (key.startsWith("cp")) { 25 // Custom CP437 charset changes 26 charsetIdsList.add("CP437"); 27 charsetNamesList.add("CP437"); 28 } 29 charsetIdsList.add(entry.getKey()); 30 charsetNamesList.add(c.displayName()); 31 } 32 } 33 34 this.setEntryValues(charsetIdsList.toArray(new CharSequence[charsetIdsList.size()])); 35 this.setEntries(charsetNamesList.toArray(new CharSequence[charsetNamesList.size()])); 36 } 37 } 38