From 1c6eb70f0640269304041982f7514df92b047776 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Sat, 1 May 2010 23:14:07 +0200 Subject: New feature: decode Unicode character string. --- .../android/unicodeMap/UnicodeArrayAdapter.java | 5 +- .../android/unicodeMap/UnicodeCharacter.java | 21 ++++- .../android/unicodeMap/UnicodeMapActivity.java | 90 ++++++++++++++++++++++ 3 files changed, 114 insertions(+), 2 deletions(-) (limited to 'src/org') 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(coded.length()); + for ( int i=0 ; i= 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("", 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("", 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("", codePoint); + category = UnicodeCharacter.Category.PRIVATE_USE; + } else { + name = String.format("", 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; -- cgit v1.2.3