* For #9857: Creates text button style * Adds lint check * Fixes onboarding cardsmaster
parent
997f6c72d6
commit
8185ba793e
|
@ -6,7 +6,7 @@ package org.mozilla.fenix.home.sessioncontrol.viewholders
|
|||
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kotlinx.android.synthetic.main.save_tab_group_button.view.*
|
||||
import kotlinx.android.synthetic.main.save_to_collection_button.view.*
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.components.metrics.Event
|
||||
import org.mozilla.fenix.ext.components
|
||||
|
@ -27,6 +27,6 @@ class SaveTabGroupViewHolder(
|
|||
|
||||
companion object {
|
||||
const val TELEMETRY_HOME_IDENTIFIER = "home"
|
||||
const val LAYOUT_ID = R.layout.save_tab_group_button
|
||||
const val LAYOUT_ID = R.layout.save_to_collection_button
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,13 +7,13 @@
|
|||
<item android:id="@android:id/mask">
|
||||
<shape>
|
||||
<solid android:color="#000000" />
|
||||
<corners android:radius="8dp" />
|
||||
<corners android:radius="4dp" />
|
||||
</shape>
|
||||
</item>
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="?inset" />
|
||||
<corners android:radius="8dp" />
|
||||
<corners android:radius="4dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</ripple>
|
|
@ -10,7 +10,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginTop="32dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:paddingStart="@dimen/radio_button_preference_horizontal"
|
||||
android:paddingEnd="@dimen/radio_button_preference_horizontal"
|
||||
android:visibility="gone"
|
||||
|
@ -54,12 +54,8 @@
|
|||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/settings_button"
|
||||
style="@style/ThemeIndependentMaterialGreyButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:paddingStart="24dp"
|
||||
android:paddingEnd="24dp"
|
||||
style="@style/NeutralButton"
|
||||
android:layout_marginVertical="16dp"
|
||||
android:text="@string/phone_feature_go_to_settings" />
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -6,17 +6,10 @@
|
|||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/bookmark_folders_sign_in"
|
||||
style="@style/ThemeIndependentMaterialGreyButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/sign_in_button_margin"
|
||||
android:layout_marginStart="@dimen/sign_in_button_margin"
|
||||
android:layout_marginTop="@dimen/sign_in_button_margin_top"
|
||||
android:paddingBottom="@dimen/sign_in_button_padding"
|
||||
android:paddingTop="@dimen/sign_in_button_padding"
|
||||
style="@style/NeutralButton"
|
||||
android:text="@string/bookmark_sign_in_button"
|
||||
android:visibility="gone"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:rippleColor="?secondaryText"/>
|
||||
app:layout_constraintStart_toStartOf="parent"/>
|
||||
|
|
|
@ -2,14 +2,10 @@
|
|||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<com.google.android.material.button.MaterialButton xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<com.google.android.material.button.MaterialButton
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/removeAllExceptions"
|
||||
style="@style/ThemeIndependentMaterialGreyButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:paddingStart="24dp"
|
||||
android:paddingEnd="24dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start"
|
||||
android:layout_margin="12dp"
|
||||
style="@style/NeutralButton"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:text="@string/preferences_tracking_protection_exceptions_turn_on_for_all" />
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@
|
|||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/learn_button"
|
||||
style="@style/ThemeIndependentMaterialGreyButton"
|
||||
style="@style/NeutralButton"
|
||||
android:padding="16dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -79,7 +79,7 @@
|
|||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/connect_button"
|
||||
style="@style/ThemeIndependentMaterialGreyButton"
|
||||
style="@style/NeutralButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
|
|
|
@ -78,10 +78,8 @@
|
|||
app:deleteBrowsingDataItemTitle="@string/preferences_delete_browsing_data_site_permissions" />
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/delete_data"
|
||||
style="@style/ThemeIndependentMaterialGreyButtonDestructive"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="12dp"
|
||||
style="@style/DestructiveButton"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:text="@string/preferences_delete_browsing_data_button" />
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
|
|
@ -75,11 +75,8 @@
|
|||
|
||||
<Button
|
||||
android:id="@+id/remove_add_on"
|
||||
style="@style/ThemeIndependentMaterialGreyButtonDestructive"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/DestructiveButton"
|
||||
android:layout_below="@+id/permissions"
|
||||
android:layout_margin="12dp"
|
||||
android:text="@string/mozac_feature_addons_remove" />
|
||||
</RelativeLayout>
|
||||
</ScrollView>
|
||||
|
|
|
@ -23,13 +23,11 @@
|
|||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/delete_all_site_permissions_button"
|
||||
style="@style/ThemeIndependentMaterialGreyButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
style="@style/DestructiveButton"
|
||||
android:background="@drawable/button_background"
|
||||
android:text="@string/clear_permissions_on_all_sites"
|
||||
android:visibility="gone"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/exceptions" />
|
||||
|
||||
|
|
|
@ -56,34 +56,19 @@
|
|||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/signInScanButton"
|
||||
style="@style/Widget.MaterialComponents.Button.TextButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="48dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:letterSpacing="0"
|
||||
style="@style/PositiveButton"
|
||||
android:text="@string/sign_in_ready_for_scan"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="?contrastText"
|
||||
android:textStyle="bold"
|
||||
app:backgroundTint="?accent"
|
||||
android:layout_marginVertical="16dp"
|
||||
app:icon="@drawable/ic_qr"
|
||||
app:iconGravity="textStart"
|
||||
app:iconPadding="8dp"
|
||||
app:iconTint="?contrastText"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/signInInstructions"
|
||||
app:fontFamily="@font/metropolis_semibold" />
|
||||
app:layout_constraintTop_toBottomOf="@id/signInInstructions" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/signInEmailButton"
|
||||
style="@style/ThemeIndependentMaterialGreyButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="48dp"
|
||||
android:layout_marginTop="8dp"
|
||||
style="@style/NeutralButton"
|
||||
android:text="@string/sign_in_with_email"
|
||||
android:layout_margin="0dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/signInScanButton" />
|
||||
|
|
|
@ -10,14 +10,11 @@
|
|||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/delete_button"
|
||||
style="@style/ThemeIndependentMaterialGreyButtonDestructive"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:text="@string/history_delete_all"
|
||||
app:rippleColor="?secondaryText"
|
||||
android:visibility="gone" />
|
||||
android:id="@+id/delete_button"
|
||||
style="@style/DestructiveButton"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:text="@string/history_delete_all"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/header_title"
|
||||
|
@ -27,7 +24,6 @@
|
|||
android:textColor="?primaryText"
|
||||
android:paddingStart="20dp"
|
||||
android:paddingEnd="0dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
tools:text="Header"
|
||||
android:visibility="gone" />
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<com.google.android.material.button.MaterialButton xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<com.google.android.material.button.MaterialButton
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/reset_permission"
|
||||
style="@style/ThemeIndependentMaterialGreyButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:paddingStart="24dp"
|
||||
android:paddingEnd="24dp"
|
||||
style="@style/DestructiveButton"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:text="@string/clear_permissions" />
|
||||
|
|
|
@ -35,17 +35,9 @@
|
|||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/add_new_tab_button"
|
||||
style="@style/ThemeIndependentMaterialGreyButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
style="@style/NeutralButton"
|
||||
android:layout_marginTop="6dp"
|
||||
android:paddingStart="0dp"
|
||||
android:paddingEnd="12dp"
|
||||
android:textSize="14sp"
|
||||
android:visibility="gone"
|
||||
app:iconGravity="textStart"
|
||||
app:iconTint="@color/button_text_color"
|
||||
tools:icon="@drawable/ic_new"
|
||||
tools:text="@string/home_screen_shortcut_open_new_tab_2"
|
||||
tools:visibility="visible" />
|
||||
|
|
|
@ -3,17 +3,7 @@
|
|||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<Button xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
style="@style/PositiveButton"
|
||||
android:id="@+id/finish_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:background="@drawable/onboarding_button_background"
|
||||
android:backgroundTint="@color/onboarding_card_icon"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:gravity="center"
|
||||
android:text="@string/onboarding_finish"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="?contrastText"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
android:text="@string/onboarding_finish" />
|
||||
|
|
|
@ -23,20 +23,9 @@
|
|||
tools:text="@string/onboarding_firefox_account_header" />
|
||||
|
||||
<Button
|
||||
style="@style/NeutralButton"
|
||||
android:id="@+id/turn_on_sync_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:background="@drawable/button_background"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:gravity="center"
|
||||
android:padding="10dp"
|
||||
android:text="@string/onboarding_firefox_account_sign_in"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="@color/button_text_color"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold"
|
||||
app:backgroundTint="@color/foundation_light_theme"
|
||||
style="@style/MetropolisButton" />
|
||||
app:backgroundTint="@color/foundation_light_theme" />
|
||||
</LinearLayout>
|
||||
|
|
|
@ -33,32 +33,14 @@
|
|||
app:layout_constraintTop_toBottomOf="@id/header_text"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
<FrameLayout
|
||||
android:id="@+id/read_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:background="@drawable/button_background"
|
||||
android:backgroundTint="?neutralFaded"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:foreground="?android:attr/selectableItemBackground"
|
||||
android:padding="10dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/description_text"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:textStyle="bold"
|
||||
android:gravity="center"
|
||||
android:text="@string/onboarding_privacy_notice_read_button"
|
||||
android:textColor="?primaryText"
|
||||
android:textSize="14sp"
|
||||
app:fontFamily="@font/metropolis_regular" />
|
||||
</FrameLayout>
|
||||
|
||||
<Button
|
||||
style="@style/NeutralOnboardingButton"
|
||||
android:id="@+id/read_button"
|
||||
android:text="@string/onboarding_privacy_notice_read_button"
|
||||
android:layout_marginTop="16dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/description_text"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
|
@ -46,32 +46,13 @@
|
|||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@id/open_settings_button" />
|
||||
|
||||
<FrameLayout
|
||||
<Button
|
||||
android:id="@+id/open_settings_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/NeutralOnboardingButton"
|
||||
android:layout_marginTop="16dp"
|
||||
android:background="@drawable/button_background"
|
||||
android:backgroundTint="?neutralFaded"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:foreground="?android:attr/selectableItemBackground"
|
||||
android:padding="10dp"
|
||||
android:text="@string/onboarding_private_browsing_button"
|
||||
app:layout_constraintTop_toBottomOf="@id/description_text_always"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:textStyle="bold"
|
||||
android:gravity="center"
|
||||
android:text="@string/onboarding_private_browsing_button"
|
||||
android:textColor="?primaryText"
|
||||
android:textSize="14sp"
|
||||
app:fontFamily="@font/metropolis_regular" />
|
||||
</FrameLayout>
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<com.google.android.material.button.MaterialButton xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/save_tab_group_button"
|
||||
style="@style/Widget.MaterialComponents.Button.TextButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="36dp"
|
||||
android:insetTop="0dp"
|
||||
android:insetBottom="0dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:background="@drawable/button_background"
|
||||
android:letterSpacing="0"
|
||||
android:text="@string/save_to_collection"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="?contrastText"
|
||||
app:backgroundTint="?accent"
|
||||
app:icon="@drawable/ic_tab_collection"
|
||||
app:iconGravity="textStart"
|
||||
app:iconPadding="8dp"
|
||||
app:fontFamily="@font/metropolis_medium"
|
||||
app:iconTint="?attr/contrastText" />
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<com.google.android.material.button.MaterialButton
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
style="@style/PositiveButton"
|
||||
android:id="@+id/save_tab_group_button"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:text="@string/save_to_collection"
|
||||
app:icon="@drawable/ic_tab_collection" />
|
|
@ -61,7 +61,7 @@
|
|||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/allow"
|
||||
style="@style/ThemeIndependentMaterialGreyButton"
|
||||
style="@style/NeutralButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="12dp"
|
||||
|
|
|
@ -180,18 +180,39 @@
|
|||
<item name="android:windowExitAnimation">@anim/fade_out</item>
|
||||
</style>
|
||||
|
||||
<style name="ThemeIndependentMaterialGreyButton" parent="Widget.MaterialComponents.Button.TextButton">
|
||||
<!-- UI button styling -->
|
||||
<style name="NeutralButton" parent="Widget.MaterialComponents.Button.TextButton">
|
||||
<item name="iconTint">@color/button_text_color</item>
|
||||
<item name="iconPadding">8dp</item>
|
||||
<item name="iconGravity">textStart</item>
|
||||
<item name="android:textAlignment">center</item>
|
||||
<item name="android:background">@drawable/rounded_button_background</item>
|
||||
<item name="android:layout_width">match_parent</item>
|
||||
<item name="android:layout_height">48dp</item>
|
||||
<item name="android:textStyle">bold</item>
|
||||
<item name="android:textAllCaps">false</item>
|
||||
<item name="backgroundTint">@color/grey_button_color</item>
|
||||
<item name="android:textColor">@color/button_text_color</item>
|
||||
<item name="rippleColor">?secondaryText</item>
|
||||
<item name="android:letterSpacing">0</item>
|
||||
<item name="fontFamily">@font/metropolis_semibold</item>
|
||||
</style>
|
||||
|
||||
<style name="ThemeIndependentMaterialGreyButtonDestructive" parent="ThemeIndependentMaterialGreyButton">
|
||||
<!-- Ideally we should consolidate this with NeutralButton in the future -->
|
||||
<style name="NeutralOnboardingButton" parent="NeutralButton">
|
||||
<item name="backgroundTint">?neutralFaded</item>
|
||||
<item name="android:textColor">?primaryText</item>
|
||||
</style>
|
||||
|
||||
<style name="DestructiveButton" parent="NeutralButton">
|
||||
<item name="iconTint">@color/destructive_button_text_color</item>
|
||||
<item name="android:textColor">@color/destructive_button_text_color</item>
|
||||
<item name="fontFamily">@font/metropolis_semibold</item>
|
||||
</style>
|
||||
|
||||
<style name="PositiveButton" parent="NeutralButton">
|
||||
<item name="backgroundTint">?accent</item>
|
||||
<item name="iconTint">?contrastText</item>
|
||||
<item name="android:textColor">?contrastText</item>
|
||||
</style>
|
||||
|
||||
<style name="search_pill" parent="Widget.AppCompat.Button.Borderless">
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
package org.mozilla.fenix.lintrules
|
||||
|
||||
import com.android.SdkConstants
|
||||
import com.android.resources.ResourceFolderType
|
||||
import com.android.tools.lint.detector.api.Category
|
||||
import com.android.tools.lint.detector.api.Implementation
|
||||
import com.android.tools.lint.detector.api.Issue
|
||||
import com.android.tools.lint.detector.api.ResourceXmlDetector
|
||||
import com.android.tools.lint.detector.api.Scope
|
||||
import com.android.tools.lint.detector.api.Severity
|
||||
import com.android.tools.lint.detector.api.XmlContext
|
||||
import org.w3c.dom.Element
|
||||
|
||||
/**
|
||||
* A custom lint check that prohibits not using the style attribute on buttons
|
||||
*/
|
||||
class ButtonStyleXmlDetector : ResourceXmlDetector() {
|
||||
companion object {
|
||||
const val SCHEMA = "http://schemas.android.com/apk/res-auto"
|
||||
|
||||
// TODO:
|
||||
const val ERROR_MESSAGE =
|
||||
"All buttons must have a style, try using NeutralButton or similar."
|
||||
|
||||
val ISSUE_XML_STYLE = Issue.create(
|
||||
id = "ButtonStyleXmlDetector",
|
||||
briefDescription = "Prohibits using a button without a style",
|
||||
explanation = "Butttons should have a style applied",
|
||||
category = Category.CORRECTNESS,
|
||||
severity = Severity.ERROR,
|
||||
implementation = Implementation(
|
||||
ButtonStyleXmlDetector::class.java,
|
||||
Scope.RESOURCE_FILE_SCOPE
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun appliesTo(folderType: ResourceFolderType): Boolean {
|
||||
// Return true if we want to analyze resource files in the specified resource
|
||||
// folder type. In this case we only need to analyze layout resource files.
|
||||
return folderType == ResourceFolderType.LAYOUT
|
||||
}
|
||||
|
||||
override fun getApplicableElements(): Collection<String>? {
|
||||
return setOf(
|
||||
SdkConstants.FQCN_BUTTON,
|
||||
SdkConstants.MATERIAL_BUTTON,
|
||||
SdkConstants.BUTTON
|
||||
)
|
||||
}
|
||||
|
||||
override fun visitElement(context: XmlContext, element: Element) {
|
||||
if (element.hasAttributeNS(SCHEMA, SdkConstants.ATTR_STYLE)) { return }
|
||||
|
||||
context.report(
|
||||
issue = ISSUE_XML_STYLE,
|
||||
scope = element,
|
||||
location = context.getLocation(element),
|
||||
message = ERROR_MESSAGE
|
||||
)
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@ import com.android.tools.lint.detector.api.Issue
|
|||
class LintIssueRegistry : IssueRegistry() {
|
||||
override val api: Int = com.android.tools.lint.detector.api.CURRENT_API
|
||||
override val issues: List<Issue> = listOf(
|
||||
ButtonStyleXmlDetector.ISSUE_XML_STYLE,
|
||||
AndroidSrcXmlDetector.ISSUE_XML_SRC_USAGE,
|
||||
TextViewAndroidSrcXmlDetector.ISSUE_XML_SRC_USAGE,
|
||||
ImageViewAndroidTintXmlDetector.ISSUE_XML_SRC_USAGE
|
||||
|
|
Loading…
Reference in New Issue