part one of modernizing wordlists browser: long-tap selects and

de-selects, but menus aren't updated and don't work.
This commit is contained in:
Eric House 2013-10-30 07:03:15 -07:00
parent dbf76287a8
commit eefcd18fa8
6 changed files with 256 additions and 83 deletions

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="120"
height="120" xml:space="preserve">
<g
id="g12"
transform="matrix(1.25,0,0,-1.25,0,120)">
<g transform='translate(47.72,32.35)' id='g676'>
<path style='fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none' d='M 0,0 -16.37,22.32 -6.158,22.32 -6.158,43.16 6.056,43.16 6.056,22.32 16.37,22.32 0,0 z M -33.34,-5.839 -33.34,-11.85 33.9,-11.85 33.89,-5.839 -33.34,-5.839 z' id='path678'/>
</g></g>
</svg>

After

Width:  |  Height:  |  Size: 664 B

View file

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/dicts_item_move"
android:title="@string/dicts_item_move"
/>
<item android:id="@+id/dicts_item_select"
android:title="@string/dicts_item_select"
/>
</menu>

View file

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/dicts_download"
android:title="@string/download_dicts"
android:icon="@drawable/download__gen"
android:showAsAction="ifRoom"
/>
<item android:id="@+id/dicts_delete"
android:title="@string/list_item_delete"
android:icon="@drawable/content_discard__gen"
android:showAsAction="ifRoom"
/>
<item android:id="@+id/dicts_move"
android:title="@string/dicts_item_move"
/>
<item android:id="@+id/dicts_select"
android:title="@string/dicts_item_select"
/>
</menu>

View file

@ -2156,4 +2156,5 @@
<string name="sel_gamesf">Games: %d"</string>
<string name="sel_groupsf">Groups: %d"</string>
<string name="sel_dictsf">Wordlists: %d"</string>
</resources>

View file

