Commit 4251af72 authored by Anuththara18's avatar Anuththara18

Introductory Videos for games - Code Fix

parent de7c1b0c
...@@ -4,7 +4,13 @@ import android.content.Intent; ...@@ -4,7 +4,13 @@ import android.content.Intent;
import android.media.MediaPlayer; import android.media.MediaPlayer;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.MediaController; import android.widget.MediaController;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import android.widget.VideoView; import android.widget.VideoView;
...@@ -17,19 +23,25 @@ import com.anuththara18.attentionassessment.focused.AnimalChoosingActivity; ...@@ -17,19 +23,25 @@ import com.anuththara18.attentionassessment.focused.AnimalChoosingActivity;
import com.anuththara18.attentionassessment.focused.FocusedAttentionGame1; import com.anuththara18.attentionassessment.focused.FocusedAttentionGame1;
import com.anuththara18.attentionassessment.focused.FocusedAttentionGame2; import com.anuththara18.attentionassessment.focused.FocusedAttentionGame2;
import com.anuththara18.attentionassessment.home.MainFragment; import com.anuththara18.attentionassessment.home.MainFragment;
import com.anuththara18.attentionassessment.language.LanguageSetter;
import com.anuththara18.attentionassessment.map.Map1Activity; import com.anuththara18.attentionassessment.map.Map1Activity;
import com.anuththara18.attentionassessment.map.Map2Activity; import com.anuththara18.attentionassessment.map.Map2Activity;
import com.anuththara18.attentionassessment.selective.SelectiveAttentionGame1;
import com.anuththara18.attentionassessment.sustained.BirdChoosingActivity; import com.anuththara18.attentionassessment.sustained.BirdChoosingActivity;
public class IntroductoryVideoLandscapeActivity extends AppCompatActivity { public class IntroductoryVideoLandscapeActivity extends AppCompatActivity {
String videoUrl = "https://media.geeksforgeeks.org/wp-content/uploads/20201217192146/Screenrecorder-2020-12-17-19-17-36-828.mp4?_=1"; String videoStr;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_introductory_video); setContentView(R.layout.activity_introductory_video);
TextView skip = findViewById(R.id.skip);
skip.setText(LanguageSetter.getresources().getString(R.string.skip));
/*
// finding videoview by its id // finding videoview by its id
VideoView videoView = findViewById(R.id.videoView); VideoView videoView = findViewById(R.id.videoView);
...@@ -40,35 +52,11 @@ public class IntroductoryVideoLandscapeActivity extends AppCompatActivity { ...@@ -40,35 +52,11 @@ public class IntroductoryVideoLandscapeActivity extends AppCompatActivity {
videoUrl = ""; videoUrl = "";
} }
// Uri object to refer the */
// resource from the videoUrl
Uri uri = Uri.parse(videoUrl);
// sets the resource from the
// videoUrl to the videoView
videoView.setVideoURI(uri);
// creating object of
// media controller class
MediaController mediaController = new MediaController(this);
// sets the anchor view
// anchor view for the videoView
mediaController.setAnchorView(videoView);
// sets the media player to the videoView
mediaController.setMediaPlayer(videoView);
// sets the media controller to the videoView
videoView.setMediaController(mediaController);
// starts the video skip.setOnClickListener(new View.OnClickListener() {
videoView.start();
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override @Override
public void onCompletion(MediaPlayer mp) { public void onClick(View view) {
//Toast.makeText(getApplicationContext(), "Video completed", Toast.LENGTH_LONG).show();
if (MainFragment.game.equals("focused")) { if (MainFragment.game.equals("focused")) {
if (Map1Activity.level == 1){ if (Map1Activity.level == 1){
startActivity(new Intent(getApplicationContext(), FocusedAttentionGame2.class)); startActivity(new Intent(getApplicationContext(), FocusedAttentionGame2.class));
...@@ -86,6 +74,34 @@ public class IntroductoryVideoLandscapeActivity extends AppCompatActivity { ...@@ -86,6 +74,34 @@ public class IntroductoryVideoLandscapeActivity extends AppCompatActivity {
} }
}); });
if (MainFragment.game.equals("focused")) {
if (Map1Activity.level == 1 || Map1Activity.level == 2) {
videoStr = "<html><body><iframe width=\"100%\" height=\"100%\" src=\"https://www.youtube.com/embed/9n7kxFr-nBA\" frameborder=\"0\" allowfullscreen></iframe></body></html>";
}
else if (Map1Activity.level == 5){
videoStr = "<html><body><iframe width=\"100%\" height=\"100%\" src=\"https://www.youtube.com/embed/9n7kxFr-nBA\" frameborder=\"0\" allowfullscreen></iframe></body></html>";
}
}
else if (MainFragment.game.equals("alternating")) {
videoStr = "<html><body><iframe width=\"100%\" height=\"100%\" src=\"https://www.youtube.com/embed/9n7kxFr-nBA\" frameborder=\"0\" allowfullscreen></iframe></body></html>";
}
Log.i("*********************************************************Video", "Video Playing....");
WebView mWebView=(WebView)findViewById(R.id.videoView);
int height = 2;
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
WebSettings ws = mWebView.getSettings();
ws.setJavaScriptEnabled(true);
mWebView.loadData(videoStr, "text/html", "utf-8");
} }
} }
\ No newline at end of file
...@@ -10,11 +10,14 @@ import android.graphics.Bitmap; ...@@ -10,11 +10,14 @@ import android.graphics.Bitmap;
import android.media.MediaPlayer; import android.media.MediaPlayer;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.DownloadListener; import android.webkit.DownloadListener;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import android.widget.MediaController; import android.widget.MediaController;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import android.widget.VideoView; import android.widget.VideoView;
...@@ -23,84 +26,30 @@ import com.anuththara18.attentionassessment.dividedattention.DividedAttentionGam ...@@ -23,84 +26,30 @@ import com.anuththara18.attentionassessment.dividedattention.DividedAttentionGam
import com.anuththara18.attentionassessment.focused.AnimalChoosingActivity; import com.anuththara18.attentionassessment.focused.AnimalChoosingActivity;
import com.anuththara18.attentionassessment.focused.FocusedAttentionGame1; import com.anuththara18.attentionassessment.focused.FocusedAttentionGame1;
import com.anuththara18.attentionassessment.home.MainFragment; import com.anuththara18.attentionassessment.home.MainFragment;
import com.anuththara18.attentionassessment.language.LanguageSetter;
import com.anuththara18.attentionassessment.map.Map1Activity; import com.anuththara18.attentionassessment.map.Map1Activity;
import com.anuththara18.attentionassessment.map.Map2Activity; import com.anuththara18.attentionassessment.map.Map2Activity;
import com.anuththara18.attentionassessment.selective.SelectiveAttentionGame1; import com.anuththara18.attentionassessment.selective.SelectiveAttentionGame1;
import com.anuththara18.attentionassessment.sustained.BirdChoosingActivity; import com.anuththara18.attentionassessment.sustained.BirdChoosingActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;
public class IntroductoryVideoPortraitActivity extends AppCompatActivity { public class IntroductoryVideoPortraitActivity extends AppCompatActivity {
//String videoUrl; String videoStr;
String videoUrl = "https://1drv.ms/v/s!AvtsEIqJweWzmFqPURb36VGZZJpp";
//String videoUrl = "https://drive.google.com/file/d/1Qt8C8Ucf0icgnLYdBSfhThm1nQbatGDa/view?usp=sharing";
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_introductory_video); setContentView(R.layout.activity_introductory_video);
/* TextView skip = findViewById(R.id.skip);
if (MainFragment.game.equals("focused")) { skip.setText(LanguageSetter.getresources().getString(R.string.skip));
videoUrl = "https://media.geeksforgeeks.org/wp-content/uploads/20201217192146/Screenrecorder-2020-12-17-19-17-36-828.mp4?_=1";
}
else if (MainFragment.game.equals("divided")) {
videoUrl = "https://1drv.ms/v/s!AvtsEIqJweWzmFqPURb36VGZZJpp";
}
else if (MainFragment.game.equals("selective")) {
videoUrl = "";
}
else if (MainFragment.game.equals("sustained")) {
videoUrl = "";
}
*/
// initialising the web view
WebView wv = (WebView) findViewById(R.id.videoView);
// add your link here
wv.loadUrl("https://drive.google.com/file/d/1Qt8C8Ucf0icgnLYdBSfhThm1nQbatGDa/view?usp=sharing");
//wv.loadUrl("https://1drv.ms/v/s!AvtsEIqJweWzmFqPURb36VGZZJpp");
wv.setWebViewClient(new Client());
WebSettings ws = wv.getSettings();
// Enabling javascript
ws.setJavaScriptEnabled(true);
wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
wv.clearCache(true);
wv.clearHistory();
// download manager is a service that can be used to handle downloads
wv.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String s1, String s2, String s3, long l) {
DownloadManager.Request req = new DownloadManager.Request(Uri.parse(url));
req.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(req);
Toast.makeText(IntroductoryVideoPortraitActivity.this, "Downloading....", Toast.LENGTH_SHORT).show();
}
});
/*
VideoView videoView = findViewById(R.id.videoView);
Uri uri = Uri.parse(videoUrl);
videoView.setVideoURI(uri);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
mediaController.setMediaPlayer(videoView);
videoView.setMediaController(mediaController);
videoView.start();
*/ skip.setOnClickListener(new View.OnClickListener() {
/*
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override @Override
public void onCompletion(MediaPlayer mp) { public void onClick(View view) {
//Toast.makeText(getApplicationContext(), "Video completed", Toast.LENGTH_LONG).show();
if (MainFragment.game.equals("focused")) { if (MainFragment.game.equals("focused")) {
if (Map1Activity.level == 3){ if (Map1Activity.level == 3){
startActivity(new Intent(getApplicationContext(), AnimalChoosingActivity.class)); startActivity(new Intent(getApplicationContext(), AnimalChoosingActivity.class));
...@@ -120,57 +69,37 @@ public class IntroductoryVideoPortraitActivity extends AppCompatActivity { ...@@ -120,57 +69,37 @@ public class IntroductoryVideoPortraitActivity extends AppCompatActivity {
} }
} }
}); });
*/
if (MainFragment.game.equals("focused")) {
videoStr = "<html><body><iframe width=\"100%\" height=\"100%\" src=\"https://www.youtube.com/embed/9n7kxFr-nBA\" frameborder=\"0\" allowfullscreen></iframe></body></html>";
} }
else if (MainFragment.game.equals("divided")) {
private class Client extends WebViewClient { videoStr = "<html><body><iframe width=\"100%\" height=\"100%\" src=\"https://www.youtube.com/embed/9n7kxFr-nBA\" frameborder=\"0\" allowfullscreen></iframe></body></html>";
// on page started load start loading the url
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
} }
else if (MainFragment.game.equals("selective")) {
// load the url of our drive videoStr = "<html><body><iframe width=\"100%\" height=\"100%\" src=\"https://www.youtube.com/embed/9n7kxFr-nBA\" frameborder=\"0\" allowfullscreen></iframe></body></html>";
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
} }
else if (MainFragment.game.equals("sustained")) {
@Override videoStr = "<html><body><iframe width=\"100%\" height=\"100%\" src=\"https://www.youtube.com/embed/9n7kxFr-nBA\" frameborder=\"0\" allowfullscreen></iframe></body></html>";
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
} }
public void onReceivedError(WebView webView, int errorCode, String description, String failingUrl) { Log.i("*********************************************************Video", "Video Playing....");
// if stop loading
try {
webView.stopLoading();
} catch (Exception e) {
}
if (webView.canGoBack()) { WebView mWebView=(WebView)findViewById(R.id.videoView);
webView.goBack();
} int height = 2;
// if loaded blank then show error mWebView.setWebViewClient(new WebViewClient() {
// to check internet connection using @Override
// alert dialog public boolean shouldOverrideUrlLoading(WebView view, String url) {
webView.loadUrl("about:blank"); return false;
AlertDialog alertDialog = new AlertDialog.Builder(IntroductoryVideoPortraitActivity.this).create();
alertDialog.setTitle("Error");
alertDialog.setMessage("Check your internet connection and Try again.");
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Try Again", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
startActivity(getIntent());
} }
}); });
WebSettings ws = mWebView.getSettings();
ws.setJavaScriptEnabled(true);
mWebView.loadData(videoStr, "text/html", "utf-8");
alertDialog.show();
super.onReceivedError(webView, errorCode, description, failingUrl);
}
} }
} }
\ No newline at end of file
...@@ -6,6 +6,7 @@ buildscript { ...@@ -6,6 +6,7 @@ buildscript {
} }
dependencies { dependencies {
classpath "com.android.tools.build:gradle:4.1.3" classpath "com.android.tools.build:gradle:4.1.3"
classpath 'com.google.gms:google-services:4.3.10'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment