first cut at putting a delete button next to players in config list

This commit is contained in:
Andy2 2010-07-16 05:50:20 -07:00
parent ea2b6b6df9
commit f9a561bd2a
4 changed files with 56 additions and 55 deletions

View file

@ -11,4 +11,19 @@
android:textAppearance="?android:attr/textAppearanceLarge"
android:longClickable="true"
android:background="@android:drawable/list_selector_background"
/>
>
<TextView android:id="@+id/text_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<ImageButton android:id="@+id/hint_button_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_delete"
android:visibility="gone"
/>
</org.eehouse.android.xw4.XWListItem>

View file

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<!-- <item android:id="@+id/list_item_open" -->
<!-- android:title="@string/list_item_open" -->
<!-- /> -->
<item android:id="@+id/player_list_item_delete"
android:title="@string/list_item_delete"
/>
<item android:id="@+id/player_list_item_up"
android:title="@string/list_item_up"
/>
<item android:id="@+id/player_list_item_down"
android:title="@string/list_item_down"
/>
</menu>

View file

@ -41,8 +41,6 @@ import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuInflater;
import android.view.KeyEvent;
import android.widget.Spinner;
@ -56,7 +54,8 @@ import junit.framework.Assert;
import org.eehouse.android.xw4.jni.*;
import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole;
public class GameConfig extends Activity implements View.OnClickListener {
public class GameConfig extends Activity implements View.OnClickListener,
XWListItem.DeleteCallback {
private static final int PLAYER_EDIT = 1;
private static final int ROLE_EDIT_RELAY = 2;
@ -453,42 +452,12 @@ public class GameConfig extends Activity implements View.OnClickListener {
setTitle( String.format( fmt, GameUtils.gameName( this, m_path ) ) );
} // onCreate
@Override
public void onCreateContextMenu( ContextMenu menu, View view,
ContextMenuInfo menuInfo ) {
MenuInflater inflater = getMenuInflater();
inflater.inflate( R.menu.players_list_item_menu, menu );
m_whichPlayer = ((XWListItem)view).getPosition();
}
@Override
public boolean onContextItemSelected( MenuItem item )
// DeleteCallback interface
public void deleteCalled( int myPosition )
{
boolean handled = true;
boolean changed = false;
switch (item.getItemId()) {
// case R.id.player_list_item_edit:
// showDialog( PLAYER_EDIT );
// break;
case R.id.player_list_item_delete:
changed = m_gi.delete( m_whichPlayer );
break;
case R.id.player_list_item_up:
changed = m_gi.moveUp( m_whichPlayer );
break;
case R.id.player_list_item_down:
changed = m_gi.moveDown( m_whichPlayer );
break;
default:
handled = false;
}
if ( changed ) {
if ( m_gi.delete( myPosition ) ) {
loadPlayers();
}
return handled;
}
public void onClick( View view )
@ -560,8 +529,11 @@ public class GameConfig extends Activity implements View.OnClickListener {
view.setPosition( ii );
view.setText( names[ii] );
view.setGravity( Gravity.CENTER );
// only enable delete if one will remain
if ( 1 < names.length ) {
view.setDeleteCallback( this );
}
registerForContextMenu( view );
view.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick( View view ) {

View file

@ -20,18 +20,48 @@
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;
public class XWListItem extends TextView {
public class XWListItem extends LinearLayout {
private int m_position;
private ImageButton m_button;
private Context m_context;
DeleteCallback m_cb;
public interface DeleteCallback {
void deleteCalled( int myPosition );
}
public XWListItem( Context cx, AttributeSet as ) {
super( cx, as );
m_context = cx;
}
public int getPosition() { return m_position; }
public void setPosition( int indx ) { m_position = indx; }
public void setText( String text )
{
TextView view = (TextView)getChildAt( 0 );
view.setText( text );
}
public void setDeleteCallback( DeleteCallback cb )
{
m_cb = cb;
ImageButton button = (ImageButton)getChildAt( 1 );
button.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick( View view ) {
m_cb.deleteCalled( m_position );
}
} );
button.setVisibility( View.VISIBLE );
}
}