05-19-2012 07:23 AM
hello,
I am trying to figure out how to modify the example of SliderField so it turns into a kind of lock which goes back to beginning if the user doesn't swipe to the other side in one swipe.
Does anyone have any example of doing this or can help me with my problem which is that I can insert the following into the SliderField class and it seems to send the slider back to the beginning fine on the storm 2 simulator (when release mouse button) but on my 9900 device the slider just sticks wherever i release my thumb.
protected void fieldChangeNotify(int context) {
if (_currentState != _numStates)
{
_currentState = 0;
}
invalidate();
super.fieldChangeNotify(context);
}
protected boolean touchEvent(TouchEvent message)
{
boolean isConsumed = false;
boolean isOutOfBounds = false;
int x = message.getX(1);
int y = message.getY(1);
// Check to ensure point is within this field
if(x < 0 || y < 0 || x > getExtent().width || y > getExtent().height) {
isOutOfBounds = true;
}
switch(message.getEvent()) {
case TouchEvent.CLICK:
case TouchEvent.MOVE:
if(isOutOfBounds) return true; // consume
_selected = true; // Pressed effect
// update state
int stateWidth = getExtent().width / _numStates;
int numerator = x / stateWidth;
int denominator = x % stateWidth;
if( denominator > stateWidth / 2 ) {
numerator++;
}
_currentState = numerator;
invalidate();
isConsumed = true;
break;
case TouchEvent.UNCLICK:
if(isOutOfBounds) {
_selected = false; // Reset presssed effect
return true;
}
// A field change notification is only sent on UNCLICK to allow for recovery
// should the user cancel, i.e. click and move off the button
_selected = false; // Reset pressed effect
// Update state
stateWidth = getExtent().width / _numStates;
numerator = x / stateWidth;
denominator = x % stateWidth;
if( denominator > stateWidth / 2 ) {
numerator++;
}
_currentState = numerator;
invalidate();
fieldChangeNotify(0);
isConsumed = true;
break;
}
return isConsumed;
}
thanks.
05-19-2012 06:45 PM
05-20-2012 05:57 AM
Thanks CMY for taking the time to answer my question.
I have actually gone down the route you suggested and now have the slider returning to 0 when released on 9900 and 9550.
I am just concerned now by the fact that the trackpad on 9900 doesn't do any sliding with the new code so for non touch screen devices this code actually won't work.
Any solutions?
protected boolean touchEvent(TouchEvent message)
{
boolean isConsumed = false;
boolean isOutOfBounds = false;
int x = message.getX(1);
int y = message.getY(1);
// Check to ensure point is within this field
if(x < 0 || y < 0 || x > getExtent().width || y > getExtent().height) {
isOutOfBounds = true;
}
switch(message.getEvent()) {
case TouchEvent.CLICK:
Log.info("CLICK");
case TouchEvent.UP:
Log.info("up");
fieldChangeNotify(0);
invalidate();
dontDoClick = true;
break;
case TouchEvent.MOVE:
Log.info("move");
if(dontDoClick)
{
dontDoClick = false;
break;
}
if(isOutOfBounds) return true; // consume
_selected = true; // Pressed effect
// update state
int stateWidth = getExtent().width / _numStates;
int numerator = x / stateWidth;
int denominator = x % stateWidth;
if( denominator > stateWidth / 2 ) {
numerator++;
}
_currentState = numerator;
invalidate();
isConsumed = true;
break;
case TouchEvent.UNCLICK:
Log.info("unCLICK");
if(isOutOfBounds) {
_selected = false; // Reset presssed effect
return true;
}
// A field change notification is only sent on UNCLICK to allow for recovery
// should the user cancel, i.e. click and move off the button
_selected = false; // Reset pressed effect
// Update state
stateWidth = getExtent().width / _numStates;
numerator = x / stateWidth;
denominator = x % stateWidth;
if( denominator > stateWidth / 2 ) {
numerator++;
}
_currentState = numerator;
fieldChangeNotify(0);
invalidate();
isConsumed = true;
break;
}
return isConsumed;
}
05-20-2012 06:37 PM