Code example for BitmapDrawable

Methods: getBitmap, getIntrinsicHeight, getIntrinsicWidth

0
			mOutgoingScale = 1.0f;
		} 
		 
		mOutgoingDeltaX =  (outgoingWidth * mOutgoingScale) - getWidth();
		 
		int incomingHeight = mIncomingDrawable.getIntrinsicHeight();
		int incomingWidth = mIncomingDrawable.getIntrinsicWidth();
		if(incomingHeight < getHeight()) {
			mIncomingScale = ((float) getHeight()) / ((float) incomingHeight);
		} else { 
			mIncomingScale = 1.0f;
		} 
		mIncomingDeltaX =  (incomingWidth * mIncomingScale) - getWidth();
		 
		mDrawablesLoaded = true;
	} 
	 
	public void setInterpolation(float interpolatedTime) {
		mInterpolatedTime = interpolatedTime;
	} 
 
	@Override 
	public void onAnimationRepeat(Animation animation) {
		mCurrentDrawable = (mCurrentDrawable + 1) % mBackgroundResourceIds.length;
		setInterpolation(0); 
		mDrawablesLoaded = false;
	} 
	 
	@Override 
	public void onAnimationStart(Animation animation) { } // TODO Auto-generated method stub
	 
	@Override 
	public void onAnimationEnd(Animation animation) { } // TODO Auto-generated method stub
 
	@Override 
	protected void onDraw(Canvas canvas) {
		if(!mDrawablesLoaded) {
			loadDrawables(); 
		} 
		 
		// images should start at position x=-deltaX and end at position x=0 
		// the images are on the screen for one full cycle plus the fade out time 
		// of the next cycle, so a cycle is effectivly 1 + FADE_IN_FRACTION 
		if(mInterpolatedTime < FADE_IN_FRACTION) {
			Matrix outgoingMatrix = new Matrix();
			outgoingMatrix.postScale(mOutgoingScale, mOutgoingScale);
			float outgoingTransX = -mOutgoingDeltaX + mOutgoingDeltaX * (1 + mInterpolatedTime) / (1 + FADE_IN_FRACTION);
			outgoingMatrix.postTranslate(Math.round(outgoingTransX), 0.0f);
			canvas.drawBitmap(mOutgoingDrawable.getBitmap(), outgoingMatrix, null);
			 
			Matrix incomingMatrix = new Matrix();
			incomingMatrix.postScale(mIncomingScale, mIncomingScale);
			float incomingTransX = -mIncomingDeltaX + mIncomingDeltaX * (mInterpolatedTime) / (1 + FADE_IN_FRACTION);
			incomingMatrix.postTranslate(Math.round(incomingTransX), 0.0f);
			Paint translucentPaint = new Paint();
			translucentPaint.setAlpha(Math.round(255 * mInterpolatedTime / FADE_IN_FRACTION));
			canvas.drawBitmap(mIncomingDrawable.getBitmap(), incomingMatrix, translucentPaint);
		} else { 
			Matrix incomingMatrix = new Matrix();
			incomingMatrix.postScale(mIncomingScale, mIncomingScale);
			float incomingTransX = -mIncomingDeltaX + mIncomingDeltaX * (mInterpolatedTime) / (1 + FADE_IN_FRACTION);
			incomingMatrix.postTranslate(Math.round(incomingTransX), 0.0f);
			canvas.drawBitmap(mIncomingDrawable.getBitmap(), incomingMatrix, null);
		} 
	} 
	 
	private class BackgroundAnimation extends Animation {