diff --git a/AndroidHackVer2/app/build.gradle b/AndroidHackVer2/app/build.gradle index e446da0..89d2a99 100644 --- a/AndroidHackVer2/app/build.gradle +++ b/AndroidHackVer2/app/build.gradle @@ -18,18 +18,24 @@ android { } } +repositories { + maven { + url "https://repo.eclipse.org/content/repositories/paho-releases/" + } +} + dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:28.0.0' - implementation 'com.android.support.constraint:constraint-layout:1.1.3' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' - implementation('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2') { exclude module: 'support-v4' } + implementation fileTree(dir: 'libs', include: ['*.jar']) +// implementation 'com.android.support:appcompat-v7:27.1.1' + implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1' implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.1' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' } diff --git a/AndroidHackVer2/app/src/main/AndroidManifest.xml b/AndroidHackVer2/app/src/main/AndroidManifest.xml index b491372..a3cbe54 100644 --- a/AndroidHackVer2/app/src/main/AndroidManifest.xml +++ b/AndroidHackVer2/app/src/main/AndroidManifest.xml @@ -2,6 +2,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/DamnIt/.gitignore b/DamnIt/.gitignore new file mode 100644 index 0000000..fd45b12 --- /dev/null +++ b/DamnIt/.gitignore @@ -0,0 +1,11 @@ +*.iml +.gradle +/local.properties +/.idea/caches/build_file_checksums.ser +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/DamnIt/.idea/codeStyles/Project.xml b/DamnIt/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/DamnIt/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DamnIt/.idea/gradle.xml b/DamnIt/.idea/gradle.xml new file mode 100644 index 0000000..7ac24c7 --- /dev/null +++ b/DamnIt/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/DamnIt/.idea/misc.xml b/DamnIt/.idea/misc.xml new file mode 100644 index 0000000..e0d5b93 --- /dev/null +++ b/DamnIt/.idea/misc.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/DamnIt/.idea/runConfigurations.xml b/DamnIt/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/DamnIt/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/DamnIt/app/.gitignore b/DamnIt/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/DamnIt/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/DamnIt/app/build.gradle b/DamnIt/app/build.gradle new file mode 100644 index 0000000..b6cef45 --- /dev/null +++ b/DamnIt/app/build.gradle @@ -0,0 +1,35 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 28 + defaultConfig { + applicationId "com.divyanshu.damnit" + minSdkVersion 23 + targetSdkVersion 28 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'com.android.support.constraint:constraint-layout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + + implementation('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2') { + exclude module: 'support-v4' + } + + implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1' + implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.1' +} diff --git a/DamnIt/app/proguard-rules.pro b/DamnIt/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/DamnIt/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/DamnIt/app/src/androidTest/java/com/divyanshu/damnit/ExampleInstrumentedTest.java b/DamnIt/app/src/androidTest/java/com/divyanshu/damnit/ExampleInstrumentedTest.java new file mode 100644 index 0000000..f962876 --- /dev/null +++ b/DamnIt/app/src/androidTest/java/com/divyanshu/damnit/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.divyanshu.damnit; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.divyanshu.damnit", appContext.getPackageName()); + } +} diff --git a/DamnIt/app/src/main/AndroidManifest.xml b/DamnIt/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..1baddfe --- /dev/null +++ b/DamnIt/app/src/main/AndroidManifest.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DamnIt/app/src/main/java/com/divyanshu/damnit/MainActivity.java b/DamnIt/app/src/main/java/com/divyanshu/damnit/MainActivity.java new file mode 100644 index 0000000..a5bfca7 --- /dev/null +++ b/DamnIt/app/src/main/java/com/divyanshu/damnit/MainActivity.java @@ -0,0 +1,184 @@ +package com.divyanshu.damnit; + +import android.app.TimePickerDialog; +import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.NumberPicker; +import android.widget.TimePicker; +import android.widget.Toast; + +import com.divyanshu.damnit.R; + +import org.eclipse.paho.android.service.MqttAndroidClient; +import org.eclipse.paho.client.mqttv3.IMqttActionListener; +import org.eclipse.paho.client.mqttv3.IMqttToken; +import org.eclipse.paho.client.mqttv3.MqttClient; +import org.eclipse.paho.client.mqttv3.MqttConnectOptions; +import org.eclipse.paho.client.mqttv3.MqttException; +import org.eclipse.paho.client.mqttv3.MqttMessage; + +import java.io.UnsupportedEncodingException; +import java.util.Calendar; + +public class MainActivity extends AppCompatActivity { + + final static private String TAG = "MainActivity"; + + Button next; + EditText edit_message; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + final EditText edit_message = (EditText) findViewById(R.id.edit_message); + Button send_message = (Button) findViewById(R.id.next); +// Button receive_message = (Button) findViewById(R.id.receive_message); + + final MqttConnectOptions options = new MqttConnectOptions(); + options.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1); + options.setUserName("aakashk_kvjp58"); + options.setPassword("46f406136c5e4e5f874e283f95ed3dfc".toCharArray()); + +// +// String clientId = "clientId-xzFiqpzdbZ"; + String clientId = MqttClient.generateClientId(); + final MqttAndroidClient client = + new MqttAndroidClient(getApplicationContext(), "tcp://io.adafruit.com:1883", + clientId); + + /** + * Send message Button + */ + send_message.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + + + try { + IMqttToken token = client.connect(options); + token.setActionCallback(new IMqttActionListener() { + @Override + public void onSuccess(IMqttToken asyncActionToken) { + // We are connected + Log.d(TAG, "onSuccess"); + Toast toast = Toast.makeText(getApplicationContext(), "Connection Done", Toast.LENGTH_SHORT); + toast.show(); + + //Subscribing +// final String topic = "aakashk_kvjp58/f"; +// int qos = 1; +// try { +// IMqttToken subToken = client.subscribe(topic, qos); +// subToken.setActionCallback(new IMqttActionListener() { +// @Override +// public void onSuccess(IMqttToken asyncActionToken) { +// // The message was published +// Toast.makeText(MainActivity.this, "Successfully subscribed to: " + topic, Toast.LENGTH_SHORT).show(); + + //sending the message + + String user_message = edit_message.getText().toString(); + String topic = "aakashk_kvjp58/f/switch1"; + String payload = user_message; + byte[] encodedPayload = new byte[0]; + try { + encodedPayload = payload.getBytes("UTF-8"); + MqttMessage message = new MqttMessage(encodedPayload); + client.publish(topic, message); + Toast.makeText(MainActivity.this, "Message Sent", Toast.LENGTH_SHORT).show(); + + } catch (UnsupportedEncodingException | MqttException e) { + e.printStackTrace(); + } + + // disconnecting after task is done +// try { +// IMqttToken disconToken = client.disconnect(); +// disconToken.setActionCallback(new IMqttActionListener() { +// @Override +// public void onSuccess(IMqttToken asyncActionToken) { +// // we are now successfully disconnected +// } +// +// @Override +// public void onFailure(IMqttToken asyncActionToken, +// Throwable exception) { +// // something went wrong, but probably we are disconnected anyway +// } +// }); +// } catch (MqttException e) { +// e.printStackTrace(); +// } + + } + +// @Override +// public void onFailure(IMqttToken asyncActionToken, +// Throwable exception) { +// // The subscription could not be performed, maybe the user was not +// // authorized to subscribe on the specified topic e.g. using wildcards +// Toast.makeText(MainActivity.this, "Couldn't subscribe to: " + topic, Toast.LENGTH_SHORT).show(); +// +// +// } +// }); +// } catch (MqttException e) { +// e.printStackTrace(); +// } +// } + + @Override + public void onFailure(IMqttToken asyncActionToken, Throwable exception) { + // Something went wrong e.g. connection timeout or firewall problems + Log.d(TAG, "onFailure"); + Toast toast1 = Toast.makeText(getApplicationContext(), "failed", Toast.LENGTH_SHORT); + toast1.show(); + + + } + }); + } catch (MqttException e) { + e.printStackTrace(); + } + } + }); + + +// client.setCallback(new MqttCallback() { +// @Override +// public void connectionLost(Throwable cause) { +// Toast.makeText(MainActivity.this, "LOST", Toast.LENGTH_SHORT).show(); +// } +// +// @Override +// public void messageArrived(String topic, MqttMessage message) throws Exception { +// +// Toast.makeText(MainActivity.this, message.toString(), Toast.LENGTH_SHORT).show(); +// Log.d(TAG, "received"); +// } +// +// @Override +// public void deliveryComplete(IMqttDeliveryToken token) { +// +// Toast.makeText(MainActivity.this, "completed", Toast.LENGTH_SHORT).show(); +// } +// }); + + + + } + +} + + + + + diff --git a/DamnIt/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/DamnIt/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1f6bb29 --- /dev/null +++ b/DamnIt/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/DamnIt/app/src/main/res/drawable/ic_launcher_background.xml b/DamnIt/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..0d025f9 --- /dev/null +++ b/DamnIt/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DamnIt/app/src/main/res/layout/activity_main.xml b/DamnIt/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..4cc9ef6 --- /dev/null +++ b/DamnIt/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,21 @@ + + + + + +