fixed layout

This commit is contained in:
Mariotaku Lee 2015-04-28 01:57:39 +08:00
parent a8744f499d
commit e99a370146
8 changed files with 82 additions and 37 deletions

View File

@ -31,6 +31,7 @@ import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.NavUtils;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.internal.widget.ActionBarContainer;
import android.support.v7.internal.widget.NativeActionModeAwareLayout;
import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.Toolbar;
@ -77,7 +78,7 @@ public class LinkHandlerActivity extends BaseAppCompatActivity implements System
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
if (left != oldLeft && top != oldTop && right != oldRight && bottom != oldBottom) {
if (left != oldLeft || top != oldTop || right != oldRight || bottom != oldBottom) {
mMainContent.getSystemWindowsInsets(tempInsets);
onFitSystemWindows(tempInsets);
}
@ -85,9 +86,12 @@ public class LinkHandlerActivity extends BaseAppCompatActivity implements System
};
private TintedStatusFrameLayout mMainContent;
private View mActionBarOverlay;
private ActionBarContainer mActionBarContainer;
private boolean mFinishOnly;
private int mActionBarItemsColor;
private int mActionBarHeight;
@Override
@ -191,14 +195,16 @@ public class LinkHandlerActivity extends BaseAppCompatActivity implements System
setContentView(R.layout.activity_content_fragment);
setSupportActionBar((Toolbar) findViewById(R.id.action_bar));
final NativeActionModeAwareLayout layout = (NativeActionModeAwareLayout) findViewById(android.R.id.content);
mTwidereActionModeForChildListener = new TwidereActionModeForChildListener(this, this, false);
final NativeActionModeAwareLayout layout = (NativeActionModeAwareLayout) findViewById(android.R.id.content);
layout.setActionModeForChildListener(mTwidereActionModeForChildListener);
ThemeUtils.setCompatContentViewOverlay(this, new EmptyDrawable());
final View actionBarContainer = findViewById(R.id.twidere_action_bar_container);
ViewCompat.setElevation(actionBarContainer, ThemeUtils.getSupportActionBarElevation(this));
ViewSupport.setOutlineProvider(actionBarContainer, ViewOutlineProviderCompat.BACKGROUND);
final View windowOverlay = findViewById(R.id.window_overlay);
ViewSupport.setBackground(windowOverlay, ThemeUtils.getNormalWindowContentOverlay(this, getCurrentThemeResourceId()));
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
@ -215,16 +221,16 @@ public class LinkHandlerActivity extends BaseAppCompatActivity implements System
@Override
protected void onStart() {
mMainContent.addOnLayoutChangeListener(mLayoutChangeListener);
super.onStart();
mMultiSelectHandler.dispatchOnStart();
mMainContent.addOnLayoutChangeListener(mLayoutChangeListener);
}
@Override
protected void onStop() {
mMainContent.removeOnLayoutChangeListener(mLayoutChangeListener);
mMultiSelectHandler.dispatchOnStop();
super.onStop();
mMainContent.removeOnLayoutChangeListener(mLayoutChangeListener);
}
@Override
@ -264,6 +270,8 @@ 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_overlay);
mActionBarContainer = (ActionBarContainer) findViewById(R.id.twidere_action_bar_container);
}
protected boolean shouldSetActionItemColor() {
@ -322,17 +330,16 @@ public class LinkHandlerActivity extends BaseAppCompatActivity implements System
final int themeId = getCurrentThemeResourceId();
final String option = getThemeBackgroundOption();
int actionBarItemsColor = ThemeUtils.getContrastActionBarItemColor(this, themeId, themeColor);
final ActionBarContainer actionBarContainer = (ActionBarContainer) findViewById(R.id.twidere_action_bar_container);
switch (linkId) {
case LINK_ID_SEARCH:
case LINK_ID_USER_LISTS:
case LINK_ID_FILTERS: {
ThemeUtils.applyActionBarBackground(actionBar, this, themeId, themeColor, option, false);
ThemeUtils.applyActionBarBackground(getActionBar(), this, themeId, themeColor, option, true);
ThemeUtils.applyActionBarBackground(actionBarContainer, this, themeId, themeColor, option, false);
break;
}
default: {
ThemeUtils.applyActionBarBackground(actionBar, this, themeId, themeColor, option, true);
ThemeUtils.applyActionBarBackground(getActionBar(), this, themeId, themeColor, option, true);
ThemeUtils.applyActionBarBackground(actionBarContainer, this, themeId, themeColor, option, true);
break;
}
}
@ -525,22 +532,22 @@ public class LinkHandlerActivity extends BaseAppCompatActivity implements System
@Override
public void setControlBarOffset(float offset) {
final Toolbar toolbar = peekActionBarToolbar();
if (toolbar == null) return;
toolbar.setTranslationY(-Math.round((1 - offset) * getControlBarHeight()));
mActionBarContainer.setTranslationY(-Math.round((1 - offset) * getControlBarHeight()));
notifyControlBarOffsetChanged();
}
@Override
public float getControlBarOffset() {
final Toolbar toolbar = peekActionBarToolbar();
return toolbar != null ? 1 + toolbar.getTranslationY() / (float) getControlBarHeight() : 0;
return 1 + mActionBarContainer.getTranslationY() / (float) getControlBarHeight();
}
@Override
public int getControlBarHeight() {
final Toolbar toolbar = peekActionBarToolbar();
return toolbar != null ? toolbar.getHeight() : 0;
if (mActionBarHeight != 0) return mActionBarHeight;
return mActionBarHeight = ThemeUtils.getActionBarHeight(this);
}
public ActionBarContainer getActionBarContainer() {
return mActionBarContainer;
}
}

