package com.example.momskart.ui.gallery; import android.graphics.Bitmap; import android.os.Bundle; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.ProgressBar; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; import com.example.momskart.R; import com.example.momskart.databinding.FragmentGalleryBinding; public class GalleryFragment extends Fragment { private GalleryViewModel galleryViewModel; private FragmentGalleryBinding binding; public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { galleryViewModel = new ViewModelProvider(this).get(GalleryViewModel.class); binding = FragmentGalleryBinding.inflate(inflater, container, false); View root = binding.getRoot(); final WebView specialWebView = binding.idWebViewSpecail; final ProgressBar loadingPB =binding.idPBLoading; specialWebView.loadUrl("https://themomskart.com/categorypage/Homemade-Biscuits-&-Cookies%3Fcat_id%3D11%3Fsup_cat_id%3D18&marketplace%3DMOMSKART"); specialWebView.setWebViewClient(new WebViewClient(){ @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); loadingPB.setVisibility(View.VISIBLE); } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); loadingPB.setVisibility(View.GONE); } }); specialWebView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View view, int i, KeyEvent keyEvent) { if (keyEvent.getAction()==KeyEvent.ACTION_DOWN){ switch (keyCode){ case KeyEvent.KEYCODE_BACK: if(specialWebView.canGoBack()){ specialWebView.canGoBack(); } } } return false; } }); return root; } @Override public void onDestroyView() { super.onDestroyView(); binding = null; } }
keyCode
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)