Skip to content

Commit

Permalink
Merge pull request #19 from p-davide/fix
Browse files Browse the repository at this point in the history
Autosize text inside `Element`
  • Loading branch information
udenr authored Sep 3, 2024
2 parents 8e6e622 + 03d8969 commit 19b7f2f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
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

0 comments on commit 19b7f2f

Please sign in to comment.