From 1eaacf6b0d117c39ebfe78b57ae080652484ea1f Mon Sep 17 00:00:00 2001 From: anderbytes Date: Mon, 5 Jul 2021 12:21:00 -0300 Subject: [PATCH] custom class TextShadow used instead of generic Map --- app/build.gradle | 14 ++++---- .../photoeditor/TextStyleBuilder.java | 35 ++++++++++++------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f355b214..9a8b5bc2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,9 +24,9 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' - implementation 'com.google.android.material:material:1.3.0' + implementation 'com.google.android.material:material:1.4.0' // NOTE(lucianocheng): Using the local photoeditor implementation instead of the published // maven package to faciliate testing, and for the integration tests @@ -35,10 +35,10 @@ dependencies { implementation project(':photoeditor') implementation 'androidx.cardview:cardview:1.0.0' - testImplementation 'junit:junit:4.12' + testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test:runner:1.3.0' - androidTestImplementation 'androidx.test:rules:1.3.0' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' - androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.3.0' + androidTestImplementation 'androidx.test:runner:1.4.0' + androidTestImplementation 'androidx.test:rules:1.4.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0' } diff --git a/photoeditor/src/main/java/ja/burhanrashid52/photoeditor/TextStyleBuilder.java b/photoeditor/src/main/java/ja/burhanrashid52/photoeditor/TextStyleBuilder.java index e22c8394..afbd2e8d 100644 --- a/photoeditor/src/main/java/ja/burhanrashid52/photoeditor/TextStyleBuilder.java +++ b/photoeditor/src/main/java/ja/burhanrashid52/photoeditor/TextStyleBuilder.java @@ -41,14 +41,9 @@ public void withTextSize(@NonNull float size) { * @param dy Vertical distance of the shadow * @param color Color of the shadow */ - public void withTextShadow(@NonNull float radius, float dx, float dy, int color) { - Map shadow = new HashMap<>(); - shadow.put("RADIUS", radius); - shadow.put("DX", dx); - shadow.put("DY", dy); - shadow.put("COLOR", color); + public void withTextShadow(@NonNull float radius, @NonNull float dx, @NonNull float dy, @NonNull int color) { + TextShadow shadow = new TextShadow(radius, dx, dy, color); values.put(TextStyle.SHADOW, shadow); - } /** @@ -136,12 +131,8 @@ void applyStyle(@NonNull TextView textView) { break; case SHADOW: { - final Map shadow = (Map) entry.getValue(); - final float radius = (float) shadow.get("RADIUS"); - final float dx = (float) shadow.get("DX"); - final float dy = (float) shadow.get("DY"); - final int color = (int) shadow.get("COLOR"); - applyTextShadow(textView, radius, dx, dy, color); + TextShadow shadow = (TextShadow) entry.getValue(); + applyTextShadow(textView, shadow.radius, shadow.dx, shadow.dy, shadow.color); } break; @@ -279,6 +270,24 @@ protected void applyTextAppearance(TextView textView, int styleAppearance) { } + /** + * Object to hold Text Shadow properties to be used + */ + + private static class TextShadow { + private final float radius; + private final float dx; + private final float dy; + private final int color; + + private TextShadow(float radius, float dx, float dy, int color) { + this.radius = radius; + this.dx = dx; + this.dy = dy; + this.color = color; + } + } + /** * Enum to maintain current supported style properties used on on {@link PhotoEditor#addText(String, TextStyleBuilder)} and {@link PhotoEditor#editText(View, String, TextStyleBuilder)} */