Skip to content

Commit

Permalink
Merge pull request #444 from auth0/attempt-to-fix-non-touchscreen-nav…
Browse files Browse the repository at this point in the history
…igation

Fix non-touchscreen navigation
  • Loading branch information
lbalmaceda authored Oct 12, 2017
2 parents a822bfe + 6261ba9 commit d756e46
Show file tree
Hide file tree
Showing 31 changed files with 397 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ private void showPasswordlessLock() {
private Auth0 getAccount() {
Auth0 account = new Auth0(getString(R.string.com_auth0_client_id), getString(R.string.com_auth0_domain));
account.setOIDCConformant(true);
account.setLoggingEnabled(true);
return account;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ public void run() {
};

private void showLinkSentLayout() {
//Next 2 lines required to avoid focus on the form behind
rootView.setFocusable(false);
rootView.setFocusableInTouchMode(false);
TextView successMessage = (TextView) passwordlessSuccessCover.findViewById(R.id.com_auth0_lock_passwordless_message);
successMessage.setText(String.format(getString(R.string.com_auth0_lock_title_passwordless_link_sent), lastPasswordlessIdentity));
TextView gotCodeButton = (TextView) passwordlessSuccessCover.findViewById(R.id.com_auth0_lock_got_code);
Expand Down
29 changes: 22 additions & 7 deletions lib/src/main/java/com/auth0/android/lock/views/ActionButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
import android.graphics.drawable.Drawable;
import android.graphics.drawable.RippleDrawable;
import android.graphics.drawable.StateListDrawable;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.ColorUtils;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
Expand Down Expand Up @@ -68,22 +70,35 @@ private void init(Theme lockTheme) {
ViewUtils.setBackground(icon, generateStateBackground(lockTheme));
ViewUtils.setBackground(labeledLayout, generateStateBackground(lockTheme));
showLabel(false);
icon.setFocusable(true);
icon.setFocusableInTouchMode(false);
labeledLayout.setFocusable(true);
labeledLayout.setFocusableInTouchMode(false);
}

private Drawable generateStateBackground(Theme lockTheme) {
int normalColor = lockTheme.getPrimaryColor(getContext());
int pressedColor = lockTheme.getDarkPrimaryColor(getContext());
//164 -> 64% alpha
int focusedColor = ColorUtils.setAlphaComponent(normalColor, 164);
int disabledColor = ContextCompat.getColor(getContext(), R.color.com_auth0_lock_submit_disabled);

final StateListDrawable buttonDrawable = new StateListDrawable();
buttonDrawable.addState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed}, new ColorDrawable(pressedColor));
buttonDrawable.addState(new int[]{android.R.attr.state_enabled, android.R.attr.state_focused}, new ColorDrawable(focusedColor));
buttonDrawable.addState(new int[]{android.R.attr.state_enabled}, new ColorDrawable(normalColor));
buttonDrawable.addState(new int[]{}, new ColorDrawable(disabledColor));

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
return new RippleDrawable(ColorStateList.valueOf(pressedColor), new ColorDrawable(normalColor), null);
} else {
StateListDrawable states = new StateListDrawable();
states.addState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed}, new ColorDrawable(pressedColor));
states.addState(new int[]{android.R.attr.state_enabled}, new ColorDrawable(normalColor));
states.addState(new int[]{}, new ColorDrawable(disabledColor));
return states;
return new RippleDrawable(ColorStateList.valueOf(pressedColor), buttonDrawable, null);
}
return buttonDrawable;
}

@Override
public void setOnClickListener(@Nullable OnClickListener l) {
icon.setOnClickListener(l);
labeledLayout.setOnClickListener(l);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ private void init(String email) {
emailInput.setText(email);
emailInput.setIdentityListener(this);
emailInput.setOnEditorActionListener(this);
requestFocus();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ public boolean onBackPressed() {
resetHeaderTitle();
showSignUpTerms(subForm instanceof CustomFieldsFormView);
removeSubForm();
clearFocus();
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
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.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
Expand Down Expand Up @@ -84,13 +84,17 @@ private void setupBackground() {
Drawable rightBackground = ViewUtils.getRoundedBackground(getResources(), ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_country_code_background), ViewUtils.Corners.ONLY_RIGHT);
ViewUtils.setBackground(icon, leftBackground);
ViewUtils.setBackground(chevron, rightBackground);
ViewGroup parent = ((ViewGroup) countryNameTextView.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));
gd.setStroke(getResources().getDimensionPixelSize(R.dimen.com_auth0_lock_input_field_stroke_width), ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_field_border_normal));
gd.setColor(ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_field_border_normal));
ViewUtils.setBackground(parent, gd);

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);
}

private void prepareTask() {
Expand Down
114 changes: 114 additions & 0 deletions lib/src/main/java/com/auth0/android/lock/views/ImageCheckbox.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.auth0.android.lock.views;

import android.content.Context;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.AccessibilityDelegateCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.accessibility.AccessibilityEventCompat;
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
import android.support.v7.widget.AppCompatImageButton;
import android.util.AttributeSet;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import android.widget.Checkable;
import android.widget.ImageButton;

import com.auth0.android.lock.R;

/**
* A custom CheckBox implementation that doesn't have a TextView next to the ImageView, and changes the background drawable when focused.
*/
public class ImageCheckbox extends AppCompatImageButton implements Checkable {

private static final int[] DRAWABLE_STATE_CHECKED = new int[]{android.R.attr.state_checked};
private final Drawable focusedBackground;

private boolean mChecked;
private OnCheckedChangeListener checkedChangedListener;

public ImageCheckbox(Context context) {
this(context, null);
}

public ImageCheckbox(Context context, AttributeSet attrs) {
this(context, attrs, android.support.v7.appcompat.R.attr.imageButtonStyle);
}

public ImageCheckbox(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);

ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegateCompat() {
@Override
public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
super.onInitializeAccessibilityEvent(host, event);
event.setChecked(isChecked());
}

@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
super.onInitializeAccessibilityNodeInfo(host, info);
info.setCheckable(true);
info.setChecked(isChecked());
}
});
setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
toggle();
}
});
ViewUtils.setBackground(this, null);
focusedBackground = ContextCompat.getDrawable(getContext(), R.drawable.com_auth0_lock_link_background);
}


@Override
public void setChecked(boolean checked) {
if (mChecked != checked) {
mChecked = checked;
refreshDrawableState();
sendAccessibilityEvent(AccessibilityEventCompat.TYPE_WINDOW_CONTENT_CHANGED);
if (checkedChangedListener != null) {
checkedChangedListener.onCheckedChanged(this, checked);
}
}
}

@Override
public boolean isChecked() {
return mChecked;
}

@Override
public void toggle() {
setChecked(!mChecked);
}

@Override
public int[] onCreateDrawableState(int extraSpace) {
if (mChecked) {
return mergeDrawableStates(super.onCreateDrawableState(extraSpace + DRAWABLE_STATE_CHECKED.length), DRAWABLE_STATE_CHECKED);
} else {
return super.onCreateDrawableState(extraSpace);
}
}

@Override
protected void onFocusChanged(boolean gainFocus, int direction, @Nullable Rect previouslyFocusedRect) {
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
ViewUtils.setBackground(this, gainFocus ? focusedBackground : null);
}

void setOnCheckedChangeListener(OnCheckedChangeListener listener) {
checkedChangedListener = listener;
}

interface OnCheckedChangeListener {
void onCheckedChanged(ImageButton view, boolean isChecked);
}

}

44 changes: 44 additions & 0 deletions lib/src/main/java/com/auth0/android/lock/views/LinkTextView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.auth0.android.lock.views;

import android.content.Context;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;

import com.auth0.android.lock.R;

/**
* A custom AppCompatTextView implementation that changes the background drawable when focused.
*/
public class LinkTextView extends android.support.v7.widget.AppCompatTextView {
private Drawable focusedBackground;

public LinkTextView(Context context) {
super(context);
init();
}

public LinkTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}

public LinkTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}

private void init() {
focusedBackground = ContextCompat.getDrawable(getContext(), R.drawable.com_auth0_lock_link_background);
setFocusableInTouchMode(false);
setFocusable(true);
}

@Override
protected void onFocusChanged(boolean gainFocus, int direction, @Nullable Rect previouslyFocusedRect) {
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
ViewUtils.setBackground(this, gainFocus ? focusedBackground : null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,21 @@ private void init() {
}

public void setSelectedMode(@AuthMode int mode) {
tabLayout.getTabAt(mode).select();
TabLayout.Tab tab = tabLayout.getTabAt(mode);
tab.select();
toggleBoldText(tab, true);
}

@Override
public void onTabSelected(TabLayout.Tab tab) {
final TextView text = (TextView) tab.getCustomView().findViewById(android.R.id.text1);
setBoldFont(text, true);
toggleBoldText(tab, true);
//noinspection WrongConstant
callback.onModeSelected(getCurrentMode(tab));
}

@Override
public void onTabUnselected(TabLayout.Tab tab) {
final TextView text = (TextView) tab.getCustomView().findViewById(android.R.id.text1);
setBoldFont(text, false);
toggleBoldText(tab, false);
}

@Override
Expand All @@ -81,8 +81,9 @@ public void onTabReselected(TabLayout.Tab tab) {
callback.onModeSelected(getCurrentMode(tab));
}

private void setBoldFont(TextView view, boolean bold) {
view.setTypeface(bold ? view.getTypeface() : null, bold ? Typeface.BOLD : Typeface.NORMAL);
private void toggleBoldText(TabLayout.Tab tab, boolean bold) {
final TextView text = (TextView) tab.getCustomView().findViewById(android.R.id.text1);
text.setTypeface(bold ? text.getTypeface() : null, bold ? Typeface.BOLD : Typeface.NORMAL);
}

public interface ModeSelectedListener {
Expand Down
Loading

0 comments on commit d756e46

Please sign in to comment.