use of android.support.v4.widget.NestedScrollView in project smooth-app-bar-layout by henrytao-me.
the class BaseBehavior method initScrollTarget.
private void initScrollTarget(final CoordinatorLayout coordinatorLayout, final AppBarLayout child) {
Utils.log("initScrollTarget | %b", vScrollTarget != null);
if (vScrollTarget != null) {
long tag = getViewTag(vScrollTarget, true);
if (!mScrollTargets.contains(tag)) {
mScrollTargets.add(tag);
OnScrollListener listener = new OnScrollListener() {
@Override
public void onScrollChanged(View view, int x, int y, int dx, int dy, boolean accuracy) {
if (view == vScrollTarget) {
BaseBehavior.this.onScrollChanged(coordinatorLayout, child, view, y, dy, accuracy);
}
}
};
if (vScrollTarget instanceof NestedScrollView) {
ObservableNestedScrollView.newInstance((NestedScrollView) vScrollTarget, mOverrideOnScrollListener, listener);
} else if (vScrollTarget instanceof RecyclerView) {
ObservableRecyclerView.newInstance((RecyclerView) vScrollTarget, listener);
}
}
}
}
use of android.support.v4.widget.NestedScrollView in project material-components-android by material-components.
the class BottomSheetBehaviorTest method testNestedScroll.
@Test
@MediumTest
public void testNestedScroll() throws Throwable {
final ViewGroup bottomSheet = getBottomSheet();
final BottomSheetBehavior behavior = getBehavior();
final NestedScrollView scroll = new NestedScrollView(activityTestRule.getActivity());
// Set up nested scrolling area
activityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
bottomSheet.addView(scroll, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
TextView view = new TextView(activityTestRule.getActivity());
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 500; ++i) {
sb.append("It is fine today. ");
}
view.setText(sb);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Do nothing
}
});
scroll.addView(view);
assertThat(behavior.getState(), is(BottomSheetBehavior.STATE_COLLAPSED));
// The scroll offset is 0 at first
assertThat(scroll.getScrollY(), is(0));
}
});
// Swipe from the very bottom of the bottom sheet to the top edge of the screen so that the
// scrolling content is also scrolled
Espresso.onView(ViewMatchers.withId(R.id.coordinator)).perform(new GeneralSwipeAction(Swipe.SLOW, new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
return new float[] { view.getWidth() / 2, view.getHeight() - 1 };
}
}, new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
return new float[] { view.getWidth() / 2, 1 };
}
}, Press.FINGER));
registerIdlingResourceCallback();
try {
Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
activityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
assertThat(behavior.getState(), is(BottomSheetBehavior.STATE_EXPANDED));
// This confirms that the nested scrolling area was scrolled continuously after
// the bottom sheet is expanded.
assertThat(scroll.getScrollY(), is(not(0)));
}
});
} finally {
unregisterIdlingResourceCallback();
}
}
use of android.support.v4.widget.NestedScrollView in project Reader by TheKeeperOfPie.
the class FragmentNewMessage method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_new_message, container, false);
layoutCoordinator = (CoordinatorLayout) view.findViewById(R.id.layout_coordinator);
layoutAppBar = (AppBarLayout) view.findViewById(R.id.layout_app_bar);
scrollText = (NestedScrollView) view.findViewById(R.id.scroll_text);
textAuthor = (TextView) view.findViewById(R.id.text_author);
textAuthor.setText(getString(R.string.sending_from) + " " + controllerUser.getUser().getName());
editTextRecipient = (EditText) view.findViewById(R.id.edit_recipient);
editTextSubject = (EditText) view.findViewById(R.id.edit_subject);
editTextMessage = (EditText) view.findViewById(R.id.edit_message);
Bundle arguments = getArguments();
editTextRecipient.setText(arguments.getString(ARG_RECIPIENT));
editTextSubject.setText(arguments.getString(ARG_SUBJECT));
editTextMessage.setText(arguments.getString(ARG_MESSAGE));
toolbar = (Toolbar) view.findViewById(R.id.toolbar);
toolbar.setTitle(getString(R.string.message));
toolbar.setTitleTextColor(themer.getColorFilterPrimary().getColor());
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
toolbar.setNavigationOnClickListener(v -> {
UtilsInput.hideKeyboard(editTextMessage);
mListener.onNavigationBackClick();
});
toolbar.getNavigationIcon().mutate().setColorFilter(themer.getColorFilterPrimary());
setUpOptionsMenu();
View.OnFocusChangeListener onFocusChangeListener = (v, hasFocus) -> {
if (hasFocus) {
AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
}
};
editTextRecipient.setOnFocusChangeListener(onFocusChangeListener);
editTextSubject.setOnFocusChangeListener(onFocusChangeListener);
editTextMessage.setOnFocusChangeListener(onFocusChangeListener);
editMarginDefault = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());
editMarginWithActions = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 56, getResources().getDisplayMetrics());
textPreview = (TextView) view.findViewById(R.id.text_preview);
viewDivider = view.findViewById(R.id.view_divider);
toolbarActions = (Toolbar) view.findViewById(R.id.toolbar_actions);
toolbarActions.inflateMenu(R.menu.menu_editor_actions);
toolbarActions.setOnMenuItemClickListener(this);
tabLayout = (TabLayout) view.findViewById(R.id.layout_tab);
tabLayout.setTabMode(TabLayout.MODE_FIXED);
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
tabLayout.setTabTextColors(themer.getColorFilterTextMuted().getColor(), themer.getColorFilterPrimary().getColor());
viewPager = (ViewPager) view.findViewById(R.id.view_pager);
viewPager.setAdapter(new PagerAdapter() {
@Override
public CharSequence getPageTitle(int position) {
switch(position) {
case PAGE_BODY:
return getString(R.string.page_message);
case PAGE_PREVIEW:
return getString(R.string.page_preview);
}
return super.getPageTitle(position);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
return viewPager.getChildAt(position);
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
}
@Override
public int getCount() {
return viewPager.getChildCount();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
});
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
if (position == PAGE_BODY && toolbarActions.getVisibility() == View.VISIBLE) {
float translationY = positionOffset * (toolbarActions.getHeight() + viewDivider.getHeight());
viewDivider.setTranslationY(translationY);
toolbarActions.setTranslationY(translationY);
}
}
@Override
public void onPageSelected(int position) {
if (position == PAGE_PREVIEW) {
if (editTextMessage.length() == 0) {
textPreview.setText(R.string.empty_reply_preview);
} else {
textPreview.setText(Html.fromHtml(Processor.process(editTextMessage.getText().toString())));
}
}
itemHideActions.setVisible(position == PAGE_BODY);
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
tabLayout.setupWithViewPager(viewPager);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
layoutCaptcha = (RelativeLayout) view.findViewById(R.id.layout_captcha);
imageCaptcha = (ImageView) view.findViewById(R.id.image_captcha);
editCaptcha = (EditText) view.findViewById(R.id.edit_captcha);
buttonCaptchaRefresh = (ImageButton) view.findViewById(R.id.button_captcha_refresh);
buttonCaptchaRefresh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadCaptcha();
}
});
reddit.needsCaptcha().subscribe(new Observer<String>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
}
@Override
public void onNext(String response) {
Log.d(TAG, "needsCaptcha onNext: " + response);
if ("true".equalsIgnoreCase(response)) {
layoutCaptcha.setVisibility(View.VISIBLE);
loadCaptcha();
}
}
});
view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Menu menu = toolbarActions.getMenu();
int maxNum = (int) (view.getWidth() / TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48, getResources().getDisplayMetrics()));
int numShown = 0;
for (int index = 0; index < menu.size(); index++) {
MenuItem menuItem = menu.getItem(index);
menuItem.getIcon().setColorFilter(themer.getColorFilterIcon());
if (numShown++ < maxNum - 1) {
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
} else {
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
}
}
// Toggle visibility to fix weird bug causing tabs to not be added
tabLayout.setVisibility(View.GONE);
tabLayout.setVisibility(View.VISIBLE);
view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
return view;
}
use of android.support.v4.widget.NestedScrollView in project GSYVideoPlayer by CarGuo.
the class WebDetailActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_detail);
ButterKnife.bind(this);
String url = "http://baobab.wdjcdn.com/14564977406580.mp4";
//String url = "https://d131x7vzzf85jg.cloudfront.net/upload/documents/paper/b2/61/00/00/20160420_115018_b544.mp4";
webPlayer.setUp(url, true, null, "测试视频");
//增加封面
ImageView imageView = new ImageView(this);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setImageResource(R.mipmap.xxx1);
webPlayer.setThumbImageView(imageView);
resolveNormalVideoUI();
//外部辅助的旋转,帮助全屏
orientationUtils = new OrientationUtils(this, webPlayer);
//初始化不打开外部的旋转
orientationUtils.setEnable(false);
webPlayer.setIsTouchWiget(true);
//关闭自动旋转
webPlayer.setRotateViewAuto(false);
webPlayer.setLockLand(false);
webPlayer.setShowFullAnimation(false);
webPlayer.setNeedLockFull(true);
//detailPlayer.setOpenPreView(true);
webPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//直接横屏
orientationUtils.resolveByClick();
//第一个true是否需要隐藏actionbar,第二个true是否需要隐藏statusbar
webPlayer.startWindowFullscreen(WebDetailActivity.this, true, true);
}
});
webPlayer.setStandardVideoAllCallBack(new SampleListener() {
@Override
public void onPrepared(String url, Object... objects) {
super.onPrepared(url, objects);
//开始播放了才能旋转和全屏
orientationUtils.setEnable(true);
isPlay = true;
}
@Override
public void onAutoComplete(String url, Object... objects) {
super.onAutoComplete(url, objects);
}
@Override
public void onClickStartError(String url, Object... objects) {
super.onClickStartError(url, objects);
}
@Override
public void onQuitFullscreen(String url, Object... objects) {
super.onQuitFullscreen(url, objects);
if (orientationUtils != null) {
orientationUtils.backToProtVideo();
}
}
});
webPlayer.setLockClickListener(new LockClickListener() {
@Override
public void onClick(View view, boolean lock) {
if (orientationUtils != null) {
//配合下方的onConfigurationChanged
orientationUtils.setEnable(!lock);
}
}
});
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
webView.loadUrl("https://www.baidu.com");
webTopLayout.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (!webPlayer.isIfCurrentIsFullscreen() && scrollY >= 0 && isPlay) {
if (scrollY > webPlayer.getHeight()) {
//如果是小窗口就不需要处理
if (!isSamll) {
isSamll = true;
int size = CommonUtil.dip2px(WebDetailActivity.this, 150);
webPlayer.showSmallVideo(new Point(size, size), true, true);
orientationUtils.setEnable(false);
}
} else {
if (isSamll) {
isSamll = false;
orientationUtils.setEnable(true);
//必须
webTopLayoutVideo.postDelayed(new Runnable() {
@Override
public void run() {
webPlayer.hideSmallVideo();
}
}, 50);
}
}
webTopLayoutVideo.setTranslationY((scrollY <= webTopLayoutVideo.getHeight()) ? -scrollY : -webTopLayoutVideo.getHeight());
}
}
});
}
use of android.support.v4.widget.NestedScrollView in project RxBinding by JakeWharton.
the class RxNestedScrollViewTestActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ScrollView scrollView = new ScrollView(this);
nestedScrollView = new NestedScrollView(this);
emptyView = new FrameLayout(this);
LayoutParams scrollParams = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
LayoutParams emptyParams = new LayoutParams(50000, 50000);
nestedScrollView.addView(emptyView, emptyParams);
scrollView.addView(nestedScrollView, scrollParams);
setContentView(scrollView, scrollParams);
}
Aggregations