mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-03-29 19:23:30 -04:00
Show app version in the app #5
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package com.geeksville.mesh
|
||||
|
||||
// import kotlinx.android.synthetic.main.tabs.*
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
@@ -12,6 +11,7 @@ import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.pm.PackageInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.hardware.usb.UsbDevice
|
||||
import android.hardware.usb.UsbManager
|
||||
@@ -22,10 +22,11 @@ import android.os.RemoteException
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.widget.TooltipCompat
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
@@ -121,6 +122,8 @@ class MainActivity : AppCompatActivity(), Logging,
|
||||
bluetoothManager.adapter
|
||||
}
|
||||
|
||||
private var actionBarMenu: Menu? = null
|
||||
|
||||
val model: UIViewModel by viewModels()
|
||||
|
||||
data class TabInfo(val text: String, val icon: Int, val content: Fragment)
|
||||
@@ -390,6 +393,8 @@ class MainActivity : AppCompatActivity(), Logging,
|
||||
} */
|
||||
setContentView(R.layout.activity_main)
|
||||
|
||||
initToolbar()
|
||||
|
||||
pager.adapter = tabsAdapter
|
||||
pager.isUserInputEnabled =
|
||||
false // Gestures for screen switching doesn't work so good with the map view
|
||||
@@ -409,8 +414,18 @@ class MainActivity : AppCompatActivity(), Logging,
|
||||
askToRate()
|
||||
}
|
||||
|
||||
private fun initToolbar() {
|
||||
val toolbar =
|
||||
findViewById<View>(R.id.toolbar) as Toolbar
|
||||
setSupportActionBar(toolbar)
|
||||
supportActionBar?.setDisplayShowTitleEnabled(false)
|
||||
}
|
||||
|
||||
private fun updateConnectionStatusImage(connected: MeshService.ConnectionState) {
|
||||
|
||||
if (actionBarMenu==null)
|
||||
return
|
||||
|
||||
val (image, tooltip) = when (connected) {
|
||||
MeshService.ConnectionState.CONNECTED -> Pair(R.drawable.cloud_on, R.string.connected)
|
||||
MeshService.ConnectionState.DEVICE_SLEEP -> Pair(
|
||||
@@ -424,8 +439,11 @@ class MainActivity : AppCompatActivity(), Logging,
|
||||
else -> Pair(R.drawable.cloud_off, R.string.disconnected)
|
||||
}
|
||||
|
||||
connectStatusImage.setImageResource(image)
|
||||
TooltipCompat.setTooltipText(connectStatusImage, getString(tooltip))
|
||||
val item = actionBarMenu?.findItem(R.id.connectStatusImage)
|
||||
if (item != null) {
|
||||
item.setIcon(image)
|
||||
item.setTitle(tooltip)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -804,6 +822,7 @@ class MainActivity : AppCompatActivity(), Logging,
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
menuInflater.inflate(R.menu.menu_main, menu)
|
||||
actionBarMenu = menu
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -812,10 +831,27 @@ class MainActivity : AppCompatActivity(), Logging,
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
return when (item.itemId) {
|
||||
R.id.action_settings -> true
|
||||
R.id.about -> {
|
||||
getVersionInfo()
|
||||
return true
|
||||
}
|
||||
R.id.connectStatusImage -> {
|
||||
Toast.makeText(this, item.title, Toast.LENGTH_SHORT).show()
|
||||
return true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getVersionInfo() {
|
||||
try {
|
||||
val packageInfo: PackageInfo = packageManager.getPackageInfo(packageName, 0)
|
||||
val versionName = packageInfo.versionName
|
||||
Toast.makeText(this, versionName, Toast.LENGTH_LONG).show()
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
errormsg("Can not find the version: ${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/appBarLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/AppTheme.AppBarOverlay">
|
||||
@@ -15,48 +16,41 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView4"
|
||||
android:layout_width="wrap_content"
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:contentDescription="@string/application_icon"
|
||||
android:scaleType="center"
|
||||
android:scaleX="1.5"
|
||||
android:scaleY="1.5"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:srcCompat="@drawable/ic_baseline_settings_input_antenna_24" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:gravity="center"
|
||||
android:minHeight="?actionBarSize"
|
||||
android:padding="16dp"
|
||||
android:text="@string/app_name"
|
||||
android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title"
|
||||
app:layout_constraintStart_toEndOf="@+id/imageView4"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/connectStatusImage"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_weight="1"
|
||||
android:contentDescription="@string/connection_status"
|
||||
android:tint="#FFFFFF"
|
||||
|
||||
android:background="?attr/colorPrimary"
|
||||
android:minHeight="?attr/actionBarSize"
|
||||
android:visibility="visible"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
app:layout_constraintHeight_percent=".5"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:srcCompat="@drawable/cloud_off" />
|
||||
<ImageView
|
||||
android:id="@+id/imageView5"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:contentDescription="@string/application_icon"
|
||||
android:scaleType="center"
|
||||
android:scaleX="1.5"
|
||||
android:scaleY="1.5"
|
||||
app:srcCompat="@drawable/ic_baseline_settings_input_antenna_24" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:gravity="center"
|
||||
android:minHeight="?actionBarSize"
|
||||
android:padding="16dp"
|
||||
android:text="@string/app_name"
|
||||
android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title" />
|
||||
|
||||
</androidx.appcompat.widget.Toolbar>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
<menu 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"
|
||||
tools:context="com.geeksville.mesh.MainActivity">
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="100"
|
||||
android:title="@string/action_settings"
|
||||
app:showAsAction="never" />
|
||||
android:id="@+id/connectStatusImage"
|
||||
android:contentDescription="@string/connection_status"
|
||||
android:icon="@drawable/cloud_off"
|
||||
android:tint="#FFFFFF"
|
||||
android:title="@string/disconnected"
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
android:id="@+id/about"
|
||||
android:title="@string/about"
|
||||
app:showAsAction="withText" />
|
||||
</menu>
|
||||
|
||||
@@ -70,4 +70,5 @@
|
||||
<string name="modem_config_unrecognized">UNRECOGNIZED</string>
|
||||
<string name="meshtastic_service_notifications">Meshtastic Service Notifications</string>
|
||||
<string name="location_disabled_warning">You must turn on location services in Android Settings</string>
|
||||
<string name="about">About</string>
|
||||
</resources>
|
||||
|
||||
@@ -5,17 +5,21 @@
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
<item name="colorAccent">#FFFFFF</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.NoActionBar" parent="Theme.MaterialComponents.Light.NoActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
<item name="android:itemTextAppearance">@style/menu_item_color</item>
|
||||
</style>
|
||||
|
||||
|
||||
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
|
||||
|
||||
<style name="menu_item_color">
|
||||
<item name="android:textColor">@android:color/black</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
|
||||
|
||||
<style name="Widget.App.Button.OutlinedButton.IconOnly" parent="Widget.MaterialComponents.Button.OutlinedButton">
|
||||
@@ -28,5 +32,5 @@
|
||||
<item name="android:minHeight">48dp</item>
|
||||
</style>
|
||||
|
||||
<style name="Widget.App.CardView" parent="Widget.MaterialComponents.CardView"></style>
|
||||
<style name="Widget.App.CardView" parent="Widget.MaterialComponents.CardView"/>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user