parent
7a9f5a8364
commit
dc80f62b21
@ -0,0 +1,120 @@ |
||||
package net.pokeranalytics.android.ui.activity |
||||
|
||||
import android.animation.Animator |
||||
import android.animation.AnimatorListenerAdapter |
||||
import android.content.Context |
||||
import android.content.Intent |
||||
import android.os.Bundle |
||||
import android.view.View |
||||
import android.view.ViewAnimationUtils |
||||
import kotlinx.android.synthetic.main.activity_new_data.* |
||||
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
||||
import net.pokeranalytics.android.ui.extensions.px |
||||
|
||||
|
||||
class NewDataMenuActivity : PokerAnalyticsActivity() { |
||||
|
||||
enum class IntentKey(val keyName: String) { |
||||
CHOICE("CHOICE"), |
||||
} |
||||
|
||||
companion object { |
||||
fun newInstance(context: Context) { |
||||
val intent = Intent(context, NewDataMenuActivity::class.java) |
||||
context.startActivity(intent) |
||||
} |
||||
} |
||||
|
||||
private val fabSize = 48.px |
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) { |
||||
super.onCreate(savedInstanceState) |
||||
setContentView(net.pokeranalytics.android.R.layout.activity_new_data) |
||||
initUI() |
||||
} |
||||
|
||||
override fun onBackPressed() { |
||||
hideMenu() |
||||
} |
||||
|
||||
override fun onPause() { |
||||
super.onPause() |
||||
overridePendingTransition(0, 0) |
||||
} |
||||
|
||||
/** |
||||
* Init UI |
||||
*/ |
||||
private fun initUI() { |
||||
|
||||
overridePendingTransition(0, 0) |
||||
|
||||
container.viewTreeObserver.addOnGlobalLayoutListener { |
||||
showMenu() |
||||
} |
||||
|
||||
newCashGame.setOnClickListener { |
||||
finishWithResult(0) |
||||
} |
||||
|
||||
newTournament.setOnClickListener { |
||||
finishWithResult(1) |
||||
} |
||||
|
||||
newTransaction.setOnClickListener { |
||||
finishWithResult(2) |
||||
} |
||||
|
||||
container.setOnClickListener { |
||||
hideMenu() |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Set the result and hide menu |
||||
*/ |
||||
private fun finishWithResult(choice: Int) { |
||||
val intent = Intent() |
||||
intent.putExtra(IntentKey.CHOICE.keyName, choice) |
||||
setResult(RESULT_OK, intent) |
||||
hideMenu(true) |
||||
} |
||||
|
||||
/** |
||||
* Show menu |
||||
*/ |
||||
private fun showMenu() { |
||||
|
||||
val cx = menuContainer.measuredWidth - fabSize / 2 |
||||
val cy = menuContainer.measuredHeight - fabSize / 2 |
||||
val finalRadius = Math.max(menuContainer.width, menuContainer.height) |
||||
val anim = ViewAnimationUtils.createCircularReveal(menuContainer, cx, cy, 0f, finalRadius.toFloat()) |
||||
anim.duration = 300 |
||||
|
||||
menuContainer.visibility = View.VISIBLE |
||||
anim.start() |
||||
} |
||||
|
||||
/** |
||||
* Hide menu |
||||
*/ |
||||
private fun hideMenu(hideQuickly: Boolean = false) { |
||||
|
||||
val cx = menuContainer.measuredWidth - fabSize / 2 |
||||
val cy = menuContainer.measuredHeight - fabSize / 2 |
||||
val initialRadius = menuContainer.width |
||||
val anim = ViewAnimationUtils.createCircularReveal(menuContainer, cx, cy, initialRadius.toFloat(), 0f) |
||||
anim.duration = if (hideQuickly) 150 else 300 |
||||
|
||||
anim.addListener(object : AnimatorListenerAdapter() { |
||||
override fun onAnimationEnd(animation: Animator?) { |
||||
super.onAnimationEnd(animation) |
||||
menuContainer.visibility = View.INVISIBLE |
||||
finish() |
||||
} |
||||
}) |
||||
|
||||
anim.start() |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,132 @@ |
||||
<?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/container" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent"> |
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout |
||||
android:id="@+id/menuContainer" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_gravity="center" |
||||
android:layout_marginEnd="16dp" |
||||
android:layout_marginBottom="72dp" |
||||
android:background="@android:color/transparent" |
||||
android:elevation="4dp" |
||||
android:orientation="vertical" |
||||
android:visibility="invisible" |
||||
app:layout_constraintBottom_toBottomOf="parent" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
tools:visibility="visible"> |
||||
|
||||
<View |
||||
android:layout_width="0dp" |
||||
android:layout_height="0dp" |
||||
android:transitionName="newButtonTransition" |
||||
app:layout_constraintBottom_toBottomOf="parent" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
android:background="@color/gray_darker" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toTopOf="parent" /> |
||||
|
||||
<LinearLayout |
||||
android:id="@+id/newCashGame" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="48dp" |
||||
android:layout_marginTop="8dp" |
||||
android:background="?selectableItemBackground" |
||||
android:gravity="center_vertical" |
||||
android:orientation="horizontal" |
||||
android:paddingStart="24dp" |
||||
android:paddingEnd="24dp" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toTopOf="parent"> |
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView |
||||
android:layout_width="32dp" |
||||
android:layout_height="32dp" |
||||
android:tint="@color/green" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toTopOf="parent" |
||||
app:srcCompat="@drawable/add_cash_game" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
style="@style/PokerAnalyticsTheme.TextView.RowTitle" |
||||
android:layout_width="160dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="20dp" |
||||
android:text="@string/new_cash_game" |
||||
app:layout_constraintEnd_toEndOf="parent" /> |
||||
|
||||
</LinearLayout> |
||||
|
||||
<LinearLayout |
||||
android:id="@+id/newTournament" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="48dp" |
||||
android:background="?selectableItemBackground" |
||||
android:gravity="center_vertical" |
||||
android:orientation="horizontal" |
||||
android:paddingStart="24dp" |
||||
android:paddingEnd="24dp" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toBottomOf="@+id/newCashGame"> |
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView |
||||
android:layout_width="32dp" |
||||
android:layout_height="32dp" |
||||
android:tint="@color/green" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toTopOf="parent" |
||||
app:srcCompat="@drawable/add_tournament" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
style="@style/PokerAnalyticsTheme.TextView.RowTitle" |
||||
android:layout_width="160dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="20dp" |
||||
android:text="@string/new_tournament" |
||||
app:layout_constraintEnd_toEndOf="parent" /> |
||||
|
||||
</LinearLayout> |
||||
|
||||
<LinearLayout |
||||
android:id="@+id/newTransaction" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="48dp" |
||||
android:layout_marginBottom="8dp" |
||||
android:background="?selectableItemBackground" |
||||
android:gravity="center_vertical" |
||||
android:orientation="horizontal" |
||||
android:paddingStart="24dp" |
||||
android:paddingEnd="24dp" |
||||
app:layout_constraintBottom_toBottomOf="parent" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toBottomOf="@+id/newTournament"> |
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView |
||||
android:layout_width="32dp" |
||||
android:layout_height="32dp" |
||||
android:tint="@color/green" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toTopOf="parent" |
||||
app:srcCompat="@drawable/add_transaction" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
style="@style/PokerAnalyticsTheme.TextView.RowTitle" |
||||
android:layout_width="160dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="20dp" |
||||
android:text="@string/new_operation" |
||||
app:layout_constraintEnd_toEndOf="parent" /> |
||||
|
||||
</LinearLayout> |
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout> |
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout> |
||||
Loading…
Reference in new issue