Wear Add preferenceMenuActivity

This commit is contained in:
Philoul 2023-09-06 23:35:04 +02:00
parent 343045ca9b
commit d9bbb830b3
11 changed files with 187 additions and 110 deletions

View file

@ -602,6 +602,10 @@
android:name=".interaction.menus.StatusMenuActivity"
android:exported="true"
android:label="@string/menu_status" />
<activity
android:name=".interaction.menus.PreferenceMenuActivity"
android:exported="true"
android:label="@string/menu_settings" />
<activity
android:name=".interaction.actions.TreatmentActivity"
android:exported="true"

View file

@ -8,6 +8,7 @@ import info.nightscout.androidaps.interaction.TileConfigurationActivity
import info.nightscout.androidaps.interaction.actions.*
import info.nightscout.androidaps.interaction.menus.FillMenuActivity
import info.nightscout.androidaps.interaction.menus.MainMenuActivity
import info.nightscout.androidaps.interaction.menus.PreferenceMenuActivity
import info.nightscout.androidaps.interaction.menus.StatusMenuActivity
import info.nightscout.androidaps.interaction.utils.MenuListActivity
@ -33,6 +34,7 @@ abstract class WearActivitiesModule {
@ContributesAndroidInjector abstract fun contributesMenuListActivity(): MenuListActivity
@ContributesAndroidInjector abstract fun contributesFillMenuActivity(): FillMenuActivity
@ContributesAndroidInjector abstract fun contributesPreferenceMenuActivity(): PreferenceMenuActivity
@ContributesAndroidInjector abstract fun contributesMainMenuActivity(): MainMenuActivity
@ContributesAndroidInjector abstract fun contributesStatusMenuActivity(): StatusMenuActivity
@ContributesAndroidInjector abstract fun contributesQuickSnoozeActivity(): QuickSnoozeActivity

View file

@ -21,7 +21,8 @@ class WatchfaceConfigurationActivity : WearPreferenceActivity(), SharedPreferenc
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
addPreferencesFromResource(R.xml.preferences)
val preferenceFile = intent.getIntExtra(getString(R.string.key_preference_id), R.xml.display_preferences)
addPreferencesFromResource(preferenceFile)
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this)
val view = window.decorView as ViewGroup
removeBackgroundRecursively(view)
@ -37,12 +38,9 @@ class WatchfaceConfigurationActivity : WearPreferenceActivity(), SharedPreferenc
}
override fun onSharedPreferenceChanged(sp: SharedPreferences, key: String?) {
if (key == getString(R.string.key_heart_rate_sampling)) {
if (sp.getBoolean(key, false)) {
if (key == getString(R.string.key_heart_rate_sampling) && sp.getBoolean(key, false))
requestBodySensorPermission()
}
}
}
private fun requestBodySensorPermission() {
val permission = Manifest.permission.BODY_SENSORS

View file

@ -42,7 +42,7 @@ class MainMenuActivity : MenuListActivity() {
override fun doAction(position: String) {
when (position) {
getString(R.string.menu_settings) -> startActivity(Intent(this, WatchfaceConfigurationActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) })
getString(R.string.menu_settings) -> startActivity(Intent(this, PreferenceMenuActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) })
getString(R.string.menu_resync) -> rxBus.send(EventWearToMobile(ActionResendData("Re-Sync")))
getString(R.string.status_profile_switch) -> rxBus.send(EventWearToMobile(EventData.ActionProfileSwitchSendInitialData(System.currentTimeMillis())))
getString(R.string.menu_tempt) -> startActivity(Intent(this, TempTargetActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) })

View file

@ -0,0 +1,49 @@
package info.nightscout.androidaps.interaction.menus
import android.content.Intent
import android.os.Bundle
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interaction.WatchfaceConfigurationActivity
import info.nightscout.androidaps.interaction.utils.MenuListActivity
class PreferenceMenuActivity : MenuListActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
setTitle(R.string.menu_settings)
super.onCreate(savedInstanceState)
}
override fun provideElements(): List<MenuItem> =
ArrayList<MenuItem>().apply {
add(MenuItem(R.drawable.ic_settings, getString(R.string.pref_display_settings)))
add(MenuItem(R.drawable.ic_settings, getString(R.string.pref_graph_settings)))
add(MenuItem(R.drawable.ic_settings, getString(R.string.pref_interface_settings)))
add(MenuItem(R.drawable.ic_settings, getString(R.string.pref_complication_settings)))
add(MenuItem(R.drawable.ic_settings, getString(R.string.pref_others_settings)))
}
override fun doAction(position: String) {
when (position) {
getString(R.string.pref_display_settings) -> startActivity(Intent(this, WatchfaceConfigurationActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
putExtra(getString(R.string.key_preference_id), R.xml.display_preferences)
})
getString(R.string.pref_graph_settings) -> startActivity(Intent(this, WatchfaceConfigurationActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
putExtra(getString(R.string.key_preference_id), R.xml.graph_preferences)
})
getString(R.string.pref_interface_settings) -> startActivity(Intent(this, WatchfaceConfigurationActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
putExtra(getString(R.string.key_preference_id), R.xml.interface_preferences)
})
getString(R.string.pref_complication_settings) -> startActivity(Intent(this, WatchfaceConfigurationActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
putExtra(getString(R.string.key_preference_id), R.xml.complication_preferences)
})
getString(R.string.pref_others_settings) -> startActivity(Intent(this, WatchfaceConfigurationActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
putExtra(getString(R.string.key_preference_id), R.xml.others_preferences)
})
}
}
}

