From 9d9faf72eab2db4ed686836b73b47cee682cf15a Mon Sep 17 00:00:00 2001 From: Julien Guerinet Date: Mon, 23 Apr 2018 15:00:57 -0400 Subject: [PATCH] v2.4.1 Signed-off-by: Julien Guerinet --- CHANGELOG.md | 5 +++ gradle.properties | 2 +- .../suitcase/ui/extensions/TextViewExt.kt | 9 ++++ .../guerinet/suitcase/ui/extensions/View.kt | 42 +++++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 ui/src/main/java/com/guerinet/suitcase/ui/extensions/View.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fce7b6..297d6db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## Version 2.4.1 (2018-04-23) + * `ui`: + * Added extension to set a `View`'s padding with a dimension Id + * Added extension to set a `TextView`'s text size with a dimension Id + ## Version 2.4.0 (2018-04-14) * `io`: * Deprecated the `IOUtils`, replacing it with extensions diff --git a/gradle.properties b/gradle.properties index ddf9407..c2a48f8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -34,7 +34,7 @@ # org.gradle.parallel=true # Project properties -suitcase_version=2.4.0 +suitcase_version=2.4.1 group=com.guerinet # Android specific properties diff --git a/ui/src/main/java/com/guerinet/suitcase/ui/extensions/TextViewExt.kt b/ui/src/main/java/com/guerinet/suitcase/ui/extensions/TextViewExt.kt index 8f1f303..849b8ca 100644 --- a/ui/src/main/java/com/guerinet/suitcase/ui/extensions/TextViewExt.kt +++ b/ui/src/main/java/com/guerinet/suitcase/ui/extensions/TextViewExt.kt @@ -17,6 +17,8 @@ package com.guerinet.suitcase.ui.extensions import android.support.annotation.ColorInt +import android.support.annotation.DimenRes +import android.util.TypedValue import android.widget.TextView /** @@ -38,4 +40,11 @@ fun TextView.setDrawableTint(position: Int, @ColorInt color: Int) { // Set the drawables back setCompoundDrawablesRelativeWithIntrinsicBounds(drawables[0], drawables[1], drawables[2], drawables[3]) +} + +/** + * Changes the [TextView]'s text size by using the [textSizeId] + */ +fun TextView.setTextSizeId(@DimenRes textSizeId: Int) { + setTextSize(TypedValue.COMPLEX_UNIT_PX, context.resources.getDimension(textSizeId)) } \ No newline at end of file diff --git a/ui/src/main/java/com/guerinet/suitcase/ui/extensions/View.kt b/ui/src/main/java/com/guerinet/suitcase/ui/extensions/View.kt new file mode 100644 index 0000000..d564f33 --- /dev/null +++ b/ui/src/main/java/com/guerinet/suitcase/ui/extensions/View.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2016-2018 Julien Guerinet + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.guerinet.suitcase.ui.extensions + +import android.support.annotation.DimenRes +import android.view.View +import android.view.ViewGroup + +/** + * [View] extensions + * @author Julien Guerinet + * @since 2.4.1 + */ + +/** + * Quickly sets the [width] and [height] (warning: this creates new [ViewGroup.LayoutParams]) + */ +fun View.setWidthAndHeight(width: Int, height: Int) { + layoutParams = ViewGroup.LayoutParams(width, height) +} + +/** + * Sets the padding with [paddingId] on all 4 sides of the view + */ +fun View.setPaddingId(@DimenRes paddingId: Int) { + val padding = resources.getDimensionPixelOffset(paddingId) + setPadding(padding, padding, padding, padding) +} \ No newline at end of file