improved transparent theme

This commit is contained in:
Mariotaku Lee 2015-05-17 23:16:54 +08:00
parent ae1acdeb46
commit a9a80e4de0
12 changed files with 80 additions and 27 deletions

View File

@ -268,6 +268,14 @@ public class SettingsActivity extends BasePreferenceActivity {
ViewSupport.setBackground(windowOverlay, ThemeUtils.getNormalWindowContentOverlay(this, getCurrentThemeResourceId()));
setIntent(getIntent().addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT));
final String backgroundOption = getCurrentThemeBackgroundOption();
final boolean isTransparent = ThemeUtils.isTransparentBackground(backgroundOption);
final int actionBarAlpha = isTransparent ? ThemeUtils.getActionBarAlpha(ThemeUtils.getUserThemeBackgroundAlpha(this)) : 0xFF;
actionBarContainer.setAlpha(actionBarAlpha / 255f);
windowOverlay.setAlpha(actionBarAlpha / 255f);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

View File

@ -796,7 +796,7 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
final int themeResId = getCurrentThemeResourceId();
final String backgroundOption = getCurrentThemeBackgroundOption();
final boolean isTransparent = ThemeUtils.isTransparentBackground(backgroundOption);
final int actionBarAlpha = isTransparent ? ThemeUtils.getUserThemeBackgroundAlpha(this) : 0xFF;
final int actionBarAlpha = isTransparent ? ThemeUtils.getActionBarAlpha(ThemeUtils.getUserThemeBackgroundAlpha(this)) : 0xFF;
final IHomeActionButton homeActionButton = (IHomeActionButton) mActionsButton;
mTabIndicator.setItemContext(ThemeUtils.getActionBarThemedContext(this, themeResId, themeColor));
ViewSupport.setBackground(mActionBarContainer, ThemeUtils.getActionBarBackground(this, themeResId, themeColor,

View File

@ -92,7 +92,7 @@ public class LinkHandlerActivity extends BaseAppCompatActivity implements System
};
private TintedStatusFrameLayout mMainContent;
private View mActionBarOverlay;
private View mActionBarWithOverlay;
private ActionBarContainer mActionBarContainer;
private boolean mFinishOnly;
@ -278,7 +278,7 @@ public class LinkHandlerActivity extends BaseAppCompatActivity implements System
public void onContentChanged() {
super.onContentChanged();
mMainContent = (TintedStatusFrameLayout) findViewById(R.id.main_content);
mActionBarOverlay = findViewById(R.id.twidere_action_bar_with_overlay);
mActionBarWithOverlay = findViewById(R.id.twidere_action_bar_with_overlay);
mActionBarContainer = (ActionBarContainer) findViewById(R.id.twidere_action_bar_container);
}
@ -352,6 +352,9 @@ public class LinkHandlerActivity extends BaseAppCompatActivity implements System
break;
}
}
final boolean isTransparent = ThemeUtils.isTransparentBackground(option);
final int actionBarAlpha = isTransparent ? ThemeUtils.getActionBarAlpha(ThemeUtils.getUserThemeBackgroundAlpha(this)) : 0xFF;
mActionBarWithOverlay.setAlpha(actionBarAlpha / 255f);
}
private void setStatusBarColor(int linkId, Uri uri) {
@ -364,8 +367,9 @@ public class LinkHandlerActivity extends BaseAppCompatActivity implements System
mMainContent.setDrawShadow(false);
mMainContent.setDrawColor(true);
mMainContent.setFactor(1);
final int alpha = ThemeUtils.isTransparentBackground(getThemeBackgroundOption()) ? getCurrentThemeBackgroundAlpha() : 0xFF;
final int statusBarColor=ThemeUtils.getActionBarColor(this, getCurrentThemeColor(), getCurrentThemeResourceId(), getThemeBackgroundOption());
final int alpha = ThemeUtils.isTransparentBackground(getThemeBackgroundOption())
? ThemeUtils.getActionBarAlpha(getCurrentThemeBackgroundAlpha()) : 0xFF;
final int statusBarColor = ThemeUtils.getActionBarColor(this, getCurrentThemeColor(), getCurrentThemeResourceId(), getThemeBackgroundOption());
mMainContent.setColor(statusBarColor, alpha);
StatusBarProxy.setStatusBarDarkIcon(getWindow(), TwidereColorUtils.getYIQLuminance(statusBarColor) > ThemeUtils.ACCENT_COLOR_THRESHOLD);
break;

View File

@ -30,6 +30,7 @@ import android.view.View;
import android.view.ViewGroup;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.activity.iface.IThemedActivity;
import org.mariotaku.twidere.adapter.support.SupportTabsAdapter;
import org.mariotaku.twidere.fragment.BaseFiltersFragment.FilteredKeywordsFragment;
import org.mariotaku.twidere.fragment.BaseFiltersFragment.FilteredLinksFragment;
@ -78,6 +79,13 @@ public class FiltersFragment extends BaseSupportFragment implements RefreshScrol
ThemeUtils.setCompatToolbarOverlay(activity, new EmptyDrawable());
ThemeUtils.setCompatContentViewOverlay(activity, new EmptyDrawable());
ThemeUtils.setWindowOverlayViewOverlay(activity, new EmptyDrawable());
if (activity instanceof IThemedActivity) {
final String backgroundOption = ((IThemedActivity) activity).getCurrentThemeBackgroundOption();
final boolean isTransparent = ThemeUtils.isTransparentBackground(backgroundOption);
final int actionBarAlpha = isTransparent ? ThemeUtils.getActionBarAlpha(ThemeUtils.getUserThemeBackgroundAlpha(activity)) : 0xFF;
mPagerIndicator.setAlpha(actionBarAlpha / 255f);
}
}
@Override

