Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/
.DS_Store
/build
/captures
Expand Down
19 changes: 12 additions & 7 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
tools:context=".MainActivity"
android:orientation="vertical">

<com.outsmart.atlanticadesign.Molecules.ATLImageLogo
android:background="#0fc3ac"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="280dp"
app:imageLogo="@drawable/logo_sample"
/>
<com.outsmart.atlanticadesign.Molecules.ATLTitle
app:text="Titulo com atributos setados pelo tema"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<com.outsmart.atlanticadesign.Molecules.ATLTitle
app:text="Titulo com atributos setados no xml (sobrescrevem os do style)"
app:labelFontSize="5sp"
app:labelTextAlignment="right"
app:labelFontColor="@color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

</LinearLayout>
1 change: 0 additions & 1 deletion app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
<color name="black">#000000</color>
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@
<style name="AtlanticaDesignTheme" parent="Theme.AppCompat.Light">

<!-- Spacing -->
<item name="verticalSpacingSmall">10dp</item>
<item name="verticalSpacingSmall">8dp</item>
<item name="horizontalSpacingMargin">10dp</item>
<item name="horizontalSpacingSmall">10dp</item>
<item name="horizontalSpacingMedium">10dp</item>
<item name="colorPrimary">@color/red</item>

<!-- Size -->
<item name="iconListSize">30dp</item>
<item name="listItemLabelFontSize">6sp</item>
<item name="fontSizeHighlight">10sp</item>

<!-- Color -->
<item name="mediumGrayColor">#6b6b6b</item>

<!-- Enums -->
<item name="settingsTextAlignment">left</item>
<item name="sizeImageLogo">30dp</item>
<item name="textAlignmentBody">right</item>
<item name="textAlignmentTitle">left</item>

<!-- Misc -->
<!-- TODO figure out fonts -->
<!--<item name="projectFont">#ec92cd</item>-->

</style>

