diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/BasePreferenceActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/BasePreferenceActivity.java
index 84c53c4c1..6d3a4bd17 100644
--- a/twidere/src/main/java/org/mariotaku/twidere/activity/BasePreferenceActivity.java
+++ b/twidere/src/main/java/org/mariotaku/twidere/activity/BasePreferenceActivity.java
@@ -35,6 +35,7 @@ public abstract class BasePreferenceActivity extends PreferenceActivity implemen
IThemedActivity {
private int mCurrentThemeResource;
+ private String mCurrentThemeBackgroundOption;
@Override
public boolean onMenuOpened(int featureId, Menu menu) {
@@ -99,10 +100,21 @@ public abstract class BasePreferenceActivity extends PreferenceActivity implemen
@Override
protected void onCreate(final Bundle savedInstanceState) {
setTheme(mCurrentThemeResource = getThemeResourceId());
+ mCurrentThemeBackgroundOption = getThemeBackgroundOption();
super.onCreate(savedInstanceState);
setActionBarBackground();
}
+ @Override
+ public String getCurrentThemeBackgroundOption() {
+ return mCurrentThemeBackgroundOption;
+ }
+
+
+ @Override
+ public String getThemeBackgroundOption() {
+ return ThemeUtils.getThemeBackgroundOption(this);
+ }
@Override
protected void onResume() {
super.onResume();
diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/BaseThemedActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/BaseThemedActivity.java
index 48878592a..ecdfc0b33 100644
--- a/twidere/src/main/java/org/mariotaku/twidere/activity/BaseThemedActivity.java
+++ b/twidere/src/main/java/org/mariotaku/twidere/activity/BaseThemedActivity.java
@@ -38,10 +38,16 @@ public abstract class BaseThemedActivity extends Activity implements IThemedActi
private int mCurrentThemeResource, mCurrentThemeColor, mCurrentThemeBackgroundAlpha;
private String mCurrentThemeFontFamily;
private Theme mTheme;
+ private String mCurrentThemeBackgroundOption;
@Override
- public Resources getDefaultResources() {
- return super.getResources();
+ public int getCurrentThemeBackgroundAlpha() {
+ return mCurrentThemeBackgroundAlpha;
+ }
+
+ @Override
+ public int getCurrentThemeColor() {
+ return mCurrentThemeColor;
}
@Override
@@ -50,21 +56,13 @@ public abstract class BaseThemedActivity extends Activity implements IThemedActi
}
@Override
- public Theme getTheme() {
- if (mTheme == null) {
- mTheme = getResources().newTheme();
- mTheme.setTo(super.getTheme());
- final int getThemeResourceId = getThemeResourceId();
- if (getThemeResourceId != 0) {
- mTheme.applyStyle(getThemeResourceId, true);
- }
- }
- return mTheme;
+ public Resources getDefaultResources() {
+ return super.getResources();
}
@Override
public int getThemeBackgroundAlpha() {
- return ThemeUtils.isTransparentBackground(this) ? ThemeUtils.getUserThemeBackgroundAlpha(this) : 0xff;
+ return ThemeUtils.getUserThemeBackgroundAlpha(this);
}
@Override
@@ -88,22 +86,25 @@ public abstract class BaseThemedActivity extends Activity implements IThemedActi
restartActivity(this);
}
+ @Override
+ public Theme getTheme() {
+ if (mTheme == null) {
+ mTheme = getResources().newTheme();
+ mTheme.setTo(super.getTheme());
+ final int getThemeResourceId = getThemeResourceId();
+ if (getThemeResourceId != 0) {
+ mTheme.applyStyle(getThemeResourceId, true);
+ }
+ }
+ return mTheme;
+ }
+
protected final boolean isThemeChanged() {
return getThemeResourceId() != mCurrentThemeResource || getThemeColor() != mCurrentThemeColor
|| !CompareUtils.objectEquals(getThemeFontFamily(), mCurrentThemeFontFamily)
|| getThemeBackgroundAlpha() != mCurrentThemeBackgroundAlpha;
}
- @Override
- public int getCurrentThemeBackgroundAlpha() {
- return mCurrentThemeBackgroundAlpha;
- }
-
- @Override
- public int getCurrentThemeColor() {
- return mCurrentThemeColor;
- }
-
@Override
protected void onCreate(final Bundle savedInstanceState) {
if (Utils.isDebugBuild()) {
@@ -133,9 +134,8 @@ public abstract class BaseThemedActivity extends Activity implements IThemedActi
mCurrentThemeColor = getThemeColor();
mCurrentThemeFontFamily = getThemeFontFamily();
mCurrentThemeBackgroundAlpha = getThemeBackgroundAlpha();
+ mCurrentThemeBackgroundOption = getThemeBackgroundOption();
setTheme(mCurrentThemeResource);
- if (ThemeUtils.isTransparentBackground(mCurrentThemeResource)) {
- getWindow().setBackgroundDrawable(ThemeUtils.getWindowBackground(this));
- }
+ ThemeUtils.applyWindowBackground(this, getWindow(),mCurrentThemeResource, mCurrentThemeBackgroundOption, mCurrentThemeBackgroundAlpha);
}
}
diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/iface/IThemedActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/iface/IThemedActivity.java
index 0264ea766..21db5c417 100644
--- a/twidere/src/main/java/org/mariotaku/twidere/activity/iface/IThemedActivity.java
+++ b/twidere/src/main/java/org/mariotaku/twidere/activity/iface/IThemedActivity.java
@@ -23,18 +23,22 @@ import android.content.res.Resources;
public interface IThemedActivity {
+ public int getCurrentThemeBackgroundAlpha();
+
+ public String getCurrentThemeBackgroundOption();
+
+ public int getCurrentThemeColor();
+
public int getCurrentThemeResourceId();
public Resources getDefaultResources();
public int getThemeBackgroundAlpha();
- public int getCurrentThemeBackgroundAlpha();
+ String getThemeBackgroundOption();
public int getThemeColor();
- public int getCurrentThemeColor();
-
public String getThemeFontFamily();
int getThemeResourceId();
diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/BaseSupportDialogActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/BaseSupportDialogActivity.java
index a57707fab..c922e0950 100644
--- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/BaseSupportDialogActivity.java
+++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/BaseSupportDialogActivity.java
@@ -46,11 +46,6 @@ public class BaseSupportDialogActivity extends ThemedFragmentActivity implements
return (TwidereApplication) getApplication();
}
- @Override
- protected final boolean shouldSetWindowBackground() {
- return false;
- }
-
protected boolean isStateSaved() {
return mInstanceStateSaved;
}
diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/HomeActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/HomeActivity.java
index 39ec8a0e9..70053146c 100644
--- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/HomeActivity.java
+++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/HomeActivity.java
@@ -100,9 +100,9 @@ import org.mariotaku.twidere.util.ParseUtils;
import org.mariotaku.twidere.util.ReadStateManager;
import org.mariotaku.twidere.util.ThemeUtils;
import org.mariotaku.twidere.util.Utils;
+import org.mariotaku.twidere.util.ViewUtils;
import org.mariotaku.twidere.util.accessor.ActivityAccessor;
import org.mariotaku.twidere.util.accessor.ActivityAccessor.TaskDescriptionCompat;
-import org.mariotaku.twidere.util.ViewUtils;
import org.mariotaku.twidere.util.message.TaskStateChangedEvent;
import org.mariotaku.twidere.util.message.UnreadCountUpdatedEvent;
import org.mariotaku.twidere.view.ExtendedViewPager;
@@ -661,11 +661,6 @@ public class HomeActivity extends BaseActionBarActivity implements OnClickListen
mColorStatusFrameLayout = (TintedStatusFrameLayout) findViewById(R.id.home_content);
}
- @Override
- protected boolean shouldSetWindowBackground() {
- return false;
- }
-
private boolean handleFragmentKeyboardShortcutSingle(int keyCode, @NonNull KeyEvent event) {
final Fragment fragment = getCurrentVisibleFragment();
if (fragment instanceof ShortcutCallback) {
@@ -780,7 +775,7 @@ public class HomeActivity extends BaseActionBarActivity implements OnClickListen
private void setupBars() {
final int themeColor = getThemeColor();
final int themeResId = getCurrentThemeResourceId();
- final boolean isTransparent = ThemeUtils.isTransparentBackground(themeResId);
+ final boolean isTransparent = ThemeUtils.isTransparentBackground(getCurrentThemeBackgroundOption());
final int actionBarAlpha = isTransparent ? ThemeUtils.getUserThemeBackgroundAlpha(this) : 0xFF;
final IHomeActionButton homeActionButton = (IHomeActionButton) mActionsButton;
mTabIndicator.setItemContext(ThemeUtils.getActionBarContext(this));
@@ -846,14 +841,14 @@ public class HomeActivity extends BaseActionBarActivity implements OnClickListen
mLeftDrawerContainer = (LeftDrawerFrameLayout) mSlidingMenu.getMenu().findViewById(R.id.left_drawer_container);
mRightDrawerContainer = (RightDrawerFrameLayout) mSlidingMenu.getSecondaryMenu().findViewById(
R.id.right_drawer_container);
- final boolean isTransparentBackground = ThemeUtils.isTransparentBackground(this);
+ final boolean isTransparentBackground = ThemeUtils.isTransparentBackground(getCurrentThemeBackgroundOption());
mLeftDrawerContainer.setClipEnabled(isTransparentBackground);
mLeftDrawerContainer.setScrollScale(mSlidingMenu.getBehindScrollScale());
mRightDrawerContainer.setClipEnabled(isTransparentBackground);
mRightDrawerContainer.setScrollScale(mSlidingMenu.getBehindScrollScale());
mSlidingMenu.setBehindCanvasTransformer(new ListenerCanvasTransformer(this));
final Window window = getWindow();
- final Drawable windowBackground = ThemeUtils.getWindowBackground(this, getCurrentThemeResourceId());
+ final Drawable windowBackground = ThemeUtils.getWindowBackground(this);
ViewUtils.setBackground(mSlidingMenu.getContent(), windowBackground);
window.setBackgroundDrawable(new EmptyDrawable(windowBackground));
}
diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/LinkHandlerActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/LinkHandlerActivity.java
index 7a93ca155..d3d95e8c4 100644
--- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/LinkHandlerActivity.java
+++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/LinkHandlerActivity.java
@@ -78,10 +78,9 @@ public class LinkHandlerActivity extends BaseActionBarActivity implements System
return getSupportFragmentManager().findFragmentById(R.id.main_content);
}
-
@Override
public int getThemeResourceId() {
- return R.style.Theme_Twidere_Light_DialogWhenLarge;
+ return ThemeUtils.getDialogWhenLargeThemeResource(this);
}
@Override
@@ -172,6 +171,7 @@ public class LinkHandlerActivity extends BaseActionBarActivity implements System
final View actionBarView = getWindow().findViewById(android.support.v7.appcompat.R.id.action_bar);
if (actionBarView instanceof Toolbar) {
((Toolbar) actionBarView).setTitleTextColor(mActionBarItemsColor);
+ ((Toolbar) actionBarView).setSubtitleTextColor(mActionBarItemsColor);
ThemeUtils.setActionBarOverflowColor((Toolbar) actionBarView, mActionBarItemsColor);
}
}
@@ -250,7 +250,7 @@ public class LinkHandlerActivity extends BaseActionBarActivity implements System
}
}
if (transitionRes != 0 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
- && !ThemeUtils.isTransparentBackground(this)) {
+ && !ThemeUtils.isTransparentBackground(getCurrentThemeBackgroundOption())) {
Utils.setSharedElementTransition(this, window, transitionRes);
}
}
diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/ThemedActionBarActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/ThemedActionBarActivity.java
index 62f8050ff..3647bcf2d 100644
--- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/ThemedActionBarActivity.java
+++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/ThemedActionBarActivity.java
@@ -47,10 +47,21 @@ public abstract class ThemedActionBarActivity extends ActionBarActivity implemen
private int mCurrentThemeResource, mCurrentThemeColor, mCurrentThemeBackgroundAlpha;
@ShapeStyle
private int mProfileImageStyle;
+ private String mCurrentThemeBackgroundOption;
@Override
- public Resources getDefaultResources() {
- return super.getResources();
+ public int getCurrentThemeBackgroundAlpha() {
+ return mCurrentThemeBackgroundAlpha;
+ }
+
+ @Override
+ public String getCurrentThemeBackgroundOption() {
+ return mCurrentThemeBackgroundOption;
+ }
+
+ @Override
+ public int getCurrentThemeColor() {
+ return mCurrentThemeColor;
}
@Override
@@ -58,19 +69,19 @@ public abstract class ThemedActionBarActivity extends ActionBarActivity implemen
return mCurrentThemeResource;
}
+ @Override
+ public Resources getDefaultResources() {
+ return super.getResources();
+ }
+
@Override
public int getThemeBackgroundAlpha() {
- return ThemeUtils.isTransparentBackground(this) ? ThemeUtils.getUserThemeBackgroundAlpha(this) : 0xff;
+ return ThemeUtils.getUserThemeBackgroundAlpha(this);
}
@Override
- public int getCurrentThemeBackgroundAlpha() {
- return mCurrentThemeBackgroundAlpha;
- }
-
- @Override
- public int getCurrentThemeColor() {
- return mCurrentThemeColor;
+ public String getThemeBackgroundOption() {
+ return ThemeUtils.getThemeBackgroundOption(this);
}
@Override
@@ -94,15 +105,10 @@ public abstract class ThemedActionBarActivity extends ActionBarActivity implemen
StrictModeUtils.detectAllVmPolicy();
StrictModeUtils.detectAllThreadPolicy();
}
- setTheme();
+ setupTheme();
super.onCreate(savedInstanceState);
}
- @Override
- protected void onStart() {
- super.onStart();
- }
-
@Override
protected void onTitleChanged(CharSequence title, int color) {
final SpannableStringBuilder builder = new SpannableStringBuilder(title);
@@ -130,18 +136,20 @@ public abstract class ThemedActionBarActivity extends ActionBarActivity implemen
super.onResume();
}
- protected boolean shouldSetWindowBackground() {
- return true;
+ @Override
+ protected void onStart() {
+ super.onStart();
}
- private void setTheme() {
+ private void setupTheme() {
mCurrentThemeResource = getThemeResourceId();
mCurrentThemeColor = getThemeColor();
mCurrentThemeBackgroundAlpha = getThemeBackgroundAlpha();
mProfileImageStyle = Utils.getProfileImageStyle(this);
+ mCurrentThemeBackgroundOption = getThemeBackgroundOption();
setTheme(mCurrentThemeResource);
- if (shouldSetWindowBackground() && ThemeUtils.isTransparentBackground(mCurrentThemeResource)) {
- getWindow().setBackgroundDrawable(ThemeUtils.getWindowBackground(this));
- }
+ ThemeUtils.applyWindowBackground(this, getWindow(), mCurrentThemeResource, mCurrentThemeBackgroundOption, mCurrentThemeBackgroundAlpha);
}
+
+
}
diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/ThemedFragmentActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/ThemedFragmentActivity.java
index e58103c1a..326904e40 100644
--- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/ThemedFragmentActivity.java
+++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/ThemedFragmentActivity.java
@@ -47,20 +47,21 @@ public abstract class ThemedFragmentActivity extends FragmentActivity implements
private int mCurrentThemeResource, mCurrentThemeColor, mCurrentThemeBackgroundAlpha;
@ShapeStyle
private int mProfileImageStyle;
-
- @Override
- public Resources getDefaultResources() {
- return super.getResources();
- }
+ private String mCurrentThemeBackgroundOption;
@Override
public final int getCurrentThemeResourceId() {
return mCurrentThemeResource;
}
+ @Override
+ public Resources getDefaultResources() {
+ return super.getResources();
+ }
+
@Override
public int getThemeBackgroundAlpha() {
- return ThemeUtils.isTransparentBackground(this) ? ThemeUtils.getUserThemeBackgroundAlpha(this) : 0xff;
+ return ThemeUtils.getUserThemeBackgroundAlpha(this);
}
@Override
@@ -68,6 +69,16 @@ public abstract class ThemedFragmentActivity extends FragmentActivity implements
return mCurrentThemeBackgroundAlpha;
}
+ @Override
+ public String getCurrentThemeBackgroundOption() {
+ return mCurrentThemeBackgroundOption;
+ }
+
+ @Override
+ public String getThemeBackgroundOption() {
+ return ThemeUtils.getThemeBackgroundOption(this);
+ }
+
@Override
public int getCurrentThemeColor() {
return mCurrentThemeColor;
@@ -98,22 +109,6 @@ public abstract class ThemedFragmentActivity extends FragmentActivity implements
super.onCreate(savedInstanceState);
}
- @Override
- protected void onStart() {
- super.onStart();
- }
-
- @Override
- protected void onTitleChanged(CharSequence title, int color) {
- final SpannableStringBuilder builder = new SpannableStringBuilder(title);
- final int themeResId = getCurrentThemeResourceId();
- final int themeColor = getThemeColor(), contrastColor = ColorUtils.getContrastYIQ(themeColor, 192);
- if (!ThemeUtils.isDarkTheme(themeResId)) {
- builder.setSpan(new ForegroundColorSpan(contrastColor), 0, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- }
- super.onTitleChanged(title, color);
- }
-
@Override
public View onCreateView(String name, @NonNull Context context, @NonNull AttributeSet attrs) {
final View view = ThemeUtils.createView(name, context, attrs, mCurrentThemeColor);
@@ -130,8 +125,20 @@ public abstract class ThemedFragmentActivity extends FragmentActivity implements
super.onResume();
}
- protected boolean shouldSetWindowBackground() {
- return true;
+ @Override
+ protected void onStart() {
+ super.onStart();
+ }
+
+ @Override
+ protected void onTitleChanged(CharSequence title, int color) {
+ final SpannableStringBuilder builder = new SpannableStringBuilder(title);
+ final int themeResId = getCurrentThemeResourceId();
+ final int themeColor = getThemeColor(), contrastColor = ColorUtils.getContrastYIQ(themeColor, 192);
+ if (!ThemeUtils.isDarkTheme(themeResId)) {
+ builder.setSpan(new ForegroundColorSpan(contrastColor), 0, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ }
+ super.onTitleChanged(title, color);
}
private void setTheme() {
@@ -139,9 +146,8 @@ public abstract class ThemedFragmentActivity extends FragmentActivity implements
mCurrentThemeColor = getThemeColor();
mCurrentThemeBackgroundAlpha = getThemeBackgroundAlpha();
mProfileImageStyle = Utils.getProfileImageStyle(this);
+ mCurrentThemeBackgroundOption = getThemeBackgroundOption();
setTheme(mCurrentThemeResource);
- if (shouldSetWindowBackground() && ThemeUtils.isTransparentBackground(mCurrentThemeResource)) {
- getWindow().setBackgroundDrawable(ThemeUtils.getWindowBackground(this));
- }
+ ThemeUtils.applyWindowBackground(this, getWindow(), mCurrentThemeResource, mCurrentThemeBackgroundOption, mCurrentThemeBackgroundAlpha);
}
}
diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java
index 2abfd1e4d..abd7b34bb 100644
--- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java
+++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserFragment.java
@@ -1094,8 +1094,8 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
final FragmentActivity activity = getActivity();
final boolean isTransparentBackground;
if (activity instanceof IThemedActivity) {
- final int themeRes = ((IThemedActivity) activity).getCurrentThemeResourceId();
- isTransparentBackground = ThemeUtils.isTransparentBackground(themeRes);
+ final String backgroundOption = ((IThemedActivity) activity).getCurrentThemeBackgroundOption();
+ isTransparentBackground = ThemeUtils.isTransparentBackground(backgroundOption);
} else {
isTransparentBackground = ThemeUtils.isTransparentBackground(getActivity());
}
@@ -1324,8 +1324,11 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
if (actionBar == null) return;
final Drawable shadow = ResourcesCompat.getDrawable(activity.getResources(), R.drawable.shadow_user_banner_action_bar, null);
mActionBarBackground = new ActionBarDrawable(shadow);
- mActionBarBackground.setAlpha(linkHandler.getCurrentThemeBackgroundAlpha());
- mProfileBannerView.setAlpha(linkHandler.getCurrentThemeBackgroundAlpha() / 255f);
+ if (!ThemeUtils.isWindowFloating(linkHandler, linkHandler.getCurrentThemeResourceId())
+ && ThemeUtils.isTransparentBackground(linkHandler.getCurrentThemeBackgroundOption())) {
+ mActionBarBackground.setAlpha(linkHandler.getCurrentThemeBackgroundAlpha());
+ mProfileBannerView.setAlpha(linkHandler.getCurrentThemeBackgroundAlpha() / 255f);
+ }
actionBar.setBackgroundDrawable(mActionBarBackground);
mActionBarHomeAsUpIndicator = ThemeUtils.getActionBarHomeAsUpIndicator(actionBar);
actionBar.setHomeAsUpIndicator(mActionBarHomeAsUpIndicator);
diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/ThemeUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/ThemeUtils.java
index db1c7bbb1..d57eda4a2 100644
--- a/twidere/src/main/java/org/mariotaku/twidere/util/ThemeUtils.java
+++ b/twidere/src/main/java/org/mariotaku/twidere/util/ThemeUtils.java
@@ -57,6 +57,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.view.Window;
+import android.view.WindowManager;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.ProgressBar;
@@ -165,6 +166,16 @@ public class ThemeUtils implements Constants {
}
}
+ public static void applyWindowBackground(Context context, Window window, int theme, String option, int alpha) {
+ if (window.isFloating()) return;
+ if (VALUE_THEME_BACKGROUND_TRANSPARENT.equals(option)) {
+ window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
+ window.setBackgroundDrawable(ThemeUtils.getWindowBackgroundApplyAlpha(context, alpha));
+ } else if (VALUE_THEME_BACKGROUND_SOLID.equals(option)) {
+ window.setBackgroundDrawable(new ColorDrawable(isDarkTheme(theme) ? Color.BLACK : Color.WHITE));
+ }
+ }
+
public static Drawable getCompatToolbarOverlay(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) return null;
final View view = activity.getWindow().findViewById(android.support.v7.appcompat.R.id.decor_content_parent);
@@ -199,6 +210,21 @@ public class ThemeUtils implements Constants {
indicator.updateAppearance();
}
+ public static boolean isWindowFloating(Context context, int theme) {
+ final TypedArray a;
+ if (theme != 0) {
+ //noinspection ConstantConditions
+ a = context.obtainStyledAttributes(null, new int[]{android.R.attr.windowIsFloating}, 0, theme);
+ } else {
+ a = context.obtainStyledAttributes(new int[]{android.R.attr.windowIsFloating});
+ }
+ try {
+ return a.getBoolean(0, false);
+ } finally {
+ a.recycle();
+ }
+ }
+
public static void resetCheatSheet(ActionMenuView menuView) {
final OnLongClickListener listener = new OnLongClickListener() {
@Override
@@ -357,6 +383,7 @@ public class ThemeUtils implements Constants {
public static int getActionBarPopupThemeRes(final Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return 0;
+ @SuppressLint("InlinedApi")
final TypedArray a = context.obtainStyledAttributes(new int[]{android.R.attr.actionBarPopupTheme});
try {
return a.getResourceId(0, 0);
@@ -475,6 +502,7 @@ public class ThemeUtils implements Constants {
}
public static float getSupportActionBarElevation(final Context context) {
+ @SuppressWarnings("ConstantConditions")
final TypedArray a = context.obtainStyledAttributes(null, new int[]{R.attr.elevation}, R.attr.actionBarStyle, 0);
try {
return a.getDimension(0, 0);
@@ -486,6 +514,7 @@ public class ThemeUtils implements Constants {
public static float getActionBarElevation(final Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return 0;
@SuppressLint("InlinedApi")
+ @SuppressWarnings("ConstantConditions")
final TypedArray a = context.obtainStyledAttributes(null, new int[]{android.R.attr.elevation},
android.R.attr.actionBarStyle, 0);
try {
@@ -496,21 +525,24 @@ public class ThemeUtils implements Constants {
}
+ @Deprecated
public static Drawable getActionBarBackground(final Context context, final int themeRes) {
+ @SuppressWarnings("ConstantConditions")
final TypedArray a1 = context.obtainStyledAttributes(null, new int[]{android.R.attr.background},
R.attr.actionBarStyle, themeRes);
try {
if (a1.hasValue(0)) {
- return applyActionBarDrawable(context, a1.getDrawable(0), isTransparentBackground(themeRes));
+ return applyActionBarDrawable(context, a1.getDrawable(0), isTransparentBackground(context));
}
} finally {
a1.recycle();
}
+ @SuppressWarnings("ConstantConditions")
final TypedArray a2 = context.obtainStyledAttributes(null, new int[]{android.R.attr.background},
android.R.attr.actionBarStyle, themeRes);
try {
if (a2.hasValue(0)) {
- return applyActionBarDrawable(context, a2.getDrawable(0), isTransparentBackground(themeRes));
+ return applyActionBarDrawable(context, a2.getDrawable(0), isTransparentBackground(context));
}
} finally {
a2.recycle();
@@ -528,7 +560,7 @@ public class ThemeUtils implements Constants {
actionBarColor = accentColor;
}
final ColorDrawable d = new ActionBarColorDrawable(actionBarColor, outlineEnabled);
- return applyActionBarDrawable(context, d, isTransparentBackground(themeRes));
+ return applyActionBarDrawable(context, d, isTransparentBackground(context));
}
@NonNull
@@ -541,10 +573,11 @@ public class ThemeUtils implements Constants {
actionBarColor = accentColor;
}
final ColorDrawable d = new ActionBarColorDrawable(actionBarColor, outlineEnabled);
- return applyActionBarDrawable(context, d, isTransparentBackground(themeRes));
+ return applyActionBarDrawable(context, d, isTransparentBackground(context));
}
public static Context getActionBarContext(final Context context) {
+ @SuppressLint("InlinedApi")
final TypedArray a = context.obtainStyledAttributes(new int[]{R.attr.actionBarTheme,
R.attr.actionBarWidgetTheme, android.R.attr.actionBarTheme,
android.R.attr.actionBarWidgetTheme});
@@ -561,18 +594,12 @@ public class ThemeUtils implements Constants {
public static Drawable getActionBarSplitBackground(final Context context, final int themeRes) {
+ @SuppressWarnings("ConstantConditions")
final TypedArray a = context.obtainStyledAttributes(null, new int[]{android.R.attr.backgroundSplit},
android.R.attr.actionBarStyle, themeRes);
final Drawable d = a.getDrawable(0);
a.recycle();
- return applyActionBarDrawable(context, d, isTransparentBackground(themeRes));
- }
-
- public static int getColorBackgroundCacheHint(final Context context) {
- final TypedArray a = context.obtainStyledAttributes(new int[]{android.R.attr.colorBackgroundCacheHint});
- final int color = a.getColor(0, Color.TRANSPARENT);
- a.recycle();
- return color;
+ return applyActionBarDrawable(context, d, isTransparentBackground(context));
}
public static int getCardBackgroundColor(final Context context) {
@@ -610,26 +637,9 @@ public class ThemeUtils implements Constants {
}
public static int getDrawerThemeResource(final int themeRes) {
- switch (themeRes) {
- case R.style.Theme_Twidere_Dark_Transparent:
- case R.style.Theme_Twidere_Light_Transparent:
- return R.style.Theme_Twidere_Drawer_Dark_Transparent;
- }
return R.style.Theme_Twidere_Drawer_Dark;
}
- public static int getLightDrawerThemeResource(final Context context) {
- return getLightDrawerThemeResource(getThemeResource(context));
- }
-
- public static int getLightDrawerThemeResource(final int themeRes) {
- switch (themeRes) {
- case R.style.Theme_Twidere_Light_Transparent:
- return R.style.Theme_Twidere_Drawer_Light_Transparent;
- }
- return R.style.Theme_Twidere_Drawer_Light;
- }
-
public static Drawable getImageHighlightDrawable(final Context context) {
final Drawable d = getSelectableItemBackgroundDrawable(context);
if (d != null) {
@@ -693,6 +703,7 @@ public class ThemeUtils implements Constants {
}
public static int getTextColorSecondary(final Context context) {
+ @SuppressWarnings("ConstantConditions")
final TypedArray a = context.obtainStyledAttributes(new int[]{android.R.attr.textColorSecondary});
try {
return a.getColor(0, Color.TRANSPARENT);
@@ -706,11 +717,6 @@ public class ThemeUtils implements Constants {
}
public static int getThemeAlpha(final int themeRes) {
- switch (themeRes) {
- case R.style.Theme_Twidere_Dark_Transparent:
- case R.style.Theme_Twidere_Light_Transparent:
- return 0xa0;
- }
return 0xff;
}
@@ -760,6 +766,7 @@ public class ThemeUtils implements Constants {
if (themeRes == 0) {
return getThemeBackgroundColor(context);
}
+ @SuppressWarnings("ConstantConditions")
final TypedArray a = context.obtainStyledAttributes(null, new int[]{android.R.attr.colorBackground},
0, themeRes);
try {
@@ -798,28 +805,29 @@ public class ThemeUtils implements Constants {
}
public static int getThemeResource(final Context context) {
- return getThemeResource(getThemeNameOption(context), getThemeBackgroundOption(context));
+ return getThemeResource(getThemeNameOption(context));
}
- public static int getThemeResource(final String name, final String background) {
- if (VALUE_THEME_NAME_LIGHT.equals(name)) {
- if (VALUE_THEME_BACKGROUND_SOLID.equals(background))
- return R.style.Theme_Twidere_Light_SolidBackground;
- else if (VALUE_THEME_BACKGROUND_TRANSPARENT.equals(background))
- return R.style.Theme_Twidere_Light_Transparent;
- return R.style.Theme_Twidere_Light;
+ public static int getDialogWhenLargeThemeResource(final Context context) {
+ return getDialogWhenLargeThemeResource(getThemeNameOption(context));
+ }
- } else if (VALUE_THEME_NAME_DARK.equals(name)) {
- if (VALUE_THEME_BACKGROUND_SOLID.equals(background))
- return R.style.Theme_Twidere_Dark_SolidBackground;
- else if (VALUE_THEME_BACKGROUND_TRANSPARENT.equals(background))
- return R.style.Theme_Twidere_Dark_Transparent;
+ public static int getThemeResource(final String name) {
+ if (VALUE_THEME_NAME_DARK.equals(name)) {
return R.style.Theme_Twidere_Dark;
}
return R.style.Theme_Twidere_Light;
}
+ public static int getDialogWhenLargeThemeResource(final String name) {
+ if (VALUE_THEME_NAME_DARK.equals(name)) {
+ return R.style.Theme_Twidere_Dark_DialogWhenLarge;
+ }
+ return R.style.Theme_Twidere_Light_DialogWhenLarge;
+ }
+
public static int getTitleTextAppearance(final Context context) {
+ @SuppressWarnings("ConstantConditions")
final TypedArray a = context.obtainStyledAttributes(null, new int[]{android.R.attr.titleTextStyle},
android.R.attr.actionBarStyle, android.R.style.Widget_Holo_ActionBar);
final int textAppearance = a.getResourceId(0, android.R.style.TextAppearance_Holo);
@@ -848,6 +856,10 @@ public class ThemeUtils implements Constants {
public static int getUserThemeBackgroundAlpha(final Context context) {
+ if (context instanceof IThemedActivity) {
+ final int alpha = ((IThemedActivity) context).getCurrentThemeBackgroundAlpha();
+ if (alpha >= 0) return alpha;
+ }
if (context == null) return DEFAULT_THEME_BACKGROUND_ALPHA;
final SharedPreferencesWrapper pref = getSharedPreferencesWrapper(context);
return pref.getInt(KEY_THEME_BACKGROUND_ALPHA, DEFAULT_THEME_BACKGROUND_ALPHA);
@@ -885,17 +897,27 @@ public class ThemeUtils implements Constants {
return d;
}
- public static Drawable getWindowBackground(final Context context, final int themeRes) {
- final TypedArray a = context.obtainStyledAttributes(null, new int[]{android.R.attr.windowBackground}, 0,
- themeRes);
+ public static Drawable getWindowBackground(final Context context, int theme) {
+ @SuppressWarnings("ConstantConditions")
+ final TypedArray a = context.obtainStyledAttributes(null, new int[]{android.R.attr.windowBackground}, 0, theme);
final Drawable d = a.getDrawable(0);
a.recycle();
- if (isTransparentBackground(themeRes)) {
+ if (isTransparentBackground(context)) {
applyThemeBackgroundAlphaToDrawable(context, d);
}
return d;
}
+ public static Drawable getWindowBackgroundApplyAlpha(final Context context, final int alpha) {
+ final TypedArray a = context.obtainStyledAttributes(new int[]{android.R.attr.windowBackground});
+ final Drawable d = a.getDrawable(0);
+ a.recycle();
+ if (d != null) {
+ d.setAlpha(alpha);
+ }
+ return d;
+ }
+
public static Drawable getWindowContentOverlay(final Context context) {
final TypedArray a = context.obtainStyledAttributes(new int[]{android.R.attr.windowContentOverlay});
final Drawable d = a.getDrawable(0);
@@ -910,26 +932,24 @@ public class ThemeUtils implements Constants {
public static boolean isDarkTheme(final int themeRes) {
switch (themeRes) {
case R.style.Theme_Twidere_Dark:
- case R.style.Theme_Twidere_Dark_SolidBackground:
case R.style.Theme_Twidere_Dark_Dialog:
+ case R.style.Theme_Twidere_Dark_DialogWhenLarge:
case R.style.Theme_Twidere_Dark_Compose:
- case R.style.Theme_Twidere_Dark_Transparent:
return true;
}
return false;
}
public static boolean isTransparentBackground(final Context context) {
- return isTransparentBackground(getThemeResource(context));
+ if (context instanceof IThemedActivity) {
+ final String option = ((IThemedActivity) context).getCurrentThemeBackgroundOption();
+ if (option != null) return isTransparentBackground(option);
+ }
+ return isTransparentBackground(getThemeBackgroundOption(context));
}
- public static boolean isTransparentBackground(final int themeRes) {
- switch (themeRes) {
- case R.style.Theme_Twidere_Dark_Transparent:
- case R.style.Theme_Twidere_Light_Transparent:
- return true;
- }
- return false;
+ public static boolean isTransparentBackground(final String option) {
+ return VALUE_THEME_BACKGROUND_TRANSPARENT.equals(option);
}
public static void overrideActivityCloseAnimation(final Activity activity) {
@@ -962,6 +982,7 @@ public class ThemeUtils implements Constants {
}
public static void overrideNormalActivityCloseAnimation(final Activity activity) {
+ @SuppressWarnings("ConstantConditions")
final TypedArray a = activity.obtainStyledAttributes(null, ANIM_CLOSE_STYLE_ATTRS,
0, android.R.style.Animation_Activity);
final int activityCloseEnterAnimation = a.getResourceId(0, 0);
@@ -992,6 +1013,7 @@ public class ThemeUtils implements Constants {
public static int getThemeColor(Context context, int themeResourceId) {
final Context appContext = context.getApplicationContext();
final Resources res = appContext.getResources();
+ @SuppressWarnings("ConstantConditions")
final TypedArray a = appContext.obtainStyledAttributes(null,
new int[]{android.R.attr.colorActivatedHighlight}, 0, themeResourceId);
try {
@@ -1045,6 +1067,13 @@ public class ThemeUtils implements Constants {
}
}
+ public static void setActionBarSubtitleTextColor(Window window, int itemColor) {
+ final View actionBarView = window.findViewById(android.support.v7.appcompat.R.id.action_bar);
+ if (actionBarView instanceof Toolbar) {
+ ((Toolbar) actionBarView).setSubtitleTextColor(itemColor);
+ }
+ }
+
public static Drawable getActionBarHomeAsUpIndicator(android.support.v7.app.ActionBar actionBar) {
final Context context = actionBar.getThemedContext();
@SuppressWarnings("ConstantConditions")
diff --git a/twidere/src/main/res/values/themes.xml b/twidere/src/main/res/values/themes.xml
index 5fccc0dc7..35a7e775f 100644
--- a/twidere/src/main/res/values/themes.xml
+++ b/twidere/src/main/res/values/themes.xml
@@ -136,37 +136,6 @@
- @color/message_bubble_color_light
-
-
-
-
-
-
-
-
-
-
-
-
-
-