View File

@ -29,6 +29,7 @@ import android.view.View;
import android.view.ViewGroup;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.activity.iface.IThemedActivity;
import org.mariotaku.twidere.adapter.support.SupportTabsAdapter;
import org.mariotaku.twidere.fragment.iface.IBaseFragment.SystemWindowsInsetsCallback;
import org.mariotaku.twidere.fragment.iface.RefreshScrollTopInterface;
@ -64,6 +65,13 @@ public class ListsFragment extends BaseSupportFragment implements RefreshScrollT
ThemeUtils.setCompatToolbarOverlay(activity, new EmptyDrawable());
ThemeUtils.setCompatContentViewOverlay(activity, new EmptyDrawable());
ThemeUtils.setWindowOverlayViewOverlay(activity, new EmptyDrawable());
if (activity instanceof IThemedActivity) {
final String backgroundOption = ((IThemedActivity) activity).getCurrentThemeBackgroundOption();
final boolean isTransparent = ThemeUtils.isTransparentBackground(backgroundOption);
final int actionBarAlpha = isTransparent ? ThemeUtils.getActionBarAlpha(ThemeUtils.getUserThemeBackgroundAlpha(activity)) : 0xFF;
mPagerIndicator.setAlpha(actionBarAlpha / 255f);
}
}

View File

