From d26ebea0de1806f21d53d3b7d93a0352de8eb07b Mon Sep 17 00:00:00 2001 From: Matteo Carnelos Date: Wed, 6 Nov 2019 15:25:54 +0100 Subject: [PATCH 01/38] Solved warning --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6bc5512..000f84c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,9 +24,9 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'com.google.android.material:material:1.0.0' - implementation 'androidx.preference:preference:1.1.0-alpha05' + implementation 'androidx.preference:preference:1.1.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' - compile project(path: ':smslibrary') + implementation project(path: ':smslibrary') } From cae65b2fed6a814751e5dc101e317c0e1589a069 Mon Sep 17 00:00:00 2001 From: Edoardo Raimondi <56430825+EdoardoRaimondi@users.noreply.github.com> Date: Fri, 8 Nov 2019 16:34:42 +0100 Subject: [PATCH 02/38] Layout and demo skeleton added (missing dictionary calls) --- .idea/misc.xml | 3 + .../com/eis0/library_demo/SMSCore_Tests.java | 0 .../eis0/library_demo/SMSHandler_Tests.java | 0 app/src/main/AndroidManifest.xml | 11 +- .../com/eis0/library_demo/DemoActivity.java | 257 ------------------ .../com/eis0/library_demo/NetworkDemo.java | 38 +++ .../eis0/library_demo/SettingsActivity.java | 31 --- app/src/main/res/layout/activity_demo.xml | 11 - .../main/res/layout/activity_network_demo.xml | 57 ++++ app/src/main/res/layout/content_demo.xml | 59 ---- app/src/main/res/layout/settings_activity.xml | 9 - app/src/main/res/values/strings.xml | 2 +- 12 files changed, 101 insertions(+), 377 deletions(-) delete mode 100644 app/src/androidTest/java/com/eis0/library_demo/SMSCore_Tests.java delete mode 100644 app/src/androidTest/java/com/eis0/library_demo/SMSHandler_Tests.java delete mode 100644 app/src/main/java/com/eis0/library_demo/DemoActivity.java create mode 100644 app/src/main/java/com/eis0/library_demo/NetworkDemo.java delete mode 100644 app/src/main/java/com/eis0/library_demo/SettingsActivity.java delete mode 100644 app/src/main/res/layout/activity_demo.xml create mode 100644 app/src/main/res/layout/activity_network_demo.xml delete mode 100644 app/src/main/res/layout/content_demo.xml delete mode 100644 app/src/main/res/layout/settings_activity.xml diff --git a/.idea/misc.xml b/.idea/misc.xml index 37a7509..b6746da 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,8 @@ + + + diff --git a/app/src/androidTest/java/com/eis0/library_demo/SMSCore_Tests.java b/app/src/androidTest/java/com/eis0/library_demo/SMSCore_Tests.java deleted file mode 100644 index e69de29..0000000 diff --git a/app/src/androidTest/java/com/eis0/library_demo/SMSHandler_Tests.java b/app/src/androidTest/java/com/eis0/library_demo/SMSHandler_Tests.java deleted file mode 100644 index e69de29..0000000 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c98497b..8463df8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,16 +14,9 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> + - - - diff --git a/app/src/main/java/com/eis0/library_demo/DemoActivity.java b/app/src/main/java/com/eis0/library_demo/DemoActivity.java deleted file mode 100644 index 1d533ec..0000000 --- a/app/src/main/java/com/eis0/library_demo/DemoActivity.java +++ /dev/null @@ -1,257 +0,0 @@ -package com.eis0.library_demo; - -import android.Manifest; -import android.app.AlertDialog; -import android.app.NotificationChannel; -import android.app.NotificationManager; -import android.app.PendingIntent; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.SharedPreferences; -import android.os.Build; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.provider.Settings; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.EditText; -import android.widget.Toast; - -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.app.ActivityCompat; -import androidx.core.app.NotificationCompat; -import androidx.core.app.NotificationManagerCompat; -import androidx.lifecycle.Lifecycle; - -import com.eis0.smslibrary.SMSMessage; -import com.eis0.smslibrary.SMSPeer; -import com.eis0.smslibrary.ReceivedMessageListener; -import com.eis0.smslibrary.SMSManager; - -import java.util.ArrayList; -import java.util.Set; - -public class DemoActivity extends AppCompatActivity implements ReceivedMessageListener { - private EditText destText; - private SharedPreferences sharedPreferences; - private boolean deliveryReport = false; - - private static NotificationManager notificationManager; - private static final String CHANNEL_ID = "eis0_notification_channel"; - private static int notificationID = 0; - private static ArrayList pendingDialogs = new ArrayList<>(); - private static final String[] PERMISSIONS = { - Manifest.permission.SEND_SMS, - Manifest.permission.RECEIVE_SMS, - Manifest.permission.READ_PHONE_STATE, - Manifest.permission.READ_SMS - }; - - /** - * Demo start function. - */ - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_demo); - - // Get app settings - sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); - - // Asks the user for permission if not already granted - if(!isNotificationListenerEnabled(getApplicationContext())) - openNotificationListenSettings(); - - destText = findViewById(R.id.recipientNumber); - - if (Build.VERSION.SDK_INT >= 23) { - notificationManager = getSystemService(NotificationManager.class); - } - - requestPermissions(); - SMSManager.getInstance(this).addReceiveListener(this); - - createNotificationChannel(); - for(final String[] pendingDialog : pendingDialogs) { - new AlertDialog.Builder(this) - .setTitle(pendingDialog[0] + getString(R.string.says_hi)) - .setPositiveButton(getString(R.string.say_hi_back), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - sendHello(new SMSPeer(pendingDialog[0])); - } - }) - .setNegativeButton(getString(R.string.ok), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - notificationManager.cancel(Integer.parseInt(pendingDialog[1])); - } - }) - .setIcon(R.drawable.ic_hello_received) - .show(); - } - pendingDialogs.clear(); - } - - /** - * Creates a notification channel (only for API >= 26) - */ - private void createNotificationChannel() { - if (Build.VERSION.SDK_INT >= 26) { - CharSequence name = getString(R.string.channel_name); - String description = getString(R.string.channel_description); - int importance = NotificationManager.IMPORTANCE_HIGH; - NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance); - channel.setDescription(description); - notificationManager.createNotificationChannel(channel); - } - } - - /** - * Every time this activity appears on the foreground - */ - @Override - protected void onResume() { - super.onResume(); - deliveryReport = sharedPreferences.getBoolean("deliveryReport", false); - } - - /** - * Unregister BroadcastReceivers used for confirmation of sending and delivery of SMS - */ - @Override - protected void onStop() { - super.onStop(); - } - - /** - * Called when the option menu is created - * @param menu Option menu created - * @return Returns true when the option menu is created - */ - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.menu_main, menu); - return true; - } - - /** - * Called when an item is selected in the option menu - * @param item Item that gets selected - * @return Returns the state of the option menu - */ - @Override - public boolean onOptionsItemSelected(MenuItem item) { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - int id = item.getItemId(); - - //noinspection SimplifiableIfStatement - if (id == R.id.action_settings) { - Intent intent = new Intent(this, SettingsActivity.class); - startActivity(intent); - return true; - } - - return super.onOptionsItemSelected(item); - } - - /** - * Sends a message to the target received in input from the demo. - * @param view View that sends the onClick event. - */ - public void sendButtonOnClick(View view) { - SMSPeer destination = new SMSPeer(destText.getText().toString()); - if(destination.isEmpty()) { - Toast.makeText(this, getString(R.string.to_field_cannot_be_empty), Toast.LENGTH_SHORT).show(); - return; - } - //TODO: check if destination is valid - sendHello(destination); - } - - /** - * Sends a message (SMS) to the specified target. - * @param destination Target who will receive the message with the APP_ID. - */ - private void sendHello(SMSPeer destination) { - requestPermissions(); - SMSManager.getInstance(this).sendMessage(new SMSMessage(destination, "")); - } - - /** - * Requests permissions for the library/app to work if not granted - */ - private void requestPermissions(){ - ActivityCompat.requestPermissions(this, PERMISSIONS, 1); - } - - /** - * Creates and shows an Alert when a message is received. If the app is running in background shows - * a notification. - * @param message The message received. - */ - public void onMessageReceived(SMSMessage message) { - final SMSPeer from = message.getPeer(); - final int notID = notificationID++; - if(getLifecycle().getCurrentState() != Lifecycle.State.RESUMED) { - Intent intent = new Intent(this, DemoActivity.class); - intent.setAction(Intent.ACTION_MAIN); - intent.addCategory(Intent.CATEGORY_LAUNCHER); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); - NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID) - .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) - .setPriority(NotificationCompat.PRIORITY_HIGH) - .setSmallIcon(R.drawable.ic_hello_received) - .setContentTitle(from + getString(R.string.says_hi)) - .setContentText(getString(R.string.open_app)) - .setContentIntent(pendingIntent) - .setAutoCancel(true); - notificationManager.notify(notID, builder.build()); - } - - if(getLifecycle().getCurrentState() == Lifecycle.State.DESTROYED) { - String[] pendingDialog = {from.getAddress(), notID + ""}; - pendingDialogs.add(pendingDialog); - } - else { - new AlertDialog.Builder(this) - .setTitle(from + getString(R.string.says_hi)) - .setPositiveButton(getString(R.string.say_hi_back), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - sendHello(from); - } - }) - .setNegativeButton(getString(R.string.ok), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - notificationManager.cancel(notID); - } - }) - .setIcon(R.drawable.ic_hello_received) - .show(); - } - } - - /** - * Checks if the notification listener is enabled. - * @param context Context where the notification listener should be active. - * @return Returns if the notification listener is enabled. - */ - private boolean isNotificationListenerEnabled(Context context) { - Set packageNames = NotificationManagerCompat.getEnabledListenerPackages(this); - return packageNames.contains(context.getPackageName()); - } - - /** - * Opens the notification settings menu for the user to enable notifications. - */ - private void openNotificationListenSettings() { - Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS); - startActivity(intent); - } -} diff --git a/app/src/main/java/com/eis0/library_demo/NetworkDemo.java b/app/src/main/java/com/eis0/library_demo/NetworkDemo.java new file mode 100644 index 0000000..5f9881a --- /dev/null +++ b/app/src/main/java/com/eis0/library_demo/NetworkDemo.java @@ -0,0 +1,38 @@ +package com.eis0.library_demo; + +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Bundle; +import android.view.View; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ListView; + +import com.eis0.smslibrary.Peer; + +import java.util.ArrayList; + +public class NetworkDemo extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_network_demo); + Button btn = findViewById(R.id.button); + EditText t1 = findViewById(R.id.editText); + ListView AddressesList = findViewById(R.id.ListView); + //list containing user's number inside the network + final ArrayList UserList = new ArrayList(); + //adapter array that will provide AddressesList's information + final ArrayAdapter adapter = new ArrayAdapter ( this,android.R.layout.simple_list_item_1, UserList ); + AddressesList.setAdapter(adapter); //insert information to AddressesList + btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View arg0) { + //TODO dictionary + } + }); + + } +} diff --git a/app/src/main/java/com/eis0/library_demo/SettingsActivity.java b/app/src/main/java/com/eis0/library_demo/SettingsActivity.java deleted file mode 100644 index 01678b0..0000000 --- a/app/src/main/java/com/eis0/library_demo/SettingsActivity.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.eis0.library_demo; - -import android.os.Bundle; - -import androidx.appcompat.app.ActionBar; -import androidx.appcompat.app.AppCompatActivity; -import androidx.preference.PreferenceFragmentCompat; - -public class SettingsActivity extends AppCompatActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.settings_activity); - getSupportFragmentManager() - .beginTransaction() - .replace(R.id.settings, new SettingsFragment()) - .commit(); - ActionBar actionBar = getSupportActionBar(); - if (actionBar != null) { - actionBar.setDisplayHomeAsUpEnabled(true); - } - } - - public static class SettingsFragment extends PreferenceFragmentCompat { - @Override - public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { - setPreferencesFromResource(R.xml.root_preferences, rootKey); - } - } -} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_demo.xml b/app/src/main/res/layout/activity_demo.xml deleted file mode 100644 index 5136e07..0000000 --- a/app/src/main/res/layout/activity_demo.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_network_demo.xml b/app/src/main/res/layout/activity_network_demo.xml new file mode 100644 index 0000000..51ff519 --- /dev/null +++ b/app/src/main/res/layout/activity_network_demo.xml @@ -0,0 +1,57 @@ + + + +