Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autosize text inside Element #19

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
import static org.secuso.privacyfriendly2048.helpers.ThemeResolverKt.GetColorInt;
import static org.secuso.privacyfriendly2048.helpers.ThemeResolverKt.GetColorRes;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.util.TypedValue;
import android.view.View;

import org.secuso.privacyfriendly2048.R;
Expand All @@ -50,18 +52,22 @@ public class Element extends androidx.appcompat.widget.AppCompatButton {
public int dPosY = 0;
public boolean activated;
public boolean animateMoving = false;
public float textSize = 24;
Context context;
int color;


@SuppressLint("RestrictedApi")
public Element(Context c) {
super(c);
context = c;
setAllCaps(false);
setTextSize(textSize);
setBackgroundResource(R.drawable.game_brick);
setColor(GetColorRes(context, R.attr.buttonEmpty));
setMaxLines(1);
setAutoSizeTextTypeUniformWithConfiguration(1,
100,
1,
TypedValue.COMPLEX_UNIT_SP);
}

public void drawItem() {
Expand Down Expand Up @@ -136,14 +142,10 @@ public void drawItem() {
case 16384:
setColor(GetColorRes(context, R.attr.button16384));
setTextColor(GetColorInt(context, R.attr.button16384Text));
textSize = textSize * 0.8f;
setTextSize(textSize);
break;
case 32768:
setColor(GetColorRes(context, R.attr.button32768));
setTextColor(GetColorInt(context, R.attr.button32768Text));
textSize = textSize * 0.8f;
setTextSize(textSize);
break;
}
}
Expand Down Expand Up @@ -197,11 +199,6 @@ public int getPosY() {
return posY;
}

public void updateFontSize() {
textSize = (float) (getLayoutParams().width / 7.0);
setTextSize(textSize);
}

public Element copy() {
Element temp = new Element(context);
temp.number = number;
Expand All @@ -212,9 +209,7 @@ public Element copy() {
temp.dPosY = dPosY;
temp.activated = activated;
temp.animateMoving = animateMoving;
temp.textSize = textSize;
temp.color = color;
temp.setTextSize(textSize);
//temp.setBackgroundResource(backGroundResource);
temp.setColor(color);
temp.setVisibility(getVisibility());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ record = gameStatistics.getRecord();
elements[i][j].setDPosition(lp.getMarginStart(), lp.topMargin);
elements[i][j].setLayoutParams(lp);
backgroundElements[i][j].setLayoutParams(lp);
elements[i][j].updateFontSize();
backgroundElements[i][j].setLayoutParams(lp);
backgroundElements[i][j].setOnTouchListener(swipeListener);
elements[i][j].setOnTouchListener(swipeListener);
Expand Down
Loading