@ -33,8 +33,6 @@ import android.database.DataSetObserver;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -43,23 +41,28 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
import android.widget.ExpandableListView;
import android.widget.AdapterView;
import android.widget.PopupMenu;
import android.widget.TextView;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import junit.framework.Assert;
import org.eehouse.android.xw4.DictUtils.DictAndLoc;
import org.eehouse.android.xw4.jni.XwJNI;
import org.eehouse.android.xw4.jni.JNIUtilsImpl;
import org.eehouse.android.xw4.jni.GameSummary;
import org.eehouse.android.xw4.DictUtils.DictLoc;
public class DictsActivity extends XWExpandableListActivity
implements View.OnClickListener, XWListItem.DeleteCallback,
implements View.OnClickListener,
AdapterView.OnItemLongClickListener,
XWListItem.DeleteCallback, SelectableItem,
MountEventReceiver.SDCardNotifiee, DlgDelegate.DlgClickNotify,
DictImportActivity.DownloadFinishedListener {
@ -98,6 +101,8 @@ public class DictsActivity extends XWExpandableListActivity
private ExpandableListView m_expView;
private String[] m_locNames;
private DictListAdapter m_adapter;
private HashSet<XWListItem> m_selDicts;
private CharSequence m_origTitle;
private long m_packedPosition;
private DictLoc m_moveFromLoc;
@ -144,6 +149,7 @@ public class DictsActivity extends XWExpandableListActivity
if ( null == view ) {
view = (XWListItem)
m_factory.inflate( R.layout.list_item, null );
view.setSelCB( DictsActivity.this );
int lang = (int)getGroupId( groupPosition );
DictAndLoc[] dals = DictLangCache.getDALsHaveLang( m_context,
@ -411,15 +417,13 @@ public class DictsActivity extends XWExpandableListActivity
setContentView( R.layout.dict_browse );
m_expView = getExpandableListView();
registerForContextMenu( m_expView );
m_expView.setOnItemLongClickListener( this );
Button download = (Button)findViewById( R.id.download );
download.setOnClickListener( this );
mkListAdapter();
// showNotAgainDlg( R.string.not_again_dicts,
// R.string.key_notagain_dicts );
m_selDicts = new HashSet<XWListItem>();
Intent intent = getIntent();
if ( null != intent ) {
@ -436,6 +440,8 @@ public class DictsActivity extends XWExpandableListActivity
downloadNewDict( intent );
}
}
m_origTitle = getTitle();
} // onCreate
@Override
@ -495,67 +501,110 @@ public class DictsActivity extends XWExpandableListActivity
}
@Override
public void onCreateContextMenu( ContextMenu menu, View view,
ContextMenuInfo menuInfo )
{
super.onCreateContextMenu( menu, view, menuInfo );
ExpandableListView.ExpandableListContextMenuInfo info
= (ExpandableListView.ExpandableListContextMenuInfo)menuInfo;
long packedPosition = info.packedPosition;
int childPosition = ExpandableListView.
getPackedPositionChild( packedPosition );
// int groupPosition = ExpandableListView.
// getPackedPositionGroup( packedPosition );
// DbgUtils.logf( "onCreateContextMenu: group: %d; child: %d",
// groupPosition, childPosition );
// We don't have a menu yet for languages, just for their dict
// children
if ( childPosition >= 0 ) {
MenuInflater inflater = getMenuInflater();
inflater.inflate( R.menu.dicts_item_menu, menu );
XWListItem row = (XWListItem)info.targetView;
DictLoc loc = (DictLoc)row.getCached();
if ( loc == DictLoc.BUILT_IN
|| ! DictUtils.haveWriteableSD() ) {
menu.removeItem( R.id.dicts_item_move );
}
String title = getString( R.string.game_item_menu_titlef,
row.getText() );
menu.setHeaderTitle( title );
public void onBackPressed() {
if ( 0 == m_selDicts.size() ) {
super.onBackPressed();
} else {
clearSelections();
}
}
@Override
public boolean onContextItemSelected( MenuItem item )
public boolean onCreateOptionsMenu( Menu menu )
{
boolean handled = false;
ExpandableListContextMenuInfo info = null;
try {
info = (ExpandableListContextMenuInfo)item.getMenuInfo();
} catch (ClassCastException cce) {
DbgUtils.loge( cce );
return false;
}
m_packedPosition = info.packedPosition;
MenuInflater inflater = getMenuInflater();
inflater.inflate( R.menu.dicts_menu, menu );
int id = item.getItemId();
switch( id ) {
case R.id.dicts_item_move:
askMoveDict( (XWListItem)info.targetView );
break;
case R.id.dicts_item_select:
showDialog( SET_DEFAULT );
break;
}
return handled;
return true;
}
@Override
public boolean onPrepareOptionsMenu( Menu menu )
{
return super.onPrepareOptionsMenu( menu );
}
public boolean onOptionsItemSelected( MenuItem item )
{
boolean handled = true;
switch ( item.getItemId() ) {
case R.id.dicts_download:
case R.id.dicts_delete:
case R.id.dicts_move:
case R.id.dicts_select:
break;
default:
handled = false;
}
return handled || super.onOptionsItemSelected( item );
}
// @Override
// public void onCreateContextMenu( ContextMenu menu, View view,
// ContextMenuInfo menuInfo )
// {
// super.onCreateContextMenu( menu, view, menuInfo );
// ExpandableListView.ExpandableListContextMenuInfo info
// = (ExpandableListView.ExpandableListContextMenuInfo)menuInfo;
// long packedPosition = info.packedPosition;
// int childPosition = ExpandableListView.
// getPackedPositionChild( packedPosition );
// // int groupPosition = ExpandableListView.
// // getPackedPositionGroup( packedPosition );
// // DbgUtils.logf( "onCreateContextMenu: group: %d; child: %d",
// // groupPosition, childPosition );
// // We don't have a menu yet for languages, just for their dict
// // children
// if ( childPosition >= 0 ) {
// MenuInflater inflater = getMenuInflater();
// inflater.inflate( R.menu.dicts_item_menu, menu );
// XWListItem row = (XWListItem)info.targetView;
// DictLoc loc = (DictLoc)row.getCached();
// if ( loc == DictLoc.BUILT_IN
// || ! DictUtils.haveWriteableSD() ) {
// menu.removeItem( R.id.dicts_item_move );
// }
// String title = getString( R.string.game_item_menu_titlef,
// row.getText() );
// menu.setHeaderTitle( title );
// }
// }
// @Override
// public boolean onContextItemSelected( MenuItem item )
// {
// boolean handled = false;
// ExpandableListContextMenuInfo info = null;
// try {
// info = (ExpandableListContextMenuInfo)item.getMenuInfo();
// } catch (ClassCastException cce) {
// DbgUtils.loge( cce );
// return false;
// }
// m_packedPosition = info.packedPosition;
// int id = item.getItemId();
// switch( id ) {
// case R.id.dicts_item_move:
// askMoveDict( (XWListItem)info.targetView );
// break;
// case R.id.dicts_item_select:
// showDialog( SET_DEFAULT );
// break;
// }
// return handled;
// }
private void downloadNewDict( Intent intent )
{
int loci = intent.getIntExtra( UpdateCheckReceiver.NEW_DICT_LOC, 0 );
@ -588,6 +637,16 @@ public class DictsActivity extends XWExpandableListActivity
showDialog( MOVE_DICT );
}
// OnItemLongClickListener interface
public boolean onItemLongClick( AdapterView<?> parent, View view,
int position, long id ) {
boolean success = view instanceof SelectableItem.LongClickHandler;
if ( success ) {
((SelectableItem.LongClickHandler)view).longClicked();
}
return success;
}
// XWListItem.DeleteCallback interface
public void deleteCalled( XWListItem item )
{
@ -711,6 +770,32 @@ public class DictsActivity extends XWExpandableListActivity
XWPrefs.setClosedLangs( this, asArray );
}
private void clearSelections()
{
if ( 0 < m_selDicts.size() ) {
XWListItem[] items = new XWListItem[m_selDicts.size()];
int indx = 0;
for ( Iterator<XWListItem> iter = m_selDicts.iterator();
iter.hasNext(); ) {
items[indx++] = iter.next();
}
m_selDicts.clear();
for ( XWListItem item : items ) {
item.setSelected( false );
}
}
}
private void setTitleBar()
{
int nSels = m_selDicts.size();
if ( 0 < nSels ) {
setTitle( getString( R.string.sel_dictsf, nSels ) );
} else {
setTitle( m_origTitle );
}
}
private String[] makeDictDirItems()
{
@ -793,6 +878,32 @@ public class DictsActivity extends XWExpandableListActivity
}
}
// SelectableItem interface
public void itemClicked( SelectableItem.LongClickHandler clicked,
GameSummary summary )
{
DbgUtils.logf( "itemClicked not implemented" );
}
public void itemToggled( SelectableItem.LongClickHandler toggled,
boolean selected )
{
XWListItem dictView = (XWListItem)toggled;
if ( selected ) {
m_selDicts.add( dictView );
} else {
m_selDicts.remove( dictView );
}
Utils.invalidateOptionsMenuIf( this );
setTitleBar();
}
public boolean getSelected( SelectableItem.LongClickHandler obj )
{
XWListItem dictView = (XWListItem)obj;
return m_selDicts.contains( dictView );
}
private static class SafePopupImpl implements SafePopup {
public void doPopup( final Context context, View button,
String curDict ) {
@ -857,4 +968,4 @@ public class DictsActivity extends XWExpandableListActivity
context.startActivity( intent );
}
}
}

