Skip to content

Commit b4bec18

Browse files
committed
RTL support
Highlight mode enum created Update kotlin stdlib
1 parent 3c1e423 commit b4bec18

File tree

8 files changed

+72
-6
lines changed

8 files changed

+72
-6
lines changed

app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ android {
2525
dependencies {
2626
implementation fileTree(dir: 'libs', include: ['*.jar'])
2727
implementation project(':bubbleshowcase')
28-
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
28+
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
29+
implementation 'com.android.support:design:27.1.1'
2930
implementation 'com.android.support:appcompat-v7:27.1.1'
3031
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
3132
testImplementation 'junit:junit:4.12'

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
android:roundIcon="@mipmap/ic_launcher_round"
1010
android:supportsRtl="true"
1111
android:theme="@style/AppTheme">
12-
<activity android:name=".MainActivity">
12+
<activity
13+
android:name=".MainActivity">
1314
<intent-filter>
1415
<action android:name="android.intent.action.MAIN" />
1516

app/src/main/java/com/elconfidencial/bubbleshowcase/MainActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class MainActivity : AppCompatActivity() {
5252
.image(ContextCompat.getDrawable(this, R.drawable.ic_format_size)!!)
5353
.titleTextSize(18)
5454
.descriptionTextSize(16)
55+
.closeActionImage(null)
5556
.targetView(buttonTextSizeShowCase)
5657
}
5758

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7+
78
tools:context="com.elconfidencial.bubbleshowcase.MainActivity">
89

910
<Button

bubbleshowcase/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ dokka {
3939

4040
dependencies {
4141
implementation fileTree(dir: 'libs', include: ['*.jar'])
42-
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
42+
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
4343
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
4444
implementation 'com.android.support:appcompat-v7:26.1.0'
4545
testImplementation 'junit:junit:4.12'

bubbleshowcase/src/main/java/com/elconfidencial/bubbleshowcase/BubbleMessageView.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ class BubbleMessageView : ConstraintLayout {
7979
imageViewClose?.visibility = View.VISIBLE
8080
imageViewClose?.setImageDrawable(builder.mCloseAction!!)
8181
}
82+
83+
if(builder.mDisableCloseAction!=null && builder.mDisableCloseAction!!){
84+
imageViewClose?.visibility = View.INVISIBLE
85+
}
86+
8287
builder.mTitle?.let {
8388
textViewTitle?.visibility = View.VISIBLE
8489
textViewTitle?.text = builder.mTitle
@@ -235,6 +240,7 @@ class BubbleMessageView : ConstraintLayout {
235240
lateinit var mContext: WeakReference<Context>
236241
var mTargetViewScreenLocation: RectF? = null
237242
var mImage: Drawable? = null
243+
var mDisableCloseAction: Boolean? = null
238244
var mTitle: String? = null
239245
var mSubtitle: String? = null
240246
var mCloseAction: Drawable? = null
@@ -270,6 +276,11 @@ class BubbleMessageView : ConstraintLayout {
270276
return this
271277
}
272278

279+
fun disableCloseAction(isDisabled: Boolean): Builder {
280+
mDisableCloseAction = isDisabled
281+
return this
282+
}
283+
273284
fun targetViewScreenLocation(targetViewLocationOnScreen: RectF): Builder{
274285
mTargetViewScreenLocation = targetViewLocationOnScreen
275286
return this

bubbleshowcase/src/main/java/com/elconfidencial/bubbleshowcase/BubbleShowCase.kt

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ class BubbleShowCase(builder: BubbleShowCaseBuilder){
4040
TOP, BOTTOM, LEFT, RIGHT
4141
}
4242

43+
/**
44+
* Highlight mode. It represents the way that the target view will be highlighted
45+
* - VIEW_LAYOUT: Default value. All the view box is highlighted (the rectangle where the view is contained). Example: For a TextView, all the element is highlighted (characters and background)
46+
* - VIEW_SURFACE: Only the view surface is highlighted, but not the background. Example: For a TextView, only the characters will be highlighted
47+
*/
48+
enum class HighlightMode {
49+
VIEW_LAYOUT, VIEW_SURFACE
50+
}
51+
52+
4353
private val mActivity: WeakReference<Activity> = builder.mActivity!!
4454

4555
//BubbleMessageView params
@@ -53,6 +63,8 @@ class BubbleShowCase(builder: BubbleShowCaseBuilder){
5363
private val mSubtitleTextSize: Int? = builder.mSubtitleTextSize
5464
private val mShowOnce: String? = builder.mShowOnce
5565
private val mDisableTargetClick: Boolean = builder.mDisableTargetClick
66+
private val mDisableCloseAction: Boolean = builder.mDisableCloseAction
67+
private val mHighlightMode: BubbleShowCase.HighlightMode? = builder.mHighlightMode
5668
private val mArrowPositionList: MutableList<ArrowPosition> = builder.mArrowPositionList
5769
private val mTargetView: WeakReference<View>? = builder.mTargetView
5870
private val mBubbleShowCaseListener: BubbleShowCaseListener? = builder.mBubbleShowCaseListener
@@ -153,6 +165,7 @@ class BubbleShowCase(builder: BubbleShowCaseBuilder){
153165
.subtitle(mSubtitle)
154166
.image(mImage)
155167
.closeActionImage(mCloseAction)
168+
.disableCloseAction(mDisableCloseAction)
156169
.listener(object : OnDismissBubbleMessageViewListener{
157170
override fun onDismiss() {
158171
dismiss()
@@ -188,7 +201,7 @@ class BubbleShowCase(builder: BubbleShowCaseBuilder){
188201
private fun addTargetViewAtForegroundLayout(targetView: View?, foregroundLayout: RelativeLayout?) {
189202
if(targetView==null) return
190203

191-
val targetScreenshot = takeScreenshot(targetView)
204+
val targetScreenshot = takeScreenshot(targetView, mHighlightMode)
192205
val targetScreenshotView = ImageView(mActivity.get()!!)
193206
targetScreenshotView.setImageBitmap(targetScreenshot)
194207
targetScreenshotView.setOnClickListener {
@@ -198,7 +211,7 @@ class BubbleShowCase(builder: BubbleShowCaseBuilder){
198211
}
199212

200213
val targetViewParams = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT)
201-
targetViewParams.setMargins(getXposition(targetView), getYposition(targetView), 0, 0)
214+
targetViewParams.setMargins(getXposition(targetView), getYposition(targetView), getScreenWidth(mActivity.get()!!) - (getXposition(targetView) + targetView.width), 0)
202215
foregroundLayout?.addView(AnimationUtils.setBouncingAnimation(targetScreenshotView, 0, DURATION_BEATING_ANIMATION), targetViewParams)
203216
}
204217

@@ -317,7 +330,13 @@ class BubbleShowCase(builder: BubbleShowCaseBuilder){
317330
}
318331
}
319332

320-
private fun takeScreenshot(targetView: View): Bitmap? {
333+
private fun takeScreenshot(targetView: View, highlightMode: HighlightMode?): Bitmap? {
334+
if (highlightMode==null || highlightMode == HighlightMode.VIEW_LAYOUT)
335+
return takeScreenshotOfLayoutView(targetView)
336+
return takeScreenshotOfSurfaceView(targetView)
337+
}
338+
339+
private fun takeScreenshotOfLayoutView(targetView: View): Bitmap? {
321340
if (targetView.width == 0 || targetView.height == 0) {
322341
return null
323342
}
@@ -332,6 +351,17 @@ class BubbleShowCase(builder: BubbleShowCaseBuilder){
332351
return bitmap
333352
}
334353

354+
private fun takeScreenshotOfSurfaceView(targetView: View): Bitmap? {
355+
if (targetView.width == 0 || targetView.height == 0) {
356+
return null
357+
}
358+
359+
targetView.isDrawingCacheEnabled = true
360+
val bitmap: Bitmap = Bitmap.createBitmap(targetView.drawingCache)
361+
targetView.isDrawingCacheEnabled = false
362+
return bitmap
363+
}
364+
335365
private fun getXposition(targetView: View): Int{
336366
return ScreenUtils.getAxisXpositionOfViewOnScreen(targetView) - getScreenHorizontalOffset()
337367
}

bubbleshowcase/src/main/java/com/elconfidencial/bubbleshowcase/BubbleShowCaseBuilder.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ class BubbleShowCaseBuilder{
2121
internal var mTextColor: Int? = null
2222
internal var mTitleTextSize: Int? = null
2323
internal var mSubtitleTextSize: Int? = null
24+
internal var mHighlightMode: BubbleShowCase.HighlightMode? = null
2425
internal var mDisableTargetClick: Boolean = false
26+
internal var mDisableCloseAction: Boolean = false
2527
internal var mShowOnce: String? = null
2628
internal var mIsFirstOfSequence: Boolean? = null
2729
internal var mIsLastOfSequence: Boolean? = null
@@ -136,6 +138,15 @@ class BubbleShowCaseBuilder{
136138
return this
137139
}
138140

141+
/**
142+
* If this variable is true, close action button will be gone
143+
* Default value -> false
144+
*/
145+
fun disableCloseAction(isDisabled: Boolean): BubbleShowCaseBuilder{
146+
mDisableCloseAction = isDisabled
147+
return this
148+
}
149+
139150
/**
140151
* Insert an arrowPosition to force the position of the BubbleShowCase.
141152
* - ArrowPosition enum values: LEFT, RIGHT, TOP and DOWN
@@ -158,6 +169,16 @@ class BubbleShowCaseBuilder{
158169
return this
159170
}
160171

172+
/**
173+
* Highlight mode. It represents the way that the target view will be highlighted
174+
* - VIEW_LAYOUT: Default value. All the view box is highlighted (the rectangle where the view is contained). Example: For a TextView, all the element is highlighted (characters and background)
175+
* - VIEW_SURFACE: Only the view surface is highlighted, but not the background. Example: For a TextView, only the characters will be highlighted
176+
*/
177+
fun highlightMode(highlightMode: BubbleShowCase.HighlightMode): BubbleShowCaseBuilder {
178+
mHighlightMode = highlightMode
179+
return this
180+
}
181+
161182
/**
162183
* Add a BubbleShowCaseListener in order to listen the user actions:
163184
* - onTargetClick -> It is triggered when the user clicks on the target view

0 commit comments

Comments
 (0)