View File

@ -46,10 +46,11 @@ import org.mariotaku.twidere.view.TabPagerIndicator;
public class FiltersFragment extends BaseSupportFragment implements RefreshScrollTopInterface,
SupportFragmentCallback, IBaseFragment.SystemWindowsInsetsCallback {
private SupportTabsAdapter mPagerAdapter;
private TabPagerIndicator mPagerIndicator;
private ViewPager mViewPager;
private SupportTabsAdapter mPagerAdapter;
private View mPagerOverlay;
@Nullable
@Override
@ -73,7 +74,7 @@ public class FiltersFragment extends BaseSupportFragment implements RefreshScrol
mPagerAdapter.addTab(FilteredSourcesFragment.class, null, getString(R.string.sources), null, 2, null);
mPagerAdapter.addTab(FilteredLinksFragment.class, null, getString(R.string.links), null, 3, null);
ThemeUtils.initPagerIndicatorAsActionBarTab(activity, mPagerIndicator);
ThemeUtils.initPagerIndicatorAsActionBarTab(activity, mPagerIndicator, mPagerOverlay);
ThemeUtils.setCompatToolbarOverlay(activity, new EmptyDrawable());
ThemeUtils.setCompatContentViewOverlay(activity, new EmptyDrawable());
ThemeUtils.setWindowOverlayViewOverlay(activity, new EmptyDrawable());
@ -84,6 +85,7 @@ public class FiltersFragment extends BaseSupportFragment implements RefreshScrol
super.onBaseViewCreated(view, savedInstanceState);
mViewPager = (ViewPager) view.findViewById(R.id.view_pager);
mPagerIndicator = (TabPagerIndicator) view.findViewById(R.id.view_pager_tabs);
mPagerOverlay = view.findViewById(R.id.pager_window_overlay);
}
@Override

View File

@ -164,7 +164,7 @@ public class SearchFragment extends BaseSupportFragment implements RefreshScroll
mPagerIndicator.setViewPager(mViewPager);
mPagerIndicator.setTabDisplayOption(TabPagerIndicator.LABEL);
mPagerIndicator.setOnPageChangeListener(this);
ThemeUtils.initPagerIndicatorAsActionBarTab(activity, mPagerIndicator);
ThemeUtils.initPagerIndicatorAsActionBarTab(activity, mPagerIndicator, mPagerWindowOverlay);
ThemeUtils.setCompatToolbarOverlay(activity, new EmptyDrawable());
ThemeUtils.setCompatContentViewOverlay(activity, new EmptyDrawable());
ThemeUtils.setWindowOverlayViewOverlay(activity, new EmptyDrawable());

View File

