├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── README_pushing_to_maven.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── tourguide
│ │ └── tourguidedemo
│ │ ├── ApplicationTest.kt
│ │ ├── BasicActivityCrashTest.kt
│ │ └── ToolTilMeasureTest.kt
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── tourguide
│ │ ├── instrumentation
│ │ └── test
│ │ │ └── ToolTipMeasureTestActivity.kt
│ │ └── tourguidedemo
│ │ ├── AdjustPaddingOverlayActivity.kt
│ │ ├── BasicActivity.kt
│ │ ├── ManualSequenceActivity.kt
│ │ ├── MemoryLeakTestActivity.kt
│ │ ├── MultipleToolTipActivity.kt
│ │ ├── MyApplication.kt
│ │ ├── NavDrawerActivity.kt
│ │ ├── NoOverlayActivity.kt
│ │ ├── NoPointerActivity.kt
│ │ ├── NoPointerNoToolTipActivity.kt
│ │ ├── OverlayCustomizationActivity.kt
│ │ ├── RecyclerViewActivity.kt
│ │ ├── RoundedRectangleOverlayActivity.kt
│ │ ├── ToolTipCustomizationActivity.kt
│ │ ├── ToolTipGravityActivity.kt
│ │ ├── ToolbarActivity.kt
│ │ ├── main
│ │ ├── MainActivity.kt
│ │ └── MainAdapter.kt
│ │ └── recyclerview
│ │ └── RecyclerViewAdapter.kt
│ └── res
│ ├── drawable-hdpi
│ └── tour_guide_icon.png
│ ├── drawable-mdpi
│ └── tour_guide_icon.png
│ ├── drawable-xhdpi
│ └── tour_guide_icon.png
│ ├── drawable-xxhdpi
│ └── tour_guide_icon.png
│ ├── drawable
│ └── toolbar_drop_shadow.xml
│ ├── layout
│ ├── activity_basic.xml
│ ├── activity_customization.xml
│ ├── activity_in_sequence.xml
│ ├── activity_multiple_tooltip.xml
│ ├── activity_nav_drawer.xml
│ ├── activity_overlay_customization.xml
│ ├── activity_recycler_view.xml
│ ├── activity_toolbar.xml
│ ├── activity_tooltip_gravity_i.xml
│ ├── activity_tooltip_gravity_ii.xml
│ ├── activity_tooltip_gravity_iii.xml
│ ├── activity_tooltip_gravity_iv.xml
│ ├── activity_tour_guide_demo_main.xml
│ ├── nav_drawer_header.xml
│ ├── row.xml
│ ├── row_recycler_view.xml
│ └── sequence_dialog.xml
│ ├── menu
│ └── menu_demo_main.xml
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ ├── styles.xml
│ └── themes.xml
├── build.gradle
├── gradle-mvn-push.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
├── tourguide
├── .gitignore
├── build.gradle
├── gradle.properties
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── tourguide
│ │ └── tourguide
│ │ └── ApplicationTest.kt
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── tourguide
│ │ └── tourguide
│ │ ├── FrameLayoutWithHole.kt
│ │ ├── Overlay.kt
│ │ ├── Pointer.kt
│ │ ├── ToolTip.kt
│ │ ├── TourGuide.kt
│ │ └── util
│ │ ├── MotionEventExtension.kt
│ │ ├── StandardExtension.kt
│ │ └── ViewExtension.kt
│ └── res
│ ├── drawable-xhdpi
│ └── tourguide_drop_shadow.9.png
│ ├── drawable
│ └── tourguide_shadow_upward.xml
│ ├── layout
│ └── tourguide_tooltip.xml
│ └── values
│ └── colors.xml
└── update_version.rb
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 | .idea/
8 | *.iml
9 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 | jdk: oraclejdk8
3 | env:
4 | matrix:
5 | - ANDROID_API=26 ANDROID_ABI=armeabi-v7a
6 | android:
7 | components:
8 | # Uncomment the lines below if you want to
9 | # use the latest revision of Android SDK Tools
10 | - tools
11 | - platform-tools
12 | - tools
13 |
14 | # The BuildTools version used by your project
15 | - build-tools-26.0.2
16 |
17 | # The SDK version used to compile your project
18 | - android-26
19 | - android-22
20 | - extra-android-support
21 | - extra-android-m2repository
22 | # Additional components
23 | #- extra-google-google_play_services
24 | #- extra-google-m2repository
25 | #- extra-android-m2repository
26 | #- addon-google_apis-google-19
27 |
28 | # Specify at least one system image,
29 | # if you need to run emulator(s) during your tests
30 | - sys-img-armeabi-v7a-android-22
31 | #- sys-img-x86-android-17
32 | licenses:
33 | - 'android-sdk-preview-license-.+'
34 | - 'android-sdk-license-.+'
35 | - 'google-gdk-license-.+'
36 | before_script:
37 | # Create and start emulator
38 | - echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a
39 | - emulator -avd test -no-skin -no-audio -no-window &
40 | - android-wait-for-emulator
41 | - adb shell input keyevent 82 &
42 |
43 | script: ./gradlew build connectedCheck
44 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) [2015] [Tan Jun Rong]
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |   
2 |
3 | # TourGuide
4 | TourGuide is an Android library. It lets you add pointer, overlay and tooltip easily, guiding users on how to use your app. Refer to the example below(this is a trivial example for demo purpose):
5 |
6 | # Documentation
7 | Refer to this :point_down:
8 |
9 | http://worker8.github.io/TourGuide/
10 |
11 | # License
12 |
13 |
14 | click to reveal License
15 |
16 |
17 | The MIT License (MIT)
18 |
19 | Copyright (c) 2016 Tan Jun Rong
20 |
21 | Permission is hereby granted, free of charge, to any person obtaining a copy
22 | of this software and associated documentation files (the "Software"), to deal
23 | in the Software without restriction, including without limitation the rights
24 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25 | copies of the Software, and to permit persons to whom the Software is
26 | furnished to do so, subject to the following conditions:
27 |
28 | The above copyright notice and this permission notice shall be included in all
29 | copies or substantial portions of the Software.
30 |
31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37 | SOFTWARE.
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/README_pushing_to_maven.md:
--------------------------------------------------------------------------------
1 | update versions
2 |
3 | 1. run `ruby update_version.rb`
4 | - this will increase the versionName & versionCode in gradle.properties
5 | 2. update gh-pages branch install guide version
6 |
7 | 4. git push origin master
8 | 5. ./gradlew clean build uploadArchives
9 | 6. update git tag, convention: git tag -a v1.0.11 -m "VERSION_CODE=12, VERSION_NAME=1.0.11-SNAPSHOT"
10 | 7. git push --tags
11 |
12 | reference:
13 | https://github.com/chrisbanes/gradle-mvn-push
14 |
15 | update playstore steps:
16 | 1. ./production.sh
17 | 2. upload apk
18 | 3. update commit hash in playstore readme
19 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | repositories {
6 | mavenCentral()
7 | maven() {
8 | url "https://oss.sonatype.org/content/repositories/snapshots"
9 | }
10 | }
11 |
12 | Properties getGradleProperties() {
13 | def gradlePropsFile = file('../gradle.properties')
14 | def Properties gradleProps = new Properties()
15 | if (gradlePropsFile.canRead()) {
16 | gradleProps.load(new FileInputStream(gradlePropsFile))
17 | println gradleProps['VERSION_CODE']
18 | println gradleProps['VERSION_NAME']
19 | } else {
20 | throw new GradleException("Could not read gradle.properties!")
21 | }
22 | gradleProps;
23 | }
24 |
25 | android {
26 | compileSdkVersion compileSdkVersionNum
27 | buildToolsVersion buildToolVersionNum
28 | def gradleProps = getGradleProperties()
29 | defaultConfig {
30 | applicationId "tourguide.tourguide"
31 | minSdkVersion minSdkVersionNum
32 | targetSdkVersion targetSdkVersionNum
33 | versionCode gradleProps['VERSION_CODE'].toInteger()
34 | versionName gradleProps['VERSION_NAME']
35 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
36 | }
37 |
38 | buildTypes {
39 | release {
40 | minifyEnabled false
41 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
42 | }
43 | }
44 | lintOptions {
45 | abortOnError false
46 | }
47 | packagingOptions {
48 | exclude 'LICENSE.txt'
49 | }
50 | }
51 |
52 | task sourcesJar(type: Jar) {
53 | from android.sourceSets.main.java.srcDirs
54 | classifier = 'sources'
55 | }
56 |
57 | artifacts {
58 | archives sourcesJar
59 | }
60 |
61 | dependencies {
62 | implementation fileTree(dir: 'libs', include: ['*.jar'])
63 | implementation "com.android.support:appcompat-v7:$supportVersion"
64 | implementation "com.android.support:design:$supportVersion"
65 | implementation project(':tourguide')
66 |
67 | /* this is for debugging memory leak: https://github.com/square/leakcanary */
68 | debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.3.1'
69 | releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
70 |
71 | androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1') {
72 | exclude group: 'com.android.support', module: 'support-annotations'
73 | }
74 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
75 |
76 |
77 | }
78 |
79 | task print_git_tag_command << {
80 | def gradleProps = getGradleProperties()
81 | println "git tag -a v" + gradleProps['VERSION_NAME'] + " -m \"VERSION_CODE=" + gradleProps['VERSION_CODE'] + ", VERSION_NAME=" + gradleProps['VERSION_NAME'] + "\""
82 | println "git push --tags"
83 | }
84 |
85 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/tanjunrong/adt-bundle-mac-x86_64-20140702/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/tourguide/tourguidedemo/ApplicationTest.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguidedemo
2 |
3 | import android.app.Application
4 | import android.test.ApplicationTestCase
5 |
6 | /**
7 | * [Testing Fundamentals](http://d.android.com/tools/testing/testing_android.html)
8 | */
9 | class ApplicationTest : ApplicationTestCase(Application::class.java)
--------------------------------------------------------------------------------
/app/src/androidTest/java/tourguide/tourguidedemo/BasicActivityCrashTest.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguidedemo
2 |
3 | import android.support.test.espresso.Espresso.onView
4 | import android.support.test.espresso.action.ViewActions.click
5 | import android.support.test.espresso.matcher.ViewMatchers.withId
6 | import android.support.test.rule.ActivityTestRule
7 | import org.hamcrest.Matchers.allOf
8 | import org.junit.Assert
9 | import org.junit.Rule
10 | import org.junit.Test
11 |
12 | class BasicActivityCrashTest {
13 | @Rule @JvmField
14 | var rule: ActivityTestRule = ActivityTestRule(BasicActivity::class.java)
15 |
16 | @Test
17 | fun testNoCrash() {
18 | onView(allOf(withId(R.id.button1))).perform(click())
19 | Assert.assertTrue("There is no crash :)", true)
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/tourguide/tourguidedemo/ToolTilMeasureTest.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguidedemo
2 |
3 | import android.app.Activity
4 | import android.graphics.Point
5 | import android.test.ActivityInstrumentationTestCase2
6 | import android.view.View
7 | import org.junit.Assert
8 | import tourguide.instrumentation.test.ToolTipMeasureTestActivity
9 |
10 | class ToolTilMeasureTest : ActivityInstrumentationTestCase2(ToolTipMeasureTestActivity::class.java) {
11 | private var mActivity: ToolTipMeasureTestActivity? = null
12 | private var mToolTip: View? = null
13 |
14 | @Throws(Exception::class)
15 | override fun setUp() {
16 | super.setUp()
17 |
18 | // Starts the activity under test using the default Intent with:
19 | // action = {@link Intent#ACTION_MAIN}
20 | // flags = {@link Intent#FLAG_ACTIVITY_NEW_TASK}
21 | // All other fields are null or empty.
22 | mActivity = activity
23 | mToolTip = mActivity!!.tourGuide.toolTipView
24 | }
25 |
26 | fun testNoCrash() {
27 | val isOutOfLeftBound = mToolTip!!.x < 0
28 | val isOutOfRightBound = mToolTip!!.x + mToolTip!!.width > getScreenWidth(mActivity!!)
29 | Assert.assertFalse("x of ToolTip is out of screen boundary", isOutOfLeftBound || isOutOfRightBound)
30 |
31 | val isOutOfTopBound = mToolTip!!.y < 0
32 | val isOutOfBottomBound = mToolTip!!.y + mToolTip!!.height > getScreenHeight(mActivity!!)
33 | Assert.assertFalse("y of ToolTip is out of screen boundary", isOutOfTopBound || isOutOfBottomBound)
34 | }
35 |
36 | private fun getScreenWidth(activity: Activity): Int {
37 | val display = activity.windowManager.defaultDisplay
38 | val size = Point()
39 | display.getSize(size)
40 | return size.x
41 | }
42 |
43 | private fun getScreenHeight(activity: Activity): Int {
44 | val display = activity.windowManager.defaultDisplay
45 | val size = Point()
46 | display.getSize(size)
47 | return size.y
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
15 |
18 |
21 |
24 |
27 |
30 |
33 |
36 |
39 |
42 |
45 |
49 |
52 |
55 |
59 |
62 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
78 |
79 |
80 |
81 |
82 |
--------------------------------------------------------------------------------
/app/src/main/java/tourguide/instrumentation/test/ToolTipMeasureTestActivity.kt:
--------------------------------------------------------------------------------
1 | package tourguide.instrumentation.test
2 |
3 | import android.graphics.Color
4 | import android.os.Bundle
5 | import android.support.v7.app.AppCompatActivity
6 | import android.view.Gravity
7 | import kotlinx.android.synthetic.main.activity_tooltip_gravity_i.*
8 | import tourguide.tourguide.Overlay
9 | import tourguide.tourguide.Pointer
10 | import tourguide.tourguide.TourGuide
11 | import tourguide.tourguidedemo.R
12 |
13 |
14 | class ToolTipMeasureTestActivity : AppCompatActivity() {
15 | lateinit var tourGuide: TourGuide
16 |
17 | override fun onCreate(savedInstanceState: Bundle?) {
18 | /* Get parameters from main activity */
19 | val intent = intent
20 | val tooltipNumber = intent.getIntExtra(TOOLTIP_NUM, 1)
21 |
22 | super.onCreate(savedInstanceState)
23 | val gravity = when (tooltipNumber) {
24 | 1 -> {
25 | setContentView(R.layout.activity_tooltip_gravity_i)
26 | Gravity.RIGHT or Gravity.BOTTOM
27 | }
28 | 2 -> {
29 | setContentView(R.layout.activity_tooltip_gravity_ii)
30 | Gravity.LEFT or Gravity.BOTTOM
31 | }
32 | 3 -> {
33 | setContentView(R.layout.activity_tooltip_gravity_iii)
34 | Gravity.LEFT or Gravity.TOP
35 | }
36 | else -> {
37 | setContentView(R.layout.activity_tooltip_gravity_iv)
38 | Gravity.RIGHT or Gravity.TOP
39 | }
40 | }
41 |
42 | tourGuide = TourGuide.create(this) {
43 | pointer { Pointer() }
44 | overlay { Overlay() }
45 | toolTip {
46 | title { "Welcome!" }
47 | description { "This is a really really long title....This is a really really long title....This is a really really long title....This is a really really long title....This is a really really long title....This is a really really long title....This is a really really long title...." }
48 | backgroundColor { Color.parseColor("#2980b9") }
49 | textColor { Color.parseColor("#FFFFFF") }
50 | gravity { gravity }
51 | shadow { true }
52 | }
53 | }.playOn(button)
54 |
55 | button.setOnClickListener { tourGuide.cleanUp() }
56 | }
57 |
58 | companion object {
59 | const val TOOLTIP_NUM = "tooltip_num"
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/app/src/main/java/tourguide/tourguidedemo/AdjustPaddingOverlayActivity.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguidedemo
2 |
3 | import android.graphics.Color
4 | import android.os.Bundle
5 | import android.support.v7.app.AppCompatActivity
6 | import android.text.Editable
7 | import android.text.TextUtils
8 | import android.text.TextWatcher
9 | import android.view.View
10 | import kotlinx.android.synthetic.main.activity_overlay_customization.*
11 | import tourguide.tourguide.Overlay
12 | import tourguide.tourguide.TourGuide
13 |
14 |
15 | class AdjustPaddingOverlayActivity : AppCompatActivity() {
16 | lateinit var tourGuide: TourGuide
17 | override fun onCreate(savedInstanceState: Bundle?) {
18 | super.onCreate(savedInstanceState)
19 | setContentView(R.layout.activity_overlay_customization)
20 | tourGuide = TourGuide
21 | .create(this) {
22 | toolTip {
23 | title { "Hello!" }
24 | description { String.format("Current OVERLAY Padding: %s", paddingEditText.text.toString()) }
25 | }
26 | overlay {
27 | disableClick { false }
28 | disableClickThroughHole { false }
29 | style { Overlay.Style.ROUNDED_RECTANGLE }
30 | holePadding { Integer.valueOf(paddingEditText.text.toString()) }
31 | backgroundColor { Color.parseColor("#AAFF0000") }
32 | onClickListener { View.OnClickListener { tourGuide.cleanUp() } }
33 | }
34 | }
35 | .apply { playOn(button) }
36 |
37 | paddingEditText.setText(10.toString())
38 | textInputLayout.visibility = View.VISIBLE
39 |
40 | nextButton.visibility = View.GONE
41 |
42 | button.setOnClickListener {
43 | tourGuide.cleanUp()
44 | tourGuide.playOn(button)
45 | }
46 | button.text = " show "
47 |
48 | paddingEditText.addTextChangedListener(object : TextWatcher {
49 | override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {
50 |
51 | }
52 |
53 | override fun onTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {
54 | tourGuide.overlay?.setHolePadding(if (charSequence.length > 0 && TextUtils.isDigitsOnly(charSequence)) Integer.valueOf(charSequence.toString()) else 10)
55 | tourGuide.toolTip?.setDescription(String.format("Current Overlay Padding: %s", charSequence))
56 | }
57 |
58 | override fun afterTextChanged(editable: Editable) {
59 | }
60 | })
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/app/src/main/java/tourguide/tourguidedemo/BasicActivity.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguidedemo
2 |
3 | import android.graphics.Color
4 | import android.os.Bundle
5 | import android.support.v7.app.AppCompatActivity
6 | import android.view.Gravity
7 | import kotlinx.android.synthetic.main.activity_basic.*
8 | import tourguide.tourguide.TourGuide
9 |
10 | class BasicActivity : AppCompatActivity() {
11 | override fun onCreate(savedInstanceState: Bundle?) {
12 | /* Get parameters from main activity */
13 | val colorDemo = intent.getBooleanExtra(COLOR_DEMO, false)
14 | val gravityDemo = intent.getBooleanExtra(GRAVITY_DEMO, false)
15 |
16 | super.onCreate(savedInstanceState)
17 | setContentView(R.layout.activity_basic)
18 |
19 | // the return handler is used to manipulate the cleanup of all the tutorial elements
20 | val tourGuide = TourGuide.create(this) {
21 | technique = TourGuide.Technique.CLICK
22 | pointer {
23 | color {
24 | if (colorDemo) {
25 | Color.RED
26 | } else {
27 | Color.WHITE
28 | }
29 | }
30 | gravity {
31 | if (gravityDemo) {
32 | Gravity.BOTTOM or Gravity.RIGHT
33 | } else {
34 | Gravity.CENTER
35 | }
36 | }
37 | }
38 | toolTip {
39 | title { "Welcome!" }
40 | description { "Click on Get Started to begin..." }
41 | }
42 | overlay {
43 | backgroundColor { Color.parseColor("#66FF0000") }
44 | }
45 | }
46 | val handler = tourGuide playOn button1
47 |
48 | button1.setOnClickListener { handler.cleanUp() }
49 | button2.setOnClickListener { handler.playOn(button1) }
50 | }
51 |
52 | companion object {
53 | const val COLOR_DEMO = "color_demo"
54 | const val GRAVITY_DEMO = "gravity_demo"
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/java/tourguide/tourguidedemo/ManualSequenceActivity.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguidedemo
2 |
3 | import android.os.Bundle
4 | import android.support.v7.app.AppCompatActivity
5 | import android.view.Gravity
6 | import android.view.animation.AlphaAnimation
7 | import kotlinx.android.synthetic.main.activity_in_sequence.*
8 | import tourguide.tourguide.Pointer
9 | import tourguide.tourguide.TourGuide
10 |
11 | /**
12 | * InSequenceActivity demonstrates how to use TourGuide in sequence one after another
13 | */
14 | class ManualSequenceActivity : AppCompatActivity() {
15 | lateinit var tourGuide: TourGuide
16 |
17 | override fun onCreate(savedInstanceState: Bundle?) {
18 | super.onCreate(savedInstanceState)
19 | setContentView(R.layout.activity_in_sequence)
20 |
21 | /* setup enter and exit animation */
22 | val enterAnimation = AlphaAnimation(0f, 1f)
23 | .apply {
24 | duration = 600
25 | fillAfter = true
26 | }
27 |
28 |
29 | val exitAnimation = AlphaAnimation(1f, 0f)
30 | .apply {
31 | duration = 600
32 | fillAfter = true
33 | }
34 |
35 | /* initialize TourGuide without playOn() */
36 | tourGuide = TourGuide.create(this) {
37 | pointer { Pointer() }
38 | toolTip {
39 | title { "Hey!" }
40 | description { "I'm the top fellow" }
41 | gravity { Gravity.RIGHT }
42 | }
43 | overlay {
44 | setEnterAnimation(enterAnimation)
45 | setExitAnimation(exitAnimation)
46 | }
47 | }
48 |
49 | /* setup 1st button, when clicked, cleanUp() and re-run TourGuide on button2 */
50 | button.setOnClickListener {
51 | tourGuide.apply {
52 | cleanUp()
53 | toolTip {
54 | title { "Hey there!" }
55 | description { "Just the middle man" }
56 | gravity { Gravity.BOTTOM or Gravity.LEFT }
57 | }
58 | }.playOn(button2)
59 | }
60 |
61 | /* setup 2nd button, when clicked, cleanUp() and re-run TourGuide on button3 */
62 | button2.setOnClickListener {
63 | tourGuide.apply {
64 | cleanUp()
65 | toolTip {
66 | title { "Hey..." }
67 | description { "It's time to say goodbye" }
68 | gravity { Gravity.TOP or Gravity.RIGHT }
69 | }
70 | }.playOn(button3)
71 | }
72 |
73 | /* setup 3rd button, when clicked, run cleanUp() */
74 | button3.setOnClickListener { tourGuide.cleanUp() }
75 |
76 | tourGuide.playOn(button)
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/app/src/main/java/tourguide/tourguidedemo/MemoryLeakTestActivity.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguidedemo
2 |
3 | import android.os.Bundle
4 | import android.support.v7.app.AppCompatActivity
5 | import kotlinx.android.synthetic.main.activity_basic.*
6 | import tourguide.tourguide.Overlay
7 | import tourguide.tourguide.Pointer
8 | import tourguide.tourguide.TourGuide
9 |
10 | /**
11 | * This activity is used for testing memory, it serves no demo purpose, hence it's not listed in TourGuideDemoMain activity (it's commented out)
12 | * To test this:
13 | * 1. uncomment MemoryLeakTestActivity in TourGuideDemoMain.java
14 | * 2. Then launch MemoryLeakTestActivity and click back, launch MemoryLeakTestActivity and click back, repeat many times
15 | * 3. Then look at the memory usage, also check if LeakCanary freezes the screen and log a memory heap dump
16 | * 4. To force a memory leak, comment 'onDetachedFromWindow()' method in FrameLayoutWithHole
17 | * TODO: this should be included as a test, rather than being a commented activity
18 | */
19 | class MemoryLeakTestActivity : AppCompatActivity() {
20 | lateinit var tourGuide: TourGuide
21 | override fun onCreate(savedInstanceState: Bundle?) {
22 | super.onCreate(savedInstanceState)
23 | setContentView(R.layout.activity_basic)
24 |
25 | tourGuide = TourGuide.create(this) {
26 | pointer { Pointer() }
27 | overlay { Overlay() }
28 | toolTip {
29 | title { "Hey!" }
30 | description { "Let's hope that there's no memory leak..." }
31 | }
32 | }.playOn(button1)
33 |
34 | button1.setOnClickListener { tourGuide.cleanUp() }
35 | }
36 |
37 | public override fun onDestroy() {
38 | super.onDestroy()
39 | MyApplication.getRefWatcher(this)?.also { _refWatcher ->
40 | _refWatcher.watch(this)
41 | _refWatcher.watch(tourGuide)
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/tourguide/tourguidedemo/MultipleToolTipActivity.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguidedemo
2 |
3 | import android.os.Bundle
4 | import android.support.v7.app.AppCompatActivity
5 | import android.view.Gravity
6 | import kotlinx.android.synthetic.main.activity_multiple_tooltip.*
7 | import tourguide.tourguide.Pointer
8 | import tourguide.tourguide.TourGuide
9 |
10 | /**
11 | * Note that currently multiple Overlay doesn't work well, but multiple ToolTip is working fine
12 | * Therefore, if you want to use multiple ToolTip, please switch off the Overlay by .setOverlay(null)
13 | */
14 | class MultipleToolTipActivity : AppCompatActivity() {
15 |
16 | override fun onCreate(savedInstanceState: Bundle?) {
17 | super.onCreate(savedInstanceState)
18 |
19 | setContentView(R.layout.activity_multiple_tooltip)
20 |
21 | // the return handler is used to manipulate the cleanup of all the tutorial elements
22 | val tourGuide = TourGuide.create(this) {
23 | pointer { Pointer() }
24 | toolTip {
25 | title { "Hey!" }
26 | description { "I'm the top guy" }
27 | gravity { Gravity.RIGHT }
28 | }
29 | }.playOn(button)
30 |
31 | val tourGuide2 = TourGuide.create(this) {
32 | pointer { Pointer() }
33 | toolTip {
34 | title { "Hey!" }
35 | description { "I'm the bottom guy" }
36 | gravity { Gravity.TOP or Gravity.LEFT }
37 | }
38 | }.playOn(button2)
39 |
40 | button.setOnClickListener { tourGuide.cleanUp() }
41 | button2.setOnClickListener { tourGuide2.cleanUp() }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/tourguide/tourguidedemo/MyApplication.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguidedemo
2 |
3 | import android.app.Application
4 | import android.content.Context
5 |
6 | import com.squareup.leakcanary.LeakCanary
7 | import com.squareup.leakcanary.RefWatcher
8 |
9 | class MyApplication : Application() {
10 | private var _refWatcher: RefWatcher? = null
11 |
12 | override fun onCreate() {
13 | super.onCreate()
14 | /* This is for checking memory leak: https://github.com/square/leakcanary */
15 | _refWatcher = LeakCanary.install(this)
16 | }
17 |
18 | companion object {
19 |
20 | fun getRefWatcher(context: Context): RefWatcher? {
21 | val application = context.applicationContext as MyApplication
22 | return application._refWatcher
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/tourguide/tourguidedemo/NavDrawerActivity.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguidedemo
2 |
3 | import android.graphics.Color
4 | import android.os.Bundle
5 | import android.support.v7.app.ActionBarDrawerToggle
6 | import android.support.v7.app.AppCompatActivity
7 | import android.view.Gravity
8 | import android.view.View
9 | import android.view.ViewTreeObserver
10 | import kotlinx.android.synthetic.main.activity_nav_drawer.*
11 | import tourguide.tourguide.TourGuide
12 |
13 | class NavDrawerActivity : AppCompatActivity() {
14 |
15 | override fun onCreate(savedInstanceState: Bundle?) {
16 | super.onCreate(savedInstanceState)
17 | setContentView(R.layout.activity_nav_drawer)
18 |
19 | /* setup toolbar */
20 | setSupportActionBar(toolbar.apply { title = "Nav Drawer Example" })
21 | supportActionBar?.apply {
22 | setDisplayHomeAsUpEnabled(true)
23 | setHomeButtonEnabled(true)
24 | setDisplayShowTitleEnabled(false)
25 | }
26 |
27 | val tourGuide = TourGuide.create(this) {
28 | pointer { }
29 | overlay { backgroundColor { Color.parseColor("#66FF0000") } }
30 | toolTip {
31 | title { "" }
32 | description { "hello world" }
33 | }
34 | }
35 |
36 | val drawerToggle = object : ActionBarDrawerToggle(
37 | this, drawerLayout, toolbar, R.string.drawer_open_string, R.string.drawer_close_string) {
38 | override fun onDrawerOpened(drawerView: View?) {
39 | super.onDrawerOpened(drawerView)
40 | /* We need call playOn only after the drawer is opened,
41 | so that TourGuide knows the updated location of the targetted view */
42 | tourGuide.playOn(textView1)
43 | }
44 | }
45 | drawerLayout.setDrawerListener(drawerToggle)
46 | drawerToggle.syncState()
47 |
48 | /* setup clean up code */
49 | textView1.setOnClickListener {
50 | tourGuide.cleanUp()
51 | drawerLayout.closeDrawers()
52 | }
53 |
54 | textView1.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
55 | override fun onGlobalLayout() {
56 | textView1.viewTreeObserver.removeGlobalOnLayoutListener(this)// make sure this only run once
57 | drawerLayout.openDrawer(Gravity.LEFT)
58 | }
59 | })
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/app/src/main/java/tourguide/tourguidedemo/NoOverlayActivity.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguidedemo
2 |
3 | import android.os.Bundle
4 | import android.support.v7.app.AppCompatActivity
5 | import kotlinx.android.synthetic.main.activity_basic.*
6 | import tourguide.tourguide.Pointer
7 | import tourguide.tourguide.ToolTip
8 | import tourguide.tourguide.TourGuide
9 |
10 |
11 | class NoOverlayActivity : AppCompatActivity() {
12 |
13 | override fun onCreate(savedInstanceState: Bundle?) {
14 | super.onCreate(savedInstanceState)
15 | setContentView(R.layout.activity_basic)
16 |
17 | val tourGuide = TourGuide.init(this).with(TourGuide.Technique.CLICK)
18 | .setPointer(Pointer()) // set pointer to null
19 | .setToolTip(ToolTip().setTitle("Welcome :)").setDescription("Have a nice and fun day!"))
20 | .playOn(button1)
21 |
22 | button1.setOnClickListener { tourGuide.cleanUp() }
23 | button2.setOnClickListener { tourGuide.playOn(button1) }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/tourguide/tourguidedemo/NoPointerActivity.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguidedemo
2 |
3 | import android.os.Bundle
4 | import android.support.v7.app.AppCompatActivity
5 | import android.view.View
6 | import kotlinx.android.synthetic.main.activity_basic.*
7 | import tourguide.tourguide.TourGuide
8 |
9 |
10 | class NoPointerActivity : AppCompatActivity() {
11 | lateinit var tourGuide: TourGuide
12 | override fun onCreate(savedInstanceState: Bundle?) {
13 | /* Get parameters from main activity */
14 | super.onCreate(savedInstanceState)
15 | setContentView(R.layout.activity_basic)
16 |
17 | button1.text = "Purchase"
18 |
19 | tourGuide = TourGuide.create(this) {
20 | toolTip {
21 | title { "Expensive Item" }
22 | description { "Click 'purchase' only when you are ready\nClick on the anywhere to dismiss" }
23 | }
24 | overlay {
25 | disableClickThroughHole { true }
26 | onClickListener { View.OnClickListener { tourGuide.cleanUp() } }
27 | }
28 | }.playOn(button1)
29 |
30 | button2.setOnClickListener { tourGuide.playOn(button1) }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/tourguide/tourguidedemo/NoPointerNoToolTipActivity.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguidedemo
2 |
3 | import android.os.Bundle
4 | import android.support.v7.app.AppCompatActivity
5 | import kotlinx.android.synthetic.main.activity_basic.*
6 | import tourguide.tourguide.TourGuide
7 |
8 |
9 | class NoPointerNoToolTipActivity : AppCompatActivity() {
10 |
11 | override fun onCreate(savedInstanceState: Bundle?) {
12 | super.onCreate(savedInstanceState)
13 | setContentView(R.layout.activity_basic)
14 | val tourGuide = TourGuide.create(this) {
15 | overlay {}
16 | }.playOn(button1)
17 |
18 | button1.setOnClickListener { tourGuide.cleanUp() }
19 | button2.setOnClickListener { tourGuide.playOn(button1) }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/tourguide/tourguidedemo/OverlayCustomizationActivity.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguidedemo
2 |
3 | import android.graphics.Color
4 | import android.os.Bundle
5 | import android.support.v7.app.AppCompatActivity
6 | import android.view.View
7 | import android.widget.Toast
8 | import kotlinx.android.synthetic.main.activity_overlay_customization.*
9 | import tourguide.tourguide.Overlay
10 | import tourguide.tourguide.TourGuide
11 |
12 |
13 | class OverlayCustomizationActivity : AppCompatActivity() {
14 | lateinit var tourGuide: TourGuide
15 | override fun onCreate(savedInstanceState: Bundle?) {
16 | super.onCreate(savedInstanceState)
17 | setContentView(R.layout.activity_overlay_customization)
18 |
19 | // the return handler is used to manipulate the cleanup of all the tutorial elements
20 | tourGuide = TourGuide.create(this) {
21 | pointer {}
22 | toolTip {
23 | title { "Hello!" }
24 | description { "Click to view tutorial. Next button is disabled until tutorial is viewed" }
25 | }
26 | overlay {
27 | disableClick { false }
28 | disableClickThroughHole { false }
29 | style { Overlay.Style.RECTANGLE }
30 | backgroundColor { Color.parseColor("#AAFF0000") }
31 | onClickListener { View.OnClickListener { tourGuide.cleanUp() } }
32 | }
33 | }.playOn(button)
34 |
35 | nextButton.setOnClickListener { Toast.makeText(this, "BOOM!", Toast.LENGTH_LONG).show() }
36 | button.setOnClickListener { tourGuide.cleanUp() }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/tourguide/tourguidedemo/RecyclerViewActivity.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguidedemo
2 |
3 | import android.graphics.Color
4 | import android.os.Bundle
5 | import android.support.v7.app.AppCompatActivity
6 | import android.support.v7.widget.DividerItemDecoration
7 | import android.support.v7.widget.LinearLayoutManager
8 | import android.view.View
9 | import kotlinx.android.synthetic.main.activity_recycler_view.*
10 | import tourguide.tourguide.TourGuide
11 | import tourguide.tourguidedemo.recyclerview.RecyclerViewAdapter
12 |
13 | class RecyclerViewActivity : AppCompatActivity() {
14 | private val linearLayoutManager = LinearLayoutManager(this)
15 |
16 | private val tourGuide = TourGuide.create(this) {
17 | overlay {
18 | backgroundColor = Color.parseColor("#66FF0000")
19 | }
20 | }
21 |
22 | private val launchTourGuide = { view: View ->
23 | tourGuide.playOn(view)
24 | Unit
25 | }
26 | val dismissTourGuide = {
27 | tourGuide.cleanUp()
28 | Unit
29 | }
30 |
31 | override fun onCreate(savedInstanceState: Bundle?) {
32 | super.onCreate(savedInstanceState)
33 | setContentView(R.layout.activity_recycler_view)
34 |
35 | recyclerView.apply {
36 | adapter = RecyclerViewAdapter(launchTourGuide, dismissTourGuide)
37 | addItemDecoration(DividerItemDecoration(context, DividerItemDecoration.VERTICAL))
38 | layoutManager = linearLayoutManager
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/app/src/main/java/tourguide/tourguidedemo/RoundedRectangleOverlayActivity.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguidedemo
2 |
3 | import android.graphics.Color
4 | import android.os.Bundle
5 | import android.support.v7.app.AppCompatActivity
6 | import android.view.View
7 | import android.widget.Toast
8 | import kotlinx.android.synthetic.main.activity_overlay_customization.*
9 | import tourguide.tourguide.Overlay
10 | import tourguide.tourguide.TourGuide
11 |
12 |
13 | class RoundedRectangleOverlayActivity : AppCompatActivity() {
14 | lateinit var tourGuide: TourGuide
15 | override fun onCreate(savedInstanceState: Bundle?) {
16 | super.onCreate(savedInstanceState)
17 | setContentView(R.layout.activity_overlay_customization)
18 | tourGuide = TourGuide.create(this) {
19 | toolTip {
20 | title { "Hello!" }
21 | description { "Click to view tutorial. Next button is disabled until tutorial is viewed" }
22 | }
23 | overlay {
24 | disableClick { false }
25 | disableClickThroughHole { false }
26 | style { Overlay.Style.ROUNDED_RECTANGLE }
27 | roundedCornerRadius { 8 }
28 | onClickListener { View.OnClickListener { tourGuide.cleanUp() } }
29 | backgroundColor { Color.parseColor("#AAFF0000") }
30 | }
31 | pointer {}
32 | }.playOn(button)
33 | nextButton.setOnClickListener { Toast.makeText(this, "BOOM!", Toast.LENGTH_LONG).show() }
34 |
35 | button.setOnClickListener { tourGuide.cleanUp() }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/tourguide/tourguidedemo/ToolTipCustomizationActivity.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguidedemo
2 |
3 | import android.graphics.Color
4 | import android.os.Bundle
5 | import android.support.v7.app.AppCompatActivity
6 | import android.view.Gravity
7 | import android.view.animation.BounceInterpolator
8 | import android.view.animation.TranslateAnimation
9 | import kotlinx.android.synthetic.main.activity_customization.*
10 | import tourguide.tourguide.TourGuide
11 |
12 |
13 | class ToolTipCustomizationActivity : AppCompatActivity() {
14 |
15 | override fun onCreate(savedInstanceState: Bundle?) {
16 | super.onCreate(savedInstanceState)
17 | setContentView(R.layout.activity_customization)
18 |
19 | val tourGuide = TourGuide.create(this) {
20 | toolTip {
21 | title { "Next Button" }
22 | description { "Click on Next button to proceed..." }
23 | textColor { Color.parseColor("#bdc3c7") }
24 | backgroundColor { Color.parseColor("#e74c3c") }
25 | shadow { true }
26 | gravity { Gravity.TOP or Gravity.LEFT }
27 | enterAnimation {
28 | TranslateAnimation(0f, 0f, 200f, 0f).apply {
29 | duration = 1000
30 | fillAfter = true
31 | interpolator = BounceInterpolator()
32 | }
33 | }
34 | }
35 | }.playOn(button)
36 |
37 | button.setOnClickListener { tourGuide.cleanUp() }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/tourguide/tourguidedemo/ToolTipGravityActivity.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguidedemo
2 |
3 | import android.graphics.Color
4 | import android.os.Bundle
5 | import android.support.v7.app.AppCompatActivity
6 | import android.view.Gravity
7 | import kotlinx.android.synthetic.main.activity_tooltip_gravity_i.*
8 | import tourguide.tourguide.TourGuide
9 |
10 |
11 | class ToolTipGravityActivity : AppCompatActivity() {
12 |
13 | override fun onCreate(savedInstanceState: Bundle?) {
14 | /* Get parameters from main activity */
15 | val tooltipNum = intent.getIntExtra(TOOLTIP_NUM, 1)
16 |
17 | super.onCreate(savedInstanceState)
18 |
19 | val gravity = when (tooltipNum) {
20 | 1 -> {
21 | setContentView(R.layout.activity_tooltip_gravity_i)
22 | Gravity.RIGHT or Gravity.BOTTOM
23 | }
24 | 2 -> {
25 | setContentView(R.layout.activity_tooltip_gravity_ii)
26 | Gravity.LEFT or Gravity.BOTTOM
27 | }
28 | 3 -> {
29 | setContentView(R.layout.activity_tooltip_gravity_iii)
30 | Gravity.LEFT or Gravity.TOP
31 | }
32 | else -> {
33 | setContentView(R.layout.activity_tooltip_gravity_iv)
34 | Gravity.RIGHT or Gravity.TOP
35 | }
36 | }
37 |
38 | val tourGuide =
39 | TourGuide.create(this) {
40 | toolTip {
41 | title { "Welcome!" }
42 | description { "Click on Get Started to begin..." }
43 | backgroundColor { Color.parseColor("#2980b9") }
44 | textColor { Color.parseColor("#FFFFFF") }
45 | gravity { gravity }
46 | shadow { true }
47 | }
48 | pointer {}
49 | overlay {}
50 | }.playOn(button)
51 |
52 | button.setOnClickListener { tourGuide.cleanUp() }
53 |
54 | }
55 |
56 | companion object {
57 | val TOOLTIP_NUM = "tooltip_num"
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/java/tourguide/tourguidedemo/ToolbarActivity.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguidedemo
2 |
3 | import android.os.Bundle
4 | import android.support.v7.app.AppCompatActivity
5 | import android.view.Gravity
6 | import android.view.Menu
7 | import android.view.Window
8 | import android.view.WindowManager
9 | import android.widget.ImageView
10 | import kotlinx.android.synthetic.main.activity_toolbar.*
11 | import tourguide.tourguide.Overlay
12 | import tourguide.tourguide.Pointer
13 | import tourguide.tourguide.ToolTip
14 | import tourguide.tourguide.TourGuide
15 |
16 |
17 | class ToolbarActivity : AppCompatActivity() {
18 |
19 | private val hasStatusBar
20 | get() = intent.getBooleanExtra(STATUS_BAR, false)
21 |
22 | override fun onCreate(savedInstanceState: Bundle?) {
23 | /* Get parameters from main activity */
24 | if (!hasStatusBar) {
25 | requestWindowFeature(Window.FEATURE_NO_TITLE)
26 | window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
27 | }
28 |
29 | super.onCreate(savedInstanceState)
30 |
31 | setContentView(R.layout.activity_toolbar)
32 | setSupportActionBar(toolbar)
33 | }
34 |
35 | override fun onCreateOptionsMenu(menu: Menu): Boolean {
36 | // Inflate the menu
37 | menuInflater.inflate(R.menu.menu_demo_main, menu)
38 |
39 | // We need to get the menu item as a View in order to work with TourGuide
40 | val menuItem = menu.getItem(0)
41 | val button = menuItem.actionView as ImageView
42 |
43 | // just adding some padding to look better
44 | val density = resources.displayMetrics.density
45 | val padding = (5 * density).toInt()
46 | button.setPadding(padding, padding, padding, padding)
47 |
48 | // set an image
49 | button.setImageDrawable(resources.getDrawable(android.R.drawable.ic_dialog_email))
50 |
51 | val toolTip = ToolTip()
52 | .setTitle("Welcome!")
53 | .setDescription("Click on Get Started to begin...")
54 | .setGravity(Gravity.LEFT or Gravity.BOTTOM)
55 |
56 | val tourGuide = TourGuide.init(this).with(TourGuide.Technique.CLICK)
57 | .motionType(TourGuide.MotionType.CLICK_ONLY)
58 | .setPointer(Pointer())
59 | .setToolTip(toolTip)
60 | .apply {
61 | overlay { Overlay() }
62 | }.playOn(button)
63 | button.setOnClickListener { tourGuide.cleanUp() }
64 |
65 | return true
66 | }
67 |
68 | companion object {
69 | val STATUS_BAR = "status_bar"
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/app/src/main/java/tourguide/tourguidedemo/main/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguidedemo.main
2 |
3 | import android.os.Bundle
4 | import android.support.v7.app.AppCompatActivity
5 | import kotlinx.android.synthetic.main.activity_tour_guide_demo_main.*
6 |
7 | import tourguide.tourguidedemo.R
8 |
9 | class MainActivity : AppCompatActivity() {
10 | override fun onCreate(savedInstanceState: Bundle?) {
11 | super.onCreate(savedInstanceState)
12 | setContentView(R.layout.activity_tour_guide_demo_main)
13 | mainRecyclerView.adapter = RecyclerViewAdapter()
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/java/tourguide/tourguidedemo/main/MainAdapter.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguidedemo.main
2 |
3 | import android.content.Intent
4 | import android.support.v4.content.ContextCompat
5 | import android.support.v7.app.AlertDialog
6 | import android.support.v7.widget.RecyclerView
7 | import android.view.LayoutInflater
8 | import android.view.View
9 | import android.view.ViewGroup
10 | import kotlinx.android.synthetic.main.row.view.*
11 | import tourguide.tourguidedemo.*
12 |
13 | class RecyclerViewAdapter : RecyclerView.Adapter() {
14 | private val numOfRow = 20
15 | private fun View.startActivity(intent: Intent) = ContextCompat.startActivity(context, intent, null)
16 |
17 | override fun onBindViewHolder(viewHolder: RecyclerView.ViewHolder, position: Int) {
18 | viewHolder.itemView.apply {
19 | decorateBackground(this, position)
20 |
21 | when (position) {
22 | 0 -> {
23 | textView.text = "Basic Activity"
24 | setOnClickListener {
25 | startActivity(Intent(context, BasicActivity::class.java))
26 | }
27 | }
28 | 1 -> {
29 | textView.text = "Pointer: color"
30 | setOnClickListener {
31 | startActivity(Intent(context, BasicActivity::class.java).apply {
32 | putExtra(BasicActivity.COLOR_DEMO, true)
33 | })
34 | }
35 | }
36 | 2 -> {
37 | textView.text = "Pointer: gravity"
38 | setOnClickListener {
39 | startActivity(Intent(context, BasicActivity::class.java).apply {
40 | putExtra(BasicActivity.GRAVITY_DEMO, true)
41 | })
42 | }
43 | }
44 | 3 -> {
45 | textView.text = "Toolbar Example"
46 | setOnClickListener {
47 | startActivity(Intent(context, ToolbarActivity::class.java).apply {
48 | putExtra(ToolbarActivity.STATUS_BAR, true)
49 | })
50 | }
51 | }
52 | 4 -> {
53 | textView.text = "Toolbar Example\n(no status bar)"
54 | setOnClickListener {
55 | startActivity(Intent(context, ToolbarActivity::class.java).apply {
56 | putExtra(ToolbarActivity.STATUS_BAR, false)
57 | })
58 | }
59 | }
60 | 5 -> {
61 | textView.text = "ToolTip Gravity I"
62 | setOnClickListener {
63 | startActivity(Intent(context, ToolTipGravityActivity::class.java).apply {
64 | putExtra(ToolTipGravityActivity.TOOLTIP_NUM, 1)
65 | })
66 | }
67 | }
68 | 6 -> {
69 | textView.text = "ToolTip Gravity II"
70 | setOnClickListener {
71 |
72 |
73 | startActivity(Intent(context, ToolTipGravityActivity::class.java).apply {
74 | putExtra(ToolTipGravityActivity.TOOLTIP_NUM, 2)
75 |
76 | })
77 | }
78 | }
79 | 7 -> {
80 | textView.text = "ToolTip Gravity III"
81 | setOnClickListener {
82 | startActivity(Intent(context, ToolTipGravityActivity::class.java).apply {
83 | putExtra(ToolTipGravityActivity.TOOLTIP_NUM, 3)
84 | })
85 | }
86 | }
87 | 8 -> {
88 | textView.text = "ToolTip Gravity IV"
89 | setOnClickListener {
90 |
91 | startActivity(Intent(context, ToolTipGravityActivity::class.java).apply {
92 | putExtra(ToolTipGravityActivity.TOOLTIP_NUM, 4)
93 | })
94 | }
95 | }
96 | 9 -> {
97 | textView.text = "ToolTip Customization"
98 | setOnClickListener {
99 | startActivity(Intent(context, ToolTipCustomizationActivity::class.java))
100 | }
101 | }
102 | 10 -> {
103 | textView.text = "Multiple ToolTip"
104 | setOnClickListener {
105 | startActivity(Intent(context, MultipleToolTipActivity::class.java))
106 | }
107 | }
108 | 11 -> {
109 | textView.text = "Overlay Customization"
110 | setOnClickListener {
111 | startActivity(Intent(context, OverlayCustomizationActivity::class.java))
112 | }
113 | }
114 | 12 -> {
115 | textView.text = "ToolTip & Overlay only, no Pointer"
116 | setOnClickListener {
117 | startActivity(Intent(context, NoPointerActivity::class.java))
118 | }
119 | }
120 | 13 -> {
121 | textView.text = "Overlay only, no Tooltip, no Pointer"
122 | setOnClickListener {
123 | startActivity(Intent(context, NoPointerNoToolTipActivity::class.java))
124 | }
125 | }
126 | 14 -> {
127 | textView.text = "ToolTip & Pointer only, no Overlay"
128 | setOnClickListener {
129 | startActivity(Intent(context, NoOverlayActivity::class.java))
130 | }
131 | }
132 | 15 -> {
133 | textView.text = "Button Tour (Manual)"
134 | infoIcon.visibility = View.VISIBLE
135 | infoIcon.setOnClickListener {
136 | val builder = AlertDialog.Builder(context)
137 | builder.setTitle("Button Tour").setMessage("- Button Tour example shows a sequence of TourGuide running on different buttons. \n- The method of proceeding to the next TourGuide is to press on the button itself. \n- This is suitable when you actually want the user to click on the button during the Tour.\n")
138 | builder.create().show()
139 | }
140 | setOnClickListener {
141 | startActivity(Intent(context, ManualSequenceActivity::class.java))
142 | }
143 | }
144 | 16 -> {
145 | textView.text = "Navigational Drawer"
146 | setOnClickListener {
147 | startActivity(Intent(context, NavDrawerActivity::class.java))
148 | }
149 | }
150 | 17 -> {
151 | textView.text = "Rounded Rectangle Overlay"
152 | setOnClickListener {
153 | startActivity(Intent(context, RoundedRectangleOverlayActivity::class.java))
154 | }
155 | }
156 | 18 -> {
157 | textView.text = "Adjust Overlay Padding"
158 | setOnClickListener {
159 | startActivity(Intent(context, AdjustPaddingOverlayActivity::class.java))
160 | }
161 | }
162 | else -> {
163 | textView.text = "Recycler View"
164 | setOnClickListener {
165 | startActivity(Intent(context, RecyclerViewActivity::class.java))
166 | }
167 | }
168 | }
169 | }
170 | }
171 |
172 | private fun decorateBackground(view: View, position: Int) =
173 | view.apply {
174 | setBackgroundColor(ContextCompat.getColor(context,
175 | if (position % 2 == 0) {
176 | R.color.blue1
177 | } else {
178 | R.color.blue2
179 | }))
180 | }
181 |
182 |
183 | override fun getItemCount() = numOfRow
184 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
185 | ViewHolder((LayoutInflater
186 | .from(parent.context)
187 | .inflate(R.layout.row, parent, false)))
188 |
189 | inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
190 | }
191 |
--------------------------------------------------------------------------------
/app/src/main/java/tourguide/tourguidedemo/recyclerview/RecyclerViewAdapter.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguidedemo.recyclerview
2 |
3 | import android.support.v7.widget.RecyclerView
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import kotlinx.android.synthetic.main.row_recycler_view.view.*
8 | import tourguide.tourguidedemo.R
9 |
10 | class RecyclerViewAdapter(val launchTourGuide: (View) -> Unit, val dismissTourGuide: () -> Unit) : RecyclerView.Adapter() {
11 |
12 | override fun onBindViewHolder(_holder: RecyclerView.ViewHolder, position: Int) {
13 | val holder = _holder as DemoViewHolder
14 | holder.itemView.rowTextView
15 | .apply { text = "row #${position}" }
16 | .also {
17 | if (position == 1) {
18 | launchTourGuide.invoke(it)
19 | holder.itemView.setOnClickListener {
20 | dismissTourGuide.invoke()
21 | }
22 | }
23 | }
24 | }
25 |
26 | override fun getItemCount() = 10
27 |
28 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
29 | LayoutInflater
30 | .from(parent.context)
31 | .inflate(R.layout.row_recycler_view, parent, false)
32 | .let { DemoViewHolder(it) }
33 |
34 | class DemoViewHolder(item: View) : RecyclerView.ViewHolder(item)
35 |
36 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/tour_guide_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worker8/TourGuide/949c4a484cb98febcc223d19d960dbc2f5c5a4c4/app/src/main/res/drawable-hdpi/tour_guide_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/tour_guide_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worker8/TourGuide/949c4a484cb98febcc223d19d960dbc2f5c5a4c4/app/src/main/res/drawable-mdpi/tour_guide_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/tour_guide_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worker8/TourGuide/949c4a484cb98febcc223d19d960dbc2f5c5a4c4/app/src/main/res/drawable-xhdpi/tour_guide_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/tour_guide_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worker8/TourGuide/949c4a484cb98febcc223d19d960dbc2f5c5a4c4/app/src/main/res/drawable-xxhdpi/tour_guide_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/toolbar_drop_shadow.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_basic.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
13 |
14 |
27 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_customization.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
14 |
15 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_in_sequence.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
11 |
12 |
27 |
28 |
43 |
44 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_multiple_tooltip.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
11 |
12 |
27 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_nav_drawer.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
14 |
23 |
27 |
28 |
29 |
38 |
39 |
44 |
45 |
49 |
50 |
55 |
60 |
69 |
70 |
71 |
72 |
77 |
82 |
91 |
92 |
97 |
102 |
111 |
112 |
113 |
114 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_overlay_customization.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
18 |
19 |
32 |
33 |
34 |
35 |
47 |
48 |
61 |
62 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_recycler_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_toolbar.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
16 |
17 |
20 |
21 |
22 |
29 |
30 |
41 |
42 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_tooltip_gravity_i.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
14 |
15 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_tooltip_gravity_ii.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
14 |
15 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_tooltip_gravity_iii.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
14 |
15 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_tooltip_gravity_iv.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
14 |
15 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_tour_guide_demo_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/nav_drawer_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/row.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
20 |
21 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/row_recycler_view.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/sequence_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
19 |
32 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_demo_main.xml:
--------------------------------------------------------------------------------
1 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFFFFF
4 | #3498db
5 | #2980b9
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
8 | 240dp
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Tour Guide
5 | Hello world!
6 | Settings
7 |
8 | Drawer is opened
9 | Drawer is closed
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
11 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | buildscript {
3 | ext {
4 | kotlin_version = '1.2.30'
5 | espressoVersion = '2.2.2'
6 | supportVersion = '25.4.0'
7 | compileSdkVersionNum = 26
8 | minSdkVersionNum = 11
9 | targetSdkVersionNum = 26
10 | buildToolVersionNum = '26.0.2'
11 | gradlePluginVersion = '3.0.1'
12 | }
13 | dependencies {
14 | repositories {
15 | jcenter()
16 | }
17 | classpath "com.android.tools.build:gradle:$gradlePluginVersion"
18 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
19 |
20 | }
21 | repositories {
22 | mavenCentral()
23 | maven {
24 | url "https://maven.google.com/"
25 | name "Google"
26 | }
27 | google()
28 | }
29 | }
30 |
31 | allprojects {
32 | repositories {
33 | mavenCentral()
34 | maven {
35 | url "https://maven.google.com/"
36 | name "Google"
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/gradle-mvn-push.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Taken from https://github.com/chrisbanes/gradle-mvn-push
3 | * Copyright 2013 Chris Banes
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | apply plugin: 'maven'
19 | apply plugin: 'signing'
20 |
21 | def isReleaseBuild() {
22 | return VERSION_NAME.contains("SNAPSHOT") == false
23 | }
24 |
25 | def getReleaseRepositoryUrl() {
26 | return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
27 | : "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
28 | }
29 |
30 | def getSnapshotRepositoryUrl() {
31 | return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
32 | : "https://oss.sonatype.org/content/repositories/snapshots/"
33 | }
34 |
35 | def getRepositoryUsername() {
36 | return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
37 | }
38 |
39 | def getRepositoryPassword() {
40 | return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
41 | }
42 |
43 | afterEvaluate { project ->
44 | uploadArchives {
45 | repositories {
46 | mavenDeployer {
47 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
48 |
49 | pom.groupId = GROUP
50 | pom.artifactId = POM_ARTIFACT_ID
51 | pom.version = VERSION_NAME
52 |
53 | repository(url: getReleaseRepositoryUrl()) {
54 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
55 | }
56 | snapshotRepository(url: getSnapshotRepositoryUrl()) {
57 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
58 | }
59 |
60 | pom.project {
61 | name POM_NAME
62 | packaging POM_PACKAGING
63 | description POM_DESCRIPTION
64 | url POM_URL
65 |
66 | scm {
67 | url POM_SCM_URL
68 | connection POM_SCM_CONNECTION
69 | developerConnection POM_SCM_DEV_CONNECTION
70 | }
71 |
72 | licenses {
73 | license {
74 | name POM_LICENCE_NAME
75 | url POM_LICENCE_URL
76 | distribution POM_LICENCE_DIST
77 | }
78 | }
79 |
80 | developers {
81 | developer {
82 | id POM_DEVELOPER_ID
83 | name POM_DEVELOPER_NAME
84 | }
85 | }
86 | }
87 | }
88 | }
89 | }
90 |
91 | signing {
92 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
93 | sign configurations.archives
94 | }
95 |
96 | task androidSourcesJar(type: Jar) {
97 | classifier = 'sources'
98 | from android.sourceSets.main.java.sourceFiles
99 | }
100 |
101 | artifacts {
102 | archives androidSourcesJar
103 | }
104 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | VERSION_NAME=2.0.0-SNAPSHOT
2 | VERSION_CODE=20
3 | GROUP=com.github.worker8
4 | NEXUS_USERNAME=worker8
5 | NEXUS_PASSWORD=
6 | POM_DESCRIPTION=A library to teach and guide users on how to use the app.
7 | POM_URL=https://github.com/worker8/TourGuide
8 | POM_SCM_URL=https://github.com/worker8/TourGuide
9 | POM_SCM_CONNECTION=scm:git@github.com:worker8/TourGuide.git
10 | POM_SCM_DEV_CONNECTION=scm:git@github.com:worker8/TourGuide.git
11 | POM_LICENCE_NAME=The MIT License
12 | POM_LICENCE_URL=https://opensource.org/licenses/MIT
13 | POM_LICENCE_DIST=repo
14 | POM_DEVELOPER_ID=worker8
15 | POM_DEVELOPER_NAME=Jun Rong
16 | SNAPSHOT_REPOSITORY_URL=https://oss.sonatype.org/content/repositories/snapshots
17 | RELEASE_REPOSITORY_URL=https://oss.sonatype.org/service/local/staging/deploy/maven2
18 | org.gradle.parallel=true
19 | org.gradle.configureondemand=true
20 | # caching speeds up build time, but it can sometimes cause duplication method name error, in that case, change to false, then clean, then recompile should solve the problem
21 | org.gradle.caching=true
22 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worker8/TourGuide/949c4a484cb98febcc223d19d960dbc2f5c5a4c4/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Aug 03 18:30:02 JST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':tourguide'
2 |
--------------------------------------------------------------------------------
/tourguide/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/tourguide/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 | apply from: '../gradle-mvn-push.gradle'
5 |
6 | Properties getGradleProperties() {
7 | def gradlePropsFile = file('../gradle.properties')
8 | def Properties gradleProps = new Properties()
9 | if (gradlePropsFile.canRead()) {
10 | gradleProps.load(new FileInputStream(gradlePropsFile))
11 | println gradleProps['VERSION_CODE']
12 | println gradleProps['VERSION_NAME']
13 | } else {
14 | throw new GradleException("Could not read gradle.properties!")
15 | }
16 | gradleProps;
17 | }
18 |
19 | android {
20 | compileSdkVersion compileSdkVersionNum
21 | buildToolsVersion buildToolVersionNum
22 | def gradleProps = getGradleProperties()
23 | defaultConfig {
24 | minSdkVersion 11
25 | targetSdkVersion targetSdkVersionNum
26 | versionCode gradleProps['VERSION_CODE'].toInteger()
27 | versionName gradleProps['VERSION_NAME']
28 | }
29 | buildTypes {
30 | release {
31 | minifyEnabled false
32 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
33 | }
34 | }
35 | lintOptions {
36 | abortOnError false
37 | }
38 | sourceSets {
39 | main {
40 | java {
41 | include '**/*.java'
42 | include '**/*.kt'
43 | }
44 | }
45 | }
46 | }
47 |
48 | dependencies {
49 | implementation fileTree(dir: 'libs', include: ['*.jar'])
50 | implementation "com.android.support:appcompat-v7:$supportVersion"
51 | implementation 'net.i2p.android.ext:floatingactionbutton:1.9.0'
52 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
53 |
54 | }
55 |
56 | repositories {
57 | mavenCentral()
58 | }
--------------------------------------------------------------------------------
/tourguide/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 |
20 | POM_NAME=TourGuide Library
21 | POM_ARTIFACT_ID=tourguide
22 | POM_PACKAGING=aar
23 |
24 |
--------------------------------------------------------------------------------
/tourguide/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/tanjunrong/adt-bundle-mac-x86_64-20140702/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/tourguide/src/androidTest/java/tourguide/tourguide/ApplicationTest.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguide
2 |
3 | import android.app.Application
4 | import android.test.ApplicationTestCase
5 |
6 | /**
7 | * [Testing Fundamentals](http://d.android.com/tools/testing/testing_android.html)
8 | */
9 | class ApplicationTest : ApplicationTestCase(Application::class.java)
--------------------------------------------------------------------------------
/tourguide/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/tourguide/src/main/java/tourguide/tourguide/FrameLayoutWithHole.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguide
2 |
3 | import android.animation.AnimatorSet
4 | import android.app.Activity
5 | import android.graphics.*
6 | import android.support.v4.content.ContextCompat
7 | import android.text.TextPaint
8 | import android.util.AttributeSet
9 | import android.view.MotionEvent
10 | import android.view.View
11 | import android.view.ViewGroup
12 | import android.view.animation.Animation
13 | import android.widget.FrameLayout
14 | import tourguide.tourguide.util.letWith
15 | import tourguide.tourguide.util.locationOnScreen
16 |
17 | open class FrameLayoutWithHole @JvmOverloads constructor(private val mActivity: Activity, private var mViewHole: View // This is the targeted view to be highlighted, where the hole should be placed
18 | , private val mMotionType: TourGuide.MotionType? = TourGuide.MotionType.ALLOW_ALL, private val mOverlay: Overlay? = Overlay()) : FrameLayout(mActivity) {
19 | private var mTextPaint: TextPaint? = null
20 | private var mEraser: Paint? = null
21 |
22 | internal var mEraserBitmap: Bitmap? = null
23 | private var _eraserCanvas: Canvas? = null
24 | private var mPaint: Paint? = null
25 | private var transparentPaint: Paint? = null
26 | private var mRadius: Int = 0
27 | private val mPosition: Point
28 | get() = mViewHole.locationOnScreen
29 | private val mDensity: Float
30 | private var mRectF: RectF? = null
31 |
32 | private val mAnimatorSetArrayList by lazy { mutableListOf() }
33 |
34 | private var mCleanUpLock = false
35 |
36 | init {
37 | init(null, 0)
38 | enforceMotionType()
39 |
40 | mDensity = mActivity.resources.displayMetrics.density
41 | val padding = (20 * mDensity).toInt()
42 |
43 | if (mViewHole.height > mViewHole.width) {
44 | mRadius = mViewHole.height / 2 + padding
45 | } else {
46 | mRadius = mViewHole.width / 2 + padding
47 | }
48 |
49 | // Init a RectF to be used in OnDraw for a ROUNDED_RECTANGLE Style Overlay
50 | mOverlay?.also { _overlay ->
51 | if (_overlay.mStyle === Overlay.Style.ROUNDED_RECTANGLE) {
52 | val recfFPaddingPx = (_overlay.mPaddingDp * mDensity).toInt()
53 | mRectF = RectF((mPosition.x - recfFPaddingPx + _overlay.mHoleOffsetLeft).toFloat(),
54 | (mPosition.y - recfFPaddingPx + _overlay.mHoleOffsetTop).toFloat(),
55 | (mPosition.x + mViewHole.width + recfFPaddingPx + _overlay.mHoleOffsetLeft).toFloat(),
56 | (mPosition.y + mViewHole.height + recfFPaddingPx + _overlay.mHoleOffsetTop).toFloat())
57 | }
58 | }
59 | }
60 |
61 | private fun init(attrs: AttributeSet?, defStyle: Int) {
62 | // Load attributes
63 | // val a = getContext()
64 | // .obtainStyledAttributes(attrs, FrameLayoutWithHole, defStyle, 0)
65 | // .apply { a.recycle() }
66 | setWillNotDraw(false)
67 | // Set up a default TextPaint object
68 | mTextPaint = TextPaint().apply {
69 | flags = Paint.ANTI_ALIAS_FLAG
70 | textAlign = Paint.Align.LEFT
71 | }
72 |
73 | val size = Point()
74 | size.x = mActivity.resources.displayMetrics.widthPixels
75 | size.y = mActivity.resources.displayMetrics.heightPixels
76 |
77 | mEraserBitmap = Bitmap.createBitmap(size.x, size.y, Bitmap.Config.ARGB_8888)
78 | _eraserCanvas = Canvas(mEraserBitmap!!)
79 |
80 | mPaint = Paint().apply { color = -0x34000000 }
81 | transparentPaint = Paint().apply {
82 | color = ContextCompat.getColor(context, android.R.color.transparent)
83 | xfermode = PorterDuffXfermode(PorterDuff.Mode.CLEAR)
84 | }
85 |
86 | mEraser = Paint().apply {
87 | color = -0x1
88 | xfermode = PorterDuffXfermode(PorterDuff.Mode.CLEAR)
89 | flags = Paint.ANTI_ALIAS_FLAG
90 | }
91 | }
92 |
93 | fun setViewHole(viewHole: View) {
94 | this.mViewHole = viewHole
95 | enforceMotionType()
96 | }
97 |
98 | fun addAnimatorSet(animatorSet: AnimatorSet) {
99 | mAnimatorSetArrayList.add(animatorSet)
100 | }
101 |
102 | fun cleanUp() {
103 | parent?.also {
104 | if (mOverlay?.mExitAnimation != null) {
105 | performOverlayExitAnimation()
106 | } else {
107 | (parent as ViewGroup).removeView(this)
108 | }
109 | }
110 | }
111 |
112 | private fun enforceMotionType() {
113 | if (mMotionType == TourGuide.MotionType.CLICK_ONLY) {
114 | mViewHole.setOnTouchListener { view, motionEvent ->
115 | mViewHole.parent.requestDisallowInterceptTouchEvent(true)
116 | false
117 | }
118 | } else if (mMotionType == TourGuide.MotionType.SWIPE_ONLY) {
119 | mViewHole.isClickable = false
120 | }
121 | }
122 |
123 | private fun performOverlayExitAnimation() {
124 | if (!mCleanUpLock) {
125 | val pointerToFrameLayout = this
126 | mCleanUpLock = true
127 | mOverlay?.mExitAnimation?.also {
128 | it.setAnimationListener(object : Animation.AnimationListener {
129 | override fun onAnimationStart(animation: Animation) {}
130 |
131 | override fun onAnimationRepeat(animation: Animation) {}
132 |
133 | override fun onAnimationEnd(animation: Animation) {
134 | (pointerToFrameLayout.parent as ViewGroup).removeView(pointerToFrameLayout)
135 | }
136 | })
137 | startAnimation(it)
138 | }
139 | }
140 | }
141 |
142 | /* comment this whole method to cause a memory leak */
143 | override fun onDetachedFromWindow() {
144 | super.onDetachedFromWindow()
145 | /* cleanup reference to prevent memory leak */
146 | _eraserCanvas?.setBitmap(null)
147 | mEraserBitmap = null
148 |
149 | if (!mAnimatorSetArrayList.isEmpty()) {
150 | for (i in mAnimatorSetArrayList.indices) {
151 | mAnimatorSetArrayList[i].end()
152 | mAnimatorSetArrayList[i].removeAllListeners()
153 | }
154 | }
155 | }
156 |
157 | override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
158 | //first check if the location button should handle the touch event
159 | // ev.dumpEvent();
160 | // int action = MotionEventCompat.getActionMasked(ev);
161 | if (isWithinButton(ev) && mOverlay != null && mOverlay.mDisableClickThroughHole) {
162 | // block it
163 | return true
164 | } else if (isWithinButton(ev)) {
165 | // let it pass through
166 | return false
167 | }
168 | // do nothing, just propagating up to super
169 | return super.dispatchTouchEvent(ev)
170 | }
171 |
172 | private fun isWithinButton(ev: MotionEvent): Boolean {
173 | val pos = IntArray(2)
174 | mViewHole.getLocationOnScreen(pos)
175 | return ev.rawY >= pos[1] &&
176 | ev.rawY <= pos[1] + mViewHole.height &&
177 | ev.rawX >= pos[0] &&
178 | ev.rawX <= pos[0] + mViewHole.width
179 | }
180 |
181 | override fun onDraw(canvas: Canvas) {
182 | super.onDraw(canvas)
183 | mEraserBitmap!!.eraseColor(Color.TRANSPARENT)
184 |
185 | mOverlay.letWith(_eraserCanvas) { _overlay, _eraserCanvas ->
186 | _eraserCanvas.drawColor(_overlay.backgroundColor)
187 | val padding = (_overlay.mPaddingDp * mDensity).toInt()
188 |
189 | if (_overlay.mStyle === Overlay.Style.RECTANGLE) {
190 | _eraserCanvas.drawRect(
191 | (mPosition.x - padding + _overlay.mHoleOffsetLeft).toFloat(),
192 | (mPosition.y - padding + _overlay.mHoleOffsetTop).toFloat(),
193 | (mPosition.x + mViewHole.width + padding + _overlay.mHoleOffsetLeft).toFloat(),
194 | (mPosition.y + mViewHole.height + padding + _overlay.mHoleOffsetTop).toFloat(), mEraser!!)
195 | } else if (_overlay.mStyle === Overlay.Style.NO_HOLE) {
196 | _eraserCanvas.drawCircle(
197 | (mPosition.x + mViewHole.width / 2 + _overlay.mHoleOffsetLeft).toFloat(),
198 | (mPosition.y + mViewHole.height / 2 + _overlay.mHoleOffsetTop).toFloat(),
199 | 0f, mEraser!!)
200 | } else if (_overlay.mStyle === Overlay.Style.ROUNDED_RECTANGLE) {
201 | val roundedCornerRadiusPx: Int
202 | if (_overlay.mRoundedCornerRadiusDp != 0) {
203 | roundedCornerRadiusPx = (_overlay.mRoundedCornerRadiusDp * mDensity).toInt()
204 | } else {
205 | roundedCornerRadiusPx = (10 * mDensity).toInt()
206 | }
207 | _eraserCanvas.drawRoundRect(mRectF!!, roundedCornerRadiusPx.toFloat(), roundedCornerRadiusPx.toFloat(), mEraser!!)
208 | } else {
209 | val holeRadius = if (_overlay.mHoleRadius != Overlay.NOT_SET) _overlay.mHoleRadius else mRadius
210 | _eraserCanvas.drawCircle(
211 | (mPosition.x + mViewHole.width / 2 + _overlay.mHoleOffsetLeft).toFloat(),
212 | (mPosition.y + mViewHole.height / 2 + _overlay.mHoleOffsetTop).toFloat(),
213 | holeRadius.toFloat(), mEraser!!)
214 | }
215 | }
216 | canvas.drawBitmap(mEraserBitmap!!, 0f, 0f, null)
217 |
218 | }
219 |
220 | override fun onAttachedToWindow() {
221 | super.onAttachedToWindow()
222 | mOverlay?.letWith(mOverlay.mEnterAnimation) { _, _enterAnimation ->
223 | startAnimation(_enterAnimation)
224 | }
225 | }
226 | }
227 |
--------------------------------------------------------------------------------
/tourguide/src/main/java/tourguide/tourguide/Overlay.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguide
2 |
3 | import android.graphics.Color
4 | import android.view.View
5 | import android.view.animation.Animation
6 |
7 | /**
8 | * [Overlay] shows a tinted background to cover up the rest of the screen. A 'hole' will be made on this overlay to let users obtain focus on the targeted element.
9 | */
10 | class Overlay @JvmOverloads constructor(var mDisableClick: Boolean = true, var backgroundColor: Int = Color.parseColor("#55000000"), var mStyle: Style = Style.CIRCLE) {
11 | var mDisableClickThroughHole: Boolean = false
12 | var mEnterAnimation: Animation? = null
13 | var mExitAnimation: Animation? = null
14 | var mHoleOffsetLeft = 0
15 | var mHoleOffsetTop = 0
16 | var mOnClickListener: View.OnClickListener? = null
17 | var mHoleRadius = NOT_SET
18 | var mPaddingDp = 10
19 | var mRoundedCornerRadiusDp = 0
20 |
21 | enum class Style {
22 | CIRCLE, RECTANGLE, ROUNDED_RECTANGLE, NO_HOLE
23 | }
24 |
25 | fun backgroundColor(block: () -> Int) {
26 | backgroundColor = block()
27 | }
28 |
29 | /**
30 | * Set to true if you want to block all user input to pass through this overlay, set to false if you want to allow user input under the overlay
31 | * @param yesNo
32 | * @return return [Overlay] instance for chaining purpose
33 | */
34 | fun disableClick(yesNo: Boolean): Overlay {
35 | mDisableClick = yesNo
36 | return this
37 | }
38 |
39 | fun disableClick(block: () -> Boolean) {
40 | mDisableClick = block()
41 | }
42 |
43 | /**
44 | * Set to true if you want to disallow the highlighted view to be clicked through the hole,
45 | * set to false if you want to allow the highlighted view to be clicked through the hole
46 | * @param yesNo
47 | * @return return Overlay instance for chaining purpose
48 | */
49 | fun disableClickThroughHole(yesNo: Boolean): Overlay {
50 | mDisableClickThroughHole = yesNo
51 | return this
52 | }
53 |
54 | fun disableClickThroughHole(block: () -> Boolean) {
55 | mDisableClickThroughHole = block()
56 | }
57 |
58 | fun setStyle(style: Style): Overlay {
59 | mStyle = style
60 | return this
61 | }
62 |
63 | fun style(block: () -> Style) {
64 | mStyle = block()
65 | }
66 |
67 | /**
68 | * Set enter animation
69 | * @param enterAnimation
70 | * @return return [Overlay] instance for chaining purpose
71 | */
72 | fun setEnterAnimation(enterAnimation: Animation): Overlay {
73 | mEnterAnimation = enterAnimation
74 | return this
75 | }
76 |
77 | /**
78 | * Set exit animation
79 | * @param exitAnimation
80 | * @return return [Overlay] instance for chaining purpose
81 | */
82 | fun setExitAnimation(exitAnimation: Animation): Overlay {
83 | mExitAnimation = exitAnimation
84 | return this
85 | }
86 |
87 | /**
88 | * Set [Overlay.mOnClickListener] for the [Overlay]
89 | * @param onClickListener
90 | * @return return [Overlay] instance for chaining purpose
91 | */
92 | fun setOnClickListener(onClickListener: View.OnClickListener): Overlay {
93 | mOnClickListener = onClickListener
94 | return this
95 | }
96 |
97 | fun onClickListener(block: () -> View.OnClickListener) {
98 | mOnClickListener = block()
99 | }
100 |
101 | /**
102 | * This method sets the hole's radius.
103 | * If this is not set, the size of view hole fill follow the max(view.width, view.height)
104 | * If this is set, it will take precedence
105 | * It only has effect when [Overlay.Style.CIRCLE] is chosen
106 | * @param holeRadius the radius of the view hole, setting 0 will make the hole disappear, in pixels
107 | * @return return [Overlay] instance for chaining purpose
108 | */
109 | fun setHoleRadius(holeRadius: Int): Overlay {
110 | mHoleRadius = holeRadius
111 | return this
112 | }
113 |
114 |
115 | /**
116 | * This method sets offsets to the hole's position relative the position of the targeted view.
117 | * @param offsetLeft left offset, in pixels
118 | * @param offsetTop top offset, in pixels
119 | * @return [Overlay] instance for chaining purpose
120 | */
121 | fun setHoleOffsets(offsetLeft: Int, offsetTop: Int): Overlay {
122 | mHoleOffsetLeft = offsetLeft
123 | mHoleOffsetTop = offsetTop
124 | return this
125 | }
126 |
127 | /**
128 | * This method sets the padding to be applied to the hole cutout from the overlay
129 | * @param paddingDp padding, in dp
130 | * @return [Overlay] intance for chaining purpose
131 | */
132 | fun setHolePadding(paddingDp: Int): Overlay {
133 | mPaddingDp = paddingDp
134 | return this
135 | }
136 |
137 | fun holePadding(block: () -> Int) {
138 | mPaddingDp = block()
139 | }
140 |
141 | /**
142 | * This method sets the radius for the rounded corner
143 | * It only has effect when [Overlay.Style.ROUNDED_RECTANGLE] is chosen
144 | * @param roundedCornerRadiusDp padding, in pixels
145 | * @return [Overlay] intance for chaining purpose
146 | */
147 | fun setRoundedCornerRadius(roundedCornerRadiusDp: Int): Overlay {
148 | mRoundedCornerRadiusDp = roundedCornerRadiusDp
149 | return this
150 | }
151 |
152 | fun roundedCornerRadius(block: () -> Int) {
153 | mRoundedCornerRadiusDp = block()
154 | }
155 |
156 | companion object {
157 | const val NOT_SET = -1
158 | }
159 | }
160 |
--------------------------------------------------------------------------------
/tourguide/src/main/java/tourguide/tourguide/Pointer.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguide
2 |
3 | import android.graphics.Color
4 | import android.view.Gravity
5 |
6 | class Pointer @JvmOverloads constructor(var gravity: Int = Gravity.CENTER, var color: Int = Color.parseColor("#FFFFFF")) {
7 |
8 | fun gravity(block: () -> Int) {
9 | gravity = block()
10 | }
11 |
12 | fun color(block: () -> Int) {
13 | color = block()
14 | }
15 | }
--------------------------------------------------------------------------------
/tourguide/src/main/java/tourguide/tourguide/ToolTip.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguide
2 |
3 | import android.graphics.Color
4 | import android.view.Gravity
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import android.view.animation.AlphaAnimation
8 | import android.view.animation.Animation
9 | import android.view.animation.BounceInterpolator
10 |
11 | class ToolTip() {
12 | var title: String
13 | private set
14 | var description: String
15 | private set
16 | var mBackgroundColor: Int = 0
17 | var mTextColor: Int = 0
18 | var mEnterAnimation: Animation
19 | var mExitAnimation: Animation? = null
20 | var mShadow: Boolean = false
21 | var mGravity: Int = 0
22 | var mOnClickListener: View.OnClickListener? = null
23 | var mCustomView: ViewGroup? = null
24 | var mWidth: Int = 0
25 |
26 | init {
27 | /* default values */
28 | title = ""
29 | description = ""
30 | mBackgroundColor = Color.parseColor("#3498db")
31 | mTextColor = Color.parseColor("#FFFFFF")
32 |
33 | mEnterAnimation = AlphaAnimation(0f, 1f)
34 | mEnterAnimation.duration = 1000
35 | mEnterAnimation.fillAfter = true
36 | mEnterAnimation.interpolator = BounceInterpolator()
37 | mShadow = true
38 | mWidth = -1
39 |
40 | // TODO: exit animation
41 | mGravity = Gravity.CENTER
42 | }
43 |
44 | constructor(init: ToolTip.() -> Unit) : this() {
45 | init()
46 | }
47 |
48 | fun title(block: () -> String) {
49 | title = block()
50 | }
51 |
52 | fun description(block: () -> String) {
53 | description = block()
54 | }
55 |
56 | fun backgroundColor(block: () -> Int) {
57 | mBackgroundColor = block()
58 | }
59 |
60 | fun textColor(block: () -> Int) {
61 | mTextColor = block()
62 | }
63 |
64 | fun gravity(block: () -> Int) {
65 | mGravity = block()
66 | }
67 |
68 | fun shadow(block: () -> Boolean) {
69 | mShadow = block()
70 | }
71 |
72 | fun enterAnimation(block: () -> Animation) {
73 | mEnterAnimation = block()
74 | }
75 |
76 | fun exitAnimation(block: () -> Animation) {
77 | mExitAnimation = block()
78 | }
79 |
80 | /**
81 | * Set title text
82 | * @param title
83 | * @return return ToolTip instance for chaining purpose
84 | */
85 | fun setTitle(title: String): ToolTip {
86 | this.title = title
87 | return this
88 | }
89 |
90 | /**
91 | * Set description text
92 | * @param description
93 | * @return return ToolTip instance for chaining purpose
94 | */
95 | fun setDescription(description: String): ToolTip {
96 | this.description = description
97 | return this
98 | }
99 |
100 | /**
101 | * Set background color
102 | * @param backgroundColor
103 | * @return return ToolTip instance for chaining purpose
104 | */
105 | fun setBackgroundColor(backgroundColor: Int): ToolTip {
106 | mBackgroundColor = backgroundColor
107 | return this
108 | }
109 |
110 | /**
111 | * Set text color
112 | * @param textColor
113 | * @return return ToolTip instance for chaining purpose
114 | */
115 | fun setTextColor(textColor: Int): ToolTip {
116 | mTextColor = textColor
117 | return this
118 | }
119 |
120 | /**
121 | * Set enter animation
122 | * @param enterAnimation
123 | * @return return ToolTip instance for chaining purpose
124 | */
125 | fun setEnterAnimation(enterAnimation: Animation): ToolTip {
126 | mEnterAnimation = enterAnimation
127 | return this
128 | }
129 |
130 | /**
131 | * Set the gravity, the setGravity is centered relative to the targeted button
132 | * @param gravity Gravity.CENTER, Gravity.TOP, Gravity.BOTTOM, etc
133 | * @return return ToolTip instance for chaining purpose
134 | */
135 | fun setGravity(gravity: Int): ToolTip {
136 | mGravity = gravity
137 | return this
138 | }
139 |
140 | /**
141 | * Set if you want to have setShadow
142 | * @param shadow
143 | * @return return ToolTip instance for chaining purpose
144 | */
145 | fun setShadow(shadow: Boolean): ToolTip {
146 | mShadow = shadow
147 | return this
148 | }
149 |
150 | /**
151 | * Method to set the width of the ToolTip
152 | * @param px desired width of ToolTip in pixels
153 | * @return ToolTip instance for chaining purposes
154 | */
155 | fun setWidth(px: Int): ToolTip {
156 | if (px >= 0) mWidth = px
157 | return this
158 | }
159 |
160 | fun setOnClickListener(onClickListener: View.OnClickListener): ToolTip {
161 | mOnClickListener = onClickListener
162 | return this
163 | }
164 |
165 | fun getCustomView(): ViewGroup? {
166 | return mCustomView
167 | }
168 |
169 | fun setCustomView(view: ViewGroup): ToolTip {
170 | mCustomView = view
171 | return this
172 | }
173 | }
--------------------------------------------------------------------------------
/tourguide/src/main/java/tourguide/tourguide/TourGuide.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguide
2 |
3 | import android.animation.Animator
4 | import android.animation.AnimatorSet
5 | import android.animation.ObjectAnimator
6 | import android.app.Activity
7 | import android.graphics.Color
8 | import android.graphics.Point
9 | import android.os.Build
10 | import android.support.v4.view.ViewCompat
11 | import android.util.Log
12 | import android.view.Gravity
13 | import android.view.View
14 | import android.view.ViewGroup
15 | import android.view.ViewTreeObserver
16 | import android.widget.FrameLayout
17 | import android.widget.LinearLayout
18 | import kotlinx.android.synthetic.main.tourguide_tooltip.view.*
19 | import net.i2p.android.ext.floatingactionbutton.FloatingActionButton
20 | import tourguide.tourguide.util.locationOnScreen
21 |
22 | open class TourGuide(private val activity: Activity) {
23 | var technique: Technique = Technique.CLICK
24 | protected lateinit var highlightedView: View
25 | private var motionType: MotionType = MotionType.CLICK_ONLY
26 | /**
27 | *
28 | * @return FrameLayoutWithHole that is used as overlay
29 | */
30 | var frameLayoutWithHole: FrameLayoutWithHole? = null
31 | protected set
32 | /**
33 | *
34 | * @return the ToolTip container View
35 | */
36 | var toolTipView: View? = null
37 | private set
38 | var toolTip: ToolTip? = null
39 | private set
40 | var mPointer: Pointer? = null
41 | var overlay: Overlay? = null
42 |
43 | private val screenWidth: Int
44 | get() = activity.resources?.displayMetrics?.widthPixels ?: 0
45 |
46 | /**
47 | * This describes the animation techniques
48 | */
49 | enum class Technique {
50 | CLICK, HORIZONTAL_LEFT, HORIZONTAL_RIGHT, VERTICAL_UPWARD, VERTICAL_DOWNWARD
51 | }
52 |
53 | /**
54 | * This describes the allowable motion, for example if you want the users to learn about clicking, but want to stop them from swiping, then use CLICK_ONLY
55 | */
56 | enum class MotionType {
57 | ALLOW_ALL, CLICK_ONLY, SWIPE_ONLY
58 | }
59 |
60 | /**
61 | * Setter for the animation to be used
62 | * @param technique Animation to be used
63 | * @return return TourGuide instance for chaining purpose
64 | */
65 | open fun with(technique: Technique): TourGuide {
66 | this.technique = technique
67 | return this
68 | }
69 |
70 | /**
71 | * Sets which motion type is motionType
72 | * @param motionType
73 | * @return return TourGuide instance for chaining purpose
74 | */
75 | open fun motionType(_motionType: MotionType): TourGuide {
76 | motionType = _motionType
77 | return this
78 | }
79 |
80 | /**
81 | * Sets the targeted view for TourGuide to play on
82 | * @param targetView the view in which the tutorial button will be placed on top of
83 | * @return return TourGuide instance for chaining purpose
84 | */
85 | open infix fun playOn(targetView: View): TourGuide {
86 | highlightedView = targetView
87 | setupView()
88 | return this
89 | }
90 |
91 | /**
92 | * Set the toolTipView
93 | * @param toolTip this toolTipView object should contain the attributes of the ToolTip, such as, the title text, and the description text, background color, etc
94 | * @return return TourGuide instance for chaining purpose
95 | */
96 | open fun setToolTip(toolTip: ToolTip): TourGuide {
97 | this.toolTip = toolTip
98 | return this
99 | }
100 |
101 | /**
102 | * Set the Pointer
103 | * @param pointer this pointer object should contain the attributes of the Pointer, such as the pointer color, pointer gravity, etc, refer to @Link{pointer}
104 | * @return return TourGuide instance for chaining purpose
105 | */
106 | open fun setPointer(pointer: Pointer): TourGuide {
107 | mPointer = pointer
108 | return this
109 | }
110 |
111 | /**
112 | * Clean up the tutorial that is added to the activity
113 | */
114 | fun cleanUp() {
115 | frameLayoutWithHole?.cleanUp()
116 | toolTipView.also {
117 | (activity.window.decorView as ViewGroup).removeView(it)
118 | }
119 | }
120 |
121 | //TODO: move into Pointer
122 | private fun getXBasedOnGravity(width: Int): Int {
123 | val x = highlightedView.locationOnScreen.x
124 | mPointer?.let { _pointer ->
125 | if (_pointer.gravity and Gravity.RIGHT == Gravity.RIGHT) {
126 | return x + highlightedView.width - width
127 | } else if (_pointer.gravity and Gravity.LEFT == Gravity.LEFT) {
128 | return x
129 | }
130 | }
131 | return x + highlightedView.width / 2 - width / 2
132 | }
133 |
134 | //TODO: move into Pointer
135 | private fun getYBasedOnGravity(height: Int): Int {
136 | val y = highlightedView.locationOnScreen.y
137 | mPointer?.let { _pointer ->
138 | if (_pointer.gravity and Gravity.BOTTOM == Gravity.BOTTOM) {
139 | return y + highlightedView.height - height
140 | } else if (_pointer.gravity and Gravity.TOP == Gravity.TOP) {
141 | return y
142 | }
143 | }
144 | return y + highlightedView.height / 2 - height / 2
145 | }
146 |
147 | protected fun setupView() {
148 | // TourGuide can only be setup after all the views is ready and obtain it's position/measurement
149 | // so when this is the 1st time TourGuide is being added,
150 | // else block will be executed, and ViewTreeObserver will make TourGuide setup process to be delayed until everything is ready
151 | // when this is run the 2nd or more times, if block will be executed
152 | if (ViewCompat.isAttachedToWindow(highlightedView)) {
153 | startView()
154 | } else {
155 | val viewTreeObserver = highlightedView.viewTreeObserver
156 | viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
157 | override fun onGlobalLayout() {
158 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
159 | highlightedView.viewTreeObserver.removeGlobalOnLayoutListener(this)
160 | } else {
161 | highlightedView.viewTreeObserver.removeOnGlobalLayoutListener(this)
162 | }
163 | startView()
164 | }
165 | })
166 | }
167 | }
168 |
169 | private fun startView() {
170 | /* Initialize a frame layout with a hole */
171 | frameLayoutWithHole = FrameLayoutWithHole(activity, highlightedView, motionType, overlay)
172 | /* handle click disable */
173 | frameLayoutWithHole?.let {
174 | handleDisableClicking(it)
175 | }
176 |
177 | /* setup floating action button */
178 | if (mPointer != null) {
179 | frameLayoutWithHole?.let {
180 | val fab = setupAndAddFABToFrameLayout(it)
181 | performAnimationOn(fab)
182 | }
183 | }
184 | setupFrameLayout()
185 | /* setup tourguide_tooltip view */
186 | setupToolTip()
187 | }
188 |
189 | private fun handleDisableClicking(frameLayoutWithHole: FrameLayoutWithHole) {
190 | overlay?.also { _overlay ->
191 | if (_overlay.mOnClickListener != null) {
192 | // 1. if user provides an overlay listener, use that as 1st priority
193 | frameLayoutWithHole.isClickable = true
194 | frameLayoutWithHole.setOnClickListener(_overlay.mOnClickListener)
195 | } else if (_overlay.mDisableClick) {
196 | // 2. if overlay listener is not provided, check if it's disabled
197 | Log.w("tourguide", "Overlay's default OnClickListener is null, it will proceed to next tourguide when it is clicked")
198 | frameLayoutWithHole.setViewHole(highlightedView)
199 | frameLayoutWithHole.isSoundEffectsEnabled = false
200 | frameLayoutWithHole.setOnClickListener { }
201 | }
202 | }
203 | }
204 |
205 | private fun setupToolTip() {
206 | val layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT)
207 |
208 | toolTip?.also { _toolTip ->
209 |
210 | /* inflate and get views */
211 | val parent = activity.window.decorView as ViewGroup
212 | val layoutInflater = activity.layoutInflater
213 |
214 | if (_toolTip.getCustomView() == null) {
215 | toolTipView = layoutInflater.inflate(R.layout.tourguide_tooltip, null)
216 | toolTipView?.apply {
217 |
218 | /* set tourguide_tooltip attributes */
219 | toolTipContainer.setBackgroundColor(_toolTip.mBackgroundColor)
220 | toolTipTitleTextView.setTextColor(_toolTip.mTextColor)
221 | toolTipDescTextView.setTextColor(_toolTip.mTextColor)
222 |
223 | if (_toolTip.title.isEmpty()) {
224 | toolTipTitleTextView.visibility = View.GONE
225 | } else {
226 | toolTipTitleTextView.visibility = View.VISIBLE
227 | toolTipTitleTextView.text = _toolTip.title
228 | }
229 |
230 | if (_toolTip.description.isEmpty()) {
231 | toolTipDescTextView.visibility = View.GONE
232 | } else {
233 | toolTipDescTextView.visibility = View.VISIBLE
234 | toolTipDescTextView.text = _toolTip.description
235 | }
236 |
237 | if (_toolTip.mWidth != -1) {
238 | layoutParams.width = _toolTip.mWidth
239 | }
240 | }
241 | } else {
242 | toolTipView = _toolTip.getCustomView()
243 | }
244 | toolTipView?.also { _toolTipView ->
245 | _toolTipView.startAnimation(_toolTip.mEnterAnimation)
246 |
247 | /* add setShadow if it's turned on */
248 | if (_toolTip.mShadow) {
249 | _toolTipView.setBackgroundDrawable(activity.resources.getDrawable(R.drawable.tourguide_drop_shadow))
250 | }
251 |
252 | /* position and size calculation */
253 | val pos = IntArray(2)
254 | highlightedView.getLocationOnScreen(pos)
255 | val targetViewX = pos[0]
256 | val targetViewY = pos[1]
257 |
258 | // get measured size of tourguide_tooltip
259 | _toolTipView.measure(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT)
260 | var toolTipMeasuredWidth = if (_toolTip.mWidth != -1) _toolTip.mWidth else _toolTipView.measuredWidth
261 | val toolTipMeasuredHeight = _toolTipView.measuredHeight
262 |
263 | val resultPoint = Point() // this holds the final position of tourguide_tooltip
264 | val density = activity.resources.displayMetrics.density
265 | val adjustment = 10 * density //adjustment is that little overlapping area of tourguide_tooltip and targeted button
266 |
267 | // calculate x position, based on gravity, tooltipMeasuredWidth, parent max width, x position of target view, adjustment
268 | if (toolTipMeasuredWidth > parent.width) {
269 | resultPoint.x = getXForTooTip(_toolTip.mGravity, parent.width, targetViewX, adjustment)
270 | } else {
271 | resultPoint.x = getXForTooTip(_toolTip.mGravity, toolTipMeasuredWidth, targetViewX, adjustment)
272 | }
273 |
274 | resultPoint.y = getYForTooTip(_toolTip.mGravity, toolTipMeasuredHeight, targetViewY, adjustment)
275 |
276 | parent.addView(_toolTipView, layoutParams)
277 |
278 | // 1. width < screen check
279 | if (toolTipMeasuredWidth > parent.width) {
280 | _toolTipView.layoutParams.width = parent.width
281 | toolTipMeasuredWidth = parent.width
282 | }
283 | // 2. x left boundary check
284 | if (resultPoint.x < 0) {
285 | _toolTipView.layoutParams.width = toolTipMeasuredWidth + resultPoint.x //since point.x is negative, use plus
286 | resultPoint.x = 0
287 | }
288 | // 3. x right boundary check
289 | val tempRightX = resultPoint.x + toolTipMeasuredWidth
290 | if (tempRightX > parent.width) {
291 | _toolTipView.layoutParams.width = parent.width - resultPoint.x //since point.x is negative, use plus
292 | }
293 |
294 | // pass toolTipView onClickListener into toolTipViewGroup
295 | if (_toolTip.mOnClickListener != null) {
296 | _toolTipView.setOnClickListener(_toolTip.mOnClickListener)
297 | }
298 |
299 | // TODO: no boundary check for height yet, this is a unlikely case though
300 | // height boundary can be fixed by user changing the gravity to the other size, since there are plenty of space vertically compared to horizontally
301 |
302 | // this needs an viewTreeObserver, that's because TextView measurement of it's vertical height is not accurate (didn't take into account of multiple lines yet) before it's rendered
303 | // re-calculate height again once it's rendered
304 | _toolTipView.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
305 | override fun onGlobalLayout() {
306 | // make sure this only run once
307 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
308 | _toolTipView.viewTreeObserver.removeGlobalOnLayoutListener(this)
309 | } else {
310 | _toolTipView.viewTreeObserver.removeOnGlobalLayoutListener(this)
311 | }
312 |
313 | val fixedY: Int
314 | val toolTipHeightAfterLayouted = _toolTipView.height
315 | fixedY = getYForTooTip(_toolTip.mGravity, toolTipHeightAfterLayouted, targetViewY, adjustment)
316 | layoutParams.setMargins(_toolTipView.x.toInt(), fixedY, 0, 0)
317 | }
318 | })
319 |
320 | // set the position using setMargins on the left and top
321 | layoutParams.setMargins(resultPoint.x, resultPoint.y, 0, 0)
322 | }
323 | }
324 |
325 | }
326 |
327 | private fun getXForTooTip(gravity: Int, toolTipMeasuredWidth: Int, targetViewX: Int, adjustment: Float) =
328 | when {
329 | gravity and Gravity.LEFT == Gravity.LEFT -> targetViewX - toolTipMeasuredWidth + adjustment.toInt()
330 | gravity and Gravity.RIGHT == Gravity.RIGHT -> targetViewX + highlightedView.width - adjustment.toInt()
331 | else -> targetViewX + highlightedView.width / 2 - toolTipMeasuredWidth / 2
332 | }
333 |
334 | private fun getYForTooTip(gravity: Int, toolTipMeasuredHeight: Int, targetViewY: Int, adjustment: Float) =
335 | when {
336 | gravity and Gravity.TOP == Gravity.TOP -> if (gravity and Gravity.LEFT == Gravity.LEFT || gravity and Gravity.RIGHT == Gravity.RIGHT) {
337 | targetViewY - toolTipMeasuredHeight + adjustment.toInt()
338 | } else {
339 | targetViewY - toolTipMeasuredHeight - adjustment.toInt()
340 | }
341 | else -> // this is center
342 | if (gravity and Gravity.LEFT == Gravity.LEFT || gravity and Gravity.RIGHT == Gravity.RIGHT) {
343 | targetViewY + highlightedView.height - adjustment.toInt()
344 | } else {
345 | targetViewY + highlightedView.height + adjustment.toInt()
346 | }
347 | }
348 |
349 | private fun setupAndAddFABToFrameLayout(frameLayoutWithHole: FrameLayoutWithHole): FloatingActionButton {
350 | // invisFab is invisible, and it's only used for getting the width and height
351 | val invisFab = FloatingActionButton(activity)
352 | invisFab.size = FloatingActionButton.SIZE_MINI
353 | invisFab.visibility = View.INVISIBLE
354 | (activity.window.decorView as ViewGroup).addView(invisFab)
355 |
356 | // fab is the real fab that is going to be added
357 | return FloatingActionButton(activity).apply {
358 | setBackgroundColor(Color.BLUE)
359 | size = FloatingActionButton.SIZE_MINI
360 | mPointer?.also { colorNormal = it.color }
361 | isStrokeVisible = false
362 | isClickable = false
363 |
364 | // When invisFab is layouted, it's width and height can be used to calculate the correct position of fab
365 | invisFab.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
366 | override fun onGlobalLayout() {
367 | // make sure this only run once
368 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
369 |
370 | invisFab.viewTreeObserver.removeGlobalOnLayoutListener(this)
371 | } else {
372 | invisFab.viewTreeObserver.removeOnGlobalLayoutListener(this)
373 | }
374 | val params = FrameLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)
375 | frameLayoutWithHole.addView(this@apply, params)
376 |
377 | // measure size of image to be placed
378 | params.setMargins(getXBasedOnGravity(invisFab.width), getYBasedOnGravity(invisFab.height), 0, 0)
379 | }
380 | })
381 | }
382 | }
383 |
384 | private fun setupFrameLayout() {
385 | val layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)
386 | val contentArea = activity.window.decorView.findViewById(android.R.id.content) as ViewGroup
387 | val pos = IntArray(2)
388 | contentArea.getLocationOnScreen(pos)
389 | // frameLayoutWithHole's coordinates are calculated taking full screen height into account
390 | // but we're adding it to the content area only, so we need to offset it to the same Y value of contentArea
391 |
392 | layoutParams.setMargins(0, -pos[1], 0, 0)
393 | contentArea.addView(frameLayoutWithHole, layoutParams)
394 | }
395 |
396 | private fun performAnimationOn(view: View) {
397 |
398 | if (technique == Technique.HORIZONTAL_LEFT) {
399 |
400 | val animatorSet = AnimatorSet()
401 | val animatorSet2 = AnimatorSet()
402 | val lis1 = object : Animator.AnimatorListener {
403 | override fun onAnimationStart(animator: Animator) {}
404 | override fun onAnimationCancel(animator: Animator) {}
405 | override fun onAnimationRepeat(animator: Animator) {}
406 | override fun onAnimationEnd(animator: Animator) {
407 | view.scaleX = 1f
408 | view.scaleY = 1f
409 | view.translationX = 0f
410 | animatorSet2.start()
411 | }
412 | }
413 | val lis2 = object : Animator.AnimatorListener {
414 | override fun onAnimationStart(animator: Animator) {}
415 | override fun onAnimationCancel(animator: Animator) {}
416 | override fun onAnimationRepeat(animator: Animator) {}
417 | override fun onAnimationEnd(animator: Animator) {
418 | view.scaleX = 1f
419 | view.scaleY = 1f
420 | view.translationX = 0f
421 | animatorSet.start()
422 | }
423 | }
424 |
425 | val fadeInDuration: Long = 800
426 | val scaleDownDuration: Long = 800
427 | val goLeftXDuration: Long = 2000
428 | val translationX = (screenWidth / 2).toFloat()
429 |
430 | val fadeInAnim = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f)
431 | fadeInAnim.duration = fadeInDuration
432 | val scaleDownX = ObjectAnimator.ofFloat(view, "scaleX", 1f, 0.85f)
433 | scaleDownX.duration = scaleDownDuration
434 | val scaleDownY = ObjectAnimator.ofFloat(view, "scaleY", 1f, 0.85f)
435 | scaleDownY.duration = scaleDownDuration
436 | val goLeftX = ObjectAnimator.ofFloat(view, "translationX", -translationX)
437 | goLeftX.duration = goLeftXDuration
438 | val fadeOutAnim = ObjectAnimator.ofFloat(view, "alpha", 1f, 0f)
439 | fadeOutAnim.duration = goLeftXDuration
440 |
441 | val fadeInAnim2 = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f)
442 | fadeInAnim2.duration = fadeInDuration
443 | val scaleDownX2 = ObjectAnimator.ofFloat(view, "scaleX", 1f, 0.85f)
444 | scaleDownX2.duration = scaleDownDuration
445 | val scaleDownY2 = ObjectAnimator.ofFloat(view, "scaleY", 1f, 0.85f)
446 | scaleDownY2.duration = scaleDownDuration
447 | val goLeftX2 = ObjectAnimator.ofFloat(view, "translationX", -translationX)
448 | goLeftX2.duration = goLeftXDuration
449 | val fadeOutAnim2 = ObjectAnimator.ofFloat(view, "alpha", 1f, 0f)
450 | fadeOutAnim2.duration = goLeftXDuration
451 |
452 | animatorSet.play(fadeInAnim)
453 | animatorSet.play(scaleDownX).with(scaleDownY).after(fadeInAnim)
454 | animatorSet.play(goLeftX).with(fadeOutAnim).after(scaleDownY)
455 |
456 | animatorSet2.play(fadeInAnim2)
457 | animatorSet2.play(scaleDownX2).with(scaleDownY2).after(fadeInAnim2)
458 | animatorSet2.play(goLeftX2).with(fadeOutAnim2).after(scaleDownY2)
459 |
460 | animatorSet.addListener(lis1)
461 | animatorSet2.addListener(lis2)
462 | animatorSet.start()
463 |
464 | /* these animatorSets are kept track in FrameLayout, so that they can be cleaned up when FrameLayout is detached from window */
465 | frameLayoutWithHole?.addAnimatorSet(animatorSet)
466 | frameLayoutWithHole?.addAnimatorSet(animatorSet2)
467 | } else if (technique == Technique.HORIZONTAL_RIGHT) { //TODO: new feature
468 |
469 | } else if (technique == Technique.VERTICAL_UPWARD) {//TODO: new feature
470 |
471 | } else if (technique == Technique.VERTICAL_DOWNWARD) {//TODO: new feature
472 |
473 | } else { // do click for default case
474 | val animatorSet = AnimatorSet()
475 | val animatorSet2 = AnimatorSet()
476 | val lis1 = object : Animator.AnimatorListener {
477 | override fun onAnimationStart(animator: Animator) {}
478 | override fun onAnimationCancel(animator: Animator) {}
479 | override fun onAnimationRepeat(animator: Animator) {}
480 | override fun onAnimationEnd(animator: Animator) {
481 | view.scaleX = 1f
482 | view.scaleY = 1f
483 | view.translationX = 0f
484 | animatorSet2.start()
485 | }
486 | }
487 | val lis2 = object : Animator.AnimatorListener {
488 | override fun onAnimationStart(animator: Animator) {}
489 | override fun onAnimationCancel(animator: Animator) {}
490 | override fun onAnimationRepeat(animator: Animator) {}
491 | override fun onAnimationEnd(animator: Animator) {
492 | view.scaleX = 1f
493 | view.scaleY = 1f
494 | view.translationX = 0f
495 | animatorSet.start()
496 | }
497 | }
498 |
499 | val fadeInDuration: Long = 800
500 | val scaleDownDuration: Long = 800
501 | val fadeOutDuration: Long = 800
502 | val delay: Long = 1000
503 |
504 | val delayAnim = ObjectAnimator.ofFloat(view, "translationX", 0f)
505 | delayAnim.setDuration(delay)
506 | val fadeInAnim = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f)
507 | fadeInAnim.duration = fadeInDuration
508 | val scaleDownX = ObjectAnimator.ofFloat(view, "scaleX", 1f, 0.85f)
509 | scaleDownX.duration = scaleDownDuration
510 | val scaleDownY = ObjectAnimator.ofFloat(view, "scaleY", 1f, 0.85f)
511 | scaleDownY.duration = scaleDownDuration
512 | val scaleUpX = ObjectAnimator.ofFloat(view, "scaleX", 0.85f, 1f)
513 | scaleUpX.duration = scaleDownDuration
514 | val scaleUpY = ObjectAnimator.ofFloat(view, "scaleY", 0.85f, 1f)
515 | scaleUpY.duration = scaleDownDuration
516 | val fadeOutAnim = ObjectAnimator.ofFloat(view, "alpha", 1f, 0f)
517 | fadeOutAnim.duration = fadeOutDuration
518 |
519 | val delayAnim2 = ObjectAnimator.ofFloat(view, "translationX", 0f)
520 | delayAnim2.setDuration(delay)
521 | val fadeInAnim2 = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f)
522 | fadeInAnim2.duration = fadeInDuration
523 | val scaleDownX2 = ObjectAnimator.ofFloat(view, "scaleX", 1f, 0.85f)
524 | scaleDownX2.duration = scaleDownDuration
525 | val scaleDownY2 = ObjectAnimator.ofFloat(view, "scaleY", 1f, 0.85f)
526 | scaleDownY2.duration = scaleDownDuration
527 | val scaleUpX2 = ObjectAnimator.ofFloat(view, "scaleX", 0.85f, 1f)
528 | scaleUpX2.duration = scaleDownDuration
529 | val scaleUpY2 = ObjectAnimator.ofFloat(view, "scaleY", 0.85f, 1f)
530 | scaleUpY2.duration = scaleDownDuration
531 | val fadeOutAnim2 = ObjectAnimator.ofFloat(view, "alpha", 1f, 0f)
532 | fadeOutAnim2.duration = fadeOutDuration
533 | view.alpha = 0f
534 | animatorSet.startDelay = toolTip?.run { mEnterAnimation.duration } ?: 0
535 | animatorSet.play(fadeInAnim)
536 | animatorSet.play(scaleDownX).with(scaleDownY).after(fadeInAnim)
537 | animatorSet.play(scaleUpX).with(scaleUpY).with(fadeOutAnim).after(scaleDownY)
538 | animatorSet.play(delayAnim).after(scaleUpY)
539 |
540 | animatorSet2.play(fadeInAnim2)
541 | animatorSet2.play(scaleDownX2).with(scaleDownY2).after(fadeInAnim2)
542 | animatorSet2.play(scaleUpX2).with(scaleUpY2).with(fadeOutAnim2).after(scaleDownY2)
543 | animatorSet2.play(delayAnim2).after(scaleUpY2)
544 |
545 | animatorSet.addListener(lis1)
546 | animatorSet2.addListener(lis2)
547 | animatorSet.start()
548 |
549 | /* these animatorSets are kept track in FrameLayout, so that they can be cleaned up when FrameLayout is detached from window */
550 | frameLayoutWithHole?.addAnimatorSet(animatorSet)
551 | frameLayoutWithHole?.addAnimatorSet(animatorSet2)
552 | }
553 | }
554 |
555 | fun pointer(block: Pointer.() -> Unit) {
556 | mPointer = Pointer().apply { block() }
557 | }
558 |
559 | fun toolTip(block: ToolTip.() -> Unit) {
560 | toolTip = ToolTip().apply { block() }
561 | }
562 |
563 | fun overlay(block: Overlay.() -> Unit) {
564 | overlay = Overlay().apply { block() }
565 | }
566 |
567 | companion object {
568 | @JvmStatic
569 | open fun init(activity: Activity) = TourGuide(activity)
570 |
571 | fun create(activity: Activity, block: TourGuide.() -> Unit): TourGuide {
572 | return TourGuide(activity).apply { block() }
573 | }
574 | }
575 | }
576 |
--------------------------------------------------------------------------------
/tourguide/src/main/java/tourguide/tourguide/util/MotionEventExtension.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguide.util
2 |
3 | import android.view.MotionEvent
4 |
5 | /**
6 | * Show an event in the LogCat view, for debugging
7 | */
8 | fun MotionEvent.dumpEvent() {
9 | val event = this
10 | val names = arrayOf("DOWN", "UP", "MOVE", "CANCEL", "OUTSIDE", "POINTER_DOWN", "POINTER_UP", "7?", "8?", "9?")
11 | val sb = StringBuilder()
12 | val action = event.action
13 | val actionCode = action and MotionEvent.ACTION_MASK
14 | sb.append("event ACTION_").append(names[actionCode])
15 | if (actionCode == MotionEvent.ACTION_POINTER_DOWN || actionCode == MotionEvent.ACTION_POINTER_UP) {
16 | sb.append("(pid ").append(
17 | action shr MotionEvent.ACTION_POINTER_ID_SHIFT)
18 | sb.append(")")
19 | }
20 | sb.append("[")
21 | for (i in 0 until event.pointerCount) {
22 | sb.append("#").append(i)
23 | sb.append("(pid ").append(event.getPointerId(i))
24 | sb.append(")=").append(event.getX(i).toInt())
25 | sb.append(",").append(event.getY(i).toInt())
26 | if (i + 1 < event.pointerCount)
27 | sb.append(";")
28 | }
29 | sb.append("]")
30 | }
--------------------------------------------------------------------------------
/tourguide/src/main/java/tourguide/tourguide/util/StandardExtension.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguide.util
2 |
3 | /**
4 | * example usage:
5 | * ```
6 | *
7 | * var recipe: String? = null
8 | * var uri: Boolean? = null
9 | *
10 | * recipe.let(uri) { recipe, uri ->
11 | * // safe usage here
12 | * }
13 | * }
14 | * ```
15 | */
16 | inline fun T?.letWith(secondArg: T2?, block: (T, T2) -> R): R? {
17 | return this?.let {
18 | secondArg?.let {
19 | block(this, secondArg)
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/tourguide/src/main/java/tourguide/tourguide/util/ViewExtension.kt:
--------------------------------------------------------------------------------
1 | package tourguide.tourguide.util
2 |
3 | import android.graphics.Point
4 | import android.view.View
5 |
6 | val View.locationOnScreen: Point
7 | get() = IntArray(2).let {
8 | getLocationOnScreen(it)
9 | Point(it[0], it[1])
10 | }
11 |
--------------------------------------------------------------------------------
/tourguide/src/main/res/drawable-xhdpi/tourguide_drop_shadow.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/worker8/TourGuide/949c4a484cb98febcc223d19d960dbc2f5c5a4c4/tourguide/src/main/res/drawable-xhdpi/tourguide_drop_shadow.9.png
--------------------------------------------------------------------------------
/tourguide/src/main/res/drawable/tourguide_shadow_upward.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
--------------------------------------------------------------------------------
/tourguide/src/main/res/layout/tourguide_tooltip.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
21 |
22 |
30 |
31 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/tourguide/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FF33E5B5
4 | #10FFFFFF
5 | #FFFFFF
6 | #FFFFF0
7 | #FFFFE0
8 | #FFFF00
9 | #FFFAFA
10 | #FFFAF0
11 | #FFFACD
12 | #FFF8DC
13 | #FFF5EE
14 | #FFF0F5
15 | #FFEFD5
16 | #FFEBCD
17 | #FFE4E1
18 | #FFE4C4
19 | #FFE4B5
20 | #FFDEAD
21 | #FFDAB9
22 | #FFD700
23 | #FFC0CB
24 | #FFB6C1
25 | #FFA500
26 | #FFA07A
27 | #FF8C00
28 | #FF7F50
29 | #FF69B4
30 | #FF6347
31 | #FF4500
32 | #FF1493
33 | #FF00FF
34 | #FF00FF
35 | #FF0000
36 | #FDF5E6
37 | #FAFAD2
38 | #FAF0E6
39 | #FAEBD7
40 | #FA8072
41 | #F8F8FF
42 | #F5FFFA
43 | #F5F5F5
44 | #F5F5DC
45 | #F5DEB3
46 | #F4A460
47 | #F0FFFF
48 | #F0FFF0
49 | #F0F8FF
50 | #F0E68C
51 | #F08080
52 | #EEE8AA
53 | #EE82EE
54 | #E9967A
55 | #E6E6FA
56 | #E0FFFF
57 | #DEB887
58 | #DDA0DD
59 | #DCDCDC
60 | #DC143C
61 | #DB7093
62 | #DAA520
63 | #DA70D6
64 | #D8BFD8
65 | #D3D3D3
66 | #D2B48C
67 | #D2691E
68 | #CD853F
69 | #CD5C5C
70 | #C71585
71 | #C0C0C0
72 | #BDB76B
73 | #BC8F8F
74 | #BA55D3
75 | #B8860B
76 | #B22222
77 | #B0E0E6
78 | #B0C4DE
79 | #AFEEEE
80 | #ADFF2F
81 | #ADD8E6
82 | #A9A9A9
83 | #88A9A9A9
84 | #FFA9A9A9
85 | #A52A2A
86 | #A0522D
87 | #9ACD32
88 | #9932CC
89 | #98FB98
90 | #9400D3
91 | #9370DB
92 | #90EE90
93 | #8FBC8F
94 | #8B4513
95 | #8B008B
96 | #8B0000
97 | #8A2BE2
98 | #87CEFA
99 | #87CEEB
100 | #808080
101 | #808000
102 | #800080
103 | #800000
104 | #7FFFD4
105 | #7FFF00
106 | #7CFC00
107 | #7B68EE
108 | #778899
109 | #708090
110 | #6B8E23
111 | #6A5ACD
112 | #696969
113 | #66CDAA
114 | #6495ED
115 | #5F9EA0
116 | #556B2F
117 | #4B0082
118 | #48D1CC
119 | #483D8B
120 | #4682B4
121 | #4169E1
122 | #40E0D0
123 | #3CB371
124 | #32CD32
125 | #2F4F4F
126 | #2E8B57
127 | #228B22
128 | #20B2AA
129 | #1E90FF
130 | #191970
131 | #00FFFF
132 | #00FFFF
133 | #00FF7F
134 | #00FF00
135 | #00FA9A
136 | #00CED1
137 | #00BFFF
138 | #008B8B
139 | #008080
140 | #008000
141 | #006400
142 | #0000FF
143 | #0000CD
144 | #00008B
145 | #000080
146 | #66000000
147 | #000000
148 |
149 | - @color/holo_blue_dark
150 | - @color/holo_yellow_dark
151 | - @color/holo_green_dark
152 | - @color/holo_purple_dark
153 | - @color/holo_red_dark
154 |
155 |
156 |
157 | - @color/Green
158 |
159 |
160 |
161 | - @color/gplus_color_1
162 | - @color/gplus_color_2
163 | - @color/gplus_color_3
164 | - @color/gplus_color_4
165 |
166 |
167 |
168 | - @color/pocket_color_1
169 | - @color/pocket_color_1
170 | - @color/pocket_color_1
171 | - @color/pocket_color_1
172 | - @color/pocket_color_2
173 | - @color/pocket_color_2
174 | - @color/pocket_color_2
175 | - @color/pocket_color_2
176 | - @color/pocket_color_3
177 | - @color/pocket_color_3
178 | - @color/pocket_color_3
179 | - @color/pocket_color_3
180 | - @color/pocket_color_4
181 | - @color/pocket_color_4
182 | - @color/pocket_color_4
183 | - @color/pocket_color_4
184 |
185 |
186 |
187 | - @color/pocket_color_1
188 | - @color/pocket_color_2
189 | - @color/pocket_color_3
190 | - @color/pocket_color_4
191 |
192 |
193 | #85edb9
194 | #34bdb7
195 | #ee4458
196 | #fcb74d
197 |
198 | #3e802f
199 | #f4b400
200 | #427fed
201 | #b23424
202 |
203 | #0099cc
204 | #ff8800
205 | #669900
206 | #9933cc
207 | #cc0000
208 | //Color Swatches provided by http://designmodo.github.io/Flat-UI/
209 | #1abc9c
210 | #16a085
211 | #2ecc71
212 | #27ae60
213 | #3498db
214 | #2980b9
215 | #9b59b6
216 | #8e44ad
217 | #34495e
218 | #2c3e50
219 | #f1c40f
220 | #f39c12
221 | #e67e22
222 | #d35400
223 | #e74c3c
224 | #c0392b
225 | #ecf0f1
226 | #bdc3c7
227 | #95a5a6
228 | #7f8c8d
229 |
230 |
231 | #30f1c40f
232 |
--------------------------------------------------------------------------------
/update_version.rb:
--------------------------------------------------------------------------------
1 | @version_name_regex = /VERSION_NAME=(.*)/
2 | @version_code_regex = /VERSION_CODE=(.*)/
3 | @file_name = "gradle.properties"
4 |
5 | def update_version_name
6 |
7 | text = File.read(@file_name)
8 |
9 | versionName = @version_name_regex.match(text)[0].split('=')[1]
10 | # 2.0.0-SNAPSHOT
11 |
12 | versionNumber = versionName.split('-')[0]
13 | # 2.0.0
14 |
15 | (major, minor, patch) = versionNumber.split(".")
16 |
17 | major = (major.to_i + 0).to_s
18 | minor = (minor.to_i + 0).to_s
19 | patch = (patch.to_i + 1).to_s
20 |
21 | newVersionNumber = [major, minor, patch].join(".")
22 | # 2.0.1
23 |
24 | newVersionName = "#{newVersionNumber}-SNAPSHOT"
25 | # 2.0.1-SNAPSHOT
26 |
27 | # VERSION_NAME=2.0.0-SNAPSHOT
28 | new_content = text.gsub(@version_name_regex, "VERSION_NAME=#{newVersionName}")
29 | # VERSION_NAME=2.0.1-SNAPSHOT
30 |
31 | File.open(@file_name, "w") {|file| file.puts new_content }
32 | end
33 |
34 | def update_version_code
35 | text = File.read(@file_name)
36 | versionCode = @version_code_regex.match(text)[0].split('=')[1]
37 | # 20
38 |
39 | newVersionCode = (versionCode.to_i + 1).to_s
40 | # 21
41 |
42 | # VERSION_CODE=20
43 | new_content = text.gsub(@version_code_regex, "VERSION_CODE=#{newVersionCode}")
44 | # VERSION_CODE=21
45 |
46 | File.open(@file_name, "w") {|file| file.puts new_content }
47 | end
48 |
49 | update_version_name
50 | update_version_code
51 |
--------------------------------------------------------------------------------