improved pure black/white theme

This commit is contained in:
Mariotaku Lee 2017-04-09 11:49:47 +08:00
parent ba244295df
commit 407deb7fac
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
3 changed files with 31 additions and 5 deletions

View File

@ -33,6 +33,7 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.ColorUtils;
import android.support.v7.app.TwilightManagerAccessor;
import android.support.v7.view.menu.ActionMenuItemView;
import android.support.v7.widget.ActionMenuView;
@ -100,19 +101,32 @@ public class ThemeUtils implements Constants {
}
}
public static void applyWindowBackground(@NonNull Context context, @NonNull Window window, String option, int alpha) {
public static void applyWindowBackground(@NonNull Context context, @NonNull Window window,
String backgroundOption, int alpha) {
if (isWindowFloating(context)) {
window.setBackgroundDrawable(getWindowBackground(context));
} else if (VALUE_THEME_BACKGROUND_TRANSPARENT.equals(option)) {
} else if (VALUE_THEME_BACKGROUND_TRANSPARENT.equals(backgroundOption)) {
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
window.setBackgroundDrawable(getWindowBackgroundFromThemeApplyAlpha(context, alpha));
} else if (VALUE_THEME_BACKGROUND_SOLID.equals(option)) {
} else if (VALUE_THEME_BACKGROUND_SOLID.equals(backgroundOption)) {
window.setBackgroundDrawable(new ColorDrawable(isLightTheme(context) ? Color.WHITE : Color.BLACK));
} else {
window.setBackgroundDrawable(getWindowBackground(context));
}
}
public static int getThemeBackgroundColor(@NonNull final Context context, String backgroundOption,
int alpha) {
if (isWindowFloating(context)) {
return getThemeBackgroundColor(context);
} else if (VALUE_THEME_BACKGROUND_TRANSPARENT.equals(backgroundOption)) {
return ColorUtils.setAlphaComponent(getThemeBackgroundColor(context), alpha);
} else if (VALUE_THEME_BACKGROUND_SOLID.equals(backgroundOption)) {
return isLightTheme(context) ? Color.WHITE : Color.BLACK;
} else {
return getThemeBackgroundColor(context);
}
}
public static int getCardBackgroundColor(final Context context, String backgroundOption, int themeAlpha) {
final TypedArray a = context.obtainStyledAttributes(new int[]{R.attr.cardItemBackgroundColor});

View File

@ -26,6 +26,7 @@ import android.content.Intent
import android.content.IntentFilter
import android.content.SharedPreferences
import android.content.res.Resources
import android.graphics.Color
import android.graphics.Rect
import android.nfc.NfcAdapter
import android.os.Bundle
@ -51,6 +52,7 @@ import org.mariotaku.kpreferences.get
import org.mariotaku.restfu.http.RestHttpClient
import org.mariotaku.twidere.BuildConfig
import org.mariotaku.twidere.TwidereConstants.SHARED_PREFERENCES_NAME
import org.mariotaku.twidere.TwidereConstants.VALUE_THEME_BACKGROUND_SOLID
import org.mariotaku.twidere.activity.iface.IBaseActivity
import org.mariotaku.twidere.activity.iface.IControlBarActivity
import org.mariotaku.twidere.activity.iface.IThemedActivity
@ -129,10 +131,18 @@ open class BaseActivity : ChameleonActivity(), IBaseActivity<BaseActivity>, IThe
val theme = Chameleon.Theme.from(this)
theme.colorAccent = ThemeUtils.getUserAccentColor(this)
theme.colorPrimary = ThemeUtils.getUserAccentColor(this)
val backgroundOption = themeBackgroundOption
if (theme.isToolbarColored) {
theme.colorToolbar = theme.colorPrimary
} else if (backgroundOption == VALUE_THEME_BACKGROUND_SOLID) {
theme.colorToolbar = if (ThemeUtils.isLightTheme(this)) {
Color.WHITE
} else {
Color.BLACK
}
}
if (ThemeUtils.isTransparentBackground(themeBackgroundOption)) {
if (ThemeUtils.isTransparentBackground(backgroundOption)) {
theme.colorToolbar = ColorUtils.setAlphaComponent(theme.colorToolbar,
ThemeUtils.getActionBarAlpha(themePreferences[themeBackgroundAlphaKey]))
}

View File

@ -76,9 +76,11 @@ class SettingsActivity : BaseActivity(), OnItemClickListener, OnPreferenceStartF
return
}
val backgroundOption = currentThemeBackgroundOption
val backgroundAlpha = currentThemeBackgroundAlpha
detailFragmentContainer.setBackgroundColor(backgroundAlpha shl 24 or 0xFFFFFF and ThemeUtils.getThemeBackgroundColor(this))
detailFragmentContainer.setBackgroundColor(ThemeUtils.getThemeBackgroundColor(this,
backgroundOption, backgroundAlpha))
slidingPane.setShadowResourceLeft(R.drawable.sliding_pane_shadow_left)
slidingPane.setShadowResourceRight(R.drawable.sliding_pane_shadow_right)