@ -60,6 +60,7 @@ import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.internal.widget.ActionBarContainer;
import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.Toolbar;
import android.text.Html;
@ -188,6 +189,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
private HeaderDrawerLayout mHeaderDrawerLayout;
private ViewPager mViewPager;
private TabPagerIndicator mPagerIndicator;
private View mPagerOverlay;
private View mUuckyFooter;
private View mProfileBannerContainer;
private Button mFollowButton;
@ -200,7 +202,6 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
private ActionBarDrawable mActionBarBackground;
private Drawable mActionBarHomeAsUpIndicator;
private SupportTabsAdapter mPagerAdapter;
private ParcelableUser mUser;
@ -778,6 +779,11 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
final float actionBarElevation = ThemeUtils.getSupportActionBarElevation(activity);
ViewCompat.setElevation(mPagerIndicator, actionBarElevation);
if (activity instanceof IThemedActivity) {
ViewSupport.setBackground(mPagerOverlay, ThemeUtils.getNormalWindowContentOverlay(activity,
((IThemedActivity) activity).getCurrentThemeResourceId()));
}
setupBaseActionBar();
setupUserPages();
if (activity instanceof IThemedActivity) {
@ -1068,6 +1074,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
mProfileBannerSpace = headerView.findViewById(R.id.profile_banner_space);
mViewPager = (ViewPager) contentView.findViewById(R.id.view_pager);
mPagerIndicator = (TabPagerIndicator) contentView.findViewById(R.id.view_pager_tabs);
mPagerOverlay = (View) contentView.findViewById(R.id.pager_window_overlay);
mFollowButton = (Button) headerView.findViewById(R.id.follow);
mFollowProgress = (ProgressBar) headerView.findViewById(R.id.follow_progress);
mUuckyFooter = headerView.findViewById(R.id.uucky_footer);
@ -1367,8 +1374,9 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
final FragmentActivity activity = getActivity();
if (!(activity instanceof LinkHandlerActivity)) return;
final LinkHandlerActivity linkHandler = (LinkHandlerActivity) activity;
final ActionBarContainer actionBarContainer = linkHandler.getActionBarContainer();
final ActionBar actionBar = linkHandler.getSupportActionBar();
if (actionBar == null) return;
if (actionBarContainer == null || actionBar == null) return;
final Drawable shadow = ResourcesCompat.getDrawable(activity.getResources(), R.drawable.shadow_user_banner_action_bar, null);
mActionBarBackground = new ActionBarDrawable(shadow);
if (!ThemeUtils.isWindowFloating(linkHandler, linkHandler.getCurrentThemeResourceId())
@ -1376,9 +1384,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
mActionBarBackground.setAlpha(linkHandler.getCurrentThemeBackgroundAlpha());
mProfileBannerView.setAlpha(linkHandler.getCurrentThemeBackgroundAlpha() / 255f);
}
actionBar.setBackgroundDrawable(mActionBarBackground);
mActionBarHomeAsUpIndicator = ThemeUtils.getActionBarHomeAsUpIndicator(actionBar);
actionBar.setHomeAsUpIndicator(mActionBarHomeAsUpIndicator);
actionBarContainer.setPrimaryBackground(mActionBarBackground);
}
private void setupUserPages() {
@ -1492,16 +1498,17 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
}
final int barColor = (Integer) sArgbEvaluator.evaluate(factor, mActionBarShadowColor, stackedTabColor);
final int itemColor = ThemeUtils.getContrastActionBarItemColor(activity, themeId, barColor);
if (mActionBarHomeAsUpIndicator != null) {
mActionBarHomeAsUpIndicator.setColorFilter(itemColor, Mode.SRC_ATOP);
}
final Toolbar actionBarView = activity.getActionBarToolbar();
if (actionBarView != null) {
final Toolbar toolbar = actionBarView;
toolbar.setTitleTextColor(itemColor);
toolbar.setSubtitleTextColor(itemColor);
ThemeUtils.setActionBarOverflowColor(toolbar, itemColor);
actionBarView.setTitleTextColor(itemColor);
actionBarView.setSubtitleTextColor(itemColor);
ThemeUtils.setActionBarOverflowColor(actionBarView, itemColor);
ThemeUtils.wrapToolbarMenuIcon(ViewSupport.findViewByType(actionBarView, ActionMenuView.class), itemColor, itemColor);
final Drawable navigationIcon = actionBarView.getNavigationIcon();
if (navigationIcon != null) {
navigationIcon.setColorFilter(itemColor, Mode.SRC_ATOP);
}
actionBarView.setNavigationIcon(navigationIcon);
}
mPagerIndicator.updateAppearance();
}

View File

