Installation
- Install Kotlin plugin
- Run
Troubleshooting
There seems to be some issue with instant run or Android Studio itself. Just try cleaning the project(Build -> Clean) and running again
There seems to be some issue with instant run or Android Studio itself. Just try cleaning the project(Build -> Clean) and running again
I don't know Kotlin well. I tried to convert the code to Java. Is the next conversion ok ?
/**
* code based on : https://github.com/manidesto/scrolling-demo
*/
public class RecyclerViewEx extends RecyclerView {
private static final int INVALID_POINTER = -1;
private int scrollPointerId = INVALID_POINTER;
private int initialTouchX = 0;
private int initialTouchY = 0;
private int touchSlop;
public RecyclerViewEx(final Context context) {
this(context, null);
}
public RecyclerViewEx(final Context context, @Nullable final AttributeSet attrs) {
this(context, attrs, 0);
}
public RecyclerViewEx(final Context context, @Nullable final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
ViewConfiguration vc = ViewConfiguration.get(context);
touchSlop = vc.getScaledTouchSlop();
}
@Override
public void setScrollingTouchSlop(final int slopConstant) {
super.setScrollingTouchSlop(slopConstant);
ViewConfiguration vc = ViewConfiguration.get(getContext());
switch (slopConstant) {
case TOUCH_SLOP_DEFAULT:
touchSlop = vc.getScaledTouchSlop();
break;
case TOUCH_SLOP_PAGING:
touchSlop = vc.getScaledPagingTouchSlop();
break;
}
}
@Override
public boolean onInterceptTouchEvent(final MotionEvent e) {
if (e == null)
return false;
int action = MotionEventCompat.getActionMasked(e);
int actionIndex = MotionEventCompat.getActionIndex(e);
switch (action) {
case MotionEvent.ACTION_DOWN:
scrollPointerId = e.getPointerId(0);
initialTouchX = Math.round(e.getX() + 0.5f);
initialTouchY = Math.round(e.getY() + 0.5f);
return super.onInterceptTouchEvent(e);
case MotionEvent.ACTION_POINTER_DOWN:
scrollPointerId = e.getPointerId(actionIndex);
initialTouchX = Math.round(e.getX(actionIndex) + 0.5f);
initialTouchY = Math.round(e.getY(actionIndex) + 0.5f);
return super.onInterceptTouchEvent(e);
case MotionEvent.ACTION_MOVE:
int index = e.findPointerIndex(scrollPointerId);
if (index < 0)
return false;
int x = Math.round(e.getX(index) + 0.5f);
int y = Math.round(e.getY(index) + 0.5f);
if (getScrollState() != SCROLL_STATE_DRAGGING) {
int dx = x - initialTouchX;
int dy = y - initialTouchY;
boolean startScroll = false;
if (getLayoutManager().canScrollHorizontally() && Math.abs(dx) > touchSlop
&& (getLayoutManager().canScrollVertically() || Math.abs(dx) > Math.abs(dy)))
startScroll = true;
if (getLayoutManager().canScrollVertically() && Math.abs(dy) > touchSlop
&& (getLayoutManager().canScrollHorizontally() || Math.abs(dy) > Math.abs(dx)))
startScroll = true;
return startScroll && super.onInterceptTouchEvent(e);
}
return super.onInterceptTouchEvent(e);
default:
return super.onInterceptTouchEvent(e);
}
}
@Override
public void requestDisallowInterceptTouchEvent(final boolean disallowIntercept) {
//super.requestDisallowInterceptTouchEvent(disallowIntercept);
// do nothing
}
}
This is for when both checkboxes are enabled in the sample.
That's the only code which is needed, right? There is nothing more that I can find that's really relevant.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.