diff --git a/Movim/build.gradle b/Movim/build.gradle
index dccae43..746a372 100644
--- a/Movim/build.gradle
+++ b/Movim/build.gradle
@@ -1,15 +1,14 @@
apply plugin: 'com.android.application'
-apply plugin: 'com.google.gms.google-services'
android {
- compileSdkVersion 30
+ compileSdkVersion 29
defaultConfig {
applicationId "com.movim.movim"
minSdkVersion 21
- targetSdkVersion 30
- versionCode 15
- versionName "0.19"
+ targetSdkVersion 29
+ versionCode 17
+ versionName "0.19.2"
}
buildTypes {
@@ -21,9 +20,9 @@ android {
}
dependencies {
- implementation 'androidx.legacy:legacy-support-v4:1.0.0'
- implementation 'androidx.appcompat:appcompat:1.0.0'
- implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
- implementation platform('com.google.firebase:firebase-bom:26.3.0')
- implementation 'com.google.firebase:firebase-messaging'
-}
+ //noinspection GradleCompatible
+ implementation 'com.android.support:support-v4:28.0.0'
+ //noinspection GradleCompatible
+ implementation 'com.android.support:appcompat-v7:28.0.0'
+ implementation 'com.android.support.constraint:constraint-layout:2.0.4'
+}
\ No newline at end of file
diff --git a/Movim/src/main/AndroidManifest.xml b/Movim/src/main/AndroidManifest.xml
index 6b6306c..bff4f41 100644
--- a/Movim/src/main/AndroidManifest.xml
+++ b/Movim/src/main/AndroidManifest.xml
@@ -14,37 +14,19 @@
-
-
-
-
-
-
-
-
-
-
+ android:launchMode="singleTask"
+ android:exported="true">
-
-
@@ -52,21 +34,18 @@
android:name=".VisioActivity"
android:configChanges="orientation|screenSize"
android:label="@string/call"
- android:launchMode="standard"
+ android:theme="@style/SplashTheme"
android:taskAffinity=".MainActivity"
- android:theme="@style/SplashTheme" />
+ android:launchMode="standard" />
+ android:theme="@style/SplashTheme"
+ android:exported="true">
-
-
\ No newline at end of file
diff --git a/Movim/src/main/java/com/movim/movim/MainActivity.java b/Movim/src/main/java/com/movim/movim/MainActivity.java
index 89c8bce..f8ac939 100644
--- a/Movim/src/main/java/com/movim/movim/MainActivity.java
+++ b/Movim/src/main/java/com/movim/movim/MainActivity.java
@@ -1,6 +1,11 @@
package com.movim.movim;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import android.Manifest;
@@ -8,26 +13,35 @@
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
-import android.content.pm.PackageManager;
+import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
+import androidx.core.app.NotificationCompat;
+import androidx.core.content.ContextCompat;
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
import android.content.res.Configuration;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Build;
import android.os.Bundle;
-import androidx.core.content.ContextCompat;
import android.text.InputType;
-import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
-import android.view.WindowManager;
import android.webkit.HttpAuthHandler;
import android.webkit.JavascriptInterface;
import android.webkit.PermissionRequest;
@@ -41,22 +55,16 @@
import android.widget.ProgressBar;
import android.widget.Toast;
-import com.google.android.gms.tasks.OnCompleteListener;
-import com.google.android.gms.tasks.Task;
-import com.google.firebase.messaging.FirebaseMessaging;
-
-import static com.google.firebase.messaging.Constants.TAG;
-
@SuppressLint("SetJavaScriptEnabled")
public class MainActivity extends Activity {
+ private final static int FILE_REQUEST_CODE = 1;
+ private final static int CAMERA_REQUEST_CODE = 2;
private WebView webview;
private ProgressBar progressbar;
- private String firebaseToken = "";
+ private HashMap> notifs;
private static MainActivity instance;
private ValueCallback mUploadMessageArray;
- private final static int FILE_REQUEST_CODE = 1;
- private final static int CAMERA_REQUEST_CODE = 2;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -77,18 +85,7 @@ protected void onCreate(Bundle savedInstanceState) {
webview.getSettings().setAppCacheEnabled(true);
webview.getSettings().setMediaPlaybackRequiresUserGesture(false);
- FirebaseMessaging.getInstance().getToken()
- .addOnCompleteListener(new OnCompleteListener() {
- @Override
- public void onComplete(@NonNull Task task) {
- if (!task.isSuccessful()) {
- Log.w(TAG, "Fetching FCM registration token failed", task.getException());
- return;
- }
- firebaseToken = task.getResult();
- }
- });
-
+
if (Build.VERSION.SDK_INT >= 21) {
webview.getSettings().setAllowUniversalAccessFromFileURLs(true);
getWindow().setNavigationBarColor(Color.parseColor("#000000"));
@@ -128,9 +125,6 @@ public void onProgressChanged(WebView view, int progress) {
if (progress == 100) {
progressbar.setVisibility(ProgressBar.GONE);
- if (!firebaseToken.isEmpty()) {
- webview.loadUrl("javascript:Presence.setFirebaseToken('" + firebaseToken + "')");
- }
}
}
@@ -182,12 +176,12 @@ public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslE
}
public void onReceivedHttpAuthRequest(final WebView view, final HttpAuthHandler handler, final String host,
- final String realm) {
+ final String realm) {
final String[] httpAuth = new String[2];
final String[] viewAuth = view.getHttpAuthUsernamePassword(host, realm);
final EditText usernameInput = new EditText(MainActivity.getInstance());
final EditText passwordInput = new EditText(MainActivity.getInstance());
-
+
httpAuth[0] = viewAuth != null ? viewAuth[0] : new String();
httpAuth[1] = viewAuth != null ? viewAuth[1] : new String();
@@ -225,13 +219,8 @@ public void onClick(DialogInterface dialog, int whichButton) {
instance = this;
}
- @Override
- protected void onStop () {
- super.onStop() ;
- startService( new Intent( this, NotificationService. class )) ;
- }
- private boolean checkAndRequestPermissions() {
+ private void checkAndRequestPermissions() {
int permissionCamera = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
int permissionRecordAudio = ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO);
@@ -244,10 +233,8 @@ private boolean checkAndRequestPermissions() {
}
if (!listPermissionsNeeded.isEmpty()) {
ActivityCompat.requestPermissions(this, listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]), CAMERA_REQUEST_CODE);
- return false;
}
- return true;
}
@Override
@@ -266,7 +253,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
@Override
public void onNewIntent(Intent intent) {
if (intent.getAction() != null) {
- //this.notifs.remove(intent.getAction());
+ this.notifs.remove(intent.getAction());
webview.loadUrl(intent.getAction());
}
}
@@ -275,44 +262,24 @@ public void onNewIntent(Intent intent) {
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
- };
+ }
public static MainActivity getInstance() {
return instance;
}
- @Override
- protected void onResume() {
- super.onResume();
- if (mUploadMessageArray == null)
- return;
-
- mUploadMessageArray.onReceiveValue(new Uri[]{});
- mUploadMessageArray = null;
- }
-
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
- if (requestCode != FILE_REQUEST_CODE || mUploadMessageArray == null) {
+ if (requestCode != FILE_REQUEST_CODE || resultCode != Activity.RESULT_OK || data.getData() == null)
return;
- }
- Uri[] results = null;
- if (resultCode == Activity.RESULT_OK) {
- String dataString = data.getDataString();
- if (dataString != null) {
- results = new Uri[]{Uri.parse(dataString)};
- }
- }
- mUploadMessageArray.onReceiveValue(results);
- mUploadMessageArray = null;
- }
+ if (mUploadMessageArray == null)
+ return;
- @JavascriptInterface
- public void clearFirebaseToken() {
- firebaseToken = "";
+ mUploadMessageArray.onReceiveValue(new Uri[] { data.getData() });
+ mUploadMessageArray = null;
}
@JavascriptInterface
@@ -330,24 +297,107 @@ public void showToast(String toast) {
@JavascriptInterface
public void clearNotifications(String action) {
- Intent notificationService = new Intent(this, NotificationService.class);
- notificationService.setAction("clear");
- notificationService.putExtra("action", action);
- startService(notificationService);
+ NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+ notificationManager.cancel(action, 0);
+
+ if (this.notifs.get(action) != null) {
+ this.notifs.remove(action);
+ }
+
+ this.updateNotifications();
}
@JavascriptInterface
public void showNotification(String title, String body, String picture, String action) {
- Intent notificationService = new Intent(this, NotificationService.class);
- notificationService.setAction("notify");
- notificationService.putExtra("title", title);
- notificationService.putExtra("body", body);
- notificationService.putExtra("picture", picture);
- notificationService.putExtra("action", action);
- startService(notificationService);
+ Bitmap pictureBitmap = getBitmapFromURL(picture);
+
+ Intent i = new Intent(this, MainActivity.class);
+ if (action != null) {
+ i.setAction(action);
+ i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ }
+ PendingIntent pi = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
+
+ // The deleteIntent declaration
+ Intent deleteIntent = new Intent(action);
+ PendingIntent pendingDeleteIntent = PendingIntent.getBroadcast(this, 0, deleteIntent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+ registerReceiver(receiver, new IntentFilter(action));
+
+ // Integer counter;
+ List messages;
+
+ // There is already pending notifications
+ if (this.notifs.get(action) != null) {
+ messages = this.notifs.get(action);
+ } else {
+ messages = new ArrayList();
+ }
+
+ messages.add(body);
+
+ if (messages.size() > 5) {
+ messages.remove(0);
+ }
+
+ this.notifs.put(action, messages);
+
+ // We create the inbox
+ NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
+ for (int j = 0; j < messages.size(); j++) {
+ style.addLine(messages.get(j));
+ }
+
+ style.setBigContentTitle(title);
+
+ NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+
+ String channelId = "channel-movim";
+ String channelName = "Movim";
+ String groupId = "movim";
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ NotificationChannel mChannel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT);
+ notificationManager.createNotificationChannel(mChannel);
+ }
+
+ Notification notification = new NotificationCompat.Builder(this, channelId)
+ .setSmallIcon(R.drawable.ic_stat_name)
+ .setLargeIcon(pictureBitmap)
+ .setContentTitle(title)
+ .setContentText(body)
+ .setContentIntent(pi)
+ .setDeleteIntent(pendingDeleteIntent).setAutoCancel(true).setColor(Color.parseColor("#3F51B5"))
+ .setLights(Color.parseColor("#3F51B5"), 1000, 5000)
+ .setNumber(messages.size())
+ .setStyle(style)
+ .setGroup(groupId)
+ .build();
+ notificationManager.notify(action, 0, notification);
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ Notification summaryNotification = new NotificationCompat.Builder(this, channelId)
+ .setSmallIcon(R.drawable.ic_stat_name)
+ .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_vectorial))
+ .setGroup(groupId)
+ .setGroupSummary(true)
+ .setAutoCancel(true)
+ .build();
+ notificationManager.notify("summary", 0, summaryNotification);
+ }
}
- /*private final BroadcastReceiver receiver = new BroadcastReceiver() {
+ protected void updateNotifications() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+ int counter = notificationManager.getActiveNotifications().length;
+
+ if (counter <= 1) {
+ notificationManager.cancel("summary", 0);
+ }
+ }
+ }
+
+ private final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() != null) {
@@ -355,7 +405,22 @@ public void onReceive(Context context, Intent intent) {
}
unregisterReceiver(this);
}
- };*/
+ };
+
+ public static Bitmap getBitmapFromURL(String src) {
+ try {
+ URL url = new URL(src);
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setDoInput(true);
+ connection.connect();
+ InputStream input = connection.getInputStream();
+ Bitmap myBitmap = BitmapFactory.decodeStream(input);
+ return myBitmap;
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU) {
@@ -368,4 +433,14 @@ public boolean onKeyUp(int keyCode, KeyEvent event) {
}
return super.onKeyUp(keyCode, event);
}
+
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
+ webview.goBack();
+ return true;
+ }
+ return super.onKeyDown(keyCode, event);
+ }
+
}
\ No newline at end of file
diff --git a/Movim/src/main/java/com/movim/movim/NotificationService.java b/Movim/src/main/java/com/movim/movim/NotificationService.java
deleted file mode 100644
index 3254ac8..0000000
--- a/Movim/src/main/java/com/movim/movim/NotificationService.java
+++ /dev/null
@@ -1,216 +0,0 @@
-package com.movim.movim;
-
-import android.app.Notification;
-import android.app.NotificationChannel;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Color;
-
-import androidx.core.app.NotificationCompat;
-
-import com.google.firebase.messaging.CommonNotificationBuilder;
-import com.google.firebase.messaging.FirebaseMessagingService;
-import com.google.firebase.messaging.RemoteMessage;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-public class NotificationService extends FirebaseMessagingService {
- private HashMap> notifs;
-
- @Override
- protected Intent getStartCommandIntent(Intent intent) {
- handleIntent(intent);
- return super.getStartCommandIntent(intent);
- }
-
- @Override
- public void handleIntent(Intent intent) {
- if (intent.getAction() != null) {
- if (intent.getAction().equals("update")) {
- updateNotification();
- }
-
- if (intent.getAction().equals("clear")) {
- clearNotifications(intent.getStringExtra("action"));
- }
-
- // Coming from within the application
- if (intent.getAction().equals("notify")) {
- showNotification(
- intent.getStringExtra("title"),
- intent.getStringExtra("body"),
- intent.getStringExtra("image"),
- intent.getStringExtra("action")
- );
- }
-
- super.handleIntent(intent);
- }
- }
-
- @Override
- public void onCreate() {
- this.notifs = new HashMap>();
- super.onCreate();
- }
-
- @Override
- public void onMessageReceived(RemoteMessage remoteMessage) {
- if (remoteMessage.getData().size() > 0) {
- if (remoteMessage.getData().get("clear") != null) {
- clearNotifications(
- remoteMessage.getData().get("action")
- );
- } else {
- showNotification(
- remoteMessage.getData().get("title"),
- remoteMessage.getData().get("body"),
- remoteMessage.getData().get("image"),
- remoteMessage.getData().get("action")
- );
- }
- }
-
- //super.onMessageReceived(remoteMessage);
- }
-
- private final BroadcastReceiver receiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- if (intent.getAction() != null) {
- clearNotifications(intent.getAction());
- }
- unregisterReceiver(this);
- }
- };
-
- public void showNotification(String title, String body, String picture, String action) {
- Bitmap pictureBitmap = getBitmapFromURL(picture);
-
- Intent i = new Intent(this, MainActivity.class);
- if (action != null) {
- i.setAction(action);
- i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
- }
- PendingIntent pi = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
-
- // The deleteIntent declaration
- Intent deleteIntent = new Intent(action);
- PendingIntent pendingDeleteIntent = PendingIntent.getBroadcast(this, 0, deleteIntent,
- PendingIntent.FLAG_UPDATE_CURRENT);
- registerReceiver(receiver, new IntentFilter(action));
-
- // Integer counter;
- List messages = null;
-
- // There is already pending notifications
- if (this.notifs.get(action) != null) {
- messages = this.notifs.get(action);
- } else {
- messages = new ArrayList();
- }
-
- messages.add(body);
-
- if (messages.size() > 3) {
- messages.remove(0);
- }
-
- this.notifs.put(action, messages);
-
- // We create the inbox
- NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
- for (int j = 0; j < messages.size(); j++) {
- style.addLine(messages.get(j));
- }
-
- style.setBigContentTitle(title);
-
- NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
-
- String channelId = "channel-movim";
- String channelName = "Movim";
- String groupId = "movim";
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
- NotificationChannel mChannel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT);
- notificationManager.createNotificationChannel(mChannel);
- }
-
- NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId)
- .setSmallIcon(R.drawable.ic_stat_name)
- .setLargeIcon(pictureBitmap)
- .setContentTitle(title)
- .setContentText(body)
- .setContentIntent(pi)
- .setDeleteIntent(pendingDeleteIntent).setAutoCancel(true).setColor(Color.parseColor("#3F51B5"))
- .setLights(Color.parseColor("#3F51B5"), 1000, 5000)
- .setNumber(messages.size())
- .setStyle(style)
- .setGroup(groupId);
-
- Notification notification = notificationBuilder.setVibrate(new long[]{0L}).build();
- notificationManager.notify(action, 0, notification);
-
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
- Notification summaryNotification = new NotificationCompat.Builder(this, channelId)
- .setSmallIcon(R.drawable.ic_stat_name)
- .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_vectorial))
- .setGroup(groupId)
- .setGroupSummary(true)
- .setAutoCancel(true)
- .setVibrate(new long[]{0L})
- .build();
- notificationManager.notify("summary", 0, summaryNotification);
- }
- }
-
- public void clearNotifications(String action) {
- NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
- notificationManager.cancel(action, 0);
-
- if (this.notifs.get(action) != null) {
- this.notifs.remove(action);
- }
-
- this.updateNotification();
- }
-
- public void updateNotification() {
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
- NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
-
- int counter = notificationManager.getActiveNotifications().length;
-
- if (counter <= 1) {
- notificationManager.cancel("summary", 0);
- }
- }
- }
-
- public static Bitmap getBitmapFromURL(String src) {
- try {
- URL url = new URL(src);
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
- connection.setDoInput(true);
- connection.connect();
- InputStream input = connection.getInputStream();
- Bitmap myBitmap = BitmapFactory.decodeStream(input);
- return myBitmap;
- } catch (IOException e) {
- e.printStackTrace();
- return null;
- }
- }
-}
diff --git a/Movim/src/main/java/com/movim/movim/VisioActivity.java b/Movim/src/main/java/com/movim/movim/VisioActivity.java
index 3bae095..72802bc 100644
--- a/Movim/src/main/java/com/movim/movim/VisioActivity.java
+++ b/Movim/src/main/java/com/movim/movim/VisioActivity.java
@@ -89,9 +89,9 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
.build();
notificationManager.notify("call", 0, notification);
- Intent notificationService = new Intent(this, NotificationService.class);
- notificationService.setAction("update");
- startService(notificationService);
+ if (MainActivity.getInstance() != null) {
+ MainActivity.getInstance().updateNotifications();
+ }
}
protected void onDestroy() {
@@ -100,10 +100,7 @@ protected void onDestroy() {
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
notificationManager.cancel("call", 0);
-
- Intent notificationService = new Intent(this, NotificationService.class);
- notificationService.setAction("update");
- startService(notificationService);
+ MainActivity.getInstance().updateNotifications();
}
private void endCall() {
diff --git a/build.gradle b/build.gradle
index 3c55f66..f535d68 100644
--- a/build.gradle
+++ b/build.gradle
@@ -2,17 +2,24 @@
buildscript {
repositories {
jcenter()
+ maven {
+ url 'https://maven.google.com/'
+ name 'Google'
+ }
google()
}
dependencies {
- classpath 'com.google.gms:google-services:4.3.4'
- classpath 'com.android.tools.build:gradle:4.2.0'
+ classpath 'com.android.tools.build:gradle:4.2.2'
}
}
allprojects {
repositories {
jcenter()
+ maven {
+ url 'https://maven.google.com/'
+ name 'Google'
+ }
google()
}
-}
+}
\ No newline at end of file