View file

@ -24,6 +24,11 @@
<string name="pref_vibrate_on_bolus">Vibrate on Bolus</string>
<string name="pref_units_for_actions">Units for Actions</string>
<string name="units_short">U</string>
<string name="pref_display_settings">Display</string>
<string name="pref_graph_settings">Graph</string>
<string name="pref_interface_settings">Interface</string>
<string name="pref_others_settings">Others</string>
<string name="pref_complication_settings">Complication</string>
<string name="pref_show_date">Show Date</string>
<string name="pref_show_iob">Show IOB</string>
<string name="pref_show_detailed_iob">Show detailed IOB</string>
@ -175,6 +180,7 @@
<string name="tile_no_config">No config available</string>
<string name="wear_control_not_enabled">Wear controls disabled</string>
<string name="wear_control_no_data">No data available</string>
<string name="key_preference_id" translatable="false">preference_id</string>
<string name="key_quickwizard" translatable="false">QuickWizard</string>
<string name="key_wear_control" translatable="false">wearcontrol</string>
<string name="key_units_mgdl" translatable="false">units_mgdl</string>

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ListPreference
android:defaultValue="default"
android:entries="@array/complication_tap_action"
android:entryValues="@array/complication_tap_action_values"
android:key="@string/key_complication_tap_action"
android:summary="What dialog to show after tap on complication"
android:title="@string/pref_complication_tap_action" />
<CheckBoxPreference
android:defaultValue="true"
android:key="complication_unicode"
android:summary="Use unicode special characters in complications."
android:title="@string/pref_unicode_in_complications"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" />
</PreferenceScreen>

View file

