From fd817a98dad38d516edf019a8c48f8e162bf3ca0 Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 19 Mar 2014 21:29:20 -0700 Subject: [PATCH] implement menus, including adding crappy placeholder icons --- xwords4/android/XWords4/img_src/clear_all.svg | 19 +++++ .../android/XWords4/img_src/select_all.svg | 17 +++++ .../android/XWords4/res/menu/studylist.xml | 16 +++-- .../android/XWords4/res/values/strings.xml | 8 +-- .../src/org/eehouse/android/xw4/DBUtils.java | 16 ++++- .../org/eehouse/android/xw4/StudyList.java | 71 +++++++++++++++---- 6 files changed, 121 insertions(+), 26 deletions(-) create mode 100644 xwords4/android/XWords4/img_src/clear_all.svg create mode 100644 xwords4/android/XWords4/img_src/select_all.svg diff --git a/xwords4/android/XWords4/img_src/clear_all.svg b/xwords4/android/XWords4/img_src/clear_all.svg new file mode 100644 index 000000000..0fd5926f8 --- /dev/null +++ b/xwords4/android/XWords4/img_src/clear_all.svg @@ -0,0 +1,19 @@ + + + + + + + image/svg+xml + + Gnome Symbolic Icon Theme + + + + Gnome Symbolic Icon Theme + + + + + + diff --git a/xwords4/android/XWords4/img_src/select_all.svg b/xwords4/android/XWords4/img_src/select_all.svg new file mode 100644 index 000000000..af8fae650 --- /dev/null +++ b/xwords4/android/XWords4/img_src/select_all.svg @@ -0,0 +1,17 @@ + + + + + + + image/svg+xml + + Gnome Symbolic Icon Theme + + + + Gnome Symbolic Icon Theme + + + + diff --git a/xwords4/android/XWords4/res/menu/studylist.xml b/xwords4/android/XWords4/res/menu/studylist.xml index 34b9ef0fa..64903be5a 100644 --- a/xwords4/android/XWords4/res/menu/studylist.xml +++ b/xwords4/android/XWords4/res/menu/studylist.xml @@ -1,22 +1,26 @@ - - - - diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index 0a25c5e30..96c014072 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -2207,10 +2207,10 @@ of words to remember Studylist… - Copy to clipboard - Delete + Copy to clipboard + Delete Are you sure you want to - delete this list?\n\n(This action cannot be undone.) + delete the selected words?\n\n(This action cannot be undone.) %d word[s] copied %s added to list Studylist for %s @@ -2222,7 +2222,7 @@ You have not yet saved any words into a studylist. - The words in this list will be + The selected words will be copied to the system clipboard. You can then paste them into any app that supports pasting text, e.g. an email app. diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java index d4bffa9e6..2ef1724f5 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java @@ -1665,9 +1665,18 @@ public class DBUtils { return result; } - public static void studyListClear( Context context, int lang ) + public static void studyListClear( Context context, int lang, String[] words ) { String selection = String.format( "%s = %d", DBHelper.LANGUAGE, lang ); + if ( null != words ) { + String[] inQuotes = new String[words.length]; + for ( int ii = 0; ii < inQuotes.length; ++ii ) { + inQuotes[ii] = String.format( "'%s'", words[ii] ); + } + String wordsTest = String.format( " AND %s in (%s)", DBHelper.WORD, + TextUtils.join(",", inQuotes) ); + selection += wordsTest; + } initDB( context ); synchronized( s_dbHelper ) { @@ -1677,6 +1686,11 @@ public class DBUtils { } } + public static void studyListClear( Context context, int lang ) + { + studyListClear( context, lang, null ); + } + private static void copyGameDB( Context context, boolean toSDCard ) { String name = DBHelper.getDBName(); 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 a4c1d4bd9..a119a88a0 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/StudyList.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/StudyList.java @@ -37,6 +37,7 @@ import android.widget.ArrayAdapter; import android.widget.Spinner; import java.util.Arrays; import java.util.HashSet; +import java.util.Iterator; import junit.framework.Assert; @@ -74,6 +75,15 @@ public class StudyList extends XWListActivity initOrFinish( getIntent() ); } + @Override + public void onBackPressed() { + if ( 0 == m_checkeds.size() ) { + super.onBackPressed(); + } else { + clearSels(); + } + } + @Override public boolean onCreateOptionsMenu( Menu menu ) { @@ -81,37 +91,40 @@ public class StudyList extends XWListActivity return true; } - // @Override - // public boolean onPrepareOptionsMenu( Menu menu ) - // { - // return true; - // } + @Override + public boolean onPrepareOptionsMenu( Menu menu ) + { + int nSel = m_checkeds.size(); + Utils.setItemVisible( menu, R.id.slmenu_copy_sel, 0 < nSel ); + Utils.setItemVisible( menu, R.id.slmenu_clear_sel, 0 < nSel ); + Utils.setItemVisible( menu, R.id.slmenu_select_all, m_words.length > nSel ); + Utils.setItemVisible( menu, R.id.slmenu_deselect_all, 0 < nSel ); + return super.onPrepareOptionsMenu( menu ); + } public boolean onOptionsItemSelected( MenuItem item ) { boolean handled = true; switch ( item.getItemId() ) { - case R.id.copy_all: + case R.id.slmenu_copy_sel: showNotAgainDlgThen( R.string.not_again_studycopy, R.string.key_na_studycopy, Action.SL_COPY_ACTION ); break; - case R.id.clear_all: + case R.id.slmenu_clear_sel: showConfirmThen( R.string.confirm_studylist_clear, Action.SL_CLEAR_ACTION ); break; - case R.id.select_all: + case R.id.slmenu_select_all: for ( int ii = 0; ii < m_words.length; ++ii ) { m_checkeds.add( ii ); } makeAdapter(); setTitleBar(); break; - case R.id.deselect_all: - m_checkeds.clear(); - makeAdapter(); - setTitleBar(); + case R.id.slmenu_deselect_all: + clearSels(); break; default: @@ -129,15 +142,20 @@ public class StudyList extends XWListActivity if ( AlertDialog.BUTTON_POSITIVE == which ) { switch ( action ) { case SL_CLEAR_ACTION: - DBUtils.studyListClear( this, m_langCodes[m_langPosition] ); + String[] selWords = getSelWords(); + if ( selWords.length == m_words.length ) { + selWords = null; // all: easier on DB :-) + } + DBUtils.studyListClear( this, m_langCodes[m_langPosition], selWords ); initOrFinish( null ); break; case SL_COPY_ACTION: + selWords = getSelWords(); ClipboardManager clipboard = (ClipboardManager) getSystemService( Context.CLIPBOARD_SERVICE ); - clipboard.setText( TextUtils.join( "\n", m_words ) ); + clipboard.setText( TextUtils.join( "\n", selWords ) ); - String msg = getString( R.string.paste_donef, m_words.length ); + String msg = getString( R.string.paste_donef, selWords.length ); Utils.showToast( this, msg ); break; default: @@ -269,6 +287,29 @@ public class StudyList extends XWListActivity setTitle( newTitle ); } + private String[] getSelWords() + { + String[] result; + int nSels = m_checkeds.size(); + if ( nSels == m_words.length ) { + result = m_words; + } else { + result = new String[nSels]; + Iterator iter = m_checkeds.iterator(); + for ( int ii = 0; iter.hasNext(); ++ii ) { + result[ii] = m_words[iter.next()]; + } + } + return result; + } + + private void clearSels() + { + m_checkeds.clear(); + makeAdapter(); + setTitleBar(); + } + public static void launchOrAlert( Context context, int lang, DlgDelegate.HasDlgDelegate dlg ) {