I made a panorama app that scrolls the image automatically, from left to right to left and so on. It works nicely, except for the fact that it doesn't quite scrolls as smoothly (meaning constant velocity) as I would like. It sometimes 'jumps' a bit. It shouldn't be in a device with a core of 1.4 GHz...
I implemented this just by translating the image, then waiting a bit with a Thread.sleep(panoanimspeed);
(where 1/1000s <= panoanimspeed <= 1/50s), and so on. Probably not the smartest thing to do...?
Do you know how can I make this smoother? Below is the code of the relevant AsyncTask.
Thanks!
class AnimatePanorama extends AsyncTask<Void, Integer, Void> {
private float scale = foto.getCropScale() * foto.getBaseScale();
private Matrix m = foto.matrix;
@Override
protected void onProgressUpdate(Integer... values) {
if (values[0] == 0) {
m.setScale(scale, scale);
m.postTranslate(values[1], 0);
foto.setImageMatrix(m);
}
}
@Override
protected Void doInBackground(Void... arg) {
dir = -dir;
int l, ini = 0;
float lim = foto.getImageWidth()*scale - foto.getViewWidth();
float[] mm = new float[9];
foto.matrix.getValues(mm);
if (foto.getScale() == foto.getCropScale())
ini = (int) (dir*(lim*(dir+1)/2 + mm[2]));
while (true) {
if(isCancelled()) break;
l = (int) (lim*(dir+1)/2);
for (int i = ini; i < lim; i++) {
if(isCancelled()) break;
try {
Thread.sleep(panoanimspeed);
} catch (InterruptedException e) {
e.printStackTrace();
}
publishProgress(0, dir * i - l);
}
ini = 0;
dir = -dir;
}
return null;
}
}