Search in sources :

Example 16 with NestedScrollView

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);
            }
        }
    }
}
Also used : OnScrollListener(me.henrytao.smoothappbarlayout.base.OnScrollListener) ObservableRecyclerView(me.henrytao.smoothappbarlayout.base.ObservableRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) ObservableNestedScrollView(me.henrytao.smoothappbarlayout.base.ObservableNestedScrollView) NestedScrollView(android.support.v4.widget.NestedScrollView) ObservableRecyclerView(me.henrytao.smoothappbarlayout.base.ObservableRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) ObservableNestedScrollView(me.henrytao.smoothappbarlayout.base.ObservableNestedScrollView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView)

Example 17 with NestedScrollView

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();
    }
}
Also used : GeneralSwipeAction(android.support.test.espresso.action.GeneralSwipeAction) ViewGroup(android.view.ViewGroup) CoordinatesProvider(android.support.test.espresso.action.CoordinatesProvider) TextView(android.widget.TextView) NestedScrollView(android.support.v4.widget.NestedScrollView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) TextView(android.widget.TextView) SmallTest(android.support.test.filters.SmallTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) MediumTest(android.support.test.filters.MediumTest)

Example 18 with NestedScrollView

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;
}
Also used : AppBarLayout(android.support.design.widget.AppBarLayout) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) ImageButton(android.widget.ImageButton) Bundle(android.os.Bundle) ImageView(android.widget.ImageView) ViewPager(android.support.v4.view.ViewPager) MenuItem(android.view.MenuItem) TabLayout(android.support.design.widget.TabLayout) Inject(javax.inject.Inject) Picasso(com.squareup.picasso.Picasso) JSONException(org.json.JSONException) Reddit(com.winsonchiu.reader.data.reddit.Reddit) JSONObject(org.json.JSONObject) Toast(android.widget.Toast) Menu(android.view.Menu) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) Log(android.util.Log) Processor(com.github.rjeschke.txtmark.Processor) UtilsInput(com.winsonchiu.reader.utils.UtilsInput) LayoutInflater(android.view.LayoutInflater) PagerAdapter(android.support.v4.view.PagerAdapter) TextUtils(android.text.TextUtils) Observer(rx.Observer) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) TypedValue(android.util.TypedValue) Toolbar(android.support.v7.widget.Toolbar) Html(android.text.Html) ViewTreeObserver(android.view.ViewTreeObserver) RelativeLayout(android.widget.RelativeLayout) Nullable(android.support.annotation.Nullable) Activity(android.app.Activity) EditText(android.widget.EditText) PagerAdapter(android.support.v4.view.PagerAdapter) TabLayout(android.support.design.widget.TabLayout) AppBarLayout(android.support.design.widget.AppBarLayout) Menu(android.view.Menu) ViewTreeObserver(android.view.ViewTreeObserver) Bundle(android.os.Bundle) ViewGroup(android.view.ViewGroup) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) TextView(android.widget.TextView) ViewPager(android.support.v4.view.ViewPager) JSONObject(org.json.JSONObject)

Example 19 with NestedScrollView

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());
            }
        }
    });
}
Also used : Point(android.graphics.Point) SampleListener(com.example.gsyvideoplayer.listener.SampleListener) ImageView(android.widget.ImageView) BindView(butterknife.BindView) ScrollWebView(com.example.gsyvideoplayer.view.ScrollWebView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) LockClickListener(com.shuyu.gsyvideoplayer.listener.LockClickListener) Point(android.graphics.Point) WebSettings(android.webkit.WebSettings) OrientationUtils(com.shuyu.gsyvideoplayer.utils.OrientationUtils) ImageView(android.widget.ImageView) NestedScrollView(android.support.v4.widget.NestedScrollView)

Example 20 with NestedScrollView

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);
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams) ScrollView(android.widget.ScrollView) NestedScrollView(android.support.v4.widget.NestedScrollView) FrameLayout(android.widget.FrameLayout) NestedScrollView(android.support.v4.widget.NestedScrollView)

Aggregations

NestedScrollView (android.support.v4.widget.NestedScrollView)20 View (android.view.View)8 RecyclerView (android.support.v7.widget.RecyclerView)6 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)5 ViewGroup (android.view.ViewGroup)5 ViewTreeObserver (android.view.ViewTreeObserver)4 TextView (android.widget.TextView)4 AppBarLayout (android.support.design.widget.AppBarLayout)3 TabLayout (android.support.design.widget.TabLayout)3 PagerAdapter (android.support.v4.view.PagerAdapter)3 ViewPager (android.support.v4.view.ViewPager)3 Toolbar (android.support.v7.widget.Toolbar)3 Menu (android.view.Menu)3 MenuItem (android.view.MenuItem)3 ImageView (android.widget.ImageView)3 Test (org.junit.Test)3 Activity (android.app.Activity)2 Bundle (android.os.Bundle)2 Nullable (android.support.annotation.Nullable)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2