Skip to content

Commit 38d9b16

Browse files
committed
preventing excessive values.
1 parent 5016dfc commit 38d9b16

File tree

6 files changed

+45
-26
lines changed

6 files changed

+45
-26
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The library is generally available on JitPack; either by version tag or `master-
88
The JitPack repository URL would be: `maven { url 'https://jitpack.io' }`
99

1010
dependencies {
11-
implementation "io.syslogic:androidx-colorpicker:1.1.6"
11+
implementation "io.syslogic:androidx-colorpicker:1.1.7"
1212
}
1313

1414
Alternatively, one can also check out the repository and depend on the local `:library` module:

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Root project build.gradle
22
buildscript {
33
ext {
4-
version_name = '1.1.6'
4+
version_name = '1.1.7'
55
version_code = 16
66
compile_sdk = 34
77
target_sdk = 34

library/build.gradle

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ plugins {
77
}
88

99
android {
10+
1011
compileSdk compile_sdk
1112
namespace 'io.syslogic.colorpicker'
1213
defaultConfig {
@@ -16,25 +17,28 @@ android {
1617
targetSdk target_sdk
1718
minSdk min_sdk
1819
}
20+
1921
compileOptions {
2022
sourceCompatibility JavaVersion.VERSION_17
2123
targetCompatibility JavaVersion.VERSION_17
2224
}
25+
2326
kotlinOptions {
2427
jvmTarget = 17
2528
}
29+
2630
composeOptions {
31+
// See the "Compose to Kotlin Compatibility Map" for compatible versions:
32+
// https://developer.android.com/jetpack/androidx/releases/compose-kotlin
2733
kotlinCompilerExtensionVersion kotlin_compiler_extension_version
2834
}
29-
packagingOptions {
30-
resources.pickFirsts.add('META-INF/LGPL2.1')
31-
resources.pickFirsts.add('META-INF/AL2.0')
32-
}
35+
3336
buildFeatures {
3437
buildConfig true
3538
dataBinding true
3639
compose true
3740
}
41+
3842
buildTypes {
3943
debug {
4044
// it breaks the data-binding, eg. when running ./gradlew :library:publishToMavenLocal
@@ -45,13 +49,20 @@ android {
4549
minifyEnabled false
4650
}
4751
}
52+
4853
lint {
4954
lintConfig file('../lint.xml')
5055
checkAllWarnings true
5156
warningsAsErrors true
5257
abortOnError false
5358
showAll false
5459
}
60+
61+
packagingOptions {
62+
resources.pickFirsts.add('META-INF/LGPL2.1')
63+
resources.pickFirsts.add('META-INF/AL2.0')
64+
}
65+
5566
publishing {
5667
singleVariant('release') {
5768
withSourcesJar()

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,10 @@ public boolean onPreferenceClick(@NonNull Preference preference) {
124124
public boolean onPreferenceChange(@NonNull Preference preference, @NonNull Object newValue) {
125125
this.mCurrentValue = Integer.parseInt(newValue.toString());
126126
this.setSummary(convertToARGB(this.mCurrentValue));
127-
if (preference.getIcon() instanceof BitmapDrawable) {
128-
BitmapDrawable drawable = (BitmapDrawable) preference.getIcon();
127+
if (preference.getIcon() instanceof BitmapDrawable drawable) {
129128
drawable.setTintMode(PorterDuff.Mode.ADD);
130129
drawable.setTint(this.mCurrentValue);
131-
} else if (preference.getIcon() instanceof VectorDrawable) {
132-
VectorDrawable drawable = (VectorDrawable) preference.getIcon();
130+
} else if (preference.getIcon() instanceof VectorDrawable drawable) {
133131
drawable.setTintMode(PorterDuff.Mode.ADD);
134132
drawable.setTint(this.mCurrentValue);
135133
} else if(mDebug) {
@@ -224,12 +222,11 @@ protected Parcelable onSaveInstanceState() {
224222

225223
@Override
226224
protected void onRestoreInstanceState(@Nullable Parcelable state) {
227-
if (!(state instanceof SavedState)) {
225+
if (!(state instanceof SavedState myState)) {
228226
// didn't save state in onSaveInstanceState
229227
super.onRestoreInstanceState(state);
230228
return;
231229
}
232-
SavedState myState = (SavedState) state;
233230
super.onRestoreInstanceState(myState.getSuperState());
234231
}
235232

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -411,20 +411,15 @@ public boolean onTrackballEvent(@NonNull MotionEvent event) {
411411
public boolean onTouchEvent(@NonNull MotionEvent event) {
412412
boolean update = false;
413413
switch (event.getAction()) {
414-
415-
case MotionEvent.ACTION_DOWN:
414+
case MotionEvent.ACTION_DOWN -> {
416415
mStartTouchPoint = new Point((int) event.getX(), (int) event.getY());
417416
update = moveTrackersIfNeeded(event);
418-
break;
419-
420-
case MotionEvent.ACTION_MOVE:
421-
update = moveTrackersIfNeeded(event);
422-
break;
423-
424-
case MotionEvent.ACTION_UP:
417+
}
418+
case MotionEvent.ACTION_MOVE -> update = moveTrackersIfNeeded(event);
419+
case MotionEvent.ACTION_UP -> {
425420
mStartTouchPoint = null;
426421
update = moveTrackersIfNeeded(event);
427-
break;
422+
}
428423
}
429424

430425
if (update) {

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -546,37 +546,53 @@ fun getChannelValue(color: Int, name: String): String {
546546
}
547547

548548
/**
549+
* Excessive values may occur and must be limited.
549550
* @param rect boundaries of the hue rectangle.
550551
* @param y the relative position on the y axis.
551552
* @return hue 0.0F to 360.0F.
552553
*/
553554
private fun pointToHue(rect: RectF, y: Float): Float {
554-
return 360f - y * 360f / rect.height()
555+
val value = 360f - y * 360f / rect.height()
556+
if (value <= 0f) {return 0f}
557+
if (value >= 360f) {return 360f}
558+
return value
555559
}
556560

557561
/**
562+
* Excessive values may occur and must be limited.
558563
* @param rect boundaries of the sat/val rectangle.
559564
* @param x the relative position on the x axis.
560565
* @return sat 0.0F to 1.0F.
561566
*/
562567
private fun pointToSat(rect: RectF, x: Float): Float {
563-
return 1f / rect.width() * x
568+
val value = 1f / rect.width() * x
569+
if (value <= 0f) {return 0f}
570+
if (value >= 1f) {return 1f}
571+
return value
564572
}
565573

566574
/**
575+
* Excessive values may occur and must be limited.
567576
* @param rect boundaries of the sat/val rectangle.
568577
* @param y the relative position on the x axis.
569578
* @return value 0.0F to 1.0F.
570579
*/
571580
private fun pointToVal(rect: RectF, y: Float): Float {
572-
return 1f - 1f / rect.height() * y
581+
val value = 1f - 1f / rect.height() * y
582+
if (value <= 0f) {return 0f}
583+
if (value >= 1f) {return 1f}
584+
return value
573585
}
574586

575587
/**
588+
* Excessive values may occur and must be limited.
576589
* @param rect boundaries of the alpha rectangle.
577590
* @param x the relative position on the x axis.
578591
* @return alpha 0.0F to 1.0F.
579592
*/
580593
private fun pointToAlpha(rect: RectF, x: Float): Float {
581-
return x / rect.width()
594+
val value = x / rect.width()
595+
if (value <= 0f) {return 0f}
596+
if (value >= 1f) {return 1f}
597+
return value
582598
}

0 commit comments

Comments
 (0)