-
Notifications
You must be signed in to change notification settings - Fork 935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
introducing confetti animation using konfetti library #1743
Changes from all commits
a2ae1fd
2fd7b44
6901968
d643397
48c0b39
83328b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -36,6 +36,7 @@ import android.view.ViewGroup | |||||
import android.view.ViewGroup.LayoutParams.MATCH_PARENT | ||||||
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT | ||||||
import android.view.WindowManager | ||||||
import android.widget.LinearLayout | ||||||
import android.widget.RelativeLayout | ||||||
import android.widget.RelativeLayout.ALIGN_PARENT_BOTTOM | ||||||
import android.widget.RelativeLayout.ALIGN_PARENT_TOP | ||||||
|
@@ -46,13 +47,18 @@ import androidx.appcompat.app.AppCompatActivity | |||||
import androidx.appcompat.widget.Toolbar | ||||||
import androidx.core.content.FileProvider | ||||||
import com.google.android.material.snackbar.Snackbar | ||||||
import nl.dionsegijn.konfetti.core.Party | ||||||
import nl.dionsegijn.konfetti.core.Position | ||||||
import nl.dionsegijn.konfetti.core.emitter.Emitter | ||||||
import nl.dionsegijn.konfetti.xml.KonfettiView | ||||||
import org.isoron.platform.gui.toInt | ||||||
import org.isoron.uhabits.HabitsApplication | ||||||
import org.isoron.uhabits.R | ||||||
import org.isoron.uhabits.activities.AndroidThemeSwitcher | ||||||
import org.isoron.uhabits.core.models.PaletteColor | ||||||
import org.isoron.uhabits.core.ui.views.Theme | ||||||
import java.io.File | ||||||
import java.util.concurrent.TimeUnit | ||||||
|
||||||
fun RelativeLayout.addBelow( | ||||||
view: View, | ||||||
|
@@ -77,7 +83,9 @@ fun RelativeLayout.addAtBottom( | |||||
view.layoutParams = RelativeLayout.LayoutParams(width, height).apply { | ||||||
addRule(ALIGN_PARENT_BOTTOM) | ||||||
} | ||||||
view.id = View.generateViewId() | ||||||
if (view.id == null) { | ||||||
view.id = View.generateViewId() | ||||||
} | ||||||
this.addView(view) | ||||||
} | ||||||
|
||||||
|
@@ -89,7 +97,10 @@ fun RelativeLayout.addAtTop( | |||||
view.layoutParams = RelativeLayout.LayoutParams(width, height).apply { | ||||||
addRule(ALIGN_PARENT_TOP) | ||||||
} | ||||||
view.id = View.generateViewId() | ||||||
|
||||||
if (view.id == null) { | ||||||
view.id = View.generateViewId() | ||||||
} | ||||||
this.addView(view) | ||||||
} | ||||||
|
||||||
|
@@ -98,6 +109,32 @@ fun ViewGroup.buildToolbar(): Toolbar { | |||||
return inflater.inflate(R.layout.toolbar, null) as Toolbar | ||||||
} | ||||||
|
||||||
fun ViewGroup.buildKonfettiView(): View { | ||||||
val inflater = LayoutInflater.from(context) | ||||||
return inflater.inflate(R.layout.konfetti, null) as View | ||||||
} | ||||||
|
||||||
fun showConfetti(view: View) { | ||||||
val viewId = R.id.konfetttiView | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Is this a typo or is there a reason to have 3 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not typo, i was just using 3 |
||||||
val linearLayout = view.findViewById<LinearLayout>(R.id.konfettiLayout) | ||||||
val kv = view.findViewById<KonfettiView>(viewId) | ||||||
if (linearLayout != null) { | ||||||
linearLayout.bringToFront() | ||||||
} | ||||||
val party = Party( | ||||||
speed = 0f, | ||||||
maxSpeed = 32f, | ||||||
damping = 0.9f, | ||||||
spread = 360, | ||||||
colors = listOf(0xfce18a, 0xff726d, 0xf4306d, 0xb48def, 0x818181, 0x81a48c), | ||||||
position = Position.Relative(0.5, 0.3), | ||||||
emitter = Emitter(duration = 300, TimeUnit.MILLISECONDS).max(300) | ||||||
) | ||||||
if (kv != null) { | ||||||
kv.start(party) | ||||||
} | ||||||
} | ||||||
|
||||||
fun View.showMessage(msg: String) { | ||||||
try { | ||||||
val snackbar = Snackbar.make(this, msg, Snackbar.LENGTH_SHORT) | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,29 @@ | ||||||
<?xml version="1.0" encoding="utf-8"?> | ||||||
<!-- | ||||||
~ Copyright (C) 2013 The Android Open Source Project | ||||||
~ | ||||||
~ 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 | ||||||
--> | ||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
android:id="@+id/konfettiLayout" | ||||||
android:layout_width="wrap_content" | ||||||
android:layout_height="match_parent" | ||||||
android:focusable="false" | ||||||
android:orientation="vertical" > | ||||||
|
||||||
<nl.dionsegijn.konfetti.xml.KonfettiView | ||||||
android:layout_width="match_parent" | ||||||
android:layout_height="match_parent" | ||||||
android:id="@+id/konfetttiView"/> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
</LinearLayout> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it should be on completion rather than for any value? Not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a code comment.
Reason: I thought it would be motivating for users to at least add some value rather than not doing the habit. 😸