<commit_before>/*
 * (C) Copyright 2009-2011 Smart&Soft SAS (http://www.smartnsoft.com/) and contributors.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * Contributors:
 *     Smart&Soft - initial API and implementation
 */
package com.smartnsoft.droid4me.download;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Map;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.view.View;
import android.widget.ImageView;

import com.smartnsoft.droid4me.download.DownloadContracts.Bitmapable;
import com.smartnsoft.droid4me.download.DownloadContracts.Handlerable;
import com.smartnsoft.droid4me.download.DownloadContracts.Viewable;

/**
 * Gathers in one place the download instructions contracts used by {@link BitmapDownloader}.
 * 
 * @author <NAME>
 * @since 2011.07.03
 */
public class DownloadInstructions
    extends BasisDownloadInstructions
{

  /**
   * An implementation of the {@link BitmapableBitmap} interface specific to the Android platform.
   */
  public final static class BitmapableBitmap
      implements Bitmapable
  {

    private final Bitmap bitmap;

    /**
     * Creates a wrapper around the provided actual Android bitmap.
     * 
     * @param bitmap
     *          the bitmap to be wrapped
     */
    public BitmapableBitmap(Bitmap bitmap)
    {
      this.bitmap = bitmap;
    }

    /**
     * @return the wrapped bitmap
     */
    public Bitmap getBitmap()
    {
      return bitmap;
    }

    public int getSizeInBytes()
    {
      return bitmap == null ? 0 : bitmap.getWidth() * bitmap.getHeight() * 4;
    }

    public void recycle()
    {
      if (bitmap != null)
      {
        bitmap.recycle();
      }
    }

  }

  /**
   * An implementation of the {@link Viewable} interface specific to the Android platform.
   */
  public final static class ViewableView
      implements Viewable
  {

    private final View view;

    /**<commit_msg>Refines the way the size in bytes of a "Bitmap" is computed.<commit_after>/*
 * (C) Copyright 2009-2011 Smart&Soft SAS (http://www.smartnsoft.com/) and contributors.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * Contributors:
 *     Smart&Soft - initial API and implementation
 */
package com.smartnsoft.droid4me.download;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Map;

import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.view.View;
import android.widget.ImageView;

import com.smartnsoft.droid4me.download.DownloadContracts.Bitmapable;
import com.smartnsoft.droid4me.download.DownloadContracts.Handlerable;
import com.smartnsoft.droid4me.download.DownloadContracts.Viewable;

/**
 * Gathers in one place the download instructions contracts used by {@link BitmapDownloader}.
 * 
 * @author <NAME>
 * @since 2011.07.03
 */
public class DownloadInstructions
    extends BasisDownloadInstructions
{

  /**
   * An implementation of the {@link BitmapableBitmap} interface specific to the Android platform.
   */
  public final static class BitmapableBitmap
      implements Bitmapable
  {

    private final Bitmap bitmap;

    /**
     * Creates a wrapper around the provided actual Android bitmap.
     * 
     * @param bitmap
     *          the bitmap to be wrapped
     */
    public BitmapableBitmap(Bitmap bitmap)
    {
      this.bitmap = bitmap;
    }

    /**
     * @return the wrapped bitmap
     */
    public Bitmap getBitmap()
    {
      return bitmap;
    }

    public int getSizeInBytes()
    {
      return bitmap == null ? 0 : (bitmap.getWidth() * bitmap.getHeight()) * (bitmap.getConfig() == Config.ARGB_8888 ? 4
          : (bitmap.getConfig() == Config.ALPHA_8 ? 1 : 2));
    }

    public void recycle()
    {
      if (bitmap != null)
      {
        bitmap.recycle();
      }
    }

  }

  /**
   * An implementation of the {@link Viewable} interface specific to the Android platform.
   */
  public final static class ViewableView
      implements Viewable
  {

    private final View view;

    /**
{'fraction_non_alphanumeric': 0.08833718244803695, 'fraction_numerical': 0.010585065434949961, 'mean_word_length': 3.1377388535031847, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '830775', 'n_tokens_mistral': 1476, 'n_tokens_neox': 1409, 'n_words': 479}