From 3141ca4e4f232a4efae252fcdb15cc8f84e72fed Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Fri, 16 Mar 2012 18:49:50 +0100 Subject: Add copy and append buttons to character popup. --- .../android/unicodeMap/UnicodeMapActivity.java | 27 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'src/org/madore') diff --git a/src/org/madore/android/unicodeMap/UnicodeMapActivity.java b/src/org/madore/android/unicodeMap/UnicodeMapActivity.java index 9db0476..f82382b 100644 --- a/src/org/madore/android/unicodeMap/UnicodeMapActivity.java +++ b/src/org/madore/android/unicodeMap/UnicodeMapActivity.java @@ -29,6 +29,7 @@ public final class UnicodeMapActivity extends ListActivity { protected UnicodeDatabase db; protected ListView lv; + protected ClipboardManager cmgr; protected static abstract class Display { protected String title; @@ -300,11 +301,11 @@ public final class UnicodeMapActivity extends ListActivity { } public boolean onItemLongClick(AdapterView parent, View view, int position, long id) { - UnicodeDisplayable it + final UnicodeDisplayable it = (UnicodeDisplayable)parent.getItemAtPosition(position); if ( it instanceof UnicodeCharacter ) { - UnicodeCharacter itch = (UnicodeCharacter)it; - Dialog dialog = new Dialog(UnicodeMapActivity.this); + final UnicodeCharacter itch = (UnicodeCharacter)it; + final Dialog dialog = new Dialog(UnicodeMapActivity.this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setOwnerActivity(UnicodeMapActivity.this); dialog.setContentView(R.layout.char_details); @@ -327,6 +328,23 @@ public final class UnicodeMapActivity extends ListActivity { text.setText(new String(s)); text = (TextView) dialog.findViewById(R.id.categoryLabel); text.setText(itch.getCategory().getDescr()); + final Button copyCharButton = (Button) dialog.findViewById(R.id.copyCharButton); + copyCharButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View view) { + dialog.dismiss(); + cmgr.setText(itch.getChar()); + Toast.makeText(UnicodeMapActivity.this, + R.string.copied_toast, + Toast.LENGTH_SHORT).show(); + } + }); + final Button appendCharButton = (Button) dialog.findViewById(R.id.appendCharButton); + appendCharButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View view) { + dialog.dismiss(); + textForm.append(itch.getChar()); + } + }); if ( UnicodeCharacter.Range.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A.belongs(itch) || UnicodeCharacter.Range.CJK_UNIFIED_IDEOGRAPHS.belongs(itch) || UnicodeCharacter.Range.CJK_COMPATIBILITY_IDEOGRAPHS.belongs(itch) @@ -393,6 +411,7 @@ public final class UnicodeMapActivity extends ListActivity { if ( needPopulate ) launchPopulation(); lv = getListView(); + cmgr = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE); Object testament = getLastNonConfigurationInstance(); if ( testament != null ) { @SuppressWarnings("unchecked") @@ -405,8 +424,6 @@ public final class UnicodeMapActivity extends ListActivity { lv.setSelectionFromTop(saved.getSelPosition(), saved.getYOffset()); } else doDisplay(new RootDisplay(), true); - final ClipboardManager cmgr - = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE); final Button btn = (Button) findViewById(R.id.copyButton); textForm = (EditText) findViewById(R.id.edit); btn.setOnClickListener(new View.OnClickListener() { -- cgit v1.2.3