View file

@ -20,19 +20,25 @@
package org.eehouse.android.xw4;
import android.widget.LinearLayout;
import android.view.View;
import android.widget.TextView;
import android.widget.ImageButton;
import android.content.Context;
import android.util.AttributeSet;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
public class XWListItem extends LinearLayout {
public class XWListItem extends LinearLayout
implements SelectableItem.LongClickHandler {
private int m_position;
private Context m_context;
private Object m_cached;
private DeleteCallback m_cb;
private DeleteCallback m_delCb;
private Drawable m_origDrawable;
private boolean m_selected = false;
private SelectableItem m_selCb;
public interface DeleteCallback {
void deleteCalled( XWListItem item );
@ -69,17 +75,29 @@ public class XWListItem extends LinearLayout {
public void setDeleteCallback( DeleteCallback cb )
{
m_cb = cb;
m_delCb = cb;
ImageButton button = (ImageButton)findViewById( R.id.del );
button.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick( View view ) {
m_cb.deleteCalled( XWListItem.this );
m_delCb.deleteCalled( XWListItem.this );
}
} );
button.setVisibility( View.VISIBLE );
}
public void setSelCB( SelectableItem selCB )
{
m_selCb = selCB;
}
public void setSelected( boolean selected )
{
if ( selected != m_selected ) {
toggleSelected();
}
}
@Override
public void setEnabled( boolean enabled )
{
@ -105,4 +123,21 @@ public class XWListItem extends LinearLayout {
return m_cached;
}
// SelectableItem.LongClickHandler interface
public void longClicked()
{
toggleSelected();
}
private void toggleSelected()
{
m_selected = !m_selected;
if ( m_selected ) {
m_origDrawable = getBackground();
setBackgroundColor( XWApp.SEL_COLOR );
} else {
setBackgroundDrawable( m_origDrawable );
}
m_selCb.itemToggled( this, m_selected );
}
}