@Override public void run() { super.run(); try { do { if (myAnim.start == -1 || myAnim.end == -1) { // this is a single image, not an animation tryLoadBitmap(myAnim.filename); } else { for (int i = myAnim.start; i <= myAnim.end; i++) { boolean bitmapLoaded; bitmapLoaded = tryLoadBitmap(myAnim.filename + new DecimalFormat("0000").format(i) + ".png"); if (!bitmapLoaded) { break; } } } } while (myAnim.loop); } catch (InterruptedException e) { e.printStackTrace(); } finally { if (shouldTurn) { myCanvasView.setmLookingRight(!myCanvasView.ismLookingRight()); } } }
@Override public void run() { super.run(); // float h2 = (float)myCanvasView.getHeight()/2.0f; // float w2 = (float)myCanvasView.getWidth()/2.0f; // float h2 = clip.height()/2.0f; // float w2 = clip.width()/2.0f; float rotstep = (deg - rotation) / 20.0f; float scalestep = (scl - scale) / 20.0f; for (int i = 0; i < 20; i++) { matrixLock.lock(); matrix.reset(); // linear interpolation // rotation += rotstep; // matrix.setRotate(rotation,w2,h2); scale += scalestep; matrix.postScale(scale, scale); matrixLock.unlock(); myCanvasView.postInvalidate(); try { sleep(30); } catch (InterruptedException e) { Log.i(TAG, "interrupted", e); break; } } }
private boolean tryLoadBitmap(String bmpFilename) throws InterruptedException { try { bmpLock.lock(); bmp = BitmapFactory.decodeStream(assets.open(bmpFilename)); bmpLock.unlock(); if (bmp == null) { AlertDialog a = new AlertDialog.Builder(getContext()).create(); a.setMessage("Cannot load image"); a.show(); return false; } myCanvasView.postInvalidate(); sleep(25); } catch (IOException e) { e.printStackTrace(); } return true; }
public Animator(MyAnimations.MyAnim myAnim, boolean shouldTurn, MyCanvasView myCanvasView) { this.myAnim = myAnim; this.shouldTurn = shouldTurn; this.myCanvasView = myCanvasView; assets = myCanvasView.getContext().getAssets(); }