/**
 * Copyright (C) 2005-2012 XELOG AG
 */
package ch.spherIC.recurvebowsight.utilities;

import android.app.AlertDialog;

import android.content.Context;
import android.content.DialogInterface;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;

import ch.spherIC.recurvebowsight.R;


/**
 * @author  FC Smilari
 */
public class PlatformUtils {

    public static int platformSelectionColor;


    public static int getPlatformSelectionColor(final Context ctx) {

        Bitmap bitmap = BitmapFactory.decodeResource(ctx.getResources(), android.R.drawable.list_selector_background);

        int redBucket = 0;
        int greenBucket = 0;
        int blueBucket = 0;
        int pixelCount = 0;

        if (bitmap != null) {
            for (int y = 0; y < bitmap.getHeight(); y++) {
                for (int x = 0; x < bitmap.getWidth(); x++) {
                    int c = bitmap.getPixel(x, y);

                    pixelCount++;
                    redBucket += Color.red(c);
                    greenBucket += Color.green(c);
                    blueBucket += Color.blue(c);
                    // does alpha matter?
                }
            }

            platformSelectionColor = Color.rgb(redBucket / pixelCount, greenBucket / pixelCount, blueBucket / pixelCount);
            return platformSelectionColor;
        }

        return 0;
    }

    public static AlertDialog getDeleteConfirmDialog(final Context context, final String itemToDelete,
                                                     final DialogInterface.OnClickListener okListener) {


        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        String msg = context.getResources().getString(R.string.caption_DeleteMsg, itemToDelete);
        builder = builder.setTitle(R.string.caption_ConfirmDelete).setMessage(msg);
        builder = builder.setPositiveButton(R.string.caption_Delete, okListener).setNegativeButton(android.R.string.cancel, null);

        // Create the AlertDialog object and return it
        return builder.create();
    }

}
