Skip to content

Commit

Permalink
Merge pull request #445 from auth0/rtl-support
Browse files Browse the repository at this point in the history
Add RTL support
  • Loading branch information
lbalmaceda authored Oct 17, 2017
2 parents d756e46 + cc80db8 commit 699e0da
Show file tree
Hide file tree
Showing 40 changed files with 408 additions and 178 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.StateListDrawable;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
Expand All @@ -53,6 +53,9 @@ public class CountryCodeSelectorView extends LinearLayout {
private TextView countryNameTextView;
private TextView countryCodeTextView;
private ImageView chevron;
private View outline;
private ShapeDrawable focusedBackground;
private ShapeDrawable normalBackground;

public CountryCodeSelectorView(Context context) {
super(context);
Expand All @@ -75,26 +78,26 @@ private void init() {
chevron = (ImageView) findViewById(R.id.com_auth0_lock_chevron);
countryNameTextView = (TextView) findViewById(R.id.com_auth0_lock_country_name);
countryCodeTextView = (TextView) findViewById(R.id.com_auth0_lock_country_code);
outline = findViewById(R.id.com_auth0_lock_outline);
prepareTask();
setupBackground();
setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
ViewUtils.setBackground(outline, hasFocus ? focusedBackground : normalBackground);
}
});
}

private void setupBackground() {
Drawable leftBackground = ViewUtils.getRoundedBackground(getResources(), ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_field_border_normal), ViewUtils.Corners.ONLY_LEFT);
Drawable rightBackground = ViewUtils.getRoundedBackground(getResources(), ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_country_code_background), ViewUtils.Corners.ONLY_RIGHT);
Drawable leftBackground = ViewUtils.getRoundedBackground(this, ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_field_border_normal), ViewUtils.Corners.ONLY_LEFT);
Drawable rightBackground = ViewUtils.getRoundedBackground(this, ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_country_code_background), ViewUtils.Corners.ONLY_RIGHT);
ViewUtils.setBackground(icon, leftBackground);
ViewUtils.setBackground(chevron, rightBackground);

ShapeDrawable normalBackground = ViewUtils.getRoundedBackground(getResources(), ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_field_border_normal), ViewUtils.Corners.ALL);
Drawable focusedBackground = ViewUtils.getRoundedOutlineBackground(getResources(), ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_field_border_focused));

StateListDrawable states = new StateListDrawable();
states.addState(new int[]{android.R.attr.state_focused}, focusedBackground);
states.addState(new int[]{}, normalBackground);

setFocusableInTouchMode(false);
setFocusable(true);
ViewUtils.setBackground(this, states);
focusedBackground = ViewUtils.getRoundedOutlineBackground(getResources(), ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_field_border_focused));
normalBackground = ViewUtils.getRoundedOutlineBackground(getResources(), ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_field_border_normal));
ViewUtils.setBackground(outline, normalBackground);
}

private void prepareTask() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package com.auth0.android.lock.views;

import android.content.Context;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
Expand Down Expand Up @@ -86,6 +87,10 @@ private LinearLayout.LayoutParams defineFieldParams() {
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.CENTER_HORIZONTAL;
params.setMargins(horizontalMargin, verticalMargin / 2, horizontalMargin, verticalMargin / 2);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
params.setMarginStart(horizontalMargin);
params.setMarginEnd(horizontalMargin);
}
return params;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package com.auth0.android.lock.views;

