0

in live wallpaper we have method called onOffsetsChanged which is called when user swipes on the screen of this phone the value of xOffset is changed from 0.1 to 0.9

now i want to make is this way that when the value falls less then 0.5

it might return different value

for example

0.5 --> 0.48

0.4 --> 0.46

0.3 --> 0.44

0.2 --> 0.42

0.1 --> 0.40

but when it increases from 0.5 it stays the same

0.9 --> 0.9

0.8 --> 0.8

0.7 --> 0.7

0.6 --> 0.6

can some one help me with this formula i am not able to get any logic here

@Override
public void onOffsetsChanged(final float xOffset, final float yOffset, final float xOffsetStep, final float yOffsetStep, final int xPixelOffset, final int yPixelOffset) 
{
    super.onOffsetsChanged(xOffset, yOffset, xOffsetStep, yOffsetStep, xPixelOffset, yPixelOffset);
    Runnable offsetsChangedCommand = new Runnable() 
    {
        public void run() {
            if (xOffsetStep != 0f) 
            {
                glRenderer.setParallax(xOffset - 0.5f);
            }
        };
    };
    executor.execute(offsetsChangedCommand);
}
Kendrick
  • 3,747
  • 1
  • 23
  • 41
Iori
  • 660
  • 1
  • 10
  • 19

2 Answers2

2

There may be a better way, but the easiest thing I can think of is to do:

float actualOffset;
if(xOffset>0.5f)
{
    actualOffset=xOffset;
}
else
{
    actualOffset=0.38f+(xOffset*0.2f);
}

glRenderer.setParallax(actualOffset- 0.5f);
Kendrick
  • 3,747
  • 1
  • 23
  • 41
1
float myXOffset;
if(xOffset <= 0.5) 
{
    myXOffset = 0.38 + (xOffset / 5);
} else {
    myXOffset = xOffset;
}
Joshua Carmody
  • 13,410
  • 16
  • 64
  • 83