/*
 * $URL$
 * $Revision$
 * $LastChangedBy$
 * $LastChangedDate$
 *
 * Copyright (c) 2005 syseca AG, Switzerland
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of syseca AG. ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only
 * in accordance with the terms of the license agreement you
 * entered into with syseca AG.
 */
package ch.spherIC.resultlist;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Bitmap.Config;
import android.graphics.Paint.Style;
import ch.spherIC.R;


/**
 * Factory that creates the exposure icons according to the EV range and values.
 */
public class ExposureIconFactory {

    /**
     * Retrieves Icon.
     *
     * @param   context  Context
     * @param   exp {@link Exposure} object
     *
     * @return  Color stepped icon
     */
    public static Bitmap getExpIcon(Context context, Exposure exp) {

        Bitmap mIcon;
        Bitmap mIconBG;
        Bitmap mIconSymbol;
        Bitmap mIconSymbol_bl;
        Canvas canvas;
        Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        final Resources res = context.getResources();

        // The background
        mIconBG = Bitmap.createBitmap(36, 36, Config.ARGB_8888);
        mIconBG.eraseColor(0x00000000);
        canvas = new Canvas(mIconBG);
        mPaint.setStyle(Style.FILL);
        mPaint.setColor(0xFF000000);
        canvas.drawRect(2, 2, 33, 33, mPaint);

        // Let's retrieve all icon pieces as Bitmaps.
        mIcon = BitmapFactory.decodeResource(res, R.drawable.exposureicon_frame);
        mIconSymbol = BitmapFactory.decodeResource(res, R.drawable.exposureicon_symb_white);
        mIconSymbol_bl = BitmapFactory.decodeResource(res, R.drawable.exposureicon_symb_black);

        // Prepares the paint that will be used to draw our icon mask. Using
        // PorterDuff.Mode.SRC_OVER means the image that will be drawn will
        // mask the already drawn image.
        mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));

        // We're now ready to drawn our Android-like icon :)
        canvas.drawBitmap(mIconSymbol, 0, 0, mPaint);
        canvas.drawBitmap(mIcon, 0, 0, mPaint);

        return mIconBG;
    }
}
