Added Dark Theme settings option

Added drawable-night folder for night theme drawings
This commit is contained in:
Juha Heinanen
2021-01-10 13:25:17 +02:00
parent 6d45798944
commit 1ffcebc2ab
10 changed files with 90 additions and 17 deletions

View File

@ -53,6 +53,7 @@ dependencies {
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
implementation "androidx.preference:preference-ktx:1.1.1"
}
repositories {

View File

@ -47,17 +47,10 @@ class ChatListAdapter(private val ctx: Context, private var rows: ArrayList<Mess
textAvatarView.setBackgroundResource(R.drawable.person_image)
}
if ((message.direction == R.drawable.arrow_down_green) ||
(message.direction == R.drawable.arrow_down_red)) {
if (Utils.darkTheme(ctx))
layout.setBackgroundResource(R.drawable.message_in_dark_bg)
else
(message.direction == R.drawable.arrow_down_red))
layout.setBackgroundResource(R.drawable.message_in_bg)
} else {
if (Utils.darkTheme(ctx))
layout.setBackgroundResource(R.drawable.message_out_dark_bg)
else
else
layout.setBackgroundResource(R.drawable.message_out_bg)
}
val peerView = rowView.findViewById(R.id.peer) as TextView
peerView.setText(peer)
val infoView = rowView.findViewById(R.id.info) as TextView

View File

