Parcourir la source

Introduce light/dark theme / black/white primary-color-aware primary-button theming

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Andy Scherzinger il y a 4 ans
Parent
commit
7005cdef2e

+ 1 - 2
src/main/java/com/owncloud/android/ui/activity/CommunityActivity.java

@@ -92,8 +92,7 @@ public class CommunityActivity extends FileActivity {
                                 getString(R.string.contributing_link)))));
 
         MaterialButton reportButton = findViewById(R.id.community_testing_report);
-        reportButton.setBackgroundColor(ThemeUtils.primaryColor(this,true));
-        reportButton.setTextColor(ThemeUtils.fontColor(this, false));
+        ThemeUtils.colorPrimaryButton(reportButton, this);
         reportButton.setOnClickListener(v -> DisplayUtils.startLinkIntent(this, R.string.report_issue_link));
     }
 

+ 16 - 0
src/main/java/com/owncloud/android/utils/ThemeUtils.java

@@ -38,6 +38,7 @@ import android.text.style.ForegroundColorSpan;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.Window;
+import android.widget.Button;
 import android.widget.EditText;
 import android.widget.ImageButton;
 import android.widget.ImageView;
@@ -435,6 +436,21 @@ public final class ThemeUtils {
         return hsl;
     }
 
+    public static void colorPrimaryButton(Button button, Context context) {
+        int primaryColor = ThemeUtils.primaryColor(null, true, false, context);
+        int fontColor = ThemeUtils.fontColor(context, false);
+
+        button.setBackgroundColor(primaryColor);
+
+        if (Color.BLACK == primaryColor) {
+            button.setTextColor(Color.WHITE);
+        } else if (Color.WHITE == primaryColor) {
+            button.setTextColor(Color.BLACK);
+        } else {
+            button.setTextColor(fontColor);
+        }
+    }
+
     /**
      * sets the tinting of the given ImageButton's icon to color_accent.
      *