|
@@ -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;
|
|
@@ -118,7 +119,15 @@ public final class ThemeUtils {
|
|
|
OCCapability capability = getCapability(account, context);
|
|
|
|
|
|
try {
|
|
|
- return adjustLightness(-0.2f, Color.parseColor(capability.getServerColor()), -1f);
|
|
|
+ return calculateDarkColor(Color.parseColor(capability.getServerColor()), context);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return context.getResources().getColor(R.color.primary_dark);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int calculateDarkColor(int color, Context context){
|
|
|
+ try {
|
|
|
+ return adjustLightness(-0.2f, color, -1f);
|
|
|
} catch (Exception e) {
|
|
|
return context.getResources().getColor(R.color.primary_dark);
|
|
|
}
|
|
@@ -133,6 +142,24 @@ public final class ThemeUtils {
|
|
|
}
|
|
|
|
|
|
public static int primaryColor(Account account, boolean replaceEdgeColors, Context context) {
|
|
|
+ return primaryColor(account, replaceEdgeColors, false, context);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * return the primary color defined in the server-side theming respecting Android dark/light theming and edge case
|
|
|
+ * scenarios including drawer menu.
|
|
|
+ *
|
|
|
+ * @param account the Nextcloud user
|
|
|
+ * @param replaceEdgeColors flag if edge case color scenarios should be handled
|
|
|
+ * @param replaceEdgeColorsByInvertedColor flag in edge case handling should be done via color inversion
|
|
|
+ * (black/white)
|
|
|
+ * @param context the context (needed to load client-side colors)
|
|
|
+ * @return the color
|
|
|
+ */
|
|
|
+ public static int primaryColor(Account account,
|
|
|
+ boolean replaceEdgeColors,
|
|
|
+ boolean replaceEdgeColorsByInvertedColor,
|
|
|
+ Context context) {
|
|
|
if (context == null) {
|
|
|
return Color.GRAY;
|
|
|
}
|
|
@@ -142,13 +169,21 @@ public final class ThemeUtils {
|
|
|
if (replaceEdgeColors) {
|
|
|
if (isDarkModeActive(context)) {
|
|
|
if (Color.BLACK == color) {
|
|
|
- return getNeutralGrey(context);
|
|
|
+ if (replaceEdgeColorsByInvertedColor) {
|
|
|
+ return Color.WHITE;
|
|
|
+ } else {
|
|
|
+ return getNeutralGrey(context);
|
|
|
+ }
|
|
|
} else {
|
|
|
return color;
|
|
|
}
|
|
|
} else {
|
|
|
if (Color.WHITE == color) {
|
|
|
- return getNeutralGrey(context);
|
|
|
+ if (replaceEdgeColorsByInvertedColor) {
|
|
|
+ return Color.BLACK;
|
|
|
+ } else {
|
|
|
+ return getNeutralGrey(context);
|
|
|
+ }
|
|
|
} else {
|
|
|
return color;
|
|
|
}
|
|
@@ -165,51 +200,6 @@ public final class ThemeUtils {
|
|
|
return darkTheme(context) ? context.getResources().getColor(R.color.fg_contrast) : Color.GRAY;
|
|
|
}
|
|
|
|
|
|
- public static int elementColor(Context context) {
|
|
|
- return elementColor(null, context, false);
|
|
|
- }
|
|
|
-
|
|
|
- @NextcloudServer(max = 12)
|
|
|
- public static int elementColor(Account account, Context context, boolean replaceEdgeColors) {
|
|
|
- OCCapability capability = getCapability(account, context);
|
|
|
-
|
|
|
- try {
|
|
|
- return Color.parseColor(capability.getServerElementColor());
|
|
|
- } catch (Exception e) {
|
|
|
- int color;
|
|
|
-
|
|
|
- try {
|
|
|
- color = Color.parseColor(capability.getServerColor());
|
|
|
- } catch (Exception e1) {
|
|
|
- color = context.getResources().getColor(R.color.primary);
|
|
|
- }
|
|
|
-
|
|
|
- if (replaceEdgeColors) {
|
|
|
- if (isDarkModeActive(context)) {
|
|
|
- if (Color.BLACK == color) {
|
|
|
- return getNeutralGrey(context);
|
|
|
- } else {
|
|
|
- return color;
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (Color.WHITE == color) {
|
|
|
- return getNeutralGrey(context);
|
|
|
- } else {
|
|
|
- return color;
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- float[] hsl = colorToHSL(color);
|
|
|
-
|
|
|
- if (hsl[INDEX_LUMINATION] > LUMINATION_THRESHOLD) {
|
|
|
- return context.getResources().getColor(R.color.element_fallback_color);
|
|
|
- } else {
|
|
|
- return color;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
public static boolean themingEnabled(Context context) {
|
|
|
return getCapability(context).getServerColor() != null && !getCapability(context).getServerColor().isEmpty();
|
|
|
}
|
|
@@ -409,6 +399,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.
|
|
|
*
|
|
@@ -420,10 +425,10 @@ public final class ThemeUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static void colorEditText(EditText editText, int elementColor) {
|
|
|
+ public static void colorEditText(EditText editText, int color) {
|
|
|
if (editText != null) {
|
|
|
- editText.setTextColor(elementColor);
|
|
|
- editText.getBackground().setColorFilter(elementColor, PorterDuff.Mode.SRC_ATOP);
|
|
|
+ editText.setTextColor(color);
|
|
|
+ editText.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -680,14 +685,31 @@ public final class ThemeUtils {
|
|
|
return String.format("#%06X", 0xFFFFFF & color);
|
|
|
}
|
|
|
|
|
|
- public static void tintFloatingActionButton(FloatingActionButton button, Context context) {
|
|
|
- button.setBackgroundTintList(ColorStateList.valueOf(ThemeUtils.primaryColor(context)));
|
|
|
- button.setRippleColor(ThemeUtils.primaryDarkColor(context));
|
|
|
+ public static void colorFloatingActionButton(FloatingActionButton button, @DrawableRes int drawable,
|
|
|
+ Context context) {
|
|
|
+ int primaryColor = ThemeUtils.primaryColor(null, true, false, context);
|
|
|
+ colorFloatingActionButton(button, context, primaryColor);
|
|
|
+
|
|
|
+ if (Color.BLACK == primaryColor) {
|
|
|
+ button.setImageDrawable(ThemeUtils.tintDrawable(drawable, Color.WHITE));
|
|
|
+ } else if (Color.WHITE == primaryColor) {
|
|
|
+ button.setImageDrawable(ThemeUtils.tintDrawable(drawable, Color.BLACK));
|
|
|
+ } else {
|
|
|
+ button.setImageDrawable(ThemeUtils.tintDrawable(drawable, ThemeUtils.fontColor(context, false)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void colorFloatingActionButton(FloatingActionButton button, Context context) {
|
|
|
+ colorFloatingActionButton(button, context, ThemeUtils.primaryColor(null, true, false, context));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void colorFloatingActionButton(FloatingActionButton button, Context context, int primaryColor) {
|
|
|
+ colorFloatingActionButton(button, primaryColor, calculateDarkColor(primaryColor, context));
|
|
|
}
|
|
|
|
|
|
- public static void drawableFloatingActionButton(FloatingActionButton button, @DrawableRes int
|
|
|
- drawable, Context context) {
|
|
|
- button.setImageDrawable(ThemeUtils.tintDrawable(drawable, ThemeUtils.fontColor(context)));
|
|
|
+ public static void colorFloatingActionButton(FloatingActionButton button, int backgroundColor, int rippleColor) {
|
|
|
+ button.setBackgroundTintList(ColorStateList.valueOf(backgroundColor));
|
|
|
+ button.setRippleColor(rippleColor);
|
|
|
}
|
|
|
|
|
|
private static OCCapability getCapability(Context context) {
|