ExpiringDelegate rather than ExpiringTextView needs to draw selected

state so can coordinate with expiring state representation.
This commit is contained in:
Eric House 2013-10-21 07:46:58 -07:00
parent 7a4d3093a1
commit 1b3c8ed661
3 changed files with 39 additions and 20 deletions

View file

@ -26,6 +26,7 @@ import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Handler; import android.os.Handler;
import android.view.View; import android.view.View;
@ -47,10 +48,13 @@ public class ExpiringDelegate {
private boolean m_haveTurnLocal = false; private boolean m_haveTurnLocal = false;
private long m_startSecs; private long m_startSecs;
private Runnable m_runnable = null; private Runnable m_runnable = null;
private boolean m_selected;
private Drawable m_origDrawable;
// these can be static as drawing's all in same thread. // these can be static as drawing's all in same thread.
private static Rect s_rect; private static Rect s_rect;
private static Paint s_paint; private static Paint s_paint;
private static float[] s_points; private static float[] s_points;
private static Drawable s_selDrawable;
static { static {
s_rect = new Rect(); s_rect = new Rect();
@ -58,12 +62,18 @@ public class ExpiringDelegate {
s_paint.setStyle(Paint.Style.STROKE); s_paint.setStyle(Paint.Style.STROKE);
s_paint.setStrokeWidth( 1 ); s_paint.setStrokeWidth( 1 );
s_points = new float[4*6]; s_points = new float[4*6];
s_selDrawable = new ColorDrawable( XWApp.SEL_COLOR );
} }
public ExpiringDelegate( Context context, View view, Handler handler ) public ExpiringDelegate( Context context, View view )
{ {
m_context = context; m_context = context;
m_view = view; m_view = view;
m_origDrawable = view.getBackground();
}
public void setHandler( Handler handler )
{
m_handler = handler; m_handler = handler;
} }
@ -85,9 +95,22 @@ 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 );
}
}
public void onDraw( Canvas canvas ) public void onDraw( Canvas canvas )
{ {
if ( m_active && m_doFrame ) { if ( m_selected ) {
// do nothing; the drawable's set already
} else if ( m_active && m_doFrame ) {
Assert.assertTrue( 0 <= m_pct && m_pct <= 100 ); Assert.assertTrue( 0 <= m_pct && m_pct <= 100 );
m_view.getDrawingRect( s_rect ); m_view.getDrawingRect( s_rect );
int width = s_rect.width(); int width = s_rect.width();

View file

@ -38,7 +38,8 @@ public class ExpiringLinearLayout extends LinearLayout {
boolean haveTurnLocal, long startSecs ) boolean haveTurnLocal, long startSecs )
{ {
if ( null == m_delegate ) { if ( null == m_delegate ) {
m_delegate = new ExpiringDelegate( m_context, this, handler ); m_delegate = new ExpiringDelegate( m_context, this );
m_delegate.setHandler( handler );
} }
m_delegate.configure( haveTurn, haveTurnLocal, startSecs ); m_delegate.configure( haveTurn, haveTurnLocal, startSecs );
} }

View file

@ -21,8 +21,6 @@ package org.eehouse.android.xw4;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Handler; import android.os.Handler;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.widget.TextView; import android.widget.TextView;
@ -30,14 +28,8 @@ import android.widget.TextView;
class ExpiringTextView extends TextView { class ExpiringTextView extends TextView {
private ExpiringDelegate m_delegate = null; private ExpiringDelegate m_delegate = null;
private Context m_context; private Context m_context;
private Drawable m_origDrawable;
private static Drawable s_selDrawable;
protected boolean m_selected = false; protected boolean m_selected = false;
static {
s_selDrawable = new ColorDrawable( XWApp.SEL_COLOR );
}
public ExpiringTextView( Context context, AttributeSet attrs ) public ExpiringTextView( Context context, AttributeSet attrs )
{ {
super( context, attrs ); super( context, attrs );
@ -47,9 +39,9 @@ class ExpiringTextView extends TextView {
public void setPct( Handler handler, boolean haveTurn, public void setPct( Handler handler, boolean haveTurn,
boolean haveTurnLocal, long startSecs ) boolean haveTurnLocal, long startSecs )
{ {
if ( null == m_delegate ) { ExpiringDelegate delegate = getDelegate();
m_delegate = new ExpiringDelegate( m_context, this, handler ); delegate.setHandler( handler );
}
setPct( haveTurn, haveTurnLocal, startSecs ); setPct( haveTurn, haveTurnLocal, startSecs );
} }
@ -64,12 +56,7 @@ class ExpiringTextView extends TextView {
protected void toggleSelected() protected void toggleSelected()
{ {
m_selected = !m_selected; m_selected = !m_selected;
if ( m_selected ) { getDelegate().setSelected( m_selected );
m_origDrawable = getBackground();
setBackgroundDrawable( s_selDrawable );
} else {
setBackgroundDrawable( m_origDrawable );
}
} }
@Override @Override
@ -80,4 +67,12 @@ class ExpiringTextView extends TextView {
m_delegate.onDraw( canvas ); m_delegate.onDraw( canvas );
} }
} }
private ExpiringDelegate getDelegate()
{
if ( null == m_delegate ) {
m_delegate = new ExpiringDelegate( m_context, this );
}
return m_delegate;
}
} }