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

Separate the Target and realize the use of the square view on the basis of the circle #404

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
-Added to expand the shape of TargetIcon in the form of combination, …
…and now expand the rectangle
  • Loading branch information
huaweikai committed Aug 5, 2023
commit 6fa49cabcfca96b2f39dd7a363d409e56137c0d1
Binary file added .github/screenshot3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 26 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<h1 align="center">
<img src="/.github/video.gif" width="280" height="498" alt="Video 1"/>
<img src="/.github/screenshot1.png" width="280" height="498" alt="Screenshot 1"/>
<img src="/.github/screenshot2.png" width="280" height="498" alt="Screenshot 2"/><br/>
<img src="/.github/screenshot2.png" width="280" height="498" alt="Screenshot 2"/>
<img src="/.github/screenshot3.jpg" width="280" height="498" alt="Screenshot 2"/><br/>

TapTargetView
</h1>
Expand Down Expand Up @@ -37,33 +38,29 @@ For snapshots, please follow the instructions [here](https://jitpack.io/#KeepSaf

### Simple usage

```kotlin
Activity.showGuideView(
view.createTarget("Please Input Some Thing")
.outerCircleColor(R.color.colorAccent)
.targetIconColor(android.R.color.holo_blue_dark)
.transparentTarget(true)
.textColor(android.R.color.black)
.setTargetShapeType(TapTargetShapeType.RectAngle(16))
)
```

```java
TapTargetView.showFor(this, // `this` is an Activity
TapTarget.forView(findViewById(R.id.target), "This is a target", "We have the best targets, believe me")
// All options below are optional
.outerCircleColor(R.color.red) // Specify a color for the outer circle
.outerCircleAlpha(0.96f) // Specify the alpha amount for the outer circle
.targetCircleColor(R.color.white) // Specify a color for the target circle
.titleTextSize(20) // Specify the size (in sp) of the title text
.titleTextColor(R.color.white) // Specify the color of the title text
.descriptionTextSize(10) // Specify the size (in sp) of the description text
.descriptionTextColor(R.color.red) // Specify the color of the description text
.textColor(R.color.blue) // Specify a color for both the title and description text
.textTypeface(Typeface.SANS_SERIF) // Specify a typeface for the text
.dimColor(R.color.black) // If set, will dim behind the view with 30% opacity of the given color
.drawShadow(true) // Whether to draw a drop shadow or not
.cancelable(false) // Whether tapping outside the outer circle dismisses the view
.tintTarget(true) // Whether to tint the target view's color
.transparentTarget(false) // Specify whether the target is transparent (displays the content underneath)
.icon(Drawable) // Specify a custom drawable to draw as the target
.targetRadius(60), // Specify the target radius (in dp)
new TapTargetView.Listener() { // The listener can listen for regular clicks, long clicks or cancels
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view); // This call is optional
doSomething();
}
});
TargetViewExtensionsKTX.showGuideView(
Activity,
view.createTarget("Please Input Some Thing")
.outerCircleColor(R.color.colorAccent)
.targetIconColor(android.R.color.holo_blue_dark)
.transparentTarget(true)
.textColor(android.R.color.black)
.setTargetShapeType(TapTargetShapeType.RectAngle(16)),
null
);
}
```

You may also choose to target your own custom `Rect` with `TapTarget.forBounds(Rect, ...)`
Expand All @@ -76,9 +73,9 @@ Additionally, each color can be specified via a `@ColorRes` or a `@ColorInt`. Fu

You can easily create a sequence of tap targets with `TapTargetSequence`:

```java
```kotlin
new TapTargetSequence(this)
.targets(
.addTarget(
TapTarget.forView(findViewById(R.id.never), "Gonna"),
TapTarget.forView(findViewById(R.id.give), "You", "Up")
.dimColor(android.R.color.never)
Expand Down
113 changes: 70 additions & 43 deletions app/src/main/java/com/getkeepsafe/taptargetviewsample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@ import android.text.style.StyleSpan
import android.text.style.UnderlineSpan
import android.util.Log
import android.view.View
import android.widget.EditText
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat
import com.getkeepsafe.taptargetview.TapTarget
import com.getkeepsafe.taptargetview.target.TapTarget
import com.getkeepsafe.taptargetview.TapTargetSequence
import com.getkeepsafe.taptargetview.TapTargetView
import com.getkeepsafe.taptargetview.createNavigationIcon
import com.getkeepsafe.taptargetview.createOverflow
import com.getkeepsafe.taptargetview.createTarget
import com.getkeepsafe.taptargetview.forToolbarMenuItem
import com.getkeepsafe.taptargetview.showGuideView
import com.getkeepsafe.taptargetview.target.TapTargetShapeType

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -49,32 +55,29 @@ class MainActivity : AppCompatActivity() {
// We have a sequence of targets, so lets build it!
val sequence = TapTargetSequence(this)
.addTarget( // This tap target will target the back button, we just need to pass its containing toolbar
TapTarget.forToolbarNavigationIcon(toolbar, "This is the back button", sassyDesc)
toolbar.createNavigationIcon("This is the back button", sassyDesc)
.id(1), // Likewise, this tap target will target the search button
TapTarget.forToolbarMenuItem(
toolbar,
toolbar.forToolbarMenuItem(
R.id.search,
"This is a search icon",
"As you can see, it has gotten pretty dark around here..."
)
.dimColor(android.R.color.black)
.outerCircleColor(R.color.colorAccent)
.targetCircleColor(android.R.color.black)
.targetIconColor(android.R.color.black)
.transparentTarget(true)
.textColor(android.R.color.black)
.id(2), // You can also target the overflow button in your toolbar
TapTarget.forToolbarOverflow(
toolbar,
toolbar.createOverflow(
"This will show more options",
"But they're not useful :("
).id(3), // This tap target will target our droid buddy at the given target rect
TapTarget.forBounds(
droid.createTarget(
droidTarget,
"Oh look!",
"You can point to any part of the screen. You also can't cancel this one!"
)
.cancelable(false)
.icon(droid)
.id(4)
)
.listener(object : TapTargetSequence.Listener {
Expand All @@ -94,18 +97,18 @@ class MainActivity : AppCompatActivity() {
.setTitle("Uh oh")
.setMessage("You canceled the sequence")
.setPositiveButton("Oops", null).show()
dialog.showGuideView(TapTarget.forView(
dialog.getButton(DialogInterface.BUTTON_POSITIVE),
"Uh oh!",
"You canceled the sequence at step " + lastTarget?.id()
)
.cancelable(false)
.tintTarget(false), object : TapTargetView.Listener() {
override fun onTargetClick(view: TapTargetView) {
super.onTargetClick(view)
dialog.dismiss()
}
})
dialog.showGuideView(
dialog.getButton(DialogInterface.BUTTON_POSITIVE).createTarget(
"Uh oh!",
"You canceled the sequence at step " + lastTarget?.id()
)
.cancelable(false)
.tintTarget(false), object : TapTargetView.Listener() {
override fun onTargetClick(view: TapTargetView) {
super.onTargetClick(view)
dialog.dismiss()
}
})
}
})

Expand All @@ -117,29 +120,53 @@ class MainActivity : AppCompatActivity() {
spannedDesc.length,
0
)
this.showGuideView(TapTarget.forView(findViewById(R.id.fab), "Hello, world!", spannedDesc)
.cancelable(false)
.drawShadow(true)
.titleTextDimen(R.dimen.title_text_size)
.tintTarget(false), object : TapTargetView.Listener() {
override fun onTargetClick(view: TapTargetView) {
super.onTargetClick(view)
// .. which evidently starts the sequence we defined earlier
sequence.start()
}
this.showGuideView(
findViewById<View>(R.id.fab).createTarget("Hello, world!", spannedDesc)
.cancelable(false)
.drawShadow(true)
.titleTextDimen(R.dimen.title_text_size)
.tintTarget(false), object : TapTargetView.Listener() {
override fun onTargetClick(view: TapTargetView) {
super.onTargetClick(view)
// .. which evidently starts the sequence we defined earlier
sequence.start()
}

override fun onOuterCircleClick(view: TapTargetView) {
super.onOuterCircleClick(view)
Toast.makeText(
view.context,
"You clicked the outer circle!",
Toast.LENGTH_SHORT
).show()
}

override fun onOuterCircleClick(view: TapTargetView) {
super.onOuterCircleClick(view)
Toast.makeText(
view.context,
"You clicked the outer circle!",
Toast.LENGTH_SHORT
).show()
}
override fun onTargetDismissed(view: TapTargetView, userInitiated: Boolean) {
Log.d("TapTargetViewSample", "You dismissed me :(")
}
})

override fun onTargetDismissed(view: TapTargetView, userInitiated: Boolean) {
Log.d("TapTargetViewSample", "You dismissed me :(")
}
})
val ed = findViewById<EditText>(R.id.ed)
ed.setOnClickListener {
showGuideView(
ed.createTarget("Please Input Some Thing")
.outerCircleColor(R.color.colorAccent)
.targetIconColor(android.R.color.holo_blue_dark)
.transparentTarget(true)
.textColor(android.R.color.black)
.setTargetShapeType(TapTargetShapeType.RectAngle(16)),
object : TapTargetView.Listener() {
override fun onTargetClick(view: TapTargetView) {
Toast.makeText(
view.context,
"You clicked the target!",
Toast.LENGTH_SHORT
).show()
super.onTargetClick(view)
}
}
)
}
}

}
10 changes: 10 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,14 @@
android:layout_height="wrap_content"
android:padding="16dp"/>

<EditText
android:id="@+id/ed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="32dp"
android:padding="16dp"
android:background="@color/colorPrimary"
style="@style/ThemeOverlay.Material3.TextInputEditText"
android:hint="Please input some thing"/>

</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package com.getkeepsafe.taptargetview
import android.app.Activity
import android.app.Dialog
import androidx.annotation.UiThread
import com.getkeepsafe.taptargetview.target.TapTarget
import java.util.LinkedList
import java.util.Queue

Expand Down
Loading