diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java index a4355ab0a..777ef81a6 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java @@ -1020,7 +1020,7 @@ public class BoardDelegate extends DelegateBase String curDict = m_gi.dictName( m_view.getCurPlayer() ); View button = m_toolbar.getViewFor( Toolbar.BUTTON_BROWSE_DICT ); if ( Action.BUTTON_BROWSEALL_ACTION == action && - DictsActivity.handleDictsPopup( m_activity, button, + DictsDelegate.handleDictsPopup( m_activity, button, curDict, m_gi.dictLang ) ){ break; } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java index 8c50fa365..d5e90814f 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java @@ -26,7 +26,6 @@ import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.widget.PopupMenu; import java.util.HashMap; @@ -35,11 +34,6 @@ import org.eehouse.android.xw4.loc.LocUtils; public class DictsActivity extends XWActivity { - private static interface SafePopup { - public void doPopup( Context context, View button, - String curDict, int lang ); - } - private static SafePopup s_safePopup = null; // I can't provide a subclass of MenuItem to hold DictAndLoc, so // settle for a hash on the side. private DictsDelegate m_dlgt; @@ -51,64 +45,6 @@ public class DictsActivity extends XWActivity { super.onCreate( savedInstanceState, m_dlgt ); } // onCreate - private static class SafePopupImpl implements SafePopup { - public void doPopup( final Context context, View button, - String curDict, int lang ) { - - final HashMap itemData - = new HashMap(); - - MenuItem.OnMenuItemClickListener listener = - new MenuItem.OnMenuItemClickListener() { - public boolean onMenuItemClick( MenuItem item ) - { - DictAndLoc dal = itemData.get( item ); - - DictBrowseDelegate.launch( context, dal.name, - dal.loc ); - return true; - } - }; - - PopupMenu popup = new PopupMenu( context, button ); - Menu menu = popup.getMenu(); - - // Add at top but save until have dal info - MenuItem curItem = - menu.add( LocUtils.getString( context, - R.string.cur_menu_marker_fmt, - curDict ) ); - - DictAndLoc[] dals = DictLangCache.getDALsHaveLang( context, lang ); - for ( DictAndLoc dal : dals ) { - MenuItem item = dal.name.equals(curDict) - ? curItem : menu.add( dal.name ); - item.setOnMenuItemClickListener( listener ); - itemData.put( item, dal ); - } - - popup.show(); - } - } - - public static boolean handleDictsPopup( Context context, View button, - String curDict, int lang ) - { - int nDicts = DictLangCache.getLangCount( context, lang ); - if ( null == s_safePopup && 1 < nDicts ) { - int sdkVersion = Integer.valueOf( android.os.Build.VERSION.SDK ); - if ( 11 <= sdkVersion ) { - s_safePopup = new SafePopupImpl(); - } - } - - boolean canHandle = null != s_safePopup && 1 < nDicts; - if ( canHandle ) { - s_safePopup.doPopup( context, button, curDict, lang ); - } - return canHandle; - } - public static void start( Context context ) { Intent intent = new Intent( context, DictsActivity.class ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java index 58958f9f0..fb1707a38 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsDelegate.java @@ -44,6 +44,7 @@ import android.widget.Button; import android.widget.CheckBox; import android.widget.LinearLayout; import android.widget.ListView; +import android.widget.PopupMenu; import android.widget.TextView; import java.net.HttpURLConnection; @@ -107,6 +108,52 @@ public class DictsDelegate extends ListDelegateBase private String m_lastDict; private String m_noteNone; + private static interface SafePopup { + public void doPopup( Context context, View button, + String curDict, int lang ); + } + private static SafePopup s_safePopup = null; + + private static class SafePopupImpl implements SafePopup { + public void doPopup( final Context context, View button, + String curDict, int lang ) { + + final HashMap itemData + = new HashMap(); + + MenuItem.OnMenuItemClickListener listener = + new MenuItem.OnMenuItemClickListener() { + public boolean onMenuItemClick( MenuItem item ) + { + DictAndLoc dal = itemData.get( item ); + + DictBrowseDelegate.launch( context, dal.name, + dal.loc ); + return true; + } + }; + + PopupMenu popup = new PopupMenu( context, button ); + Menu menu = popup.getMenu(); + + // Add at top but save until have dal info + MenuItem curItem = + menu.add( LocUtils.getString( context, + R.string.cur_menu_marker_fmt, + curDict ) ); + + DictAndLoc[] dals = DictLangCache.getDALsHaveLang( context, lang ); + for ( DictAndLoc dal : dals ) { + MenuItem item = dal.name.equals(curDict) + ? curItem : menu.add( dal.name ); + item.setOnMenuItemClickListener( listener ); + itemData.put( item, dal ); + } + + popup.show(); + } + } + private static class DictInfo implements Comparable { public String m_name; public String m_lang; @@ -1017,6 +1064,24 @@ public class DictsDelegate extends ListDelegateBase new GetDefaultDictTask( context, lc, lstnr ).execute(); } + public static boolean handleDictsPopup( Context context, View button, + String curDict, int lang ) + { + int nDicts = DictLangCache.getLangCount( context, lang ); + if ( null == s_safePopup && 1 < nDicts ) { + int sdkVersion = Integer.valueOf( android.os.Build.VERSION.SDK ); + if ( 11 <= sdkVersion ) { + s_safePopup = new SafePopupImpl(); + } + } + + boolean canHandle = null != s_safePopup && 1 < nDicts; + if ( canHandle ) { + s_safePopup.doPopup( context, button, curDict, lang ); + } + return canHandle; + } + ////////////////////////////////////////////////////////////////////// // XWListItem.ExpandedListener interface //////////////////////////////////////////////////////////////////////