I use the following code to set the sensitivity of the trackball
public class Main extends UiApplication {
public static void main(String[] args) {
Main theApp = new Main();
theApp.enterEventDispatcher();
}
public Main() {
if (Trackball.isSupported()) {
Trackball.setFilter(Trackball.FILTER_ACCELERATION);
Trackball.setSensitivityX(20);
Trackball.setSensitivityY(20);
}
pushScreen(new LoginScreen());
}
}
Here's the screen used:
public class LoginScreen extends MainScreen {
public LoginScreen() {
super(MainScreen.NO_VERTICAL_SCROLL | MainScreen.NO_VERTICAL_SCROLLBAR);
add(...) // SOME COMPONENTS ARE ADDED HERE
}
}
When I check the sensitivity of trackball in LoginScreen
using Trackball.getSensitivityX()
and Trackball.getSensitivityY()
in navigationMovement
, it returns "2147483647", meanwhile if I checked it after setting it immediately in Main
it returns "20" !
So I moved the setting block inside the LoginScreen
itself as follows:
public class LoginScreen extends MainScreen {
public LoginScreen() {
super(MainScreen.NO_VERTICAL_SCROLL | MainScreen.NO_VERTICAL_SCROLLBAR);
if (Trackball.isSupported()) {
Trackball.setFilter(Trackball.FILTER_ACCELERATION);
Trackball.setSensitivityX(20);
Trackball.setSensitivityY(20);
}
add(...) // SOME COMPONENTS ARE ADDED HERE
}
}
It also returns "2147483647" via using Trackball.getSensitivityX()
and Trackball.getSensitivityY()
in navigationMovement
.
Finally, based on some web searches, I moved the condition inside the navigationMovement
as follows:
protected boolean navigationMovement(int dx, int dy, int status, int time) {
if (Trackball.isSupported()) {
Trackball.setFilter(Trackball.FILTER_ACCELERATION);
Trackball.setSensitivityX(20);
Trackball.setSensitivityY(20);
}
return super.navigationMovement(dx, dy, status, time);
}
the problem becomes that the navigation movement jumps from field at index 0 to index 2 to index 4 ... etc bypassing on field with each movement !
How to correctly set the sensitivity of trackball for a screen ?