@ -43,6 +43,7 @@ import android.view.ViewGroup;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.activity.iface.IControlBarActivity;
import org.mariotaku.twidere.activity.iface.IControlBarActivity.ControlBarOffsetListener;
import org.mariotaku.twidere.activity.iface.IThemedActivity;
import org.mariotaku.twidere.activity.support.ComposeActivity;
import org.mariotaku.twidere.activity.support.LinkHandlerActivity;
import org.mariotaku.twidere.adapter.support.SupportTabsAdapter;
@ -168,6 +169,13 @@ public class SearchFragment extends BaseSupportFragment implements RefreshScroll
ThemeUtils.setCompatToolbarOverlay(activity, new EmptyDrawable());
ThemeUtils.setCompatContentViewOverlay(activity, new EmptyDrawable());
ThemeUtils.setWindowOverlayViewOverlay(activity, new EmptyDrawable());
if (activity instanceof IThemedActivity) {
final String backgroundOption = ((IThemedActivity) activity).getCurrentThemeBackgroundOption();
final boolean isTransparent = ThemeUtils.isTransparentBackground(backgroundOption);
final int actionBarAlpha = isTransparent ? ThemeUtils.getActionBarAlpha(ThemeUtils.getUserThemeBackgroundAlpha(activity)) : 0xFF;
mPagerIndicator.setAlpha(actionBarAlpha / 255f);
}
if (savedInstanceState == null && args != null && args.containsKey(EXTRA_QUERY)) {
final String query = args.getString(EXTRA_QUERY);
final SearchRecentSuggestions suggestions = new SearchRecentSuggestions(getActivity(),

View File

@ -1382,7 +1382,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
final String backgroundOption = themed.getThemeBackgroundOption();
final int actionBarColor = ThemeUtils.getActionBarColor(activity, color, themeRes, backgroundOption);
if (mTintedStatusContent != null) {
mTintedStatusContent.setColor(actionBarColor, themed.getCurrentThemeBackgroundAlpha());
mTintedStatusContent.setColor(actionBarColor, ThemeUtils.getActionBarAlpha(themed.getCurrentThemeBackgroundAlpha()));
}
if (mActionBarBackground != null) {
mActionBarBackground.setColor(actionBarColor);
@ -1413,7 +1413,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
mActionBarBackground = new ActionBarDrawable(shadow);
if (!ThemeUtils.isWindowFloating(linkHandler, linkHandler.getCurrentThemeResourceId())
&& ThemeUtils.isTransparentBackground(linkHandler.getCurrentThemeBackgroundOption())) {
mActionBarBackground.setAlpha(linkHandler.getCurrentThemeBackgroundAlpha());
// mActionBarBackground.setAlpha(ThemeUtils.getActionBarAlpha(linkHandler.getCurrentThemeBackgroundAlpha()));
mProfileBannerView.setAlpha(linkHandler.getCurrentThemeBackgroundAlpha() / 255f);
}
actionBarContainer.setPrimaryBackground(mActionBarBackground);
@ -1515,7 +1515,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
activity.getThemeBackgroundOption());
if (ThemeUtils.isTransparentBackground(activity.getCurrentThemeBackgroundOption())) {
stackedTabColor = ColorUtils.setAlphaComponent(stackedTabColor, activity.getCurrentThemeBackgroundAlpha());
stackedTabColor = ColorUtils.setAlphaComponent(stackedTabColor, ThemeUtils.getActionBarAlpha(activity.getCurrentThemeBackgroundAlpha()));
}
final int tabColor = (Integer) sArgbEvaluator.evaluate(tabOutlineAlphaFactor, stackedTabColor, mCardBackgroundColor);
((ColorDrawable) tabBackground).setColor(tabColor);

View File

@ -60,6 +60,10 @@ import org.mariotaku.twidere.activity.iface.IThemedActivity;
import org.mariotaku.twidere.activity.support.AccountSelectorActivity;
import org.mariotaku.twidere.activity.support.UserListSelectorActivity;
import org.mariotaku.twidere.adapter.support.SupportTabsAdapter;
import org.mariotaku.twidere.api.twitter.Twitter;
import org.mariotaku.twidere.api.twitter.TwitterException;
import org.mariotaku.twidere.api.twitter.model.UserList;
import org.mariotaku.twidere.api.twitter.model.UserListUpdate;
import org.mariotaku.twidere.app.TwidereApplication;
import org.mariotaku.twidere.constant.SharedPreferenceConstants;
import org.mariotaku.twidere.fragment.iface.IBaseFragment.SystemWindowsInsetsCallback;
@ -82,11 +86,6 @@ import org.mariotaku.twidere.util.UserColorNameManager;
import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.view.TabPagerIndicator;
import org.mariotaku.twidere.api.twitter.Twitter;
import org.mariotaku.twidere.api.twitter.TwitterException;
import org.mariotaku.twidere.api.twitter.model.UserList;
import org.mariotaku.twidere.api.twitter.model.UserListUpdate;
import static org.mariotaku.twidere.util.MenuUtils.setMenuItemAvailability;
import static org.mariotaku.twidere.util.Utils.addIntentToMenu;
import static org.mariotaku.twidere.util.Utils.openUserListDetails;
@ -240,11 +239,6 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
mViewPager.setAdapter(mPagerAdapter);
mPagerIndicator.setViewPager(mViewPager);
mPagerIndicator.setTabDisplayOption(TabPagerIndicator.LABEL);
if (activity instanceof IThemedActivity) {
mPagerIndicator.setStripColor(((IThemedActivity) activity).getCurrentThemeColor());
} else {
}
getUserListInfo(false);
setupUserPages();
}
@ -454,6 +448,13 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
ThemeUtils.setCompatToolbarOverlay(activity, new EmptyDrawable());
ThemeUtils.setCompatContentViewOverlay(activity, new EmptyDrawable());
ThemeUtils.setWindowOverlayViewOverlay(activity, new EmptyDrawable());
if (activity instanceof IThemedActivity) {
final String backgroundOption = ((IThemedActivity) activity).getCurrentThemeBackgroundOption();
final boolean isTransparent = ThemeUtils.isTransparentBackground(backgroundOption);
final int actionBarAlpha = isTransparent ? ThemeUtils.getActionBarAlpha(ThemeUtils.getUserThemeBackgroundAlpha(activity)) : 0xFF;
mPagerIndicator.setAlpha(actionBarAlpha / 255f);
}
}
public static class EditUserListDialogFragment extends BaseSupportDialogFragment implements

