Skip to content

Commit

Permalink
custom class TextShadow used instead of generic Map
Browse files Browse the repository at this point in the history
  • Loading branch information
anderbytes authored and burhanrashid52 committed Jul 10, 2021
1 parent 876e801 commit 1eaacf6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
14 changes: 7 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> 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);

}

/**
Expand Down Expand Up @@ -136,12 +131,8 @@ void applyStyle(@NonNull TextView textView) {
break;

case SHADOW: {
final Map<String, Object> 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;

Expand Down Expand Up @@ -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)}
*/
Expand Down

0 comments on commit 1eaacf6

Please sign in to comment.