Skip to content

Commit

Permalink
Added custom usage activity
Browse files Browse the repository at this point in the history
  • Loading branch information
konifar committed Jun 21, 2018
1 parent c432715 commit 3374e05
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 33 deletions.
5 changes: 5 additions & 0 deletions example/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
android:name=".SimpleUsageActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:exported="false" />

<activity
android:name=".CustomUsageActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:exported="false" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -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()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MainActivity : AppCompatActivity() {
startActivity(SimpleUsageActivity.createIntent(this@MainActivity))
}
customUsage.setOnClickListener {

startActivity(CustomUsageActivity.createIntent(this@MainActivity))
}
}
}
Expand Down
51 changes: 21 additions & 30 deletions example/src/main/res/layout/activity_custom_usage.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
xmlns:app="http://schemas.android.com/apk/res-auto">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/theme"
android:elevation="4dp"
app:elevation="4dp"
app:title="@string/app_name"
app:titleTextColor="@color/white"
tools:targetApi="lollipop" />
style="@style/Toolbar.Back"
app:title="Custom Usage" />

<ScrollView
android:id="@+id/scrollview"
Expand All @@ -27,41 +20,39 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
style="@style/Title"
android:padding="@dimen/space_16dp"
android:text="Simple Usage" />

<View style="@style/Border" />

<TextView
style="@style/Title"
android:padding="@dimen/space_16dp"
android:text="Custom Usage" />
android:orientation="vertical"
android:padding="@dimen/space_16dp">

<TextView
android:id="@+id/first_text"
style="@style/Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="First text"
android:textSize="20dp" />
android:background="@color/white"
android:gravity="center"
android:padding="@dimen/space_16dp"
android:text="First text" />

<View
<TextView
style="@style/Subhead"
android:layout_width="match_parent"
android:layout_height="1000dp"
android:layout_height="800dp"
android:layout_marginTop="@dimen/space_16dp"
android:background="@color/red" />
android:background="@color/white"
android:padding="@dimen/space_16dp"
android:text="Long scroll" />

<TextView
android:id="@+id/second_text"
style="@style/Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="@dimen/space_16dp"
android:background="@color/white"
android:padding="@dimen/space_16dp"
android:text="Second text"
android:textSize="20dp" />
android:text="Second text" />

<View
android:layout_width="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="8dp"
android:paddingEnd="48dp"
android:paddingStart="48dp"
android:paddingTop="8dp"
android:paddingEnd="48dp"
android:paddingBottom="8dp"
android:visibility="invisible">

<ImageView
Expand Down
6 changes: 6 additions & 0 deletions example/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
<item name="android:textAppearance">@style/TextAppearance.AppCompat.Title</item>
</style>

<style name="Subhead">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textAppearance">@style/TextAppearance.AppCompat.Subhead</item>
</style>

<style name="Row">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
Expand Down

0 comments on commit 3374e05

Please sign in to comment.