dbachelder / CreditCardEntry

Smooth UI for Credit Card Entry on Android device, regex check for supported credit card types and luhn check. Inspired by Square credit card entry interface
MIT License
503 stars 166 forks source link

Widget is hard to style for dark themes #25

Closed kojustin closed 9 years ago

kojustin commented 9 years ago

The credit card entry form doesn't really fit in when it is placed in an application with a dark theme. The defaults for app:cursor_color, app:text_color, app:input_background, etc. are dark colors and are not very visible on dark themes. It's possible to manually set these colors, but it would be nicer if the widget just used the default colors that are provided by the theme.

I tried going through and just removing the places where the underlying EditTexts have colors assigned, and it worked pretty well for me.

diff --git a/CreditCardEntry/src/com/devmarvel/creditcardentry/fields/CreditEntryFieldBase.java b/CreditCardEntry/src/com/devmarvel/creditcardentry/fields/CreditEntryFieldBase.java
index 064b1b9..de368a8 100644
--- a/CreditCardEntry/src/com/devmarvel/creditcardentry/fields/CreditEntryFieldBase.java
+++ b/CreditCardEntry/src/com/devmarvel/creditcardentry/fields/CreditEntryFieldBase.java
@@ -82,9 +82,9 @@ public abstract class CreditEntryFieldBase extends EditText implements
        }

        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CreditCardForm);
-       setTextColor(typedArray.getColor(R.styleable.CreditCardForm_text_color, Color.BLACK));
-       setHintTextColor(typedArray.getColor(R.styleable.CreditCardForm_hint_text_color, Color.LTGRAY));
-       setCursorDrawableColor(typedArray.getColor(R.styleable.CreditCardForm_cursor_color, Color.BLACK));
+//     setTextColor(typedArray.getColor(R.styleable.CreditCardForm_text_color, Color.BLACK));
+//     setHintTextColor(typedArray.getColor(R.styleable.CreditCardForm_hint_text_color, Color.LTGRAY));
+//     setCursorDrawableColor(typedArray.getColor(R.styleable.CreditCardForm_cursor_color, Color.BLACK));
        typedArray.recycle();
    }

diff --git a/CreditCardEntry/src/com/devmarvel/creditcardentry/internal/CreditCardEntry.java b/CreditCardEntry/src/com/devmarvel/creditcardentry/internal/CreditCardEntry.java
index 6987b28..e586971 100644
--- a/CreditCardEntry/src/com/devmarvel/creditcardentry/internal/CreditCardEntry.java
+++ b/CreditCardEntry/src/com/devmarvel/creditcardentry/internal/CreditCardEntry.java
@@ -86,7 +86,7 @@ public class CreditCardEntry extends HorizontalScrollView implements
         this.context = context;

         TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CreditCardForm, 0, 0);
-        textColor = typedArray.getColor(R.styleable.CreditCardForm_text_color, Color.BLACK);
+//        textColor = typedArray.getColor(R.styleable.CreditCardForm_text_color, Color.BLACK);
         typedArray.recycle();

         WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
@@ -123,7 +123,8 @@ public class CreditCardEntry extends HorizontalScrollView implements

         textFourDigits = new TextView(context);
         textFourDigits.setTextSize(20);
-        textFourDigits.setTextColor(textColor);
+        textColor = textFourDigits.getCurrentTextColor();
+//        textFourDigits.setTextColor(textColor);
         container.addView(textFourDigits);

         expDateText = new ExpDateText(context, attrs);
kojustin commented 9 years ago

So, it might be too late to change the defaults for app:text_color, app:hint_text_color, app:cursor_color, but maybe we could have a app:use_default_text_colors that tells the widget to use the default text colors instead of supplying its own.

kojustin commented 9 years ago

Now that #26 is merged I think this can be closed.