Added animation

This commit is contained in:
NoodleMage 2016-03-19 15:39:19 +01:00
parent bc473055b9
commit 137c21e6c9
5 changed files with 147 additions and 12 deletions

View File

@ -1,5 +1,8 @@
package eu.kanade.tachiyomi.ui.manga.chapter package eu.kanade.tachiyomi.ui.manga.chapter
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.support.v7.view.ActionMode import android.support.v7.view.ActionMode
import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.LinearLayoutManager
@ -16,6 +19,7 @@ import eu.kanade.tachiyomi.ui.base.decoration.DividerItemDecoration
import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment
import eu.kanade.tachiyomi.ui.manga.MangaActivity import eu.kanade.tachiyomi.ui.manga.MangaActivity
import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.reader.ReaderActivity
import eu.kanade.tachiyomi.util.getCoordinates
import eu.kanade.tachiyomi.util.getResourceDrawable import eu.kanade.tachiyomi.util.getResourceDrawable
import eu.kanade.tachiyomi.util.toast import eu.kanade.tachiyomi.util.toast
import kotlinx.android.synthetic.main.fragment_manga_chapters.* import kotlinx.android.synthetic.main.fragment_manga_chapters.*
@ -73,7 +77,19 @@ class ChaptersFragment : BaseRxFragment<ChaptersPresenter>(), ActionMode.Callbac
fab.setOnClickListener { v -> fab.setOnClickListener { v ->
val chapter = presenter.getNextUnreadChapter() val chapter = presenter.getNextUnreadChapter()
if (chapter != null) { if (chapter != null) {
openChapter(chapter) // Create animation listener
var revealAnimationListener: Animator.AnimatorListener = object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) {
// On done open chapter
openChapter(chapter, true)
}
}
// Get coordinates and start animation
val coordinates = fab.getCoordinates()
if (!reveal_view.showRevealEffect(coordinates.x, coordinates.y, revealAnimationListener)) {
openChapter(chapter)
}
} else { } else {
context.toast(R.string.no_next_chapter) context.toast(R.string.no_next_chapter)
} }
@ -90,6 +106,16 @@ class ChaptersFragment : BaseRxFragment<ChaptersPresenter>(), ActionMode.Callbac
super.onPause() super.onPause()
} }
override fun onResume() {
// Check if animation view is visible
if (reveal_view.visibility == View.VISIBLE) {
// Show the unReveal effect
var coordinates = fab.getCoordinates()
reveal_view.hideRevealEffect(coordinates.x, coordinates.y, 1920)
}
super.onResume()
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.chapters, menu) inflater.inflate(R.menu.chapters, menu)
menu.findItem(R.id.action_filter_unread).isChecked = presenter.onlyUnread() menu.findItem(R.id.action_filter_unread).isChecked = presenter.onlyUnread()
@ -159,9 +185,12 @@ class ChaptersFragment : BaseRxFragment<ChaptersPresenter>(), ActionMode.Callbac
val isCatalogueManga: Boolean val isCatalogueManga: Boolean
get() = (activity as MangaActivity).isCatalogueManga get() = (activity as MangaActivity).isCatalogueManga
protected fun openChapter(chapter: Chapter) { protected fun openChapter(chapter: Chapter, hasAnimation: Boolean = false) {
presenter.onOpenChapter(chapter) presenter.onOpenChapter(chapter)
val intent = ReaderActivity.newIntent(activity) val intent = ReaderActivity.newIntent(activity)
if (hasAnimation) {
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
}
startActivity(intent) startActivity(intent)
} }
@ -349,5 +378,4 @@ class ChaptersFragment : BaseRxFragment<ChaptersPresenter>(), ActionMode.Callbac
fun setDownloadedFilter() { fun setDownloadedFilter() {
this.activity.supportInvalidateOptionsMenu() this.activity.supportInvalidateOptionsMenu()
} }
} }

View File

@ -0,0 +1,19 @@
package eu.kanade.tachiyomi.util
import android.graphics.Point
import android.view.View
/**
* Returns coordinates of view.
* Used for animation
*
* @return coordinates of view
*/
fun View.getCoordinates(): Point
{
var cx = (this.left + this.right) / 2;
var cy = (this.top + this.bottom) / 2;
return Point(cx, cy)
}

View File

