Browse Source

first bits of the nfc reader

pull/31/head
Jannik 3 years ago
parent
commit
3a0a31f781
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
  1. 14
      app/src/main/AndroidManifest.xml
  2. 14
      app/src/main/java/org/mosad/seil0/projectlaogai/MainActivity.kt
  3. 1
      app/src/main/java/org/mosad/seil0/projectlaogai/fragments/MensaFragment.kt
  4. 2
      app/src/main/res/layout/fragment_timetable.xml
  5. 6
      app/src/main/res/xml/nfc_tech_filter.xml

14
app/src/main/AndroidManifest.xml

@ -2,6 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.mosad.seil0.projectlaogai">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.NFC" />
<application
android:allowBackup="true"
@ -17,6 +18,7 @@
android:label="@string/app_name"
android:theme="@style/SplashTheme"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
@ -27,7 +29,17 @@
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.Light"
android:screenOrientation="portrait">
android:screenOrientation="portrait"
android:launchMode="singleTop">
<!-- nfc stuff -->
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/nfc_tech_filter" />
</activity>
</application>

14
app/src/main/java/org/mosad/seil0/projectlaogai/MainActivity.kt

@ -23,6 +23,8 @@
package org.mosad.seil0.projectlaogai
import android.graphics.Color
import android.nfc.NfcAdapter
import android.nfc.Tag
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
@ -32,6 +34,7 @@ import androidx.core.view.GravityCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction
import com.afollestad.aesthetic.Aesthetic
import com.afollestad.materialdialogs.MaterialDialog
import com.google.android.material.navigation.NavigationView
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.app_bar_main.*
@ -42,6 +45,7 @@ import org.mosad.seil0.projectlaogai.controller.PreferencesController.Companion.
import org.mosad.seil0.projectlaogai.fragments.*
import kotlin.system.measureTimeMillis
// TODO save the current fragment to show it when the app is restarted
class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
private var activeFragment: Fragment = HomeFragment() // the currently active fragment, home at the start
@ -68,6 +72,16 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
toggle.syncState()
nav_view.setNavigationItemSelectedListener(this)
// TODO nfc stuff, needs to move to it's own function
if (intent.action == NfcAdapter.ACTION_TECH_DISCOVERED) {
val tag: Tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG)
MaterialDialog(this)
.title(text = "nfc tag detected")
.message(text = tag.toString())
.show()
}
}
override fun onResume() {

1
app/src/main/java/org/mosad/seil0/projectlaogai/fragments/MensaFragment.kt

@ -43,7 +43,6 @@ import org.mosad.seil0.projectlaogai.uicomponents.MealLinearLayout
/**
* The mensa controller class
* contains all needed parts to display and the mensa detail screen
* TODO investigate reading the mensa card value via nfc in a background task, show value if card detected
*/
class MensaFragment : Fragment() {

2
app/src/main/res/layout/fragment_timetable.xml

@ -27,6 +27,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true" android:id="@+id/faBtnAddLesson" android:elevation="7dp"
android:visibility="visible" android:layout_gravity="bottom|center|end" android:layout_marginEnd="11dp"
android:visibility="gone" android:layout_gravity="bottom|center|end" android:layout_marginEnd="11dp"
android:layout_marginBottom="11dp" android:focusable="true"/>
</FrameLayout>

6
app/src/main/res/xml/nfc_tech_filter.xml

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<tech-list>
<tech>android.nfc.tech.NfcA</tech>
</tech-list>
</resources>
Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close