diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 2b42a80..5ac4784 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index 30aa626..0000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index f3d13dd..e8ee3d9 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,28 +1,36 @@ - - - diff --git a/app/build.gradle b/app/build.gradle index 0466881..22d8dc3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,15 +1,15 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 23 - buildToolsVersion '25.0.2' + compileSdkVersion 28 defaultConfig { applicationId "sed.inf.u_szeged.hu.androidiotsimulator" minSdkVersion 19 - targetSdkVersion 23 + targetSdkVersion 28 versionCode 13 - versionName "1.3" + versionName "1.4" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { @@ -20,10 +20,10 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - testCompile 'junit:junit:4.12' - compile 'com.android.support:appcompat-v7:23.1.1' - compile 'com.android.support:design:23.1.1' - compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2' - compile 'com.google.code.gson:gson:2.7' + implementation fileTree(dir: 'libs', include: ['*.jar']) + testImplementation 'junit:junit:4.12' + implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'com.android.support:design:28.0.0' + implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.1' + implementation 'com.google.code.gson:gson:2.8.2' } diff --git a/app/src/main/java/sed/inf/u_szeged/hu/androidiotsimulator/activity/cloud/CloudActivity.java b/app/src/main/java/sed/inf/u_szeged/hu/androidiotsimulator/activity/cloud/CloudActivity.java index 980cc20..af65a42 100644 --- a/app/src/main/java/sed/inf/u_szeged/hu/androidiotsimulator/activity/cloud/CloudActivity.java +++ b/app/src/main/java/sed/inf/u_szeged/hu/androidiotsimulator/activity/cloud/CloudActivity.java @@ -51,13 +51,13 @@ protected void onResume() { } private void initializeButtons() { - ((FloatingActionButton) findViewById(R.id.new_cloud_fab)).setOnClickListener(new View.OnClickListener() { + findViewById(R.id.new_cloud_fab).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(CloudActivity.this); builder.setTitle("Select a Cloud Type"); - final String cloudTypes[] = {"Bluemix Quickstart demo", "Bluemix regular"}; + final String[] cloudTypes = {"Bluemix Quickstart demo", "Bluemix regular"}; builder.setItems(cloudTypes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { @@ -90,7 +90,7 @@ public void onClick(DialogInterface dialog, int which) { } }); - ((Button) findViewById(R.id.edit_btn)).setOnClickListener(new View.OnClickListener() { + findViewById(R.id.edit_btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(CloudActivity.this, CloudSettingsActivity.class); @@ -138,10 +138,10 @@ public void onClick(View v) { } }); - ((Button) findViewById(R.id.delete_btn)).setOnClickListener(new View.OnClickListener() { + findViewById(R.id.delete_btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - Spinner spinner = (Spinner) findViewById(R.id.cloud_providers_spinner); + Spinner spinner = findViewById(R.id.cloud_providers_spinner); String currentlySelected = MobIoTApplication.loadData(CloudSettingsActivity.KEY_NAME); ArrayList providers = createProvidersList(); @@ -205,7 +205,7 @@ private void loadSettingsFromPreferences() { private void saveActualCloud() { - Spinner cloudSpinner = (Spinner) findViewById(R.id.cloud_providers_spinner); + Spinner cloudSpinner = findViewById(R.id.cloud_providers_spinner); int pos = cloudSpinner.getSelectedItemPosition(); CloudSettingsWrapper cloudSettingsWrapper = cloudSettingsWrappers.get(pos); @@ -250,7 +250,7 @@ private void initCloudProvidersSpinner(String overrideSelected) { ArrayList providers = createProvidersList(); - Spinner spinner = (Spinner) findViewById(R.id.cloud_providers_spinner); + Spinner spinner = findViewById(R.id.cloud_providers_spinner); // Create an ArrayAdapter using the string array and a default spinner layout adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, providers); // Specify the layout to use when the list of choices appears @@ -350,7 +350,7 @@ private void setConnectionTypeSpinner(String connectionType) { if (connectionType == null) { connectionType = ""; } - Spinner connectionTypeSpinner = ((Spinner) findViewById(R.id.connection_type_spinner)); + Spinner connectionTypeSpinner = findViewById(R.id.connection_type_spinner); connectionTypeSpinner.setEnabled(false); int count = connectionTypeSpinner.getCount(); for (int i = 0; i < count; i++) { @@ -364,7 +364,7 @@ private void setConnectionTypeSpinner(String connectionType) { private void initConnectionTypeSpinner() { - Spinner spinner = (Spinner) findViewById(R.id.connection_type_spinner); + Spinner spinner = findViewById(R.id.connection_type_spinner); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.connection_types, android.R.layout.simple_spinner_item); diff --git a/app/src/main/java/sed/inf/u_szeged/hu/androidiotsimulator/activity/device/DeviceSettingsActivity.java b/app/src/main/java/sed/inf/u_szeged/hu/androidiotsimulator/activity/device/DeviceSettingsActivity.java index d9079eb..d4ebc26 100644 --- a/app/src/main/java/sed/inf/u_szeged/hu/androidiotsimulator/activity/device/DeviceSettingsActivity.java +++ b/app/src/main/java/sed/inf/u_szeged/hu/androidiotsimulator/activity/device/DeviceSettingsActivity.java @@ -94,18 +94,12 @@ public void handleMessage(Message msg) { private static boolean isExternalStorageReadOnly() { String extStorageState = Environment.getExternalStorageState(); - if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(extStorageState)) { - return true; - } - return false; + return Environment.MEDIA_MOUNTED_READ_ONLY.equals(extStorageState); } private static boolean isExternalStorageAvailable() { String extStorageState = Environment.getExternalStorageState(); - if (Environment.MEDIA_MOUNTED.equals(extStorageState)) { - return true; - } - return false; + return Environment.MEDIA_MOUNTED.equals(extStorageState); } private void deleteParamter(int position) { @@ -155,7 +149,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_device_settings); - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -178,10 +172,10 @@ public void onClick(View view) { res = getResources(); - listView = (ExpandedListView) findViewById(R.id.list); + listView = findViewById(R.id.list); SensorDataWrapper sdw; - aSwitch = (Switch) findViewById(R.id.sw_random); + aSwitch = findViewById(R.id.sw_random); aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton cb, boolean on) { @@ -249,7 +243,7 @@ public void onCheckedChanged(CompoundButton cb, boolean on) { // }); - ((Button) findViewById(R.id.add_btn)).setOnClickListener(new View.OnClickListener() { + findViewById(R.id.add_btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String paramName = res.getString(R.string.new_paramter_name); @@ -269,7 +263,7 @@ public void onClick(View v) { // } // }); - ((Button) findViewById(R.id.trace_import_btn)).setOnClickListener(new View.OnClickListener() { + findViewById(R.id.trace_import_btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showFileChooser(); @@ -282,9 +276,7 @@ public void onClick(View v) { // } - listView.setOnTouchListener(new View.OnTouchListener() - - { + listView.setOnTouchListener(new View.OnTouchListener() { // Setting on Touch Listener for handling the touch inside ScrollView @Override public boolean onTouch(View v, MotionEvent event) { @@ -357,7 +349,7 @@ private ArrayList loadOrganizationIds() { } private void initOrgIdSpinner(String defaultOrgId) { - Spinner spinner = (Spinner) findViewById(R.id.orgid_spinner); + Spinner spinner = findViewById(R.id.orgid_spinner); ArrayList organizationIds = loadOrganizationIds(); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter spinnerAdapter = new ArrayAdapter<>(this, @@ -384,7 +376,7 @@ public void onNothingSelected(AdapterView parent) { } private void initTypeSpinner(int selectedPos) { - Spinner spinner = (Spinner) findViewById(R.id.type_spinner); + Spinner spinner = findViewById(R.id.type_spinner); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter spinnerAdapter = ArrayAdapter.createFromResource(this, R.array.device_types, android.R.layout.simple_spinner_item); @@ -399,7 +391,7 @@ private void initTypeSpinner(int selectedPos) { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { - EditText freqET = (EditText) findViewById(R.id.freq_value_et); + EditText freqET = findViewById(R.id.freq_value_et); switch (position) { case 0: @@ -549,12 +541,10 @@ private void setData(Bundle bundle) { } private void initTypeIdSpinner(String type_id) { - Spinner spinner = (Spinner) findViewById(R.id.typeid_spinner); + Spinner spinner = findViewById(R.id.typeid_spinner); ArrayList typeIds = deviceTypeIds; - if (typeIds.contains("Create new type...")) { - typeIds.remove("Create new type..."); - } + typeIds.remove("Create new type..."); typeIds.add("Create new type..."); final int positionOfLast = typeIds.size() - 1; @@ -593,7 +583,7 @@ private void showInputDialog() { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(DeviceSettingsActivity.this); alertDialogBuilder.setView(promptView); - final EditText editText = (EditText) promptView.findViewById(R.id._dialog_input_et); + final EditText editText = promptView.findViewById(R.id._dialog_input_et); // setup a dialog window alertDialogBuilder.setCancelable(false) .setPositiveButton("OK", new DialogInterface.OnClickListener() { @@ -639,17 +629,23 @@ private class TypeSpinnerFillingTask extends AsyncTask { @Override protected Void doInBackground(String... strings) { - - jsonTypeIds = restTools.getDeviceTypes(); - + try { + jsonTypeIds = restTools.getDeviceTypes(); + } catch (Exception e) { + e.printStackTrace(); + } return null; } @Override protected void onPostExecute(Void aVoid) { deviceTypeIds = new ArrayList<>(); - for (Result result : jsonTypeIds) { - deviceTypeIds.add(result.getId()); + if (jsonTypeIds != null) { + for (Result result : jsonTypeIds) { + deviceTypeIds.add(result.getId()); + } + } else { + deviceTypeIds.add("MobIoTSimType"); } initTypeIdSpinner(defaultTypeid); } diff --git a/app/src/main/java/sed/inf/u_szeged/hu/androidiotsimulator/activity/device/DevicesActivity.java b/app/src/main/java/sed/inf/u_szeged/hu/androidiotsimulator/activity/device/DevicesActivity.java index 85bfc27..3dc9b0b 100644 --- a/app/src/main/java/sed/inf/u_szeged/hu/androidiotsimulator/activity/device/DevicesActivity.java +++ b/app/src/main/java/sed/inf/u_szeged/hu/androidiotsimulator/activity/device/DevicesActivity.java @@ -3,14 +3,12 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.res.Resources; -import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.Message; import android.provider.DocumentsContract; -import android.provider.MediaStore; import android.support.annotation.NonNull; import android.support.design.widget.FloatingActionButton; import android.support.v7.app.AlertDialog; @@ -20,7 +18,6 @@ import android.widget.Button; import android.widget.ListView; import android.widget.Spinner; -import android.widget.TextView; import android.widget.Toast; import com.google.gson.Gson; @@ -32,9 +29,7 @@ import sed.inf.u_szeged.hu.androidiotsimulator.MobIoTApplication; import sed.inf.u_szeged.hu.androidiotsimulator.R; import sed.inf.u_szeged.hu.androidiotsimulator.activity.adapter.DeviceGroupAdapter; -import sed.inf.u_szeged.hu.androidiotsimulator.activity.cloud.CloudActivity; import sed.inf.u_szeged.hu.androidiotsimulator.activity.cloud.CloudSettingsActivity; -import sed.inf.u_szeged.hu.androidiotsimulator.model.cloudsettings.CloudSettingsWrapper; import sed.inf.u_szeged.hu.androidiotsimulator.model.device.Device; import sed.inf.u_szeged.hu.androidiotsimulator.model.device.DeviceGroup; import sed.inf.u_szeged.hu.androidiotsimulator.model.device.SensorDataWrapper; @@ -310,13 +305,13 @@ public void initDevices() { private void initButtons() { - ((FloatingActionButton) findViewById(R.id.new_device_fab)).setOnClickListener(new View.OnClickListener() { + findViewById(R.id.new_device_fab).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(DevicesActivity.this); builder.setTitle("Select source"); - final String cloudTypes[] = {"Create new device", "Import device template"}; + final String[] cloudTypes = {"Create new device", "Import device template"}; builder.setItems(cloudTypes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { @@ -344,10 +339,7 @@ public void onClick(DialogInterface dialog, int which) { }); - - - - ((Button) findViewById(R.id.stop_all_btn)).setOnClickListener(new View.OnClickListener() { + findViewById(R.id.stop_all_btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { for (DeviceGroup deviceGroup : deviceGroupList) { @@ -357,7 +349,7 @@ public void onClick(View v) { } }); - ((Button) findViewById(R.id.start_all_btn)).setOnClickListener(new View.OnClickListener() { + findViewById(R.id.start_all_btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { for (DeviceGroup deviceGroup : deviceGroupList) { @@ -369,7 +361,7 @@ public void onClick(View v) { } }); - ((Button) findViewById(R.id.delete_all_btn)).setOnClickListener(new View.OnClickListener() { + findViewById(R.id.delete_all_btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { for (DeviceGroup group : deviceGroupList) { @@ -382,6 +374,24 @@ public void onClick(View v) { }); } + private class Param { + String paramName; + int min; + int max; + + Param() { + paramName = ""; + min = 0; + max = 0; + } + + Param(String paramName, int min, int max) { + this.paramName = paramName; + this.min = min; + this.max = max; + } + } + private void createNewDeviceAction() { AlertDialog.Builder builder = new AlertDialog.Builder(DevicesActivity.this); builder.setTitle("Select device type"); @@ -405,12 +415,78 @@ public void onClick(DialogInterface dialog, int which) { //TODO from resources String type = "Custom"; double freq = 1; + /* String paramName = ""; int min = 0; int max = 0; + */ + List param_container = new ArrayList(); Resources res = getResources(); switch (String.valueOf(sp.getSelectedItem())) { + case "Bracelet": + type = getString(R.string.type_bracelet); + + param_container.add(new Param( + getString(R.string.param_heart_rate_monitor), + res.getInteger(R.integer.heart_rate_monitor_min), + res.getInteger(R.integer.heart_rate_monitor_max)) + ); + param_container.add(new Param( + getString(R.string.param_blood_pressure_monitor), + res.getInteger(R.integer.blood_pressure_monitor_min), + res.getInteger(R.integer.blood_pressure_monitor_max)) + ); + break; + case "Custom": + type = getString(R.string.type_custom); + param_container.add(new Param( + getString(R.string.param_custom), + res.getInteger(R.integer.custom_min), + res.getInteger(R.integer.custom_max)) + ); + freq = res.getInteger(R.integer.custom_frequency); + break; + case "Thermostat": + type = getString(R.string.type_thermostat); + param_container.add(new Param( + getString(R.string.param_temperature), + res.getInteger(R.integer.temp_min), + res.getInteger(R.integer.temp_max)) + ); + freq = res.getInteger(R.integer.temp_frequency); + break; + case "Temperature": + type = getString(R.string.type_temperature); + param_container.add(new Param( + getString(R.string.param_temperature), + res.getInteger(R.integer.temp_min), + res.getInteger(R.integer.temp_max)) + ); + freq = res.getInteger(R.integer.temp_frequency); + break; + case "Humidity": + type = getString(R.string.type_humidity); + freq = res.getInteger(R.integer.humidity_frequency); + param_container.add(new Param( + getString(R.string.param_humidity), + res.getInteger(R.integer.humidity_min), + res.getInteger(R.integer.humidity_max)) + ); + break; + case "Weathergroup": + type = getString(R.string.type_custom); + param_container.add(new Param( + getString(R.string.param_custom), + res.getInteger(R.integer.custom_min), + res.getInteger(R.integer.custom_max)) + ); + freq = res.getInteger(R.integer.custom_frequency); + break; + default: + param_container.add(new Param()); + break; + /* case "Custom": type = getString(R.string.type_custom); paramName = getString(R.string.param_custom); @@ -446,12 +522,19 @@ public void onClick(DialogInterface dialog, int which) { max = res.getInteger(R.integer.custom_max); freq = res.getInteger(R.integer.custom_frequency); break; + */ } bundle.putString(DeviceSettingsActivity.KEY_TYPE, type); bundle.putString(DeviceSettingsActivity.KEY_FREQ, Double.toString(freq)); - bundle.putString(DeviceSettingsActivity.KEY_SENSORS, paramName + "+" + min + "+" + max); + String sensorDataSerial = ""; + for (Param p : param_container) { + if (!sensorDataSerial.isEmpty()) sensorDataSerial += "*"; + sensorDataSerial += p.paramName + "+" + p.min + "+" + p.max; + } + bundle.putString(DeviceSettingsActivity.KEY_SENSORS, sensorDataSerial); + //bundle.putString(DeviceSettingsActivity.KEY_SENSORS, paramName + "+" + min + "+" + max); bundle.putString(DeviceSettingsActivity.KEY_TRACE_LOCATION, "random"); bundle.putString(DeviceSettingsActivity.KEY_NUM_OF_DEVICES, "1"); bundle.putString(DeviceSettingsActivity.KEY_SAVE_TRACE, String.valueOf(true)); @@ -483,7 +566,7 @@ private void saveDevicesToPrefs() { } public void initDevicesList() { - devicesLV = (ListView) findViewById(R.id.devices_lv); + devicesLV = findViewById(R.id.devices_lv); deviceGroupAdapter = new DeviceGroupAdapter(this, R.layout.device_item, deviceGroupList); devicesLV.setAdapter(deviceGroupAdapter); deviceGroupAdapter.notifyDataSetChanged(); diff --git a/app/src/main/java/sed/inf/u_szeged/hu/androidiotsimulator/model/device/Device.java b/app/src/main/java/sed/inf/u_szeged/hu/androidiotsimulator/model/device/Device.java index 9890de6..704b79c 100644 --- a/app/src/main/java/sed/inf/u_szeged/hu/androidiotsimulator/model/device/Device.java +++ b/app/src/main/java/sed/inf/u_szeged/hu/androidiotsimulator/model/device/Device.java @@ -195,9 +195,15 @@ private void bluemixQuickstartSubscribe() { public void stop(Context ctx) { isRunning = false; - if (traceFileLocation.equals("random")) { - //saveLog(ctx); + try{ + if(client.isConnected()) + client.disconnect(); + } catch(MqttException e){ + e.printStackTrace(); } + /*if (traceFileLocation.equals("random")) { + //saveLog(ctx); + }*/ } @@ -213,8 +219,8 @@ public void bluemixQuickstartConnect() { //TODO SSL //https://console.bluemix.net/docs/services/IoT/reference/security/connect_devices_apps_gw.html#client_port_security - String broker_prefix = "tcp://"; - String broker_suffix = ".messaging.internetofthings.ibmcloud.com:8883"; + String broker_prefix = "ssl://"; + String broker_suffix = ".messaging.internetofthings.ibmcloud.com:443"; String broker = broker_prefix + organizationID + broker_suffix; @@ -613,15 +619,11 @@ public boolean equals(Object o) { return false; } - if (other.getTraceFileLocation() != traceFileLocation) { - return false; - } - - if (other.isSaveTrace() != saveTrace) { + if (!other.getTraceFileLocation().equals(traceFileLocation)) { return false; } - return true; + return other.isSaveTrace() == saveTrace; } else { return false; } diff --git a/app/src/main/res/values/integers.xml b/app/src/main/res/values/integers.xml index 758e6f6..d68f8e3 100644 --- a/app/src/main/res/values/integers.xml +++ b/app/src/main/res/values/integers.xml @@ -16,4 +16,11 @@ 1 10 + + 60 + 100 + + 60 + 120 + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e6286c3..b881f96 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -21,6 +21,7 @@ + Bracelet Custom Temperature Humidity @@ -98,4 +99,8 @@ Set parameters Field is empty! + Bracelet + Heart rate monitor + Blood pressure monitor + diff --git a/build.gradle b/build.gradle index 6bac596..0f728a6 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.3' + classpath 'com.android.tools.build:gradle:3.4.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -18,6 +18,7 @@ allprojects { repositories { jcenter() maven { url 'https://repo.eclipse.org/content/repositories/paho-releases/' } + google() } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 385c90b..eb8d1d4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip