From b4fd784a9e01ba9c0d6fe447987bbb575d4279c4 Mon Sep 17 00:00:00 2001 From: Sultan Mustafijul Hoque Date: Thu, 7 Dec 2023 14:07:53 +0530 Subject: [PATCH] Progress bar replaced with Lottie --- .../sultan/plantdatabse/WebViewActivity.java | 19 +++++++++++++------ app/src/main/res/layout/activity_webview.xml | 10 ++++++---- app/src/main/res/raw/loading2.json | 1 + 3 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 app/src/main/res/raw/loading2.json diff --git a/app/src/main/java/com/sultan/plantdatabse/WebViewActivity.java b/app/src/main/java/com/sultan/plantdatabse/WebViewActivity.java index 59ccc29..909e9af 100644 --- a/app/src/main/java/com/sultan/plantdatabse/WebViewActivity.java +++ b/app/src/main/java/com/sultan/plantdatabse/WebViewActivity.java @@ -11,18 +11,19 @@ import android.webkit.WebResourceRequest; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Button; -import android.widget.ProgressBar; import android.widget.Toast; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import com.airbnb.lottie.LottieAnimationView; import com.google.zxing.integration.android.IntentIntegrator; import com.google.zxing.integration.android.IntentResult; public class WebViewActivity extends AppCompatActivity implements View.OnClickListener { - private ProgressBar progressBar; + // private ProgressBar progressBar; + private LottieAnimationView lottieAnimationView; Button scanAgainButton; Button btnHome; @@ -34,7 +35,8 @@ public class WebViewActivity extends AppCompatActivity implements View.OnClickLi scanAgainButton = findViewById(R.id.scanAgain); btnHome = findViewById(R.id.btnHome); - progressBar = findViewById(R.id.progressBar); + // progressBar = findViewById(R.id.progressBar); + lottieAnimationView = findViewById(R.id.lottieAnimationView); // Retrieve the URL from the intent String url = getIntent().getStringExtra("url"); @@ -46,19 +48,24 @@ public class WebViewActivity extends AppCompatActivity implements View.OnClickLi @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { // Show the progress bar when the page starts loading - progressBar.setVisibility(View.VISIBLE); + // progressBar.setVisibility(View.VISIBLE); + // Show the Lottie animation when the page starts loading + lottieAnimationView.setVisibility(View.VISIBLE); } @Override public void onPageFinished(WebView view, String url) { // Hide the progress bar when the page finishes loading - progressBar.setVisibility(View.INVISIBLE); + // progressBar.setVisibility(View.INVISIBLE); + // Hide the Lottie animation when the page finishes loading + lottieAnimationView.setVisibility(View.INVISIBLE); } @Override public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { // Handle page load error Toast.makeText(WebViewActivity.this, "Failed to load the page", Toast.LENGTH_SHORT).show(); - progressBar.setVisibility(View.INVISIBLE); + // progressBar.setVisibility(View.INVISIBLE); + lottieAnimationView.setVisibility(View.INVISIBLE); } }); diff --git a/app/src/main/res/layout/activity_webview.xml b/app/src/main/res/layout/activity_webview.xml index 7ab9637..02948e6 100644 --- a/app/src/main/res/layout/activity_webview.xml +++ b/app/src/main/res/layout/activity_webview.xml @@ -4,6 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="@color/white" tools:context=".WebViewActivity"> @@ -34,7 +35,8 @@ android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" - android:text="Scan QR"/> + android:backgroundTint="#0F9D58" + android:text="Scan QR Code"/>