package com.metaio.cloud.plugin.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.AsyncTask.Status;
import android.util.AttributeSet;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.DecelerateInterpolator;
import android.widget.ImageButton;
import android.widget.ImageView;
import com.metaio.cloud.plugin.MetaioCloudPlugin;
import com.metaio.cloud.plugin.data.RemoteAssetsManager;
import com.metaio.sdk.MetaioDebug;

public class RemoteImageView extends ImageButton
{
  private DownloadImage downloader;
  private Animation fadein;
  private Animation fadeout;
  private String mURL = null;

  public RemoteImageView(Context paramContext)
  {
    super(paramContext);
    initAnims();
  }

  public RemoteImageView(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
    initAnims();
  }

  private void initAnims()
  {
    this.fadein = new AlphaAnimation(0.0F, 1.0F);
    this.fadein.setDuration(150L);
    this.fadein.setInterpolator(new DecelerateInterpolator());
    this.fadein.setFillAfter(true);
    this.fadeout = new AlphaAnimation(1.0F, 0.0F);
    this.fadeout.setDuration(150L);
    this.fadeout.setInterpolator(new AccelerateInterpolator());
  }

  public void cancelDownload()
  {
    if ((this.downloader != null) && (!this.downloader.getStatus().equals(AsyncTask.Status.FINISHED)))
      this.downloader.cancel(true);
  }

  public String getRemoteSource()
  {
    return this.mURL;
  }

  public void setRemoteSource(String paramString)
  {
    this.mURL = paramString;
    try
    {
      if (MetaioCloudPlugin.getRemoteAssetsManager(getContext()).getImage(this.mURL) == null)
      {
        DownloadImage localDownloadImage = new DownloadImage(this);
        String[] arrayOfString = new String[1];
        arrayOfString[0] = this.mURL;
        localDownloadImage.execute(arrayOfString);
        MetaioDebug.log("Downloading image " + this.mURL);
        return;
      }
      setImageBitmap(MetaioCloudPlugin.getRemoteAssetsManager(getContext()).getImage(this.mURL));
      MetaioDebug.log("Image cached " + this.mURL);
      return;
    }
    catch (NullPointerException localNullPointerException)
    {
    }
  }

  public void setRemoteSource(String paramString1, String paramString2)
  {
    if (paramString2.startsWith("?"))
    {
      setRemoteSource(paramString1 + paramString2);
      return;
    }
    setRemoteSource(paramString1 + "?" + paramString2);
  }

  private class DownloadImage extends AsyncTask<String, Integer, Bitmap>
  {
    private ImageView mImageView;
    String url;

    public DownloadImage(ImageView arg2)
    {
      Object localObject;
      this.mImageView = localObject;
    }

    protected Bitmap doInBackground(String[] paramArrayOfString)
    {
      try
      {
        this.url = paramArrayOfString[0];
        if (paramArrayOfString.length > 1)
          MetaioCloudPlugin.getRemoteAssetsManager(RemoteImageView.this.getContext()).downloadImage(this, paramArrayOfString[0], paramArrayOfString[1]);
        while (true)
        {
          return MetaioCloudPlugin.getRemoteAssetsManager(RemoteImageView.this.getContext()).getImage(paramArrayOfString[0]);
          MetaioCloudPlugin.getRemoteAssetsManager(RemoteImageView.this.getContext()).downloadImage(this, paramArrayOfString[0], null);
        }
      }
      catch (Exception localException)
      {
      }
      return null;
    }

    protected void onPostExecute(final Bitmap paramBitmap)
    {
      try
      {
        if ((!isCancelled()) && (paramBitmap != null) && (((this.mImageView.getTag() != null) && (this.mImageView.getTag().toString().equalsIgnoreCase(this.url))) || (this.mImageView.getTag() == null)))
        {
          RemoteImageView.this.fadeout.setAnimationListener(new Animation.AnimationListener()
          {
            public void onAnimationEnd(Animation paramAnonymousAnimation)
            {
              RemoteImageView.DownloadImage.this.mImageView.setImageBitmap(paramBitmap);
              RemoteImageView.DownloadImage.this.mImageView.startAnimation(RemoteImageView.this.fadein);
            }

            public void onAnimationRepeat(Animation paramAnonymousAnimation)
            {
            }

            public void onAnimationStart(Animation paramAnonymousAnimation)
            {
            }
          });
          this.mImageView.startAnimation(RemoteImageView.this.fadeout);
        }
        return;
      }
      catch (Exception localException)
      {
      }
    }

    protected void onProgressUpdate(Integer[] paramArrayOfInteger)
    {
    }
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.metaio.cloud.plugin.view.RemoteImageView
 * JD-Core Version:    0.6.2
 */