View File

@ -31,6 +31,9 @@ import org.mariotaku.twidere.util.support.ViewSupport;
*/
public class ThemeBackgroundPreference extends DialogPreference implements Constants {
public final static int MAX_ALPHA = 0xFF;
public final static int MIN_ALPHA = 0x40;
private final String[] mBackgroundEntries, mBackgroundValues;
private String mValue;
@ -69,7 +72,7 @@ public class ThemeBackgroundPreference extends DialogPreference implements Const
if (positiveResult) {
final SharedPreferences preferences = getSharedPreferences();
final SharedPreferences.Editor editor = preferences.edit();
editor.putInt(KEY_THEME_BACKGROUND_ALPHA, mAlphaSlider.getProgress());
editor.putInt(KEY_THEME_BACKGROUND_ALPHA, getSliderAlpha());
editor.apply();
persistValue(mValue);
}
@ -161,9 +164,9 @@ public class ThemeBackgroundPreference extends DialogPreference implements Const
mAlphaContainer = view.findViewById(R.id.alpha_container);
mAlphaSlider = (SeekBar) view.findViewById(R.id.alpha_slider);
mAlphaPreview = (ImageView) view.findViewById(R.id.alpha_preview);
mAlphaSlider.setMax(0xFF);
mAlphaSlider.setMax(MAX_ALPHA - MIN_ALPHA);
mAlphaSlider.setOnSeekBarChangeListener(mAlphaSliderChangedListener);
mAlphaSlider.setProgress(preferences.getInt(KEY_THEME_BACKGROUND_ALPHA, DEFAULT_THEME_BACKGROUND_ALPHA));
mAlphaSlider.setProgress(preferences.getInt(KEY_THEME_BACKGROUND_ALPHA, DEFAULT_THEME_BACKGROUND_ALPHA) - MIN_ALPHA);
final int patternSize = res.getDimensionPixelSize(R.dimen.element_spacing_msmall);
ViewSupport.setBackground(mAlphaPreview, new AlphaPatternDrawable(patternSize));
updateAlphaVisibility();
@ -182,6 +185,10 @@ public class ThemeBackgroundPreference extends DialogPreference implements Const
if (mAlphaPreview == null || mAlphaSlider == null) return;
final Drawable drawable = mAlphaPreview.getDrawable();
if (drawable == null) return;
drawable.setAlpha(mAlphaSlider.getProgress());
drawable.setAlpha(getSliderAlpha());
}
private int getSliderAlpha() {
return mAlphaSlider.getProgress() + MIN_ALPHA;
}
}

