Skip to content

Commit c1ea932

Browse files
committed
Initial commit
0 parents  commit c1ea932

39 files changed

+575
-0
lines changed

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apply plugin: 'com.android.application'
2+
apply plugin: 'kotlin-android'
3+
apply plugin: 'kotlin-android-extensions'
4+
5+
android {
6+
compileSdkVersion 26
7+
buildToolsVersion "26.0.1"
8+
defaultConfig {
9+
applicationId "com.smartarmenia.websocketclient"
10+
minSdkVersion 16
11+
targetSdkVersion 26
12+
versionCode 1
13+
versionName "1.0"
14+
}
15+
buildTypes {
16+
release {
17+
minifyEnabled false
18+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19+
}
20+
}
21+
}
22+
23+
dependencies {
24+
implementation fileTree(include: ['*.jar'], dir: 'libs')
25+
implementation 'com.android.support:appcompat-v7:26.1.0'
26+
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
27+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
28+
implementation 'com.google.code.gson:gson:2.8.1'
29+
compile project(path: ':dotnetcoresignalrclient')
30+
}

app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile

app/src/main/AndroidManifest.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.smartarmenia.websocketclient">
4+
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
7+
<application
8+
android:allowBackup="true"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:roundIcon="@mipmap/ic_launcher_round"
12+
android:supportsRtl="true"
13+
android:theme="@style/AppTheme">
14+
<activity android:name=".MainActivity">
15+
<intent-filter>
16+
<action android:name="android.intent.action.MAIN" />
17+
18+
<category android:name="android.intent.category.LAUNCHER" />
19+
</intent-filter>
20+
</activity>
21+
</application>
22+
23+
</manifest>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.smartarmenia.websocketclient
2+
3+
import android.os.Bundle
4+
import android.support.v7.app.AppCompatActivity
5+
import android.widget.Toast
6+
import com.google.gson.Gson
7+
import com.smartarmenia.dotnetcoresignalrclient.*
8+
import kotlinx.android.synthetic.main.activity_main.*
9+
10+
11+
class MainActivity : AppCompatActivity(), HubConnectionListener, HubEventListener {
12+
override fun onEventMessage(message: HubMessage) {
13+
runOnUiThread { Toast.makeText(this@MainActivity, "Event message: ${message.target}\n${Gson().toJson(message.arguments)}", Toast.LENGTH_SHORT).show() }
14+
}
15+
16+
override fun onConnected() {
17+
runOnUiThread { Toast.makeText(this@MainActivity, "Connected", Toast.LENGTH_SHORT).show() }
18+
}
19+
20+
override fun onDisconnected() {
21+
runOnUiThread { Toast.makeText(this@MainActivity, "Disconnected", Toast.LENGTH_SHORT).show() }
22+
}
23+
24+
override fun onMessage(message: HubMessage) {
25+
runOnUiThread { Toast.makeText(this@MainActivity, "${message.target}\n${Gson().toJson(message.arguments)}", Toast.LENGTH_SHORT).show() }
26+
}
27+
28+
override fun onError(exception: Exception) {
29+
30+
}
31+
32+
private val connection: HubConnection = WebSocketHubConnection("http://192.168.0.109:5002/signalr/hubs/auth")
33+
34+
override fun onCreate(savedInstanceState: Bundle?) {
35+
super.onCreate(savedInstanceState)
36+
setContentView(R.layout.activity_main)
37+
38+
btnHello.setOnClickListener {
39+
connection.invoke("Send", "Hello")
40+
}
41+
42+
Thread(Runnable {
43+
connect()
44+
}).start()
45+
}
46+
47+
override fun onDestroy() {
48+
super.onDestroy()
49+
connection.removeListener(this)
50+
connection.unSubscribeFromEvent("Send", this)
51+
connection.disconnect()
52+
}
53+
54+
private fun connect() {
55+
try {
56+
connection.connect("Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6Ijc5NzhjMjI3LWViMGItNGMwOS1iYWEyLTEwYmE0MjI4YWE4OSIsImNlcnRzZXJpYWxudW1iZXIiOiJtYWNfYWRkcmVzc19vZl9waG9uZSIsInNlY3VyaXR5U3RhbXAiOiJlMTAxOWNiYy1jMjM2LTQ0ZTEtYjdjYy0zNjMxYTYxYzMxYmIiLCJuYmYiOjE1MDYyODQ4NzMsImV4cCI6NDY2MTk1ODQ3MywiaWF0IjoxNTA2Mjg0ODczLCJpc3MiOiJCbGVuZCIsImF1ZCI6IkJsZW5kIn0.QUh241IB7g3axLcfmKR2899Kt1xrTInwT6BBszf6aP4")
57+
} catch (ex: Exception) {
58+
runOnUiThread { Toast.makeText(this@MainActivity, ex.message, Toast.LENGTH_SHORT).show() }
59+
}
60+
connection.addListener(this@MainActivity)
61+
connection.subscribeToEvent("Send", this)
62+
}
63+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:width="24dp"
4+
android:height="24dp"
5+
android:viewportHeight="108.0"
6+
android:viewportWidth="108.0">
7+
<path
8+
android:fillColor="#26A69A"
9+
android:pathData="M0,0h108v108h-108z"
10+
android:strokeColor="#66FFFFFF"
11+
android:strokeWidth="0.8" />
12+
<path
13+
android:fillColor="#00000000"
14+
android:pathData="M19,0L19,108"
15+
android:strokeColor="#33FFFFFF"
16+
android:strokeWidth="0.8" />
17+
<path
18+
android:fillColor="#00000000"
19+
android:pathData="M9,0L9,108"
20+
android:strokeColor="#66FFFFFF"
21+
android:strokeWidth="0.8" />
22+
<path
23+
android:fillColor="#00000000"
24+
android:pathData="M39,0L39,108"
25+
android:strokeColor="#66FFFFFF"
26+
android:strokeWidth="0.8" />
27+
<path
28+
android:fillColor="#00000000"
29+
android:pathData="M29,0L29,108"
30+
android:strokeColor="#66FFFFFF"
31+
android:strokeWidth="0.8" />
32+
<path
33+
android:fillColor="#00000000"
34+
android:pathData="M59,0L59,108"
35+
android:strokeColor="#66FFFFFF"
36+
android:strokeWidth="0.8" />
37+
<path
38+
android:fillColor="#00000000"
39+
android:pathData="M49,0L49,108"
40+
android:strokeColor="#66FFFFFF"
41+
android:strokeWidth="0.8" />
42+
<path
43+
android:fillColor="#00000000"
44+
android:pathData="M79,0L79,108"
45+
android:strokeColor="#66FFFFFF"
46+
android:strokeWidth="0.8" />
47+
<path
48+
android:fillColor="#00000000"
49+
android:pathData="M69,0L69,108"
50+
android:strokeColor="#66FFFFFF"
51+
android:strokeWidth="0.8" />
52+
<path
53+
android:fillColor="#00000000"
54+
android:pathData="M89,0L89,108"
55+
android:strokeColor="#33FFFFFF"
56+
android:strokeWidth="0.8" />
57+
<path
58+
android:fillColor="#00000000"
59+
android:pathData="M99,0L99,108"
60+
android:strokeColor="#66FFFFFF"
61+
android:strokeWidth="0.8" />
62+
<path
63+
android:fillColor="#00000000"
64+
android:pathData="M0,89L108,89"
65+
android:strokeColor="#33FFFFFF"
66+
android:strokeWidth="0.8" />
67+
<path
68+
android:fillColor="#00000000"
69+
android:pathData="M0,99L108,99"
70+
android:strokeColor="#66FFFFFF"
71+
android:strokeWidth="0.8" />
72+
<path
73+
android:fillColor="#00000000"
74+
android:pathData="M0,69L108,69"
75+
android:strokeColor="#66FFFFFF"
76+
android:strokeWidth="0.8" />
77+
<path
78+
android:fillColor="#00000000"
79+
android:pathData="M0,79L108,79"
80+
android:strokeColor="#66FFFFFF"
81+
android:strokeWidth="0.8" />
82+
<path
83+
android:fillColor="#00000000"
84+
android:pathData="M0,49L108,49"
85+
android:strokeColor="#66FFFFFF"
86+
android:strokeWidth="0.8" />
87+
<path
88+
android:fillColor="#00000000"
89+
android:pathData="M0,59L108,59"
90+
android:strokeColor="#66FFFFFF"
91+
android:strokeWidth="0.8" />
92+
<path
93+
android:fillColor="#00000000"
94+
android:pathData="M0,29L108,29"
95+
android:strokeColor="#66FFFFFF"
96+
android:strokeWidth="0.8" />
97+
<path
98+
android:fillColor="#00000000"
99+
android:pathData="M0,39L108,39"
100+
android:strokeColor="#66FFFFFF"
101+
android:strokeWidth="0.8" />
102+
<path
103+
android:fillColor="#00000000"
104+
android:pathData="M0,19L108,19"
105+
android:strokeColor="#33FFFFFF"
106+
android:strokeWidth="0.8" />
107+
<path
108+
android:fillColor="#00000000"
109+
android:pathData="M0,9L108,9"
110+
android:strokeColor="#66FFFFFF"
111+
android:strokeWidth="0.8" />
112+
</vector>
113+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
tools:context="com.smartarmenia.websocketclient.MainActivity">
8+
9+
<android.support.v7.widget.AppCompatButton
10+
android:id="@+id/btnHello"
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
android:text="Hello World!"
14+
app:layout_constraintBottom_toBottomOf="parent"
15+
app:layout_constraintLeft_toLeftOf="parent"
16+
app:layout_constraintRight_toRightOf="parent"
17+
app:layout_constraintTop_toTopOf="parent" />
18+
19+
</android.support.constraint.ConstraintLayout>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
3+
<background android:drawable="@drawable/ic_launcher_background" />
4+
<foreground android:drawable="@mipmap/ic_launcher_foreground" />
5+
</adaptive-icon>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
3+
<background android:drawable="@drawable/ic_launcher_background" />
4+
<foreground android:drawable="@mipmap/ic_launcher_foreground" />
5+
</adaptive-icon>
3.28 KB
Loading

0 commit comments

Comments
 (0)