sforkowany z mirror/meshtastic-android
commit
4d9ae0df73
|
@ -7,10 +7,7 @@ import android.bluetooth.BluetoothAdapter
|
|||
import android.bluetooth.BluetoothDevice
|
||||
import android.bluetooth.BluetoothManager
|
||||
import android.companion.CompanionDeviceManager
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.*
|
||||
import android.content.pm.PackageInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.hardware.usb.UsbDevice
|
||||
|
@ -28,7 +25,9 @@ import android.view.View
|
|||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
|
@ -379,6 +378,9 @@ class MainActivity : AppCompatActivity(), Logging,
|
|||
val prefs = UIViewModel.getPreferences(this)
|
||||
model.ownerName.value = prefs.getString("owner", "")!!
|
||||
|
||||
/// Set theme
|
||||
setUITheme(prefs)
|
||||
|
||||
/// Set initial bluetooth state
|
||||
updateBluetoothEnabled()
|
||||
|
||||
|
@ -1068,6 +1070,10 @@ class MainActivity : AppCompatActivity(), Logging,
|
|||
startActivityForResult(intent, CREATE_CSV_FILE)
|
||||
return true
|
||||
}
|
||||
R.id.theme -> {
|
||||
chooseThemeDialog()
|
||||
return true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
@ -1114,5 +1120,80 @@ class MainActivity : AppCompatActivity(), Logging,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Theme functions
|
||||
|
||||
private fun chooseThemeDialog() {
|
||||
|
||||
/// Prepare dialog and its items
|
||||
val builder = AlertDialog.Builder(this)
|
||||
builder.setTitle(getString(R.string.choose_theme_title))
|
||||
|
||||
val styles = arrayOf(
|
||||
getString(R.string.theme_light),
|
||||
getString(R.string.theme_dark),
|
||||
getString(R.string.theme_system))
|
||||
|
||||
/// Load preferences and its value
|
||||
val prefs = UIViewModel.getPreferences(this)
|
||||
val editor: SharedPreferences.Editor = prefs.edit()
|
||||
val checkedItem = prefs.getInt("theme", 2)
|
||||
|
||||
builder.setSingleChoiceItems(styles, checkedItem) { dialog, which ->
|
||||
|
||||
when (which) {
|
||||
0 -> {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||
editor.putInt("theme", 0)
|
||||
editor.apply()
|
||||
|
||||
delegate.applyDayNight()
|
||||
dialog.dismiss()
|
||||
}
|
||||
1 -> {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||
editor.putInt("theme", 1)
|
||||
editor.apply()
|
||||
|
||||
delegate.applyDayNight()
|
||||
dialog.dismiss()
|
||||
}
|
||||
2 -> {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||
editor.putInt("theme", 2)
|
||||
editor.apply()
|
||||
|
||||
delegate.applyDayNight()
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
val dialog = builder.create()
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
private fun setUITheme(prefs: SharedPreferences) {
|
||||
/// Read theme settings from preferences and set it
|
||||
/// If nothing is found set FOLLOW SYSTEM option
|
||||
|
||||
when (prefs.getInt("theme", 2)) {
|
||||
0 -> {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||
delegate.applyDayNight()
|
||||
}
|
||||
1 -> {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||
delegate.applyDayNight()
|
||||
}
|
||||
2 -> {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||
delegate.applyDayNight()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:theme="@style/MyToolbar"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/colorPrimary"
|
||||
|
|
|
@ -77,7 +77,9 @@
|
|||
android:alpha="0.4"
|
||||
app:layout_constraintEnd_toStartOf="@+id/dateReceived"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:srcCompat="@drawable/cloud_download_outline_24" />
|
||||
app:srcCompat="@drawable/cloud_download_outline_24"
|
||||
android:contentDescription="TODO"
|
||||
app:tint="@color/colorIconTint" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" android:background="#FFFFFF"
|
||||
>
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/colorAdvancedBackground">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/positionBroadcastPeriodView"
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#FFFFFF"
|
||||
android:background="@color/colorDebugBackground"
|
||||
>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
|
|
|
@ -5,4 +5,5 @@
|
|||
android:padding="16dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textAppearance="?attr/textAppearanceSubtitle1" />
|
||||
android:textAppearance="?attr/textAppearanceSubtitle1"
|
||||
/>
|
|
@ -132,7 +132,7 @@
|
|||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:background="@color/cardview_light_background"
|
||||
android:background="@android:color/transparent"
|
||||
android:checked="true"
|
||||
android:text="@string/analytics_okay"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
|
|
|
@ -24,6 +24,10 @@
|
|||
android:id="@+id/save_messages_csv"
|
||||
app:showAsAction="withText"
|
||||
android:title="@string/save_messages" />
|
||||
<item
|
||||
android:id="@+id/theme"
|
||||
android:title="@string/theme"
|
||||
app:showAsAction="withText" />
|
||||
<item
|
||||
android:id="@+id/about"
|
||||
android:title="@string/about"
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="colorPrimary">#3700B3</color>
|
||||
<color name="colorPrimaryDark">#3700B3</color>
|
||||
<color name="colorMsg">#212121</color>
|
||||
<color name="colorMyMsg">#212121</color>
|
||||
<color name="colorDebugBackground">#141414</color>
|
||||
<color name="colorAdvancedBackground">#141414</color>
|
||||
<color name="colorIconTint">#FFFFFF</color>
|
||||
<color name="colorMenuItem">#FFFFFF</color>
|
||||
<color name="colorToolbar">#000000</color>
|
||||
</resources>
|
|
@ -4,4 +4,9 @@
|
|||
<color name="colorPrimaryDark">#3700B3</color>
|
||||
<color name="colorMsg">#F2F2F2</color>
|
||||
<color name="colorMyMsg">#EDEAF4</color>
|
||||
<color name="colorDebugBackground">#FFFFFF</color>
|
||||
<color name="colorAdvancedBackground">#FFFFFF</color>
|
||||
<color name="colorIconTint">#000000</color>
|
||||
<color name="colorMenuItem">#000000</color>
|
||||
<color name="colorToolbar">#FFFFFF</color>
|
||||
</resources>
|
||||
|
|
|
@ -103,4 +103,9 @@
|
|||
<string name="reset_to_defaults">Reset to defaults</string>
|
||||
<string name="apply">Apply</string>
|
||||
<string name="no_app_found">No application found to send URLs</string>
|
||||
<string name="theme">Theme</string>
|
||||
<string name="theme_light">Light</string>
|
||||
<string name="theme_dark">Dark</string>
|
||||
<string name="theme_system">System default</string>
|
||||
<string name="choose_theme_title">Choose theme</string>
|
||||
</resources>
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
|
||||
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">#FFFFFF</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.NoActionBar" parent="Theme.MaterialComponents.Light.NoActionBar">
|
||||
<style name="AppTheme.NoActionBar" parent="Theme.MaterialComponents.DayNight.NoActionBar">
|
||||
<item name="windowNoTitle">true</item>
|
||||
<item name="android:itemTextAppearance">@style/menu_item_color</item>
|
||||
</style>
|
||||
|
@ -31,7 +31,7 @@
|
|||
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
|
||||
|
||||
<style name="menu_item_color">
|
||||
<item name="android:textColor">@android:color/black</item>
|
||||
<item name="android:textColor">@color/colorMenuItem</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
|
||||
|
@ -52,4 +52,11 @@
|
|||
<item name="cornerFamily">rounded</item>
|
||||
<item name="cornerSize">50%</item>
|
||||
</style>
|
||||
|
||||
// Toolbar style
|
||||
<style name="MyToolbar" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
|
||||
<item name="tint">@color/colorToolbar</item>
|
||||
<item name="colorOnPrimary">@color/colorToolbar</item>
|
||||
<item name="android:textColor">@color/colorToolbar</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
|
Ładowanie…
Reference in New Issue