Skip to content

Commit

Permalink
bug fixing on auto back view flipping and overlapping on initial stat…
Browse files Browse the repository at this point in the history
…e, copyrights are added on the project
  • Loading branch information
HasnathJami committed Jul 12, 2024
1 parent 04494e9 commit b19617c
Show file tree
Hide file tree
Showing 16 changed files with 317 additions and 29 deletions.
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 Hasnath Jami Chowdhury
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hasnath.jami.animated_flip_view.afv_custom_view

import android.animation.AnimatorInflater
Expand Down Expand Up @@ -62,31 +78,39 @@ class AnimatedFlipView @JvmOverloads constructor(

@SuppressLint("ResourceType")
fun flipToFront() {
val frontAnim = getAnimatorSet(flipDirection, true)
val backAnim = getAnimatorSet(flipDirection, false)

frontAnim.setTarget(backView)
backAnim.setTarget(frontView)
frontAnim.start()
backAnim.start()

frontView.visibility = View.VISIBLE
backView.visibility = View.GONE
isFlipped = false
try {
val frontAnim = getAnimatorSet(flipDirection, true)
val backAnim = getAnimatorSet(flipDirection, false)

frontAnim.setTarget(backView)
backAnim.setTarget(frontView)
frontAnim.start()
backAnim.start()

frontView.visibility = View.VISIBLE
backView.visibility = View.GONE
isFlipped = false
} catch (e: Exception) {
e.printStackTrace()
}
}

@SuppressLint("ResourceType")
fun flipToBack() {
val frontAnim = getAnimatorSet(flipDirection, true)
val backAnim = getAnimatorSet(flipDirection, false)

backAnim.setTarget(backView)
frontAnim.start()
backAnim.start()

frontView.visibility = View.GONE
backView.visibility = View.VISIBLE
isFlipped = true
try {
val frontAnim = getAnimatorSet(flipDirection, true)
val backAnim = getAnimatorSet(flipDirection, false)

backAnim.setTarget(backView)
frontAnim.start()
backAnim.start()

backView.visibility = View.VISIBLE
frontView.visibility = View.GONE
isFlipped = true
} catch (e: Exception) {
e.printStackTrace()
}
}

private fun getAnimatorSet(direction: FlipDirection, isFront: Boolean): AnimatorSet {
Expand All @@ -100,25 +124,41 @@ class AnimatedFlipView @JvmOverloads constructor(
}

fun setFrontView(view: View) {
frontView = view
findViewById<ViewGroup>(R.id.frontView).addView(view)
try {
frontView = view
findViewById<ViewGroup>(R.id.frontView).addView(view)
} catch (e: Exception) {
e.printStackTrace()
}
}

fun setBackView(view: View) {
backView = view
findViewById<ViewGroup>(R.id.backView).addView(view)
try {
backView = view
findViewById<ViewGroup>(R.id.backView).addView(view)
backView.visibility = View.GONE
} catch (e: Exception) {
e.printStackTrace()
}
}

fun startAutoBackFlippingWithIntervals(delay: Long) {
handler.postDelayed({
try {
flipToBack()
handler.postDelayed({
flipToFront()
}, delay)
}, delay)
} catch (e: Exception) {
e.printStackTrace()
}
}

fun removeHandler() {
handler.removeCallbacksAndMessages(null)
try {
handler.removeCallbacksAndMessages(null)
} catch (e: Exception) {
e.printStackTrace()
}

}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 Hasnath Jami Chowdhury
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hasnath.jami.animated_flip_view.afv_utils

enum class FlipDirection {
Expand Down
19 changes: 19 additions & 0 deletions AnimatedFlipView/src/main/res/anim/back_animator.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>


<!--
* Copyright 2024 Hasnath Jami Chowdhury
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->

<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:valueFrom="180"
Expand Down
18 changes: 18 additions & 0 deletions AnimatedFlipView/src/main/res/anim/front_animator.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
* Copyright 2024 Hasnath Jami Chowdhury
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->

<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:valueFrom="0"
Expand Down
18 changes: 18 additions & 0 deletions AnimatedFlipView/src/main/res/animator/down_to_top_back.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
* Copyright 2024 Hasnath Jami Chowdhury
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->

<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:valueFrom="-180"
Expand Down
18 changes: 18 additions & 0 deletions AnimatedFlipView/src/main/res/animator/down_to_top_front.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
* Copyright 2024 Hasnath Jami Chowdhury
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->

<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:valueFrom="0"
Expand Down
18 changes: 18 additions & 0 deletions AnimatedFlipView/src/main/res/animator/left_to_right_back.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
* Copyright 2024 Hasnath Jami Chowdhury
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->

<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:valueFrom="180"
Expand Down
18 changes: 18 additions & 0 deletions AnimatedFlipView/src/main/res/animator/left_to_right_front.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
* Copyright 2024 Hasnath Jami Chowdhury
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->

<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:valueFrom="0"
Expand Down
18 changes: 18 additions & 0 deletions AnimatedFlipView/src/main/res/animator/right_to_left_back.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
* Copyright 2024 Hasnath Jami Chowdhury
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->

<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:valueFrom="-180"
Expand Down
18 changes: 18 additions & 0 deletions AnimatedFlipView/src/main/res/animator/right_to_left_front.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
* Copyright 2024 Hasnath Jami Chowdhury
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->

<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:valueFrom="0"
Expand Down
18 changes: 18 additions & 0 deletions AnimatedFlipView/src/main/res/animator/top_to_down_back.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
* Copyright 2024 Hasnath Jami Chowdhury
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->

<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:valueFrom="180"
Expand Down
18 changes: 18 additions & 0 deletions AnimatedFlipView/src/main/res/animator/top_to_down_front.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
* Copyright 2024 Hasnath Jami Chowdhury
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->

<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:valueFrom="0"
Expand Down
Loading

0 comments on commit b19617c

Please sign in to comment.