Skip to content

Commit 7934f2b

Browse files
committed
loading stings with stringResource.
1 parent 0b8244f commit 7934f2b

12 files changed

+60
-50
lines changed

library/src/main/java/io/syslogic/colorpicker/AlphaPatternDrawable.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
/**
1616
* This drawable that draws a simple white and gray chessboard pattern.
17-
*
1817
* @author Martin Zeitler
1918
*/
2019
public class AlphaPatternDrawable extends Drawable {

library/src/main/java/io/syslogic/colorpicker/ColorPickerDialogFragment.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
/**
2727
* The Color-Picker {@link DialogFragment} accepts NavArgs and returns a FragmentResult.
28-
*
2928
* @author Martin Zeitler
3029
*/
3130
public class ColorPickerDialogFragment extends DialogFragment implements

library/src/main/java/io/syslogic/colorpicker/ColorPickerDialogFragmentImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.syslogic.colorpicker;
22

33
/**
4-
* ColorPickerDialogFragment Impl
4+
* ColorPickerDialogFragment Impl.
55
* Used to instance ColorPickerDialogFragmentImpl from ColorPickerPreference.
66
* @author Martin Zeitler
77
*/

library/src/main/java/io/syslogic/colorpicker/ColorPickerPanelView.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
import androidx.annotation.NonNull;
1212

1313
/**
14-
* The Color-Picker Panel {@link View}
15-
*
14+
* The Color-Picker Panel {@link View}.
1615
* This class draws a panel which which will be filled with a color which can be set.
1716
* It can be used to show the currently selected color which you will get from the {@link ColorPickerView}.
1817
* @author Martin Zeitler

library/src/main/java/io/syslogic/colorpicker/ColorPickerPreference.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
import java.util.Locale;
2626

2727
/**
28-
* The Color-Picker {@link Preference}
29-
*
28+
* The Color-Picker {@link Preference}.
3029
* @author Martin Zeitler
3130
*/
3231
public class ColorPickerPreference extends Preference implements

library/src/main/java/io/syslogic/colorpicker/ColorPickerView.java

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
* The Color-Picker {@link View} (refactored version).
3030
* It displays a color picker to the user and allow them to select a color.
3131
* the slider for the alpha-channel can be enabled setAlphaSliderVisible(true).
32-
*
3332
* @author Martin Zeitler
3433
*/
3534
public class ColorPickerView extends View {
@@ -362,42 +361,52 @@ public boolean onTrackballEvent(@NonNull MotionEvent event) {
362361
boolean update = false;
363362
if (event.getAction() == MotionEvent.ACTION_MOVE) {
364363
switch (mLastTouchedPanel) {
365-
366-
case PANEL_SAT:
364+
case PANEL_SAT -> {
367365
float sat, val;
368366
sat = mSaturation + x / 50f;
369367
val = mContrast - y / 50f;
370-
if (sat < 0f) {sat = 0f;}
371-
else if (sat > 1f) {sat = 1f;}
372-
if (val < 0f) {val = 0f;}
373-
else if (val > 1f) {val = 1f;}
368+
if (sat < 0f) {
369+
sat = 0f;
370+
} else if (sat > 1f) {
371+
sat = 1f;
372+
}
373+
if (val < 0f) {
374+
val = 0f;
375+
} else if (val > 1f) {
376+
val = 1f;
377+
}
374378
mSaturation = sat;
375379
mContrast = val;
376380
update = true;
377-
break;
378-
379-
case PANEL_HUE:
381+
}
382+
case PANEL_HUE -> {
380383
float hue = mHue - y * 10f;
381-
if (hue < 0f) {hue = 0f;}
382-
else if (hue > 360f) {hue = 360f;}
384+
if (hue < 0f) {
385+
hue = 0f;
386+
} else if (hue > 360f) {
387+
hue = 360f;
388+
}
383389
mHue = hue;
384390
update = true;
385-
break;
386-
387-
case PANEL_ALPHA:
391+
}
392+
case PANEL_ALPHA -> {
388393
if (mShowAlphaPanel || mAlphaRect != null) {
389394
int alpha = (int) (mAlpha - x * 10);
390-
if (alpha < 0) {alpha = 0;}
391-
else if (alpha > 0xff) {alpha = 0xff;}
395+
if (alpha < 0) {
396+
alpha = 0;
397+
} else if (alpha > 0xff) {
398+
alpha = 0xff;
399+
}
392400
mAlpha = alpha;
393401
update = true;
394402
}
395-
break;
403+
}
396404
}
397405
}
398406
if (update) {
399407
if (mListener != null) {
400-
mListener.onColorChanged(Color.HSVToColor(mAlpha, new float[]{mHue, mSaturation, mContrast}));
408+
int intValue = Color.HSVToColor(mAlpha, new float[]{mHue, mSaturation, mContrast});
409+
mListener.onColorChanged(intValue);
401410
}
402411
invalidate();
403412
return true;
@@ -649,8 +658,8 @@ public float getDrawingOffset() {
649658
*
650659
* @param visible whether to show the alpha-slider panel.
651660
*/
661+
@SuppressWarnings("unused")
652662
public void setAlphaSliderVisible(boolean visible) {
653-
654663
if (mShowAlphaPanel != visible) {
655664
mShowAlphaPanel = visible;
656665

@@ -663,6 +672,7 @@ public void setAlphaSliderVisible(boolean visible) {
663672
}
664673
}
665674

675+
@SuppressWarnings("unused")
666676
public boolean getAlphaSliderVisible() {
667677
return mShowAlphaPanel;
668678
}

library/src/main/java/io/syslogic/colorpicker/OnColorChangedListener.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
/**
44
* Color-Picker OnColorChangedListener.
5-
*
65
* @author Martin Zeitler
76
*/
87
public interface OnColorChangedListener {

library/src/main/java/io/syslogic/colorpicker/compose/ColorPickerComponent.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ fun ColorPickerComponent(
5858
val colPadding = dimensionResource(R.dimen.compose_col_padding)
5959

6060
/* All the values are being initialized by the `initialColor`. */
61-
var currentColor: Int by remember { mutableStateOf(initialColor.hashCode()) }
62-
var currentAlpha: Float by remember { mutableStateOf(initialColor.alpha) }
63-
var currentHue: Float by remember { mutableStateOf(getHSV(initialColor)[0]) }
64-
var currentSat: Float by remember { mutableStateOf(getHSV(initialColor)[1]) }
65-
var currentVal: Float by remember { mutableStateOf(getHSV(initialColor)[2]) }
61+
var currentColor: Int by remember { mutableIntStateOf(initialColor.hashCode()) }
62+
var currentAlpha: Float by remember { mutableFloatStateOf(initialColor.alpha) }
63+
var currentHue: Float by remember { mutableFloatStateOf(getHSV(initialColor)[0]) }
64+
var currentSat: Float by remember { mutableFloatStateOf(getHSV(initialColor)[1]) }
65+
var currentVal: Float by remember { mutableFloatStateOf(getHSV(initialColor)[2]) }
6666

6767
/* The measured position of the SatValPainter. */
6868
var offsetSatVal by remember { mutableStateOf(Offset.Zero) }
@@ -241,7 +241,7 @@ fun ColorPickerComponent(
241241

242242
/* Sat/Val Panel */
243243
Image(
244-
contentDescription = "Sat/Val by Hue",
244+
contentDescription = stringResource(R.string.text_label_panel_sat_val),
245245
contentScale = ContentScale.FillBounds,
246246
painter = SatValPainter(Size(900F, 900F)).also {
247247
it.setAlpha(currentAlpha)
@@ -285,7 +285,7 @@ fun ColorPickerComponent(
285285

286286
/* Hue Panel */
287287
Image(
288-
contentDescription = "Hue",
288+
contentDescription = stringResource(R.string.text_label_panel_hue),
289289
contentScale = ContentScale.FillBounds,
290290
painter = HuePainter(Size(100F, 900F)).also {
291291
it.setValue(currentHue)
@@ -330,7 +330,7 @@ fun ColorPickerComponent(
330330
contentAlignment = Alignment.Center
331331
) {
332332
Image(
333-
contentDescription = "Alpha Slider",
333+
contentDescription = stringResource(R.string.text_label_panel_alpha),
334334
contentScale = ContentScale.FillBounds,
335335
painter = AlphaPainter(Size(1014F, 80F)).also {
336336
it.setAlphaByColor(currentColor)
@@ -377,7 +377,7 @@ fun ColorPickerComponent(
377377
contentAlignment = Alignment.Center
378378
) {
379379
Text(
380-
text = "Hex Value: ${toARGB(currentColor)}",
380+
text = stringResource(R.string.text_label_panel_hex_value, toARGB(currentColor)),
381381
modifier = Modifier.testTag("hex")
382382
)
383383
}
@@ -394,7 +394,7 @@ fun ColorPickerComponent(
394394
contentAlignment = Alignment.Center
395395
) {
396396
Image(
397-
contentDescription = "Old Color",
397+
contentDescription = stringResource(R.string.text_label_panel_old_color),
398398
contentScale = ContentScale.FillBounds,
399399
painter = ColorPainter(Size(422F, 120F)).also {
400400
it.setValue(initialColor)
@@ -432,7 +432,7 @@ fun ColorPickerComponent(
432432
) {
433433

434434
Image(
435-
contentDescription = "New Color",
435+
contentDescription = stringResource(R.string.text_label_panel_new_color),
436436
contentScale = ContentScale.FillBounds,
437437
painter = ColorPainter(Size(422F, 120F)).also {
438438
it.setValue(currentColor)

library/src/main/java/io/syslogic/colorpicker/compose/ColorPickerDialog.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fun ColorPickerDialog(
4545
) {
4646

4747
/* The value is being initialized by the `initialColor`. */
48-
val currentColor: Int by remember { mutableStateOf(initialColor.hashCode()) }
48+
val currentColor: Int by remember { mutableIntStateOf(initialColor.hashCode()) }
4949

5050
Dialog(
5151
onDismissRequest = {

library/src/main/res/layout-land/dialog_fragment_color_picker.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
<io.syslogic.colorpicker.ColorPickerPanelView
4242
android:id="@+id/old_color_panel"
43-
android:contentDescription="@string/text_label_old_color_panel"
43+
android:contentDescription="@string/text_label_panel_old_color"
4444
android:layout_width="0dp"
4545
android:layout_height="match_parent"
4646
android:layout_weight="0.50"/>
@@ -55,7 +55,7 @@
5555

5656
<io.syslogic.colorpicker.ColorPickerPanelView
5757
android:id="@+id/new_color_panel"
58-
android:contentDescription="@string/text_label_new_color_panel"
58+
android:contentDescription="@string/text_label_panel_new_color"
5959
android:layout_width="0dp"
6060
android:layout_height="match_parent"
6161
android:layout_weight="0.50"/>
@@ -67,7 +67,7 @@
6767
android:layout_width="match_parent"
6868
android:layout_height="wrap_content"
6969
android:gravity="center_vertical|end"
70-
android:hint="@string/text_hexadecimal_value"
70+
android:hint="@string/hint_hexadecimal_value"
7171
android:imeOptions="actionDone"
7272
android:maxLength="7"
7373
android:maxLines="1"

0 commit comments

Comments
 (0)