Skip to content

Commit

Permalink
fix full screen lottie
Browse files Browse the repository at this point in the history
  • Loading branch information
x3rocode committed Oct 4, 2022
1 parent 0d32383 commit 94457f2
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 38 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies {
implementation 'com.airbnb.android:lottie:5.2.0'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

implementation project(":library")
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.DialogInterface
import android.graphics.Color
import android.os.Bundle
import android.os.CountDownTimer
import android.provider.SyncStateContract
import android.view.View
import android.view.Window
import android.view.WindowManager
Expand All @@ -13,15 +14,14 @@ import android.widget.CheckBox
import android.widget.EditText
import android.widget.LinearLayout
import androidx.appcompat.app.AppCompatActivity
import com.fascinate98.library.Constants
import com.fascinate98.library.SweetLottieAlertDialog
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.activity_main.view.*


class MainActivity : AppCompatActivity(), View.OnClickListener {
class MainActivity : AppCompatActivity() , View.OnClickListener{

private lateinit var sd : SweetLottieAlertDialog
private lateinit var sd: SweetLottieAlertDialog
private var i = -1
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -47,23 +47,35 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
)
for (id in btnIds) {
findViewById<Button>(id).setOnClickListener ( this )
findViewById<Button>(id).setOnTouchListener(Constants.FOCUS_TOUCH_LISTENER)
// findViewById<Button>(id).setOnTouchListener(SyncStateContract.Constants.FOCUS_TOUCH_LISTENER)
}

button1.setOnClickListener {
val lsd = SweetLottieAlertDialog(this, SweetLottieAlertDialog.NORMAL_TYPE)
//text in alert
lsd.contentText = "Congratulation!"
//set full screen lottie.
//setPopupLottieAnimation(your_lottie_res, isLoop(boolean), elevation);
lsd.setPopupLottieAnimation(R.raw.lottie_congratulation, false, 999f)
lsd.show()
}


}


override fun onClick(v: View) {
when (v.id) {

basic_lottie_test.id -> {
lottie_test.visibility= View.VISIBLE
val lsd = SweetLottieAlertDialog(this, SweetLottieAlertDialog.CUSTOM_IMAGE_TYPE)
lottie_test.visibility = View.VISIBLE
val lsd = SweetLottieAlertDialog(this, SweetLottieAlertDialog.CUSTOM_IMAGE_TYPE)
lottie_test.addAnimatorListener(object : Animator.AnimatorListener {

override fun onAnimationStart(animation: Animator) {

}

override fun onAnimationEnd(animation: Animator) {
lsd.dismissWithAnimation()
}
Expand All @@ -85,24 +97,39 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {

}
basic_lottie_by_id_test.id -> {
//1. you have to set type SweetLottieAlertDialog.LOTTIE_ID_TYPE.
val lsd2 = SweetLottieAlertDialog(this, SweetLottieAlertDialog.LOTTIE_ID_TYPE)
lsd2.contentText = "Try Again!"
lsd2.setLottieImagebyId(R.raw.lottie_cryingface, true, null)
//2. setLottieImagebyId(your_lottie_res, isLoop(boolean), listner)
lsd2.setLottieImagebyId(R.raw.ok_btn_lottie, false, object : Animator.AnimatorListener {

override fun onAnimationStart(animation: Animator) {

}

override fun onAnimationEnd(animation: Animator) {
lsd2.dismissWithAnimation()
}

override fun onAnimationCancel(animation: Animator) {
}

override fun onAnimationRepeat(animation: Animator) {
}
})
lsd2.contentText = "Success!"
lsd2.setCancelable(true)
lsd2.confirmText = "OK"
lsd2.setCanceledOnTouchOutside(true)
lsd2.setButtonTextFont(R.font.lexend_deca)
lsd2.show()
}
basic_lottie_popup_test.id -> {
val lsd2 = SweetLottieAlertDialog(this, SweetLottieAlertDialog.LOTTIE_ID_TYPE)
lsd2.contentText = "Congratulation!"
lsd2.setLottieImagebyId(R.raw.lottie_happyface, true, null)
lsd2.setCancelable(true)
lsd2.setPopupLottieAnimation(R.raw.lottie_congratulation, false, 999f)
lsd2.setCanceledOnTouchOutside(true)
lsd2.setButtonTextFont(R.font.lexend_deca)
lsd2.show()
val lsd = SweetLottieAlertDialog(this, SweetLottieAlertDialog.LOTTIE_ID_TYPE)
lsd.contentText = "Congratulation!"
lsd.setLottieImagebyId(R.raw.bg_lottie, true, null)
lsd.setCancelable(true)
lsd.setPopupLottieAnimation(R.raw.lottie_congratulation, false, 999f)
lsd.setCanceledOnTouchOutside(true)
lsd.setButtonTextFont(R.font.lexend_deca)
lsd.show()
}

popup_lottie_behind_test.id -> {
Expand Down Expand Up @@ -134,7 +161,10 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
.setTitleText("Title")
.setContentText("It's pretty, isn't it?")
.show()
styled_text_and_stroke.id -> SweetLottieAlertDialog(this, SweetLottieAlertDialog.NORMAL_TYPE)
styled_text_and_stroke.id -> SweetLottieAlertDialog(
this,
SweetLottieAlertDialog.NORMAL_TYPE
)
.setTitleText("<font color='red'>Red</font> title")
.setContentText("Big <font color='green'>green </font><b><i> bold</i></b>")
.setContentTextSize(21)
Expand All @@ -144,22 +174,32 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
.setTitleText("Oops...")
.setContentText("Something went wrong!")
.show()
success_text_test.id -> SweetLottieAlertDialog(this, SweetLottieAlertDialog.SUCCESS_TYPE)
success_text_test.id -> SweetLottieAlertDialog(
this,
SweetLottieAlertDialog.SUCCESS_TYPE
)
.setTitleText("Good job!")
.setContentText("You clicked the button!")
.show()
warning_confirm_test.id -> SweetLottieAlertDialog(this, SweetLottieAlertDialog.WARNING_TYPE)
warning_confirm_test.id -> SweetLottieAlertDialog(
this,
SweetLottieAlertDialog.WARNING_TYPE
)
.setTitleText("Are you sure?")
.setContentText("Won't be able to recover this file!")
.setCancelButton("Yes, delete it!"
.setCancelButton(
"Yes, delete it!"
) { sweetAlertDialog -> // reuse previous dialog instance
sweetAlertDialog.setTitleText("Deleted!")
.setContentText("Your imaginary file has been deleted!")
.setConfirmClickListener(null)
.changeAlertType(SweetLottieAlertDialog.SUCCESS_TYPE)
}
.show()
warning_cancel_test.id -> SweetLottieAlertDialog(this, SweetLottieAlertDialog.WARNING_TYPE)
warning_cancel_test.id -> SweetLottieAlertDialog(
this,
SweetLottieAlertDialog.WARNING_TYPE
)
.setTitleText("Are you sure?")
.setContentText("Won't be able to recover this file!")
.setCancelText("No, cancel pls!")
Expand Down Expand Up @@ -192,7 +232,10 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
.changeAlertType(SweetLottieAlertDialog.SUCCESS_TYPE)
}
.show()
custom_img_test.id -> SweetLottieAlertDialog(this, SweetLottieAlertDialog.CUSTOM_IMAGE_TYPE)
custom_img_test.id -> SweetLottieAlertDialog(
this,
SweetLottieAlertDialog.CUSTOM_IMAGE_TYPE
)
.setTitleText("Sweet!")
.setContentText("Here's a custom image.")
.setCustomImage(R.drawable.custom_img)
Expand Down Expand Up @@ -270,13 +313,17 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
linearLayout.orientation = LinearLayout.VERTICAL
linearLayout.addView(editText)
linearLayout.addView(checkBox)
val dialog: SweetLottieAlertDialog = SweetLottieAlertDialog(this, SweetLottieAlertDialog.NORMAL_TYPE)
.setTitleText("Custom view")
.hideConfirmButton()
val dialog: SweetLottieAlertDialog =
SweetLottieAlertDialog(this, SweetLottieAlertDialog.NORMAL_TYPE)
.setTitleText("Custom view")
.hideConfirmButton()
dialog.setCustomView(linearLayout)
dialog.show()
}
custom_btn_colors_test.id -> SweetLottieAlertDialog(this, SweetLottieAlertDialog.NORMAL_TYPE)
custom_btn_colors_test.id -> SweetLottieAlertDialog(
this,
SweetLottieAlertDialog.NORMAL_TYPE
)
.setTitleText("Custom view")
.setCancelButton("red", null)
.setCancelButtonBackgroundColor(Color.RED)
Expand All @@ -287,7 +334,6 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
.show()



}


Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
style="@style/description_style"
android:text="A basic message" />

<Button
android:id="@+id/button1"
style="@style/dialog_blue_button"
android:layout_margin="10dp"
android:text="Try me!" />

<Button
android:id="@+id/basic_test"
style="@style/dialog_blue_button"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/raw/bg_lottie.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
Expand Down Expand Up @@ -210,6 +211,8 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.alert_dialog);



mDialogView = getWindow().getDecorView().findViewById(android.R.id.content);
mTitleTextView = (TextView)findViewById(R.id.title_text);
mContentTextView = (TextView)findViewById(R.id.content_text);
Expand Down Expand Up @@ -342,7 +345,7 @@ private void changeAlertType(int alertType, boolean fromCreate) {
}
}

public int getAlerType () {
public int getAlertType () {
return mAlertType;
}

Expand Down Expand Up @@ -626,7 +629,6 @@ public SweetLottieAlertDialog setPopupLottieAnimation (int lottieRes, boolean is
mPopupLottieElevation = popupLottieElevation;

if (mPopupLottieRes != 0 && mPopupLottieAnimationView != null) {

mPopupLottieAnimationView.setVisibility(View.VISIBLE);
mPopupLottieAnimationView.setAnimation(mPopupLottieRes);
mPopupLottieAnimationView.playAnimation();
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/res/layout/alert_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
android:elevation="1dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:scaleType="centerCrop"
wheel:lottie_rawRes="@raw/testlottie"
wheel:lottie_autoPlay="true"
android:visibility="gone"
Expand Down
1 change: 0 additions & 1 deletion library/src/main/res/raw/coin_lottie.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions library/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="alert_dialog_light" parent="android:Theme.Dialog">
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowBackground">@color/float_transparent</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowAnimationStyle">@null</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:backgroundDimAmount">0.4</item>
Expand All @@ -18,11 +18,11 @@


<style name="alert_dialog_dark" parent="alert_dialog_light">
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowBackground">@color/float_transparent</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowAnimationStyle">@null</item>
<item name="android:backgroundDimEnabled">true</item>

Expand Down

0 comments on commit 94457f2

Please sign in to comment.