Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
genofire
donkey
Commits
bcf06692
Commit
bcf06692
authored
Aug 06, 2019
by
Anon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Turn MainActivity into a menu with status
parent
a9a9d954
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
83 additions
and
14 deletions
+83
-14
app/src/main/java/com/github/antweb/donkey/ConnectionService.kt
...c/main/java/com/github/antweb/donkey/ConnectionService.kt
+17
-0
app/src/main/java/com/github/antweb/donkey/MainActivity.kt
app/src/main/java/com/github/antweb/donkey/MainActivity.kt
+24
-9
app/src/main/java/com/github/antweb/donkey/ScanActivity.kt
app/src/main/java/com/github/antweb/donkey/ScanActivity.kt
+2
-2
app/src/main/res/layout/activity_main_connected.xml
app/src/main/res/layout/activity_main_connected.xml
+16
-0
app/src/main/res/layout/activity_main_not_connected.xml
app/src/main/res/layout/activity_main_not_connected.xml
+16
-0
app/src/main/res/values/strings.xml
app/src/main/res/values/strings.xml
+8
-3
No files found.
app/src/main/java/com/github/antweb/donkey/ConnectionService.kt
0 → 100644
View file @
bcf06692
package
com.github.antweb.donkey
import
android.bluetooth.BluetoothDevice
object
ConnectionService
{
var
device
:
BluetoothDevice
?
=
null
val
deviceName
:
String
?
get
()
=
device
?.
name
val
deviceAddress
:
String
?
get
()
=
device
?.
address
fun
hasDevice
():
Boolean
{
return
device
!=
null
}
}
\ No newline at end of file
app/src/main/java/com/github/antweb/donkey/MainActivity.kt
View file @
bcf06692
...
@@ -10,19 +10,34 @@ private const val TAG = "MainActivity"
...
@@ -10,19 +10,34 @@ private const val TAG = "MainActivity"
class
MainActivity
:
AppCompatActivity
()
{
class
MainActivity
:
AppCompatActivity
()
{
private
lateinit
var
tvConnection
:
TextView
private
lateinit
var
tvValue
:
TextView
private
lateinit
var
buttonConnect
:
Button
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_main
)
tvValue
=
findViewById
(
R
.
id
.
text_value
)
if
(
ConnectionService
.
hasDevice
())
{
tvConnection
=
findViewById
(
R
.
id
.
text_connection_status
)
showConnectedView
()
tvConnection
.
text
=
"STATE_DISCONNECTED"
}
else
{
showNotConnectedView
()
}
}
private
fun
showConnectedView
()
{
setContentView
(
R
.
layout
.
activity_main_connected
)
val
buttonSend
=
findViewById
<
Button
>(
R
.
id
.
button_send
)
buttonSend
.
setOnClickListener
{
val
intent
=
Intent
(
this
,
SendActivity
::
class
.
java
)
startActivity
(
intent
)
}
val
tvStatus
=
findViewById
<
TextView
>(
R
.
id
.
label_status
)
tvStatus
.
text
=
getString
(
R
.
string
.
main_label_status
,
ConnectionService
.
deviceName
,
ConnectionService
.
deviceAddress
)
}
private
fun
showNotConnectedView
()
{
setContentView
(
R
.
layout
.
activity_main_not_connected
)
buttonConnect
=
findViewById
(
R
.
id
.
button_connect
)
val
buttonConnect
=
findViewById
<
Button
>
(
R
.
id
.
button_connect
)
buttonConnect
.
setOnClickListener
{
buttonConnect
.
setOnClickListener
{
val
intent
=
Intent
(
this
,
ScanActivity
::
class
.
java
)
val
intent
=
Intent
(
this
,
ScanActivity
::
class
.
java
)
startActivity
(
intent
)
startActivity
(
intent
)
...
...
app/src/main/java/com/github/antweb/donkey/ScanActivity.kt
View file @
bcf06692
...
@@ -41,8 +41,8 @@ class ScanActivity : AppCompatActivity() {
...
@@ -41,8 +41,8 @@ class ScanActivity : AppCompatActivity() {
val
item
=
adapterView
.
adapter
.
getItem
(
i
)
as
?
BluetoothDevice
val
item
=
adapterView
.
adapter
.
getItem
(
i
)
as
?
BluetoothDevice
if
(
item
!=
null
)
{
if
(
item
!=
null
)
{
selectedD
evice
=
item
ConnectionService
.
d
evice
=
item
val
intent
=
Intent
(
this
,
Send
Activity
::
class
.
java
)
val
intent
=
Intent
(
this
,
Main
Activity
::
class
.
java
)
startActivity
(
intent
)
startActivity
(
intent
)
}
}
}
}
...
...
app/src/main/res/layout/activity_main_connected.xml
0 → 100644
View file @
bcf06692
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:orientation=
"vertical"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:id=
"@+id/label_status"
/>
<Button
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:id=
"@+id/button_send"
android:text=
"@string/main_button_send"
/>
</LinearLayout>
\ No newline at end of file
app/src/main/res/layout/activity_main.xml
→
app/src/main/res/layout/activity_main
_not_connected
.xml
View file @
bcf06692
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:orientation=
"vertical"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
android:layout_height=
"match_parent"
android:orientation=
"vertical"
tools:context=
".MainActivity"
>
<TextView
android:layout_width=
"wrap_content"
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:id=
"@+id/text_connection_status"
android:text=
"@string/main_label_not_connected"
/>
/>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:id=
"@+id/text_value"
/>
<Button
android:layout_width=
"wrap_content"
<Button
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"@string/main_button_connect"
android:text=
"@string/main_button_connect"
android:id=
"@+id/button_connect"
android:id=
"@+id/button_connect"
/>
/>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
app/src/main/res/values/strings.xml
View file @
bcf06692
<resources>
<resources>
<string
name=
"app_name"
>
BLE File Transfer
</string>
<string
name=
"app_name"
>
card10
</string>
<string
name=
"main_activity_title"
>
BLE File Transfer
</string>
<string
name=
"main_button_connect"
>
Reconnect
</string>
<string
name=
"scan_activity_title"
>
Scan Devices
</string>
<string
name=
"scan_activity_title"
>
Scan Devices
</string>
<string
name=
"send_activity_title"
>
Send File
</string>
<string
name=
"send_activity_title"
>
Send File
</string>
<string
name=
"main_activity_title"
>
@string/app_name
</string>
<string
name=
"main_label_not_connected"
>
You are currently not connected to your card10.
</string>
<string
name=
"main_label_status"
>
You are connected to %1$s (%2$s)
</string>
<string
name=
"main_button_connect"
>
Connect
</string>
<string
name=
"main_button_send"
>
Send File
</string>
</resources>
</resources>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment