2626public class FoundTriplesView extends View {
2727
2828 private static final float CARD_ASPECT_RATIO = (float ) ((Math .sqrt (5 ) - 1 ) / 2 );
29- private static final int COLUMNS = 6 ;
30- private static final int PADDING_DP = 8 ;
31- private static final int STACK_OVERLAP_DP = 16 ;
32- private static final int STACK_WIDTH_REDUCTION_DP = 10 ;
29+ private static final int COLUMNS = 7 ;
30+ private static final int PADDING_DP = 6 ;
31+ private static final int STACK_OVERLAP_DP = 20 ;
3332 private static final int HIGHLIGHT_DURATION_MS = 1000 ;
34- private static final int MAX_HEIGHT_DP = 120 ;
33+ private static final int MAX_HEIGHT_DP = 140 ;
3534
3635 private final Paint mPlaceholderPaint ;
3736 private final Paint mBackgroundPaint ;
3837 private final Paint mHighlightPaint ;
3938 private final int mPadding ;
4039 private final int mOverlap ;
41- private final int mWidthReduction ;
4240 private final int mMaxHeight ;
4341
4442 private List <Set <Card >> mAllTriples = Lists .newArrayList ();
@@ -57,23 +55,22 @@ public FoundTriplesView(Context context, AttributeSet attrs) {
5755 float density = getResources ().getDisplayMetrics ().density ;
5856 mPadding = (int ) (PADDING_DP * density );
5957 mOverlap = (int ) (STACK_OVERLAP_DP * density );
60- mWidthReduction = (int ) (STACK_WIDTH_REDUCTION_DP * density );
6158 mMaxHeight = (int ) (MAX_HEIGHT_DP * density );
6259
6360 mPlaceholderPaint = new Paint (Paint .ANTI_ALIAS_FLAG );
6461 mPlaceholderPaint .setStyle (Paint .Style .STROKE );
6562 mPlaceholderPaint .setColor (ContextCompat .getColor (context , R .color .colorOutlineVariant ));
66- mPlaceholderPaint .setStrokeWidth (density ); // thin border
63+ mPlaceholderPaint .setStrokeWidth (1 ); // Very thin
6764 mPlaceholderPaint .setPathEffect (new DashPathEffect (new float []{10 , 5 }, 0 ));
6865
6966 mBackgroundPaint = new Paint (Paint .ANTI_ALIAS_FLAG );
7067 mBackgroundPaint .setColor (ContextCompat .getColor (context , R .color .card_background ));
71- mBackgroundPaint .setShadowLayer (4 , 2 , 2 , ContextCompat .getColor (context , R .color .card_shadow ));
68+ mBackgroundPaint .setShadowLayer (2 , 1 , 1 , ContextCompat .getColor (context , R .color .card_shadow ));
7269
7370 mHighlightPaint = new Paint (Paint .ANTI_ALIAS_FLAG );
7471 mHighlightPaint .setColor (ContextCompat .getColor (context , R .color .card_selected_outline ));
7572 mHighlightPaint .setStyle (Paint .Style .STROKE );
76- mHighlightPaint .setStrokeWidth (density * 3 );
73+ mHighlightPaint .setStrokeWidth (density * 2 );
7774
7875 setLayerType (LAYER_TYPE_SOFTWARE , null );
7976 }
@@ -113,12 +110,11 @@ public Map<Card, Rect> getCardLocations(Set<Card> triple) {
113110 int row = visualIndex / COLUMNS ;
114111
115112 int availableWidth = getWidth () - (COLUMNS + 1 ) * mPadding ;
116- int colWidth = availableWidth / COLUMNS ;
117- int cardWidth = colWidth - mWidthReduction ;
113+ int cardWidth = availableWidth / COLUMNS ;
118114 int cardHeight = (int ) (cardWidth * CARD_ASPECT_RATIO );
119115 int stackHeight = cardHeight + mOverlap * 2 ;
120116
121- int x = mPadding + column * (colWidth + mPadding ) + mWidthReduction / 2 ;
117+ int x = mPadding + column * (cardWidth + mPadding );
122118 int y = mPadding + row * (stackHeight + mPadding );
123119
124120 int [] location = new int [2 ];
@@ -144,8 +140,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
144140 }
145141
146142 int availableWidth = width - (COLUMNS + 1 ) * mPadding ;
147- int colWidth = availableWidth / COLUMNS ;
148- int cardWidth = colWidth - mWidthReduction ;
143+ int cardWidth = availableWidth / COLUMNS ;
149144 int cardHeight = (int ) (cardWidth * CARD_ASPECT_RATIO );
150145 int stackHeight = cardHeight + mOverlap * 2 ;
151146
@@ -164,29 +159,28 @@ protected void onDraw(Canvas canvas) {
164159 if (mAllTriples .isEmpty ()) return ;
165160
166161 int availableWidth = getWidth () - (COLUMNS + 1 ) * mPadding ;
167- int colWidth = availableWidth / COLUMNS ;
168- int cardWidth = colWidth - mWidthReduction ;
162+ int cardWidth = availableWidth / COLUMNS ;
169163 int cardHeight = (int ) (cardWidth * CARD_ASPECT_RATIO );
170164 int stackHeight = cardHeight + mOverlap * 2 ;
171165
172166 for (int i = 0 ; i < mFoundTriples .size (); i ++) {
173167 int column = i % COLUMNS ;
174168 int row = i / COLUMNS ;
175- int x = mPadding + column * (colWidth + mPadding ) + mWidthReduction / 2 ;
169+ int x = mPadding + column * (cardWidth + mPadding );
176170 int y = mPadding + row * (stackHeight + mPadding );
177171
178172 Set <Card > triple = mFoundTriples .get (i );
179173 drawTripleStack (canvas , triple , x , y , cardWidth , cardHeight );
180174
181175 if (triple .equals (mHighlightedTriple )) {
182- canvas .drawRoundRect (new RectF (x - 2 , y - 2 , x + cardWidth + 2 , y + stackHeight + 2 ), 8 , 8 , mHighlightPaint );
176+ canvas .drawRoundRect (new RectF (x - 2 , y - 2 , x + cardWidth + 2 , y + stackHeight + 2 ), 4 , 4 , mHighlightPaint );
183177 }
184178 }
185179
186180 for (int i = mFoundTriples .size (); i < mAllTriples .size (); i ++) {
187181 int column = i % COLUMNS ;
188182 int row = i / COLUMNS ;
189- int x = mPadding + column * (colWidth + mPadding ) + mWidthReduction / 2 ;
183+ int x = mPadding + column * (cardWidth + mPadding );
190184 int y = mPadding + row * (stackHeight + mPadding );
191185
192186 drawPlaceholderStack (canvas , x , y , cardWidth , cardHeight );
@@ -199,8 +193,19 @@ private void drawTripleStack(Canvas canvas, Set<Card> triple, int x, int y, int
199193
200194 for (int i = 0 ; i < 3 ; i ++) {
201195 Rect cardRect = new Rect (x , y + i * mOverlap , x + w , y + i * mOverlap + h );
202- canvas .drawRoundRect (new RectF (cardRect ), 8 , 8 , mBackgroundPaint );
203- canvas .drawRoundRect (new RectF (cardRect ), 8 , 8 , mPlaceholderPaint ); // thin border
196+
197+ // Scale canvas to draw the card at "normal" size then shrink it
198+ // This ensures line thicknesses etc. are consistent
199+ float scale = (float ) w / 200f ; // assuming 200 is a reasonable reference width
200+ int sc = canvas .save ();
201+ canvas .translate (cardRect .left , cardRect .top );
202+ canvas .scale ((float )w /100f , (float )h /61.8f ); // roughly golden ratio / standard aspect
203+
204+ // Actually let's just use the rect and draw simply but adjust stroke widths
205+ canvas .restoreToCount (sc );
206+
207+ canvas .drawRoundRect (new RectF (cardRect ), 4 , 4 , mBackgroundPaint );
208+ canvas .drawRoundRect (new RectF (cardRect ), 4 , 4 , mPlaceholderPaint ); // thin border
204209
205210 SymbolDrawable symbol = mSymbolDrawables .get (cards .get (i ));
206211 Rect relativeCardRect = new Rect (0 , 0 , w , h );
@@ -215,6 +220,6 @@ private void drawTripleStack(Canvas canvas, Set<Card> triple, int x, int y, int
215220
216221 private void drawPlaceholderStack (Canvas canvas , int x , int y , int w , int h ) {
217222 RectF rect = new RectF (x , y , x + w , y + h + mOverlap * 2 );
218- canvas .drawRoundRect (rect , 8 , 8 , mPlaceholderPaint );
223+ canvas .drawRoundRect (rect , 4 , 4 , mPlaceholderPaint );
219224 }
220225}
0 commit comments