Skip to content

Commit

Permalink
Survey customizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Serrano committed Jul 17, 2024
1 parent b5e37fe commit fc05f09
Show file tree
Hide file tree
Showing 15 changed files with 355 additions and 50 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.27.0 (2024-07-17)

- Add survey customizations

## 2.26.1 (2024-03-01)

- Fix disclaimer's TextView gravity for ReactNative & Flutter
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ If you use Maven, you can include this library as a dependency:
<dependency>
<groupId>com.wootric</groupId>
<artifactId>wootric-sdk-android</artifactId>
<version>2.26.1</version>
<version>2.27.0</version>
</dependency>
```

### Using Gradle

```xml
implementation 'com.wootric:wootric-sdk-android:2.26.1'
implementation 'com.wootric:wootric-sdk-android:2.27.0'
```

## Initializing Wootric
Expand Down
4 changes: 2 additions & 2 deletions androidsdk/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VERSION_NAME=2.26.1
VERSION_CODE=2261
VERSION_NAME=2.27.0
VERSION_CODE=2270
GROUP=com.wootric

POM_DESCRIPTION=WootricSDK Android
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class Settings implements Parcelable {
private WootricSocial adminPanelSocial;
private WootricSocial localSocial;

private WootricCustomColor adminPanelCustomColors;

private WootricCustomThankYou localCustomThankYou;
private WootricCustomThankYou adminPanelCustomThankYou;

Expand Down Expand Up @@ -87,6 +89,8 @@ public class Settings implements Parcelable {
private int socialSharingColor = Constants.NOT_SET;
private int surveyTypeScale = 0;

private String scoreScaleType = "filled";

private String clientID;
private String accountToken;

Expand All @@ -105,6 +109,7 @@ public Settings(Settings settings) {
this.localCustomMessage = new WootricCustomMessage(settings.getLocalCustomMessage());
this.adminPanelSocial = new WootricSocial(settings.adminPanelSocial);
this.localSocial = new WootricSocial(settings.localSocial);
this.adminPanelCustomColors = new WootricCustomColor(settings.adminPanelCustomColors);
this.localCustomThankYou = new WootricCustomThankYou(settings.localCustomThankYou);
this.adminPanelCustomThankYou = new WootricCustomThankYou(settings.adminPanelCustomThankYou);
this.timeDelay = settings.timeDelay;
Expand Down Expand Up @@ -151,6 +156,7 @@ public void mergeWithSurveyServerSettings(Settings settings) {
this.adminPanelTimeDelay = settings.adminPanelTimeDelay;
this.adminPanelCustomThankYou = settings.adminPanelCustomThankYou;
this.adminPanelSocial = settings.adminPanelSocial;
this.adminPanelCustomColors = settings.adminPanelCustomColors;
this.driverPicklist = settings.driverPicklist;
this.localizedTexts = settings.localizedTexts;
this.userID = settings.userID;
Expand Down Expand Up @@ -725,6 +731,8 @@ public void setCustomSurveyTypeScale(int customSurveyTypeScale) {
public int getSurveyColor() {
if (surveyColor != Constants.NOT_SET){
return surveyColor;
} else if (adminPanelCustomColors != null && adminPanelCustomColors.getCustomPrimaryColor() != Constants.NOT_SET) {
return adminPanelCustomColors.getCustomPrimaryColor();
}
return R.color.wootric_survey_layout_header_background;
}
Expand All @@ -736,6 +744,8 @@ public void setSurveyColor(int surveyColor) {
public int getScoreColor() {
if (scoreColor != Constants.NOT_SET){
return scoreColor;
} else if (adminPanelCustomColors != null && adminPanelCustomColors.getCustomSecondaryColor() != Constants.NOT_SET) {
return adminPanelCustomColors.getCustomSecondaryColor();
}
return R.color.wootric_score_color;
}
Expand All @@ -744,6 +754,13 @@ public void setScoreColor(int scoreColor) {
this.scoreColor = scoreColor;
}

public String getScoreScaleType() {
if (adminPanelCustomColors != null && this.adminPanelCustomColors.getCustomScoreScaleType() != "") {
return this.adminPanelCustomColors.getCustomScoreScaleType();
}
return "unfilled";
}

public void setDisclaimer(String disclaimerText, Uri disclaimerLinkURL, String disclaimerLinkText) {
if (isBlank(disclaimerText)) {
Log.w(Constants.TAG, "setDisclaimer - disclaimerText cannot be blank.");
Expand All @@ -765,6 +782,8 @@ public void setDisclaimer(String disclaimerText, Uri disclaimerLinkURL, String d
public int getThankYouButtonBackgroundColor () {
if (thankYouButtonBackgroundColor != Constants.NOT_SET) {
return thankYouButtonBackgroundColor;
} else if (adminPanelCustomColors != null && adminPanelCustomColors.getCustomSecondaryColor() != Constants.NOT_SET) {
return adminPanelCustomColors.getCustomSecondaryColor();
}
return R.color.wootric_score_color;
}
Expand All @@ -776,6 +795,8 @@ public void setThankYouButtonBackgroundColor (int thankYouButtonBackgroundColor)
public int getSocialSharingColor () {
if (socialSharingColor != Constants.NOT_SET) {
return socialSharingColor;
} else if (adminPanelCustomColors != null && adminPanelCustomColors.getCustomSecondaryColor() != Constants.NOT_SET) {
return adminPanelCustomColors.getCustomSecondaryColor();
}
return R.color.wootric_social;
}
Expand All @@ -784,6 +805,13 @@ public void setSocialSharingColor (int socialSharingColor) {
this.socialSharingColor = socialSharingColor;
}

public int getDriverPicklistColor () {
if (adminPanelCustomColors != null && adminPanelCustomColors.getCustomSecondaryColor() != Constants.NOT_SET) {
return adminPanelCustomColors.getCustomSecondaryColor();
}
return R.color.wootric_score_color;
}

public String getAccountToken() {
return this.accountToken;
}
Expand Down Expand Up @@ -826,6 +854,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeParcelable(this.adminPanelCustomThankYou, 0);
dest.writeParcelable(this.localSocial, 0);
dest.writeParcelable(this.adminPanelSocial, 0);
dest.writeParcelable(this.adminPanelCustomColors, 0);
dest.writeString(this.accountToken);
dest.writeString(this.clientID);
dest.writeByte(this.showDisclaimer ? (byte) 1 : (byte) 0);
Expand Down Expand Up @@ -862,6 +891,7 @@ private Settings(Parcel in) {
this.adminPanelCustomThankYou = in.readParcelable(WootricCustomThankYou.class.getClassLoader());
this.localSocial = in.readParcelable(WootricSocial.class.getClassLoader());
this.adminPanelSocial = in.readParcelable(WootricSocial.class.getClassLoader());
this.adminPanelCustomColors = in.readParcelable(WootricCustomColor.class.getClassLoader());
this.accountToken = in.readString();
this.clientID = in.readString();
this.showDisclaimer = in.readByte() != 0;
Expand Down Expand Up @@ -932,6 +962,9 @@ public static Settings fromJson(JSONObject settingsObject) throws JSONException
JSONObject socialJson = settingsObject.optJSONObject("social");
settings.adminPanelSocial = WootricSocial.fromJson(socialJson);

JSONObject customColorsJson = settingsObject.optJSONObject("custom_colors");
settings.adminPanelCustomColors = WootricCustomColor.fromJson(customColorsJson);

return settings;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Copyright (c) 2024 Wootric (https://wootric.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package com.wootric.androidsdk.objects;

import android.graphics.Color;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

import com.wootric.androidsdk.utils.Utils;

import org.json.JSONException;
import org.json.JSONObject;

/**
* Created by diegoserranoa on 3/28/24.
*/
public class WootricCustomColor implements Parcelable {
private static final String CUSTOM_PRIMARY_COLOR_KEY = "custom_primary_color";
private static final String CUSTOM_SECONDARY_COLOR_KEY = "custom_secondary_color";
private static final String SCORE_SCALE_TYPE_KEY = "score_scale_type";
private String customPrimaryColor;
private String customSecondaryColor;
private String customScoreScaleType;

public WootricCustomColor() {}

public WootricCustomColor(WootricCustomColor wootricCustomColor) {
if (wootricCustomColor == null) return;
this.customPrimaryColor = wootricCustomColor.customPrimaryColor;
this.customSecondaryColor = wootricCustomColor.customSecondaryColor;
this.customScoreScaleType = wootricCustomColor.customScoreScaleType;
}

public int getCustomPrimaryColor() {
if (this.customPrimaryColor != "null") {
try {
return Color.parseColor(this.customPrimaryColor);
} catch (IllegalArgumentException ex) {
return Color.parseColor("#253746");
}
}
return Color.parseColor("#253746");
}

public int getCustomSecondaryColor() {
if (Utils.isNotEmpty(this.customSecondaryColor) && this.customSecondaryColor != "null") {
try {
return Color.parseColor(this.customSecondaryColor);
} catch (IllegalArgumentException ex) {
return Color.parseColor("#B3CDFF");
}
}
return Color.parseColor("#B3CDFF");
}

public String getCustomScoreScaleType() {
return customScoreScaleType;
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.customPrimaryColor);
dest.writeString(this.customSecondaryColor);
dest.writeString(this.customScoreScaleType);
}

private WootricCustomColor(Parcel in) {
this.customPrimaryColor = in.readString();
this.customSecondaryColor = in.readString();
this.customScoreScaleType = in.readString();
}

public static final Creator<WootricCustomColor> CREATOR = new Creator<WootricCustomColor>() {
public WootricCustomColor createFromParcel(Parcel source) {
return new WootricCustomColor(source);
}
public WootricCustomColor[] newArray(int size) {
return new WootricCustomColor[size];
}
};

public static WootricCustomColor fromJson(JSONObject customColorsJson) throws JSONException {
if(customColorsJson == null) return null;

WootricCustomColor wootricCustomColor = new WootricCustomColor();
wootricCustomColor.customPrimaryColor = customColorsJson.optString(CUSTOM_PRIMARY_COLOR_KEY);
wootricCustomColor.customSecondaryColor = customColorsJson.optString(CUSTOM_SECONDARY_COLOR_KEY);
wootricCustomColor.customScoreScaleType = customColorsJson.optString(SCORE_SCALE_TYPE_KEY);

return wootricCustomColor;
}
}
52 changes: 52 additions & 0 deletions androidsdk/src/main/java/com/wootric/androidsdk/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ClickableSpan;
import android.graphics.Color;
import android.util.Log;
import android.view.View;

import androidx.core.graphics.ColorUtils;

import com.wootric.androidsdk.Constants;

import java.util.Date;
Expand Down Expand Up @@ -95,4 +98,53 @@ public static SpannableString getSpannableString(ClickableSpan clickableSpan, St
ss.setSpan(clickableSpan, disclaimerText.length() + 1, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return ss;
}

public static int getDarkerColor(int color, float percentage) {
return ColorUtils.blendARGB(color, Color.BLACK, percentage);
}

public static int getLighterColor(int color, float percentage) {
return ColorUtils.blendARGB(color, Color.WHITE, percentage);
}

private static int fontColor(String color) {
int num = Integer.parseInt(color.substring(1, 7), 16);
int red = (num >> 16) & 0xFF;
int green = (num >> 8) & 0xFF;
int blue = num & 0xFF;
double alpha = color.length() > 7 ? Integer.parseInt(color.substring(7, 9), 16) / 255.0 : 1;

red = (int) Math.round((1 - alpha) * 255 + alpha * red);
green = (int) Math.round((1 - alpha) * 255 + alpha * green);
blue = (int) Math.round((1 - alpha) * 255 + alpha * blue);

double yiq = ((red * 299) + (green * 587) + (blue * 114)) / 1000.0;
return yiq >= 128 ? Color.BLACK : Color.WHITE;
}

private static int fontColor(int color) {
int num = color;
int red = (num >> 16) & 0xFF;
int green = (num >> 8) & 0xFF;
int blue = num & 0xFF;
double alpha = 1;

red = (int) Math.round((1 - alpha) * 255 + alpha * red);
green = (int) Math.round((1 - alpha) * 255 + alpha * green);
blue = (int) Math.round((1 - alpha) * 255 + alpha * blue);

double yiq = ((red * 299) + (green * 587) + (blue * 114)) / 1000.0;
return yiq >= 128 ? Color.BLACK : Color.WHITE;
}

public static int getTextColor(int color, String scoreScaleType, boolean isSelected) {
if (isSelected || scoreScaleType.equals("filled")) {
if (color != 0) {
return fontColor(color);
} else {
return fontColor("#253746");
}
}
return Color.BLACK;
}
}
Loading

0 comments on commit fc05f09

Please sign in to comment.