Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrolling improvements #3663

Open
wants to merge 3 commits into
base: scrolling-improvements
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -4235,6 +4235,36 @@ public boolean onTouch(View v, MotionEvent me) {
return myView.getAndroidView().onTouchEvent(me);
}
});
/**
* Mouse Event Listener used to handle mouse wheel events
* The mouse wheel can be used to scroll the page up or down
*/
layoutWrapper.setOnGenericMotionListener(new View.OnGenericMotionListener() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds a motion listener to a native peer component. E.g. a webview or other native component. Not the main view. Probably we need to add similar in CodenameOneView if we want this to be for general app.

@Override
public boolean onGenericMotion(View view, MotionEvent me) {
if (AndroidImplementation.this.myView == null) {
return false;
}
if (me.isFromSource(InputDevice.SOURCE_CLASS_POINTER) &&
me.getAction() == MotionEvent.ACTION_SCROLL) {
double currentX = me.getX();
double currentY = me.getY();
int maxHeight = myView.getViewHeight();
double scrollOffSet = me.getAxisValue(MotionEvent.AXIS_VSCROLL);
int scrollToLocation = (int) (scrollOffSet * 5d + currentY);
// determine the location that the view should scroll to
// the 5d is a scroll speed factor
if (scrollToLocation <= 0) {
scrollToLocation = 0;
} else if (scrollToLocation >= maxHeight) {
scrollToLocation = maxHeight;
}
myView.getAndroidView().scrollTo((int) currentX, scrollToLocation);
return true;
}
return false;
}
});
}
if(AndroidImplementation.this.relativeLayout != null){
// not sure why this happens but we got an exception where add view was called with
Expand Down