View File

@ -70,7 +70,8 @@ public class ThemePreviewPreference extends Preference implements Constants, OnS
@Override
public void onSharedPreferenceChanged(final SharedPreferences preferences, final String key) {
if (KEY_THEME.equals(key) || KEY_THEME_BACKGROUND.equals(key) || KEY_THEME_COLOR.equals(key)) {
if (KEY_THEME.equals(key) || KEY_THEME_BACKGROUND.equals(key) || KEY_THEME_BACKGROUND_ALPHA.equals(key)
|| KEY_THEME_COLOR.equals(key)) {
notifyChanged();
}
}

View File

@ -67,6 +67,7 @@ import org.mariotaku.twidere.R;
import org.mariotaku.twidere.activity.iface.IThemedActivity;
import org.mariotaku.twidere.graphic.ActionBarColorDrawable;
import org.mariotaku.twidere.graphic.ActionIconDrawable;
import org.mariotaku.twidere.preference.ThemeBackgroundPreference;
import org.mariotaku.twidere.text.ParagraphSpacingSpan;
import org.mariotaku.twidere.util.menu.TwidereMenuInfo;
import org.mariotaku.twidere.util.support.ViewSupport;
@ -636,7 +637,13 @@ public class ThemeUtils implements Constants {
public static int getUserThemeBackgroundAlpha(final Context context) {
if (context == null) return DEFAULT_THEME_BACKGROUND_ALPHA;
final SharedPreferencesWrapper pref = getSharedPreferencesWrapper(context);
return pref.getInt(KEY_THEME_BACKGROUND_ALPHA, DEFAULT_THEME_BACKGROUND_ALPHA);
return MathUtils.clamp(pref.getInt(KEY_THEME_BACKGROUND_ALPHA, DEFAULT_THEME_BACKGROUND_ALPHA),
ThemeBackgroundPreference.MIN_ALPHA, ThemeBackgroundPreference.MAX_ALPHA);
}
public static int getActionBarAlpha(final int alpha) {
return MathUtils.clamp(alpha * 2, ThemeBackgroundPreference.MIN_ALPHA,
ThemeBackgroundPreference.MAX_ALPHA);
}
public static Typeface getUserTypeface(final Context context, final Typeface defTypeface) {
@ -687,7 +694,8 @@ public class ThemeUtils implements Constants {
final Drawable d = a.getDrawable(0);
a.recycle();
if (d != null) {
d.setAlpha(alpha);
d.setAlpha(MathUtils.clamp(alpha, ThemeBackgroundPreference.MIN_ALPHA,
ThemeBackgroundPreference.MAX_ALPHA));
}
return d;
}

View File

@ -128,7 +128,7 @@ public class TintedStatusFrameLayout extends ExtendedFrameLayout implements Tint
if (mDrawShadow) {
canvas.drawRect(0, 0, canvas.getWidth(), mStatusBarHeight, mShadowPaint);
} else if (mDrawColor) {
canvas.drawRect(0, 0, canvas.getWidth(), mStatusBarHeight, mBlackPaint);
// canvas.drawRect(0, 0, canvas.getWidth(), mStatusBarHeight, mBlackPaint);
}
canvas.drawRect(0, 0, canvas.getWidth(), mStatusBarHeight, mDrawColor ? mColorPaint : mBlackPaint);
}
@ -146,7 +146,7 @@ public class TintedStatusFrameLayout extends ExtendedFrameLayout implements Tint
private void updateAlpha() {
final float f = mFactor;
mShadowPaint.setAlpha(Math.round(mShadowAlpha * MathUtils.clamp(1 - f, 0, 1)));
mColorPaint.setAlpha(Math.round(0xFF * MathUtils.clamp(f, 0, 1)));
mColorPaint.setAlpha(Math.round(mColorAlpha * MathUtils.clamp(f, 0, 1)));
invalidate();
}
}