Merge pull request #5658 from dan0xii/5657-dark-mode

Dark Mode Improvements
This commit is contained in:
Tobias Kaminsky 2020-03-19 19:06:31 +01:00 committed by GitHub
commit bc2790ef10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 40 additions and 32 deletions

View file

@ -32,11 +32,13 @@ import android.widget.Switch;
import com.owncloud.android.R;
import com.owncloud.android.utils.ThemeUtils;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.graphics.drawable.DrawableCompat;
/**
* Themeable switch preference
* TODO Migrate to androidx
*/
public class ThemeableSwitchPreference extends SwitchPreference {
@ -72,12 +74,16 @@ public class ThemeableSwitchPreference extends SwitchPreference {
Switch switchView = (Switch) child;
if(thumbColorStateList == null && trackColorStateList == null) {
int color = ThemeUtils.primaryAccentColor(getContext());
int trackColor = Color.argb(77, Color.red(color), Color.green(color), Color.blue(color));
int thumbColor = ThemeUtils.primaryAccentColor(getContext());
if (ThemeUtils.darkTheme(getContext()) &&
AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES) {
thumbColor = Color.WHITE;
}
int trackColor = Color.argb(77, Color.red(thumbColor), Color.green(thumbColor), Color.blue(thumbColor));
int trackColorUnchecked = getContext().getResources().getColor(R.color.switch_track_color_unchecked);
thumbColorStateList = new ColorStateList(
new int[][]{new int[]{android.R.attr.state_checked}, new int[]{}},
new int[]{color, Color.WHITE});
new int[]{thumbColor, getContext().getResources().getColor(R.color.switch_thumb_color_unchecked)});
trackColorStateList = new ColorStateList(
new int[][]{new int[]{android.R.attr.state_checked},
new int[]{}},

View file

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

View file

@ -751,7 +751,8 @@ public class SettingsActivity extends ThemedPreferenceActivity
actionBar.setBackgroundDrawable(new ColorDrawable(ThemeUtils.primaryColor(this)));
Drawable backArrow = getResources().getDrawable(R.drawable.ic_arrow_back);
actionBar.setHomeAsUpIndicator(ThemeUtils.tintDrawable(backArrow, ThemeUtils.fontColor(this, true)));
actionBar.setHomeAsUpIndicator(ThemeUtils.tintDrawable(backArrow, ThemeUtils.fontColor(this,
!ThemeUtils.darkTheme(this))));
}
Window window = getWindow();

View file

@ -65,7 +65,7 @@ public abstract class ToolbarActivity extends BaseActivity {
*/
protected void setupToolbar(boolean useBackgroundImage) {
int primaryColor = ThemeUtils.primaryColor(this, false);
int fontColor = ThemeUtils.fontColor(this, true);
int fontColor = ThemeUtils.fontColor(this, !ThemeUtils.darkTheme(getApplicationContext()));
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

View file

@ -179,6 +179,7 @@ public class UploadFilesActivity extends FileActivity implements
mUploadBtn = findViewById(R.id.upload_files_btn_upload);
mUploadBtn.setBackgroundTintMode(PorterDuff.Mode.SRC_ATOP);
mUploadBtn.setBackgroundTintList(ColorStateList.valueOf(ThemeUtils.primaryColor(this, true)));
mUploadBtn.setTextColor(ThemeUtils.fontColor(this, false));
mUploadBtn.setOnClickListener(this);
int localBehaviour = preferences.getUploaderBehaviour();
@ -273,6 +274,7 @@ public class UploadFilesActivity extends FileActivity implements
ImageView searchClose = mSearchView.findViewById(androidx.appcompat.R.id.search_close_btn);
searchClose.setColorFilter(fontColor);
ThemeUtils.tintDrawable(menu.findItem(R.id.action_choose_storage_path).getIcon(), fontColor);
return super.onCreateOptionsMenu(menu);
}

View file

@ -94,7 +94,12 @@ public final class ThemeUtils {
try {
float adjust;
if (darkTheme(context)) {
adjust = +0.1f;
if (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES) {
adjust = +0.5f;
// return adjustLightness(adjust, Color.parseColor(capability.getServerColor()), -1);
} else {
adjust = +0.1f;
}
} else {
adjust = -0.1f;
}
@ -134,7 +139,7 @@ public final class ThemeUtils {
try {
int color = Color.parseColor(getCapability(account, context).getServerColor());
if (replaceWhite && Color.WHITE == color) {
return Color.GRAY;
return getNeutralGrey(context);
} else {
return color;
}
@ -143,6 +148,11 @@ public final class ThemeUtils {
}
}
public static int getNeutralGrey(Context context) {
return darkTheme(context) ? context.getResources().getColor(R.color.fg_contrast) :
Color.GRAY;
}
public static int elementColor(Context context) {
return elementColor(null, context);
}
@ -238,7 +248,7 @@ public final class ThemeUtils {
actionBar.setTitle(title);
} else {
Spannable text = new SpannableString(title);
text.setSpan(new ForegroundColorSpan(fontColor(context, true)),
text.setSpan(new ForegroundColorSpan(fontColor(context, !darkTheme(context))),
0,
text.length(),
Spannable.SPAN_INCLUSIVE_INCLUSIVE);
@ -247,6 +257,10 @@ public final class ThemeUtils {
}
}
public static void setColoredTitle(@Nullable ActionBar actionBar, int titleId, Context context) {
setColoredTitle(actionBar, context.getString(titleId), context);
}
/**
* Set color of subtitle to white/black depending on background color
*
@ -293,28 +307,6 @@ public final class ThemeUtils {
return text;
}
/**
* Set color of title to white/black depending on background color
*
* @param actionBar actionBar to be used
* @param titleId title to be shown
*/
public static void setColoredTitle(@Nullable ActionBar actionBar, int titleId, Context context) {
if (actionBar != null) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) {
actionBar.setTitle(titleId);
} else {
String title = context.getString(titleId);
Spannable text = new SpannableString(title);
text.setSpan(new ForegroundColorSpan(fontColor(context, true)),
0,
text.length(),
Spannable.SPAN_INCLUSIVE_INCLUSIVE);
actionBar.setTitle(text);
}
}
}
public static String getDefaultDisplayNameForRootFolder(Context context) {
OCCapability capability = getCapability(context);
@ -534,7 +526,7 @@ public final class ThemeUtils {
*/
public static void themeSearchView(SearchView searchView, boolean themedBackground, Context context) {
// hacky as no default way is provided
int fontColor = ThemeUtils.fontColor(context, true);
int fontColor = ThemeUtils.fontColor(context, !darkTheme(context));
SearchView.SearchAutoComplete editText = searchView.findViewById(R.id.search_src_text);
themeEditText(context, editText, themedBackground);
@ -581,7 +573,7 @@ public final class ThemeUtils {
// setting the track color
DrawableCompat.setTintList(switchView.getTrackDrawable(), new ColorStateList(
new int[][]{new int[]{android.R.attr.state_checked}, new int[]{}},
new int[]{trackColor, Color.parseColor("#4D000000")}));
new int[]{trackColor, MainApp.getAppContext().getResources().getColor(R.color.switch_track_color_unchecked)}));
}
public static Drawable tintDrawable(@DrawableRes int id, int color) {

View file

@ -25,6 +25,7 @@
<!-- Colors -->
<color name="bg_default">#151515</color>
<color name="fg_contrast">#717171</color>
<color name="primary_button_text_color">#000000</color>
<color name="uploader_list_separator_color">#2a2a2a</color>
@ -33,8 +34,11 @@
<color name="action_mode_status_bar_background">#ECECEC</color>
<color name="selected_item_background">#757575</color>
<color name="filelist_icon_background">#222222</color>
<color name="drawer_menu_icon">#ffffff</color>
<color name="bg_fallback_highlight">#737373</color>
<color name="switch_thumb_color_unchecked">#2a2a2a</color>
<color name="switch_track_color_unchecked">#B3FFFFFF</color>
<color name="drawer_active_item_background">@color/white</color>

View file

@ -77,6 +77,7 @@
<color name="drawer_menu_icon">#757575</color>
<color name="bg_fallback_highlight">#616161</color>
<color name="switch_thumb_color_unchecked">#FFFFFF</color>
<color name="switch_track_color_unchecked">#4D000000</color>
<color name="drawer_active_item_background">#80000000</color>

View file

@ -50,6 +50,7 @@
android:dialogTitle="@string/prefs_lock_title"
android:defaultValue="none"/>
<com.owncloud.android.ui.ThemeableSwitchPreference
android:title="@string/prefs_show_hidden_files"
android:key="show_hidden_files"/>
<com.owncloud.android.ui.ThemeableSwitchPreference