1717import android .view .Window ;
1818import android .view .WindowManager ;
1919import android .webkit .SslErrorHandler ;
20+ import android .webkit .WebSettings ;
2021import android .webkit .WebView ;
2122import android .webkit .WebViewClient ;
2223import android .widget .Button ;
@@ -42,7 +43,7 @@ public class KioskActivity extends Activity implements Observer {
4243
4344 private final Context context = this ;
4445 private WebView webView ;
45- private TextView face_detection_score ;
46+ private TextView face_detection_score , face_counter_view ;
4647 private static String password = "1234" ;
4748 private static String URL = "" ;
4849
@@ -105,6 +106,7 @@ protected void onCreate(Bundle savedInstanceState) {
105106 //Get the webView and load the URL
106107 webView = findViewById (R .id .webview );
107108 face_detection_score = findViewById (R .id .face_detection_score );
109+ face_counter_view = findViewById (R .id .face_counter );
108110 webView .setWebViewClient (new WebViewClient () {
109111 @ Override
110112 public void onPageFinished (final WebView view , String url ) {
@@ -140,6 +142,9 @@ public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError e
140142 }
141143 });
142144 webView .getSettings ().setJavaScriptEnabled (true );
145+ webView .getSettings ().setAppCacheEnabled (true );
146+ webView .getSettings ().setAppCacheMaxSize (5000 * 1000 * 1000 );
147+ webView .getSettings ().setCacheMode (WebSettings .LOAD_CACHE_ELSE_NETWORK );
143148 webView .getSettings ().setMediaPlaybackRequiresUserGesture (false );
144149 webView .loadUrl (URL );
145150
@@ -455,7 +460,14 @@ private boolean checkCameraHardware(Context context) {
455460 }
456461 }
457462
463+ @ Override
464+ protected void onPause () {
465+ super .onPause ();
466+ }
467+
458468 private long last_detected = 0 ;
469+ private long face_current_counter = 0 ;
470+ private long face_counter = 0 ;
459471
460472 @ Override
461473 public void update (Observable o , Object arg ) {
@@ -464,10 +476,20 @@ public void update(Observable o, Object arg) {
464476
465477 face_detection_score .setText ("Score:" + face .score );
466478
467- last_detected = System .currentTimeMillis ();
468- if (face .score >= 85 && last_detected <= System .currentTimeMillis () + 5000 ) {
469- Toast .makeText (context , "Hello face +1" , Toast .LENGTH_SHORT ).show ();
479+ if (face .score >= 85 ) {
480+ face_current_counter ++;
481+ } else {
482+ face_current_counter = 0 ;
483+ }
484+
485+ if (face_current_counter >= 5 && last_detected < System .currentTimeMillis () + 45000 ) {
486+ face_counter ++;
487+ last_detected = System .currentTimeMillis ();
488+ face_current_counter = -5000 ;
470489 }
490+
491+ face_counter_view .setText ("Viewers: " + face_counter );
492+
471493 }
472494 }
473495}
0 commit comments