Added custom action bar with USB icon.
This commit is contained in:
4
.idea/misc.xml
generated
4
.idea/misc.xml
generated
@@ -22,6 +22,10 @@
|
|||||||
<entry key="app/src/main/res/layout/fragment_test_right_process.xml" value="0.24375" />
|
<entry key="app/src/main/res/layout/fragment_test_right_process.xml" value="0.24375" />
|
||||||
<entry key="app/src/main/res/layout/fragment_test_right_results.xml" value="0.33" />
|
<entry key="app/src/main/res/layout/fragment_test_right_results.xml" value="0.33" />
|
||||||
<entry key="app/src/main/res/layout/table_item.xml" value="0.22407407407407406" />
|
<entry key="app/src/main/res/layout/table_item.xml" value="0.22407407407407406" />
|
||||||
|
<entry key="app/src/main/res/menu/menu.xml" value="0.25" />
|
||||||
|
<entry key="app/src/main/res/menu/my_menu.xml" value="0.25" />
|
||||||
|
<entry key="app/src/main/res/mipmap-anydpi-v26/hpos_icon.xml" value="0.1505" />
|
||||||
|
<entry key="app/src/main/res/mipmap-anydpi-v26/hpos_icon_round.xml" value="0.1505" />
|
||||||
</map>
|
</map>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@@ -37,7 +37,8 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name="com.example.hpos.presentation.testRight.TestRightActivity"
|
android:name="com.example.hpos.presentation.testRight.TestRightActivity"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:windowSoftInputMode="adjustPan">
|
android:windowSoftInputMode="adjustPan"
|
||||||
|
android:parentActivityName="com.example.hpos.presentation.MainActivity">
|
||||||
<!-- <intent-filter>-->
|
<!-- <intent-filter>-->
|
||||||
<!-- <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />-->
|
<!-- <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />-->
|
||||||
<!-- </intent-filter>-->
|
<!-- </intent-filter>-->
|
||||||
@@ -46,8 +47,10 @@
|
|||||||
<!-- android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"-->
|
<!-- android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"-->
|
||||||
<!-- android:resource="@xml/device_filter" />-->
|
<!-- android:resource="@xml/device_filter" />-->
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name="com.example.hpos.presentation.MainActivity"
|
android:name="com.example.hpos.presentation.MainActivity"
|
||||||
|
android:theme="@style/Theme.HPOS.ActionBar"
|
||||||
android:exported="true">
|
android:exported="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
|
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
|
||||||
@@ -58,6 +61,7 @@
|
|||||||
android:resource="@xml/device_filter" />
|
android:resource="@xml/device_filter" />
|
||||||
|
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.example.hpos.presentation.testRight
|
package com.example.hpos.presentation.testRight
|
||||||
|
|
||||||
import android.R
|
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import android.content.*
|
import android.content.*
|
||||||
import android.hardware.usb.UsbDevice
|
import android.hardware.usb.UsbDevice
|
||||||
@@ -9,16 +8,18 @@ import android.hardware.usb.UsbManager
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.view.get
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import com.example.hpos.R
|
||||||
import com.example.hpos.data.DataHolder
|
import com.example.hpos.data.DataHolder
|
||||||
import com.example.hpos.data.constant.Constants
|
import com.example.hpos.data.constant.Constants
|
||||||
import com.example.hpos.databinding.ActivityTestRightBinding
|
import com.example.hpos.databinding.ActivityTestRightBinding
|
||||||
import com.example.hpos.util.MyViewModelFactory
|
import com.example.hpos.util.MyViewModelFactory
|
||||||
import com.google.android.material.snackbar.Snackbar
|
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialDriver
|
import com.hoho.android.usbserial.driver.UsbSerialDriver
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialProber
|
import com.hoho.android.usbserial.driver.UsbSerialProber
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ class TestRightActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private lateinit var binding: ActivityTestRightBinding
|
private lateinit var binding: ActivityTestRightBinding
|
||||||
private lateinit var viewModel: TestRightViewModel
|
private lateinit var viewModel: TestRightViewModel
|
||||||
|
private var myMenu: Menu? = null
|
||||||
|
|
||||||
private lateinit var mDriver: UsbSerialDriver
|
private lateinit var mDriver: UsbSerialDriver
|
||||||
private var mConnection: UsbDeviceConnection? = null
|
private var mConnection: UsbDeviceConnection? = null
|
||||||
@@ -74,13 +76,32 @@ class TestRightActivity : AppCompatActivity() {
|
|||||||
MyViewModelFactory(this.applicationContext)
|
MyViewModelFactory(this.applicationContext)
|
||||||
)[TestRightViewModel::class.java]
|
)[TestRightViewModel::class.java]
|
||||||
|
|
||||||
|
setSupportActionBar(binding.myToolbar)
|
||||||
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
|
|
||||||
// Connected or not connected icon with livetime status using live data
|
// Connected or not connected icon with livetime status using live data
|
||||||
|
|
||||||
connectUsb(false)
|
// Todo: uncomment it
|
||||||
// testing()
|
// connectUsb(false)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||||
|
menuInflater.inflate(R.menu.my_menu, menu)
|
||||||
|
myMenu = menu
|
||||||
|
// menu?.get(0)?.icon = ContextCompat.getDrawable(this, R.drawable.ic_baseline_circle_24)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {
|
||||||
|
R.id.action_usb -> {
|
||||||
|
Toast.makeText(this, "USB Connected", Toast.LENGTH_SHORT).show()
|
||||||
|
myMenu?.get(0)?.icon = ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_off_24)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
else -> {super.onOptionsItemSelected(item)}
|
||||||
|
}
|
||||||
|
|
||||||
// private fun testing() {
|
// private fun testing() {
|
||||||
// supportFragmentManager.beginTransaction()
|
// supportFragmentManager.beginTransaction()
|
||||||
// .replace(binding.flMain.id, TestRightExpSample()).commit()
|
// .replace(binding.flMain.id, TestRightExpSample()).commit()
|
||||||
@@ -168,6 +189,14 @@ class TestRightActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
fun onUsbError(msg: String) {
|
fun onUsbError(msg: String) {
|
||||||
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
|
||||||
|
// Snackbar.make(binding.flMain, msg, Snackbar.LENGTH_LONG)
|
||||||
|
// .setAction("CLOSE", object : View.OnClickListener {
|
||||||
|
// override fun onClick(p0: View?) {
|
||||||
|
// TODO("Not yet implemented")
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// .setActionTextColor(resources.getColor(R.color.holo_red_light))
|
||||||
|
// .show()
|
||||||
if (!isFinishing)
|
if (!isFinishing)
|
||||||
onBackPressed()
|
onBackPressed()
|
||||||
}
|
}
|
||||||
|
|||||||
5
app/src/main/res/drawable/ic_baseline_usb_24.xml
Normal file
5
app/src/main/res/drawable/ic_baseline_usb_24.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||||
|
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="M15,7v4h1v2h-3V5h2l-3,-4 -3,4h2v8H8v-2.07c0.7,-0.37 1.2,-1.08 1.2,-1.93 0,-1.21 -0.99,-2.2 -2.2,-2.2 -1.21,0 -2.2,0.99 -2.2,2.2 0,0.85 0.5,1.56 1.2,1.93V13c0,1.11 0.89,2 2,2h3v3.05c-0.71,0.37 -1.2,1.1 -1.2,1.95 0,1.22 0.99,2.2 2.2,2.2 1.21,0 2.2,-0.98 2.2,-2.2 0,-0.85 -0.49,-1.58 -1.2,-1.95V15h3c1.11,0 2,-0.89 2,-2v-2h1V7h-4z"/>
|
||||||
|
</vector>
|
||||||
5
app/src/main/res/drawable/ic_baseline_usb_off_24.xml
Normal file
5
app/src/main/res/drawable/ic_baseline_usb_off_24.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<vector android:autoMirrored="true" android:height="24dp"
|
||||||
|
android:tint="#B40000" 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="M15,8h4v4h-1v2c0,0.34 -0.08,0.66 -0.23,0.94L16,13.17V12h-1V8zM11,8.17l2,2V6h2l-3,-4L9,6h2V8.17zM13,16v2.28c0.6,0.34 1,0.98 1,1.72c0,1.1 -0.9,2 -2,2s-2,-0.9 -2,-2c0,-0.74 0.4,-1.37 1,-1.72V16H8c-1.11,0 -2,-0.89 -2,-2v-2.28C5.4,11.38 5,10.74 5,10c0,-0.59 0.26,-1.13 0.68,-1.49L1.39,4.22l1.41,-1.41l18.38,18.38l-1.41,1.41L13.17,16H13zM11,14v-0.17l-2.51,-2.51c-0.14,0.16 -0.31,0.29 -0.49,0.4V14H11z"/>
|
||||||
|
</vector>
|
||||||
@@ -5,12 +5,35 @@
|
|||||||
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.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.Toolbar
|
||||||
|
android:id="@+id/my_toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
android:background="?attr/colorPrimary"
|
||||||
|
app:titleTextColor="#FFFFFF"
|
||||||
|
android:elevation="4dp"
|
||||||
|
app:menu="@menu/my_menu"
|
||||||
|
android:theme="@style/ToolbarTheme"
|
||||||
|
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"/>
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/fl_main"
|
android:id="@+id/fl_main"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="0dp"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/my_toolbar"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
tools:context=".presentation.testRight.TestRightActivity">
|
tools:context=".presentation.testRight.TestRightActivity">
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
</layout>
|
</layout>
|
||||||
@@ -2,11 +2,14 @@
|
|||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
<!-- "Mark Favorite", should appear as action button if possible -->
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_favorite"
|
android:id="@+id/action_usb"
|
||||||
|
android:checkable="false"
|
||||||
|
android:enabled="true"
|
||||||
android:icon="@drawable/ic_baseline_usb_24"
|
android:icon="@drawable/ic_baseline_usb_24"
|
||||||
android:title="@string/usb_connection"
|
android:title="@string/usb_connection"
|
||||||
app:showAsAction="always"/>
|
android:visible="true"
|
||||||
|
app:showAsAction="always" />
|
||||||
|
|
||||||
|
|
||||||
</menu>
|
</menu>
|
||||||
@@ -21,4 +21,26 @@
|
|||||||
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
|
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
|
||||||
<!-- Customize your theme here. -->
|
<!-- Customize your theme here. -->
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="Theme.HPOS.ActionBar" parent="Theme.MaterialComponents.Light.DarkActionBar">
|
||||||
|
<!-- <style name="Theme.RefactoredApp" parent="Theme.MaterialComponents.Light.DarkActionBar">-->
|
||||||
|
<!-- Primary brand color. -->
|
||||||
|
|
||||||
|
<!-- <item name="colorPrimary">@color/purple_200</item>-->
|
||||||
|
|
||||||
|
<!-- <item name="colorPrimary">@color/purple_500</item>-->
|
||||||
|
<item name="colorPrimary">@color/blue_app</item>
|
||||||
|
|
||||||
|
<!-- <item name="colorPrimaryVariant">@color/purple_700</item>-->
|
||||||
|
<item name="colorPrimaryVariant">@color/blue_app_dark</item>
|
||||||
|
|
||||||
|
<item name="colorOnPrimary">@color/black</item>
|
||||||
|
<!-- Secondary brand color. -->
|
||||||
|
<item name="colorSecondary">@color/teal_200</item>
|
||||||
|
<item name="colorSecondaryVariant">@color/teal_200</item>
|
||||||
|
<item name="colorOnSecondary">@color/black</item>
|
||||||
|
<!-- Status bar color. -->
|
||||||
|
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
|
||||||
|
<!-- Customize your theme here. -->
|
||||||
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -6,6 +6,10 @@
|
|||||||
<item name="android:windowFullscreen">true</item>
|
<item name="android:windowFullscreen">true</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="ToolbarTheme" parent="@style/ThemeOverlay.AppCompat.ActionBar">
|
||||||
|
<item name="colorControlNormal">@color/white</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
<style name="title1">
|
<style name="title1">
|
||||||
<item name="android:textSize">20.5sp</item>
|
<item name="android:textSize">20.5sp</item>
|
||||||
<item name="android:letterSpacing">-0.01</item>
|
<item name="android:letterSpacing">-0.01</item>
|
||||||
|
|||||||
@@ -15,4 +15,20 @@
|
|||||||
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
|
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
|
||||||
<!-- Customize your theme here. -->
|
<!-- Customize your theme here. -->
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="Theme.HPOS.ActionBar" parent="Theme.MaterialComponents.Light.DarkActionBar">
|
||||||
|
<!-- <style name="Theme.RefactoredApp" parent="Theme.MaterialComponents.Light.DarkActionBar">-->
|
||||||
|
<!-- Primary brand color. -->
|
||||||
|
<item name="colorPrimary">@color/blue_app</item>
|
||||||
|
<!-- <item name="colorPrimaryVariant">@color/purple_700</item>-->
|
||||||
|
<item name="colorPrimaryVariant">@color/blue_app_dark</item>
|
||||||
|
<item name="colorOnPrimary">@color/white</item>
|
||||||
|
<!-- Secondary brand color. -->
|
||||||
|
<item name="colorSecondary">@color/teal_200</item>
|
||||||
|
<item name="colorSecondaryVariant">@color/teal_700</item>
|
||||||
|
<item name="colorOnSecondary">@color/black</item>
|
||||||
|
<!-- Status bar color. -->
|
||||||
|
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
|
||||||
|
<!-- Customize your theme here. -->
|
||||||
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user