Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Gravity for Title and Message #48

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView.ScaleType;
Expand Down Expand Up @@ -120,6 +121,7 @@ private Flashbar messageAdvanced() {
.message("This is a very short message.")
.messageColor(ContextCompat.getColor(this, R.color.white))
.messageSizeInSp(24)
.messageGravity(Gravity.CENTER)
.messageTypeface(
Typeface.createFromAsset(getAssets(), "BeautifulAndOpenHearted.ttf"))
.build();
Expand Down
12 changes: 12 additions & 0 deletions flashbar/src/main/java/com/andrognito/flashbar/Flashbar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class Flashbar private constructor(private var builder: Builder) {
setTitleSizeInPx(builder.titleSizeInPx)
setTitleSizeInSp(builder.titleSizeInSp)
setTitleColor(builder.titleColor)
setTitleGravity(builder.titleGravity)
setTitleAppearance(builder.titleAppearance)

setMessage(builder.message)
Expand All @@ -107,6 +108,7 @@ class Flashbar private constructor(private var builder: Builder) {
setMessageSizeInPx(builder.messageSizeInPx)
setMessageSizeInSp(builder.messageSizeInSp)
setMessageColor(builder.messageColor)
setMessageGravity(builder.messageGravity)
setMessageAppearance(builder.messageAppearance)

setPrimaryActionText(builder.primaryActionText)
Expand Down Expand Up @@ -171,6 +173,7 @@ class Flashbar private constructor(private var builder: Builder) {
internal var titleSizeInPx: Float? = null
internal var titleSizeInSp: Float? = null
internal var titleColor: Int? = null
internal var titleGravity: Int? = null
internal var titleAppearance: Int? = null

internal var message: String? = null
Expand All @@ -179,6 +182,7 @@ class Flashbar private constructor(private var builder: Builder) {
internal var messageSizeInPx: Float? = null
internal var messageSizeInSp: Float? = null
internal var messageColor: Int? = null
internal var messageGravity: Int? = null
internal var messageAppearance: Int? = null

internal var primaryActionText: String? = null
Expand Down Expand Up @@ -397,6 +401,11 @@ class Flashbar private constructor(private var builder: Builder) {
*/
fun titleColor(@ColorInt color: Int) = apply { this.titleColor = color }

/**
* Specifies the title gravity
*/
fun titleGravity(gravity: Int) = apply { this.titleGravity = gravity }

/**
* Specifies the title color resource
*/
Expand Down Expand Up @@ -448,13 +457,16 @@ class Flashbar private constructor(private var builder: Builder) {
*/
fun messageColor(@ColorInt color: Int) = apply { this.messageColor = color }

fun messageGravity(gravity: Int) = apply { this.messageGravity = gravity }

/**
* Specifies the message color resource
*/
fun messageColorRes(@ColorRes colorId: Int) = apply {
this.messageColor = ContextCompat.getColor(activity, colorId)
}


/**
* Specifies the message appearance
*/
Expand Down
12 changes: 11 additions & 1 deletion flashbar/src/main/java/com/andrognito/flashbar/FlashbarView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ internal class FlashbarView(context: Context) : LinearLayout(context) {
if (color == null) return
fbTitle.setTextColor(color)
}

internal fun setTitleGravity(gravity: Int?) {
if (gravity == null) return
fbTitle.setGravity(gravity);
}

internal fun setTitleAppearance(titleAppearance: Int?) {
if (titleAppearance == null) return
Expand Down Expand Up @@ -214,6 +219,11 @@ internal class FlashbarView(context: Context) : LinearLayout(context) {
this.fbMessage.setTextColor(color)
}

internal fun setMessageGravity(gravity: Int?) {
if (gravity == null) return
this.fbMessage.setGravity(gravity);
}

internal fun setMessageAppearance(messageAppearance: Int?) {
if (messageAppearance == null) return

Expand Down Expand Up @@ -459,4 +469,4 @@ internal class FlashbarView(context: Context) : LinearLayout(context) {
shadow.applyShadow(shadowType)
addView(shadow, params)
}
}
}
6 changes: 3 additions & 3 deletions flashbar/src/main/res/layout/flash_bar_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

<TextView
android:id="@+id/fbTitle"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/fb_title_message_margin"
android:textAppearance="@style/FbTitleTextStyle"
Expand All @@ -62,7 +62,7 @@

<TextView
android:id="@+id/fbMessage"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/fb_title_message_margin"
android:justificationMode="inter_word"
Expand Down Expand Up @@ -129,4 +129,4 @@

</LinearLayout>

</LinearLayout>
</LinearLayout>