From 2520fb4c057307004f44ec18a5874f9d074f009c Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 29 Jan 2014 07:15:25 -0800 Subject: [PATCH] add menu and implement copy-to-clipboard --- .../android/XWords4/res/menu/studylist.xml | 11 +++++ .../android/XWords4/res/values/strings.xml | 4 ++ .../org/eehouse/android/xw4/StudyList.java | 48 ++++++++++++++++--- 3 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 xwords4/android/XWords4/res/menu/studylist.xml diff --git a/xwords4/android/XWords4/res/menu/studylist.xml b/xwords4/android/XWords4/res/menu/studylist.xml new file mode 100644 index 000000000..be7ce6e37 --- /dev/null +++ b/xwords4/android/XWords4/res/menu/studylist.xml @@ -0,0 +1,11 @@ + + + + + + + diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index 622395a00..e73c761c5 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -2210,4 +2210,8 @@ of words to remember Study list… Choose list language + + Copy to clipboard + Clear all + diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/StudyList.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/StudyList.java index dd146333b..71b81b8d3 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/StudyList.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/StudyList.java @@ -19,20 +19,26 @@ package org.eehouse.android.xw4; -import android.view.View; import android.content.Context; import android.content.Intent; import android.os.Bundle; -import android.widget.Spinner; -import android.widget.ArrayAdapter; -import android.widget.AdapterView; +import android.text.ClipboardManager; +import android.text.TextUtils; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; import android.widget.AdapterView.OnItemSelectedListener; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Spinner; public class StudyList extends XWListActivity implements OnItemSelectedListener { private Spinner m_spinner; private int[] m_langCodes; + private String[] m_words; @Override protected void onCreate( Bundle savedInstanceState ) @@ -66,6 +72,36 @@ public class StudyList extends XWListActivity } } + @Override + public boolean onCreateOptionsMenu( Menu menu ) + { + getMenuInflater().inflate( R.menu.studylist, menu ); + return true; + } + + // @Override + // public boolean onPrepareOptionsMenu( Menu menu ) + // { + // return true; + // } + + public boolean onOptionsItemSelected( MenuItem item ) + { + boolean handled = true; + switch ( item.getItemId() ) { + case R.id.copy_all: + ClipboardManager clipboard = (ClipboardManager) + getSystemService(Context.CLIPBOARD_SERVICE); + clipboard.setText( TextUtils.join( "\n", m_words ) ); + break; + case R.id.clear_all: + break; + default: + handled = false; + } + return handled; + } + ////////////////////////////////////////////////// // AdapterView.OnItemSelectedListener interface ////////////////////////////////////////////////// @@ -82,10 +118,10 @@ public class StudyList extends XWListActivity private void loadList( int lang ) { - String[] words = DBUtils.studyListWords( this, lang ); + m_words = DBUtils.studyListWords( this, lang ); ArrayAdapter adapter = new ArrayAdapter ( this, android.R.layout.simple_list_item_1 ); - for ( String word : words ) { + for ( String word : m_words ) { adapter.add( word ); } // adapter.sort();