* For #9857: Creates text button style * Adds lint check * Fixes onboarding cardsfennec/production
parent
997f6c72d6
commit
8185ba793e
@ -1,12 +1,9 @@
|
|||||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
<!-- 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
|
- 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/. -->
|
- 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"
|
android:id="@+id/reset_permission"
|
||||||
style="@style/ThemeIndependentMaterialGreyButton"
|
style="@style/DestructiveButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_marginHorizontal="16dp"
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_margin="16dp"
|
|
||||||
android:paddingStart="24dp"
|
|
||||||
android:paddingEnd="24dp"
|
|
||||||
android:text="@string/clear_permissions" />
|
android:text="@string/clear_permissions" />
|
||||||
|
@ -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" />
|
@ -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
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue