Create 5 empty tabs / fragments for the tutorial

(Start, Concept, Usage, Setup, Finish)
This commit is contained in:
Finn M Glas 2020-06-23 08:58:16 +02:00
parent 3703c5e344
commit e1f88e546d
No known key found for this signature in database
GPG key ID: 902A30146014DFBF
13 changed files with 249 additions and 129 deletions

View file

@ -9,7 +9,7 @@ import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import androidx.viewpager.widget.ViewPager
import com.finnmglas.launcher.*
import com.finnmglas.launcher.tutorial.tab.TutorialFragmentTab
import com.finnmglas.launcher.tutorial.tab.*
import com.google.android.material.tabs.TabLayout
import kotlinx.android.synthetic.main.tutorial.*
@ -22,23 +22,18 @@ import kotlinx.android.synthetic.main.tutorial.*
*/
class TutorialActivity: AppCompatActivity(), UIObject {
private var defaultApps = mutableListOf<String>()
private var isFirstTime = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Initialise layout
setContentView(R.layout.tutorial)
// Check if it is the first time starting the app
isFirstTime = !launcherPreferences.getBoolean("startedBefore", false)
if (isFirstTime)
defaultApps = resetSettings(this) // UP, DOWN, RIGHT, LEFT, VOLUME_UP, VOLUME_DOWN
else tutorial_appbar.visibility = View.VISIBLE
// Check if the app was started before
if (launcherPreferences.getBoolean("startedBefore", false))
tutorial_appbar.visibility = View.VISIBLE
// set up tabs and swiping in settings
val sectionsPagerAdapter = TutorialSectionsPagerAdapter(this, supportFragmentManager, defaultApps, isFirstTime)
val sectionsPagerAdapter = TutorialSectionsPagerAdapter(this, supportFragmentManager)
val viewPager: ViewPager = findViewById(R.id.tutorial_viewpager)
viewPager.adapter = sectionsPagerAdapter
val tabs: TabLayout = findViewById(R.id.tutorial_tabs)
@ -61,21 +56,27 @@ class TutorialActivity: AppCompatActivity(), UIObject {
}
}
class TutorialSectionsPagerAdapter(private val context: Context, fm: FragmentManager,
val defaultApps: MutableList<String>, val isFirstTime: Boolean)
/**
* The [TutorialSectionsPagerAdapter] defines which fragments are shown when,
* in the [TutorialActivity].
*
* Tabs: (Start | Concept | Usage | Setup | Finish)
*/
class TutorialSectionsPagerAdapter(private val context: Context, fm: FragmentManager)
: FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
override fun getItem(position: Int): Fragment {
return when (position){
0 -> TutorialFragmentTab(defaultApps, isFirstTime, position)
1 -> TutorialFragmentTab(defaultApps, isFirstTime, position)
else -> TutorialFragmentTab(defaultApps, isFirstTime, position)
0 -> TutorialFragmentStart()
1 -> TutorialFragmentConcept()
2 -> TutorialFragmentUsage()
3 -> TutorialFragmentSetup()
4 -> TutorialFragmentFinish()
else -> Fragment()
}
}
override fun getPageTitle(position: Int): CharSequence? {
return ""
}
override fun getCount(): Int { return 9 }
/* We don't use titles here, as we have the dots */
override fun getPageTitle(position: Int): CharSequence? { return "" }
override fun getCount(): Int { return 5 }
}

View file

@ -0,0 +1,33 @@
package com.finnmglas.launcher.tutorial.tab
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.finnmglas.launcher.*
import kotlinx.android.synthetic.main.tutorial_concept.*
/**
* The [TutorialFragmentConcept] is a used as a tab in the TutorialActivity.
*
* It is used to display info about Launchers concept (open source, efficiency ...)
*/
class TutorialFragmentConcept(): Fragment(), UIObject {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.tutorial_concept, container, false)
}
override fun onStart(){
super<Fragment>.onStart()
super<UIObject>.onStart()
}
override fun applyTheme() {
tutorial_concept_container.setBackgroundColor(dominantColor)
}
}

View file

@ -0,0 +1,43 @@
package com.finnmglas.launcher.tutorial.tab
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.finnmglas.launcher.*
import kotlinx.android.synthetic.main.tutorial_finish.*
/**
* The [TutorialFragmentFinish] is a used as a tab in the TutorialActivity.
*
* It is used to display further resources and let the user start Launcher
*/
class TutorialFragmentFinish(): Fragment(), UIObject {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.tutorial_finish, container, false)
}
override fun onStart() {
super<Fragment>.onStart()
super<UIObject>.onStart()
}
override fun applyTheme() {
tutorial_finish_container.setBackgroundColor(dominantColor)
}
fun go() {
if (!launcherPreferences.getBoolean("startedBefore", false)){
launcherPreferences.edit()
.putBoolean("startedBefore", true) // never auto run this again
.putLong("firstStartup", System.currentTimeMillis() / 1000L) // record first startup timestamp
.apply()
}
activity!!.finish()
}
}

View file

@ -0,0 +1,36 @@
package com.finnmglas.launcher.tutorial.tab
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.finnmglas.launcher.*
import kotlinx.android.synthetic.main.tutorial_setup.*
/**
* The [TutorialFragmentSetup] is a used as a tab in the TutorialActivity.
*
* It is used to display info in the tutorial
*/
class TutorialFragmentSetup(): Fragment(), UIObject {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.tutorial_setup, container, false)
}
override fun onStart(){
var defaultApps = mutableListOf<String>()
defaultApps = resetSettings(context!!) // UP, DOWN, RIGHT, LEFT, VOLUME_UP, VOLUME_DOWN
super<Fragment>.onStart()
super<UIObject>.onStart()
}
override fun applyTheme() {
tutorial_setup_container.setBackgroundColor(dominantColor)
}
}

View file

@ -0,0 +1,33 @@
package com.finnmglas.launcher.tutorial.tab
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.finnmglas.launcher.*
import kotlinx.android.synthetic.main.tutorial_start.*
/**
* The [TutorialFragmentStart] is a used as a tab in the TutorialActivity.
*
* It displays info about the app and gets the user into the tutorial
*/
class TutorialFragmentStart(): Fragment(), UIObject {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.tutorial_start, container, false)
}
override fun onStart(){
super<Fragment>.onStart()
super<UIObject>.onStart()
}
override fun applyTheme() {
tutorial_start_container.setBackgroundColor(dominantColor)
}
}

View file

@ -1,67 +0,0 @@
package com.finnmglas.launcher.tutorial.tab
import android.content.Context
import android.os.Bundle
import android.util.TypedValue
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.finnmglas.launcher.*
import kotlinx.android.synthetic.main.tutorial_tab.*
/**
* The [TutorialFragmentTab] is a used as a tab in the TutorialActivity.
*
* It is used to display info in the tutorial
*/
class TutorialFragmentTab(var defaultApps: MutableList<String>, val isFirstTime: Boolean, val n: Int): Fragment(), UIObject {
private var menuNumber = 0
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.tutorial_tab, container, false)
}
override fun onStart(){
menuNumber = n
loadMenu(context!!)
super<Fragment>.onStart()
super<UIObject>.onStart()
}
override fun applyTheme() {
tutorial_tab_container.setBackgroundColor(dominantColor)
}
private fun loadMenu(context: Context) { // Context needed for packageManager
val intro = resources.getStringArray(R.array.intro)
if (menuNumber < intro.size){
val entry = intro[menuNumber].split("|").toTypedArray() //heading|infoText|hintText|size
tutorial_tab_heading.text = entry[0]
if (entry[4] == "1" && isFirstTime)
tutorial_tab_text.text = String.format(entry[1],
defaultApps[0], defaultApps[1], defaultApps[2], defaultApps[3], defaultApps[4], defaultApps[5])
else if (entry[4] == "1" && !isFirstTime)
tutorial_tab_text.text = String.format(entry[1],
"-", "-", "-", "-", "-", "-")
else tutorial_tab_text.text = entry[1]
tutorial_tab_text.setTextSize(TypedValue.COMPLEX_UNIT_SP, entry[3].toFloat())
} else if (menuNumber > intro.size) { // End intro
if (isFirstTime){
launcherPreferences.edit()
.putBoolean("startedBefore", true) // never auto run this again
.putLong("firstStartup", System.currentTimeMillis() / 1000L) // record first startup timestamp
.apply()
}
activity!!.finish()
}
}
}

View file

@ -0,0 +1,33 @@
package com.finnmglas.launcher.tutorial.tab
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.finnmglas.launcher.*
import kotlinx.android.synthetic.main.tutorial_usage.*
/**
* The [TutorialFragmentUsage] is a used as a tab in the TutorialActivity.
*
* Tells the user how his screen will look and how the app can be used
*/
class TutorialFragmentUsage(): Fragment(), UIObject {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.tutorial_usage, container, false)
}
override fun onStart(){
super<Fragment>.onStart()
super<UIObject>.onStart()
}
override fun applyTheme() {
tutorial_usage_container.setBackgroundColor(dominantColor)
}
}

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
android:id="@+id/tutorial_concept_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorPrimary"
tools:context=".tutorial.tab.TutorialFragmentConcept"/>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
android:id="@+id/tutorial_finish_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorPrimary"
tools:context=".tutorial.tab.TutorialFragmentFinish"/>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
android:id="@+id/tutorial_setup_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorPrimary"
tools:context=".tutorial.tab.TutorialFragmentSetup"/>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
android:id="@+id/tutorial_start_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorPrimary"
tools:context=".tutorial.tab.TutorialFragmentStart"/>

View file

@ -1,42 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
android:id="@+id/tutorial_tab_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorPrimary"
tools:context=".tutorial.tab.TutorialFragmentTab">
<TextView
android:id="@+id/tutorial_tab_heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="64sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.100000024" />
<TextView
android:id="@+id/tutorial_tab_text"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:layout_marginBottom="32dp"
android:gravity="center"
android:textColor="#fff"
android:textSize="36sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.6"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tutorial_tab_heading" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
android:id="@+id/tutorial_usage_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorPrimary"
tools:context=".tutorial.tab.TutorialFragmentUsage"/>