Search in sources :

Example 31 with NestedScrollView

use of android.support.v4.widget.NestedScrollView in project android-advancedrecyclerview by h6ah4i.

the class RecyclerViewDragDropManager method startDragging.

@SuppressWarnings("unchecked")
private void startDragging(RecyclerView rv, MotionEvent e, RecyclerView.ViewHolder holder, ItemDraggableRange range, AdapterPath path, int wrappedItemPosition, Object composedAdapterTag) {
    safeEndAnimation(rv, holder);
    mHandler.cancelLongPressDetection();
    mDraggingItemInfo = new DraggingItemInfo(rv, holder, mLastTouchX, mLastTouchY);
    mDraggingItemViewHolder = holder;
    // XXX if setIsRecyclable() is used, another view holder objects will be created
    // which has the same ID with currently dragging item... Not works as expected.
    // holder.setIsRecyclable(false);
    mDraggableRange = range;
    mRootDraggableRange = convertToRootAdapterRange(path, mDraggableRange);
    NestedScrollView nestedScrollView = findAncestorNestedScrollView(mRecyclerView);
    if (nestedScrollView != null && !mRecyclerView.isNestedScrollingEnabled()) {
        mNestedScrollView = nestedScrollView;
    } else {
        mNestedScrollView = null;
    }
    mOrigOverScrollMode = rv.getOverScrollMode();
    rv.setOverScrollMode(View.OVER_SCROLL_NEVER);
    mLastTouchX = (int) (e.getX() + 0.5f);
    mLastTouchY = (int) (e.getY() + 0.5f);
    mNestedScrollViewScrollX = (mNestedScrollView != null) ? mNestedScrollView.getScrollX() : 0;
    mNestedScrollViewScrollY = (mNestedScrollView != null) ? mNestedScrollView.getScrollY() : 0;
    // disable auto scrolling until user moves the item
    mDragStartTouchY = mDragMinTouchY = mDragMaxTouchY = mLastTouchY;
    mDragStartTouchX = mDragMinTouchX = mDragMaxTouchX = mLastTouchX;
    mScrollDirMask = SCROLL_DIR_NONE;
    mCurrentItemMoveMode = mItemMoveMode;
    mComposedAdapterTag = composedAdapterTag;
    mRecyclerView.getParent().requestDisallowInterceptTouchEvent(true);
    startScrollOnDraggingProcess();
    mWrapperAdapter.startDraggingItem(mDraggingItemInfo, holder, mDraggableRange, wrappedItemPosition, mCurrentItemMoveMode);
    // setup decorators
    mWrapperAdapter.onBindViewHolder(holder, wrappedItemPosition);
    mDraggingItemDecorator = new DraggingItemDecorator(mRecyclerView, holder, mRootDraggableRange);
    mDraggingItemDecorator.setShadowDrawable(mShadowDrawable);
    mDraggingItemDecorator.setupDraggingItemEffects(mDraggingItemEffectsInfo);
    mDraggingItemDecorator.start(mDraggingItemInfo, mLastTouchX, mLastTouchY);
    final int layoutType = CustomRecyclerViewUtils.getLayoutType(mRecyclerView);
    if (!mCheckCanDrop && CustomRecyclerViewUtils.isLinearLayout(layoutType)) {
        mSwapTargetItemOperator = new SwapTargetItemOperator(mRecyclerView, holder, mDraggingItemInfo);
        mSwapTargetItemOperator.setSwapTargetTranslationInterpolator(mSwapTargetTranslationInterpolator);
        mSwapTargetItemOperator.start();
        mSwapTargetItemOperator.update(mDraggingItemDecorator.getDraggingItemTranslationX(), mDraggingItemDecorator.getDraggingItemTranslationY());
    }
    if (mEdgeEffectDecorator != null) {
        mEdgeEffectDecorator.reorderToTop();
    }
    // raise onDragItemStarted() event
    mWrapperAdapter.onDragItemStarted();
    if (mItemDragEventListener != null) {
        mItemDragEventListener.onItemDragStarted(mWrapperAdapter.getDraggingItemInitialPosition());
        mItemDragEventListener.onItemDragMoveDistanceUpdated(0, 0);
    }
}
Also used : NestedScrollView(android.support.v4.widget.NestedScrollView)

Example 32 with NestedScrollView

use of android.support.v4.widget.NestedScrollView in project LabDayApp by jakdor.

the class TimetableFragmentTest method viewTest.

/**
 * Layout inflation test
 */
