From 3374e0528ed352c05b7827a158f717f6e1c48a1c Mon Sep 17 00:00:00 2001 From: konifar Date: Thu, 21 Jun 2018 15:58:16 +0900 Subject: [PATCH] Added custom usage activity --- example/src/main/AndroidManifest.xml | 5 ++ .../example/CustomUsageActivity.kt | 78 +++++++++++++++++++ .../example/MainActivity.kt | 2 +- .../main/res/layout/activity_custom_usage.xml | 51 +++++------- ...ayout_instruction_simple_message_black.xml | 4 +- example/src/main/res/values/styles.xml | 6 ++ 6 files changed, 113 insertions(+), 33 deletions(-) create mode 100644 example/src/main/java/co/kyash/androidtargetinstructions/example/CustomUsageActivity.kt diff --git a/example/src/main/AndroidManifest.xml b/example/src/main/AndroidManifest.xml index 41b4f1d..5e3961b 100644 --- a/example/src/main/AndroidManifest.xml +++ b/example/src/main/AndroidManifest.xml @@ -27,6 +27,11 @@ android:name=".SimpleUsageActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:exported="false" /> + + \ No newline at end of file diff --git a/example/src/main/java/co/kyash/androidtargetinstructions/example/CustomUsageActivity.kt b/example/src/main/java/co/kyash/androidtargetinstructions/example/CustomUsageActivity.kt new file mode 100644 index 0000000..2f29f61 --- /dev/null +++ b/example/src/main/java/co/kyash/androidtargetinstructions/example/CustomUsageActivity.kt @@ -0,0 +1,78 @@ +package co.kyash.androidtargetinstructions.example + +import android.content.Context +import android.content.Intent +import android.databinding.DataBindingUtil +import android.os.Bundle +import android.os.Handler +import android.support.v7.app.AppCompatActivity +import android.view.ViewTreeObserver +import co.kyash.androidtargetinstructions.example.databinding.ActivityCustomUsageBinding +import co.kyash.targetinstructions.TargetInstructions +import co.kyash.targetinstructions.targets.SimpleTarget +import co.kyash.targetinstructions.targets.Target + + +class CustomUsageActivity : AppCompatActivity() { + + companion object { + fun createIntent(context: Context) = Intent(context, CustomUsageActivity::class.java) + } + + private lateinit var binding: ActivityCustomUsageBinding + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + binding = DataBindingUtil.setContentView(this, R.layout.activity_custom_usage) + + binding.root.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { + override fun onGlobalLayout() { + binding.root.viewTreeObserver.removeOnGlobalLayoutListener(this) + showInstructions() + } + }) + + binding.toolbar.setNavigationOnClickListener { + finish() + } + + binding.fab.setOnClickListener { + binding.scrollview.smoothScrollTo(0, 0) + Handler().postDelayed({ + showInstructions() + }, 150) + } + } + + private fun showInstructions() { + val target1 = SimpleTarget.Builder(this@CustomUsageActivity).setTarget(binding.fab) + .setTitle("Floating Action Button") + .setHighlightRadius(100f) + .setDescription("This is the floating action button.") + .build() + + val target2 = SimpleTarget.Builder(this@CustomUsageActivity).setTarget(binding.firstText) + .setTitle("First text") + .setDescription("This is the first text. After this is hidden, the view scrolls to bottom.") + .setHighlightPadding(R.dimen.simple_highlight_padding) + .setListener(object : Target.OnStateChangedListener { + override fun onClosed() { + binding.scrollview.smoothScrollBy(0, 10000) + } + }) + .build() + + val target3 = SimpleTarget.Builder(this@CustomUsageActivity).setTarget(binding.secondText) + .setTitle("Second text") + .setDescription("This is the second text. This is customized instruction.") + .setMessageLayoutResId(R.layout.layout_instruction_simple_message_black) + .setHighlightHorizontalPadding(R.dimen.space_16dp) + .setStartDelayMillis(500L) + .build() + + TargetInstructions.with(this@CustomUsageActivity) + .setTargets(arrayListOf(target1, target2, target3)) + .start() + } + +} \ No newline at end of file diff --git a/example/src/main/java/co/kyash/androidtargetinstructions/example/MainActivity.kt b/example/src/main/java/co/kyash/androidtargetinstructions/example/MainActivity.kt index fc99968..06a6845 100644 --- a/example/src/main/java/co/kyash/androidtargetinstructions/example/MainActivity.kt +++ b/example/src/main/java/co/kyash/androidtargetinstructions/example/MainActivity.kt @@ -15,7 +15,7 @@ class MainActivity : AppCompatActivity() { startActivity(SimpleUsageActivity.createIntent(this@MainActivity)) } customUsage.setOnClickListener { - + startActivity(CustomUsageActivity.createIntent(this@MainActivity)) } } } diff --git a/example/src/main/res/layout/activity_custom_usage.xml b/example/src/main/res/layout/activity_custom_usage.xml index c5dd4f0..b4022c4 100644 --- a/example/src/main/res/layout/activity_custom_usage.xml +++ b/example/src/main/res/layout/activity_custom_usage.xml @@ -1,7 +1,6 @@ + xmlns:app="http://schemas.android.com/apk/res-auto"> + style="@style/Toolbar.Back" + app:title="Custom Usage" /> - - - - - - + android:orientation="vertical" + android:padding="@dimen/space_16dp"> + android:background="@color/white" + android:gravity="center" + android:padding="@dimen/space_16dp" + android:text="First text" /> - + android:background="@color/white" + android:padding="@dimen/space_16dp" + android:text="Long scroll" /> + android:text="Second text" /> @style/TextAppearance.AppCompat.Title + +