Skip to content

Commit 13a4ae9

Browse files
authored
Merge pull request #575 from mikepenz/develop
dev -> main
2 parents 8c710cf + a2f6598 commit 13a4ae9

File tree

8 files changed

+64
-31
lines changed

8 files changed

+64
-31
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
## Latest releases 🛠
5252

53-
- Kotlin Next Gen | [v5.2.8](https://github.com/mikepenz/Android-Iconics/tree/v5.2.8)
53+
- Kotlin Next Gen | [v5.2.8](https://github.com/mikepenz/Android-Iconics/tree/v5.2.8) | [v5.3.0-b01](https://github.com/mikepenz/Android-Iconics/tree/v5.3.0-b01)
5454
- Kotlin | [v4.0.2](https://github.com/mikepenz/Android-Iconics/tree/v4.0.2)
5555
- Java AndroidX | [v3.2.5](https://github.com/mikepenz/Android-Iconics/tree/v3.2.5)
5656
- Java Appcompat | [v3.0.4](https://github.com/mikepenz/Android-Iconics/tree/v3.0.4)

app/src/main/java/com/mikepenz/iconics/sample/IconsFragment.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import com.mikepenz.iconics.sample.item.IconItem
4040
import com.mikepenz.iconics.utils.IconicsUtils
4141
import com.mikepenz.iconics.utils.backgroundColorRes
4242
import com.mikepenz.iconics.utils.backgroundColorString
43+
import com.mikepenz.iconics.utils.backgroundContourColorString
4344
import com.mikepenz.iconics.utils.colorRes
4445
import com.mikepenz.iconics.utils.contourColorRes
4546
import com.mikepenz.iconics.utils.contourWidthDp
@@ -81,6 +82,10 @@ class IconsFragment : Fragment(R.layout.icons_fragment) {
8182
adapter.notifyAdapterDataSetChanged()
8283
}
8384

85+
fun respectFontBounds() {
86+
adapter.notifyAdapterDataSetChanged()
87+
}
88+
8489
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
8590
super.onViewCreated(view, savedInstanceState)
8691
binding = IconsFragmentBinding.bind(view)
@@ -132,6 +137,8 @@ class IconsFragment : Fragment(R.layout.icons_fragment) {
132137
sizeDp = 144
133138
paddingDp = 8
134139
backgroundColorString = "#DDFFFFFF"
140+
backgroundContourColorString = "#DD000000"
141+
backgroundContourWidthPx = 4
135142
roundedCornersDp = 12
136143
}
137144

app/src/main/java/com/mikepenz/iconics/sample/MainActivity.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ class MainActivity : AppCompatActivity() {
179179
colorInt = Color.WHITE
180180
}
181181

182+
menu.findItem(R.id.action_respect_bounds).isChecked = Iconics.respectFontBoundsDefault
183+
182184
return super.onCreateOptionsMenu(menu)
183185
}
184186

@@ -207,6 +209,12 @@ class MainActivity : AppCompatActivity() {
207209
isShadowEnabled = item.isChecked
208210
return true
209211
}
212+
R.id.action_respect_bounds -> {
213+
item.isChecked = !item.isChecked
214+
iconsFragment?.respectFontBounds()
215+
Iconics.respectFontBoundsDefault = item.isChecked
216+
return true
217+
}
210218
R.id.action_opensource -> {
211219
LibsBuilder()
212220
.withFields(R.string::class.java.fields)

app/src/main/res/menu/menu_main.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
android:id="@+id/action_shadow"
3535
android:checkable="true"
3636
android:title="@string/action_shadow" />
37+
<item
38+
android:id="@+id/action_respect_bounds"
39+
android:checkable="true"
40+
android:title="@string/action_respect_bounds" />
3741
<item
3842
android:id="@+id/action_opensource"
3943
android:title="@string/action_opensource"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
<string name="action_randomize">Randomize</string>
2727
<string name="action_shadow">Shadow</string>
28+
<string name="action_respect_bounds">Respect font bounds</string>
2829
<string name="action_opensource">Open Source</string>
2930
<string name="action_playground">Playground</string>
3031
<string name="action_automatic">Automatic Mapping</string>

build.gradle

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ buildscript {
1818

1919
ext {
2020
release = [
21-
versionName: "5.2.8",
22-
versionCode: 50208
21+
versionName: "5.3.0-b01",
22+
versionCode: 50300
2323
]
2424

2525
setup = [
@@ -31,7 +31,7 @@ buildscript {
3131
]
3232

3333
versions = [
34-
kotlin : '1.4.30',
34+
kotlin : '1.4.31',
3535
androidX : '1.0.0',
3636
recyclerView : '1.1.0',
3737
material : '1.3.0',
@@ -43,25 +43,26 @@ buildscript {
4343
core: '1.3.2'
4444
],
4545
startup : '1.0.0',
46-
detekt : '1.15.0',
47-
aboutLibraries : '8.8.2',
46+
detekt : '1.16.0',
47+
aboutLibraries : '8.8.4',
4848
materialDrawer : '8.3.3',
49-
fastAdapter : '5.3.4',
49+
fastAdapter : '5.3.5',
5050
// compose
51-
compose : '1.0.0-beta01'
51+
compose : '1.0.0-beta03'
5252
]
5353
}
5454

5555
repositories {
5656
google()
57+
mavenCentral()
5758
jcenter()
5859
maven {
5960
url "https://plugins.gradle.org/m2/"
6061
}
6162
}
6263

6364
dependencies {
64-
classpath 'com.android.tools.build:gradle:7.0.0-alpha08'
65+
classpath 'com.android.tools.build:gradle:7.0.0-alpha12'
6566
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
6667
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:${versions.detekt}"
6768
classpath "com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin:${versions.aboutLibraries}"
@@ -73,6 +74,7 @@ allprojects {
7374

7475
repositories {
7576
google()
77+
mavenCentral()
7678
jcenter()
7779
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
7880
}
@@ -84,4 +86,4 @@ subprojects {
8486
dependencies {
8587
detektPlugins "io.gitlab.arturbosch.detekt:detekt-formatting:${versions.detekt}"
8688
}
87-
}
89+
}

iconics-core/src/main/java/com/mikepenz/iconics/Iconics.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ object Iconics {
5050

5151
@JvmField var logger: IconicsLogger = IconicsLogger.DEFAULT
5252

53+
/**
54+
* Set if Iconics should respect the original bounds of the icon.
55+
* This applies to all Drawables (including views) as a default value.
56+
*/
57+
@JvmField var respectFontBoundsDefault = false
58+
5359
/**
5460
* Initializes the `Context` required for different operations inside Iconics.
5561
*/
@@ -339,4 +345,4 @@ object Iconics {
339345
/** Defines where the icons should be applied to */
340346
fun on(on: Button): BuilderView = BuilderView(fonts, on, styles, stylesFor)
341347
}
342-
}
348+
}

iconics-core/src/main/java/com/mikepenz/iconics/IconicsDrawable.kt

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ open class IconicsDrawable internal constructor() : WrappedDrawable() {
210210
setBounds(0, 0, sizeXPx, sizeYPx)
211211
}
212212

213-
var respectFontBounds: Boolean = false
213+
var respectFontBounds: Boolean = Iconics.respectFontBoundsDefault
214214
set(value) {
215215
field = value
216216
invalidateThis()
@@ -403,8 +403,8 @@ open class IconicsDrawable internal constructor() : WrappedDrawable() {
403403
if (icon == null && iconText == null) return
404404
val viewBounds = bounds
405405
updatePaddingBounds(viewBounds)
406-
updateTextSize(viewBounds)
407-
offsetIcon(viewBounds)
406+
updatePathBounds(viewBounds)
407+
offsetIcon()
408408

409409
if (needMirroring()) {
410410
// Mirror the drawable
@@ -440,7 +440,9 @@ open class IconicsDrawable internal constructor() : WrappedDrawable() {
440440
}
441441

442442
override fun onBoundsChange(bounds: Rect) {
443-
offsetIcon(bounds)
443+
updatePaddingBounds(bounds)
444+
updatePathBounds(bounds)
445+
offsetIcon()
444446
runCatching { path.close() }
445447
super.onBoundsChange(bounds)
446448
}
@@ -519,34 +521,37 @@ open class IconicsDrawable internal constructor() : WrappedDrawable() {
519521
}
520522

521523
/** Update the TextSize */
522-
private fun updateTextSize(viewBounds: Rect) {
523-
var textSize = viewBounds.height().toFloat() * if (respectFontBounds) 1 else 2
524-
iconBrush.paint.textSize = textSize
525-
524+
private fun updatePathBounds(viewBounds: Rect) {
526525
val textValue = icon?.character?.toString() ?: iconText.toString()
527-
iconBrush.paint.getTextPath(textValue, 0, textValue.length, 0f, viewBounds.height().toFloat(), path)
526+
527+
var textSize = paddingBounds.height().toFloat()
528+
iconBrush.paint.textSize = textSize
529+
iconBrush.paint.getTextPath(textValue, 0, textValue.length, 0f, 0f, path)
528530
path.computeBounds(pathBounds, true)
529531

530-
if (!respectFontBounds) {
532+
if (respectFontBounds) {
533+
path.offset(viewBounds.exactCenterX(), paddingBounds.top + textSize - iconBrush.paint.fontMetrics.descent)
534+
} else {
531535
val deltaWidth = paddingBounds.width().toFloat() / pathBounds.width()
532536
val deltaHeight = paddingBounds.height().toFloat() / pathBounds.height()
533537
val delta = if (deltaWidth < deltaHeight) deltaWidth else deltaHeight
534538
textSize *= delta
535539
iconBrush.paint.textSize = textSize
536-
iconBrush.paint.getTextPath(textValue, 0, textValue.length, 0f, viewBounds.height().toFloat(), path)
540+
iconBrush.paint.getTextPath(textValue, 0, textValue.length, 0f, 0f, path)
537541
path.computeBounds(pathBounds, true)
542+
path.offset(paddingBounds.left - pathBounds.left, paddingBounds.top - pathBounds.top)
538543
}
539544
}
540545

541546
/** Set the icon offset */
542-
private fun offsetIcon(viewBounds: Rect) {
543-
val startX = viewBounds.centerX() - pathBounds.width() / 2
544-
val offsetX = startX - pathBounds.left
545-
546-
val startY = viewBounds.centerY() - pathBounds.height() / 2
547-
val offsetY = startY - pathBounds.top
548-
549-
path.offset(offsetX + iconOffsetXPx, offsetY + iconOffsetYPx)
547+
private fun offsetIcon() {
548+
if (respectFontBounds) {
549+
path.offset(iconOffsetXPx.toFloat(), iconOffsetYPx.toFloat())
550+
} else {
551+
val offsetX = (paddingBounds.width() - pathBounds.width()) / 2
552+
val offsetY = (paddingBounds.height() - pathBounds.height()) / 2
553+
path.offset(offsetX + iconOffsetXPx, offsetY + iconOffsetYPx)
554+
}
550555
}
551556

552557
/** Ensures the tint filter is consistent with the current tint color and mode. */
@@ -744,4 +749,4 @@ open class IconicsDrawable internal constructor() : WrappedDrawable() {
744749
invalidateSelf()
745750
return this
746751
}
747-
}
752+
}

0 commit comments

Comments
 (0)