]> git.ktnx.net Git - mobile-ledger.git/commitdiff
fix ring placement in the color selector dialog
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 13 Apr 2019 19:57:16 +0000 (22:57 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 13 Apr 2019 20:11:20 +0000 (23:11 +0300)
worked fine on 7.1, but was empty on 5.1

app/src/main/java/net/ktnx/mobileledger/ui/HueRing.java
app/src/main/res/layout/hue_dialog.xml

index 2de15fe2f4b01efb2d7c17f6e542976f7a9de57a..0a759a0a6739c0c459e8564a4c2f1905f88e04c9 100644 (file)
@@ -29,6 +29,7 @@ import android.view.MotionEvent;
 import android.view.View;
 
 import net.ktnx.mobileledger.utils.Colors;
+import net.ktnx.mobileledger.utils.DimensionUtils;
 
 import androidx.annotation.Nullable;
 
@@ -92,6 +93,8 @@ public class HueRing extends View {
 
         setInitialHue(initialHueDegrees);
         setHue(initialHueDegrees);
+
+        padding = DimensionUtils.dp2px(getContext(), 4);
     }
     public int getColor() {
         return color;
@@ -121,9 +124,10 @@ public class HueRing extends View {
     protected void onDraw(Canvas canvas) {
         super.onDraw(canvas);
 
+        float center = getWidth() / 2f;
         ringPaint.setStrokeWidth((int) bandWidth);
 
-        canvas.translate(centerX, centerY);
+        canvas.translate(center, center);
         canvas.drawOval(ringRect, ringPaint);
 
         canvas.drawArc(centerRect, 180, 180, true, initialPaint);
@@ -141,17 +145,18 @@ public class HueRing extends View {
         int heightMode = View.MeasureSpec.getMode(heightMeasureSpec);
         int heightSize = View.MeasureSpec.getSize(heightMeasureSpec);
 
-        if (((widthMode == MeasureSpec.AT_MOST) && (heightMode == MeasureSpec.AT_MOST)) ||
-            ((widthMode == MeasureSpec.EXACTLY) && (heightMode == MeasureSpec.EXACTLY)))
-        {
+        if ((widthMode == MeasureSpec.AT_MOST) && (heightMode == MeasureSpec.AT_MOST)) {
             diameter = Math.min(widthSize, heightSize);
         }
+        else {
+            setMeasuredDimension(MEASURED_STATE_TOO_SMALL, MEASURED_STATE_TOO_SMALL);
+            return;
+        }
 
         setMeasuredDimension(diameter, diameter);
 
 //        padding = DimensionUtils.dp2px(getContext(),
 //                getContext().getResources().getDimension(R.dimen.activity_horizontal_margin)) / 2;
-        padding = 0;
         diameter -= 2 * padding;
         radius = diameter / 2f;
         centerX = padding + (int) radius;
index 758809e133e9d4f70dd5ed19d2710d9724b88118..e884f18dca37ce02e7bcfd815bac3d7a2eb04727 100644 (file)
@@ -26,7 +26,7 @@
 
     <net.ktnx.mobileledger.ui.HueRing
         android:id="@+id/ring"
-        android:layout_width="match_parent"
+        android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         app:layout_constraintBottom_toTopOf="@id/button_pane"
         app:layout_constraintEnd_toEndOf="parent"