Add custom DeviceListPreference
This commit is contained in:
parent
8b94e77ca7
commit
9b10461725
8 changed files with 122 additions and 52 deletions
|
@ -1,11 +1,12 @@
|
||||||
package dev.nuculabs.nucuhub;
|
package dev.nuculabs.nucuhub;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.preference.PreferenceFragmentCompat;
|
import dev.nuculabs.nucuhub.ui.settings.SettingsFragment;
|
||||||
|
|
||||||
public class SettingsActivity extends AppCompatActivity {
|
public class SettingsActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
@ -28,8 +29,16 @@ public class SettingsActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
// TODO: Add settings menu
|
||||||
|
// getMenuInflater().inflate(R.menu.settings_actions, menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
// back button click
|
||||||
if (item.getItemId()==android.R.id.home) {
|
if (item.getItemId()==android.R.id.home) {
|
||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
|
@ -37,11 +46,4 @@ public class SettingsActivity extends AppCompatActivity {
|
||||||
|
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SettingsFragment extends PreferenceFragmentCompat {
|
|
||||||
@Override
|
|
||||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
|
||||||
setPreferencesFromResource(R.xml.root_preferences, rootKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package dev.nuculabs.nucuhub.ui.settings;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import androidx.preference.ListPreference;
|
||||||
|
|
||||||
|
public class DeviceListPreference extends ListPreference {
|
||||||
|
public DeviceListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||||
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceListPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceListPreference(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceListPreference(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
// TODO: Create custom dialog, override onClick.
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package dev.nuculabs.nucuhub.ui.settings;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import androidx.preference.ListPreference;
|
||||||
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
|
import dev.nuculabs.nucuhub.R;
|
||||||
|
|
||||||
|
public class SettingsFragment extends PreferenceFragmentCompat {
|
||||||
|
@Override
|
||||||
|
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||||
|
// To get preferences use this in main activity:
|
||||||
|
// SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
|
setPreferencesFromResource(R.xml.root_preferences, rootKey);
|
||||||
|
ListPreference devicesList = findPreference("device_list");
|
||||||
|
|
||||||
|
// TODO: Override dialog in order to add a search devices button.
|
||||||
|
//
|
||||||
|
// set default value
|
||||||
|
}
|
||||||
|
}
|
|
@ -211,7 +211,7 @@
|
||||||
tools:text="100.11"
|
tools:text="100.11"
|
||||||
/>
|
/>
|
||||||
<TextView
|
<TextView
|
||||||
android:text="@string/gasvoc_sensor_unit_descriptio"
|
android:text="@string/gasvoc_sensor_unit_description"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" android:id="@+id/textView5"
|
android:layout_height="wrap_content" android:id="@+id/textView5"
|
||||||
android:gravity="center"/>
|
android:gravity="center"/>
|
||||||
|
|
|
@ -7,25 +7,24 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".MainActivity">
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:theme="@style/AppTheme.AppBarOverlay">
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.Toolbar
|
|
||||||
android:id="@+id/toolbar"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="?attr/actionBarSize"
|
|
||||||
android:background="?attr/colorPrimary"
|
|
||||||
app:popupTheme="@style/AppTheme.PopupOverlay"/>
|
|
||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:theme="@style/AppTheme.AppBarOverlay">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.Toolbar
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
android:background="?attr/colorPrimary"
|
||||||
|
app:popupTheme="@style/AppTheme.PopupOverlay" tools:visibility="visible"/>
|
||||||
|
|
||||||
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/settings"
|
android:id="@+id/settings"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
<resources>
|
<resources>
|
||||||
|
<string-array name="device_list_array">
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<!-- Reply Preference -->
|
<!-- Reply Preference -->
|
||||||
<string-array name="reply_entries">
|
<string-array name="reply_entries">
|
||||||
<item>Reply</item>
|
<item>Reply</item>
|
||||||
|
|
|
@ -1,17 +1,22 @@
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">NucuHub</string>
|
<string name="app_name">NucuHub</string>
|
||||||
<string name="environment_status_description">Temperature sensor status</string>
|
|
||||||
<string name="navigation_drawer_open">Open navigation drawer</string>
|
<string name="navigation_drawer_open">Open navigation drawer</string>
|
||||||
<string name="navigation_drawer_close">Close navigation drawer</string>
|
<string name="navigation_drawer_close">Close navigation drawer</string>
|
||||||
<string name="nav_header_title">NucuHub</string>
|
<string name="nav_header_title">NucuHub</string>
|
||||||
<string name="nav_header_subtitle">denis@nuculabs.dev</string>
|
<string name="nav_header_subtitle">denis@nuculabs.dev</string>
|
||||||
<string name="nav_header_desc">Navigation header</string>
|
<string name="nav_header_desc">Navigation header</string>
|
||||||
<string name="action_settings">Settings</string>
|
|
||||||
<string name="menu_gallery">Gallery</string>
|
<string name="menu_gallery">Gallery</string>
|
||||||
<string name="menu_slideshow">Slideshow</string>
|
<string name="menu_slideshow">Slideshow</string>
|
||||||
|
|
||||||
|
<!-- Main Menu-->
|
||||||
|
<string name="action_settings">Settings</string>
|
||||||
|
|
||||||
|
<!-- Activity Titles-->
|
||||||
|
<string name="title_activity_settings">Settings Activity</string>
|
||||||
|
|
||||||
<!-- Environment Sensor Data -->
|
<!-- Environment Sensor Data -->
|
||||||
<string name="menu_environment_sensor">Environment Sensor</string>
|
<string name="menu_environment_sensor">Environment Sensor</string>
|
||||||
|
<string name="environment_status_description">Temperature sensor status</string>
|
||||||
<string name="humidity_icon_desc">humidity image</string>
|
<string name="humidity_icon_desc">humidity image</string>
|
||||||
<string name="temperature_icon_desc">temperature icon</string>
|
<string name="temperature_icon_desc">temperature icon</string>
|
||||||
<string name="barometer_icon_desc">barometer icon</string>
|
<string name="barometer_icon_desc">barometer icon</string>
|
||||||
|
@ -19,12 +24,16 @@
|
||||||
<string name="humidity_sensor_unit">Rh%</string>
|
<string name="humidity_sensor_unit">Rh%</string>
|
||||||
<string name="temp_sensor_unit">Celsius</string>
|
<string name="temp_sensor_unit">Celsius</string>
|
||||||
<string name="pressure_unit_desc">hPa</string>
|
<string name="pressure_unit_desc">hPa</string>
|
||||||
<string name="gasvoc_sensor_unit_descriptio">VOC kΩ</string>
|
<string name="gasvoc_sensor_unit_description">VOC kΩ</string>
|
||||||
<string name="title_activity_settings">SettingsActivity</string>
|
|
||||||
|
|
||||||
<!-- Preference Titles -->
|
<!-- Preference Titles -->
|
||||||
<string name="messages_header">Messages</string>
|
<string name="messages_header">Messages</string>
|
||||||
<string name="sync_header">Sync</string>
|
<string name="sync_header">Sync</string>
|
||||||
|
<string name="devices_header">Devices</string>
|
||||||
|
|
||||||
|
<!-- Device Preferences -->
|
||||||
|
<string name="device_selection_title">Your current device</string>
|
||||||
|
|
||||||
|
|
||||||
<!-- Messages Preferences -->
|
<!-- Messages Preferences -->
|
||||||
<string name="signature_title">Your signature</string>
|
<string name="signature_title">Your signature</string>
|
||||||
|
|
|
@ -1,37 +1,49 @@
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
<PreferenceCategory
|
<!-- <PreferenceCategory-->
|
||||||
app:title="@string/messages_header">
|
<!-- app:title="@string/messages_header">-->
|
||||||
|
|
||||||
<EditTextPreference
|
<!-- <EditTextPreference-->
|
||||||
app:key="signature"
|
<!-- app:key="signature"-->
|
||||||
app:title="@string/signature_title"
|
<!-- app:title="@string/signature_title"-->
|
||||||
app:useSimpleSummaryProvider="true"/>
|
<!-- app:useSimpleSummaryProvider="true"/>-->
|
||||||
|
|
||||||
<ListPreference
|
<!-- <ListPreference-->
|
||||||
app:key="reply"
|
<!-- app:key="reply"-->
|
||||||
app:title="@string/reply_title"
|
<!-- app:title="@string/reply_title"-->
|
||||||
app:entries="@array/reply_entries"
|
<!-- app:entries="@array/reply_entries"-->
|
||||||
app:entryValues="@array/reply_values"
|
<!-- app:entryValues="@array/reply_values"-->
|
||||||
app:defaultValue="reply"
|
<!-- app:defaultValue="reply"-->
|
||||||
app:useSimpleSummaryProvider="true"/>
|
<!-- app:useSimpleSummaryProvider="true"/>-->
|
||||||
|
|
||||||
</PreferenceCategory>
|
<!-- </PreferenceCategory>-->
|
||||||
|
|
||||||
|
<!-- <PreferenceCategory-->
|
||||||
|
<!-- app:title="@string/sync_header">-->
|
||||||
|
|
||||||
|
<!-- <SwitchPreferenceCompat-->
|
||||||
|
<!-- app:key="sync"-->
|
||||||
|
<!-- app:title="@string/sync_title"/>-->
|
||||||
|
|
||||||
|
<!-- <SwitchPreferenceCompat-->
|
||||||
|
<!-- app:key="attachment"-->
|
||||||
|
<!-- app:title="@string/attachment_title"-->
|
||||||
|
<!-- app:summaryOn="@string/attachment_summary_on"-->
|
||||||
|
<!-- app:summaryOff="@string/attachment_summary_off"-->
|
||||||
|
<!-- app:dependency="sync"/>-->
|
||||||
|
|
||||||
|
<!-- </PreferenceCategory>-->
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
app:title="@string/sync_header">
|
app:title="@string/devices_header">
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
<dev.nuculabs.nucuhub.ui.settings.DeviceListPreference
|
||||||
app:key="sync"
|
app:key="device_list"
|
||||||
app:title="@string/sync_title"/>
|
app:title="@string/device_selection_title"
|
||||||
|
app:entries="@array/device_list_array"
|
||||||
<SwitchPreferenceCompat
|
app:entryValues="@array/device_list_array"
|
||||||
app:key="attachment"
|
app:useSimpleSummaryProvider="true"/>
|
||||||
app:title="@string/attachment_title"
|
|
||||||
app:summaryOn="@string/attachment_summary_on"
|
|
||||||
app:summaryOff="@string/attachment_summary_off"
|
|
||||||
app:dependency="sync"/>
|
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue