MakerModder
MakerModder

Reputation: 1570

Artifact on Android P for the character 5 with Calligraphy 3

I have an android app using

io.github.inflationx:calligraphy3:3.0.0

With the following build settings

compileSdkVersion 28

buildToolsVersion "27.0.3"

Testing on Google Pixel XL OS android 9

What is interesting is, if I have a small text view that needs to show the 5 character, the text is elongated / squished in a weird way. This is for font_avenir_medium It only happens on the P devices, and it happens when the font SP is set below 25. But only for this font. If I change in to say avenir_book it will work fine.

This happened all over the app when I was on Calligraphy 2 and P came out, but other letters excluding the character '5' were resolved in 3. In that case more than the 5 was effected.

<TextView
               android:id="@+id/clockin_hour_count"
               android:text="5"
               android:textColor="@color/favor_blue"
               android:textSize="15sp"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_centerInParent="true"
               style="@style/AppTheme.MediumFontText"
               tools:ignore="MissingPrefix"
               />



   <style name="AppTheme.MediumFontText">
        <item name="fontPath">@string/font_avenir_medium</item>
    </style>

My base activity has the following and all other fonts are set correctly.

  @Override
  protected void attachBaseContext(Context newBase) {
    super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase));
  }

This is the CUSTOM VIEW in question, though theres really nothing interesting in it. Other than its a custom view.

public class ClockView extends LinearLayout {


....
  @BindView(R.id.clockin_hour_count)
  TextView mHoursCountTextview;

  public ClockView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mContext = context;
  }

  public void setData(@NonNull BootStrap bootStrap, EventBus eventBus, int selectedIndex) {
    init(selectedIndex);
   ...
  }

  private void init(int selectedIndex) {
    ...
  }

  public void updateHours(int numHours) {
    mNumHours = numHours;

        mHoursCountTextview.setText(
            mContext.getResources().getQuantityString(R.plurals.hours, numHours, numHours)
        );

    String text = String.format(getResources().getText(R.string.run_until).toString(), getHour(numHours));
    mRunTillButton.setText(text);
  }

  @OnClick(R.id.minus_clockin_button)
  public void onMinusClicked() {
    if (mNumHours > MIN_HOURS) {
      mNumHours--;
    }
    updateHours(mNumHours);
    updateHourButtonStates();
  }

  private void updateHourButtonStates() {
    minusIv.setEnabled(mNumHours > MIN_HOURS);
    plusIv.setEnabled(mNumHours < MAX_HOURS);

  }

  @OnClick(R.id.plus_clockin_button)
  public void onPlusClicked() {
    if (mNumHours < MAX_HOURS) {
      mNumHours++;
    }
    updateHours(mNumHours);
    updateHourButtonStates();
  }

  private String getHour(int numHours) {
    Calendar cal = Calendar.getInstance(); // creates calendar
    cal.setTime(new Date()); // sets calendar time/date
    cal.add(Calendar.HOUR_OF_DAY, numHours); // adds one hour
    cal.getTime(); // returns new date object, one hour in the future
    return sdf.format(cal.getTime());
  }

}

We can see here from left to right the effect. 15sp, 20sp, 25sp enter image description here

Upvotes: 1

Views: 158

Answers (0)

Related Questions