mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 17:46:37 +03:00
Attempt to deal with server set themes of either all white or all black.
Signed-off-by: Daniel Bailey <daniel.bailey@grappleIT.co.uk>
This commit is contained in:
parent
7df8f8ba45
commit
3dea959d5e
7 changed files with 59 additions and 19 deletions
|
@ -100,20 +100,20 @@ public class PassCodeActivity extends AppCompatActivity {
|
|||
|
||||
mPassCodeEditTexts[0] = findViewById(R.id.txt0);
|
||||
ThemeUtils.colorEditText(mPassCodeEditTexts[0], elementColor);
|
||||
ThemeUtils.themeEditText(mPassCodeEditTexts[0], ThemeUtils.primaryColor(MainApp.getAppContext()));
|
||||
ThemeUtils.themeEditText(MainApp.getAppContext(), mPassCodeEditTexts[0], false);
|
||||
mPassCodeEditTexts[0].requestFocus();
|
||||
|
||||
mPassCodeEditTexts[1] = findViewById(R.id.txt1);
|
||||
ThemeUtils.colorEditText(mPassCodeEditTexts[1], elementColor);
|
||||
ThemeUtils.themeEditText(mPassCodeEditTexts[1], ThemeUtils.primaryColor(MainApp.getAppContext()));
|
||||
ThemeUtils.themeEditText(MainApp.getAppContext(), mPassCodeEditTexts[1], false);
|
||||
|
||||
mPassCodeEditTexts[2] = findViewById(R.id.txt2);
|
||||
ThemeUtils.colorEditText(mPassCodeEditTexts[2], elementColor);
|
||||
ThemeUtils.themeEditText(mPassCodeEditTexts[2], ThemeUtils.primaryColor(MainApp.getAppContext()));
|
||||
ThemeUtils.themeEditText(MainApp.getAppContext(), mPassCodeEditTexts[2], false);
|
||||
|
||||
mPassCodeEditTexts[3] = findViewById(R.id.txt3);
|
||||
ThemeUtils.colorEditText(mPassCodeEditTexts[3], elementColor);
|
||||
ThemeUtils.themeEditText(mPassCodeEditTexts[3], ThemeUtils.primaryColor(MainApp.getAppContext()));
|
||||
ThemeUtils.themeEditText(MainApp.getAppContext(), mPassCodeEditTexts[3], false);
|
||||
|
||||
Window window = getWindow();
|
||||
if (window != null) {
|
||||
|
|
|
@ -102,7 +102,7 @@ public class RenameFileDialogFragment
|
|||
String currentName = mTargetFile.getFileName();
|
||||
EditText inputText = v.findViewById(R.id.user_input);
|
||||
inputText.setText(currentName);
|
||||
ThemeUtils.themeEditText(inputText, ThemeUtils.primaryColor(getContext()));
|
||||
ThemeUtils.themeEditText(getContext(), inputText, false);
|
||||
int selectionStart = 0;
|
||||
int extensionStart = mTargetFile.isFolder() ? -1 : currentName.lastIndexOf('.');
|
||||
int selectionEnd = extensionStart >= 0 ? extensionStart : currentName.length();
|
||||
|
|
|
@ -183,7 +183,7 @@ public class ExtendedListFragment extends Fragment
|
|||
searchView = (SearchView) MenuItemCompat.getActionView(item);
|
||||
searchView.setOnQueryTextListener(this);
|
||||
searchView.setOnCloseListener(this);
|
||||
themeSearchView(searchView, ThemeUtils.primaryAccentColor(getContext()));
|
||||
themeSearchView(getContext(), searchView, true);
|
||||
|
||||
final Handler handler = new Handler();
|
||||
|
||||
|
|
|
@ -197,7 +197,7 @@ public class FileDetailActivitiesFragment extends Fragment implements ActivityLi
|
|||
PorterDuff.Mode.SRC_ATOP
|
||||
);
|
||||
// ThemeUtils.colorEditText(commentInput, ThemeUtils.primaryAccentColor(getContext()));
|
||||
ThemeUtils.themeEditText(commentInput, ThemeUtils.primaryColor(getContext()));
|
||||
ThemeUtils.themeEditText(getContext(), commentInput, false);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
|
|
@ -201,7 +201,7 @@ public class FileDetailSharingFragment extends Fragment implements UserListAdapt
|
|||
FileDetailSharingFragmentHelper.setupSearchView(
|
||||
(SearchManager) fileDisplayActivity.getSystemService(Context.SEARCH_SERVICE), searchView,
|
||||
fileDisplayActivity.getComponentName());
|
||||
ThemeUtils.themeSearchView(searchView, ThemeUtils.primaryColor(getContext()));
|
||||
ThemeUtils.themeSearchView(getContext(), searchView, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -91,6 +91,22 @@ public final class ThemeUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static int primaryContrastColor(Context context) {
|
||||
OCCapability capability = getCapability(context);
|
||||
|
||||
try {
|
||||
float adjust = 0;
|
||||
// if (darkTheme(context)) {
|
||||
// adjust = +0.1f;
|
||||
// } else {
|
||||
// adjust = -0.1f;
|
||||
// }
|
||||
return adjustLightness(adjust, Color.parseColor(capability.getServerColor()), 0.75f);
|
||||
} catch (Exception e) {
|
||||
return context.getResources().getColor(R.color.color_accent);
|
||||
}
|
||||
}
|
||||
|
||||
public static int primaryDarkColor(Context context) {
|
||||
return primaryDarkColor(null, context);
|
||||
}
|
||||
|
@ -345,7 +361,7 @@ public final class ThemeUtils {
|
|||
*/
|
||||
public static void colorSnackbar(Context context, Snackbar snackbar) {
|
||||
// Changing action button text color
|
||||
snackbar.setActionTextColor(ContextCompat.getColor(context, R.color.white));
|
||||
snackbar.setActionTextColor(ContextCompat.getColor(context, R.color.fg_inverse));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -393,18 +409,34 @@ public final class ThemeUtils {
|
|||
));
|
||||
}
|
||||
|
||||
public static void themeEditText(EditText editText, int color) {
|
||||
editText.setHighlightColor(color);
|
||||
public static void themeEditText(Context context, EditText editText, boolean themedBackground) {
|
||||
if (editText == null) { return; }
|
||||
|
||||
int color = primaryColor(context);
|
||||
// Don't theme the view when it is already on a theme'd background
|
||||
if (themedBackground) {
|
||||
if (darkTheme(context)) {
|
||||
color = ContextCompat.getColor(context, R.color.themed_fg);
|
||||
} else {
|
||||
color = ContextCompat.getColor(context, R.color.themed_fg_inverse);
|
||||
}
|
||||
} else {
|
||||
float[] colorHSL = colorToHSL(color);
|
||||
if (colorHSL[2] >= 0.92) {
|
||||
color = ContextCompat.getColor(context, R.color.themed_fg_inverse);
|
||||
}
|
||||
}
|
||||
|
||||
editText.setHighlightColor(context.getResources().getColor(R.color.fg_contrast));
|
||||
setTextViewCursorColor(editText, color);
|
||||
setTextViewHandlesColor(editText, color);
|
||||
setTextViewHandlesColor(context, editText, color);
|
||||
}
|
||||
|
||||
public static void themeSearchView(SearchView searchView, int color) {
|
||||
SearchView.SearchAutoComplete editText = searchView.findViewById(R.id.search_src_text);
|
||||
public static void themeSearchView(Context context, SearchView searchView, boolean themedBackground) {
|
||||
if (searchView == null) { return; }
|
||||
|
||||
editText.setHighlightColor(color);
|
||||
ThemeUtils.setTextViewCursorColor(editText, color);
|
||||
ThemeUtils.setTextViewHandlesColor(editText, color);
|
||||
SearchView.SearchAutoComplete editText = searchView.findViewById(R.id.search_src_text);
|
||||
themeEditText(context, editText, themedBackground);
|
||||
}
|
||||
|
||||
public static void tintCheckbox(AppCompatCheckBox checkBox, int color) {
|
||||
|
@ -535,7 +567,7 @@ public final class ThemeUtils {
|
|||
*
|
||||
* @see https://gist.github.com/jaredrummler/2317620559d10ac39b8218a1152ec9d4
|
||||
*/
|
||||
public static void setTextViewHandlesColor(TextView view, int color) {
|
||||
public static void setTextViewHandlesColor(Context context, TextView view, int color) {
|
||||
try {
|
||||
Field editorField = TextView.class.getDeclaredField("mEditor");
|
||||
if (!editorField.isAccessible()) {
|
||||
|
@ -562,7 +594,8 @@ public final class ThemeUtils {
|
|||
resField.setAccessible(true);
|
||||
}
|
||||
int resId = resField.getInt(view);
|
||||
handleDrawable = view.getResources().getDrawable(resId);
|
||||
// handleDrawable = view.getResources().getDrawable(resId);
|
||||
handleDrawable = ContextCompat.getDrawable(context, resId);
|
||||
}
|
||||
|
||||
if (handleDrawable != null) {
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
<color name="textColor">@color/black</color>
|
||||
<color name="disabled_text">#ff888888</color>
|
||||
<color name="list_divider_background">#eee</color>
|
||||
<color name="fg_default">#000000</color>
|
||||
<color name="fg_contrast">#656565</color>
|
||||
<color name="fg_inverse">#FFFFFF</color>
|
||||
<color name="filelist_icon_backgorund">#DDDDDD</color>
|
||||
<color name="dark_background_text_color">#EEEEEE</color>
|
||||
<color name="transparent">#00000000</color>
|
||||
|
@ -43,4 +46,8 @@
|
|||
<!-- level colors for info notifications/visualisations -->
|
||||
<color name="infolevel_warning">#e9322d</color>
|
||||
|
||||
<!-- Excluded from future app dark theme -->
|
||||
<color name="themed_fg">#FFFFFF</color>
|
||||
<color name="themed_fg_inverse">#000000</color>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue