Skip to content

Commit

Permalink
Merge pull request #27 from erkutaras/develop
Browse files Browse the repository at this point in the history
release v1.4.0
  • Loading branch information
erkutaras authored May 31, 2020
2 parents f69ba90 + 9888149 commit 571f4d1
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 238 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ allprojects {
**Step 2.** Add the library dependency to your project build.gradle:
```
dependencies {
implementation 'com.github.erkutaras:ShowcaseView:1.3.7'
implementation 'com.github.erkutaras:ShowcaseView:1.4.0'
}
```

Expand Down Expand Up @@ -103,7 +103,7 @@ Patches and new features are encouraged, and may be submitted by [forking this p

# License

Copyright 2018-2019 erkutaras
Copyright 2018-2020 erkutaras

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.61'
ext.kotlin_version = '1.3.72'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:4.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Sep 29 23:26:14 MSK 2019
#Sun May 31 15:15:33 MSK 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
13 changes: 9 additions & 4 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.github.dcendents.android-maven'

group='com.erkutaras.showcaseview'

android {
compileSdkVersion 28
compileSdkVersion 29

defaultConfig {
targetSdkVersion 28
targetSdkVersion 29
minSdkVersion 14
versionCode 20
versionName "1.3.8"
versionCode 21
versionName "1.4.0"
}

buildTypes {
Expand All @@ -26,6 +27,10 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}

androidExtensions {
features = ["parcelize"]
}

}

dependencies {
Expand Down
78 changes: 59 additions & 19 deletions library/src/main/java/com/erkutaras/showcaseview/ShowcaseManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import android.app.Activity
import android.content.Context
import android.content.Intent
import android.graphics.Rect
import android.os.Build
import android.os.Parcelable
import androidx.appcompat.app.AppCompatActivity
import android.util.Log
import android.view.View
import android.view.Window
import androidx.annotation.RequiresApi

import java.util.ArrayList
import kotlin.math.pow
import kotlin.math.sqrt

/**
* Created by erkut.aras on 23.02.2018.
Expand Down Expand Up @@ -96,6 +99,8 @@ class ShowcaseManager private constructor(private val builder: Builder) {
private var colorFocusArea: Int = 0
internal var isDevelopMode: Boolean = false
private var marginFocusArea: Int = 0
private var type: ShowcaseType = ShowcaseType.CIRCLE
private var gradientFocusEnabled: Boolean = false

init {
showcaseModelList = ArrayList()
Expand Down Expand Up @@ -181,6 +186,27 @@ class ShowcaseManager private constructor(private val builder: Builder) {
return this
}

fun circle(): Builder {
this.type = ShowcaseType.CIRCLE
return this
}

fun rectangle(): Builder {
this.type = ShowcaseType.RECTANGLE
return this
}

@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
fun roundedRectangle(): Builder {
this.type = ShowcaseType.ROUND_RECTANGLE
return this
}

fun gradientFocusEnabled(enabled: Boolean): Builder {
this.gradientFocusEnabled = enabled
return this
}

fun add(): Builder {
this.showcaseModelList.add(createShowcaseModel())
return this
Expand All @@ -199,23 +225,27 @@ class ShowcaseManager private constructor(private val builder: Builder) {
val circleCenterX = getCircleCenterX(viewPositionRect).toFloat()
val circleCenterY = getCircleCenterY(viewPositionRect)
val circleCenterRadius = calculateRadius(marginFocusArea)

return ShowcaseModel.Builder()
.descriptionImageRes(descriptionImageRes)
.descriptionTitle(descriptionTitle)
.descriptionText(descriptionText)
.buttonText(buttonText)
.colorDescTitle(colorDescTitle)
.colorDescText(colorDescText)
.colorButtonText(colorButtonText)
.colorButtonBackground(colorButtonBackground)
.colorBackground(colorBackground)
.alphaBackground(alphaBackground)
.colorFocusArea(colorFocusArea)
.cxFocusArea(circleCenterX)
.cyFocusArea(circleCenterY)
.radiusFocusArea(circleCenterRadius)
.build()
val rect = calculateRect(marginFocusArea, viewPositionRect)

return ShowcaseModel(
descriptionImageRes = descriptionImageRes,
descriptionTitle = descriptionTitle,
descriptionText = descriptionText,
buttonText = buttonText,
colorDescTitle = colorDescTitle,
colorDescText = colorDescText,
colorButtonText = colorButtonText,
colorButtonBackground = colorButtonBackground,
colorBackground = colorBackground,
alphaBackground = alphaBackground,
colorFocusArea = colorFocusArea,
cxFocusArea = circleCenterX,
cyFocusArea = circleCenterY,
radiusFocusArea = circleCenterRadius,
rect = rect,
type = type,
gradientFocusEnabled = gradientFocusEnabled
)

}

Expand All @@ -233,9 +263,19 @@ class ShowcaseManager private constructor(private val builder: Builder) {
private fun calculateRadius(marginFocusArea: Int): Float {
val x = (view.width / 2).toFloat()
val y = (view.height / 2).toFloat()
val radius = Math.sqrt(Math.pow(x.toDouble(), 2.0) + Math.pow(y.toDouble(), 2.0)).toFloat()
val radius = sqrt(x.toDouble().pow(2.0) + y.toDouble().pow(2.0)).toFloat()
return radius + ShowcaseUtils.convertDpToPx(marginFocusArea.toFloat())
}

private fun calculateRect(marginFocusArea: Int, viewPositionRect: Rect): Rect {
val margin = ShowcaseUtils.convertDpToPx(marginFocusArea.toFloat())
return Rect(
(viewPositionRect.left - margin).toInt(),
(viewPositionRect.top - margin).toInt(),
(viewPositionRect.right + margin).toInt(),
(viewPositionRect.bottom + margin).toInt()
)
}
}

companion object {
Expand Down
Loading

0 comments on commit 571f4d1

Please sign in to comment.