Commit fa972779 authored by Anon's avatar Anon Committed by Andreas Schildbach
Browse files

Implement menu screen with connection status and navigation.

parent 98d48420
......@@ -35,7 +35,7 @@ import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager
import de.ccc.events.badge.card10.background.SetClockJob
import de.ccc.events.badge.card10.installer.InstallerFragment
import de.ccc.events.badge.card10.scanner.ScannerFragment
import de.ccc.events.badge.card10.main.MainFragment
import java.util.concurrent.TimeUnit
private const val REQUEST_CODE_ENABLE_BLUETOOTH = 1
......@@ -92,18 +92,15 @@ class MainActivity : AppCompatActivity() {
}
fun permissionGranted() {
var fragment = supportFragmentManager.findFragmentById(R.id.fragment_container)
if (fragment == null) {
// this dispatcher is a very rough first cut
if (intent.action == "application/x.card10.app")
fragment = InstallerFragment()
else
fragment = ScannerFragment()
supportFragmentManager.beginTransaction()
.add(R.id.fragment_container, fragment)
.commit()
val fragment = when {
intent.action == "application/x.card10.app" -> InstallerFragment()
else -> MainFragment()
}
supportFragmentManager.beginTransaction()
.replace(R.id.fragment_container, fragment)
.commit()
val workManager = WorkManager.getInstance(this)
if (!bluetoothAdapter.bondedDevices.isEmpty()
) {
......
/*
* Copyright by the original author or authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package de.ccc.events.badge.card10.main
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.fragment.app.Fragment
import de.ccc.events.badge.card10.R
import de.ccc.events.badge.card10.common.ConnectionService
class MainFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?) =
inflater.inflate(R.layout.main_fragment, container, false)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
if (ConnectionService.isConnected()) {
showConnectedView(view)
} else {
showDisconnectedView(view)
}
}
private fun showConnectedView(view: View) {
view.findViewById<ConstraintLayout>(R.id.container_connected).visibility = View.VISIBLE
view.findViewById<ConstraintLayout>(R.id.container_disconnected).visibility = View.GONE
val tvStatus = view.findViewById<TextView>(R.id.label_status)
tvStatus.text =
getString(R.string.main_label_status, ConnectionService.deviceName, ConnectionService.deviceAddress)
val buttonSend = view.findViewById<Button>(R.id.button_send)
buttonSend.setOnClickListener {
// TODO: Open file transfer fragment
}
}
private fun showDisconnectedView(view: View) {
view.findViewById<ConstraintLayout>(R.id.container_connected).visibility = View.GONE
view.findViewById<ConstraintLayout>(R.id.container_disconnected).visibility = View.VISIBLE
val tvStatus = view.findViewById<TextView>(R.id.label_status)
tvStatus.text = getString(R.string.main_label_not_connected)
val buttonConnect = view.findViewById<Button>(R.id.button_connect)
buttonConnect.setOnClickListener {
// TODO: Open scan fragment
}
}
}
<vector android:height="66dp" android:viewportHeight="220"
android:viewportWidth="660" android:width="200dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#00000000"
android:pathData="m431.2,210.5h-19.4c-19.5,0 -35.4,-15.9 -35.4,-35.4L376.4,45.4c0,-19.5 15.9,-35.4 35.4,-35.4h122.9l0.1,46.3h-19.8c-11,0 -19.9,9 -19.9,19.9v68.1c0,11 9,19.9 19.9,19.9h68.1c11,0 19.9,-9 19.9,-19.9L603,76.2c0,-11 -9,-19.9 -19.9,-19.9h-19.8l-0.2,-46.3h50.8c19.5,0 35.4,15.9 35.4,35.4L649.3,175.1c0,19.5 -15.9,35.4 -35.4,35.4h-154L459.6,56.1 417.9,110.4"
android:strokeColor="#000000" android:strokeLineCap="round"
android:strokeLineJoin="round" android:strokeWidth="15"/>
<path android:fillColor="#FF000000" android:pathData="m18.2,133.5c0,7.3 2.4,13 7.1,17.2 4.8,4.2 10.4,6.3 16.8,6.3 1.3,0 3.2,-0.2 5.7,-0.6 2.5,-0.4 5,-0.9 7.4,-1.6 2.9,-0.6 5.9,-1.5 9,-2.4l4.6,14c-3.4,1.1 -6.6,2.1 -9.7,2.9 -2.7,0.8 -5.7,1.5 -8.7,1.9 -3.1,0.5 -5.8,0.7 -8.2,0.7 -5.3,0 -10.4,-1 -15.1,-2.9 -4.8,-1.9 -8.9,-4.6 -12.5,-8 -3.6,-3.4 -6.3,-7.4 -8.4,-12.1 -2,-4.7 -3,-9.8 -3,-15.5L3.2,84.2c0,-5.5 1,-10.6 3,-15.3 2,-4.7 4.8,-8.7 8.2,-12.1 3.5,-3.4 7.6,-6 12.4,-7.9 4.8,-1.9 9.8,-2.8 15.1,-2.8 2.6,0 5.3,0.4 8.2,1.1 2.9,0.7 5.7,1.5 8.5,2.3 2.9,1 6,2.1 9.2,3.4l-3.9,13.3c-2.6,-1 -5.3,-1.8 -8,-2.4 -2.3,-0.6 -4.7,-1.2 -7.3,-1.8 -2.6,-0.6 -4.8,-0.8 -6.8,-0.8 -6.5,0 -12,2.1 -16.7,6.3 -4.7,4.2 -7,9.8 -7,16.7v49.3zM158.2,156.3 L163.5,161.1 152.6,172 146.1,165.5c-5,2.4 -10.3,4.2 -15.7,5.3 -5.5,1.1 -9.7,1.7 -12.6,1.7 -4.7,0 -9,-0.9 -13.1,-2.8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-0.8 -1.3,-0.1 -2.7,-0.1 -4.1,-0.1 -2.3,0 -5.2,0.6 -9,1.8 -3.7,1.2 -7.5,3.5 -11.4,6.9L202.2,170L187.2,170L187.2,64.8c-1,-1 -2.2,-2.1 -3.6,-3.4 -1.5,-1.3 -2.6,-2.4 -3.4,-3.4l10.7,-10.9 8.2,8c4.7,-3.7 9.1,-6.1 13.2,-7 4.1,-1 7.7,-1.5 10.8,-1.5 3.2,0 6.9,0.7 10.9,2.2 4,1.5 9.8,4.3 17.4,8.5zM322.4,2h15L337.4,156.5l6.1,5.8 -10.9,10.7 -7.3,-7.3c-4.8,2.4 -10,4.1 -15.4,5.1 -5.4,1 -9.7,1.5 -13,1.5 -4.7,0 -9,-0.9 -13,-2.7 -4,-1.8 -7.4,-4.2 -10.4,-7.4 -3,-3.1 -5.3,-6.9 -7,-11.1 -1.7,-4.3 -2.5,-8.8 -2.5,-13.7L264,81.7c0,-4.8 0.8,-9.4 2.5,-13.6 1.7,-4.2 4,-7.9 7,-11 3,-3.1 6.5,-5.7 10.4,-7.5 4,-1.9 8.3,-2.8 13,-2.8 2.4,0 5.9,0.3 10.3,0.8 4.4,0.6 9.5,2.2 15.1,5L322.3,2ZM322.1,69.8c-4.8,-2.9 -9.6,-4.9 -14.4,-6.1 -4.8,-1.1 -8.4,-1.7 -10.8,-1.7 -5,0 -9.2,1.9 -12.7,5.6 -3.5,3.7 -5.2,8.2 -5.2,13.3v57.4c0,5.2 1.7,9.6 5.2,13.2 3.5,3.6 7.6,5.4 12.5,5.4 1.5,0 3.4,-0.2 5.9,-0.6 2.5,-0.4 5.1,-0.9 7.8,-1.6 2.7,-0.6 5.1,-1.4 7.3,-2.3 2.2,-0.9 3.7,-1.9 4.5,-3L322.2,69.8Z"/>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/activity_padding">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/image_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/card10_logo_text"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/label_status"
android:layout_marginTop="@dimen/logo_margin_bottom"
android:gravity="center"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/image_logo" />
<androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/label_status"
android:id="@+id/container_connected">
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/main_label_margin"
android:id="@+id/button_hatchery"
android:text="@string/main_button_browse_apps"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/main_label_margin"
android:id="@+id/button_send"
android:text="@string/main_button_send_file"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button_hatchery" />
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/main_label_margin"
android:id="@+id/button_mood"
android:text="@string/main_button_mood"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button_send" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/label_status"
android:id="@+id/container_disconnected">
<Button android:id="@+id/button_connect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/main_button_connect"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="activity_padding">24dp</dimen>
<dimen name="logo_margin_bottom">24dp</dimen>
<dimen name="main_label_margin">24dp</dimen>
<dimen name="send_label_margin">24dp</dimen>
</resources>
\ No newline at end of file
</resources>
<resources>
<string name="app_name">card10 Companion</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_browse_apps">Browse Apps</string>
<string name="main_button_send_file">Send File</string>
<string name="main_button_mood">Change Mood</string>
<string name="file_transfer_button_pick_file">Select</string>
<string name="file_transfer_button_start_transfer">Start</string>
<string name="file_transfer_button_stop_transfer">Cancel</string>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment