mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-01-31 17:04:59 +01:00
improved quick return action bar
This commit is contained in:
parent
6ff44a2eac
commit
bbb756daa8
@ -159,7 +159,7 @@ public class HomeActivity extends BaseSupportActivity implements OnClickListener
|
||||
private HomeSlidingMenu mSlidingMenu;
|
||||
private View mEmptyTabHint;
|
||||
private ProgressBar mSmartBarProgress;
|
||||
private HomeActionsActionView mBottomActionsButton;
|
||||
private HomeActionsActionView mActionsButton;
|
||||
private LeftDrawerFrameLayout mLeftDrawerContainer;
|
||||
private RightDrawerFrameLayout mRightDrawerContainer;
|
||||
|
||||
@ -190,6 +190,7 @@ public class HomeActivity extends BaseSupportActivity implements OnClickListener
|
||||
@Override
|
||||
public void setControlBarOffset(float offset) {
|
||||
mIndicator.setTranslationY(getControlBarHeight() * (offset - 1));
|
||||
mActionsButton.setTranslationY(mActionsButton.getHeight() * (1 - offset));
|
||||
}
|
||||
|
||||
public void notifyAccountsChanged() {
|
||||
@ -242,7 +243,7 @@ public class HomeActivity extends BaseSupportActivity implements OnClickListener
|
||||
mSlidingMenu = (HomeSlidingMenu) findViewById(R.id.home_menu);
|
||||
mViewPager = (ExtendedViewPager) findViewById(R.id.main_pager);
|
||||
mEmptyTabHint = findViewById(R.id.empty_tab_hint);
|
||||
mBottomActionsButton = (HomeActionsActionView) findViewById(R.id.actions_button_bottom);
|
||||
mActionsButton = (HomeActionsActionView) findViewById(R.id.actions_button_bottom);
|
||||
mIndicator = (TabPagerIndicator) findViewById(android.R.id.tabs);
|
||||
}
|
||||
|
||||
@ -442,8 +443,7 @@ public class HomeActivity extends BaseSupportActivity implements OnClickListener
|
||||
|
||||
@Override
|
||||
public int getControlBarHeight() {
|
||||
final int height = mIndicator.getHeight();
|
||||
return Math.round(0.8f * (height != 0 ? height : Utils.getActionBarHeight(this)));
|
||||
return mIndicator.getHeight() - mIndicator.getStripHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -541,8 +541,8 @@ public class HomeActivity extends BaseSupportActivity implements OnClickListener
|
||||
mIndicator.setDisplayLabel(false);
|
||||
mIndicator.setDisplayIcon(true);
|
||||
}
|
||||
mBottomActionsButton.setOnClickListener(this);
|
||||
mBottomActionsButton.setOnLongClickListener(this);
|
||||
mActionsButton.setOnClickListener(this);
|
||||
mActionsButton.setOnLongClickListener(this);
|
||||
initTabs();
|
||||
final boolean tabsNotEmpty = mPagerAdapter.getCount() > 0;
|
||||
mEmptyTabHint.setVisibility(tabsNotEmpty ? View.GONE : View.VISIBLE);
|
||||
@ -825,10 +825,10 @@ public class HomeActivity extends BaseSupportActivity implements OnClickListener
|
||||
}
|
||||
}
|
||||
final boolean hasActivatedTask = hasActivatedTask();
|
||||
if (mBottomActionsButton != null) {
|
||||
mBottomActionsButton.setIcon(icon);
|
||||
mBottomActionsButton.setTitle(title);
|
||||
mBottomActionsButton.setShowProgress(hasActivatedTask);
|
||||
if (mActionsButton != null) {
|
||||
mActionsButton.setIcon(icon);
|
||||
mActionsButton.setTitle(title);
|
||||
mActionsButton.setShowProgress(hasActivatedTask);
|
||||
}
|
||||
if (mSmartBarProgress != null) {
|
||||
mSmartBarProgress.setVisibility(hasActivatedTask ? View.VISIBLE : View.INVISIBLE);
|
||||
@ -836,13 +836,10 @@ public class HomeActivity extends BaseSupportActivity implements OnClickListener
|
||||
}
|
||||
|
||||
private void updateActionsButtonStyle() {
|
||||
if (mBottomActionsButton == null) return;
|
||||
final boolean showBottomActionsButton = !FlymeUtils.hasSmartBar();
|
||||
final boolean leftsideComposeButton = mPreferences.getBoolean(KEY_LEFTSIDE_COMPOSE_BUTTON, false);
|
||||
mBottomActionsButton.setVisibility(View.VISIBLE);
|
||||
final FrameLayout.LayoutParams compose_lp = (LayoutParams) mBottomActionsButton.getLayoutParams();
|
||||
compose_lp.gravity = Gravity.BOTTOM | (leftsideComposeButton ? Gravity.LEFT : Gravity.RIGHT);
|
||||
mBottomActionsButton.setLayoutParams(compose_lp);
|
||||
final FrameLayout.LayoutParams lp = (LayoutParams) mActionsButton.getLayoutParams();
|
||||
lp.gravity = Gravity.BOTTOM | (leftsideComposeButton ? Gravity.LEFT : Gravity.RIGHT);
|
||||
mActionsButton.setLayoutParams(lp);
|
||||
}
|
||||
|
||||
private void updateDrawerPercentOpen(final float percentOpen, final boolean horizontalScroll) {
|
||||
|
@ -30,7 +30,6 @@ import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
@ -59,7 +58,6 @@ import org.mariotaku.twidere.menu.TwidereMenuInflater;
|
||||
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
|
||||
import org.mariotaku.twidere.util.ListScrollDistanceCalculator;
|
||||
import org.mariotaku.twidere.util.ListScrollDistanceCalculator.ScrollDistanceListener;
|
||||
import org.mariotaku.twidere.util.MathUtils;
|
||||
import org.mariotaku.twidere.util.MultiSelectManager;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
@ -435,7 +433,7 @@ public class BaseSupportListFragment extends ListFragment implements IBaseFragme
|
||||
@Override
|
||||
public void onScrollDistanceChanged(int delta, int total) {
|
||||
final FragmentActivity a = getActivity();
|
||||
if (a instanceof HomeActivity) {
|
||||
if (a instanceof HomeActivity && getTabPosition() >= 0) {
|
||||
final HomeActivity home = (HomeActivity) a;
|
||||
home.moveControlBarBy(delta);
|
||||
}
|
||||
|
@ -22,15 +22,17 @@ import org.mariotaku.twidere.view.iface.PagerIndicator;
|
||||
public class TabPagerIndicator extends RecyclerView implements PagerIndicator {
|
||||
|
||||
private final TabPagerIndicatorAdapter mAdapter;
|
||||
private final int mStripHeight;
|
||||
private PagerAdapter mTabProvider;
|
||||
private ViewPager mViewPager;
|
||||
private OnPageChangeListener mPageChangeListener;
|
||||
|
||||
public TabPagerIndicator(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
|
||||
setLayoutManager(new TabLayoutManager(this));
|
||||
mAdapter = new TabPagerIndicatorAdapter(this);
|
||||
setAdapter(mAdapter);
|
||||
mStripHeight = getResources().getDimensionPixelSize(R.dimen.element_spacing_small);
|
||||
}
|
||||
|
||||
public TabPagerIndicator(Context context, AttributeSet attrs) {
|
||||
@ -48,7 +50,7 @@ public class TabPagerIndicator extends RecyclerView implements PagerIndicator {
|
||||
|
||||
@Override
|
||||
public void setCurrentItem(int item) {
|
||||
|
||||
mViewPager.setCurrentItem(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -80,6 +82,7 @@ public class TabPagerIndicator extends RecyclerView implements PagerIndicator {
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
mAdapter.notifyDataSetChanged();
|
||||
if (mPageChangeListener == null) return;
|
||||
mPageChangeListener.onPageSelected(position);
|
||||
}
|
||||
@ -106,7 +109,11 @@ public class TabPagerIndicator extends RecyclerView implements PagerIndicator {
|
||||
|
||||
}
|
||||
|
||||
private static class TabPagerIndicatorAdapter extends Adapter<TabItemHolder> {
|
||||
public int getStripHeight() {
|
||||
return mStripHeight;
|
||||
}
|
||||
|
||||
private static class TabPagerIndicatorAdapter extends Adapter<TabItemHolder> implements OnClickListener, OnLongClickListener {
|
||||
|
||||
private final TabPagerIndicator mIndicator;
|
||||
private final LayoutInflater mInflater;
|
||||
@ -120,12 +127,21 @@ public class TabPagerIndicator extends RecyclerView implements PagerIndicator {
|
||||
|
||||
@Override
|
||||
public TabItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new TabItemHolder(mInflater.inflate(R.layout.tab_item_home, parent, false));
|
||||
final View view = mInflater.inflate(R.layout.tab_item_home, parent, false);
|
||||
view.setOnClickListener(this);
|
||||
view.setOnLongClickListener(this);
|
||||
final View selectedIndicator = view.findViewById(R.id.selected_indicator);
|
||||
final ViewGroup.LayoutParams lp = selectedIndicator.getLayoutParams();
|
||||
lp.height = mIndicator.getStripHeight();
|
||||
selectedIndicator.setLayoutParams(lp);
|
||||
return new TabItemHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(TabItemHolder holder, int position) {
|
||||
holder.setTabData(mTabProvider.getPageIcon(position), mTabProvider.getPageTitle(position));
|
||||
final Drawable icon = mTabProvider.getPageIcon(position);
|
||||
final CharSequence title = mTabProvider.getPageTitle(position);
|
||||
holder.setTabData(position, icon, title, mIndicator.getCurrentItem() == position);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -138,21 +154,75 @@ public class TabPagerIndicator extends RecyclerView implements PagerIndicator {
|
||||
mTabProvider = tabProvider;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final Object tag = v.getTag();
|
||||
if (!(tag instanceof Integer)) return;
|
||||
mIndicator.dispatchTabClick((Integer) tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
final Object tag = v.getTag();
|
||||
if (!(tag instanceof Integer)) return false;
|
||||
return mIndicator.dispatchTabLongClick((Integer) tag);
|
||||
}
|
||||
}
|
||||
|
||||
private void dispatchTabClick(int position) {
|
||||
setCurrentItem(position);
|
||||
}
|
||||
|
||||
private boolean dispatchTabLongClick(int position) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private int getCurrentItem() {
|
||||
return mViewPager.getCurrentItem();
|
||||
}
|
||||
|
||||
private static class TabItemHolder extends ViewHolder {
|
||||
|
||||
private final View itemView;
|
||||
private final ImageView iconView;
|
||||
private final View selectedIndicator;
|
||||
|
||||
public TabItemHolder(View itemView) {
|
||||
super(itemView);
|
||||
iconView = (ImageView) itemView.findViewById(android.R.id.icon);
|
||||
this.itemView = itemView;
|
||||
selectedIndicator = itemView.findViewById(R.id.selected_indicator);
|
||||
iconView = (ImageView) itemView.findViewById(R.id.tab_icon);
|
||||
}
|
||||
|
||||
|
||||
public void setTabData(Drawable icon, CharSequence title) {
|
||||
public void setTabData(int position, Drawable icon, CharSequence title, boolean activated) {
|
||||
itemView.setTag(position);
|
||||
itemView.setContentDescription(title);
|
||||
iconView.setImageDrawable(icon);
|
||||
iconView.setContentDescription(title);
|
||||
selectedIndicator.setActivated(activated);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TabLayoutManager extends LinearLayoutManager {
|
||||
|
||||
private final TabPagerIndicator mIndicator;
|
||||
|
||||
public TabLayoutManager(TabPagerIndicator indicator) {
|
||||
super(indicator.getContext(), HORIZONTAL, false);
|
||||
mIndicator = indicator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void measureChildWithMargins(View child, int widthUsed, int heightUsed) {
|
||||
final int count = mIndicator.getCount();
|
||||
if (count == 0) return;
|
||||
final int parentHeight = mIndicator.getHeight(), parentWidth = mIndicator.getWidth();
|
||||
final int width = Math.max(parentWidth / count, parentHeight);
|
||||
final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(parentHeight, MeasureSpec.EXACTLY);
|
||||
final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY);
|
||||
child.measure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
<org.mariotaku.twidere.view.TabPagerIndicator
|
||||
android:id="@android:id/tabs"
|
||||
style="?android:actionBarStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?android:actionBarSize"/>
|
||||
|
||||
|
@ -1,14 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?android:selectableItemBackground">
|
||||
|
||||
<View
|
||||
android:id="@+id/selected_indicator"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:background="?android:activatedBackgroundIndicator"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/tab_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:id="@android:id/icon"
|
||||
android:layout_height="wrap_content"/>
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
Loading…
x
Reference in New Issue
Block a user