Add Stub RegistActivity to Android

This commit is contained in:
Florian Märkl 2019-10-06 12:11:40 +02:00
commit b11bc55d9f
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
8 changed files with 166 additions and 53 deletions

View file

@ -30,8 +30,15 @@
<activity <activity
android:name=".settings.SettingsActivity" /> android:name=".settings.SettingsActivity" />
<activity android:name=".TestStartActivity" <activity
android:theme="@style/MageTheme"/> android:name=".TestStartActivity"
android:theme="@style/MageTheme"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"/>
<activity
android:name=".regist.RegistActivity"
android:theme="@style/MageTheme"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"/>
</application> </application>
</manifest> </manifest>

View file

@ -19,63 +19,30 @@ package com.metallic.chiaki
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.util.Base64 import android.util.Base64
import android.view.View import android.view.View
import android.view.ViewAnimationUtils import android.view.Window
import android.view.ViewTreeObserver import androidx.appcompat.app.AppCompatActivity
import android.view.animation.AccelerateInterpolator
import androidx.core.content.edit import androidx.core.content.edit
import androidx.core.widget.addTextChangedListener import androidx.core.widget.addTextChangedListener
import com.metallic.chiaki.lib.* import com.metallic.chiaki.common.ext.RevealActivity
import com.metallic.chiaki.lib.ConnectInfo
import com.metallic.chiaki.lib.ConnectVideoProfile
import com.metallic.chiaki.stream.StreamActivity import com.metallic.chiaki.stream.StreamActivity
import kotlinx.android.synthetic.main.activity_test_start.* import kotlinx.android.synthetic.main.activity_test_start.*
import kotlin.math.max
class TestStartActivity : AppCompatActivity() class TestStartActivity : AppCompatActivity(), RevealActivity
{ {
companion object override val revealIntent: Intent get() = intent
{ override val revealRootLayout: View get() = rootLayout
const val EXTRA_REVEAL_X = "reveal_x" override val revealWindow: Window get() = window
const val EXTRA_REVEAL_Y = "reveal_y"
}
private fun revealActivity(x: Float, y: Float)
{
val finalRadius = max(rootLayout.width, rootLayout.height).toFloat()
val reveal = ViewAnimationUtils.createCircularReveal(rootLayout, x.toInt(), y.toInt(), 0f, finalRadius)
reveal.interpolator = AccelerateInterpolator()
rootLayout.visibility = View.VISIBLE
reveal.start()
}
override fun onCreate(savedInstanceState: Bundle?) override fun onCreate(savedInstanceState: Bundle?)
{ {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_test_start) setContentView(R.layout.activity_test_start)
handleReveal()
window.setBackgroundDrawableResource(android.R.color.transparent)
if(intent.hasExtra(EXTRA_REVEAL_X) && intent.hasExtra(EXTRA_REVEAL_Y))
{
val revealX = intent.getFloatExtra(EXTRA_REVEAL_X, 0.0f)
val revealY = intent.getFloatExtra(EXTRA_REVEAL_Y, 0.0f)
rootLayout.visibility = View.INVISIBLE
rootLayout.viewTreeObserver.also {
if(it.isAlive)
{
it.addOnGlobalLayoutListener(object: ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout()
{
revealActivity(revealX, revealY)
rootLayout.viewTreeObserver.removeOnGlobalLayoutListener(this)
}
})
}
}
}
val prefs = getPreferences(Context.MODE_PRIVATE) val prefs = getPreferences(Context.MODE_PRIVATE)

View file

@ -0,0 +1,78 @@
/*
* This file is part of Chiaki.
*
* Chiaki is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Chiaki is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
*/
package com.metallic.chiaki.common.ext
import android.content.Intent
import android.graphics.Rect
import android.view.*
import android.view.animation.AccelerateInterpolator
import kotlin.math.max
interface RevealActivity
{
companion object
{
const val EXTRA_REVEAL_X = "reveal_x"
const val EXTRA_REVEAL_Y = "reveal_y"
}
val revealRootLayout: View
val revealIntent: Intent
val revealWindow: Window
private fun revealActivity(x: Int, y: Int)
{
val finalRadius = max(revealRootLayout.width, revealRootLayout.height).toFloat()
val reveal = ViewAnimationUtils.createCircularReveal(revealRootLayout, x, y, 0f, finalRadius)
reveal.interpolator = AccelerateInterpolator()
revealRootLayout.visibility = View.VISIBLE
reveal.start()
}
fun handleReveal()
{
if(!revealIntent.hasExtra(EXTRA_REVEAL_X) || !revealIntent.hasExtra(EXTRA_REVEAL_Y))
return
revealWindow.setBackgroundDrawableResource(android.R.color.transparent)
val revealX = revealIntent.getIntExtra(EXTRA_REVEAL_X, 0)
val revealY = revealIntent.getIntExtra(EXTRA_REVEAL_Y, 0)
revealRootLayout.visibility = View.INVISIBLE
revealRootLayout.viewTreeObserver.also {
if(it.isAlive)
{
it.addOnGlobalLayoutListener(object: ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout()
{
revealActivity(revealX, revealY)
revealRootLayout.viewTreeObserver.removeOnGlobalLayoutListener(this)
}
})
}
}
}
}
fun Intent.putRevealExtra(originView: View, rootLayout: ViewGroup)
{
val offsetRect = Rect()
originView.getDrawingRect(offsetRect)
rootLayout.offsetDescendantRectToMyCoords(originView, offsetRect)
putExtra(RevealActivity.EXTRA_REVEAL_X, offsetRect.left)
putExtra(RevealActivity.EXTRA_REVEAL_Y, offsetRect.top)
}

View file

@ -37,6 +37,8 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.android.material.transformation.ExpandableTransformationBehavior import com.google.android.material.transformation.ExpandableTransformationBehavior
import com.metallic.chiaki.R import com.metallic.chiaki.R
// see https://github.com/lcdsmao/ExpandableFABExample
class FloatingActionButtonSpeedDialBehavior @JvmOverloads constructor(context: Context? = null, attrs: AttributeSet? = null) : ExpandableTransformationBehavior(context, attrs) class FloatingActionButtonSpeedDialBehavior @JvmOverloads constructor(context: Context? = null, attrs: AttributeSet? = null) : ExpandableTransformationBehavior(context, attrs)
{ {
companion object companion object

View file

@ -21,7 +21,6 @@ import android.app.ActivityOptions
import android.content.Intent import android.content.Intent
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.util.Log
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
@ -30,12 +29,14 @@ import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.metallic.chiaki.R import com.metallic.chiaki.R
import com.metallic.chiaki.TestStartActivity import com.metallic.chiaki.TestStartActivity
import com.metallic.chiaki.common.ext.RevealActivity
import com.metallic.chiaki.common.ext.putRevealExtra
import com.metallic.chiaki.common.getDatabase import com.metallic.chiaki.common.getDatabase
import com.metallic.chiaki.common.ext.viewModelFactory import com.metallic.chiaki.common.ext.viewModelFactory
import com.metallic.chiaki.regist.RegistActivity
import com.metallic.chiaki.settings.SettingsActivity import com.metallic.chiaki.settings.SettingsActivity
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.activity_test_start.*
class MainActivity : AppCompatActivity() class MainActivity : AppCompatActivity()
{ {
@ -63,6 +64,9 @@ class MainActivity : AppCompatActivity()
addManualButton.setOnClickListener { addManualConsole() } addManualButton.setOnClickListener { addManualConsole() }
addManualLabelButton.setOnClickListener { addManualConsole() } addManualLabelButton.setOnClickListener { addManualConsole() }
registerButton.setOnClickListener { showRegistration() }
registerLabelButton.setOnClickListener { showRegistration() }
viewModel = ViewModelProviders viewModel = ViewModelProviders
.of(this, viewModelFactory { MainViewModel(getDatabase(this)) }) .of(this, viewModelFactory { MainViewModel(getDatabase(this)) })
.get(MainViewModel::class.java) .get(MainViewModel::class.java)
@ -148,13 +152,16 @@ class MainActivity : AppCompatActivity()
private fun addManualConsole() private fun addManualConsole()
{ {
val parent = addManualButton.parent as View
val parentParent = parent.parent as View
val x = addManualButton.x + parent.x + parentParent.x + addManualButton.width * 0.5f
val y = addManualButton.y + parent.y + parentParent.y + addManualButton.height * 0.5f
Intent(this, TestStartActivity::class.java).also { Intent(this, TestStartActivity::class.java).also {
it.putExtra(TestStartActivity.EXTRA_REVEAL_X, x) it.putRevealExtra(addManualButton, rootLayout)
it.putExtra(TestStartActivity.EXTRA_REVEAL_Y, y) startActivity(it, ActivityOptions.makeSceneTransitionAnimation(this).toBundle())
}
}
private fun showRegistration()
{
Intent(this, RegistActivity::class.java).also {
it.putRevealExtra(registerButton, rootLayout)
startActivity(it, ActivityOptions.makeSceneTransitionAnimation(this).toBundle()) startActivity(it, ActivityOptions.makeSceneTransitionAnimation(this).toBundle())
} }
} }

View file

@ -0,0 +1,41 @@
/*
* This file is part of Chiaki.
*
* Chiaki is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Chiaki is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
*/
package com.metallic.chiaki.regist
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.view.Window
import androidx.appcompat.app.AppCompatActivity
import com.metallic.chiaki.R
import com.metallic.chiaki.common.ext.RevealActivity
import kotlinx.android.synthetic.main.activity_regist.*
class RegistActivity: AppCompatActivity(), RevealActivity
{
override val revealWindow: Window get() = window
override val revealIntent: Intent get() = intent
override val revealRootLayout: View get() = rootLayout
override fun onCreate(savedInstanceState: Bundle?)
{
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_regist)
handleReveal()
}
}

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout <androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/rootLayout"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/rootLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/windowBackground">
</androidx.constraintlayout.widget.ConstraintLayout>