diff --git a/mobileapp/android/.gradle/6.1.1/executionHistory/executionHistory.bin b/mobileapp/android/.gradle/6.1.1/executionHistory/executionHistory.bin index d85d34f..e99c49f 100644 Binary files a/mobileapp/android/.gradle/6.1.1/executionHistory/executionHistory.bin and b/mobileapp/android/.gradle/6.1.1/executionHistory/executionHistory.bin differ diff --git a/mobileapp/android/.gradle/6.1.1/executionHistory/executionHistory.lock b/mobileapp/android/.gradle/6.1.1/executionHistory/executionHistory.lock index 431fec6..d513a7e 100644 Binary files a/mobileapp/android/.gradle/6.1.1/executionHistory/executionHistory.lock and b/mobileapp/android/.gradle/6.1.1/executionHistory/executionHistory.lock differ diff --git a/mobileapp/android/.gradle/6.1.1/fileHashes/fileHashes.bin b/mobileapp/android/.gradle/6.1.1/fileHashes/fileHashes.bin index 1ad05c1..1d425f4 100644 Binary files a/mobileapp/android/.gradle/6.1.1/fileHashes/fileHashes.bin and b/mobileapp/android/.gradle/6.1.1/fileHashes/fileHashes.bin differ diff --git a/mobileapp/android/.gradle/6.1.1/fileHashes/fileHashes.lock b/mobileapp/android/.gradle/6.1.1/fileHashes/fileHashes.lock index f82fc10..b3de876 100644 Binary files a/mobileapp/android/.gradle/6.1.1/fileHashes/fileHashes.lock and b/mobileapp/android/.gradle/6.1.1/fileHashes/fileHashes.lock differ diff --git a/mobileapp/android/.gradle/6.1.1/fileHashes/resourceHashesCache.bin b/mobileapp/android/.gradle/6.1.1/fileHashes/resourceHashesCache.bin index 8308bdb..b7aadfe 100644 Binary files a/mobileapp/android/.gradle/6.1.1/fileHashes/resourceHashesCache.bin and b/mobileapp/android/.gradle/6.1.1/fileHashes/resourceHashesCache.bin differ diff --git a/mobileapp/android/.gradle/6.1.1/javaCompile/classAnalysis.bin b/mobileapp/android/.gradle/6.1.1/javaCompile/classAnalysis.bin index c1c4921..a14cfdf 100644 Binary files a/mobileapp/android/.gradle/6.1.1/javaCompile/classAnalysis.bin and b/mobileapp/android/.gradle/6.1.1/javaCompile/classAnalysis.bin differ diff --git a/mobileapp/android/.gradle/6.1.1/javaCompile/javaCompile.lock b/mobileapp/android/.gradle/6.1.1/javaCompile/javaCompile.lock index 32d0e3b..484dd39 100644 Binary files a/mobileapp/android/.gradle/6.1.1/javaCompile/javaCompile.lock and b/mobileapp/android/.gradle/6.1.1/javaCompile/javaCompile.lock differ diff --git a/mobileapp/android/.gradle/6.1.1/javaCompile/taskHistory.bin b/mobileapp/android/.gradle/6.1.1/javaCompile/taskHistory.bin index 3b47c29..043d650 100644 Binary files a/mobileapp/android/.gradle/6.1.1/javaCompile/taskHistory.bin and b/mobileapp/android/.gradle/6.1.1/javaCompile/taskHistory.bin differ diff --git a/mobileapp/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/mobileapp/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 77da409..7e10615 100644 Binary files a/mobileapp/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/mobileapp/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/mobileapp/android/.gradle/buildOutputCleanup/outputFiles.bin b/mobileapp/android/.gradle/buildOutputCleanup/outputFiles.bin index c2cacb7..e2ca55e 100644 Binary files a/mobileapp/android/.gradle/buildOutputCleanup/outputFiles.bin and b/mobileapp/android/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/mobileapp/android/app/release/app-release.apk b/mobileapp/android/app/release/app-release.apk index a88a454..f2c3d80 100644 Binary files a/mobileapp/android/app/release/app-release.apk and b/mobileapp/android/app/release/app-release.apk differ diff --git a/mobileapp/android/app/src/main/java/sde/odense/skolehjem/MainActivity.java b/mobileapp/android/app/src/main/java/sde/odense/skolehjem/MainActivity.java index 6a18256..973e614 100644 --- a/mobileapp/android/app/src/main/java/sde/odense/skolehjem/MainActivity.java +++ b/mobileapp/android/app/src/main/java/sde/odense/skolehjem/MainActivity.java @@ -1,35 +1,101 @@ package sde.odense.skolehjem; +import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; +import android.Manifest; import android.annotation.SuppressLint; +import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.res.Configuration; import android.net.Uri; +import android.os.Build; import android.os.Bundle; -import android.webkit.JavascriptInterface; +import android.os.Environment; +import android.provider.MediaStore; +import android.util.Log; +import android.view.KeyEvent; +import android.view.View; import android.webkit.JsResult; +import android.webkit.ValueCallback; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; +import android.widget.Toast; + +import java.io.File; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; public class MainActivity extends AppCompatActivity { - private WebView webView; private static final String TEL_PREFIX = "tel:"; + private static final String TAG = MainActivity.class.getSimpleName(); + private final static int FCR = 1; + private String mCM; + private ValueCallback mUM; + private ValueCallback mUMA; + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent intent) { + super.onActivityResult(requestCode, resultCode, intent); + + if (Build.VERSION.SDK_INT >= 21) { + Uri[] results = null; + + //Check if response is positive + if (resultCode == Activity.RESULT_OK) { + if (requestCode == FCR) { + + if (null == mUMA) { + return; + } + if (intent == null) { + //Capture Photo if no image available + if (mCM != null) { + results = new Uri[]{Uri.parse(mCM)}; + } + } else { + String dataString = intent.getDataString(); + if (dataString != null) { + results = new Uri[]{Uri.parse(dataString)}; + } + } + } + } + mUMA.onReceiveValue(results); + mUMA = null; + } else { + + if (requestCode == FCR) { + if (null == mUM) return; + Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData(); + mUM.onReceiveValue(result); + mUM = null; + } + } + } + @SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"}) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + if (Build.VERSION.SDK_INT >= 23 && (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)) { + ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA}, 1); + } + webView = findViewById(R.id.webView); - webView.setWebViewClient(new CustomWebViewClient()); - webView.setWebChromeClient(new CustomWebChromeClient(this)); //Settings WebSettings webSettings = webView.getSettings(); @@ -42,10 +108,141 @@ public class MainActivity extends AppCompatActivity { webSettings.setSupportZoom(true); webSettings.setDefaultTextEncodingName("utf-8"); webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); + webSettings.setAllowFileAccess(true); + + if (Build.VERSION.SDK_INT >= 21) { + webSettings.setMixedContentMode(0); + webView.setLayerType(View.LAYER_TYPE_HARDWARE, null); + } else if (Build.VERSION.SDK_INT >= 19) { + webView.setLayerType(View.LAYER_TYPE_HARDWARE, null); + } else if (Build.VERSION.SDK_INT < 19) { + webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); + } + + webView.setWebViewClient(new CustomWebViewClient()); + webView.setWebChromeClient(new WebChromeClient(){ + Context myApp = getApplicationContext(); + + @Override + public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) { + new AlertDialog.Builder(myApp) + .setTitle("Confirm") + .setMessage(message) + .setPositiveButton(android.R.string.ok, + new DialogInterface.OnClickListener() + { + public void onClick(DialogInterface dialog, int which) + { + result.confirm(); + } + }) + .setNegativeButton(android.R.string.cancel, + new DialogInterface.OnClickListener() + { + public void onClick(DialogInterface dialog, int which) + { + result.cancel(); + } + }) + .create() + .show(); + + return true; + } + + //For Android 3.0+ + public void openFileChooser(ValueCallback uploadMsg) { + + mUM = uploadMsg; + Intent i = new Intent(Intent.ACTION_GET_CONTENT); + i.addCategory(Intent.CATEGORY_OPENABLE); + i.setType("*/*"); + MainActivity.this.startActivityForResult(Intent.createChooser(i, "File Chooser"), FCR); + } + + // For Android 3.0+, above method not supported in some android 3+ versions, in such case we use this + public void openFileChooser(ValueCallback uploadMsg, String acceptType) { + + mUM = uploadMsg; + Intent i = new Intent(Intent.ACTION_GET_CONTENT); + i.addCategory(Intent.CATEGORY_OPENABLE); + i.setType("*/*"); + MainActivity.this.startActivityForResult( + Intent.createChooser(i, "File Browser"), + FCR); + } + + //For Android 4.1+ + public void openFileChooser(ValueCallback uploadMsg, String acceptType, String capture) { + mUM = uploadMsg; + Intent i = new Intent(Intent.ACTION_GET_CONTENT); + i.addCategory(Intent.CATEGORY_OPENABLE); + i.setType("*/*"); + MainActivity.this.startActivityForResult(Intent.createChooser(i, "File Chooser"), MainActivity.FCR); + } + + //For Android 5.0+ + public boolean onShowFileChooser( + WebView webView, ValueCallback filePathCallback, + WebChromeClient.FileChooserParams fileChooserParams) { + + if (mUMA != null) { + mUMA.onReceiveValue(null); + } + + mUMA = filePathCallback; + Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + if (takePictureIntent.resolveActivity(MainActivity.this.getPackageManager()) != null) { + + File photoFile = null; + + try { + photoFile = createImageFile(); + takePictureIntent.putExtra("PhotoPath", mCM); + } catch (IOException ex) { + Log.e(TAG, "Image file creation failed", ex); + } + if (photoFile != null) { + mCM = "file:" + photoFile.getAbsolutePath(); + takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); + } else { + takePictureIntent = null; + } + } + + Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT); + contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE); + contentSelectionIntent.setType("*/*"); + Intent[] intentArray; + + if (takePictureIntent != null) { + intentArray = new Intent[]{takePictureIntent}; + } else { + intentArray = new Intent[0]; + } + + Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER); + chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent); + chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser"); + chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray); + startActivityForResult(chooserIntent, FCR); + + return true; + } + }); webView.loadUrl("https://ekapp.sde.dk"); } + // Create an image file + private File createImageFile() throws IOException { + + @SuppressLint("SimpleDateFormat") String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); + String imageFileName = "img_" + timeStamp + "_"; + File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); + return File.createTempFile(imageFileName, ".jpg", storageDir); + } + @Override public void onBackPressed() { if(webView.canGoBack()) @@ -54,8 +251,33 @@ public class MainActivity extends AppCompatActivity { super.onBackPressed(); } - private class CustomWebViewClient extends WebViewClient { + @Override + public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) { + if (event.getAction() == KeyEvent.ACTION_DOWN) { + + switch (keyCode) { + case KeyEvent.KEYCODE_BACK: + + if (webView.canGoBack()) { + webView.goBack(); + } else { + finish(); + } + + return true; + } + } + + return super.onKeyDown(keyCode, event); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + } + + private class CustomWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView wv, String url) { if(url.startsWith(TEL_PREFIX)) { @@ -66,40 +288,9 @@ public class MainActivity extends AppCompatActivity { } return false; } - } - static final class CustomWebChromeClient extends WebChromeClient { - Context myApp; - - CustomWebChromeClient(Context mContext){ - myApp = mContext; - } - - @Override - public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) { - new AlertDialog.Builder(myApp) - .setTitle("Confirm") - .setMessage(message) - .setPositiveButton(android.R.string.ok, - new DialogInterface.OnClickListener() - { - public void onClick(DialogInterface dialog, int which) - { - result.confirm(); - } - }) - .setNegativeButton(android.R.string.cancel, - new DialogInterface.OnClickListener() - { - public void onClick(DialogInterface dialog, int which) - { - result.cancel(); - } - }) - .create() - .show(); - - return true; + public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { + Toast.makeText(getApplicationContext(), "Failed loading app!", Toast.LENGTH_SHORT).show(); } } } \ No newline at end of file diff --git a/mobileapp/android/build/intermediates/lint-cache/maven.google/androidx/appcompat/group-index.xml b/mobileapp/android/build/intermediates/lint-cache/maven.google/androidx/appcompat/group-index.xml index ce9e9d7..f1c1a16 100644 --- a/mobileapp/android/build/intermediates/lint-cache/maven.google/androidx/appcompat/group-index.xml +++ b/mobileapp/android/build/intermediates/lint-cache/maven.google/androidx/appcompat/group-index.xml @@ -1,5 +1,5 @@ - - + + diff --git a/mobileapp/android/build/intermediates/lint-cache/maven.google/androidx/test/espresso/group-index.xml b/mobileapp/android/build/intermediates/lint-cache/maven.google/androidx/test/espresso/group-index.xml index d50f745..666c2f2 100644 --- a/mobileapp/android/build/intermediates/lint-cache/maven.google/androidx/test/espresso/group-index.xml +++ b/mobileapp/android/build/intermediates/lint-cache/maven.google/androidx/test/espresso/group-index.xml @@ -1,10 +1,10 @@ - - - - - - - + + + + + + + diff --git a/mobileapp/android/build/intermediates/lint-cache/maven.google/androidx/test/ext/group-index.xml b/mobileapp/android/build/intermediates/lint-cache/maven.google/androidx/test/ext/group-index.xml index 2048a0d..a434893 100644 --- a/mobileapp/android/build/intermediates/lint-cache/maven.google/androidx/test/ext/group-index.xml +++ b/mobileapp/android/build/intermediates/lint-cache/maven.google/androidx/test/ext/group-index.xml @@ -1,6 +1,6 @@ - - - + + + diff --git a/mobileapp/android/build/intermediates/lint-cache/maven.google/master-index.xml b/mobileapp/android/build/intermediates/lint-cache/maven.google/master-index.xml index 6aa8d5c..326a911 100644 --- a/mobileapp/android/build/intermediates/lint-cache/maven.google/master-index.xml +++ b/mobileapp/android/build/intermediates/lint-cache/maven.google/master-index.xml @@ -42,6 +42,7 @@ +