@Test
public void viewTest() throws Exception {
    startFragment(timetableFragment);
    View view = timetableFragment.getView();
    Assert.assertNotNull(view);
    AppBarLayout appBarLayout = view.findViewById(R.id.appbar_container);
    Toolbar toolbar = view.findViewById(R.id.timetable_title_bar);
    NestedScrollView nestedScrollView = view.findViewById(R.id.timetable_nested_scroll_view);
    RecyclerView recyclerView = view.findViewById(R.id.timetable_recycler_view);
    Assert.assertNotNull(appBarLayout);
    Assert.assertNotNull(toolbar);
    Assert.assertNotNull(nestedScrollView);
    Assert.assertNotNull(recyclerView);
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) AppBarLayout(android.support.design.widget.AppBarLayout) NestedScrollView(android.support.v4.widget.NestedScrollView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Toolbar(android.support.v7.widget.Toolbar) Test(org.junit.Test)

Example 33 with NestedScrollView

use of android.support.v4.widget.NestedScrollView in project Camera-Roll-Android-App by kollerlukas.

the class AboutActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_about);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().setEnterTransition(new Slide(Gravity.BOTTOM));
        getWindow().setReturnTransition(new Slide(Gravity.BOTTOM));
    }
    SwipeBackCoordinatorLayout swipeBackView = findViewById(R.id.swipeBackView);
    swipeBackView.setOnSwipeListener(this);
    final Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle("");
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    final View header = findViewById(R.id.header);
    header.setBackgroundColor(theme.getAccentColor(this));
    TextView version = findViewById(R.id.version);
    try {
        String versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
        final int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
        // noinspection deprecation
        version.setText(Html.fromHtml(versionName));
        version.setTextColor(theme.getAccentTextColor(this));
        version.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View view) {
                Toast.makeText(view.getContext(), "versionCode: " + String.valueOf(versionCode), Toast.LENGTH_SHORT).show();
                return false;
            }
        });
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    final TextView aboutText = findViewById(R.id.about_text);
    // noinspection deprecation
    aboutText.setText(Html.fromHtml(getString(R.string.about_text)));
    aboutText.setMovementMethod(new LinkMovementMethod());
    final View rootView = findViewById(R.id.root_view);
    final NestedScrollView scrollView = findViewById(R.id.scroll_view);
    scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {

        @Override
        public void onScrollChange(NestedScrollView nestedScrollView, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
            int statusBarHeight = toolbar.getPaddingTop();
            if (scrollY > header.getHeight() - statusBarHeight / 2) {
                if (theme.darkStatusBarIcons()) {
                    Util.setDarkStatusBarIcons(rootView);
                } else {
                    Util.setLightStatusBarIcons(rootView);
                }
            } else {
                if (theme.darkStatusBarIconsInSelectorMode()) {
                    Util.setDarkStatusBarIcons(rootView);
                } else {
                    Util.setLightStatusBarIcons(rootView);
                }
            }
        }
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        rootView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {

            @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH)
            @Override
            public WindowInsets onApplyWindowInsets(View view, WindowInsets insets) {
                toolbar.setPadding(toolbar.getPaddingStart(), /*+ insets.getSystemWindowInsetLeft()*/
                toolbar.getPaddingTop() + insets.getSystemWindowInsetTop(), toolbar.getPaddingEnd(), /*+ insets.getSystemWindowInsetRight()*/
                toolbar.getPaddingBottom());
                aboutText.setPadding(aboutText.getPaddingStart(), aboutText.getPaddingTop(), aboutText.getPaddingEnd(), aboutText.getPaddingBottom() + insets.getSystemWindowInsetBottom());
                View viewGroup = findViewById(R.id.swipeBackView);
                ViewGroup.MarginLayoutParams viewGroupParams = (ViewGroup.MarginLayoutParams) viewGroup.getLayoutParams();
                viewGroupParams.leftMargin += insets.getSystemWindowInsetLeft();
                viewGroupParams.rightMargin += insets.getSystemWindowInsetRight();
                viewGroup.setLayoutParams(viewGroupParams);
                // clear this listener so insets aren't re-applied
                rootView.setOnApplyWindowInsetsListener(null);
                return insets.consumeSystemWindowInsets();
            }
        });
        // set status bar icon color
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
    } else {
        rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {
                // hacky way of getting window insets on pre-Lollipop
                // somewhat works...
                int[] screenSize = Util.getScreenSize(AboutActivity.this);
                int[] windowInsets = new int[] { Math.abs(screenSize[0] - rootView.getLeft()), Math.abs(screenSize[1] - rootView.getTop()), Math.abs(screenSize[2] - rootView.getRight()), Math.abs(screenSize[3] - rootView.getBottom()) };
                toolbar.setPadding(toolbar.getPaddingStart(), toolbar.getPaddingTop() + windowInsets[1], toolbar.getPaddingEnd(), toolbar.getPaddingBottom());
                View viewGroup = findViewById(R.id.swipeBackView);
                ViewGroup.MarginLayoutParams viewGroupParams = (ViewGroup.MarginLayoutParams) viewGroup.getLayoutParams();
                viewGroupParams.leftMargin += windowInsets[0];
                viewGroupParams.rightMargin += windowInsets[2];
                viewGroup.setLayoutParams(viewGroupParams);
                rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
        });
    }
    for (int i = 0; i < toolbar.getChildCount(); i++) {
        if (toolbar.getChildAt(i) instanceof ImageView) {
            ImageView imageView = ((ImageView) toolbar.getChildAt(i));
            int color;
            if (!theme.darkStatusBarIconsInSelectorMode()) {
                color = ContextCompat.getColor(this, R.color.white_translucent1);
            } else {
                color = ContextCompat.getColor(this, R.color.black_translucent2);
            }
            imageView.setColorFilter(color, PorterDuff.Mode.SRC_IN);
            break;
        }
    }
    // needed for transparent statusBar
    setSystemUiFlags();
}
Also used : ViewGroup(android.view.ViewGroup) LinkMovementMethod(android.text.method.LinkMovementMethod) ImageView(android.widget.ImageView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) TextView(android.widget.TextView) WindowInsets(android.view.WindowInsets) PackageManager(android.content.pm.PackageManager) Slide(android.transition.Slide) SwipeBackCoordinatorLayout(us.koller.cameraroll.ui.widget.SwipeBackCoordinatorLayout) RequiresApi(android.support.annotation.RequiresApi) TextView(android.widget.TextView) ImageView(android.widget.ImageView) NestedScrollView(android.support.v4.widget.NestedScrollView) ViewTreeObserver(android.view.ViewTreeObserver) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 34 with NestedScrollView

use of android.support.v4.widget.NestedScrollView in project CustomViews by AndroidStudy233.

the class MergedAppBarLayoutBehavior method getBottomSheetBehavior.

/**
 * Look into the CoordiantorLayout for the {@link BottomSheetBehaviorGoogleMapsLike}
 * @param coordinatorLayout with app:layout_behavior= {@link BottomSheetBehaviorGoogleMapsLike}
 */
private void getBottomSheetBehavior(@NonNull CoordinatorLayout coordinatorLayout) {
    for (int i = 0; i < coordinatorLayout.getChildCount(); i++) {
        View child = coordinatorLayout.getChildAt(i);
        if (child instanceof NestedScrollView) {
            try {
                BottomSheetBehaviorGoogleMapsLike temp = BottomSheetBehaviorGoogleMapsLike.from(child);
                mBottomSheetBehaviorRef = new WeakReference<>(temp);
                break;
            } catch (IllegalArgumentException e) {
            }
        }
    }
}
Also used : NestedScrollView(android.support.v4.widget.NestedScrollView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) TextView(android.widget.TextView)

Example 35 with NestedScrollView

use of android.support.v4.widget.NestedScrollView in project CustomViews by AndroidStudy233.

the class ScrollingAppBarLayoutBehavior method getBottomSheetBehavior.

/**
 * Look into the CoordiantorLayout for the {@link BottomSheetBehaviorGoogleMapsLike}
 * @param coordinatorLayout with app:layout_behavior= {@link BottomSheetBehaviorGoogleMapsLike}
 */
private void getBottomSheetBehavior(@NonNull CoordinatorLayout coordinatorLayout) {
    for (int i = 0; i < coordinatorLayout.getChildCount(); i++) {
        View child = coordinatorLayout.getChildAt(i);
        if (child instanceof NestedScrollView) {
            try {
                BottomSheetBehaviorGoogleMapsLike temp = BottomSheetBehaviorGoogleMapsLike.from(child);
                mBottomSheetBehaviorRef = new WeakReference<>(temp);
                break;
            } catch (IllegalArgumentException e) {
            }
        }
    }
}
Also used : NestedScrollView(android.support.v4.widget.NestedScrollView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView)

Aggregations

NestedScrollView (android.support.v4.widget.NestedScrollView)42 View (android.view.View)24 RecyclerView (android.support.v7.widget.RecyclerView)15 TextView (android.widget.TextView)11 ViewGroup (android.view.ViewGroup)9 AppBarLayout (android.support.design.widget.AppBarLayout)6 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)6 Toolbar (android.support.v7.widget.Toolbar)6 AbsListView (android.widget.AbsListView)6 ImageView (android.widget.ImageView)6 ScrollView (android.widget.ScrollView)6 ViewTreeObserver (android.view.ViewTreeObserver)5 SuppressLint (android.annotation.SuppressLint)4 ViewPager (android.support.v4.view.ViewPager)4 Test (org.junit.Test)4 Activity (android.app.Activity)3 Bundle (android.os.Bundle)3 TabLayout (android.support.design.widget.TabLayout)3 PagerAdapter (android.support.v4.view.PagerAdapter)3 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3