</resources>
</resources>
1 change: 1 addition & 0 deletions atlanticadesign/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies {

implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.recyclerview:recyclerview:1.0.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.outsmart.atlanticadesign.Atoms

import android.content.Context
import android.text.InputType
import android.util.AttributeSet
import android.widget.TextView
import com.outsmart.atlanticadesign.R
Expand All @@ -19,7 +20,6 @@ class ATLSimpleLabel @JvmOverloads constructor(
var textColor = 0
var fontSize = 0f
var textAlignment = 0
var backgroundColor = 0
context.theme.obtainStyledAttributes(
attributeSet,
R.styleable.ATLSimpleLabel,
Expand All @@ -29,16 +29,18 @@ class ATLSimpleLabel @JvmOverloads constructor(
try {
textColor = getColor(R.styleable.ATLSimpleLabel_textColor, 0)
fontSize = getDimension(R.styleable.ATLSimpleLabel_fontSize, -1f)
textAlignment = getInteger(R.styleable.ATLSimpleLabel_textAlignment, -1)
backgroundColor = getColor(R.styleable.ATLSimpleLabel_backgroundColor, -1)
textAlignment = getInteger(R.styleable.ATLSimpleLabel_labelTextAlignment, -1)

} finally {
recycle()
}
}
if (textColor != 0) this.setTextColor(textColor)
if (fontSize >= 0) this.setTextSize(fontSize)
if (backgroundColor >= 0) this.setBackgroundColor(backgroundColor)
if (textColor != 0) {
this.setTextColor(textColor)
}
if (fontSize >= 0) {
this.textSize = fontSize
}

setTextAlignmentATL(textAlignment)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ import android.util.AttributeSet
import android.widget.ImageView
import com.outsmart.atlanticadesign.R

class ATLIcon @JvmOverloads constructor(context: Context,
attributeSet: AttributeSet? = null,
defStyle: Int = 0) : ImageView(context, attributeSet, defStyle) {
class ATMIcon @JvmOverloads constructor(
context: Context,
attributeSet: AttributeSet? = null,
defStyle: Int = 0
) : ImageView(context, attributeSet, defStyle) {

init {
var source = 0
context.theme.obtainStyledAttributes(
attributeSet,
R.styleable.ATLIcon,
0, 0).apply {
R.styleable.ATMIcon,
0, 0
).apply {

try {
source = getResourceId(R.styleable.ATLIcon_source, 0)
source = getResourceId(R.styleable.ATMIcon_source, 0)
} finally {
recycle()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import android.content.Context
import android.util.AttributeSet
import android.widget.Switch

class ATLSwitchButton @JvmOverloads constructor(context: Context,
class ATMSwitchButton @JvmOverloads constructor(context: Context,
attributeSet: AttributeSet? = null
) : Switch(context, attributeSet)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package com.outsmart.atlanticadesign.Helpers

object Constants {

const val RESOURCE_DEFAULT_VALUE = -1
const val RESOURCE_VALUE_UNAVAILABLE = -1
const val FONT_SIZE_DEFAULT = 12
const val MARGIN_DEFAULT_VALUE = 0
const val DIMENSION_DEFAULT_VALUE = 0
const val ENUM_DEFAULT_VALUE = 0
const val SPACING_DEFAULT = 8
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import android.content.res.Resources


fun convertPixelsToDp(px: Int): Float {
val metrics = Resources.getSystem().getDisplayMetrics()
val metrics = Resources.getSystem().displayMetrics
val dp = px / (metrics.densityDpi / 160f)
return Math.round(dp).toFloat()
}

fun convertDpToPixel(dp: Int): Int {
val metrics = Resources.getSystem().getDisplayMetrics()
val metrics = Resources.getSystem().displayMetrics
val px = dp * (metrics.densityDpi / 160f)
return Math.round(px)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Resolver(
return defValue
}

fun getResolvedColorStyle(themeAttrId: Int, viewAttrId: Int, defValue: Int): Int {
fun getResolvedColorStyle(themeAttrId: Int, viewAttrId: Int, defValue: Int = Constants.RESOURCE_VALUE_UNAVAILABLE): Int {
val hasFromInput = input.hasValue(viewAttrId)
if (hasFromInput) {
return input.getColor(viewAttrId, defValue)
Expand All @@ -48,7 +48,7 @@ class Resolver(
return defValue
}

fun getResolvedEnumStyle(themeAttrId: Int, viewAttrId: Int, defValue: Int): Int {
fun getResolvedEnumStyle(themeAttrId: Int, viewAttrId: Int, defValue: Int = Constants.ENUM_DEFAULT_VALUE): Int {
val hasFromInput = input.hasValue(viewAttrId)
if (hasFromInput) {
return input.getInteger(viewAttrId, defValue)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.outsmart.atlanticadesign.Atoms
package com.outsmart.atlanticadesign.Molecules

import android.app.Activity
import android.content.Context
Expand All @@ -17,7 +17,8 @@ class ATLDivider @JvmOverloads constructor(
defStyle: Int = 0
) : View(context, attributeSet, defStyle) {

private var style: Style = Style()
private var style: Style =
Style()

init {
context.theme.obtainStyledAttributes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ATLImageLogo @JvmOverloads constructor(
typedArray.apply {
val resourceId = getResourceId(
R.styleable.ATLImageLogo_imageLogo,
Constants.RESOURCE_DEFAULT_VALUE
Constants.RESOURCE_VALUE_UNAVAILABLE
)
setImageLogo(resourceId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import android.util.AttributeSet
import android.view.View
import android.widget.LinearLayout
import android.widget.RelativeLayout
import com.outsmart.atlanticadesign.Atoms.ATLIcon
import com.outsmart.atlanticadesign.Atoms.ATMIcon
import com.outsmart.atlanticadesign.Atoms.ATLSimpleLabel
import com.outsmart.atlanticadesign.Atoms.ATLSwitchButton
import com.outsmart.atlanticadesign.Atoms.ATMSwitchButton
import com.outsmart.atlanticadesign.Helpers.*
import com.outsmart.atlanticadesign.R
import com.outsmart.atlanticadesign.enums.TextAlignment
Expand All @@ -31,10 +31,10 @@ class ATLSettingsItem @JvmOverloads constructor(

/* Views and Components */
private val label: ATLSimpleLabel by lazy { atl_settings_item_label }
private val icon: ATLIcon by lazy { atl_settings_item_icon }
private val icon: ATMIcon by lazy { atl_settings_item_icon }
private val iconContainer: LinearLayout by lazy { atl_settings_item_icon_container }
private val rightIcon: ATLIcon by lazy { atl_settings_right_item_icon }
private val switch: ATLSwitchButton by lazy { atl_settings_item_switch_button }
private val switch: ATMSwitchButton by lazy { atl_settings_item_switch_button }
private val rightIcon: ATMIcon by lazy { atl_settings_right_item_icon }

/* */
var styleTransformer: ((style: Style) -> Style)? = null
Expand Down Expand Up @@ -100,11 +100,11 @@ class ATLSettingsItem @JvmOverloads constructor(
)
marginTopSpacing = getResolvedDimenStyle(
R.attr.verticalSpacingSmall,
R.styleable.ATLSettingsItem_marginTopSpacing
R.styleable.ATLSettingsItem_verticalSpacing
)
marginBottomSpacing = getResolvedDimenStyle(
R.attr.verticalSpacingSmall,
R.styleable.ATLSettingsItem_marginBottomSpacing
R.styleable.ATLSettingsItem_verticalSpacing
)
iconHeight = getResolvedDimenStyle(
R.attr.iconListSize,
Expand Down Expand Up @@ -132,12 +132,11 @@ class ATLSettingsItem @JvmOverloads constructor(
)
labelFontColor = getResolvedColorStyle(
R.attr.mediumGrayColor,
R.styleable.ATLSettingsItem_labelFontColor,
0
R.styleable.ATLSettingsItem_labelFontColor
)
textAlignment = TextAlignment.values()[getResolvedEnumStyle(
R.attr.textAlignment,
R.styleable.ATLSettingsItem_textAlignment,
R.attr.textAlignmentBody,
R.styleable.ATLSettingsItem_labelTextAlignment,
0
)]
}
Expand All @@ -149,20 +148,29 @@ class ATLSettingsItem @JvmOverloads constructor(

private fun loadInitialProps(input: TypedArray) {
input.apply {
setText(getString(R.styleable.ATLSettingsItem_text) ?: "")
setText(
getString(
R.styleable.ATLSettingsItem_text
) ?: ""
)
setIcon(
getResourceId(
R.styleable.ATLSettingsItem_icon,
Constants.RESOURCE_DEFAULT_VALUE
Constants.RESOURCE_VALUE_UNAVAILABLE
)
)
setRightComponentVariant(
getInteger(
R.styleable.ATLSettingsItem_rightComponentVariant,
Constants.RESOURCE_DEFAULT_VALUE
Constants.RESOURCE_VALUE_UNAVAILABLE
)
)
setRightIcon(
getResourceId(
R.styleable.ATLSettingsItem_rightIcon,
Constants.RESOURCE_VALUE_UNAVAILABLE
)
)
setRightIcon(getResourceId(R.styleable.ATLSettingsItem_rightIcon, Constants.RESOURCE_DEFAULT_VALUE))
}
}

Expand All @@ -172,10 +180,14 @@ class ATLSettingsItem @JvmOverloads constructor(
setLabelStyle()
}

private fun setLabelStyle() {
private fun setViewPadding() {
with(style) {
label.setTextColor(labelFontColor)
label.setTextAlignmentATL(textAlignment)
setPadding(
marginLeftSpacing,
marginTopSpacing,
marginRightSpacing,
marginBottomSpacing
)
}
}

Expand All @@ -189,14 +201,10 @@ class ATLSettingsItem @JvmOverloads constructor(
}
}

private fun setViewPadding() {
private fun setLabelStyle() {
with(style) {
setPadding(
marginLeftSpacing,
marginTopSpacing,
marginRightSpacing,
marginBottomSpacing
)
label.setTextColor(labelFontColor)
label.setTextAlignmentATL(textAlignment)
}
}

Expand Down
Loading