@ -0,0 +1,79 @@
package eu.kanade.tachiyomi.widget
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.annotation.TargetApi
import android.content.Context
import android.os.Build
import android.util.AttributeSet
import android.view.View
import android.view.ViewAnimationUtils
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
class RevealAnimationView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
View(context, attrs) {
/**
* Hides the animation view with a animation
*
* @param centerX x starting point
* @param centerY y starting point
* @param initialRadius size of radius of animation
*/
fun hideRevealEffect(centerX: Int, centerY: Int, initialRadius: Int) {
if (Build.VERSION.SDK_INT >= 21) {
// Make the view visible.
this.visibility = View.VISIBLE
// Create the animation (the final radius is zero).
val anim = ViewAnimationUtils.createCircularReveal(
this, centerX, centerY, initialRadius.toFloat(), 0f)
// Set duration of animation.
anim.duration = 500
// make the view invisible when the animation is done
anim.addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) {
super.onAnimationEnd(animation)
this@RevealAnimationView.visibility = View.INVISIBLE
}
})
anim.start()
}
}
/**
* Fills the animation view with a animation
*
* @param centerX x starting point
* @param centerY y starting point
* @param listener animation listener
*
* @return sdk version lower then 21
*/
fun showRevealEffect(centerX: Int, centerY: Int, listener: Animator.AnimatorListener): Boolean {
if (Build.VERSION.SDK_INT >= 21) {
this.visibility = View.VISIBLE
val height = this.height
// Create animation
val anim = ViewAnimationUtils.createCircularReveal(
this, centerX, centerY, 0f, height.toFloat())
// Set duration of animation
anim.duration = 350
anim.addListener(listener)
anim.start()
return true
}
return false
}
}

View File

@ -7,6 +7,15 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<eu.kanade.tachiyomi.widget.RevealAnimationView
android:id="@+id/reveal_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorAccent"
android:elevation="5dp"
android:visibility="invisible"
/>
<android.support.v4.widget.SwipeRefreshLayout <android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh" android:id="@+id/swipe_refresh"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout 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" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight" android:layout_height="?android:attr/listPreferredItemHeight"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?attr/selectable_list_drawable"> android:background="?attr/selectable_list_drawable">
@ -25,37 +25,38 @@
<TextView <TextView
android:id="@+id/chapter_pages" android:id="@+id/chapter_pages"
style="@style/TextAppearance.Regular.Caption.Hint"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:ellipsize="marquee" android:ellipsize="marquee"
android:singleLine="true" android:singleLine="true"
style="@style/TextAppearance.Regular.Caption.Hint"
tools:text="Pages: 45"/> tools:text="Pages: 45"/>
<TextView <TextView
android:id="@+id/chapter_date" android:id="@+id/chapter_date"
style="@style/TextAppearance.Regular.Caption"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:ellipsize="marquee" android:ellipsize="marquee"
android:singleLine="true" android:singleLine="true"
style="@style/TextAppearance.Regular.Body1"
tools:text="22/02/2016"/> tools:text="22/02/2016"/>
<TextView <TextView
android:id="@+id/download_text" android:id="@+id/download_text"
style="@style/TextAppearance.Regular.Caption.Hint"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:textAllCaps="true" android:textAllCaps="true"/>
style="@style/TextAppearance.Regular.Caption.Hint"/>
</RelativeLayout> </RelativeLayout>
<TextView <TextView
android:id="@+id/chapter_title" android:id="@+id/chapter_title"
style="@style/TextAppearance.Regular.Body1"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_above="@+id/relativeLayout" android:layout_above="@+id/relativeLayout"
@ -68,8 +69,7 @@
android:layout_marginRight="30dp" android:layout_marginRight="30dp"
android:ellipsize="middle" android:ellipsize="middle"
android:gravity="center_vertical" android:gravity="center_vertical"
android:maxLines="1" android:maxLines="2"
style="@style/TextAppearance.Regular.SubHeading"
tools:text="Title"/> tools:text="Title"/>
@ -93,8 +93,8 @@
android:layout_alignParentEnd="false" android:layout_alignParentEnd="false"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
app:srcCompat="@drawable/ic_more_horiz_black_24dp" android:tint="?android:attr/textColorPrimary"
android:tint="?android:attr/textColorPrimary"/> app:srcCompat="@drawable/ic_more_horiz_black_24dp"/>
</RelativeLayout> </RelativeLayout>