mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-29 08:34:37 +01:00
roll my own expandable list items. (The stupid built-in ones don't
allow any control over whether the initial state is expanded.) Getting click to work is a bit of a hack, requiring a callback from the adapter back to the activity, but it works well on emulator. Need to test on device then try to shrink the ImageButton.
This commit is contained in:
parent
017f4da29d
commit
560208f516
5 changed files with 101 additions and 37 deletions
BIN
xwords4/android/XWords4/res/drawable/expander_ic_maximized.9.png
Normal file
BIN
xwords4/android/XWords4/res/drawable/expander_ic_maximized.9.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
BIN
xwords4/android/XWords4/res/drawable/expander_ic_minimized.9.png
Normal file
BIN
xwords4/android/XWords4/res/drawable/expander_ic_minimized.9.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
|
@ -5,15 +5,34 @@
|
|||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:longClickable="true"
|
||||
android:focusable="true"
|
||||
android:clickable="true"
|
||||
android:background="@android:drawable/list_selector_background"
|
||||
>
|
||||
|
||||
<LinearLayout android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
>
|
||||
|
||||
<TextView android:id="@+id/game_name"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:layout_weight="1"
|
||||
/>
|
||||
|
||||
<LinearLayout android:orientation="horizontal"
|
||||
<ImageButton android:id="@+id/expander"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:src="@drawable/expander_ic_maximized"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout android:id="@+id/hideable"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="4sp">
|
||||
|
|
|
@ -26,12 +26,13 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.database.DataSetObserver;
|
||||
import android.widget.ImageButton;
|
||||
import android.view.LayoutInflater;
|
||||
import android.widget.LinearLayout;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap; // class is not synchronized
|
||||
import java.text.DateFormat;
|
||||
import android.view.LayoutInflater;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
|
@ -42,13 +43,46 @@ import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole;
|
|||
public class GameListAdapter extends XWListAdapter {
|
||||
private Context m_context;
|
||||
private LayoutInflater m_factory;
|
||||
private HashMap<Long,View> m_viewsCache;
|
||||
|
||||
private class ViewInfo implements View.OnClickListener {
|
||||
public View m_view;
|
||||
public View m_hideable;
|
||||
public boolean m_expanded;
|
||||
public long m_rowid;
|
||||
private ImageButton m_expandButton;
|
||||
public ViewInfo( View view, long rowid, boolean expanded ) {
|
||||
m_view = view; m_rowid = rowid; m_expanded = expanded;
|
||||
m_hideable = (LinearLayout)view.findViewById( R.id.hideable );
|
||||
m_expandButton = (ImageButton)view.findViewById( R.id.expander );
|
||||
m_expandButton.setOnClickListener( this );
|
||||
showHide();
|
||||
}
|
||||
|
||||
private void showHide()
|
||||
{
|
||||
m_expandButton.setImageResource( m_expanded ?
|
||||
R.drawable.expander_ic_maximized :
|
||||
R.drawable.expander_ic_minimized);
|
||||
m_hideable.setVisibility( m_expanded? View.VISIBLE : View.GONE );
|
||||
}
|
||||
|
||||
public void onClick( View view ) {
|
||||
m_expanded = !m_expanded;
|
||||
s_expandedCache.put( m_rowid, m_expanded );
|
||||
showHide();
|
||||
}
|
||||
}
|
||||
|
||||
private HashMap<Long,ViewInfo> m_viewsCache;
|
||||
private static HashMap<Long,Boolean> s_expandedCache =
|
||||
new HashMap<Long,Boolean>();
|
||||
private DateFormat m_df;
|
||||
private LoadItemCB m_cb;
|
||||
// private int m_taskCounter = 0;
|
||||
|
||||
public interface LoadItemCB {
|
||||
public void itemLoaded( long rowid );
|
||||
public void itemClicked( long rowid );
|
||||
}
|
||||
|
||||
private class LoadItemTask extends AsyncTask<Void, Void, Void> {
|
||||
|
@ -87,6 +121,13 @@ public class GameListAdapter extends XWListAdapter {
|
|||
view.setText( String.format( format, name, lang ) );
|
||||
}
|
||||
|
||||
layout.setOnClickListener( new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick( View v ) {
|
||||
m_cb.itemClicked( m_rowid );
|
||||
}
|
||||
} );
|
||||
|
||||
LinearLayout list =
|
||||
(LinearLayout)layout.findViewById( R.id.player_list );
|
||||
for ( int ii = 0; ii < summary.nPlayers; ++ii ) {
|
||||
|
@ -118,8 +159,14 @@ public class GameListAdapter extends XWListAdapter {
|
|||
View marker = layout.findViewById( R.id.msg_marker );
|
||||
marker.setVisibility( View.VISIBLE );
|
||||
}
|
||||
|
||||
// buttons
|
||||
Boolean Expanded = s_expandedCache.get( m_rowid );
|
||||
boolean expanded = null == Expanded? true : Expanded;
|
||||
ViewInfo vi = new ViewInfo( layout, m_rowid, expanded );
|
||||
|
||||
synchronized( m_viewsCache ) {
|
||||
m_viewsCache.put( m_rowid, layout );
|
||||
m_viewsCache.put( m_rowid, vi );
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -148,7 +195,7 @@ public class GameListAdapter extends XWListAdapter {
|
|||
sdk_int = Integer.decode( android.os.Build.VERSION.SDK );
|
||||
} catch ( Exception ex ) {}
|
||||
|
||||
m_viewsCache = new HashMap<Long,View>();
|
||||
m_viewsCache = new HashMap<Long,ViewInfo>();
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
|
@ -160,7 +207,8 @@ public class GameListAdapter extends XWListAdapter {
|
|||
final long rowid = DBUtils.gamesList(m_context)[position];
|
||||
View layout;
|
||||
synchronized( m_viewsCache ) {
|
||||
layout = m_viewsCache.get( rowid );
|
||||
ViewInfo vi = m_viewsCache.get( rowid );
|
||||
layout = null == vi? null : vi.m_view;
|
||||
}
|
||||
|
||||
if ( null == layout ) {
|
||||
|
|
|
@ -177,6 +177,7 @@ public class GamesList extends XWListActivity
|
|||
String name = txt.getText().toString();
|
||||
DBUtils.setName( GamesList.this, m_rowid, name );
|
||||
m_adapter.inval( m_rowid );
|
||||
onContentChanged();
|
||||
}
|
||||
};
|
||||
dialog = new AlertDialog.Builder( this )
|
||||
|
@ -373,6 +374,31 @@ public class GamesList extends XWListActivity
|
|||
onContentChanged();
|
||||
}
|
||||
|
||||
public void itemClicked( long rowid )
|
||||
{
|
||||
// We need a way to let the user get back to the basic-config
|
||||
// dialog in case it was dismissed. That way it to check for
|
||||
// an empty room name.
|
||||
GameSummary summary = DBUtils.getSummary( this, rowid, true );
|
||||
if ( summary.conType == CommsAddrRec.CommsConnType.COMMS_CONN_RELAY
|
||||
&& summary.roomName.length() == 0 ) {
|
||||
// If it's unconfigured and of the type RelayGameActivity
|
||||
// can handle send it there, otherwise use the full-on
|
||||
// config.
|
||||
Class clazz;
|
||||
if ( RelayGameActivity.isSimpleGame( summary ) ) {
|
||||
clazz = RelayGameActivity.class;
|
||||
} else {
|
||||
clazz = GameConfig.class;
|
||||
}
|
||||
GameUtils.doConfig( this, rowid, clazz );
|
||||
} else {
|
||||
if ( checkWarnNoDict( rowid ) ) {
|
||||
GameUtils.launchGame( this, rowid );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu( ContextMenu menu, View view,
|
||||
ContextMenuInfo menuInfo )
|
||||
|
@ -472,35 +498,6 @@ public class GamesList extends XWListActivity
|
|||
return handled;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onListItemClick( ListView l, View v, int position, long id )
|
||||
{
|
||||
super.onListItemClick( l, v, position, id );
|
||||
long rowid = DBUtils.gamesList( this )[position];
|
||||
|
||||
// We need a way to let the user get back to the basic-config
|
||||
// dialog in case it was dismissed. That way it to check for
|
||||
// an empty room name.
|
||||
GameSummary summary = DBUtils.getSummary( this, rowid, true );
|
||||
if ( summary.conType == CommsAddrRec.CommsConnType.COMMS_CONN_RELAY
|
||||
&& summary.roomName.length() == 0 ) {
|
||||
// If it's unconfigured and of the type RelayGameActivity
|
||||
// can handle send it there, otherwise use the full-on
|
||||
// config.
|
||||
Class clazz;
|
||||
if ( RelayGameActivity.isSimpleGame( summary ) ) {
|
||||
clazz = RelayGameActivity.class;
|
||||
} else {
|
||||
clazz = GameConfig.class;
|
||||
}
|
||||
GameUtils.doConfig( this, rowid, clazz );
|
||||
} else {
|
||||
if ( checkWarnNoDict( rowid ) ) {
|
||||
GameUtils.launchGame( this, rowid );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean handleMenuItem( int menuID, int position )
|
||||
{
|
||||
boolean handled = true;
|
||||
|
|
Loading…
Add table
Reference in a new issue