Compare commits

...

2 Commits

Author SHA1 Message Date
vsuryakumar
b22de3cf8b Merge branch 'main' of https://github.com/surya-x/sickle-cell-updated into navigation-db
Updated to main.
2023-02-13 13:09:46 +05:30
vsuryakumar
0b6d78dfbb Added navigation Drawer. 2023-02-03 11:22:31 +05:30
7 changed files with 307 additions and 187 deletions

View File

@@ -10,9 +10,12 @@ import android.os.Bundle
import android.util.Log import android.util.Log
import android.view.Gravity import android.view.Gravity
import android.view.Menu import android.view.Menu
import android.view.MenuItem
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.view.GravityCompat
import androidx.core.view.get import androidx.core.view.get
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import com.example.hpos.R import com.example.hpos.R
@@ -59,7 +62,8 @@ class MainActivity : AppCompatActivity()
)[MainViewModel::class.java] )[MainViewModel::class.java]
setSupportActionBar(binding.myToolbar) setSupportActionBar(binding.myToolbar)
// supportActionBar?.setDisplayHomeAsUpEnabled(true)
setupNavigationDrawer()
setupListeners() setupListeners()
@@ -69,6 +73,39 @@ class MainActivity : AppCompatActivity()
registerReceiver(mUsbReceiver, filter) registerReceiver(mUsbReceiver, filter)
} }
private fun setupNavigationDrawer() {
// Pass the ActionBarToggle action into the drawerListener
val actionBarToggle = ActionBarDrawerToggle(this, binding.drawerLayout, 0, 0)
binding.drawerLayout.addDrawerListener(actionBarToggle)
// For the Navigation drawer
supportActionBar?.setDisplayHomeAsUpEnabled(true)
// Call syncState() on the action bar so it'll automatically change to the back button when the drawer layout is open
actionBarToggle.syncState()
// Call setNavigationItemSelectedListener on the NavigationView to detect when items are clicked
binding.navView.setNavigationItemSelectedListener { menuItem: MenuItem ->
when (menuItem.itemId) {
R.id.about_us -> {
Toast.makeText(this, "Test clicked", Toast.LENGTH_SHORT).show()
true
}
R.id.download_report -> {
Toast.makeText(this, "Download clicked", Toast.LENGTH_SHORT).show()
true
}
R.id.settings -> {
Toast.makeText(this, "Settings clicked", Toast.LENGTH_SHORT).show()
true
}
else -> {
false
}
}
}
}
private fun checkAndUpdateUsbConnection() { private fun checkAndUpdateUsbConnection() {
val availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(getSystemService(Context.USB_SERVICE) as UsbManager) val availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(getSystemService(Context.USB_SERVICE) as UsbManager)
if (availableDrivers.isNotEmpty() && availableDrivers[0].device.productId == Constants.DEVICE_PRODUCT_ID && availableDrivers[0].device.vendorId == Constants.DEVICE_VENDOR_ID){ if (availableDrivers.isNotEmpty() && availableDrivers[0].device.productId == Constants.DEVICE_PRODUCT_ID && availableDrivers[0].device.vendorId == Constants.DEVICE_VENDOR_ID){
@@ -116,4 +153,19 @@ class MainActivity : AppCompatActivity()
return true return true
} }
// override the onSupportNavigateUp() function to launch the Drawer when the hamburger icon is clicked
override fun onSupportNavigateUp(): Boolean {
binding.drawerLayout.openDrawer(binding.navView)
return true
}
// override the onBackPressed() function to close the Drawer when the back button is clicked
override fun onBackPressed() {
if (binding.drawerLayout.isDrawerOpen(GravityCompat.START)) {
binding.drawerLayout.closeDrawer(GravityCompat.START)
} else {
super.onBackPressed()
}
}
} }

View File

@@ -0,0 +1,5 @@
<vector android:autoMirrored="true" android:height="24dp"
android:tint="#000000" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-6h2v6zM13,9h-2L11,7h2v2z"/>
</vector>

View File

@@ -0,0 +1,5 @@
<vector android:autoMirrored="true" android:height="24dp"
android:tint="#000000" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M19.14,12.94c0.04,-0.3 0.06,-0.61 0.06,-0.94c0,-0.32 -0.02,-0.64 -0.07,-0.94l2.03,-1.58c0.18,-0.14 0.23,-0.41 0.12,-0.61l-1.92,-3.32c-0.12,-0.22 -0.37,-0.29 -0.59,-0.22l-2.39,0.96c-0.5,-0.38 -1.03,-0.7 -1.62,-0.94L14.4,2.81c-0.04,-0.24 -0.24,-0.41 -0.48,-0.41h-3.84c-0.24,0 -0.43,0.17 -0.47,0.41L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33c-0.22,-0.08 -0.47,0 -0.59,0.22L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48l2.03,1.58C4.84,11.36 4.8,11.69 4.8,12s0.02,0.64 0.07,0.94l-2.03,1.58c-0.18,0.14 -0.23,0.41 -0.12,0.61l1.92,3.32c0.12,0.22 0.37,0.29 0.59,0.22l2.39,-0.96c0.5,0.38 1.03,0.7 1.62,0.94l0.36,2.54c0.05,0.24 0.24,0.41 0.48,0.41h3.84c0.24,0 0.44,-0.17 0.47,-0.41l0.36,-2.54c0.59,-0.24 1.13,-0.56 1.62,-0.94l2.39,0.96c0.22,0.08 0.47,0 0.59,-0.22l1.92,-3.32c0.12,-0.22 0.07,-0.47 -0.12,-0.61L19.14,12.94zM12,15.6c-1.98,0 -3.6,-1.62 -3.6,-3.6s1.62,-3.6 3.6,-3.6s3.6,1.62 3.6,3.6S13.98,15.6 12,15.6z"/>
</vector>

