-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom styles for focused components
- Loading branch information
1 parent
f6e34d9
commit f5745d7
Showing
13 changed files
with
187 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
lib/src/main/java/com/auth0/android/lock/views/ImageCheckbox.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} | ||
|
42 changes: 42 additions & 0 deletions
42
lib/src/main/java/com/auth0/android/lock/views/LinkTextView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
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); | ||
} | ||
|
||
@Override | ||
protected void onFocusChanged(boolean gainFocus, int direction, @Nullable Rect previouslyFocusedRect) { | ||
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); | ||
ViewUtils.setBackground(this, gainFocus ? focusedBackground : null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<solid android:color="@color/com_auth0_lock_link_focused" /> | ||
<corners android:radius="@dimen/com_auth0_lock_widget_corner_radius" /> | ||
</shape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.