diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ExpiringDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ExpiringDelegate.java index 6a73c8f22..18ea62fea 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ExpiringDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ExpiringDelegate.java @@ -26,6 +26,7 @@ import android.graphics.Color; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.Handler; import android.view.View; @@ -47,10 +48,13 @@ public class ExpiringDelegate { private boolean m_haveTurnLocal = false; 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; static { s_rect = new Rect(); @@ -58,12 +62,18 @@ public class ExpiringDelegate { s_paint.setStyle(Paint.Style.STROKE); s_paint.setStrokeWidth( 1 ); 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_view = view; + m_origDrawable = view.getBackground(); + } + + public void setHandler( 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 ) { - 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 ); m_view.getDrawingRect( s_rect ); int width = s_rect.width(); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ExpiringLinearLayout.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ExpiringLinearLayout.java index c3164eead..a3dfebf32 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ExpiringLinearLayout.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ExpiringLinearLayout.java @@ -38,7 +38,8 @@ public class ExpiringLinearLayout extends LinearLayout { boolean haveTurnLocal, long startSecs ) { 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 ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ExpiringTextView.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ExpiringTextView.java index 98b508bac..0b5ed242c 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ExpiringTextView.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ExpiringTextView.java @@ -21,8 +21,6 @@ package org.eehouse.android.xw4; import android.content.Context; import android.graphics.Canvas; -import android.graphics.drawable.ColorDrawable; -import android.graphics.drawable.Drawable; import android.os.Handler; import android.util.AttributeSet; import android.widget.TextView; @@ -30,14 +28,8 @@ import android.widget.TextView; class ExpiringTextView extends TextView { private ExpiringDelegate m_delegate = null; private Context m_context; - private Drawable m_origDrawable; - private static Drawable s_selDrawable; protected boolean m_selected = false; - static { - s_selDrawable = new ColorDrawable( XWApp.SEL_COLOR ); - } - public ExpiringTextView( Context context, AttributeSet attrs ) { super( context, attrs ); @@ -47,9 +39,9 @@ class ExpiringTextView extends TextView { public void setPct( Handler handler, boolean haveTurn, boolean haveTurnLocal, long startSecs ) { - if ( null == m_delegate ) { - m_delegate = new ExpiringDelegate( m_context, this, handler ); - } + ExpiringDelegate delegate = getDelegate(); + delegate.setHandler( handler ); + setPct( haveTurn, haveTurnLocal, startSecs ); } @@ -64,12 +56,7 @@ class ExpiringTextView extends TextView { protected void toggleSelected() { m_selected = !m_selected; - if ( m_selected ) { - m_origDrawable = getBackground(); - setBackgroundDrawable( s_selDrawable ); - } else { - setBackgroundDrawable( m_origDrawable ); - } + getDelegate().setSelected( m_selected ); } @Override @@ -80,4 +67,12 @@ class ExpiringTextView extends TextView { m_delegate.onDraw( canvas ); } } + + private ExpiringDelegate getDelegate() + { + if ( null == m_delegate ) { + m_delegate = new ExpiringDelegate( m_context, this ); + } + return m_delegate; + } }