From 1dbde30c46af406f2228bf4c83b09ac93d7cc2de Mon Sep 17 00:00:00 2001 From: Stefan Niedermann Date: Fri, 7 Apr 2023 13:36:13 +0200 Subject: [PATCH 1/6] feat(theming): Align theming closer to files app Follow-Up to https://github.com/nextcloud/notes-android/pull/1680 Signed-off-by: Stefan Niedermann --- .../notes/FormattingHelpActivity.java | 9 +++---- .../owncloud/notes/about/AboutActivity.java | 5 ++-- .../notes/branding/NotesViewThemeUtils.java | 27 +++++++++++++++++-- .../owncloud/notes/edit/EditNoteActivity.java | 3 ++- .../owncloud/notes/main/MainActivity.java | 3 ++- .../ManageAccountsActivity.java | 3 ++- .../preferences/PreferencesActivity.java | 3 ++- app/src/main/res/layout/activity_about.xml | 9 ++----- app/src/main/res/layout/activity_edit.xml | 20 +++++--------- .../main/res/layout/activity_exception.xml | 7 ++--- .../res/layout/activity_formatting_help.xml | 21 +++++---------- .../res/layout/activity_manage_accounts.xml | 21 +++++---------- .../res/layout/activity_notes_list_view.xml | 12 ++++----- .../main/res/layout/activity_preferences.xml | 23 +++++----------- app/src/main/res/values/styles.xml | 1 + 15 files changed, 76 insertions(+), 91 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/FormattingHelpActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/FormattingHelpActivity.java index 6fe0047e3..036d24e93 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/FormattingHelpActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/FormattingHelpActivity.java @@ -1,6 +1,7 @@ package it.niedermann.owncloud.notes; -import android.content.SharedPreferences; +import static it.niedermann.owncloud.notes.shared.util.NoteUtil.getFontSizeFromPreferences; + import android.graphics.Typeface; import android.os.Bundle; import android.text.method.LinkMovementMethod; @@ -10,13 +11,10 @@ import androidx.annotation.Nullable; import androidx.preference.PreferenceManager; -import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.branding.BrandedActivity; import it.niedermann.owncloud.notes.branding.BrandingUtil; import it.niedermann.owncloud.notes.databinding.ActivityFormattingHelpBinding; -import static it.niedermann.owncloud.notes.shared.util.NoteUtil.getFontSizeFromPreferences; - public class FormattingHelpActivity extends BrandedActivity { private ActivityFormattingHelpBinding binding; @@ -225,6 +223,7 @@ private String buildFormattingHelp() { @Override public void applyBrand(int color) { final var util = BrandingUtil.of(color, this); - util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent); + util.platform.themeStatusBar(this); + util.material.themeToolbar(binding.toolbar); } } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/about/AboutActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/about/AboutActivity.java index 3d871f6a2..1a31d88ca 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/about/AboutActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/about/AboutActivity.java @@ -52,8 +52,9 @@ protected void onCreate(Bundle savedInstanceState) { @Override public void applyBrand(int color) { final var util = BrandingUtil.of(color, this); - util.material.themeTabLayout(binding.tabs); - util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent); + util.platform.themeStatusBar(this); + util.material.themeToolbar(binding.toolbar); + util.material.themeTabLayoutOnSurface(binding.tabs); } private static class TabsStateAdapter extends FragmentStateAdapter { diff --git a/app/src/main/java/it/niedermann/owncloud/notes/branding/NotesViewThemeUtils.java b/app/src/main/java/it/niedermann/owncloud/notes/branding/NotesViewThemeUtils.java index 5c659afd9..c26b0bf1d 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/branding/NotesViewThemeUtils.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/branding/NotesViewThemeUtils.java @@ -4,6 +4,7 @@ import static com.nextcloud.android.common.ui.util.PlatformThemeUtil.isDarkMode; import android.content.Context; +import android.content.res.ColorStateList; import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.drawable.LayerDrawable; @@ -21,9 +22,9 @@ import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.MaterialToolbar; +import com.google.android.material.card.MaterialCardView; import com.nextcloud.android.common.ui.theme.MaterialSchemes; import com.nextcloud.android.common.ui.theme.ViewThemeUtilsBase; -import com.nextcloud.android.common.ui.theme.utils.ColorRole; import com.nextcloud.android.common.ui.theme.utils.MaterialViewThemeUtils; import it.niedermann.android.util.ColorUtil; @@ -31,7 +32,6 @@ import it.niedermann.owncloud.notes.main.navigation.NavigationItem; import it.niedermann.owncloud.notes.shared.util.NotesColorUtil; import kotlin.Pair; -import scheme.Scheme; public class NotesViewThemeUtils extends ViewThemeUtilsBase { @@ -148,4 +148,27 @@ public int getTextHighlightBackgroundColor(@NonNull Context context, @ColorInt i } } } + + /** + * @deprecated Should be replaced with {@link com.google.android.material.search.SearchBar} component. + */ + @Deprecated + public void themeSearchCardView(@NonNull MaterialCardView searchBarWrapper) { + withScheme(searchBarWrapper, scheme -> { + searchBarWrapper.setBackgroundTintList(ColorStateList.valueOf(scheme.getSurface())); + return searchBarWrapper; + }); + } + + /** + * @deprecated Should be replaced with {@link com.google.android.material.search.SearchBar} or {@link MaterialViewThemeUtils#themeToolbar(MaterialToolbar)} + */ + @Deprecated + public void themeSearchToolbar(@NonNull MaterialToolbar toolbar) { + withScheme(toolbar, scheme -> { + toolbar.setNavigationIconTint(scheme.getOnSurface()); + toolbar.setTitleTextColor(scheme.getOnSurface()); + return toolbar; + }); + } } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/EditNoteActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/edit/EditNoteActivity.java index d5306d8ac..71b43db5b 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/edit/EditNoteActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/EditNoteActivity.java @@ -420,6 +420,7 @@ public void onAccountPicked(@NonNull Account account) { @Override public void applyBrand(int color) { final var util = BrandingUtil.of(color, this); - util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent); + util.platform.themeStatusBar(this); + util.material.themeToolbar(binding.toolbar); } } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java index 479529f30..bcba3df2d 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java @@ -598,7 +598,8 @@ public void applyBrand(int color) { util.androidx.themeSwipeRefreshLayout(activityBinding.swiperefreshlayout); util.platform.colorCircularProgressBar(activityBinding.progressCircular, ColorRole.PRIMARY); util.platform.colorNavigationView(binding.navigationView); - util.notes.applyBrandToPrimaryToolbar(activityBinding.appBar, activityBinding.searchToolbar, colorAccent); + util.notes.themeSearchCardView(binding.activityNotesListView.searchBarWrapper); + util.notes.themeSearchToolbar(binding.activityNotesListView.searchToolbar); binding.headerView.setBackgroundColor(color); @ColorInt final int headerTextColor = ColorUtil.INSTANCE.getForegroundColorForBackgroundColor(color); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java index 294a530fc..18da71bae 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java @@ -210,6 +210,7 @@ public void onFailure(@NonNull Call call, @NonNull Throwable t) { @Override public void applyBrand(int color) { final var util = BrandingUtil.of(color, this); - util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent); + util.platform.themeStatusBar(this); + util.material.themeToolbar(binding.toolbar); } } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesActivity.java index fb3cb8705..8741f76bf 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesActivity.java @@ -34,6 +34,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { @Override public void applyBrand(int color) { final var util = BrandingUtil.of(color, this); - util.notes.applyBrandToPrimaryToolbar(binding.appBar, binding.toolbar, colorAccent); + util.platform.themeStatusBar(this); + util.material.themeToolbar(binding.toolbar); } } diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml index 89c2aaa66..b560bf171 100644 --- a/app/src/main/res/layout/activity_about.xml +++ b/app/src/main/res/layout/activity_about.xml @@ -4,7 +4,6 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="?attr/colorPrimary" android:orientation="vertical"> - @@ -26,7 +23,6 @@ android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="?attr/colorPrimary" app:tabMode="fixed" /> @@ -34,7 +30,6 @@ android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="?attr/colorPrimary" android:paddingHorizontal="@dimen/spacer_1x" /> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_edit.xml b/app/src/main/res/layout/activity_edit.xml index 8948c0768..4d4b375c9 100644 --- a/app/src/main/res/layout/activity_edit.xml +++ b/app/src/main/res/layout/activity_edit.xml @@ -6,21 +6,13 @@ android:layout_height="match_parent" android:orientation="vertical"> - - - - + android:layout_height="wrap_content" + app:navigationIcon="@drawable/ic_arrow_back_grey600_24dp" + app:titleMarginStart="0dp" + tools:title="Edit Sample note" /> - diff --git a/app/src/main/res/layout/activity_formatting_help.xml b/app/src/main/res/layout/activity_formatting_help.xml index 99dbb182e..ca8450136 100644 --- a/app/src/main/res/layout/activity_formatting_help.xml +++ b/app/src/main/res/layout/activity_formatting_help.xml @@ -4,24 +4,15 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="@color/primary" android:orientation="vertical"> - - - - + android:layout_height="wrap_content" + app:navigationIcon="@drawable/ic_arrow_back_grey600_24dp" + app:title="@string/action_formatting_help" + app:titleMarginStart="0dp" /> - - - - + android:layout_height="wrap_content" + app:navigationIcon="@drawable/ic_arrow_back_grey600_24dp" + app:title="@string/manage_accounts" + app:titleMarginStart="0dp" /> - - + - @@ -97,7 +97,7 @@ android:id="@+id/search_view" android:layout_width="match_parent" android:layout_height="wrap_content" /> - + diff --git a/app/src/main/res/layout/activity_preferences.xml b/app/src/main/res/layout/activity_preferences.xml index ec4cce0c9..203d7cff1 100644 --- a/app/src/main/res/layout/activity_preferences.xml +++ b/app/src/main/res/layout/activity_preferences.xml @@ -5,26 +5,17 @@ android:layout_height="match_parent" android:orientation="vertical"> - - - - + android:layout_height="wrap_content" + app:navigationIcon="@drawable/ic_arrow_back_grey600_24dp" + app:title="@string/action_settings" + app:titleMarginStart="0dp" /> + android:layout_height="match_parent" /> \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 661bcfd2f..4d8c787af 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -13,6 +13,7 @@ ?android:colorAccent @color/defaultTextHighlightBackground true + @color/bg_default ?attr/colorPrimary From 8eb9890c8a94ae52ac573afc9764d542e53aa163 Mon Sep 17 00:00:00 2001 From: Stefan Niedermann Date: Fri, 7 Apr 2023 14:01:36 +0200 Subject: [PATCH 2/6] feat(theming): Align theming closer to files app Follow-Up to https://github.com/nextcloud/notes-android/pull/1680 Signed-off-by: Stefan Niedermann --- .../notes/branding/NotesViewThemeUtils.java | 21 +++++++++++++++++++ .../owncloud/notes/main/MainActivity.java | 3 ++- app/src/main/res/layout/activity_about.xml | 1 - app/src/main/res/layout/activity_edit.xml | 1 - .../main/res/layout/activity_exception.xml | 1 - .../res/layout/activity_formatting_help.xml | 3 +-- .../res/layout/activity_manage_accounts.xml | 3 +-- .../res/layout/activity_notes_list_view.xml | 5 ++--- .../main/res/layout/activity_preferences.xml | 3 +-- app/src/main/res/values/styles.xml | 5 +++++ 10 files changed, 33 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/branding/NotesViewThemeUtils.java b/app/src/main/java/it/niedermann/owncloud/notes/branding/NotesViewThemeUtils.java index c26b0bf1d..f1862e4f0 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/branding/NotesViewThemeUtils.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/branding/NotesViewThemeUtils.java @@ -16,6 +16,7 @@ import androidx.annotation.ColorInt; import androidx.annotation.IdRes; import androidx.annotation.NonNull; +import androidx.appcompat.widget.SearchView; import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; import androidx.core.graphics.drawable.DrawableCompat; @@ -171,4 +172,24 @@ public void themeSearchToolbar(@NonNull MaterialToolbar toolbar) { return toolbar; }); } + + /** + * @deprecated Should be replaced with {@link com.google.android.material.search.SearchView} + * @see com.nextcloud.android.common.ui.theme.utils.AndroidXViewThemeUtils#themeToolbarSearchView(SearchView) + */ + @Deprecated + public void themeToolbarSearchView(@NonNull SearchView searchView) { + withScheme(searchView, scheme -> { + // hacky as no default way is provided + final var editText = (SearchView.SearchAutoComplete) searchView.findViewById(androidx.appcompat.R.id.search_src_text); + final var closeButton = (ImageView) searchView.findViewById(androidx.appcompat.R.id.search_close_btn); + final var searchButton = (ImageView) searchView.findViewById(androidx.appcompat.R.id.search_button); + editText.setHintTextColor(scheme.getOnSurfaceVariant()); + editText.setHighlightColor(scheme.getInverseOnSurface()); + editText.setTextColor(scheme.getOnSurface()); + closeButton.setColorFilter(scheme.getOnSurface()); + searchButton.setColorFilter(scheme.getOnSurface()); + return searchView; + }); + } } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java index bcba3df2d..43e482a75 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java @@ -594,12 +594,13 @@ public void onIconClick(NavigationItem item) { @Override public void applyBrand(int color) { final var util = BrandingUtil.of(color, this); - util.material.themeFAB(activityBinding.fabCreate); util.androidx.themeSwipeRefreshLayout(activityBinding.swiperefreshlayout); util.platform.colorCircularProgressBar(activityBinding.progressCircular, ColorRole.PRIMARY); util.platform.colorNavigationView(binding.navigationView); + util.material.themeFAB(activityBinding.fabCreate); util.notes.themeSearchCardView(binding.activityNotesListView.searchBarWrapper); util.notes.themeSearchToolbar(binding.activityNotesListView.searchToolbar); + util.notes.themeToolbarSearchView(binding.activityNotesListView.searchView); binding.headerView.setBackgroundColor(color); @ColorInt final int headerTextColor = ColorUtil.INSTANCE.getForegroundColorForBackgroundColor(color); diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml index b560bf171..bf04d6f5f 100644 --- a/app/src/main/res/layout/activity_about.xml +++ b/app/src/main/res/layout/activity_about.xml @@ -16,7 +16,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content" app:navigationIcon="@drawable/ic_arrow_back_grey600_24dp" - app:titleMarginStart="0dp" tools:title="@string/simple_about" /> + app:title="@string/action_formatting_help" /> + app:title="@string/manage_accounts" /> + app:contentInsetStartWithNavigation="0dp"> + app:title="@string/action_settings" /> @dimen/spacer_activity_sides + + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 6dc7248f0..90dae3ed0 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -6,7 +6,7 @@ ?android:colorPrimary @color/accent - ?attr/colorPrimary + @color/bg_default @bool/isDayMode ?attr/colorAccent ?attr/colorAccent @@ -14,7 +14,7 @@ @color/defaultTextHighlightBackground true @color/bg_default - ?attr/colorPrimary + @color/bg_default From 5cab30bcf19aa97dd9df8ca8096e1e6874e05f1b Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Tue, 11 Apr 2023 10:53:01 +0200 Subject: [PATCH 6/6] reformat for 120 characters line length Signed-off-by: Andy Scherzinger --- .../notes/branding/NotesViewThemeUtils.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/branding/NotesViewThemeUtils.java b/app/src/main/java/it/niedermann/owncloud/notes/branding/NotesViewThemeUtils.java index f1862e4f0..d3970b338 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/branding/NotesViewThemeUtils.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/branding/NotesViewThemeUtils.java @@ -88,7 +88,9 @@ public void colorNavigationViewItemText(@NonNull TextView view) { * @deprecated should be replaced by {@link MaterialViewThemeUtils#themeToolbar(MaterialToolbar)}. */ @Deprecated(forRemoval = true) - public void applyBrandToPrimaryToolbar(@NonNull AppBarLayout appBarLayout, @NonNull Toolbar toolbar, @ColorInt int color) { + public void applyBrandToPrimaryToolbar(@NonNull AppBarLayout appBarLayout, + @NonNull Toolbar toolbar, + @ColorInt int color) { // FIXME Workaround for https://github.com/nextcloud/notes-android/issues/889 appBarLayout.setBackgroundColor(ContextCompat.getColor(appBarLayout.getContext(), R.color.primary)); @@ -118,7 +120,10 @@ public void colorLayerDrawable(@NonNull LayerDrawable check, @IdRes int areaToCo } @ColorInt - public int getTextHighlightBackgroundColor(@NonNull Context context, @ColorInt int mainColor, @ColorInt int colorPrimary, @ColorInt int colorAccent) { + public int getTextHighlightBackgroundColor(@NonNull Context context, + @ColorInt int mainColor, + @ColorInt int colorPrimary, + @ColorInt int colorAccent) { if (isDarkMode(context)) { // Dark background if (ColorUtil.INSTANCE.isColorDark(mainColor)) { // Dark brand color if (NotesColorUtil.contrastRatioIsSufficient(mainColor, colorPrimary)) { // But also dark text @@ -162,7 +167,8 @@ public void themeSearchCardView(@NonNull MaterialCardView searchBarWrapper) { } /** - * @deprecated Should be replaced with {@link com.google.android.material.search.SearchBar} or {@link MaterialViewThemeUtils#themeToolbar(MaterialToolbar)} + * @deprecated Should be replaced with {@link com.google.android.material.search.SearchBar} or + * {@link MaterialViewThemeUtils#themeToolbar(MaterialToolbar)} */ @Deprecated public void themeSearchToolbar(@NonNull MaterialToolbar toolbar) { @@ -181,7 +187,8 @@ public void themeSearchToolbar(@NonNull MaterialToolbar toolbar) { public void themeToolbarSearchView(@NonNull SearchView searchView) { withScheme(searchView, scheme -> { // hacky as no default way is provided - final var editText = (SearchView.SearchAutoComplete) searchView.findViewById(androidx.appcompat.R.id.search_src_text); + final var editText = (SearchView.SearchAutoComplete) searchView + .findViewById(androidx.appcompat.R.id.search_src_text); final var closeButton = (ImageView) searchView.findViewById(androidx.appcompat.R.id.search_close_btn); final var searchButton = (ImageView) searchView.findViewById(androidx.appcompat.R.id.search_button); editText.setHintTextColor(scheme.getOnSurfaceVariant());