summaryrefslogtreecommitdiffstats
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
parentd19282f8ce9d4256875e37358eda3ee19527d1f6 (diff)
downloadUnicodeMap-1c6eb70f0640269304041982f7514df92b047776.tar.gz
UnicodeMap-1c6eb70f0640269304041982f7514df92b047776.tar.bz2
UnicodeMap-1c6eb70f0640269304041982f7514df92b047776.zip
New feature: decode Unicode character string.
-rw-r--r--res/layout/decode_dialog.xml25
-rw-r--r--res/menu/options_menu.xml2
-rw-r--r--res/values/strings.xml5
-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
6 files changed, 146 insertions, 2 deletions
diff --git a/res/layout/decode_dialog.xml b/res/layout/decode_dialog.xml
new file mode 100644
index 0000000..0cb1f20
--- /dev/null
+++ b/res/layout/decode_dialog.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:padding="10dp"
+ android:orientation="vertical">
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+ <EditText android:id="@+id/decodeString"
+ android:layout_width="0dip"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:maxLength="1000" />
+ <Button android:id="@+id/decodeButton"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:text="@string/decode_button" />
+ </LinearLayout>
+ <TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/decode_hint" />
+</LinearLayout>
diff --git a/res/menu/options_menu.xml b/res/menu/options_menu.xml
index d101b1f..34671d0 100644
--- a/res/menu/options_menu.xml
+++ b/res/menu/options_menu.xml
@@ -4,6 +4,8 @@
android:title="@string/menu_go" />
<item android:id="@+id/menuSearch"
android:title="@string/menu_search" />
+ <item android:id="@+id/menuDecode"
+ android:title="@string/menu_decode" />
<item android:id="@+id/menuAbout"
android:title="@string/menu_about" />
</menu>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 6efe70c..9dd3d63 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -22,6 +22,11 @@
be searched</string>
<string name="search_results">search results</string>
<string name="list_too_long">Only %d first results shown</string>
+ <string name="menu_decode">Decode</string>
+ <string name="decode_title">Decode string</string>
+ <string name="decode_button">Decode</string>
+ <string name="decode_hint">Paste Unicode characters here to see
+ their names</string>
<string name="menu_about">About</string>
<string name="about_title">About Unicode Map</string>
<string name="about_text">Unicode Map version 0.0.2\nby David
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;