@ -110,101 +110,6 @@
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" />
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/key_highlight_basals"
android:summary="Better visible basal rate and temp basals"
android:title="@string/pref_highlight_basals"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" />
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/key_prediction_lines"
android:summary="show prediction lines"
android:title="@string/pref_prediction_lines"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" />
<ListPreference
android:defaultValue="3"
android:entries="@array/chart_timeframe"
android:entryValues="@array/chart_timeframe_values"
android:key="@string/key_chart_time_frame"
android:summary="Chart Timeframe"
android:title="@string/pref_chart_timeframe" />
<ListPreference
android:defaultValue="1"
android:entries="@array/input_design"
android:entryValues="@array/input_design_values"
android:key="@string/key_input_design"
android:summary="Input Design"
android:title="@string/pref_input_design" />
<CheckBoxPreference
android:defaultValue="true"
android:key="showWizard"
android:summary="Calculator from watch possible"
android:title="@string/pref_wizard_in_menu"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" />
<CheckBoxPreference
android:defaultValue="true"
android:key="vibrateOnBolus"
android:title="@string/pref_vibrate_on_bolus"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" />
<CheckBoxPreference
android:defaultValue="false"
android:key="primefill"
android:summary="Prime/Fill from watch possible"
android:title="@string/pref_prime_in_menu"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" />
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/key_single_target"
android:summary="Single temp-target instead of a range."
android:title="@string/pref_single_target"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" />
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/key_wizard_percentage"
android:summary="Percentage correction."
android:title="@string/pref_wizard_percentage"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" />
<ListPreference
android:defaultValue="default"
android:entries="@array/complication_tap_action"
android:entryValues="@array/complication_tap_action_values"
android:key="@string/key_complication_tap_action"
android:summary="What dialog to show after tap on complication"
android:title="@string/pref_complication_tap_action" />
<CheckBoxPreference
android:defaultValue="true"
android:key="complication_unicode"
android:summary="Use unicode special characters in complications."
android:title="@string/pref_unicode_in_complications"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" />
<info.nightscout.androidaps.interaction.utils.VersionPreference
android:defaultValue="1"
android:entries="@array/input_design"
android:entryValues="@array/input_design_values"
android:key="version_number"
android:summary="Input Design"
android:title="@string/pref_version" />
<info.nightscout.androidaps.interaction.utils.WatchfaceSettingsPreference
android:defaultValue="1"
android:entries="@array/input_design"
@ -212,12 +117,4 @@
android:key="more_settings"
android:summary="Input Design"
android:title="@string/pref_moreWatchfaceSettings" />
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/key_heart_rate_sampling"
android:summary="Enable heart rate sampling."
android:title="@string/pref_heartRateSampling"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" />
</PreferenceScreen>

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/key_highlight_basals"
android:summary="Better visible basal rate and temp basals"
android:title="@string/pref_highlight_basals"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" />
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/key_prediction_lines"
android:summary="show prediction lines"
android:title="@string/pref_prediction_lines"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" />
<ListPreference
android:defaultValue="3"
android:entries="@array/chart_timeframe"
android:entryValues="@array/chart_timeframe_values"
android:key="@string/key_chart_time_frame"
android:summary="Chart Timeframe"
android:title="@string/pref_chart_timeframe" />
</PreferenceScreen>

View file

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ListPreference
android:defaultValue="1"
android:entries="@array/input_design"
android:entryValues="@array/input_design_values"
android:key="@string/key_input_design"
android:summary="Input Design"
android:title="@string/pref_input_design" />
<CheckBoxPreference
android:defaultValue="true"
android:key="showWizard"
android:summary="Calculator from watch possible"
android:title="@string/pref_wizard_in_menu"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" />
<CheckBoxPreference
android:defaultValue="true"
android:key="vibrateOnBolus"
android:title="@string/pref_vibrate_on_bolus"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" />
<CheckBoxPreference
android:defaultValue="false"
android:key="primefill"
android:summary="Prime/Fill from watch possible"
android:title="@string/pref_prime_in_menu"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" />
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/key_single_target"
android:summary="Single temp-target instead of a range."
android:title="@string/pref_single_target"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" />
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/key_wizard_percentage"
android:summary="Percentage correction."
android:title="@string/pref_wizard_percentage"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" />
</PreferenceScreen>

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<info.nightscout.androidaps.interaction.utils.VersionPreference
android:defaultValue="1"
android:entries="@array/input_design"
android:entryValues="@array/input_design_values"
android:key="version_number"
android:summary="Input Design"
android:title="@string/pref_version" />
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/key_heart_rate_sampling"
android:summary="Enable heart rate sampling."
android:title="@string/pref_heartRateSampling"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" />
</PreferenceScreen>