@Override public void onTabReselected(TabLayout.Tab tab) { mAppBar.setExpanded(true, true); } });
@OnFocusChange({R.id.et_gist_description, R.id.et_gist_name, R.id.cb_public}) protected void expandAppBarOnFocusChangeListener(View v, boolean hasFocus) { if (hasFocus) { appBarLayout.setExpanded(true); } }
@Override public void onPause() { super.onPause(); if (isHasImage) { appBarLayout.setExpanded(false); } }
private void longPress(@Direction int direction) { switch (direction) { case DIRECTION_DOWN: case DIRECTION_NONE: default: break; case DIRECTION_UP: if (mAppBarEnabled && mAppBarLayout != null) { mAppBarLayout.setExpanded(true, true); } if (mScrollable != null) { mScrollable.scrollToTop(); } break; } }
@OnCheckedChanged(R.id.cb_public) @OnTextChanged(value = {R.id.et_gist_description, R.id.et_gist_name, R.id.cb_public}) protected void expandAppBarOnChange() { appBarLayout.setExpanded(true); }
@Override public boolean onLongClick(View v) { // 触发一次刷新 ((AsToolbar) getToolbar()).performDoublcClick(); appBarLayout.setExpanded(true); return true; }
private void setFragemnt(final Fragment fragment, CharSequence title) { if (fragment == null) return; toolbarTitle = title.toString(); getSupportActionBar().setTitle(toolbarTitle); // 如果是TabsFragment,显示TabLayout if (fragment instanceof ATabsFragment) { tabLayout.setVisibility(View.VISIBLE); } else { tabLayout.setVisibility(View.GONE); } // 显示AppBarLayout appBarLayout.setExpanded(true, true); // .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE) View view = findViewById(R.id.content_frame); view.setAlpha(0.0f); ObjectAnimator anim = ObjectAnimator.ofFloat(view, "alpha", view.getAlpha(), 1.0f); anim.setDuration(600); anim.start(); getFragmentManager().beginTransaction().replace(R.id.content_frame, fragment, "MainFragment").commit(); }
private void shortPress(@Direction int direction) { if (mScrollable == null) { return; } switch (direction) { case DIRECTION_UP: if (!mScrollable.scrollToPrevious() && mAppBarEnabled && mAppBarLayout != null) { mAppBarLayout.setExpanded(true, true); } break; case DIRECTION_DOWN: if (mAppBarEnabled && mAppBarLayout != null && mAppBarLayout.getHeight() == mAppBarLayout.getBottom()) { mAppBarLayout.setExpanded(false, true); } else { mScrollable.scrollToNext(); } break; case DIRECTION_NONE: default: break; } }
public static void navigate(int direction, AppBarLayout appBarLayout, Navigable navigable) { switch (direction) { case Navigable.DIRECTION_DOWN: case Navigable.DIRECTION_RIGHT: if (appBarLayout.getBottom() == 0) { navigable.onNavigate(direction); } else { appBarLayout.setExpanded(false, true); } break; default: navigable.onNavigate(direction); break; } }
@Synthetic void setFullscreen() { mAppBar.setExpanded(!mFullscreen, true); mTabLayout.setVisibility(mFullscreen ? View.GONE : View.VISIBLE); mListView.setVisibility(mFullscreen ? View.GONE : View.VISIBLE); mKeyDelegate.setAppBarEnabled(!mFullscreen); mViewPager.setSwipeEnabled(!mFullscreen); AppUtils.toggleFab(mReplyButton, !mFullscreen); }
@Synthetic void setFullscreen() { mSystemUiHelper.setFullscreen(mFullscreen); mAppBar.setExpanded(!mFullscreen, true); mKeyDelegate.setAppBarEnabled(!mFullscreen); mViewPager.setSwipeEnabled(!mFullscreen); AppUtils.toggleFab(mReplyButton, !mFullscreen); }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { switch (Item.values()[position % Item.values().length]) { case 折叠: mAppBarLayout.setExpanded(false, true); mAppBarLayout.setEnabled(false); mRecyclerView.setNestedScrollingEnabled(false); break; case 展开: mAppBarLayout.setEnabled(true); mAppBarLayout.setExpanded(true, true); mRecyclerView.setNestedScrollingEnabled(true); break; case 蓝色主题: setThemeColor(R.color.colorPrimary, R.color.colorPrimaryDark); break; case 绿色主题: setThemeColor(android.R.color.holo_green_light, android.R.color.holo_green_dark); break; case 红色主题: setThemeColor(android.R.color.holo_red_light, android.R.color.holo_red_dark); break; case 橙色主题: setThemeColor(android.R.color.holo_orange_light, android.R.color.holo_orange_dark); break; } mRefreshLayout.autoRefresh(); }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { switch (Item.values()[position % Item.values().length]) { case 折叠: mAppBarLayout.setExpanded(false, true); mAppBarLayout.setEnabled(false); mRecyclerView.setNestedScrollingEnabled(false); break; case 展开: mAppBarLayout.setEnabled(true); mAppBarLayout.setExpanded(true, true); mRecyclerView.setNestedScrollingEnabled(true); break; case 蓝色主题: setThemeColor(R.color.colorPrimary, R.color.colorPrimaryDark); break; case 绿色主题: setThemeColor(android.R.color.holo_green_light, android.R.color.holo_green_dark); break; case 红色主题: setThemeColor(android.R.color.holo_red_light, android.R.color.holo_red_dark); break; case 橙色主题: setThemeColor(android.R.color.holo_orange_light, android.R.color.holo_orange_dark); break; } mRefreshLayout.autoRefresh(); }
private void setupAppBarLayout(Bundle savedInstanceState) { // 随着ToolBar的移动,来控制Fab的显示和隐藏 // appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { // // @Override // public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { // float percent = Math.abs(verticalOffset) * 1.0f / SystemUtils.getActionBarHeight(MainActivity.this); // // int translationY = fabBtn.getHeight() + getResources().getDimensionPixelSize(R.dimen.fab_spacing); // fabBtn.setTranslationY(translationY * (percent)); // } // // }); if (savedInstanceState != null) { Fragment fragment = getFragmentManager().findFragmentByTag("MainFragment"); // 如果是TabsFragment,显示TabLayout if (fragment != null) { if (fragment instanceof ATabsFragment) { tabLayout.setVisibility(View.VISIBLE); } else { tabLayout.setVisibility(View.GONE); } // 显示AppBarLayout appBarLayout.setExpanded(true, true); } } }
@Test public void testOnKeyUp() { KeyEvent keyEvent = mock(KeyEvent.class); when(keyEvent.getFlags()).thenReturn(KeyEvent.FLAG_CANCELED_LONG_PRESS); assertFalse(delegate.onKeyUp(KeyEvent.KEYCODE_BACK, keyEvent)); assertFalse(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_UP, keyEvent)); assertFalse(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_DOWN, keyEvent)); KeyEvent keyEventVolUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_UP), keyEventVolDown = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_DOWN); assertTrue(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_UP, keyEventVolUp)); verify(scrollable).scrollToPrevious(); verify(appBar).setExpanded(eq(true), anyBoolean()); reset(scrollable, appBar); when(scrollable.scrollToPrevious()).thenReturn(true); assertTrue(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_UP, keyEventVolUp)); verify(scrollable).scrollToPrevious(); verify(appBar, never()).setExpanded(eq(true), anyBoolean()); reset(scrollable, appBar); when(appBar.getHeight()).thenReturn(10); when(appBar.getBottom()).thenReturn(10); assertTrue(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_DOWN, keyEventVolDown)); verify(scrollable, never()).scrollToNext(); verify(appBar).setExpanded(eq(false), anyBoolean()); reset(scrollable, appBar); when(appBar.getHeight()).thenReturn(10); when(appBar.getBottom()).thenReturn(0); assertTrue(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_DOWN, keyEventVolDown)); verify(scrollable).scrollToNext(); verify(appBar, never()).setExpanded(eq(false), anyBoolean()); }
@Test public void testOnKeyLongPress() { assertFalse(delegate.onKeyLongPress(KeyEvent.KEYCODE_BACK, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK))); assertTrue(delegate.onKeyLongPress(KeyEvent.KEYCODE_VOLUME_UP, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_UP))); verify(appBar).setExpanded(eq(true), anyBoolean()); verify(scrollable).scrollToTop(); assertTrue(delegate.onKeyLongPress(KeyEvent.KEYCODE_VOLUME_DOWN, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_DOWN))); }
@Test public void testNavigate() { AppBarLayout appBar = mock(AppBarLayout.class); when(appBar.getBottom()).thenReturn(1); Navigable navigable = mock(Navigable.class); AppUtils.navigate(Navigable.DIRECTION_DOWN, appBar, navigable); verify(appBar).setExpanded(eq(false), anyBoolean()); verify(navigable, never()).onNavigate(anyInt()); when(appBar.getBottom()).thenReturn(0); AppUtils.navigate(Navigable.DIRECTION_DOWN, appBar, navigable); verify(navigable).onNavigate(eq(Navigable.DIRECTION_DOWN)); AppUtils.navigate(Navigable.DIRECTION_RIGHT, appBar, navigable); verify(navigable).onNavigate(eq(Navigable.DIRECTION_RIGHT)); AppUtils.navigate(Navigable.DIRECTION_UP, appBar, navigable); verify(navigable).onNavigate(eq(Navigable.DIRECTION_UP)); AppUtils.navigate(Navigable.DIRECTION_LEFT, appBar, navigable); verify(navigable).onNavigate(eq(Navigable.DIRECTION_LEFT)); } }
@Override public void onUnmorphEnd() { if (mShowingFromAppBar) { mFab.show(); } if (mShowingFromNormal) { mAppBar.setExpanded(true, true); } mShowingFromAppBar = false; mShowingFromNormal = false; }
@Override public void onClick(View view) { mAppBar.setExpanded(false, true); mFloatingToolbar.attachFab(mFab); mFloatingToolbar.show(); mShowingFromNormal = true; } });
@Override public boolean onQueryTextSubmit(String query) { adapter.filter(viewPager.getCurrentItem(), query.toLowerCase()); appbar.setExpanded(true); return true; }