Material 3: Navbar highlighting, TextInputLayouts in dialogs, Buttons

Signed-off-by: Stefan Niedermann <info@niedermann.it>
This commit is contained in:
Stefan Niedermann 2022-11-04 11:46:54 +01:00
parent 20bb948130
commit 35a378b845
11 changed files with 72 additions and 13 deletions

View file

@ -28,6 +28,9 @@ import it.niedermann.owncloud.notes.NotesApplication;
import it.niedermann.owncloud.notes.R;
import static it.niedermann.owncloud.notes.shared.util.NotesColorUtil.contrastRatioIsSufficient;
import static it.niedermann.owncloud.notes.shared.util.NotesColorUtil.contrastRatioIsSufficientBigAreas;
import com.google.android.material.textfield.TextInputLayout;
public class BrandingUtil {
@ -146,6 +149,17 @@ public class BrandingUtil {
));
}
public static void applyBrandToEditTextInputLayout(@ColorInt int color, @NonNull TextInputLayout til) {
final int colorPrimary = ContextCompat.getColor(til.getContext(), R.color.primary);
final int colorAccent = ContextCompat.getColor(til.getContext(), R.color.accent);
final var colorDanger = ColorStateList.valueOf(ContextCompat.getColor(til.getContext(), R.color.danger));
til.setBoxStrokeColor(contrastRatioIsSufficientBigAreas(color, colorPrimary) ? color : colorAccent);
til.setHintTextColor(ColorStateList.valueOf(contrastRatioIsSufficient(color, colorPrimary) ? color : colorAccent));
til.setErrorTextColor(colorDanger);
til.setBoxStrokeErrorColor(colorDanger);
til.setErrorIconTintList(colorDanger);
}
public static void tintMenuIcon(@NonNull MenuItem menuItem, @ColorInt int color) {
var drawable = menuItem.getIcon();
if (drawable != null) {

View file

@ -49,7 +49,7 @@ public class CategoryDialogFragment extends BrandedDialogFragment {
@Override
public void applyBrand(int mainColor, int textColor) {
BrandingUtil.applyBrandToEditText(mainColor, textColor, binding.search);
BrandingUtil.applyBrandToEditTextInputLayout(mainColor, binding.inputWrapper);
}
/**

View file

@ -1,5 +1,7 @@
package it.niedermann.owncloud.notes.edit.title;
import static it.niedermann.owncloud.notes.branding.BrandingUtil.applyBrandToEditTextInputLayout;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
@ -15,9 +17,10 @@ import androidx.fragment.app.DialogFragment;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.branding.BrandedDialogFragment;
import it.niedermann.owncloud.notes.databinding.DialogEditTitleBinding;
public class EditTitleDialogFragment extends DialogFragment {
public class EditTitleDialogFragment extends BrandedDialogFragment {
private static final String TAG = EditTitleDialogFragment.class.getSimpleName();
static final String PARAM_OLD_TITLE = "old_title";
@ -83,6 +86,11 @@ public class EditTitleDialogFragment extends DialogFragment {
return fragment;
}
@Override
public void applyBrand(int mainColor, int textColor) {
applyBrandToEditTextInputLayout(mainColor, binding.inputWrapper);
}
/**
* Interface that must be implemented by the calling Activity.
*/

View file

@ -28,6 +28,17 @@ public final class NotesColorUtil {
return ret;
}
public static boolean contrastRatioIsSufficientBigAreas(@ColorInt int colorOne, @ColorInt int colorTwo) {
final var key = new ColorPair(colorOne, colorTwo);
var ret = CONTRAST_RATIO_SUFFICIENT_CACHE.get(key);
if (ret == null) {
ret = ColorUtil.INSTANCE.getContrastRatio(colorOne, colorTwo) > 1.47d;
CONTRAST_RATIO_SUFFICIENT_CACHE.put(key, ret);
return ret;
}
return ret;
}
private static class ColorPair extends Pair<Integer, Integer> {
private ColorPair(@Nullable Integer first, @Nullable Integer second) {

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true" android:color="@color/accent"/>
<item android:state_hovered="true" android:color="@color/accent"/>
<item android:state_focused="true" android:color="@color/accent"/>
<item android:color="@color/grey600" />
</selector>

View file

@ -6,7 +6,6 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/accountLayout"
android:layout_width="match_parent"
@ -28,7 +27,6 @@
android:scaleType="center"
app:srcCompat="@drawable/ic_account_circle_grey_24dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -83,7 +81,6 @@
tools:itemCount="3"
tools:listitem="@layout/item_account_choose" />
<LinearLayout
android:id="@+id/add_account"
android:layout_width="match_parent"
@ -111,7 +108,6 @@
android:text="@string/add_account"
android:textAppearance="@style/TextAppearance.AppCompat.Widget.TextView.SpinnerItem"
android:textColor="?android:textColorPrimary" />
</LinearLayout>
<LinearLayout

View file

@ -8,13 +8,27 @@
android:orientation="vertical"
android:padding="?attr/dialogPreferredPadding">
<EditText
android:id="@+id/search"
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/inputWrapper"
style="@style/textInputLayoutStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/spacer_1x"
android:hint="@string/change_category_title"
android:importantForAutofill="no"
android:inputType="text" />
android:labelFor="@id/search">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:importantForAutofill="no"
android:inputType="text">
<requestFocus />
</com.google.android.material.textfield.TextInputEditText>
</com.google.android.material.textfield.TextInputLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"

View file

@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.textfield.TextInputLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/inputWrapper"
style="@style/textInputLayoutStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
android:padding="@dimen/spacer_2x">
<EditText
android:id="@+id/title"

View file

@ -25,7 +25,7 @@
<com.google.android.material.button.MaterialButton
android:id="@+id/about_app_license_button"
style="@style/Widget.MaterialComponents.Button"
style="@style/Widget.Material3.Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/about_app_license_button"

View file

@ -4,6 +4,7 @@
<color name="primary">#ffffff</color>
<color name="accent">#121212</color>
<color name="danger">#d40000</color>
<color name="defaultBrand">#0082C9</color>
@ -21,7 +22,8 @@
<color name="fg_secondary">#999999</color>
<color name="fg_contrast">#ffffff</color>
<color name="icon_color_default">#757575</color>
<color name="grey600">#757575</color>
<color name="icon_color_default">@color/grey600</color>
<color name="category_background">@color/bg_normal</color>
<color name="category_border">@color/defaultBrand</color>

View file

@ -40,6 +40,11 @@
<item name="tabIconTint">?attr/colorAccent</item>
</style>
<style name="textInputLayoutStyle" parent="Widget.Material3.TextInputLayout.OutlinedBox.Dense">
<item name="boxStrokeColor">@color/text_input_layout_color</item>
<item name="hintTextColor">@color/text_input_layout_color</item>
</style>
<style name="MaterialAlertDialogTheme" parent="ThemeOverlay.Material3.MaterialAlertDialog">
<item name="buttonBarPositiveButtonStyle">@style/buttonStyle</item>
<item name="buttonBarNegativeButtonStyle">@style/buttonStyle</item>