Skip to content

Instantly share code, notes, and snippets.

@rogergcc
Last active July 2, 2020 21:30
Show Gist options
  • Save rogergcc/557f51940dd400b35893ffe5bad04e59 to your computer and use it in GitHub Desktop.
Save rogergcc/557f51940dd400b35893ffe5bad04e59 to your computer and use it in GitHub Desktop.
Custom Layout for Dialog with Lottie Animations
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:id="@+id/layoutRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_gravity="center"
tools:context=".ui.offlineGame.GameOfflineActivity"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/myconstraint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="24dp"
android:paddingEnd="24dp">
<RelativeLayout
android:padding="@dimen/fab_margin"
android:id="@+id/relative"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="75dp"
android:background="@drawable/custom_back_button"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
</RelativeLayout>
<ImageView
android:id="@+id/imgv_frcl_complet_elevels"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:adjustViewBounds="true"
android:src="@drawable/pluto_success_1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_complete_congrats"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:gravity="center"
android:text="@string/tv_winner_complete_levels"
android:textColor="@color/duskYellow"
android:textSize="26sp"
app:layout_constraintEnd_toEndOf="@+id/relative"
app:layout_constraintStart_toStartOf="@+id/relative"
app:layout_constraintTop_toBottomOf="@+id/imgv_frcl_complet_elevels" />
<TextView
android:id="@+id/tv_messag_complete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="24dp"
android:gravity="center"
android:text="Beginner Mode"
android:textSize="22sp"
app:layout_constraintEnd_toEndOf="@+id/relative"
app:layout_constraintStart_toStartOf="@+id/relative"
app:layout_constraintTop_toBottomOf="@+id/tv_complete_congrats" />
<Button
android:id="@+id/btn_complete_levels_continue"
android:layout_width="wrap_content"
android:layout_height="56dp"
android:layout_marginTop="16dp"
android:background="@drawable/mode_selection_back"
android:padding="@dimen/padding_top"
android:text="@string/btn_complete_continue_playing"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="@+id/relative"
app:layout_constraintEnd_toEndOf="@+id/relative"
app:layout_constraintStart_toStartOf="@+id/relative"
app:layout_constraintTop_toBottomOf="@+id/tv_messag_complete" />
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/lottie_win_levels"
android:layout_width="0dp"
android:layout_height="0dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:lottie_loop="true" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
//Activity => GameOfflineActivity
Dialog dialogCompleteLevels = new Dialog(GameOfflineActivity.this);
private void configDialogCompleteLevels() {
dialogCompleteLevels.setContentView(R.layout.dialog_complet_levels);
dialogCompleteLevels.setCancelable(false);
btn_complete_levels_continue = dialogCompleteLevels.findViewById(R.id.btn_complete_levels_continue);
if (dialogCompleteLevels.getWindow() == null) {
return;
}
dialogCompleteLevels.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
Window window = dialogCompleteLevels.getWindow();
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
window.setGravity(Gravity.CENTER);
lottieAnimation = dialogCompleteLevels.findViewById(R.id.lottie_win_levels);
lottieAnimation.setVisibility(View.VISIBLE);
lottieAnimation.bringToFront();
lottieAnimation.setAnimation("colorful_confetti.json");
lottieAnimation.playAnimation();
}
private void openDialogWinLevels() {
if (!lottieAnimation.isAnimating()) {
lottieAnimation.playAnimation();
}
dialogCompleteLevels.show();
ConstantsGame.COUNT_COMPLET_LEVEL++;
int getSharefWinslevels = SharedPrefsManager.getInstance().getInt(AppConstants.COMPLETE_LEVEL, 0);
getSharefWinslevels++;
SharedPrefsManager.getInstance().setInt(AppConstants.COMPLETE_LEVEL, getSharefWinslevels);
TextView tv_messag_complete = dialogCompleteLevels.findViewById(R.id.tv_messag_complete);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment