Skip to content

Commit e91edda

Browse files
SUPERCILEXsamtstern
authored andcommitted
Add true support for vector drawables (#814)
1 parent 5e14e08 commit e91edda

39 files changed

+217
-23
lines changed

app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ android {
1111
targetSdkVersion targetSdk
1212
versionCode 1
1313
versionName "1.0"
14+
15+
vectorDrawables.useSupportLibrary = true
1416
}
1517

1618
buildTypes {

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
android:label="@string/app_name"
1313
android:allowBackup="true"
1414
android:fullBackupContent="true"
15-
android:icon="@mipmap/ic_launcher"
15+
android:icon="@drawable/ic_launcher"
1616
android:supportsRtl="true"
1717
android:theme="@style/AppTheme"
1818
tools:ignore="GoogleAppIndexingWarning">

app/src/main/java/com/firebase/uidemo/auth/AuthUiActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ private int getSelectedLogo() {
306306
if (mFirebaseLogo.isChecked()) {
307307
return R.drawable.firebase_auth_120dp;
308308
} else if (mGoogleLogo.isChecked()) {
309-
return R.drawable.logo_googleg_color_144dp;
309+
return R.drawable.ic_googleg_color_144dp;
310310
}
311311
return AuthUI.NO_LOGO;
312312
}
-894 Bytes
Binary file not shown.
Binary file not shown.
-568 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<layer-list
2+
xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:aapt="http://schemas.android.com/aapt"
4+
xmlns:tools="http://schemas.android.com/tools">
5+
<item>
6+
<shape android:shape="oval">
7+
<solid android:color="@color/material_gray_300" />
8+
<size
9+
android:width="48dp"
10+
android:height="48dp" />
11+
</shape>
12+
</item>
13+
<item
14+
android:bottom="4dp"
15+
android:left="4dp"
16+
android:right="4dp"
17+
android:top="4dp">
18+
<aapt:attr name="android:drawable">
19+
<vector
20+
android:width="44dp"
21+
android:height="44dp"
22+
android:viewportHeight="24.0"
23+
android:viewportWidth="24.0"
24+
tools:targetApi="lollipop">
25+
<path
26+
android:fillColor="@color/material_gray_500"
27+
android:pathData="M12,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM12,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z" />
28+
</vector>
29+
</aapt:attr>
30+
</item>
31+
</layer-list>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<vector
2+
xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:width="144dp"
4+
android:height="144dp"
5+
android:viewportHeight="512.0"
6+
android:viewportWidth="512.0">
7+
<path
8+
android:fillColor="#4285f4"
9+
android:pathData="M482.6,261.4c0,-16.7 -1.5,-32.8 -4.3,-48.3H256v91.3h127c-5.5,29.5 -22.1,54.5 -47.1,71.2v59.2h76.3c44.6,-41.1 70.4,-101.6 70.4,-173.5z" />
10+
<path
11+
android:fillColor="#34a853"
12+
android:pathData="M256,492c63.7,0 117.1,-21.1 156.2,-57.2l-76.3,-59.2c-21.1,14.2 -48.2,22.5 -79.9,22.5 -61.5,0 -113.5,-41.5 -132.1,-97.3H45.1v61.2c38.8,77.1 118.6,130 210.9,130z" />
13+
<path
14+
android:fillColor="#fbbc05"
15+
android:pathData="M123.9,300.8c-4.7,-14.2 -7.4,-29.3 -7.4,-44.8s2.7,-30.7 7.4,-44.8V150H45.1C29.1,181.9 20,217.9 20,256c0,38.1 9.1,74.1 25.1,106l78.8,-61.2z" />
16+
<path
17+
android:fillColor="#ea4335"
18+
android:pathData="M256,113.9c34.7,0 65.8,11.9 90.2,35.3l67.7,-67.7C373,43.4 319.6,20 256,20c-92.3,0 -172.1,52.9 -210.9,130l78.8,61.2c18.6,-55.8 70.6,-97.3 132.1,-97.3z" />
19+
</vector>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<vector
2+
xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:width="144dp"
4+
android:height="144dp"
5+
android:viewportHeight="512.0"
6+
android:viewportWidth="512.0">
7+
<path
8+
android:fillColor="#FFA000"
9+
android:pathData="M297,205.6l-36.3,33.8l-33.7,-68l17.4,-39.1c4.4,-7.8 11.6,-7.9 16,0L297,205.6z" />
10+
<path
11+
android:fillColor="#F57F17"
12+
android:pathData="M260.7,239.4l-135.8,126.3l102.1,-194.3z" />
13+
<path
14+
android:fillColor="#FFCA28"
15+
android:pathData="M336.8,153.9c6.5,-6.2 13.2,-4.1 14.9,4.7l35.3,205.4L269.9,434.2c-4.1,2.3 -15,3.2 -15,3.2s-9.9,-1.2 -13.7,-3.3L124.9,365.7L336.8,153.9z" />
16+
<path
17+
android:fillColor="#FFA000"
18+
android:pathData="M227,171.4L124.9,365.7l45.5,-284c1.7,-8.8 6.7,-9.7 11.2,-1.9L227,171.4z" />
19+
</vector>

app/src/main/res/layout/message.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
android:layout_height="50dp"
1515
android:layout_marginStart="2dp"
1616
android:layout_marginLeft="2dp"
17-
android:background="@drawable/chat_message_arrow"
17+
android:background="@drawable/ic_chat_message_arrow"
1818
android:rotation="180" />
1919

2020

@@ -24,7 +24,7 @@
2424
android:layout_height="wrap_content"
2525
android:layout_marginLeft="26dp"
2626
android:layout_marginRight="26dp"
27-
android:background="@drawable/chat_message_background"
27+
android:background="@drawable/ic_chat_message_background"
2828
android:orientation="vertical"
2929
android:padding="10dp">
3030

@@ -56,7 +56,7 @@
5656
android:layout_alignRight="@+id/message"
5757
android:layout_marginRight="25dp"
5858
android:layout_alignParentTop="true"
59-
android:background="@drawable/chat_message_arrow"
59+
android:background="@drawable/ic_chat_message_arrow"
6060
android:rotation="180" />
6161

6262
</RelativeLayout>

app/src/main/res/layout/signed_in_layout.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<ScrollView
33
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
45
xmlns:tools="http://schemas.android.com/tools"
56
android:layout_width="match_parent"
67
android:layout_height="match_parent"
@@ -71,7 +72,7 @@
7172
android:layout_gravity="center_horizontal"
7273
android:layout_margin="16dp"
7374
android:contentDescription="@string/profile_picture_content_desc"
74-
android:src="@drawable/anon_user_48dp" />
75+
app:srcCompat="@drawable/ic_anon_user_48dp" />
7576

7677
<LinearLayout
7778
android:layout_width="wrap_content"
-3.13 KB
Binary file not shown.
-2.41 KB
Binary file not shown.
-5.11 KB
Binary file not shown.
-6.45 KB
Binary file not shown.
-10.6 KB
Binary file not shown.

app/src/main/res/values/colors.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<color name="material_green_300">#AED581</color>
2020

2121
<color name="material_gray_300">#E0E0E0</color>
22+
<color name="material_gray_500">#9e9e9e</color>
2223
<color name="material_gray_850">#ff303030</color>
2324
<color name="material_gray_900">#ff212121</color>
2425

app/src/main/res/xml-v25/shortcuts.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<shortcut
44
android:shortcutId="storage"
55
android:enabled="true"
6-
android:icon="@mipmap/ic_launcher"
6+
android:icon="@drawable/ic_launcher"
77
android:shortcutShortLabel="@string/name_image">
88
<intent
99
android:action="android.intent.action.VIEW"
@@ -25,7 +25,7 @@
2525
<shortcut
2626
android:shortcutId="database"
2727
android:enabled="true"
28-
android:icon="@mipmap/ic_launcher"
28+
android:icon="@drawable/ic_launcher"
2929
android:shortcutShortLabel="@string/name_chat">
3030
<intent
3131
android:action="android.intent.action.VIEW"

auth/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ android {
1111
versionCode 1
1212
versionName "1.0"
1313

14+
vectorDrawables.useSupportLibrary = true
1415
resourcePrefix "fui_"
1516
}
1617

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package com.firebase.ui.auth.ui.idp;
2+
3+
import android.content.Context;
4+
import android.content.res.TypedArray;
5+
import android.graphics.drawable.Drawable;
6+
import android.os.Build;
7+
import android.support.v7.content.res.AppCompatResources;
8+
import android.support.v7.widget.AppCompatButton;
9+
import android.util.AttributeSet;
10+
11+
import com.firebase.ui.auth.R;
12+
13+
/**
14+
* A custom button that supports using vector drawables with the {@code
15+
* android:drawable[Start/End/Top/Bottom]} attribute pre-L.
16+
* <p>
17+
* AppCompat can only load vector drawables with srcCompat pre-L and doesn't provide a similar
18+
* compatibility attribute for compound drawables. Thus, we must load compound drawables at runtime
19+
* using AppCompat and inject them into the button to support pre-L devices.
20+
*/
21+
public class SupportVectorDrawablesButton extends AppCompatButton {
22+
public SupportVectorDrawablesButton(Context context) {
23+
super(context);
24+
}
25+
26+
public SupportVectorDrawablesButton(Context context, AttributeSet attrs) {
27+
super(context, attrs);
28+
initSupportVectorDrawablesAttrs(attrs);
29+
}
30+
31+
public SupportVectorDrawablesButton(Context context, AttributeSet attrs, int defStyleAttr) {
32+
super(context, attrs, defStyleAttr);
33+
initSupportVectorDrawablesAttrs(attrs);
34+
}
35+
36+
/**
37+
* Loads the compound drawables natively on L+ devices and using AppCompat pre-L.
38+
* <p>
39+
* <i>Note:</i> If we ever need a TextView with compound drawables, this same technique is
40+
* applicable.
41+
*/
42+
private void initSupportVectorDrawablesAttrs(AttributeSet attrs) {
43+
if (attrs == null) { return; }
44+
45+
TypedArray attributeArray = getContext().obtainStyledAttributes(
46+
attrs,
47+
R.styleable.SupportVectorDrawablesButton);
48+
49+
Drawable drawableStart = null;
50+
Drawable drawableEnd = null;
51+
Drawable drawableTop = null;
52+
Drawable drawableBottom = null;
53+
54+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
55+
drawableStart = attributeArray.getDrawable(
56+
R.styleable.SupportVectorDrawablesButton_drawableStartCompat);
57+
drawableEnd = attributeArray.getDrawable(
58+
R.styleable.SupportVectorDrawablesButton_drawableEndCompat);
59+
drawableTop = attributeArray.getDrawable(
60+
R.styleable.SupportVectorDrawablesButton_drawableTopCompat);
61+
drawableBottom = attributeArray.getDrawable(
62+
R.styleable.SupportVectorDrawablesButton_drawableBottomCompat);
63+
} else {
64+
int drawableStartId = attributeArray.getResourceId(
65+
R.styleable.SupportVectorDrawablesButton_drawableStartCompat, -1);
66+
int drawableEndId = attributeArray.getResourceId(
67+
R.styleable.SupportVectorDrawablesButton_drawableEndCompat, -1);
68+
int drawableTopId = attributeArray.getResourceId(
69+
R.styleable.SupportVectorDrawablesButton_drawableTopCompat, -1);
70+
int drawableBottomId = attributeArray.getResourceId(
71+
R.styleable.SupportVectorDrawablesButton_drawableBottomCompat, -1);
72+
73+
if (drawableStartId != -1) {
74+
drawableStart = AppCompatResources.getDrawable(getContext(), drawableStartId);
75+
}
76+
if (drawableEndId != -1) {
77+
drawableEnd = AppCompatResources.getDrawable(getContext(), drawableEndId);
78+
}
79+
if (drawableTopId != -1) {
80+
drawableTop = AppCompatResources.getDrawable(getContext(), drawableTopId);
81+
}
82+
if (drawableBottomId != -1) {
83+
drawableBottom = AppCompatResources.getDrawable(getContext(), drawableBottomId);
84+
}
85+
}
86+
87+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
88+
setCompoundDrawablesRelativeWithIntrinsicBounds(
89+
drawableStart, drawableTop, drawableEnd, drawableBottom);
90+
} else {
91+
setCompoundDrawablesWithIntrinsicBounds(
92+
drawableStart, drawableTop, drawableEnd, drawableBottom);
93+
}
94+
95+
attributeArray.recycle();
96+
}
97+
}