import android.content.Context;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
Expand Down Expand Up @@ -100,6 +101,9 @@ private void init() {
formsHolder.setOrientation(LinearLayout.VERTICAL);
formsHolder.setGravity(Gravity.CENTER);
formsHolder.setPadding(horizontalMargin, verticalMargin, horizontalMargin, verticalMargin);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
formsHolder.setPaddingRelative(horizontalMargin, verticalMargin, horizontalMargin, verticalMargin);
}
LayoutParams holderParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
holderParams.addRule(BELOW, R.id.com_auth0_lock_form_selector);
holderParams.addRule(CENTER_VERTICAL);
Expand Down Expand Up @@ -155,6 +159,9 @@ private void addSeparator() {
orSeparatorMessage.setGravity(Gravity.CENTER);
int verticalPadding = getResources().getDimensionPixelSize(R.dimen.com_auth0_lock_widget_vertical_margin_field);
orSeparatorMessage.setPadding(0, verticalPadding, 0, verticalPadding);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
orSeparatorMessage.setPaddingRelative(0, verticalPadding, 0, verticalPadding);
}
formsHolder.addView(orSeparatorMessage, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,4 @@ public void setLogo(@DrawableRes int logo) {
this.logo.setImageResource(logo);
}

public void setPaddingTop(int padding) {
header.setPadding(0, padding, 0, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package com.auth0.android.lock.views;

import android.content.Context;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.util.Log;
Expand Down Expand Up @@ -80,6 +81,9 @@ private void init() {
}
final int verticalPadding = getResources().getDimensionPixelSize(R.dimen.com_auth0_lock_widget_vertical_margin_field);
setPadding(0, verticalPadding, 0, verticalPadding);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
setPaddingRelative(0, verticalPadding, 0, verticalPadding);
}
}

private void addSocialLayout(boolean passwordlessAvailable) {
Expand Down Expand Up @@ -110,6 +114,10 @@ private void addSeparator() {
int verticalPadding = getResources().getDimensionPixelSize(R.dimen.com_auth0_lock_widget_vertical_margin_field);
LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.setMargins(0, verticalPadding, 0, verticalPadding);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
params.setMarginStart(0);
params.setMarginEnd(0);
}
addView(orSeparatorMessage, params);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.util.Log;
Expand Down Expand Up @@ -96,6 +97,9 @@ private void showContentLayout() {
formLayout = new PasswordlessFormLayout(this);
LayoutParams formLayoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1);
formLayout.setPadding(horizontalMargin, verticalMargin, horizontalMargin, verticalMargin);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
formLayout.setPaddingRelative(horizontalMargin, verticalMargin, horizontalMargin, verticalMargin);
}
addView(formLayout, formLayoutParams);

boolean showPasswordless = configuration.getPasswordlessConnection() != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package com.auth0.android.lock.views;

import android.content.Context;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
Expand Down Expand Up @@ -125,6 +126,10 @@ private LinearLayout.LayoutParams defineFieldParams() {
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.CENTER_HORIZONTAL;
params.setMargins(0, verticalMargin, 0, 0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
params.setMarginStart(0);
params.setMarginEnd(0);
}
return params;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.support.annotation.ColorInt;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
Expand Down Expand Up @@ -51,9 +52,9 @@ public void onFocusChange(View v, boolean hasFocus) {
}

private StateListDrawable getTouchFeedbackBackground(@ColorInt int pressedColor, @ViewUtils.Corners int corners) {
ShapeDrawable normalBackground = ViewUtils.getRoundedBackground(getResources(), pressedColor, corners);
ShapeDrawable normalBackground = ViewUtils.getRoundedBackground(this, pressedColor, corners);
normalBackground.getPaint().setAlpha(NORMAL_STATE_ALPHA);
Drawable pressedBackground = ViewUtils.getRoundedBackground(getResources(), pressedColor, corners);
Drawable pressedBackground = ViewUtils.getRoundedBackground(this, pressedColor, corners);

StateListDrawable states = new StateListDrawable();
states.addState(new int[]{android.R.attr.state_pressed}, pressedBackground);
Expand All @@ -77,7 +78,7 @@ public void setStyle(AuthConfig config, @AuthMode int mode) {
ViewUtils.setBackground(icon, touchBackground);
} else {
final String name = config.getName(getContext());
ShapeDrawable leftBackground = ViewUtils.getRoundedBackground(getResources(), backgroundColor, ViewUtils.Corners.ONLY_LEFT);
ShapeDrawable leftBackground = ViewUtils.getRoundedBackground(this, backgroundColor, ViewUtils.Corners.ONLY_LEFT);
final String prefixFormat = getResources().getString(mode == AuthMode.LOG_IN ? R.string.com_auth0_lock_social_log_in : R.string.com_auth0_lock_social_sign_up);
title.setText(String.format(prefixFormat, name));
ViewUtils.setBackground(icon, leftBackground);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public SpacesItemDecoration(int space, @LinearLayoutCompat.OrientationMode int o

@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
if (parent.getChildAdapterPosition(view) == 0) {
return;
}

if (orientation == RecyclerView.HORIZONTAL) {
outRect.left = space;
outRect.left = space / 2;
outRect.right = space / 2;
} else {
outRect.top = space;
boolean firstItem = parent.getChildAdapterPosition(view) == 0;
boolean lastItem = parent.getChildAdapterPosition(view) == parent.getChildCount() - 1;
outRect.top = firstItem ? 0 : space / 2;
outRect.bottom = lastItem ? 0 : space / 2;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.os.Handler;
import android.support.annotation.CallSuper;
import android.support.annotation.DrawableRes;
Expand Down Expand Up @@ -78,7 +78,6 @@ public class ValidatedInputView extends LinearLayout {
private static final String TAG = ValidatedInputView.class.getSimpleName();
private static final int VALIDATION_DELAY = 500;

protected LinearLayout rootView;
private TextView errorDescription;
private EditText input;
private ImageView icon;
Expand All @@ -87,6 +86,10 @@ public class ValidatedInputView extends LinearLayout {
private int inputIcon;
private boolean hasValidInput;
private boolean allowShowPassword = true;
private View outline;
private ShapeDrawable focusedOutlineBackground;
private ShapeDrawable normalOutlineBackground;
private ShapeDrawable errorOutlineBackground;

@IntDef({USERNAME, EMAIL, USERNAME_OR_EMAIL, MFA_CODE, PHONE_NUMBER, PASSWORD, MOBILE_PHONE, TEXT_NAME, NUMBER, NON_EMPTY_USERNAME})
@Retention(RetentionPolicy.SOURCE)
Expand Down Expand Up @@ -123,11 +126,13 @@ public ValidatedInputView(Context context, AttributeSet attrs, int defStyleAttr)

private void init(AttributeSet attrs) {
inflate(getContext(), R.layout.com_auth0_lock_validated_input_view, this);
rootView = (LinearLayout) findViewById(R.id.com_auth0_lock_container);

outline = findViewById(R.id.com_auth0_lock_outline);
errorDescription = (TextView) findViewById(R.id.errorDescription);
icon = (ImageView) findViewById(R.id.com_auth0_lock_icon);
input = (EditText) findViewById(R.id.com_auth0_lock_input);
showPasswordToggle = (ImageCheckbox) findViewById(R.id.com_auth0_lock_show_password_toggle);
setOrientation(VERTICAL);

if (attrs == null || isInEditMode()) {
return;
Expand All @@ -140,6 +145,9 @@ private void init(AttributeSet attrs) {
createBackground();

setupInputValidation();
focusedOutlineBackground = ViewUtils.getRoundedOutlineBackground(getResources(), ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_field_border_focused));
normalOutlineBackground = ViewUtils.getRoundedOutlineBackground(getResources(), ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_field_border_normal));
errorOutlineBackground = ViewUtils.getRoundedOutlineBackground(getResources(), ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_field_border_error));
updateBorder(true);

setNextFocusRightId(R.id.com_auth0_lock_show_password_toggle);
Expand All @@ -165,9 +173,7 @@ public void onCheckedChanged(ImageButton view, boolean isChecked) {
input.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!isInTouchMode()) {
updateBorder(true);
}
updateBorder(true);
}
});
}
Expand Down Expand Up @@ -306,43 +312,20 @@ private void setupInputValidation() {
*/
@CallSuper
protected void updateBorder(boolean isValid) {
ViewGroup parent = ((ViewGroup) input.getParent().getParent());
Drawable bg = parent.getBackground();
GradientDrawable gd = bg == null ? new GradientDrawable() : (GradientDrawable) bg;
gd.setCornerRadius(getResources().getDimensionPixelSize(R.dimen.com_auth0_lock_widget_corner_radius));

boolean isFocused = input.hasFocus() && !isInTouchMode();
int strokeColor = isValid ? (isFocused ? R.color.com_auth0_lock_input_field_border_focused : R.color.com_auth0_lock_input_field_border_normal) : R.color.com_auth0_lock_input_field_border_error;
gd.setStroke(getResources().getDimensionPixelSize(R.dimen.com_auth0_lock_input_field_stroke_width), ContextCompat.getColor(getContext(), strokeColor));
gd.setColor(ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_field_border_normal));
ViewUtils.setBackground(parent, gd);

errorDescription.setVisibility(isValid ? INVISIBLE : VISIBLE);
boolean isFocused = input.hasFocus() && !input.isInTouchMode();
ViewUtils.setBackground(outline, isValid ? (isFocused ? focusedOutlineBackground : normalOutlineBackground) : errorOutlineBackground);
errorDescription.setVisibility(isValid ? GONE : VISIBLE);
requestLayout();
}

private void createBackground() {
int inputBackgroundColor = ContextCompat.getColor(getContext(), isEnabled() ? R.color.com_auth0_lock_input_field_background : R.color.com_auth0_lock_input_field_background_disabled);
Drawable leftBackground = ViewUtils.getRoundedBackground(getResources(), ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_field_border_normal), ViewUtils.Corners.ONLY_LEFT);
Drawable rightBackground = ViewUtils.getRoundedBackground(getResources(), inputBackgroundColor, ViewUtils.Corners.ONLY_RIGHT);
Drawable leftBackground = ViewUtils.getRoundedBackground(this, ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_field_border_normal), ViewUtils.Corners.ONLY_LEFT);
Drawable rightBackground = ViewUtils.getRoundedBackground(this, inputBackgroundColor, ViewUtils.Corners.ONLY_RIGHT);
ViewUtils.setBackground(icon, leftBackground);
ViewUtils.setBackground((ViewGroup) input.getParent(), rightBackground);
}

@Override
@CallSuper
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);

errorDescription.measure(widthMeasureSpec, heightMeasureSpec);
int errorDescriptionHeight = ViewUtils.measureViewHeight(errorDescription);
int inputHeight = ViewUtils.measureViewHeight(input);
ViewGroup iconHolder = (ViewGroup) icon.getParent();
int iconHeight = ViewUtils.measureViewHeight(iconHolder);
int sumHeight = Math.max(inputHeight, iconHeight) + errorDescriptionHeight;
setMeasuredDimension(getMeasuredWidth(), sumHeight);
}

/**
* Changes the type of input this view will validate.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,7 @@ public ValidatedPasswordInputView(Context context, AttributeSet attrs) {

public void init() {
strengthView = new PasswordStrengthView(getContext());
rootView.addView(strengthView, 0); //Add it above the field
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int strengthHeight = ViewUtils.measureViewHeight(strengthView);
setMeasuredDimension(getMeasuredWidth(), getMeasuredHeight() + strengthHeight);
addView(strengthView, 0); //Add it above the field
}

@Override
Expand Down
Loading

0 comments on commit 699e0da

Please sign in to comment.