@ -10,6 +10,7 @@ import android.view.MenuItem
import android.view.View
import android.widget.*
import android.widget.AdapterView
import androidx.appcompat.app.AppCompatDelegate
import com.tutpro.baresip.databinding.ActivityConfigBinding
class ConfigActivity : AppCompatActivity() {
@ -20,6 +21,7 @@ class ConfigActivity : AppCompatActivity() {
private lateinit var dnsServers: EditText
private lateinit var certificateFile: CheckBox
private lateinit var caFile: CheckBox
private lateinit var darkTheme: CheckBox
private lateinit var debug: CheckBox
private lateinit var sipTrace: CheckBox
private lateinit var reset: CheckBox
@ -97,6 +99,10 @@ class ConfigActivity : AppCompatActivity() {
}
}
darkTheme = binding.DarkTheme
val oldDisplayTheme = Preferences(applicationContext).displayTheme
darkTheme.isChecked = oldDisplayTheme == AppCompatDelegate.MODE_NIGHT_YES
debug = binding.Debug
val dbCv = Config.variable("log_level")
if (dbCv.size == 0)
@ -236,6 +242,12 @@ class ConfigActivity : AppCompatActivity() {
save = true
}
val newDisplayTheme = if (darkTheme.isChecked)
AppCompatDelegate.MODE_NIGHT_YES
else
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
Preferences(applicationContext).displayTheme = newDisplayTheme
var logLevelString = "2"
if (debug.isChecked) logLevelString = "0"
if (oldLogLevel != logLevelString) {
@ -340,6 +352,10 @@ class ConfigActivity : AppCompatActivity() {
Utils.alertView(this, getString(R.string.default_call_volume),
getString(R.string.default_call_volume_help))
}
binding.DarkThemeTitle -> {
Utils.alertView(this, getString(R.string.dark_theme),
getString(R.string.dark_theme_help))
}
binding.DebugTitle -> {
Utils.alertView(this, getString(R.string.debug), getString(R.string.debug_help))
}

View File

@ -21,6 +21,7 @@ import android.view.inputmethod.InputMethodManager
import android.widget.*
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.tutpro.baresip.databinding.ActivityMainBinding
@ -67,6 +68,9 @@ class MainActivity : AppCompatActivity() {
@SuppressLint("ClickableViewAccessibility")
override fun onCreate(savedInstanceState: Bundle?) {
if (Preferences(applicationContext).displayTheme != AppCompatDelegate.getDefaultNightMode())
AppCompatDelegate.setDefaultNightMode(Preferences(applicationContext).displayTheme)
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
@ -625,6 +629,11 @@ class MainActivity : AppCompatActivity() {
super.onPause()
}
override fun recreate() {
Log.d("Baresip", "Main onCreate")
super.recreate()
}
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
when (keyCode) {
KeyEvent.KEYCODE_VOLUME_DOWN, KeyEvent.KEYCODE_VOLUME_UP -> {
@ -668,6 +677,7 @@ class MainActivity : AppCompatActivity() {
}
return
}
val uap = params[0]
val ua = UserAgent.ofUap(uap)
if (ua == null) {
@ -917,6 +927,7 @@ class MainActivity : AppCompatActivity() {
override fun onDestroy() {
Log.d("Baresip", "Main onDestroy")
BaresipService.activities.clear()
super.onDestroy()
}
@ -1031,6 +1042,11 @@ class MainActivity : AppCompatActivity() {
show()
}
}
val displayTheme = Preferences(applicationContext).displayTheme
if (displayTheme != AppCompatDelegate.getDefaultNightMode()) {
AppCompatDelegate.setDefaultNightMode(displayTheme)
delegate.applyDayNight()
}
}
CALLS_CODE -> {

View File

@ -26,17 +26,11 @@ class MessageListAdapter(private val ctx: Context, private val rows: ArrayList<M
val peer: String
if (up) {
lp.setMargins(75, 10, 0, 10)
if (Utils.darkTheme(ctx))
layout.setBackgroundResource(R.drawable.message_out_dark_bg)
else
layout.setBackgroundResource(R.drawable.message_out_bg)
layout.setBackgroundResource(R.drawable.message_out_bg)
peer = ctx.getString(R.string.you)
} else {
lp.setMargins(0, 10, 75, 10)
if (Utils.darkTheme(ctx))
layout.setBackgroundResource(R.drawable.message_in_dark_bg)
else
layout.setBackgroundResource(R.drawable.message_in_bg)
layout.setBackgroundResource(R.drawable.message_in_bg)
val contactName = ContactsActivity.contactName(message.peerUri)
if (contactName.startsWith("sip:") &&
(Utils.uriHostPart(message.peerUri) == Utils.uriHostPart(message.aor)))

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/colorSecondaryDark"/>
<corners android:bottomLeftRadius="5dp" android:radius="15dp" />
</shape>
</item>
</layer-list>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/colorPrimaryDark"/>
<corners android:topRightRadius="5dp" android:radius="15dp" />
</shape>
</item>
</layer-list>

View File

@ -172,6 +172,33 @@
</Spinner>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/DarkThemeTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_toStartOf="@id/DarkTheme"
android:textSize="18sp"
android:onClick="onClick"
android:text="@string/dark_theme" >
</TextView>
<CheckBox
android:id="@+id/DarkTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_gravity="end"
android:checked="false" >
</CheckBox>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View File

@ -312,6 +312,8 @@
<string name="default_call_volume_help">Jos valittu, puhelun äänen voimakkuus
asteikolla 110.
</string>
<string name="dark_theme">Tumma teema</string>
<string name="dark_theme_help">Käytä aina tummaa näyttöteemaa</string>
<string name="video_size">Videon kehyskoko</string>
<string name="video_size_help">Lähetettävän videon kehyskoko (leveys x korkeus).
Tehdasasetus on 800x600.</string>

View File

@ -277,6 +277,8 @@
<string name="invalid_opus_packet_loss">Invalid Opus Packet Loss Percentage</string>
<string name="default_call_volume">Default Call Volume</string>
<string name="default_call_volume_help">If set, default call audio volume at scale 110.</string>
<string name="dark_theme">Dark Theme</string>
<string name="dark_theme_help">Force dark display theme</string>
<string name="video_size">Video Frame Size</string>
<string name="video_size_help">Size of transmitted video frames (width x height).
Factory default is 800x600.</string>