From d058e6de7a36687cca8b220dab98fcde757741a6 Mon Sep 17 00:00:00 2001 From: DadeKuma Date: Tue, 12 Mar 2019 14:13:41 +0100 Subject: [PATCH] Brief: project cleanup --- app/build.gradle | 10 +- app/src/main/AndroidManifest.xml | 1 + .../dadekuma/droidstomp/MainActivity.java | 62 ++++- .../drawable-v24/ic_launcher_foreground.xml | 12 +- .../res/drawable/ic_launcher_background.xml | 236 ++++++++++++------ app/src/main/res/layout/activity_main.xml | 66 ++++- .../res/mipmap-anydpi-v26/ic_launcher.xml | 4 +- .../mipmap-anydpi-v26/ic_launcher_round.xml | 4 +- droidstomplib/build.gradle | 7 - 9 files changed, 304 insertions(+), 98 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index dbaceff..012e65d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -25,13 +25,5 @@ dependencies { 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' -} - -allprojects { - repositories { - mavenLocal() - jcenter() - // ADD IT HERE - maven { url "https://jitpack.io" } - } + implementation project(path: ':droidstomplib') } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 938ec62..514c02f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,6 +12,7 @@ + diff --git a/app/src/main/java/com/github/dadekuma/droidstomp/MainActivity.java b/app/src/main/java/com/github/dadekuma/droidstomp/MainActivity.java index 1f9d176..216b23f 100644 --- a/app/src/main/java/com/github/dadekuma/droidstomp/MainActivity.java +++ b/app/src/main/java/com/github/dadekuma/droidstomp/MainActivity.java @@ -1,13 +1,73 @@ package com.github.dadekuma.droidstomp; + import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; + +import com.github.dadekuma.droidstomplib.connection.StompCallback; +import com.github.dadekuma.droidstomplib.connection.StompClient; public class MainActivity extends AppCompatActivity { + private StompClient stompClient; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + + final ViewGroup chatLayout = findViewById(R.id.message_container); + final EditText inputText = findViewById(R.id.message_input); + final Button sendButton = findViewById(R.id.message_send); + + final String serverEndpoint = "ws://10.0.2.2:8080/server_endpoint"; + final String subscriptionTopic = "/topic/test"; + + stompClient = new StompClient(); + stompClient.setStompCallback(new StompCallback() { + @Override + public void onMessageReceived(String topic, Long subscriptionId, String message) { + //if we receive a message on subscriptionTopic we add + //a text child view to chatLayout + if(topic.equals(subscriptionTopic)){ + addChatBox(chatLayout, message); + } + } + }); + + stompClient.connect(serverEndpoint); + stompClient.subscribe(subscriptionTopic); + + sendButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + String text = inputText.getText().toString(); + stompClient.send("/app/chat", text); + inputText.setText(""); + } + }); + } + + //this function is used to add a TextView with the received message to our chatLayout + private void addChatBox(final ViewGroup chatLayout, final String message){ + runOnUiThread(new Runnable() { + @Override + public void run() { + TextView text = new TextView(getApplicationContext()); + text.setText(message); + chatLayout.addView(text); + } + }); + } + + + @Override + protected void onStop() { + super.onStop(); + stompClient.disconnect(); //remember to close the stomp client when you are done! } -} +} \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml index c7bd21d..1f6bb29 100644 --- a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -2,13 +2,13 @@ xmlns:aapt="http://schemas.android.com/aapt" android:width="108dp" android:height="108dp" - android:viewportHeight="108" - android:viewportWidth="108"> + android:viewportWidth="108" + android:viewportHeight="108"> + android:strokeWidth="1" + android:strokeColor="#00000000"> + android:strokeWidth="1" + android:strokeColor="#00000000" /> diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml index 2408e30..0d025f9 100644 --- a/app/src/main/res/drawable/ic_launcher_background.xml +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -1,74 +1,170 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:viewportHeight="108"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 5dd2444..7805c21 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -4,6 +4,70 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".MainActivity"> + tools:context=".MainActivity" + tools:layout_editor_absoluteY="81dp"> + + + + + + + + + + +