This repository has been archived by the owner on Dec 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from rmayobre/develop
Develop
- Loading branch information
Showing
29 changed files
with
867 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 16 additions & 111 deletions
127
app/src/main/java/com/multibutton/example/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,125 +1,30 @@ | ||
package com.multibutton.example | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import android.view.View | ||
import android.widget.Toast | ||
import androidx.annotation.DrawableRes | ||
import androidx.annotation.IdRes | ||
import androidx.annotation.LayoutRes | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import com.multibutton.library.HideOnScrollBehavior | ||
import com.multibutton.library.SpeedDial | ||
import com.multibutton.library.SpeedDialAction | ||
import kotlinx.android.synthetic.main.activity_main.* | ||
import com.google.android.material.tabs.TabLayout | ||
import androidx.viewpager.widget.ViewPager | ||
import androidx.appcompat.app.AppCompatActivity | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
class MainActivity : AppCompatActivity(), View.OnClickListener { | ||
private lateinit var sectionsPagerAdapter: SectionsPagerAdapter | ||
|
||
private lateinit var button: SpeedDial | ||
private lateinit var viewPager: ViewPager | ||
|
||
private lateinit var tabLayout: TabLayout | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(MAIN_ACTIVITY) | ||
|
||
button = findViewById<SpeedDial>(R.id.speedDialButton).apply { | ||
addAction(SpeedDialAction.Builder(this@MainActivity) | ||
.setId(FAB_1) | ||
.setImage(ACTION_DRAWABLE) | ||
.setLabel("test 1") | ||
.setOnClickListener(this@MainActivity) | ||
.setShowAnimation(R.anim.fab_fade_in) | ||
.setHideAnimation(R.anim.fab_fade_out) | ||
.build()) | ||
addAction(SpeedDialAction.Builder(this@MainActivity) | ||
.setId(FAB_2) | ||
.setImage(ACTION_DRAWABLE) | ||
.setLabel("test 2") | ||
.setOnClickListener(this@MainActivity) | ||
.setShowAnimation(R.anim.fab_fade_in) | ||
.setHideAnimation(R.anim.fab_fade_out) | ||
.build()) | ||
addAction(SpeedDialAction.Builder(this@MainActivity) | ||
.setId(FAB_3) | ||
.setImage(ACTION_DRAWABLE) | ||
.setLabel("test 3") | ||
.setOnClickListener(this@MainActivity) | ||
.setShowAnimation(R.anim.fab_fade_in) | ||
.setHideAnimation(R.anim.fab_fade_out) | ||
.build()) | ||
addAction(SpeedDialAction.Builder(this@MainActivity) | ||
.setId(FAB_4) | ||
.setImage(ACTION_DRAWABLE) | ||
.setLabel("test 4") | ||
.setOnClickListener(this@MainActivity) | ||
.setShowAnimation(R.anim.fab_fade_in) | ||
.setHideAnimation(R.anim.fab_fade_out) | ||
.build()) | ||
addAction(SpeedDialAction.Builder(this@MainActivity) | ||
.setId(FAB_5) | ||
.setImage(ACTION_DRAWABLE) | ||
.setLabel("test 5") | ||
.setOnClickListener(this@MainActivity) | ||
.setShowAnimation(R.anim.fab_fade_in) | ||
.setHideAnimation(R.anim.fab_fade_out) | ||
.build()) | ||
} | ||
setContentView(R.layout.activity_main) | ||
|
||
val texts: MutableList<String> = mutableListOf() | ||
texts.add("Text 1") | ||
texts.add("Text 2") | ||
texts.add("Text 3") | ||
texts.add("Text 4") | ||
texts.add("Text 5") | ||
texts.add("Text 6") | ||
texts.add("Text 7") | ||
texts.add("Text 1") | ||
texts.add("Text 2") | ||
texts.add("Text 3") | ||
texts.add("Text 4") | ||
texts.add("Text 5") | ||
texts.add("Text 6") | ||
texts.add("Text 7") | ||
texts.add("Text 1") | ||
texts.add("Text 2") | ||
texts.add("Text 3") | ||
texts.add("Text 4") | ||
texts.add("Text 5") | ||
texts.add("Text 6") | ||
texts.add("Text 7") | ||
sectionsPagerAdapter = SectionsPagerAdapter(this, supportFragmentManager) | ||
|
||
with(recyclerView) { | ||
layoutManager = LinearLayoutManager(this@MainActivity) | ||
setHasFixedSize(true) | ||
adapter = TextAdapter(texts) | ||
viewPager = findViewById<ViewPager>(R.id.view_pager).apply { | ||
adapter = sectionsPagerAdapter | ||
} | ||
|
||
HideOnScrollBehavior.from(speedDialButton).hideAtEnd(false) | ||
} | ||
|
||
override fun onClick(v: View) { | ||
val buttonNum = when (v.id) { | ||
R.id.button1 -> 1 | ||
R.id.button2 -> 2 | ||
R.id.button3 -> 3 | ||
R.id.button4 -> 4 | ||
R.id.button5 -> 5 | ||
else -> -1 | ||
} | ||
if (buttonNum != -1) { | ||
Toast.makeText(this, "Button ID clicked -> $buttonNum", Toast.LENGTH_SHORT).show() | ||
} else { | ||
Toast.makeText(this, "Button could not be identified", Toast.LENGTH_SHORT).show() | ||
tabLayout = findViewById<TabLayout>(R.id.tabs).apply { | ||
setupWithViewPager(viewPager) | ||
} | ||
} | ||
|
||
companion object { | ||
@LayoutRes private const val MAIN_ACTIVITY = R.layout.activity_main | ||
@DrawableRes private var ACTION_DRAWABLE = R.drawable.ic_android_white | ||
@IdRes private var FAB_1 = R.id.button1 | ||
@IdRes private var FAB_2 = R.id.button2 | ||
@IdRes private var FAB_3 = R.id.button3 | ||
@IdRes private var FAB_4 = R.id.button4 | ||
@IdRes private var FAB_5 = R.id.button5 | ||
} | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
app/src/main/java/com/multibutton/example/SectionsPagerAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.multibutton.example | ||
|
||
import android.content.Context | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.FragmentManager | ||
import androidx.fragment.app.FragmentPagerAdapter | ||
import com.multibutton.example.fragment.ExpandableFabFragment | ||
import com.multibutton.example.fragment.FabFragment | ||
import com.multibutton.example.fragment.SpeedDialFragment | ||
|
||
class SectionsPagerAdapter(private val context: Context, fm: FragmentManager) : FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { | ||
|
||
override fun getItem(position: Int): Fragment = FRAGMENTS[position] | ||
|
||
override fun getPageTitle(position: Int): CharSequence? = | ||
context.resources.getString(TAB_TITLES[position]) | ||
|
||
override fun getCount(): Int = 3 | ||
|
||
companion object { | ||
private val TAB_TITLES = arrayOf( | ||
R.string.fab_tab_text, | ||
R.string.expandable_fab_text, | ||
R.string.speed_dial_text | ||
) | ||
|
||
private val FRAGMENTS = listOf<Fragment>( | ||
FabFragment(), | ||
ExpandableFabFragment(), | ||
SpeedDialFragment() | ||
) | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
app/src/main/java/com/multibutton/example/fragment/ExpandableFabFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.multibutton.example.fragment | ||
|
||
import android.os.Bundle | ||
import androidx.fragment.app.Fragment | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.Toast | ||
import androidx.annotation.LayoutRes | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.multibutton.example.R | ||
import com.multibutton.example.TextAdapter | ||
import com.multibutton.library.expanding.ExpandableFAB | ||
|
||
class ExpandableFabFragment : Fragment(), View.OnClickListener { | ||
|
||
private lateinit var recyclerView: RecyclerView | ||
|
||
private lateinit var button: ExpandableFAB | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? = inflater.inflate(FRAGMENT_LAYOUT, container, false).apply { | ||
|
||
/* RecyclerView setup */ | ||
recyclerView = findViewById<RecyclerView>(R.id.recyclerView).apply { | ||
layoutManager = LinearLayoutManager(context) | ||
setHasFixedSize(true) | ||
adapter = TextAdapter(TEXT_LIST) | ||
setOnScrollChangeListener { _, _, scrollY, _, oldScrollY -> | ||
if (scrollY < oldScrollY && button.state == ExpandableFAB.State.COLLAPSED) { | ||
button.changeState() | ||
} else if (scrollY > oldScrollY && button.state == ExpandableFAB.State.EXPANDED) { | ||
button.changeState() | ||
} | ||
} | ||
} | ||
|
||
/* ExpandableFAB setup */ | ||
button = findViewById<ExpandableFAB>(R.id.expandable_fab).apply { | ||
setOnClickListener(this@ExpandableFabFragment) | ||
} | ||
} | ||
|
||
override fun onClick(v: View) { | ||
with(context) { | ||
Toast.makeText(this, "Email button was clicked.", Toast.LENGTH_SHORT).show() | ||
} | ||
} | ||
|
||
companion object { | ||
@LayoutRes private const val FRAGMENT_LAYOUT = R.layout.fragment_expandable_fab | ||
|
||
private val TEXT_LIST: MutableList<String> = mutableListOf<String>().apply { | ||
add("Text 1") | ||
add("Text 2") | ||
add("Text 3") | ||
add("Text 4") | ||
add("Text 5") | ||
add("Text 6") | ||
add("Text 7") | ||
add("Text 8") | ||
add("Text 9") | ||
add("Text 10") | ||
add("Text 11") | ||
add("Text 12") | ||
add("Text 13") | ||
add("Text 14") | ||
add("Text 15") | ||
add("Text 16") | ||
add("Text 17") | ||
add("Text 18") | ||
add("Text 19") | ||
add("Text 20") | ||
add("Text 21") | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
app/src/main/java/com/multibutton/example/fragment/FabFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.multibutton.example.fragment | ||
|
||
import android.os.Bundle | ||
import androidx.fragment.app.Fragment | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.Toast | ||
import androidx.annotation.LayoutRes | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.multibutton.example.R | ||
import com.multibutton.example.TextAdapter | ||
import com.multibutton.library.FAB | ||
|
||
class FabFragment : Fragment(), View.OnClickListener { | ||
|
||
private lateinit var recyclerView: RecyclerView | ||
|
||
private lateinit var button: FAB | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? = inflater.inflate(FRAGMENT_LAYOUT, container, false).apply { | ||
|
||
/* RecyclerView setup */ | ||
recyclerView = findViewById<RecyclerView>(R.id.recyclerView).apply { | ||
layoutManager = LinearLayoutManager(context) | ||
setHasFixedSize(true) | ||
adapter = TextAdapter(TEXT_LIST) | ||
} | ||
|
||
/* FAB setup */ | ||
button = findViewById<FAB>(R.id.fab).apply { | ||
setOnClickListener(this@FabFragment) | ||
} | ||
} | ||
|
||
override fun onClick(v: View) { | ||
with(context) { | ||
Toast.makeText(this, "Button was clicked.", Toast.LENGTH_SHORT).show() | ||
} | ||
} | ||
|
||
companion object { | ||
@LayoutRes private const val FRAGMENT_LAYOUT = R.layout.fragment_fab | ||
|
||
private val TEXT_LIST: MutableList<String> = mutableListOf<String>().apply { | ||
add("Text 1") | ||
add("Text 2") | ||
add("Text 3") | ||
add("Text 4") | ||
add("Text 5") | ||
add("Text 6") | ||
add("Text 7") | ||
add("Text 8") | ||
add("Text 9") | ||
add("Text 10") | ||
add("Text 11") | ||
add("Text 12") | ||
add("Text 13") | ||
add("Text 14") | ||
add("Text 15") | ||
add("Text 16") | ||
add("Text 17") | ||
add("Text 18") | ||
add("Text 19") | ||
add("Text 20") | ||
add("Text 21") | ||
} | ||
} | ||
} |
Oops, something went wrong.