diff --git a/app/src/main/java/devit951/github/magictipexample/MainActivity.kt b/app/src/main/java/devit951/github/magictipexample/MainActivity.kt index e89b306..c206def 100644 --- a/app/src/main/java/devit951/github/magictipexample/MainActivity.kt +++ b/app/src/main/java/devit951/github/magictipexample/MainActivity.kt @@ -1,18 +1,23 @@ package devit951.github.magictipexample +import android.annotation.TargetApi import android.graphics.Color +import android.graphics.Outline +import android.os.Build import android.os.Bundle +import android.view.View +import android.view.ViewOutlineProvider import androidx.appcompat.app.AppCompatActivity -import devit951.github.magictip.AutoCloseMagicTip +import devit951.github.magictip.tip.AutoCloseMagicTip import devit951.github.magictip.MagicTip -import devit951.github.magictip.OneMagicTip -import devit951.github.magictip.animationdelegate.AlphaMagicTipAnimation +import devit951.github.magictip.tip.OneMagicTip import devit951.github.magictip.animationdelegate.CombinedMagicTipAnimation import devit951.github.magictip.animationdelegate.ScaledTranslateMagicTipAnimation import kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivity() { + @TargetApi(Build.VERSION_CODES.LOLLIPOP) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) @@ -27,10 +32,12 @@ class MainActivity : AppCompatActivity() { imageView.setOnClickListener { OneMagicTip(it, MagicTip(it) .settings { - startAnimationDelegate = CombinedMagicTipAnimation(ScaledTranslateMagicTipAnimation()) + startAnimationDelegate = + CombinedMagicTipAnimation(ScaledTranslateMagicTipAnimation()) exitAnimationDelegate = ScaledTranslateMagicTipAnimation.Reversed() - text = "Lorem Posen" + text = "Lorem Posen" bgColor = Color.BLUE + }) .show() } diff --git a/magictip/src/main/java/devit951/github/magictip/CommonExtensions.kt b/magictip/src/main/java/devit951/github/magictip/CommonExtensions.kt index 4fe08ec..68d8e60 100644 --- a/magictip/src/main/java/devit951/github/magictip/CommonExtensions.kt +++ b/magictip/src/main/java/devit951/github/magictip/CommonExtensions.kt @@ -1,10 +1,12 @@ package devit951.github.magictip -import android.content.Context -import android.content.res.Resources -import android.content.ContextWrapper import android.app.Activity +import android.content.ContextWrapper +import android.content.res.Resources +import android.graphics.Color import android.view.View +import kotlin.math.min +import kotlin.math.roundToInt fun dp2Px(dp: Int): Int = (Resources.getSystem().displayMetrics.density * dp).toInt() @@ -18,4 +20,11 @@ fun View.activity(): Activity { context = context.baseContext } error("Activity could not find") -} \ No newline at end of file +} + +fun manipulateColor(color: Int, factor: Float) = Color.argb( + Color.alpha(color), + min((Color.red(color) * factor).roundToInt(), 255), + min((Color.green(color) * factor).roundToInt(), 255), + min((Color.blue(color) * factor).roundToInt(), 255) +) \ No newline at end of file diff --git a/magictip/src/main/java/devit951/github/magictip/MagicTipView.kt b/magictip/src/main/java/devit951/github/magictip/MagicTipView.kt index 6e97f2e..ae0dbb3 100644 --- a/magictip/src/main/java/devit951/github/magictip/MagicTipView.kt +++ b/magictip/src/main/java/devit951/github/magictip/MagicTipView.kt @@ -3,6 +3,7 @@ package devit951.github.magictip import android.content.Context import android.graphics.* import android.util.AttributeSet +import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.core.view.ViewCompat @@ -17,9 +18,9 @@ class MagicTipView @JvmOverloads constructor(context: Context, attrs: AttributeS private val trianglePath = Path() - private var magicTipPadding = dp2Px(4) + private var magicTipPadding = dp2Px(5) private var widthOfTriangle = dp2Px(14) - private var heightOfTriangle = dp2Px(10) + private var heightOfTriangle = dp2Px(12) internal var clickDelegate: MagicTipClickDelegate = ImmediatlyRemoveViewClickDelegate() @@ -28,6 +29,7 @@ class MagicTipView @JvmOverloads constructor(context: Context, attrs: AttributeS set(value) { field = value bgPaint.color = value + bgPaint.setShadowLayer(4f, 0.0f, 2.5f, manipulateColor(field, 0.8f)) } var startAnimationDelegate: MagicTipAnimationDelegate? = null @@ -46,6 +48,7 @@ class MagicTipView @JvmOverloads constructor(context: Context, attrs: AttributeS setMargins(margin, margin, margin, margin) } ViewCompat.setTranslationZ(this, Integer.MAX_VALUE.toFloat()) + setLayerType(View.LAYER_TYPE_SOFTWARE, bgPaint) } override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { @@ -73,7 +76,7 @@ class MagicTipView @JvmOverloads constructor(context: Context, attrs: AttributeS val halfTriangleWidth = widthOfTriangle / 2f val y = h.toFloat() - heightOfTriangle trianglePath.moveTo(halfWidth - halfTriangleWidth, y) - trianglePath.lineTo(halfWidth, h.toFloat()) + trianglePath.lineTo(halfWidth, h.toFloat() - 5) trianglePath.lineTo(halfWidth + halfTriangleWidth, y) } } \ No newline at end of file diff --git a/magictip/src/main/java/devit951/github/magictip/AutoCloseMagicTip.kt b/magictip/src/main/java/devit951/github/magictip/tip/AutoCloseMagicTip.kt similarity index 80% rename from magictip/src/main/java/devit951/github/magictip/AutoCloseMagicTip.kt rename to magictip/src/main/java/devit951/github/magictip/tip/AutoCloseMagicTip.kt index 62e6d42..d7d41ab 100644 --- a/magictip/src/main/java/devit951/github/magictip/AutoCloseMagicTip.kt +++ b/magictip/src/main/java/devit951/github/magictip/tip/AutoCloseMagicTip.kt @@ -1,7 +1,8 @@ -package devit951.github.magictip +package devit951.github.magictip.tip import android.os.Handler import android.view.View +import devit951.github.magictip.MagicTip class AutoCloseMagicTip(anchorView: View, private val delay: Long = 1_000): MagicTip(anchorView){ override fun show() { diff --git a/magictip/src/main/java/devit951/github/magictip/OneMagicTip.kt b/magictip/src/main/java/devit951/github/magictip/tip/OneMagicTip.kt similarity index 81% rename from magictip/src/main/java/devit951/github/magictip/OneMagicTip.kt rename to magictip/src/main/java/devit951/github/magictip/tip/OneMagicTip.kt index db60d5f..9efd7ff 100644 --- a/magictip/src/main/java/devit951/github/magictip/OneMagicTip.kt +++ b/magictip/src/main/java/devit951/github/magictip/tip/OneMagicTip.kt @@ -1,7 +1,9 @@ -package devit951.github.magictip +package devit951.github.magictip.tip import android.view.View import androidx.core.view.children +import devit951.github.magictip.MagicTip +import devit951.github.magictip.MagicTipView class OneMagicTip(anchorView: View, private val magicTip: MagicTip): MagicTip(anchorView) {