Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions example/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
android:theme="@style/NoActionBarAppTheme" />
<activity android:name=".CheckCameraOrientationActivity" />
<activity android:name=".Issue212316ParrierExampleActvity" />
<activity
android:name=".OverScrollRecyclerViewActivity"
android:theme="@style/AppTheme.Transparent" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

public class MainActivity extends AppCompatActivity {
private static final List<ActivityEntry> ACTIVITY_ENTRIES = Arrays.asList(
new ActivityEntry("Over Scroll", null,
new ActivityEntry("With RecyclerView", OverScrollRecyclerViewActivity.class)
),
new ActivityEntry("Workaround of issues", null,
new ActivityEntry("AOSP Issue 212316", Issue212316ParrierExampleActvity.class)
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package net.cattaka.android.snippets.example;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import net.cattaka.android.adaptertoolbox.adapter.ScrambleAdapter;
import net.cattaka.android.snippets.example.adapter.factory.SimpleStringViewHolderFactory;

import java.util.ArrayList;

/**
* Created by cattaka on 16/12/03.
*/

public class OverScrollRecyclerViewActivity extends AppCompatActivity {
RecyclerView mRecyclerView;

ScrambleAdapter<String> mAdapter;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_over_scroll_recycler_view);

// Find views
mRecyclerView = (RecyclerView) findViewById(R.id.view_recycler);

{ // Setup mRecyclerView
mAdapter = new ScrambleAdapter<>(this, new ArrayList<String>(), null, new SimpleStringViewHolderFactory());
mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
mRecyclerView.setAdapter(mAdapter);
for (int i = 0; i < 30; i++) {
mAdapter.getItems().add("Item : " + mAdapter.getItems().size());
}
}
}

@Override
protected void onStart() {
super.onStart();
}
}
19 changes: 19 additions & 0 deletions example/src/main/res/layout/activity_over_scroll_recycler_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<net.cattaka.android.snippets.view.OverScrollFrameLayout
android:id="@+id/layout_over_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light"
android:orientation="vertical">

<android.support.v7.widget.RecyclerView
android:id="@+id/view_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</net.cattaka.android.snippets.view.OverScrollFrameLayout>
</FrameLayout>
6 changes: 6 additions & 0 deletions example/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.Transparent">
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>

<style name="NoActionBarAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,27 @@
import android.view.View;

/**
* Created by cattaka on 2016/04/27.
* Created by cattaka on 2017/06/28.
* <p>
* Only for support-library below 26.0.0
*/
public class NestedScrollingCoordinatorLayout extends CoordinatorLayout {
public class ClassicNestedCoordinatorLayout extends CoordinatorLayout {
private final NestedScrollingChildHelper mScrollingChildHelper;
private final int[] mParentOffsetInWindow = new int[2];

public NestedScrollingCoordinatorLayout(Context context) {
public ClassicNestedCoordinatorLayout(Context context) {
super(context);
mScrollingChildHelper = new NestedScrollingChildHelper(this);
mScrollingChildHelper.setNestedScrollingEnabled(true);
}

public NestedScrollingCoordinatorLayout(Context context, AttributeSet attrs) {
public ClassicNestedCoordinatorLayout(Context context, AttributeSet attrs) {
super(context, attrs);
mScrollingChildHelper = new NestedScrollingChildHelper(this);
mScrollingChildHelper.setNestedScrollingEnabled(true);
}

public NestedScrollingCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr) {
public ClassicNestedCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mScrollingChildHelper = new NestedScrollingChildHelper(this);
mScrollingChildHelper.setNestedScrollingEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package net.cattaka.android.snippets.view;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.view.NestedScrollingChildHelper;
import android.util.AttributeSet;
import android.view.View;

/**
* Created by cattaka on 2017/06/28.
* <p>
* Only for support-library over 26.0.0
*/
public class NestedCoordinatorLayout extends CoordinatorLayout {
private final NestedScrollingChildHelper mScrollingChildHelper;
private final int[] mParentOffsetInWindow = new int[2];

public NestedCoordinatorLayout(Context context) {
super(context);
mScrollingChildHelper = new NestedScrollingChildHelper(this);
mScrollingChildHelper.setNestedScrollingEnabled(true);
}

public NestedCoordinatorLayout(Context context, AttributeSet attrs) {
super(context, attrs);
mScrollingChildHelper = new NestedScrollingChildHelper(this);
mScrollingChildHelper.setNestedScrollingEnabled(true);
}

public NestedCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mScrollingChildHelper = new NestedScrollingChildHelper(this);
mScrollingChildHelper.setNestedScrollingEnabled(true);
}

// NestedScrollingParent
@Override
public void onNestedPreScroll(@NonNull View target, int dx, int dy, @Nullable int[] consumed, int type) {
if (!mScrollingChildHelper.dispatchNestedPreScroll(dx, dy, consumed, mParentOffsetInWindow, type)) {
super.onNestedPreScroll(target, dx, dy, consumed, type);
}
}

// NestedScrollingParent
@Override
public boolean onStartNestedScroll(@NonNull View child, @NonNull View target, int axes, int type) {
boolean handled = super.onStartNestedScroll(child, target, axes, type);
handled |= mScrollingChildHelper.startNestedScroll(axes, type);
return handled;
}

@Override
public void onStopNestedScroll(@NonNull View target, int type) {
super.onStopNestedScroll(target, type);
mScrollingChildHelper.stopNestedScroll();
}

@Override
public void onNestedScrollAccepted(@NonNull View child, @NonNull View target, int axes, int type) {
if (!mScrollingChildHelper.startNestedScroll(axes, type)) {
super.onNestedScrollAccepted(child, target, axes, type);
}
}

@Override
public void onNestedScroll(@NonNull View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type) {
if (!mScrollingChildHelper.dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, mParentOffsetInWindow, type)) {
super.onNestedScroll(target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type);
}
}

@Override
public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) {
if (!mScrollingChildHelper.dispatchNestedPreScroll(dx, dy, consumed, mParentOffsetInWindow)) {
super.onNestedPreScroll(target, dx, dy, consumed);
}
}

@Override
public boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed) {
return mScrollingChildHelper.dispatchNestedFling(velocityX, velocityY, consumed)
|| super.onNestedFling(target, velocityX, velocityY, consumed);
}

@Override
public boolean onNestedPreFling(View target, float velocityX, float velocityY) {
return mScrollingChildHelper.dispatchNestedPreFling(velocityX, velocityY)
|| super.onNestedPreFling(target, velocityX, velocityY);
}

@Override
public int getNestedScrollAxes() {
return super.getNestedScrollAxes();
}
}
Loading