mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
fix selection of group item by adding a delegate all selectable items can call.
This commit is contained in:
parent
31b65e659d
commit
84698273a5
7 changed files with 130 additions and 45 deletions
|
@ -1,15 +1,30 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<org.eehouse.android.xw4.GameListGroup
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/game_name"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:paddingTop="3dp"
|
||||
android:paddingBottom="3dp"
|
||||
android:textStyle="italic"
|
||||
android:background="#FF7F7F7F"
|
||||
/>
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="horizontal"
|
||||
android:background="#FF7F7F7F"
|
||||
>
|
||||
|
||||
<org.eehouse.android.xw4.ExpiringTextView
|
||||
android:id="@+id/game_name"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="left"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:paddingTop="3dp"
|
||||
android:paddingBottom="3dp"
|
||||
android:textStyle="italic"
|
||||
android:layout_weight="1"
|
||||
/>
|
||||
|
||||
<ImageButton android:id="@+id/expander"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:src="@drawable/expander_ic_maximized"
|
||||
/>
|
||||
|
||||
</org.eehouse.android.xw4.GameListGroup>
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
/* -*- compile-command: "find-and-ant.sh debug install"; -*- */
|
||||
/*
|
||||
* Copyright 2009-2014 by Eric House (xwords@eehouse.org). All
|
||||
* rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
package org.eehouse.android.xw4;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.View;
|
||||
|
||||
public class DrawSelDelegate {
|
||||
private View m_view;
|
||||
private Drawable m_origDrawable;
|
||||
|
||||
protected DrawSelDelegate( View view )
|
||||
{
|
||||
m_view = view;
|
||||
m_origDrawable = view.getBackground();
|
||||
}
|
||||
|
||||
protected void showSelected( boolean selected, Drawable selDrawable )
|
||||
{
|
||||
if ( selected ) {
|
||||
m_origDrawable = m_view.getBackground();
|
||||
if ( null == selDrawable ) {
|
||||
m_view.setBackgroundColor( XWApp.SEL_COLOR );
|
||||
} else {
|
||||
m_view.setBackgroundDrawable( selDrawable );
|
||||
}
|
||||
} else {
|
||||
m_view.setBackgroundDrawable( m_origDrawable );
|
||||
}
|
||||
}
|
||||
|
||||
protected void showSelected( boolean selected )
|
||||
{
|
||||
showSelected( selected, null );
|
||||
}
|
||||
|
||||
}
|
|
@ -52,12 +52,12 @@ public class ExpiringDelegate {
|
|||
private long m_startSecs;
|
||||
private Runnable m_runnable = null;
|
||||
private boolean m_selected;
|
||||
private Drawable m_origDrawable;
|
||||
// these can be static as drawing's all in same thread.
|
||||
private static Rect s_rect;
|
||||
private static Paint s_paint;
|
||||
private static float[] s_points;
|
||||
private static Drawable s_selDrawable;
|
||||
private DrawSelDelegate m_dsdel;
|
||||
|
||||
static {
|
||||
s_rect = new Rect();
|
||||
|
@ -72,7 +72,7 @@ public class ExpiringDelegate {
|
|||
{
|
||||
m_context = context;
|
||||
m_view = view;
|
||||
m_origDrawable = view.getBackground();
|
||||
m_dsdel = new DrawSelDelegate( view );
|
||||
}
|
||||
|
||||
public void setHandler( Handler handler )
|
||||
|
@ -101,12 +101,7 @@ public class ExpiringDelegate {
|
|||
public void setSelected( boolean selected )
|
||||
{
|
||||
m_selected = selected;
|
||||
if ( selected ) {
|
||||
m_origDrawable = m_view.getBackground();
|
||||
m_view.setBackgroundDrawable( s_selDrawable );
|
||||
} else {
|
||||
m_view.setBackgroundDrawable( m_origDrawable );
|
||||
}
|
||||
m_dsdel.showSelected( m_selected, s_selDrawable );
|
||||
}
|
||||
|
||||
public void onDraw( Canvas canvas )
|
||||
|
|
|
@ -28,7 +28,6 @@ import android.widget.TextView;
|
|||
class ExpiringTextView extends TextView {
|
||||
private ExpiringDelegate m_delegate = null;
|
||||
private Context m_context;
|
||||
protected boolean m_selected = false;
|
||||
|
||||
public ExpiringTextView( Context context, AttributeSet attrs )
|
||||
{
|
||||
|
@ -53,12 +52,6 @@ class ExpiringTextView extends TextView {
|
|||
}
|
||||
}
|
||||
|
||||
protected void toggleSelected()
|
||||
{
|
||||
m_selected = !m_selected;
|
||||
getDelegate().setSelected( m_selected );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw( Canvas canvas )
|
||||
{
|
||||
|
|
|
@ -24,16 +24,21 @@ import android.content.Context;
|
|||
import android.graphics.Canvas;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import org.eehouse.android.xw4.DBUtils.GameGroupInfo;
|
||||
|
||||
public class GameListGroup extends ExpiringTextView
|
||||
implements SelectableItem.LongClickHandler
|
||||
public class GameListGroup extends LinearLayout
|
||||
implements SelectableItem.LongClickHandler,
|
||||
View.OnLongClickListener
|
||||
{
|
||||
private int m_groupPosition;
|
||||
private long m_groupID;
|
||||
private boolean m_expanded;
|
||||
private SelectableItem m_cb;
|
||||
private ExpiringTextView m_etv;
|
||||
private boolean m_selected;
|
||||
private DrawSelDelegate m_dsdel;
|
||||
|
||||
public static GameListGroup makeForPosition( Context context,
|
||||
int groupPosition,
|
||||
|
@ -53,6 +58,15 @@ public class GameListGroup extends ExpiringTextView
|
|||
super( cx, as );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate()
|
||||
{
|
||||
super.onFinishInflate();
|
||||
m_etv = (ExpiringTextView)findViewById( R.id.game_name );
|
||||
m_dsdel = new DrawSelDelegate( this );
|
||||
setOnLongClickListener( this );
|
||||
}
|
||||
|
||||
public void setGroupPosition( int groupPosition )
|
||||
{
|
||||
m_groupPosition = groupPosition;
|
||||
|
@ -76,6 +90,17 @@ public class GameListGroup extends ExpiringTextView
|
|||
}
|
||||
}
|
||||
|
||||
protected void setText( String text )
|
||||
{
|
||||
m_etv.setText( text );
|
||||
}
|
||||
|
||||
protected void setPct( boolean haveTurn, boolean haveTurnLocal,
|
||||
long startSecs )
|
||||
{
|
||||
m_etv.setPct( haveTurn, haveTurnLocal, startSecs );
|
||||
}
|
||||
|
||||
// GameListAdapter.ClickHandler interface
|
||||
public void longClicked()
|
||||
{
|
||||
|
@ -84,8 +109,17 @@ public class GameListGroup extends ExpiringTextView
|
|||
|
||||
protected void toggleSelected()
|
||||
{
|
||||
super.toggleSelected();
|
||||
m_selected = !m_selected;
|
||||
m_dsdel.showSelected( m_selected );
|
||||
m_cb.itemToggled( this, m_selected );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// View.OnLongClickListener interface
|
||||
//////////////////////////////////////////////////
|
||||
public boolean onLongClick( View view )
|
||||
{
|
||||
longClicked();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,8 +66,8 @@ public class GameListItem extends LinearLayout
|
|||
private int m_fieldID;
|
||||
private int m_loadingCount;
|
||||
private int m_groupPosition;
|
||||
private Drawable m_origDrawable;
|
||||
private boolean m_selected = false;
|
||||
private DrawSelDelegate m_dsdel;
|
||||
|
||||
public GameListItem( Context cx, AttributeSet as )
|
||||
{
|
||||
|
@ -80,6 +80,7 @@ public class GameListItem extends LinearLayout
|
|||
m_rowid = DBUtils.ROWID_NOTFOUND;
|
||||
m_lastMoveTime = 0;
|
||||
m_loadingCount = 0;
|
||||
m_dsdel = new DrawSelDelegate( this );
|
||||
|
||||
setOnClickListener( new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -332,12 +333,7 @@ public class GameListItem extends LinearLayout
|
|||
private void toggleSelected()
|
||||
{
|
||||
m_selected = !m_selected;
|
||||
if ( m_selected ) {
|
||||
m_origDrawable = getBackground();
|
||||
setBackgroundColor( XWApp.SEL_COLOR );
|
||||
} else {
|
||||
setBackgroundDrawable( m_origDrawable );
|
||||
}
|
||||
m_dsdel.showSelected( m_selected );
|
||||
m_cb.itemToggled( this, m_selected );
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ package org.eehouse.android.xw4;
|
|||
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
|
@ -38,10 +37,10 @@ public class XWListItem extends LinearLayout
|
|||
private Context m_context;
|
||||
private Object m_cached;
|
||||
private DeleteCallback m_delCb;
|
||||
private Drawable m_origDrawable;
|
||||
private boolean m_selected = false;
|
||||
private SelectableItem m_selCb;
|
||||
private CheckBox m_checkbox;
|
||||
private DrawSelDelegate m_dsdel;
|
||||
|
||||
public interface DeleteCallback {
|
||||
void deleteCalled( XWListItem item );
|
||||
|
@ -50,6 +49,7 @@ public class XWListItem extends LinearLayout
|
|||
public XWListItem( Context cx, AttributeSet as ) {
|
||||
super( cx, as );
|
||||
m_context = cx;
|
||||
m_dsdel = new DrawSelDelegate( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -152,12 +152,9 @@ public class XWListItem extends LinearLayout
|
|||
private void toggleSelected()
|
||||
{
|
||||
m_selected = !m_selected;
|
||||
if ( m_selected ) {
|
||||
m_origDrawable = getBackground();
|
||||
setBackgroundColor( XWApp.SEL_COLOR );
|
||||
} else {
|
||||
setBackgroundDrawable( m_origDrawable );
|
||||
}
|
||||
|
||||
m_dsdel.showSelected( m_selected );
|
||||
|
||||
m_checkbox.setChecked( m_selected );
|
||||
|
||||
m_selCb.itemToggled( this, m_selected );
|
||||
|
|
Loading…
Reference in a new issue