View File

@@ -4,6 +4,12 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<androidx.drawerlayout.widget.DrawerLayout
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
@@ -13,13 +19,13 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" android:background="?attr/colorPrimary"
app:titleTextColor="#FFFFFF"
android:elevation="4dp" android:elevation="4dp"
app:menu="@menu/my_menu"
android:theme="@style/ToolbarTheme" android:theme="@style/ToolbarTheme"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/> app:layout_constraintTop_toTopOf="parent"
app:menu="@menu/my_menu"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleTextColor="#FFFFFF" />
<TextView <TextView
android:id="@+id/tv_title" android:id="@+id/tv_title"
@@ -83,7 +89,7 @@
app:layout_constraintBottom_toBottomOf="@+id/cv_item1" app:layout_constraintBottom_toBottomOf="@+id/cv_item1"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/cv_item1" app:layout_constraintStart_toEndOf="@id/cv_item1"
app:layout_constraintTop_toTopOf="@+id/cv_item1" > app:layout_constraintTop_toTopOf="@+id/cv_item1">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -120,12 +126,12 @@
android:id="@+id/cv_item3" android:id="@+id/cv_item3"
android:layout_width="128dp" android:layout_width="128dp"
android:layout_height="128dp" android:layout_height="128dp"
android:layout_marginTop="32dp"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
app:cardElevation="8dp" app:cardElevation="8dp"
app:layout_constraintEnd_toStartOf="@id/cv_item4" app:layout_constraintEnd_toStartOf="@id/cv_item4"
app:layout_constraintTop_toBottomOf="@id/cv_item1" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toStartOf="parent"> app:layout_constraintTop_toBottomOf="@id/cv_item1">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -166,10 +172,10 @@
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
app:cardElevation="8dp" app:cardElevation="8dp"
app:layout_constraintTop_toTopOf="@id/cv_item3"
app:layout_constraintBottom_toBottomOf="@id/cv_item3" app:layout_constraintBottom_toBottomOf="@id/cv_item3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/cv_item3" app:layout_constraintStart_toEndOf="@id/cv_item3"
app:layout_constraintEnd_toEndOf="parent"> app:layout_constraintTop_toTopOf="@id/cv_item3">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -205,5 +211,15 @@
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/navView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/drawer_list"
android:layout_marginTop="?actionBarSize"
app:headerLayout="@layout/nav_header"/>
</androidx.drawerlayout.widget.DrawerLayout>
</layout> </layout>

View File

@@ -0,0 +1,21 @@
<?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:id="@+id/navConstraint"
android:layout_width="match_parent"
android:layout_height="200dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:id="@+id/headerImage"
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="fitXY"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@mipmap/hpos_icon_foreground" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/about_us"
android:icon="@drawable/ic_baseline_info_24"
android:title="@string/about_us" />
<item
android:id="@+id/download_report"
android:icon="@drawable/ic_baseline_file_download_24"
android:title="@string/download_report" />
<item
android:id="@+id/settings"
android:icon="@drawable/ic_baseline_settings_24"
android:title="@string/settings" />
</menu>

View File

@@ -60,7 +60,7 @@
<string name="age_in_textview"><b>Age</b> : %1$s years</string> <string name="age_in_textview"><b>Age</b> : %1$s years</string>
<string name="results_in_textview"><b>Results</b> :</string> <string name="results_in_textview"><b>Results</b> :</string>
<string name="negative">Negative\ \ </string> <string name="negative">Negative\ \ </string>
<string name="download_report">Download\nReport</string> <string name="download_report">Download Report</string>
<string name="home">Home</string> <string name="home">Home</string>
<string name="new_test">New Test</string> <string name="new_test">New Test</string>
<string name="start_now">Start Now</string> <string name="start_now">Start Now</string>
@@ -79,4 +79,8 @@
<string name="sickle_find">Sickle Find</string> <string name="sickle_find">Sickle Find</string>
<string name="submit">Submit</string> <string name="submit">Submit</string>
<!-- Navigation Drawer -->
<string name="about_us">About Us</string>
<string name="settings">Settings</string>
</resources> </resources>