|
@@ -53,7 +53,6 @@ import com.owncloud.android.R;
|
|
|
import com.owncloud.android.datamodel.FileDataStorageManager;
|
|
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
|
|
import com.owncloud.android.lib.resources.status.OCCapability;
|
|
|
-import com.owncloud.android.ui.activity.ToolbarActivity;
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
@@ -70,7 +69,6 @@ import androidx.core.content.res.ResourcesCompat;
|
|
|
import androidx.core.graphics.ColorUtils;
|
|
|
import androidx.core.graphics.drawable.DrawableCompat;
|
|
|
import androidx.core.widget.CompoundButtonCompat;
|
|
|
-import androidx.fragment.app.FragmentActivity;
|
|
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
|
|
|
|
@@ -150,8 +148,7 @@ public final class ThemeUtils {
|
|
|
}
|
|
|
|
|
|
public static int getNeutralGrey(Context context) {
|
|
|
- return darkTheme(context) ? context.getResources().getColor(R.color.fg_contrast) :
|
|
|
- Color.GRAY;
|
|
|
+ return darkTheme(context) ? context.getResources().getColor(R.color.fg_contrast) : Color.GRAY;
|
|
|
}
|
|
|
|
|
|
public static int elementColor(Context context) {
|
|
@@ -188,9 +185,10 @@ public final class ThemeUtils {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * returns the font color based on the server side theming and uses black/white as a fallback based on replaceWhite.
|
|
|
+ * returns the font color based on the server side theming and uses black/white as a fallback based on
|
|
|
+ * replaceWhite.
|
|
|
*
|
|
|
- * @param context the context
|
|
|
+ * @param context the context
|
|
|
* @param replaceWhite FLAG to return white/black if server side color isn't available
|
|
|
* @return int font color to use
|
|
|
*/
|
|
@@ -203,10 +201,6 @@ public final class ThemeUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return toolbarTextColor(context);
|
|
|
- }
|
|
|
-
|
|
|
- public static int toolbarTextColor(Context context) {
|
|
|
try {
|
|
|
return Color.parseColor(getCapability(context).getServerTextColor());
|
|
|
} catch (Exception e) {
|
|
@@ -224,17 +218,19 @@ public final class ThemeUtils {
|
|
|
|
|
|
/**
|
|
|
* Tests if light color is set
|
|
|
- * @return true if primaryColor is lighter than MAX_LIGHTNESS
|
|
|
+ *
|
|
|
+ * @param color the color
|
|
|
+ * @return true if primaryColor is lighter than MAX_LIGHTNESS
|
|
|
*/
|
|
|
- public static boolean lightTheme(Context context) {
|
|
|
- int primaryColor = primaryColor(context);
|
|
|
- float[] hsl = colorToHSL(primaryColor);
|
|
|
+ public static boolean lightTheme(int color) {
|
|
|
+ float[] hsl = colorToHSL(color);
|
|
|
|
|
|
return hsl[INDEX_LUMINATION] >= MAX_LIGHTNESS;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Tests if dark color is set
|
|
|
+ *
|
|
|
* @return true if dark theme -> e.g.use light font color, darker accent color
|
|
|
*/
|
|
|
public static boolean darkTheme(Context context) {
|
|
@@ -244,6 +240,22 @@ public final class ThemeUtils {
|
|
|
return hsl[INDEX_LUMINATION] <= 0.55;
|
|
|
}
|
|
|
|
|
|
+ public static int primaryAppbarColor(Context context) {
|
|
|
+ return ContextCompat.getColor(context, R.color.appbar);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int appBarPrimaryFontColor(Context context) {
|
|
|
+ return ContextCompat.getColor(context, R.color.fontAppbar);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int appBarSecondaryFontColor(Context context) {
|
|
|
+ return ContextCompat.getColor(context, R.color.fontSecondaryAppbar);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int actionModeColor(Context context) {
|
|
|
+ return ContextCompat.getColor(context, R.color.action_mode_background);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Set color of title to white/black depending on background color
|
|
|
*
|
|
@@ -256,7 +268,7 @@ public final class ThemeUtils {
|
|
|
actionBar.setTitle(title);
|
|
|
} else {
|
|
|
Spannable text = new SpannableString(title);
|
|
|
- text.setSpan(new ForegroundColorSpan(toolbarTextColor(context)),
|
|
|
+ text.setSpan(new ForegroundColorSpan(appBarPrimaryFontColor(context)),
|
|
|
0,
|
|
|
text.length(),
|
|
|
Spannable.SPAN_INCLUSIVE_INCLUSIVE);
|
|
@@ -281,7 +293,7 @@ public final class ThemeUtils {
|
|
|
actionBar.setSubtitle(title);
|
|
|
} else {
|
|
|
Spannable text = new SpannableString(title);
|
|
|
- text.setSpan(new ForegroundColorSpan(fontColor(context)),
|
|
|
+ text.setSpan(new ForegroundColorSpan(appBarSecondaryFontColor(context)),
|
|
|
0,
|
|
|
text.length(),
|
|
|
Spannable.SPAN_INCLUSIVE_INCLUSIVE);
|
|
@@ -302,7 +314,7 @@ public final class ThemeUtils {
|
|
|
}
|
|
|
|
|
|
Drawable backArrow = context.getResources().getDrawable(R.drawable.ic_arrow_back);
|
|
|
- supportActionBar.setHomeAsUpIndicator(ThemeUtils.tintDrawable(backArrow, ThemeUtils.fontColor(context)));
|
|
|
+ supportActionBar.setHomeAsUpIndicator(ThemeUtils.tintDrawable(backArrow, ThemeUtils.appBarPrimaryFontColor(context)));
|
|
|
}
|
|
|
|
|
|
public static Spanned getColoredTitle(String title, int color) {
|
|
@@ -340,7 +352,7 @@ public final class ThemeUtils {
|
|
|
* Adjust lightness of given color
|
|
|
*
|
|
|
* @param lightnessDelta values -1..+1
|
|
|
- * @param color original color
|
|
|
+ * @param color original color
|
|
|
* @param threshold 0..1 as maximum value, -1 to disable
|
|
|
* @return color adjusted by lightness
|
|
|
*/
|
|
@@ -448,38 +460,33 @@ public final class ThemeUtils {
|
|
|
* @param fragmentActivity fragment activity
|
|
|
* @param color the color
|
|
|
*/
|
|
|
- public static void colorStatusBar(FragmentActivity fragmentActivity, @ColorInt int color) {
|
|
|
+ public static void colorStatusBar(Activity fragmentActivity, @ColorInt int color) {
|
|
|
Window window = fragmentActivity.getWindow();
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && window != null) {
|
|
|
+ boolean isLightTheme = lightTheme(color);
|
|
|
+ if (window != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
window.setStatusBarColor(color);
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
View decor = window.getDecorView();
|
|
|
- if (lightTheme(fragmentActivity.getApplicationContext())) {
|
|
|
+ if (isLightTheme) {
|
|
|
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
|
|
} else {
|
|
|
decor.setSystemUiVisibility(0);
|
|
|
}
|
|
|
+ } else if (isLightTheme) {
|
|
|
+ window.setStatusBarColor(Color.BLACK);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Sets the color of the progressbar to {@code color} within the given toolbar.
|
|
|
- *
|
|
|
- * @param activity the toolbar activity instance
|
|
|
- * @param progressBarColor the color to be used for the toolbar's progress bar
|
|
|
- */
|
|
|
- public static void colorToolbarProgressBar(FragmentActivity activity, int progressBarColor) {
|
|
|
- if (activity instanceof ToolbarActivity) {
|
|
|
- ((ToolbarActivity) activity).setProgressBarBackgroundColor(progressBarColor);
|
|
|
- }
|
|
|
+ public static void colorStatusBar(Activity fragmentActivity) {
|
|
|
+ colorStatusBar(fragmentActivity, primaryAppbarColor(fragmentActivity));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Sets the color of the TextInputLayout to {@code color} for hint text and box stroke.
|
|
|
*
|
|
|
* @param textInputLayout the TextInputLayout instance
|
|
|
- * @param color the color to be used for the hint text and box stroke
|
|
|
+ * @param color the color to be used for the hint text and box stroke
|
|
|
*/
|
|
|
public static void colorTextInputLayout(TextInputLayout textInputLayout, int color) {
|
|
|
textInputLayout.setBoxStrokeColor(color);
|
|
@@ -496,7 +503,7 @@ public final class ThemeUtils {
|
|
|
}
|
|
|
|
|
|
public static void themeDialogActionButton(MaterialButton button) {
|
|
|
- if (button == null ) {
|
|
|
+ if (button == null) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -505,8 +512,8 @@ public final class ThemeUtils {
|
|
|
int disabledColor = ContextCompat.getColor(context, R.color.disabled_text);
|
|
|
button.setTextColor(new ColorStateList(
|
|
|
new int[][]{
|
|
|
- new int[] { android.R.attr.state_enabled}, // enabled
|
|
|
- new int[] {-android.R.attr.state_enabled}, // disabled
|
|
|
+ new int[]{android.R.attr.state_enabled}, // enabled
|
|
|
+ new int[]{-android.R.attr.state_enabled}, // disabled
|
|
|
},
|
|
|
new int[]{
|
|
|
accentColor,
|
|
@@ -516,7 +523,9 @@ public final class ThemeUtils {
|
|
|
}
|
|
|
|
|
|
public static void themeEditText(Context context, EditText editText, boolean themedBackground) {
|
|
|
- if (editText == null) { return; }
|
|
|
+ if (editText == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
int color = ContextCompat.getColor(context, R.color.text_color);
|
|
|
|
|
@@ -528,6 +537,10 @@ public final class ThemeUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ setEditTextColor(context, editText, color);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void setEditTextColor(Context context, EditText editText, int color) {
|
|
|
editText.setTextColor(color);
|
|
|
editText.setHighlightColor(context.getResources().getColor(R.color.fg_contrast));
|
|
|
setEditTextCursorColor(editText, color);
|
|
@@ -538,14 +551,14 @@ public final class ThemeUtils {
|
|
|
* Theme search view
|
|
|
*
|
|
|
* @param searchView searchView to be changed
|
|
|
- * @param themedBackground true if background is themed, e.g. on action bar; false if background is white
|
|
|
* @param context the app's context
|
|
|
*/
|
|
|
- public static void themeSearchView(SearchView searchView, boolean themedBackground, Context context) {
|
|
|
+ public static void themeSearchView(SearchView searchView, Context context) {
|
|
|
// hacky as no default way is provided
|
|
|
- int fontColor = ThemeUtils.fontColor(context, !darkTheme(context));
|
|
|
+ int fontColor = appBarPrimaryFontColor(context);
|
|
|
SearchView.SearchAutoComplete editText = searchView.findViewById(R.id.search_src_text);
|
|
|
- themeEditText(context, editText, themedBackground);
|
|
|
+ setEditTextColor(context, editText, fontColor);
|
|
|
+ editText.setHintTextColor(appBarSecondaryFontColor(context));
|
|
|
|
|
|
ImageView closeButton = searchView.findViewById(androidx.appcompat.R.id.search_close_btn);
|
|
|
closeButton.setColorFilter(fontColor);
|
|
@@ -560,14 +573,14 @@ public final class ThemeUtils {
|
|
|
|
|
|
public static void tintCheckbox(AppCompatCheckBox checkBox, int color) {
|
|
|
CompoundButtonCompat.setButtonTintList(checkBox, new ColorStateList(
|
|
|
- new int[][]{
|
|
|
- new int[]{-android.R.attr.state_checked},
|
|
|
- new int[]{android.R.attr.state_checked},
|
|
|
- },
|
|
|
- new int[]{
|
|
|
- Color.GRAY,
|
|
|
- color
|
|
|
- }
|
|
|
+ new int[][]{
|
|
|
+ new int[]{-android.R.attr.state_checked},
|
|
|
+ new int[]{android.R.attr.state_checked},
|
|
|
+ },
|
|
|
+ new int[]{
|
|
|
+ Color.GRAY,
|
|
|
+ color
|
|
|
+ }
|
|
|
));
|
|
|
}
|
|
|
|
|
@@ -584,13 +597,13 @@ public final class ThemeUtils {
|
|
|
|
|
|
// setting the thumb color
|
|
|
DrawableCompat.setTintList(switchView.getThumbDrawable(), new ColorStateList(
|
|
|
- new int[][]{new int[]{android.R.attr.state_checked}, new int[]{}},
|
|
|
- new int[]{color, Color.WHITE}));
|
|
|
+ new int[][]{new int[]{android.R.attr.state_checked}, new int[]{}},
|
|
|
+ new int[]{color, Color.WHITE}));
|
|
|
|
|
|
// setting the track color
|
|
|
DrawableCompat.setTintList(switchView.getTrackDrawable(), new ColorStateList(
|
|
|
- new int[][]{new int[]{android.R.attr.state_checked}, new int[]{}},
|
|
|
- new int[]{trackColor, MainApp.getAppContext().getResources().getColor(R.color.switch_track_color_unchecked)}));
|
|
|
+ new int[][]{new int[]{android.R.attr.state_checked}, new int[]{}},
|
|
|
+ new int[]{trackColor, MainApp.getAppContext().getResources().getColor(R.color.switch_track_color_unchecked)}));
|
|
|
}
|
|
|
|
|
|
public static Drawable tintDrawable(@DrawableRes int id, int color) {
|
|
@@ -616,10 +629,10 @@ public final class ThemeUtils {
|
|
|
}
|
|
|
|
|
|
public static void tintFloatingActionButton(FloatingActionButton button, @DrawableRes int
|
|
|
- drawable, Context context) {
|
|
|
+ drawable, Context context) {
|
|
|
button.setBackgroundTintList(ColorStateList.valueOf(ThemeUtils.primaryColor(context)));
|
|
|
button.setRippleColor(ThemeUtils.primaryDarkColor(context));
|
|
|
- button.setImageDrawable(ThemeUtils.tintDrawable(drawable, ThemeUtils.toolbarTextColor(context)));
|
|
|
+ button.setImageDrawable(ThemeUtils.tintDrawable(drawable, ThemeUtils.fontColor(context)));
|
|
|
}
|
|
|
|
|
|
private static OCCapability getCapability(Context context) {
|
|
@@ -645,20 +658,21 @@ public final class ThemeUtils {
|
|
|
}
|
|
|
|
|
|
public static Drawable setIconColor(Drawable drawable) {
|
|
|
- int color = Color.BLACK;
|
|
|
+ int color;
|
|
|
if (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES) {
|
|
|
color = Color.WHITE;
|
|
|
+ } else {
|
|
|
+ color = Color.BLACK;
|
|
|
}
|
|
|
return tintDrawable(drawable, color);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Lifted from SO.
|
|
|
- * FindBugs surpressed because of lack of public API to alter the cursor color.
|
|
|
+ * Lifted from SO. FindBugs surpressed because of lack of public API to alter the cursor color.
|
|
|
*
|
|
|
- * @param editText TextView to be styled
|
|
|
- * @param color The desired cursor colour
|
|
|
- * @see <a href="https://stackoverflow.com/a/52564925">StackOverflow url</a>
|
|
|
+ * @param editText TextView to be styled
|
|
|
+ * @param color The desired cursor colour
|
|
|
+ * @see <a href="https://stackoverflow.com/a/52564925">StackOverflow url</a>
|
|
|
*/
|
|
|
@SuppressFBWarnings
|
|
|
public static void setEditTextCursorColor(EditText editText, int color) {
|
|
@@ -709,15 +723,11 @@ public final class ThemeUtils {
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * Set the color of the handles when you select text in a
|
|
|
- * {@link android.widget.EditText} or other view that extends {@link TextView}.
|
|
|
- * FindBugs surpressed because of lack of public API to alter the {@link TextView} handles color.
|
|
|
- *
|
|
|
- * @param view
|
|
|
- * The {@link TextView} or a {@link View} that extends {@link TextView}.
|
|
|
- * @param color
|
|
|
- * The color to set for the text handles
|
|
|
+ * Set the color of the handles when you select text in a {@link android.widget.EditText} or other view that extends
|
|
|
+ * {@link TextView}. FindBugs surpressed because of lack of public API to alter the {@link TextView} handles color.
|
|
|
*
|
|
|
+ * @param view The {@link TextView} or a {@link View} that extends {@link TextView}.
|
|
|
+ * @param color The color to set for the text handles
|
|
|
* @see <a href="https://gist.github.com/jaredrummler/2317620559d10ac39b8218a1152ec9d4">External reference</a>
|
|
|
*/
|
|
|
@SuppressFBWarnings
|