@ -41,9 +41,10 @@ public class UserListsFragment extends BaseSupportFragment implements RefreshScr
SupportFragmentCallback, SystemWindowsInsetsCallback {
private ViewPager mViewPager;
private TabPagerIndicator mPagerIndicator;
private View mPagerOverlay;
private SupportTabsAdapter mPagerAdapter;
private TabPagerIndicator mPagerIndicator;
@Override
public void onActivityCreated(final Bundle savedInstanceState) {
@ -59,7 +60,7 @@ public class UserListsFragment extends BaseSupportFragment implements RefreshScr
mPagerAdapter.addTab(UserListsListFragment.class, args, getString(R.string.follows), null, 0, null);
mPagerAdapter.addTab(UserListMembershipsListFragment.class, args, getString(R.string.belongs_to), 0, 1, null);
ThemeUtils.initPagerIndicatorAsActionBarTab(activity, mPagerIndicator);
ThemeUtils.initPagerIndicatorAsActionBarTab(activity, mPagerIndicator, mPagerOverlay);
ThemeUtils.setCompatToolbarOverlay(activity, new EmptyDrawable());
ThemeUtils.setCompatContentViewOverlay(activity, new EmptyDrawable());
ThemeUtils.setWindowOverlayViewOverlay(activity, new EmptyDrawable());
@ -76,6 +77,7 @@ public class UserListsFragment extends BaseSupportFragment implements RefreshScr
super.onBaseViewCreated(view, savedInstanceState);
mViewPager = (ViewPager) view.findViewById(R.id.view_pager);
mPagerIndicator = (TabPagerIndicator) view.findViewById(R.id.view_pager_tabs);
mPagerOverlay = view.findViewById(R.id.pager_window_overlay);
}
@Override

View File

@ -44,6 +44,7 @@ import android.support.v7.internal.view.StandaloneActionMode;
import android.support.v7.internal.view.SupportActionModeWrapper;
import android.support.v7.internal.view.SupportActionModeWrapperTrojan;
import android.support.v7.internal.view.menu.ActionMenuItemView;
import android.support.v7.internal.widget.ActionBarContainer;
import android.support.v7.internal.widget.ActionBarContextView;
import android.support.v7.internal.widget.ActionBarOverlayLayout;
import android.support.v7.internal.widget.ContentFrameLayout;
@ -118,6 +119,15 @@ public class ThemeUtils implements Constants {
}
public static void applyActionBarBackground(final ActionBarContainer actionBar, final Context context,
final int themeRes, final int accentColor, String backgroundOption, boolean outlineEnabled) {
if (actionBar == null || context == null) return;
actionBar.setPrimaryBackground(getActionBarBackground(context, themeRes, accentColor, backgroundOption, outlineEnabled));
actionBar.setSplitBackground(getActionBarSplitBackground(context, themeRes));
actionBar.setStackedBackground(getActionBarStackedBackground(context, themeRes, accentColor, outlineEnabled));
}
public static void applyBackground(final View view) {
if (view == null) return;
applyBackground(view, getUserAccentColor(view.getContext()));
@ -733,6 +743,14 @@ public class ThemeUtils implements Constants {
}
public static int getThemeResource(final int otherTheme) {
if (isDarkTheme(otherTheme)) {
return R.style.Theme_Twidere_Dark;
}
return R.style.Theme_Twidere_Light;
}
public static int getNoActionBarThemeResource(final Context context) {
return getNoActionBarThemeResource(getThemeNameOption(context));
}
@ -865,7 +883,12 @@ public class ThemeUtils implements Constants {
}
}
public static void initPagerIndicatorAsActionBarTab(FragmentActivity activity, TabPagerIndicator indicator) {
public static Drawable getNormalWindowContentOverlay(final Context context, int themeRes) {
final int normalThemeResId = ThemeUtils.getThemeResource(themeRes);
return getWindowContentOverlay(context, normalThemeResId);
}
public static void initPagerIndicatorAsActionBarTab(FragmentActivity activity, TabPagerIndicator indicator, @Nullable View pagerOverlay) {
final float supportActionBarElevation = getSupportActionBarElevation(activity);
ViewCompat.setElevation(indicator, supportActionBarElevation);
if (!(activity instanceof IThemedActivity)) return;
@ -881,8 +904,8 @@ public class ThemeUtils implements Constants {
colorDark = textColors[0];
colorLight = textColors[1];
}
final int contrastColor = TwidereColorUtils.getContrastYIQ(themeColor,
ACCENT_COLOR_THRESHOLD, colorDark, colorLight);
final int contrastColor = TwidereColorUtils.getContrastYIQ(themeColor, ACCENT_COLOR_THRESHOLD,
colorDark, colorLight);
ViewSupport.setBackground(indicator, getActionBarStackedBackground(activity, themeRes, themeColor, true));
if (isDarkTheme(themeRes)) {
final int foregroundColor = getThemeForegroundColor(activity);
@ -895,6 +918,9 @@ public class ThemeUtils implements Constants {
indicator.setStripColor(contrastColor);
}
indicator.updateAppearance();
if (pagerOverlay != null) {
ViewSupport.setBackground(pagerOverlay, getNormalWindowContentOverlay(activity, themeRes));
}
}
public static boolean isColoredActionBar(int themeRes) {

View File

@ -56,7 +56,7 @@ public class ProfileBannerSpace extends View {
@Override
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
final int insetsTop = mSystemWindowsInsets.top;
final int top = insetsTop < mActionBarHeight ? insetsTop + mActionBarHeight : insetsTop;
final int top = insetsTop <= 0 || insetsTop < mActionBarHeight ? insetsTop + mActionBarHeight : insetsTop;
final int width = MeasureSpec.getSize(widthMeasureSpec), height = width / 2 - top;
setMeasuredDimension(width, height);
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));

View File

@ -30,6 +30,7 @@
android:layout_height="match_parent" />
<RelativeLayout
android:id="@+id/twidere_action_bar_overlay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">