Skip to content

Commit

Permalink
Add 3 more buttons to home screen
Browse files Browse the repository at this point in the history
  • Loading branch information
sounddrill31 committed Aug 23, 2024
1 parent 4b9dd9a commit c90fa6b
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 12 deletions.
41 changes: 39 additions & 2 deletions app/src/main/java/com/zeusinstitute/upiapp/FirstFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import android.view.ViewGroup
import android.widget.ImageView
import android.widget.Spinner
import android.widget.TextView
import android.widget.Toast
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.fragment.app.Fragment
Expand All @@ -20,6 +21,7 @@ import com.google.zxing.BarcodeFormat
import com.google.zxing.WriterException
import com.journeyapps.barcodescanner.BarcodeEncoder
import com.zeusinstitute.upiapp.databinding.FragmentFirstBinding
import kotlin.math.min

/**
* A simple [Fragment] subclass as the default destination in the navigation.
Expand All @@ -35,6 +37,9 @@ class FirstFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
private lateinit var paymentMethod: String
private lateinit var smsStatusTextView: TextView
private lateinit var loginButton: com.google.android.material.floatingactionbutton.FloatingActionButton
private lateinit var customAmountButton: com.google.android.material.floatingactionbutton.FloatingActionButton
private lateinit var splitBillButton: com.google.android.material.floatingactionbutton.FloatingActionButton
private lateinit var updateAppButton: com.google.android.material.floatingactionbutton.FloatingActionButton

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
Expand All @@ -60,13 +65,43 @@ class FirstFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
sharedPref.registerOnSharedPreferenceChangeListener(this) // Register listener

loginButton = view.findViewById(R.id.loginButton)
customAmountButton = view.findViewById(R.id.customAmountButton)
splitBillButton = view.findViewById(R.id.splitBillButton)
updateAppButton = view.findViewById(R.id.updateAppButton)

updateQRCode() // Generate QR code initially
updateSmsStatus()

loginButton.setOnClickListener {
findNavController().navigate(R.id.action_firstFragment_to_login)
}
customAmountButton.setOnClickListener {
findNavController().navigate(R.id.action_firstFragment_to_dynamicFragment)
}
splitBillButton.setOnClickListener {
findNavController().navigate(R.id.action_firstFragment_to_splitBillFragment)
}
updateAppButton.setOnClickListener {
findNavController().navigate(R.id.action_firstFragment_to_Update)
}
loginButton.setOnLongClickListener {
Toast.makeText(context, "Set UPI Id", Toast.LENGTH_SHORT).show()
true // Consume the long click
}
customAmountButton.setOnLongClickListener {
Toast.makeText(context, "Custom Amount", Toast.LENGTH_SHORT).show()
true // Consume the long click
}

splitBillButton.setOnLongClickListener {
Toast.makeText(context, "Split the Bill", Toast.LENGTH_SHORT).show()
true // Consume the long click
}

updateAppButton.setOnLongClickListener {
Toast.makeText(context, "Check for App Updates", Toast.LENGTH_SHORT).show()
true // Consume the long click
}
}

override fun onResume() {
Expand Down Expand Up @@ -99,9 +134,11 @@ class FirstFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList

private fun generateQRCode(text: String, imageView: ImageView) {
val barcodeEncoder = BarcodeEncoder()
try {
val bitmap: Bitmap = barcodeEncoder.encodeBitmap(text, BarcodeFormat.QR_CODE, 400, 400)
try {// Generate a high-resolution QR code (adjust size as needed)
val bitmap: Bitmap = barcodeEncoder.encodeBitmap(text, BarcodeFormat.QR_CODE, 800, 800)
imageView.setImageBitmap(bitmap)
imageView.scaleType = ImageView.ScaleType.FIT_CENTER // Let ImageView handle scaling
imageView.setPadding(0, 0, 0, 0)
} catch (e: WriterException) {
e.printStackTrace()
}
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/currency_rupee_24px.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M549,840L280,560L280,480L420,480Q473,480 511.5,445.5Q550,411 558,360L240,360L240,280L546,280Q529,245 495.5,222.5Q462,200 420,200L240,200L240,120L720,120L720,200L590,200Q604,217 615,237Q626,257 632,280L720,280L720,360L639,360Q631,445 569,502.5Q507,560 420,560L391,560L660,840L549,840Z"/>
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/receipt_long_24px.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal"
android:autoMirrored="true">
<path
android:fillColor="@android:color/white"
android:pathData="M240,880Q190,880 155,845Q120,810 120,760L120,640L240,640L240,80L300,140L360,80L420,140L480,80L540,140L600,80L660,140L720,80L780,140L840,80L840,760Q840,810 805,845Q770,880 720,880L240,880ZM720,800Q737,800 748.5,788.5Q760,777 760,760L760,200L320,200L320,640L680,640L680,760Q680,777 691.5,788.5Q703,800 720,800ZM360,360L360,280L600,280L600,360L360,360ZM360,480L360,400L600,400L600,480L360,480ZM680,360Q663,360 651.5,348.5Q640,337 640,320Q640,303 651.5,291.5Q663,280 680,280Q697,280 708.5,291.5Q720,303 720,320Q720,337 708.5,348.5Q697,360 680,360ZM680,480Q663,480 651.5,468.5Q640,457 640,440Q640,423 651.5,411.5Q663,400 680,400Q697,400 708.5,411.5Q720,423 720,440Q720,457 708.5,468.5Q697,480 680,480ZM240,800L600,800L600,720L200,720L200,760Q200,777 211.5,788.5Q223,800 240,800ZM200,800Q200,800 200,788.5Q200,777 200,760L200,720L200,720L200,800Z"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/update_24px.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M480,840Q405,840 339.5,811.5Q274,783 225.5,734.5Q177,686 148.5,620.5Q120,555 120,480Q120,405 148.5,339.5Q177,274 225.5,225.5Q274,177 339.5,148.5Q405,120 480,120Q562,120 635.5,155Q709,190 760,254L760,160L840,160L840,400L600,400L600,320L710,320Q669,264 609,232Q549,200 480,200Q363,200 281.5,281.5Q200,363 200,480Q200,597 281.5,678.5Q363,760 480,760Q585,760 663.5,692Q742,624 756,520L838,520Q823,657 720.5,748.5Q618,840 480,840ZM592,648L440,496L440,280L520,280L520,464L648,592L592,648Z"/>
</vector>
67 changes: 57 additions & 10 deletions app/src/main/res/layout/fragment_first.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
Expand All @@ -24,33 +25,43 @@
android:layout_height="0dp"
android:contentDescription="Generated QR Image"
android:padding="32dp"
android:scaleType="fitEnd"
app:layout_constraintEnd_toEndOf="parent"
android:scaleType="centerInside"
app:layout_constraintEnd_toStartOf="@+id/endGuideline"
app:layout_constraintHeight_percent="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toEndOf="@+id/startGuideline"
app:layout_constraintTop_toBottomOf="@+id/smsStatusTextView"
app:layout_constraintTop_toTopOf="parent"
tools:src="@tools:sample/backgrounds/scenic[2]" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/startGuideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="5dp" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/endGuideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_end="5dp" />

<LinearLayout
android:id="@+id/bottomLinearLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/qrCodeImageView"
app:layout_constraintVertical_bias="0.064">
app:layout_constraintTop_toBottomOf="@+id/qrCodeImageView">

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dummyupi"
android:text="UPI ID"
android:textSize="18sp" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
Expand All @@ -63,4 +74,40 @@

</LinearLayout>

<LinearLayout
android:id="@+id/fabLinearLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/bottomLinearLayout">

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/customAmountButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:clickable="true"
tools:src="@drawable/currency_rupee_24px" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/splitBillButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:clickable="true"
tools:src="@drawable/receipt_long_24px" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/updateAppButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:src="@drawable/update_24px" />

</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit c90fa6b

Please sign in to comment.