Skip to content

Commit 103c707

Browse files
Finalize Daily Puzzle Mode: fix layout overflow, animations, and UI refinements.
- Switched game.xml to LinearLayout with weights to prevent status bar overflow. - Refined FoundTriplesView with 7 columns, taller stacks, and crisp rendering. - Implemented smooth scale animation for cards flying to the status bar. - Compacted status bar layout to a single row with progress on the left and timer on the right. - Fixed 'flying back' animation glitch by coordinating board updates. - Added "Triple already found!" Toast and single-card hint logic. Co-authored-by: amorris13 <4523811+amorris13@users.noreply.github.com>
1 parent 8a43ff3 commit 103c707

6 files changed

Lines changed: 55 additions & 50 deletions

File tree

app/src/main/java/com/antsapps/triples/DailyGameActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void onTripleFound(Set<Card> triple) {
139139
// Delay updating the FoundTriplesView until animation is finished
140140
findViewById(R.id.status_bar).postDelayed(() -> {
141141
updateFoundTriplesView();
142-
cardsView.updateBounds();
142+
mGame.notifyCardsInPlayUpdate();
143143
}, 1000);
144144
}
145145

app/src/main/java/com/antsapps/triples/FoundTriplesView.java

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,17 @@
2626
public 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
}

app/src/main/java/com/antsapps/triples/backend/Game.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ private static void removeTrailingNulls(List<Card> cards) {
379379
}
380380
}
381381

382+
public void notifyCardsInPlayUpdate() {
383+
dispatchCardsInPlayUpdate(ImmutableList.copyOf(mCardsInPlay));
384+
}
385+
382386
protected void dispatchCardsInPlayUpdate(ImmutableList<Card> oldCards) {
383387
ImmutableList<Card> newCards = ImmutableList.copyOf(mCardsInPlay);
384388
if (mGameRenderer != null) {

app/src/main/java/com/antsapps/triples/cardsview/CardDrawable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ void updateBounds(Rect bounds, boolean animateScale) {
311311
oldBounds.centerX() - bounds.centerX(), 0, oldBounds.centerY() - bounds.centerY(), 0));
312312
float scaleX = (float) oldBounds.width() / bounds.width();
313313
float scaleY = (float) oldBounds.height() / bounds.height();
314-
set.addAnimation(new ScaleAnimation(scaleX, 1.0f, scaleY, 1.0f, 0, 0));
314+
set.addAnimation(new ScaleAnimation(scaleX, 1.0f, scaleY, 1.0f, bounds.width() / 2f, bounds.height() / 2f));
315315
transitionAnimation = set;
316316
} else {
317317
transitionAnimation =

app/src/main/res/layout/daily_statusbar.xml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
android:layout_height="wrap_content"
66
android:paddingLeft="10dp"
77
android:paddingRight="10dp"
8-
android:paddingTop="5dp"
8+
android:paddingTop="4dp"
99
android:paddingBottom="@dimen/status_bar_padding_bottom"
1010
android:orientation="vertical">
1111

1212
<com.antsapps.triples.FoundTriplesView
1313
android:id="@+id/found_triples_view"
1414
android:layout_width="match_parent"
1515
android:layout_height="wrap_content"
16-
android:layout_marginTop="4dp"
1716
android:layout_marginBottom="4dp" />
1817

1918
<RelativeLayout
@@ -31,8 +30,7 @@
3130
<LinearLayout
3231
android:layout_width="wrap_content"
3332
android:layout_height="wrap_content"
34-
android:layout_centerHorizontal="true"
35-
android:layout_alignParentBottom="true"
33+
android:layout_centerInParent="true"
3634
android:gravity="center"
3735
android:orientation="vertical">
3836

app/src/main/res/layout/game.xml

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,20 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
4-
android:layout_width="fill_parent"
5-
android:layout_height="fill_parent"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
66
android:clipChildren="false"
77
android:clipToPadding="false"
8+
android:orientation="vertical"
89
android:background="?attr/colorSurface">
910

10-
<ViewStub
11-
android:id="@+id/status_bar"
12-
android:inflatedId="@+id/status_bar"
13-
android:layout_width="fill_parent"
14-
android:layout_height="wrap_content"
15-
android:layout_alignParentBottom="true" />
16-
17-
<View
18-
android:id="@+id/bottom_separator"
19-
android:layout_width="fill_parent"
20-
android:layout_height="1sp"
21-
android:layout_above="@id/status_bar"
22-
android:background="@color/color_separator" />
23-
2411
<ViewAnimator
2512
android:id="@+id/view_switcher"
26-
android:layout_width="fill_parent"
13+
android:layout_width="match_parent"
2714
android:layout_height="0dp"
15+
android:layout_weight="1"
2816
android:inAnimation="@android:anim/fade_in"
2917
android:outAnimation="@android:anim/fade_out"
30-
android:layout_above="@id/bottom_separator"
31-
android:layout_alignParentTop="true"
3218
android:clipChildren="false"
3319
android:clipToPadding="false"
3420
android:measureAllChildren="false">
@@ -155,4 +141,16 @@
155141
</LinearLayout>
156142
</ViewAnimator>
157143

158-
</RelativeLayout>
144+
<View
145+
android:id="@+id/bottom_separator"
146+
android:layout_width="match_parent"
147+
android:layout_height="1sp"
148+
android:background="@color/color_separator" />
149+
150+
<ViewStub
151+
android:id="@+id/status_bar"
152+
android:inflatedId="@+id/status_bar"
153+
android:layout_width="match_parent"
154+
android:layout_height="wrap_content" />
155+
156+
</LinearLayout>

0 commit comments

Comments
 (0)