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 the ability to center text using android.view.Gravity. #219

Open
wants to merge 2 commits into
base: master
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
35 changes: 35 additions & 0 deletions app/src/main/java/me/toptas/fancyshowcasesample/SecondActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package me.toptas.fancyshowcasesample

import android.os.Bundle
import android.view.Gravity
import android.view.Menu
import android.view.MenuItem
import android.view.View
Expand Down Expand Up @@ -44,8 +45,42 @@ class SecondActivity : BaseActivity() {
toolbar.visibility = View.VISIBLE
}
}

btn_vcleft.setOnClickListener {
showShowCase(Gravity.LEFT)
}
btn_vcright.setOnClickListener {
showShowCase(Gravity.RIGHT)
}
btn_hctop.setOnClickListener {
showShowCase(Gravity.TOP or Gravity.CENTER_HORIZONTAL)
}
btn_hcbottom.setOnClickListener {
showShowCase(Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL)
}

btn_topleft.setOnClickListener {
showShowCase(Gravity.TOP or Gravity.LEFT)
}
btn_bottomright.setOnClickListener {
showShowCase(Gravity.BOTTOM or Gravity.RIGHT)
}
btn_topright.setOnClickListener {
showShowCase(Gravity.TOP or Gravity.RIGHT)
}
btn_bottomleft.setOnClickListener {
showShowCase(Gravity.BOTTOM or Gravity.LEFT)
}
}

private fun showShowCase(gravity: Int){
FancyShowCaseView.Builder(this)
.title("Long text, Long text, Long text, Long text, Long text, Long text, Long text")
.titleGravity(gravity)
.fitSystemWindows(true)
.build()
.show()
}

private fun focusOnButton() {
FancyShowCaseView.Builder(this@SecondActivity)
Expand Down
75 changes: 74 additions & 1 deletion app/src/main/res/layout/activity_second.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
tools:openDrawer="start">

<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"

android:layout_height="match_parent">
Expand Down Expand Up @@ -65,6 +64,80 @@
android:layout_height="wrap_content"
android:text="Toggle Toolbar" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center"
android:text="Title text Gravity"
android:textAllCaps="false"
android:textSize="24sp"
android:textStyle="bold" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="center"
android:orientation="horizontal">

<Button
android:id="@+id/btn_vcleft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="V.C. LEFT" />

<Button
android:id="@+id/btn_vcright"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="V.C. RIGHT" />

<Button
android:id="@+id/btn_hctop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="H.C. TOP" />

<Button
android:id="@+id/btn_hcbottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="H.C. BOTTOM" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="center"
android:orientation="horizontal">

<Button
android:id="@+id/btn_topleft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TOP LEFT" />

<Button
android:id="@+id/btn_bottomleft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BOT. LEFT" />

<Button
android:id="@+id/btn_topright"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TOP RIGHT" />

<Button
android:id="@+id/btn_bottomright"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BOT. RIGHT" />

</LinearLayout>

</LinearLayout>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,8 @@ import androidx.annotation.AttrRes
import androidx.annotation.LayoutRes
import androidx.annotation.RequiresApi
import androidx.annotation.StyleRes
import me.toptas.fancyshowcase.ext.AnimationEndListener
import me.toptas.fancyshowcase.ext.attachedShowCase
import me.toptas.fancyshowcase.ext.circularEnterAnimation
import me.toptas.fancyshowcase.ext.circularExitAnimation
import me.toptas.fancyshowcase.ext.globalLayoutListener
import me.toptas.fancyshowcase.ext.rootView
import me.toptas.fancyshowcase.internal.AndroidProperties
import me.toptas.fancyshowcase.internal.AnimationPresenter
import me.toptas.fancyshowcase.internal.DeviceParamsImpl
import me.toptas.fancyshowcase.internal.FadeOutAnimation
import me.toptas.fancyshowcase.internal.FancyImageView
import me.toptas.fancyshowcase.internal.FocusedView
import me.toptas.fancyshowcase.internal.Presenter
import me.toptas.fancyshowcase.internal.Properties
import me.toptas.fancyshowcase.internal.SharedPrefImpl
import me.toptas.fancyshowcase.internal.getStatusBarHeight
import me.toptas.fancyshowcase.ext.*
import me.toptas.fancyshowcase.internal.*
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if its a style thing but at my work we usually don't allow blanket * for the whole class. Not sure of this repos style guide

import me.toptas.fancyshowcase.listener.AnimationListener
import me.toptas.fancyshowcase.listener.DismissListener
import me.toptas.fancyshowcase.listener.OnQueueListener
Expand Down Expand Up @@ -172,11 +158,16 @@ class FancyShowCaseView @JvmOverloads constructor(context: Context, attrs: Attri
when {
props.enableTouchOnFocusedView && presenter.isWithinZone(event.x, event.y, props.focusedView!!) -> {
// Check if there is a clickable view within the focusable view
// Let the touch event pass through to clickable zone only if clicking within, otherwise return true to ignore event
// If there is no clickable view we let through the click to the focusable view
props.clickableView?.let {
return@OnTouchListener !presenter.isWithinZone(event.x, event.y, it)
} ?: return@OnTouchListener false
// Let the touch event pass through to clickable zone only if clicking within,
// otherwise return true to ignore event
val result = presenter.isWithinZone(event.x, event.y, it)
if(result)
hide()
return@OnTouchListener !result
} ?:
// If there is no clickable view we let through the click to the focusable view
return@OnTouchListener false
}
props.closeOnTouch -> hide()
}
Expand Down Expand Up @@ -245,7 +236,7 @@ class FancyShowCaseView @JvmOverloads constructor(context: Context, attrs: Attri
if (props.titleSize != -1) {
textView.setTextSize(props.titleSizeUnit, props.titleSize.toFloat())
}
textContainer.gravity = props.titleGravity
takeIf { props.titleGravity !=-1}?.let {textView.gravity = props.titleGravity}
if (props.fitSystemWindows) {
val params = textView.layoutParams as RelativeLayout.LayoutParams
params.setMargins(0, getStatusBarHeight(context), 0, 0)
Expand Down Expand Up @@ -363,7 +354,7 @@ class FancyShowCaseView @JvmOverloads constructor(context: Context, attrs: Attri

/**
* @param style title text style
* @param titleGravity title gravity
* @param titleGravity title align for text box
* @return Builder
*/
fun titleStyle(@StyleRes style: Int, titleGravity: Int) = apply {
Expand All @@ -372,20 +363,7 @@ class FancyShowCaseView @JvmOverloads constructor(context: Context, attrs: Attri
}

/**
* @param focusBorderColor Border color for focus shape
* @return Builder
*/
fun focusBorderColor(focusBorderColor: Int) = apply { props.focusBorderColor = focusBorderColor }

/**
* @param focusBorderSize Border size for focus shape
* @return Builder
*/
fun focusBorderSize(focusBorderSize: Int) = apply { props.focusBorderSize = focusBorderSize }


/**
* @param titleGravity title gravity
* @param titleGravity title gravity inside container
* @return Builder
*/
fun titleGravity(titleGravity: Int) = apply { props.titleGravity = titleGravity }
Expand All @@ -402,6 +380,18 @@ class FancyShowCaseView @JvmOverloads constructor(context: Context, attrs: Attri
props.titleSizeUnit = unit
}

/**
* @param focusBorderColor Border color for focus shape
* @return Builder
*/
fun focusBorderColor(focusBorderColor: Int) = apply { props.focusBorderColor = focusBorderColor }

/**
* @param focusBorderSize Border size for focus shape
* @return Builder
*/
fun focusBorderSize(focusBorderSize: Int) = apply { props.focusBorderSize = focusBorderSize }

/**
* @param id unique identifier for FancyShowCaseView
* @return Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

<TextView
android:id="@+id/fscv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="sans-serif-condensed"
android:gravity="center_vertical"
android:gravity="center"
android:padding="10dp"
android:textSize="24sp"
tools:text="Title" />
Expand Down