mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-22 09:58:08 +00:00
Use M3 theme, switch to Material Dialogs
- Add Monet dynamic colors on the app's `onCreate()` - Set parent in styles.xml to `Theme.Material3.DayNight.NoActionBar` - Use `MaterialAlertDialogBuilder` - In the About and About KDE fragments, it uses the M3 elevated style instead of outlines - In `edit_text_alert_dialog_view.xml`, it uses the default theme style instead of specifying the one from MaterialComponents - Added a todo in the settings fragment: Preference dialogs don't yet use the M3 style. It complements https://invent.kde.org/network/kdeconnect-android/-/merge_requests/273, though the way that merge request accomplishes color theming is the one from before the onCreate dynamics color method
This commit is contained in:
parent
fd3c6f07da
commit
6defead2ce
@ -42,9 +42,7 @@
|
|||||||
android:layout_marginRight="12dp"
|
android:layout_marginRight="12dp"
|
||||||
android:layout_marginEnd="12dp"
|
android:layout_marginEnd="12dp"
|
||||||
android:layout_marginBottom="12dp"
|
android:layout_marginBottom="12dp"
|
||||||
card_view:cardBackgroundColor="@color/card_stroke_color"
|
|
||||||
card_view:cardCornerRadius="12dp"
|
card_view:cardCornerRadius="12dp"
|
||||||
card_view:cardElevation="5dp"
|
|
||||||
card_view:cardUseCompatPadding="true">
|
card_view:cardUseCompatPadding="true">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@ -65,9 +63,7 @@
|
|||||||
android:layout_marginRight="12dp"
|
android:layout_marginRight="12dp"
|
||||||
android:layout_marginEnd="12dp"
|
android:layout_marginEnd="12dp"
|
||||||
android:layout_marginBottom="12dp"
|
android:layout_marginBottom="12dp"
|
||||||
card_view:cardBackgroundColor="@color/card_stroke_color"
|
|
||||||
card_view:cardCornerRadius="12dp"
|
card_view:cardCornerRadius="12dp"
|
||||||
card_view:cardElevation="5dp"
|
|
||||||
card_view:cardUseCompatPadding="true">
|
card_view:cardUseCompatPadding="true">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@ -88,9 +84,7 @@
|
|||||||
android:layout_marginRight="12dp"
|
android:layout_marginRight="12dp"
|
||||||
android:layout_marginEnd="12dp"
|
android:layout_marginEnd="12dp"
|
||||||
android:layout_marginBottom="12dp"
|
android:layout_marginBottom="12dp"
|
||||||
card_view:cardBackgroundColor="@color/card_stroke_color"
|
|
||||||
card_view:cardCornerRadius="12dp"
|
card_view:cardCornerRadius="12dp"
|
||||||
card_view:cardElevation="5dp"
|
|
||||||
card_view:cardUseCompatPadding="true">
|
card_view:cardUseCompatPadding="true">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@ -111,9 +105,7 @@
|
|||||||
android:layout_marginRight="12dp"
|
android:layout_marginRight="12dp"
|
||||||
android:layout_marginEnd="12dp"
|
android:layout_marginEnd="12dp"
|
||||||
android:layout_marginBottom="12dp"
|
android:layout_marginBottom="12dp"
|
||||||
card_view:cardBackgroundColor="@color/card_stroke_color"
|
|
||||||
card_view:cardCornerRadius="12dp"
|
card_view:cardCornerRadius="12dp"
|
||||||
card_view:cardElevation="5dp"
|
|
||||||
card_view:cardUseCompatPadding="true">
|
card_view:cardUseCompatPadding="true">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
@ -15,8 +15,7 @@
|
|||||||
android:id="@+id/textInputLayout"
|
android:id="@+id/textInputLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:hintEnabled="false"
|
app:hintEnabled="false">
|
||||||
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox">
|
|
||||||
|
|
||||||
<!-- inputType="text" is needed, without it lines and maxLines is ignored https://issuetracker.google.com/issues/37118772 -->
|
<!-- inputType="text" is needed, without it lines and maxLines is ignored https://issuetracker.google.com/issues/37118772 -->
|
||||||
<com.google.android.material.textfield.TextInputEditText
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
@ -25,8 +24,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:lines="1"
|
android:lines="1"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:inputType="text"
|
android:inputType="text" />
|
||||||
style="@style/Widget.MaterialComponents.TextInputEditText.FilledBox"/>
|
|
||||||
|
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
@ -19,9 +19,6 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="12dp"
|
android:layout_margin="12dp"
|
||||||
card_view:cardBackgroundColor="@color/card_stroke_color"
|
|
||||||
card_view:cardCornerRadius="12dp"
|
|
||||||
card_view:cardElevation="5dp"
|
|
||||||
card_view:cardUseCompatPadding="true">
|
card_view:cardUseCompatPadding="true">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
@ -151,9 +148,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="12dp"
|
android:layout_margin="12dp"
|
||||||
card_view:cardBackgroundColor="@color/card_stroke_color"
|
style="@style/Widget.Material3.CardView.Elevated"
|
||||||
card_view:cardCornerRadius="12dp"
|
|
||||||
card_view:cardElevation="5dp"
|
|
||||||
card_view:cardUseCompatPadding="true">
|
card_view:cardUseCompatPadding="true">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<!-- NoActionBar because we use a Toolbar widget as ActionBar -->
|
<!-- NoActionBar because we use a Toolbar widget as ActionBar -->
|
||||||
<style name="KdeConnectThemeBase" parent="Theme.MaterialComponents.DayNight">
|
<style name="KdeConnectThemeBase" parent="Theme.Material3.DayNight.NoActionBar">
|
||||||
<!-- The main color attributes -->
|
<!-- The main color attributes -->
|
||||||
<!-- The three colors used by system widgets, according to https://chris.banes.me/2014/10/17/appcompat-v21/ -->
|
<!-- The three colors used by system widgets, according to https://chris.banes.me/2014/10/17/appcompat-v21/ -->
|
||||||
<item name="colorPrimary">@color/primary</item>
|
<item name="colorPrimary">@color/primary</item>
|
||||||
@ -26,6 +26,7 @@
|
|||||||
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
|
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
|
||||||
<item name="popupTheme">@style/ThemeOverlay.AppCompat.DayNight</item>
|
<item name="popupTheme">@style/ThemeOverlay.AppCompat.DayNight</item>
|
||||||
|
|
||||||
|
<item name="materialCardViewStyle">@style/Widget.Material3.CardView.Elevated</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="KdeConnectTheme" parent="KdeConnectThemeBase" />
|
<style name="KdeConnectTheme" parent="KdeConnectThemeBase" />
|
||||||
|
@ -18,6 +18,8 @@ import androidx.annotation.StringRes;
|
|||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
|
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||||
|
|
||||||
public class AlertDialogFragment extends DialogFragment implements DialogInterface.OnClickListener {
|
public class AlertDialogFragment extends DialogFragment implements DialogInterface.OnClickListener {
|
||||||
private static final String KEY_TITLE_RES_ID = "TitleResId";
|
private static final String KEY_TITLE_RES_ID = "TitleResId";
|
||||||
private static final String KEY_TITLE = "Title";
|
private static final String KEY_TITLE = "Title";
|
||||||
@ -62,7 +64,7 @@ public class AlertDialogFragment extends DialogFragment implements DialogInterfa
|
|||||||
@SuppressLint("ResourceType")
|
@SuppressLint("ResourceType")
|
||||||
String titleString = titleResId > 0 ? getString(titleResId) : title;
|
String titleString = titleResId > 0 ? getString(titleResId) : title;
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext())
|
AlertDialog.Builder builder = new MaterialAlertDialogBuilder(requireContext())
|
||||||
.setTitle(titleString)
|
.setTitle(titleString)
|
||||||
.setPositiveButton(positiveButtonResId, this);
|
.setPositiveButton(positiveButtonResId, this);
|
||||||
if (negativeButtonResId != 0) {
|
if (negativeButtonResId != 0) {
|
||||||
|
@ -47,6 +47,9 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
|||||||
Context context = getPreferenceManager().getContext();
|
Context context = getPreferenceManager().getContext();
|
||||||
PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(context);
|
PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(context);
|
||||||
|
|
||||||
|
// TODO: preference alert dialogs don't use the material alert dialogs yet
|
||||||
|
// see https://github.com/material-components/material-components-android/issues/2732
|
||||||
|
|
||||||
// Rename device
|
// Rename device
|
||||||
renameDevice = new EditTextPreference(context);
|
renameDevice = new EditTextPreference(context);
|
||||||
renameDevice.setKey(DeviceHelper.KEY_DEVICE_NAME_PREFERENCE);
|
renameDevice.setKey(DeviceHelper.KEY_DEVICE_NAME_PREFERENCE);
|
||||||
|
@ -7,6 +7,8 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.appcompat.app.AppCompatDelegate;
|
import androidx.appcompat.app.AppCompatDelegate;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
|
import com.google.android.material.color.DynamicColors;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilities for working with android {@link android.content.res.Resources.Theme Themes}.
|
* Utilities for working with android {@link android.content.res.Resources.Theme Themes}.
|
||||||
@ -44,6 +46,7 @@ public class ThemeUtil {
|
|||||||
public static void setUserPreferredTheme(Activity activity) {
|
public static void setUserPreferredTheme(Activity activity) {
|
||||||
String appTheme = PreferenceManager.getDefaultSharedPreferences(activity)
|
String appTheme = PreferenceManager.getDefaultSharedPreferences(activity)
|
||||||
.getString("theme_pref", DEFAULT_MODE);
|
.getString("theme_pref", DEFAULT_MODE);
|
||||||
|
DynamicColors.applyIfAvailable(activity);
|
||||||
applyTheme(appTheme);
|
applyTheme(appTheme);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user