auth/src/main/res/layout/fui_idp_button_facebook.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Button
1+
<com.firebase.ui.auth.ui.idp.SupportVectorDrawablesButton
22
xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
44
android:id="@+id/facebook_button"

auth/src/main/res/layout/fui_idp_button_google.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Button
1+
<com.firebase.ui.auth.ui.idp.SupportVectorDrawablesButton
22
xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
44
android:id="@+id/google_button"

auth/src/main/res/layout/fui_idp_button_twitter.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Button
1+
<com.firebase.ui.auth.ui.idp.SupportVectorDrawablesButton
22
xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
44
android:id="@+id/twitter_button"

auth/src/main/res/layout/fui_phone_progress_dialog.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<LinearLayout
22
xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
34
android:layout_width="match_parent"
45
android:layout_height="wrap_content"
56
android:orientation="horizontal"
@@ -20,8 +21,8 @@
2021
android:layout_margin="12dp"
2122
android:contentDescription="@string/fui_done"
2223
android:max="10000"
23-
android:src="@drawable/fui_done_check_mark"
24-
android:visibility="gone" />
24+
android:visibility="gone"
25+
app:srcCompat="@drawable/fui_done_check_mark" />
2526

2627
<TextView
2728
android:id="@+id/progress_msg"

auth/src/main/res/layout/fui_provider_button_email.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Button
2+
<com.firebase.ui.auth.ui.idp.SupportVectorDrawablesButton
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
xmlns:tools="http://schemas.android.com/tools"
55
android:id="@+id/email_button"

auth/src/main/res/layout/fui_provider_button_phone.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Button
2+
<com.firebase.ui.auth.ui.idp.SupportVectorDrawablesButton
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
xmlns:tools="http://schemas.android.com/tools"
55
android:id="@+id/phone_button"

auth/src/main/res/values/attrs.xml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<resources xmlns:tools="http://schemas.android.com/tools">
3-
<declare-styleable name="SpacedEditText" tools:ignore="ResourceName">
2+
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
3+
4+
<declare-styleable name="SpacedEditText">
45
<attr name="spacingProportion" format="float" />
56
</declare-styleable>
6-
</resources>
7+
8+
<declare-styleable name="SupportVectorDrawablesButton">
9+
<attr name="drawableStartCompat" format="reference" />
10+
<attr name="drawableEndCompat" format="reference" />
11+
<attr name="drawableTopCompat" format="reference" />
12+
<attr name="drawableBottomCompat" format="reference" />
13+
</declare-styleable>
14+
15+
</resources>

auth/src/main/res/values/styles.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,31 +215,31 @@
215215
</style>
216216

217217
<style name="FirebaseUI.Button.AccountChooser.EmailButton">
218-
<item name="android:drawableLeft">@drawable/fui_ic_mail_white_24dp</item>
218+
<item name="drawableStartCompat">@drawable/fui_ic_mail_white_24dp</item>
219219
<item name="android:background">@drawable/fui_idp_button_background_email</item>
220220
<item name="android:textColor">#ffffff</item>
221221
</style>
222222

