Skip to content

Commit

Permalink
Fix EditText background color and AlertDialog bug
Browse files Browse the repository at this point in the history
- Fix EditText background for Flutter
- Fix AlertDialog theme for Flutter
- Add checks for driver picklist fields
- Remove unused code
  • Loading branch information
Diego Serrano committed Mar 6, 2023
1 parent 26a639b commit 1bf2980
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 67 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 2.24.0 (2023-03-06)

- Add support for custom first question
- Fix EditText background for Flutter
- Fix AlertDialog theme for Flutter
- Add checks for driver picklist fields
- Remove unused code

## 2.23.0 (2023-02-09)

- Add support for Driver Picklist feature
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.23.0</version>
<version>2.24.0</version>
</dependency>
```

### Using Gradle

```xml
implementation 'com.wootric:wootric-sdk-android:2.23.0'
implementation 'com.wootric:wootric-sdk-android:2.24.0'
```

## Initializing Wootric
Expand Down
4 changes: 2 additions & 2 deletions androidsdk/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 30
compileSdkVersion 33
buildToolsVersion '29.0.2'

defaultConfig {
minSdkVersion 16
targetSdkVersion 30
targetSdkVersion 33
versionName project.VERSION_NAME
versionCode Integer.parseInt(project.VERSION_CODE)
buildConfigField 'String', 'VERSION_NAME', "\"" + project.VERSION_NAME + "\""
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.23.0
VERSION_CODE=2230
VERSION_NAME=2.24.0
VERSION_CODE=2240
GROUP=com.wootric

POM_DESCRIPTION=WootricSDK Android
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
Expand Down Expand Up @@ -62,7 +59,6 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -233,10 +229,6 @@ private void initSurveyViewElements() {

private void initFeedbackViewElements() {
mEtFeedback = (EditText) mLayoutBody.findViewById(R.id.wootric_et_feedback);
Drawable etFeedbackBackground = mEtFeedback.getBackground();
etFeedbackBackground.setColorFilter(mColorBlack, PorterDuff.Mode.SRC_ATOP);
etFeedbackBackground.setAlpha(26);
mEtFeedback.setOnFocusChangeListener(onEtFeedbackFocusChanged());
mEtFeedback.setImeActionLabel(mSettings.getBtnSubmit(), KeyEvent.KEYCODE_ENTER);
mEtFeedback.setImeOptions(EditorInfo.IME_ACTION_DONE);
mEtFeedback.setOnKeyListener(new OnKeyListener() {
Expand Down Expand Up @@ -277,19 +269,6 @@ private TextView buildScoreView(int score) {
return scoreView;
}

private OnFocusChangeListener onEtFeedbackFocusChanged() {
return new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus) {
Drawable etFeedbackBackground = mEtFeedback.getBackground();
etFeedbackBackground.setColorFilter(mColorSelected, PorterDuff.Mode.SRC_ATOP);
etFeedbackBackground.setAlpha(255);
}
}
};
}

@Override
public void onScoreChanged(int oldScore, int newScore) {
updateSelectedScore(oldScore, newScore);
Expand Down Expand Up @@ -431,32 +410,6 @@ private void setColors() {
mBtnDismiss.setTextColor(mColorEnabled);
mBtnEditScore.setBackgroundColor(mColorEnabled);
mTvSurveyHeader.setBackgroundColor(mColorEnabled);

setCursorDrawableColor(mEtFeedback, mColorSelected);
}

private static void setCursorDrawableColor(EditText editText, int color) {
try {
Field fCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
fCursorDrawableRes.setAccessible(true);
int mCursorDrawableRes = fCursorDrawableRes.getInt(editText);
Field fEditor = TextView.class.getDeclaredField("mEditor");
fEditor.setAccessible(true);
Object editor = fEditor.get(editText);
Class<?> clazz = editor.getClass();
Field fCursorDrawable = clazz.getDeclaredField("mCursorDrawable");
fCursorDrawable.setAccessible(true);

Drawable[] drawables = new Drawable[2];
Resources res = editText.getContext().getResources();
drawables[0] = res.getDrawable(mCursorDrawableRes);
drawables[1] = res.getDrawable(mCursorDrawableRes);
drawables[0].setColorFilter(color, PorterDuff.Mode.SRC_IN);
drawables[1].setColorFilter(color, PorterDuff.Mode.SRC_IN);
fCursorDrawable.set(editor, drawables);
} catch (final Throwable t) {
Log.e("Wootric-SDK", t.toString());
}
}

private void updateState(int state) {
Expand Down Expand Up @@ -500,13 +453,13 @@ private void setupFeedbackState() {
JSONObject dplSettings = mSettings.getDriverPicklistSettings(currentScore);
JSONObject dpl = mSettings.getDriverPicklist(currentScore);

if (dplSettings.getBoolean("dpl_multi_select")) {
if (dplSettings.has("dpl_multi_select") && dplSettings.getBoolean("dpl_multi_select")) {
mDriverPicklist.setMode(DriverPicklist.Mode.MULTI);
} else {
mDriverPicklist.setMode(DriverPicklist.Mode.SINGLE);
}

if (dplSettings.getBoolean("dpl_hide_open_ended")) {
if (dplSettings.has("dpl_hide_open_ended") && dplSettings.getBoolean("dpl_hide_open_ended")) {
mEtFeedback.setVisibility(View.GONE);
} else {
mEtFeedback.setVisibility(View.VISIBLE);
Expand All @@ -521,17 +474,15 @@ private void setupFeedbackState() {
}
}

if (dplSettings != null) {
if (dplSettings.getBoolean("dpl_randomize_list")) {
ArrayList<String> shuffled = new ArrayList<>(dplList);
Collections.shuffle(shuffled);
for (String value : shuffled) {
mDriverPicklist.addButton(value);
}
} else {
for (String value : dplList) {
mDriverPicklist.addButton(value);
}
if (dplSettings.has("dpl_randomize_list") && dplSettings.getBoolean("dpl_randomize_list")) {
ArrayList<String> shuffled = new ArrayList<>(dplList);
Collections.shuffle(shuffled);
for (String value : shuffled) {
mDriverPicklist.addButton(value);
}
} else {
for (String value : dplList) {
mDriverPicklist.addButton(value);
}
}
} catch (JSONException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@
*/
public class ThankYouDialogFactory {
public static Dialog create(final Context context, final Settings settings, final int score, final String text, final WootricSurveyCallback surveyCallback, final OnSurveyFinishedListener onSurveyFinishedListener, final HashMap<String, String> driverPicklist) {
final AlertDialog thankYouDialog = new AlertDialog.Builder(context).create();
final AlertDialog thankYouDialog;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
thankYouDialog = new AlertDialog.Builder(context, android.R.style.Theme_Material_Light_Dialog_Alert).create();
} else {
thankYouDialog = new AlertDialog.Builder(context, AlertDialog.THEME_HOLO_LIGHT).create();
}
thankYouDialog.setCancelable(false);
final String thankYouText = settings.getFinalThankYou(score);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" >
<solid android:color="@color/edit_background_color" />
</shape>
</item>

<item
android:top="@dimen/wootric_edittext_item_top"
android:right="@dimen/wootric_edittext_item_right"
android:left="@dimen/wootric_edittext_item_left">
<shape>
<solid android:color="@android:color/transparent" />
<stroke
android:width="@dimen/wootric_edittext_stroke_width"
android:color="@color/wootric_score_color" />
</shape>
</item>
</layer-list>
1 change: 1 addition & 0 deletions androidsdk/src/main/res/layout/wootric_survey_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
android:hint="@string/wootric_example_followup_placeholder"
android:imeOptions="actionDone"
android:inputType="text"
android:background="@drawable/wootric_feedback_edit_text_background"
android:maxLines="1"
android:nextFocusLeft="@id/wootric_et_feedback"
android:nextFocusUp="@id/wootric_et_feedback"
Expand Down
1 change: 1 addition & 0 deletions androidsdk/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<color name="wootric_edit_text_background">#05000000</color>
<color name="wootric_edit_text_border">#253746</color>
<color name="edit_score_color">#FFFFFF</color>
<color name="edit_background_color">#00FFFFFF</color>

<color name="wootric_dpl_button">#333</color>
<color name="dark_grey">#333333</color>
Expand Down
5 changes: 5 additions & 0 deletions androidsdk/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,9 @@
<dimen name="min_horizontal_spacing">8dp</dimen>
<dimen name="vertical_spacing">8dp</dimen>

<!-- EditText Border -->
<dimen name="wootric_edittext_item_left">-3dp</dimen>
<dimen name="wootric_edittext_item_right">-3dp</dimen>
<dimen name="wootric_edittext_item_top">-3dp</dimen>
<dimen name="wootric_edittext_stroke_width">2dp</dimen>
</resources>

0 comments on commit 1bf2980

Please sign in to comment.