diff --git a/app/src/main/java/crazydude/com/telemetry/ui/TextViewOutline.java b/app/src/main/java/crazydude/com/telemetry/ui/TextViewOutline.java index dba18914..86512eb9 100644 --- a/app/src/main/java/crazydude/com/telemetry/ui/TextViewOutline.java +++ b/app/src/main/java/crazydude/com/telemetry/ui/TextViewOutline.java @@ -6,6 +6,7 @@ import android.graphics.Color; import android.graphics.Paint; import android.util.AttributeSet; +import android.util.TypedValue; import androidx.appcompat.widget.AppCompatTextView; @@ -73,10 +74,35 @@ private void setPaintToRegular() { super.setShadowLayer(0, 0, 0, Color.TRANSPARENT); } + private int measureDimension(int desiredSize, int measureSpec) { + int result; + int specMode = MeasureSpec.getMode(measureSpec); + int specSize = MeasureSpec.getSize(measureSpec); + + if (specMode == MeasureSpec.EXACTLY) { + result = specSize; + } else { + result = desiredSize; + if (specMode == MeasureSpec.AT_MOST) { + result = Math.min(result, specSize); + } + } + return result; + } + + public static int dpToPx(float dp, Context context) { + return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics()); + } + @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setPaintToOutline(); super.onMeasure(widthMeasureSpec, heightMeasureSpec); + + int outlineWidth = this.dpToPx(mOutlineSize, getContext()); + + this.setMeasuredDimension( this.measureDimension( getMeasuredWidth()+outlineWidth, widthMeasureSpec), + this.measureDimension( getMeasuredHeight()+outlineWidth, heightMeasureSpec)); } @Override diff --git a/app/src/main/res/layout/activity_maps.xml b/app/src/main/res/layout/activity_maps.xml index c85d2f1f..5754e157 100644 --- a/app/src/main/res/layout/activity_maps.xml +++ b/app/src/main/res/layout/activity_maps.xml @@ -45,7 +45,8 @@ android:text="Disconnected" android:layout_above="@id/seekbar" android:textColor="@android:color/white" - android:textSize="18sp" /> + android:textSize="18sp" + android:gravity="center"/>