-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Version 7.1.1
- Loading branch information
Showing
17 changed files
with
135 additions
and
18 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
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
96 changes: 96 additions & 0 deletions
96
auth/src/main/java/com/firebase/ui/auth/util/ui/SupportVectorDrawablesButton.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,96 @@ | ||
package com.firebase.ui.auth.util.ui; | ||
|
||
import android.content.Context; | ||
import android.content.res.TypedArray; | ||
import android.graphics.drawable.Drawable; | ||
import android.os.Build; | ||
import android.util.AttributeSet; | ||
|
||
import com.firebase.ui.auth.R; | ||
|
||
import androidx.annotation.RestrictTo; | ||
import androidx.appcompat.content.res.AppCompatResources; | ||
import androidx.appcompat.widget.AppCompatButton; | ||
import androidx.core.widget.TextViewCompat; | ||
|
||
/** | ||
* A custom button that supports using vector drawables with the {@code | ||
* android:drawable[Start/End/Top/Bottom]} attribute pre-L. | ||
* <p> | ||
* AppCompat can only load vector drawables with srcCompat pre-L and doesn't provide a similar | ||
* compatibility attribute for compound drawables. Thus, we must load compound drawables at runtime | ||
* using AppCompat and inject them into the button to support pre-L devices. | ||
*/ | ||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) | ||
public class SupportVectorDrawablesButton extends AppCompatButton { | ||
public SupportVectorDrawablesButton(Context context) { | ||
super(context); | ||
} | ||
|
||
public SupportVectorDrawablesButton(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
initSupportVectorDrawablesAttrs(attrs); | ||
} | ||
|
||
public SupportVectorDrawablesButton(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
initSupportVectorDrawablesAttrs(attrs); | ||
} | ||
|
||
/** | ||
* Loads the compound drawables natively on L+ devices and using AppCompat pre-L. | ||
* <p> | ||
* <i>Note:</i> If we ever need a TextView with compound drawables, this same technique is | ||
* applicable. | ||
*/ | ||
private void initSupportVectorDrawablesAttrs(AttributeSet attrs) { | ||
if (attrs == null) { return; } | ||
|
||
TypedArray attributeArray = getContext().obtainStyledAttributes( | ||
attrs, | ||
R.styleable.SupportVectorDrawablesButton); | ||
|
||
Drawable drawableStart = null; | ||
Drawable drawableEnd = null; | ||
Drawable drawableTop = null; | ||
Drawable drawableBottom = null; | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
drawableStart = attributeArray.getDrawable( | ||
R.styleable.SupportVectorDrawablesButton_drawableStartCompat); | ||
drawableEnd = attributeArray.getDrawable( | ||
R.styleable.SupportVectorDrawablesButton_drawableEndCompat); | ||
drawableTop = attributeArray.getDrawable( | ||
R.styleable.SupportVectorDrawablesButton_drawableTopCompat); | ||
drawableBottom = attributeArray.getDrawable( | ||
R.styleable.SupportVectorDrawablesButton_drawableBottomCompat); | ||
} else { | ||
int drawableStartId = attributeArray.getResourceId( | ||
R.styleable.SupportVectorDrawablesButton_drawableStartCompat, -1); | ||
int drawableEndId = attributeArray.getResourceId( | ||
R.styleable.SupportVectorDrawablesButton_drawableEndCompat, -1); | ||
int drawableTopId = attributeArray.getResourceId( | ||
R.styleable.SupportVectorDrawablesButton_drawableTopCompat, -1); | ||
int drawableBottomId = attributeArray.getResourceId( | ||
R.styleable.SupportVectorDrawablesButton_drawableBottomCompat, -1); | ||
|
||
if (drawableStartId != -1) { | ||
drawableStart = AppCompatResources.getDrawable(getContext(), drawableStartId); | ||
} | ||
if (drawableEndId != -1) { | ||
drawableEnd = AppCompatResources.getDrawable(getContext(), drawableEndId); | ||
} | ||
if (drawableTopId != -1) { | ||
drawableTop = AppCompatResources.getDrawable(getContext(), drawableTopId); | ||
} | ||
if (drawableBottomId != -1) { | ||
drawableBottom = AppCompatResources.getDrawable(getContext(), drawableBottomId); | ||
} | ||
} | ||
|
||
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds( | ||
this, drawableStart, drawableTop, drawableEnd, drawableBottom); | ||
|
||
attributeArray.recycle(); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<Button xmlns:android="http://schemas.android.com/apk/res/android" | ||
<com.firebase.ui.auth.util.ui.SupportVectorDrawablesButton xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/apple_signin_button" | ||
style="@style/FirebaseUI.Button.AccountChooser.AppleButton" | ||
android:text="@string/fui_sign_in_with_apple"/> |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<Button xmlns:android="http://schemas.android.com/apk/res/android" | ||
<com.firebase.ui.auth.util.ui.SupportVectorDrawablesButton | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
style="@style/FirebaseUI.Button.AccountChooser.FacebookButton" | ||
android:text="@string/fui_sign_in_with_facebook" /> |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<Button xmlns:android="http://schemas.android.com/apk/res/android" | ||
<com.firebase.ui.auth.util.ui.SupportVectorDrawablesButton | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
style="@style/FirebaseUI.Button.AccountChooser.GitHubButton" | ||
android:text="@string/fui_sign_in_with_github" /> |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<Button xmlns:android="http://schemas.android.com/apk/res/android" | ||
<com.firebase.ui.auth.util.ui.SupportVectorDrawablesButton | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
style="@style/FirebaseUI.Button.AccountChooser.GoogleButton" | ||
android:text="@string/fui_sign_in_with_google" /> |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<Button xmlns:android="http://schemas.android.com/apk/res/android" | ||
<com.firebase.ui.auth.util.ui.SupportVectorDrawablesButton xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/microsoft_signin_button" | ||
style="@style/FirebaseUI.Button.AccountChooser.MicrosoftButton" | ||
android:text="@string/fui_sign_in_with_microsoft"/> |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<Button xmlns:android="http://schemas.android.com/apk/res/android" | ||
<com.firebase.ui.auth.util.ui.SupportVectorDrawablesButton | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
style="@style/FirebaseUI.Button.AccountChooser.TwitterButton" | ||
android:text="@string/fui_sign_in_with_twitter" /> |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<Button xmlns:android="http://schemas.android.com/apk/res/android" | ||
<com.firebase.ui.auth.util.ui.SupportVectorDrawablesButton xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/yahoo_signin_button" | ||
style="@style/FirebaseUI.Button.AccountChooser.YahooButton" | ||
android:text="@string/fui_sign_in_with_yahoo" /> |
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