223223
<style name="FirebaseUI.Button.AccountChooser.PhoneButton">
224-
<item name="android:drawableLeft">@drawable/fui_ic_settings_phone_white_24dp</item>
224+
<item name="drawableStartCompat">@drawable/fui_ic_phone_white_24dp</item>
225225
<item name="android:background">@drawable/fui_idp_button_background_phone</item>
226226
<item name="android:textColor">#ffffff</item>
227227
</style>
228228

229229
<style name="FirebaseUI.Button.AccountChooser.GoogleButton">
230-
<item name="android:drawableLeft">@drawable/fui_ic_googleg_color_24dp</item>
230+
<item name="drawableStartCompat">@drawable/fui_ic_googleg_color_24dp</item>
231231
<item name="android:background">@drawable/fui_idp_button_background_google</item>
232232
<item name="android:textColor">#757575</item>
233233
</style>
234234

235235
<style name="FirebaseUI.Button.AccountChooser.FacebookButton">
236-
<item name="android:drawableLeft">@drawable/fui_ic_facebook_white_22dp</item>
236+
<item name="drawableStartCompat">@drawable/fui_ic_facebook_white_22dp</item>
237237
<item name="android:background">@drawable/fui_idp_button_background_facebook</item>
238238
<item name="android:textColor">#FFFFFFFF</item>
239239
</style>
240240

241241
<style name="FirebaseUI.Button.AccountChooser.TwitterButton">
242-
<item name="android:drawableLeft">@drawable/fui_ic_twitter_bird_white_24dp</item>
242+
<item name="drawableStartCompat">@drawable/fui_ic_twitter_bird_white_24dp</item>
243243
<item name="android:background">@drawable/fui_idp_button_background_twitter</item>
244244
<item name="android:textColor">#FFFFFFFF</item>
245245
</style>

library/quality/lint-baseline.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,17 @@
5050
column="13"/>
5151
</issue>
5252

53+
<!-- TODO remove in https://github.com/firebase/FirebaseUI-Android/pull/851 -->
54+
<issue
55+
id="IconLauncherFormat"
56+
severity="Error"
57+
message="Launcher icons must be in PNG format"
58+
category="Usability:Icons"
59+
priority="6"
60+
summary="Wrong launcher icon format"
61+
explanation="Launcher icons should be in the PNG format. This requirement is enforced by the The Google Play Developer Console."
62+
quickfix="studio">
63+
<location file="src/main/res/drawable/ic_launcher.xml"/>
64+
</issue>
65+
5366
</issues>

0 commit comments

Comments
 (0)