summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2010-05-01 23:14:07 +0200
committerDavid A. Madore <david+git@madore.org>2010-05-01 23:14:07 +0200
commit1c6eb70f0640269304041982f7514df92b047776 (patch)
tree8e6206a5a0d1a90b45c1c24151012f9718eb5c48 /src
parentd19282f8ce9d4256875e37358eda3ee19527d1f6 (diff)
downloadUnicodeMap-1c6eb70f0640269304041982f7514df92b047776.tar.gz
UnicodeMap-1c6eb70f0640269304041982f7514df92b047776.tar.bz2
UnicodeMap-1c6eb70f0640269304041982f7514df92b047776.zip
New feature: decode Unicode character string.
Diffstat (limited to 'src')
-rw-r--r--src/org/madore/android/unicodeMap/UnicodeArrayAdapter.java5
-rw-r--r--src/org/madore/android/unicodeMap/UnicodeCharacter.java21
-rw-r--r--src/org/madore/android/unicodeMap/UnicodeMapActivity.java90
3 files changed, 114 insertions, 2 deletions
diff --git a/src/org/madore/android/unicodeMap/UnicodeArrayAdapter.java b/src/org/madore/android/unicodeMap/UnicodeArrayAdapter.java
index ecf7348..eb3f794 100644
--- a/src/org/madore/android/unicodeMap/UnicodeArrayAdapter.java
+++ b/src/org/madore/android/unicodeMap/UnicodeArrayAdapter.java
@@ -47,7 +47,10 @@ public class UnicodeArrayAdapter
charTextView = view.findViewById(R.id.charText);
labelTextView = view.findViewById(R.id.labelText);
}
- ((TextView)charTextView).setText(((UnicodeCharacter)item).getChar());
+ if ( ((UnicodeCharacter)item).isPrintable() )
+ ((TextView)charTextView).setText(((UnicodeCharacter)item).getChar());
+ else
+ ((TextView)charTextView).setText("");
((TextView)labelTextView).setText(((UnicodeCharacter)item).getLabel());
} else if ( item instanceof UnicodeRangeable ) {
if ( convertView != null
diff --git a/src/org/madore/android/unicodeMap/UnicodeCharacter.java b/src/org/madore/android/unicodeMap/UnicodeCharacter.java
index 42e449a..5d53ccb 100644
--- a/src/org/madore/android/unicodeMap/UnicodeCharacter.java
+++ b/src/org/madore/android/unicodeMap/UnicodeCharacter.java
@@ -222,6 +222,9 @@ public class UnicodeCharacter implements UnicodeDisplayable {
public int getTo() { return this.to; }
public String getDescr() { return this.descr; }
public String getTitle() { return this.descr; }
+ public boolean belongs(int codePoint) {
+ return ( codePoint>=this.from && codePoint<this.to );
+ }
@Override
public String toString() { return this.descr; }
}
@@ -389,6 +392,7 @@ public class UnicodeCharacter implements UnicodeDisplayable {
protected final int codePoint;
protected final String name;
protected final Category category;
+ protected final boolean isUnicode;
protected final String charStr;
protected final String label;
@@ -407,6 +411,17 @@ public class UnicodeCharacter implements UnicodeDisplayable {
this.codePoint = codePoint;
this.name = name;
this.category = category;
+ this.isUnicode = true;
+ this.charStr = makeCharStr();
+ this.label = makeLabel();
+ }
+
+ public UnicodeCharacter(int codePoint, String name, Category category,
+ boolean isUnicode) {
+ this.codePoint = codePoint;
+ this.name = name;
+ this.category = category;
+ this.isUnicode = isUnicode;
this.charStr = makeCharStr();
this.label = makeLabel();
}
@@ -431,8 +446,12 @@ public class UnicodeCharacter implements UnicodeDisplayable {
return this.label;
}
+ public boolean isUnicode() {
+ return this.isUnicode;
+ }
+
public boolean isPrintable() {
- return printable.contains(this.category);
+ return this.isUnicode && printable.contains(this.category);
}
@Override
diff --git a/src/org/madore/android/unicodeMap/UnicodeMapActivity.java b/src/org/madore/android/unicodeMap/UnicodeMapActivity.java
index 8e93e36..01f5fdb 100644
--- a/src/org/madore/android/unicodeMap/UnicodeMapActivity.java
+++ b/src/org/madore/android/unicodeMap/UnicodeMapActivity.java
@@ -75,6 +75,14 @@ public final class UnicodeMapActivity extends ListActivity {
public int getLimit() { return this.limit; }
public int getSizeHint() { return this.sizeHint; }
}
+ protected static class DecodeDisplay extends Display {
+ protected String coded;
+ public DecodeDisplay(String title, String coded) {
+ super(title);
+ this.coded = coded;
+ }
+ public String getCoded() { return this.coded; }
+ }
protected static class DisplayAndPosition {
protected Display disp;
@@ -227,6 +235,42 @@ public final class UnicodeMapActivity extends ListActivity {
String.format(str, limit),
Toast.LENGTH_SHORT).show();
}
+ } else if ( disp instanceof DecodeDisplay ) {
+ String coded = ((DecodeDisplay)disp).getCoded();
+ list = new ArrayList<UnicodeDisplayable>(coded.length());
+ for ( int i=0 ; i<coded.length() ; i++ ) {
+ int codePoint = coded.codePointAt(i);
+ if ( codePoint >= 0x10000 )
+ i++;
+ UnicodeCharacter ch = db.getSingle(codePoint);
+ if ( ch == null ) {
+ String name; UnicodeCharacter.Category category;
+ if ( codePoint < 0x0020 || ( codePoint >= 0x007f
+ && codePoint < 0x00a0 ) ) {
+ name = String.format("<control-%04X>", codePoint);
+ category = UnicodeCharacter.Category.CONTROL;
+ } else if ( UnicodeCharacter.Range.HIGH_SURROGATES.belongs(codePoint)
+ || UnicodeCharacter.Range.HIGH_PRIVATE_USE_SURROGATES.belongs(codePoint)
+ || UnicodeCharacter.Range.LOW_SURROGATES.belongs(codePoint) ) {
+ name = String.format("<surrogate-%04X>", codePoint);
+ category = UnicodeCharacter.Category.SURROGATE;
+ } else if ( UnicodeCharacter.Range.PRIVATE_USE_AREA.belongs(codePoint)
+ || UnicodeCharacter.Range.SUPPLEMENTARY_PRIVATE_USE_AREA_A.belongs(codePoint)
+ || UnicodeCharacter.Range.SUPPLEMENTARY_PRIVATE_USE_AREA_B.belongs(codePoint) ) {
+ name = String.format("<private-use-%04X>", codePoint);
+ category = UnicodeCharacter.Category.PRIVATE_USE;
+ } else {
+ name = String.format("<noncharacter-%04X>", codePoint);
+ category = UnicodeCharacter.Category.UNASSIGNED;
+ }
+ ch = new UnicodeCharacter(codePoint, name, category,
+ false);
+ }
+ list.add(ch);
+ }
+ disp.setListCache(list);
+ adapter = new UnicodeArrayAdapter(this, list);
+ setListAdapter(adapter);
} else
throw new AssertionError("unknown UnicodeMapActivity.Display");
String title = disp.getTitle();
@@ -499,6 +543,49 @@ public final class UnicodeMapActivity extends ListActivity {
dialog.show();
}
+ protected void doDecode(String s) {
+ Display newDisp = new DecodeDisplay(s, s);
+ saveDisplay();
+ doDisplay(newDisp, true);
+ }
+
+ protected void queryDecode() {
+ final Dialog dialog = new Dialog(UnicodeMapActivity.this);
+ // dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
+ dialog.setTitle(R.string.decode_title);
+ dialog.setOwnerActivity(this);
+ dialog.setContentView(R.layout.decode_dialog);
+ dialog.setCancelable(true);
+ dialog.getWindow().setLayout(ViewGroup.LayoutParams.FILL_PARENT,
+ ViewGroup.LayoutParams.WRAP_CONTENT);
+ final EditText textForm
+ = (EditText) dialog.findViewById(R.id.decodeString);
+ textForm.setOnKeyListener(new View.OnKeyListener() {
+ public boolean onKey(View view, int keyCode, KeyEvent event) {
+ if ( ( event.getAction() == KeyEvent.ACTION_DOWN )
+ && ( keyCode == KeyEvent.KEYCODE_ENTER ) ) {
+ String s = textForm.getText().toString();
+ if ( ! Pattern.matches("^\\s*$", s) ) {
+ doDecode(s);
+ dialog.dismiss();
+ }
+ return true;
+ }
+ return false;
+ }
+ });
+ final Button btn = (Button) dialog.findViewById(R.id.decodeButton);
+ btn.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View view) {
+ String s = textForm.getText().toString();
+ if ( ! Pattern.matches("^\\s*$", s) )
+ doDecode(s);
+ dialog.dismiss();
+ }
+ });
+ dialog.show();
+ }
+
protected void displayAbout() {
final Dialog dialog = new Dialog(UnicodeMapActivity.this);
dialog.setTitle(R.string.about_title);
@@ -548,6 +635,9 @@ public final class UnicodeMapActivity extends ListActivity {
case R.id.menuSearch:
querySearch();
return true;
+ case R.id.menuDecode:
+ queryDecode();
+ return true;
case R.id.menuAbout:
displayAbout();
return true;