Skip to content
This repository has been archived by the owner on Dec 17, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2 from rmayobre/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
rmayobre authored Jun 23, 2020
2 parents 1c19df3 + 0d85a29 commit 6536339
Show file tree
Hide file tree
Showing 29 changed files with 867 additions and 205 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ An Android button library following [material design](https://material.io/design
## Speed Dial
A button that expands into a series of smaller buttons with labels (optional). Follow the recommend usage defined in the [Material Design reference](https://material.io/components/buttons-floating-action-button#types-of-transitions).

![SpeedDial.gif](https://github.com/rmayobre/MultiButton/blob/develop/misc/speeddial.gif)
![SpeedDial.gif](https://github.com/rmayobre/MultiButton/blob/develop/misc/examples.gif)
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.1.0'
implementation project(':library')
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
}
127 changes: 16 additions & 111 deletions app/src/main/java/com/multibutton/example/MainActivity.kt
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 app/src/main/java/com/multibutton/example/SectionsPagerAdapter.kt
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()
)
}
}
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 app/src/main/java/com/multibutton/example/fragment/FabFragment.kt
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")
}
}
}
Loading

0 comments on commit 6536339

Please sign in to comment.