diff --git a/AndroidJavaClient/.gitignore b/AndroidJavaClient/.gitignore new file mode 100644 index 0000000..5edb4ee --- /dev/null +++ b/AndroidJavaClient/.gitignore @@ -0,0 +1,10 @@ +*.iml +.gradle +/local.properties +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/AndroidJavaClient/app/.gitignore b/AndroidJavaClient/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/AndroidJavaClient/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/AndroidJavaClient/app/build.gradle b/AndroidJavaClient/app/build.gradle new file mode 100644 index 0000000..cc5f3f8 --- /dev/null +++ b/AndroidJavaClient/app/build.gradle @@ -0,0 +1,33 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 28 + defaultConfig { + applicationId "com.microsoft.aspnet.signalr.samples.androidjavaclient" + minSdkVersion 24 + 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' + } + } + compileOptions { + targetCompatibility 1.8 + sourceCompatibility 1.8 + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.android.support:appcompat-v7:28.0.0-rc01' + implementation 'com.android.support.constraint:constraint-layout:1.1.2' + 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 'com.microsoft.aspnet:signalr:0.1.0-preview1-35029' +} diff --git a/AndroidJavaClient/app/proguard-rules.pro b/AndroidJavaClient/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/AndroidJavaClient/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/AndroidJavaClient/app/src/main/AndroidManifest.xml b/AndroidJavaClient/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..f53781b --- /dev/null +++ b/AndroidJavaClient/app/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AndroidJavaClient/app/src/main/java/com/microsoft/aspnet/signalr/samples/androidjavaclient/MainActivity.java b/AndroidJavaClient/app/src/main/java/com/microsoft/aspnet/signalr/samples/androidjavaclient/MainActivity.java new file mode 100644 index 0000000..f15e138 --- /dev/null +++ b/AndroidJavaClient/app/src/main/java/com/microsoft/aspnet/signalr/samples/androidjavaclient/MainActivity.java @@ -0,0 +1,68 @@ +package com.microsoft.aspnet.signalr.samples.androidjavaclient; + + +import android.support.v7.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 android.widget.TextView; + +import com.microsoft.aspnet.signalr.Action; +import com.microsoft.aspnet.signalr.HubConnection; +import com.microsoft.aspnet.signalr.HubConnectionBuilder; +import com.microsoft.aspnet.signalr.LogLevel; + +import java.util.ArrayList; +import java.util.List; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + HubConnection hubConnection = new HubConnection("Your URL Here"); + TextView textView = (TextView)findViewById(R.id.tvMain); + ListView listView = (ListView)findViewById(R.id.lvMessages); + Button sendButton = (Button)findViewById(R.id.bSend); + EditText editText = (EditText)findViewById(R.id.etMessageText); + + List messageList = new ArrayList(); + ArrayAdapter arrayAdapter = new ArrayAdapter(MainActivity.this, + android.R.layout.simple_list_item_1, messageList); + listView.setAdapter(arrayAdapter); + + hubConnection.on("Send", (message)-> { + runOnUiThread(new Runnable() { + @Override + public void run() { + arrayAdapter.add(message); + arrayAdapter.notifyDataSetChanged(); + } + }); + }, String.class); + + sendButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + String message = editText.getText().toString(); + editText.setText(""); + try { + hubConnection.send("Send", message); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + + try { + hubConnection.start(); + } catch (Exception e) { + e.printStackTrace(); + textView.setText("There was an error: " + e.getMessage()); + } + } +} diff --git a/AndroidJavaClient/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/AndroidJavaClient/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..c7bd21d --- /dev/null +++ b/AndroidJavaClient/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/AndroidJavaClient/app/src/main/res/drawable/ic_launcher_background.xml b/AndroidJavaClient/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..d5fccc5 --- /dev/null +++ b/AndroidJavaClient/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AndroidJavaClient/app/src/main/res/layout/activity_main.xml b/AndroidJavaClient/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..87ceec9 --- /dev/null +++ b/AndroidJavaClient/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,29 @@ + + + + + + +