package com.ikea.kompis.view;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.FloatEvaluator;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Resources;
import android.os.Handler;
import android.support.v4.view.ViewCompat;
import android.text.SpannableString;
import android.text.style.StyleSpan;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewConfiguration;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewParent;
import android.view.ViewPropertyAnimator;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import com.ikea.kompis.util.C.Anim;
import com.ikea.shared.cart.ShoppingCart;
import com.ikea.shared.products.model.RetailItemCommunication;
import com.ikea.shared.util.Constant;
import com.ikea.shared.util.L;
import java.util.UnknownFormatConversionException;

public class SLAlertLayout extends FrameLayout
{
  private final Runnable dismissSLItem = new Runnable()
  {
    public void run()
    {
      SLAlertLayout.this.performDismissItem();
    }
  };
  private TextView mAlertText;
  private float mAnimFrom;
  private float mAnimTo;
  private ValueAnimator mAnimator;
  private Context mContext;
  private View mFadeView;
  private View mFrontView;
  private final Handler mHandler = new Handler();
  private ImageView mImageAlertDiscontinued;
  private ImageView mImageAlertPrice;
  private RetailItemCommunication mItem;
  private final View.OnTouchListener mTouch = new View.OnTouchListener()
  {
    float mDownX;
    float mDownY;
    float mInitialTx;

    @SuppressLint({"ClickableViewAccessibility"})
    public boolean onTouch(View paramAnonymousView, MotionEvent paramAnonymousMotionEvent)
    {
      boolean bool = true;
      switch (paramAnonymousMotionEvent.getActionMasked())
      {
      default:
      case 0:
      case 2:
      case 1:
      case 3:
      }
      while (true)
      {
        bool = false;
        float f2;
        float f4;
        do
        {
          return bool;
          this.mDownX = paramAnonymousMotionEvent.getRawX();
          this.mDownY = paramAnonymousMotionEvent.getRawY();
          this.mInitialTx = SLAlertLayout.this.mFrontView.getTranslationX();
          SLAlertLayout.this.updatePressedState(bool);
          return bool;
          f2 = paramAnonymousMotionEvent.getRawX() - this.mDownX;
          float f3 = paramAnonymousMotionEvent.getRawY() - this.mDownY;
          if (((Math.abs(f2) <= 2 * ViewConfiguration.get(SLAlertLayout.this.getContext()).getScaledTouchSlop()) || (Math.abs(f3) >= Math.abs(f2) / 2.0F)) && (!SLAlertLayout.this.mTracking))
            break;
          SLAlertLayout.access$302(SLAlertLayout.this, bool);
          SLAlertLayout.this.getParent().requestDisallowInterceptTouchEvent(bool);
          L.D("tX" + SLAlertLayout.this.mFrontView.getTranslationX() + "   dX " + f2);
          SLAlertLayout.this.updatePressedState(false);
          if ((SLAlertLayout.this.mFrontView.getTranslationX() > 3.0F * SLAlertLayout.this.mWidth / 4.0F) || (SLAlertLayout.this.mFrontView.getTranslationX() < -(3.0F * SLAlertLayout.this.mWidth / 4.0F)))
            break;
          f4 = f2 + this.mInitialTx;
          if (f4 > 3.0F * SLAlertLayout.this.mWidth / 4.0F)
          {
            SLAlertLayout.this.removeItem(bool);
            L.I("testing", "testing one ");
            return bool;
          }
          if (f4 < -(3.0F * SLAlertLayout.this.mWidth / 4.0F))
          {
            SLAlertLayout.this.removeItem(false);
            L.I("testing", "testing two ");
            return bool;
          }
        }
        while ((f4 < -(3.0F * SLAlertLayout.this.mWidth / 4.0F)) || (f4 > 3.0F * SLAlertLayout.this.mWidth / 4.0F));
        SLAlertLayout.this.translateTo(f2 + this.mInitialTx);
        L.I("testing", "testing final ");
        return bool;
        SLAlertLayout.this.updatePressedState(false);
        if (SLAlertLayout.this.mTracking)
        {
          SLAlertLayout.access$302(SLAlertLayout.this, false);
          float f1 = SLAlertLayout.this.mFrontView.getTranslationX();
          if (f1 > SLAlertLayout.this.mWidth / 4.0F)
          {
            SLAlertLayout.this.removeItem(bool);
            L.I(this, " Right ");
          }
          while (true)
          {
            SLAlertLayout.this.moveToDefault();
            return bool;
            if (f1 < -(SLAlertLayout.this.mWidth / 4.0F))
            {
              SLAlertLayout.this.removeItem(false);
              L.I(this, " Left ");
            }
          }
        }
        SLAlertLayout.this.closeQuickMenu();
        continue;
        SLAlertLayout.this.updatePressedState(false);
      }
    }
  };
  private boolean mTracking;
  private float mWidth;

  public SLAlertLayout(Context paramContext)
  {
    this(paramContext, null, 0);
    this.mContext = paramContext;
  }

  public SLAlertLayout(Context paramContext, AttributeSet paramAttributeSet)
  {
    this(paramContext, paramAttributeSet, 0);
    this.mContext = paramContext;
  }

  public SLAlertLayout(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
  {
    super(paramContext, paramAttributeSet, paramInt);
    final FloatEvaluator localFloatEvaluator = new FloatEvaluator();
    this.mAnimator = ValueAnimator.ofFloat(new float[] { 0.0F, 1.0F });
    this.mAnimator.setDuration(500L);
    this.mAnimator.setInterpolator(C.Anim.EASE_OUT_QUART_INTERPOLATOR);
    this.mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
    {
      public void onAnimationUpdate(ValueAnimator paramAnonymousValueAnimator)
      {
        float f = localFloatEvaluator.evaluate(paramAnonymousValueAnimator.getAnimatedFraction(), Float.valueOf(SLAlertLayout.this.mAnimFrom), Float.valueOf(SLAlertLayout.this.mAnimTo)).floatValue();
        SLAlertLayout.this.translateTo(f);
      }
    });
  }

  private void animateTo(float paramFloat)
  {
    this.mAnimFrom = this.mFrontView.getTranslationX();
    this.mAnimTo = paramFloat;
    this.mAnimator.start();
  }

  private void handleRemoveItemFromSL()
  {
    this.mHandler.post(this.dismissSLItem);
  }

  private void initSLALertItem()
  {
    this.mImageAlertDiscontinued = ((ImageView)findViewById(2131624359));
    this.mImageAlertPrice = ((ImageView)findViewById(2131624358));
    this.mAlertText = ((TextView)findViewById(2131624360));
    this.mFrontView = findViewById(2131624357);
    this.mFrontView.setOnTouchListener(this.mTouch);
    this.mFadeView = findViewById(2131624361);
  }

  private void moveToDefault()
  {
    L.I("moveToDefault");
    animateTo(0.0F);
  }

  private void performDismissItem()
  {
    final ViewGroup.LayoutParams localLayoutParams = getLayoutParams();
    ValueAnimator localValueAnimator = ValueAnimator.ofInt(new int[] { getHeight(), 1 }).setDuration(500L);
    localValueAnimator.addListener(new AnimatorListenerAdapter()
    {
      public void onAnimationEnd(Animator paramAnonymousAnimator)
      {
        SLAlertLayout.this.setVisibility(8);
        Constant.i().setUpdateSlAfterItemDeleted(true);
        if (SLAlertLayout.this.mItem != null)
        {
          if (SLAlertLayout.this.mItem.getUpdatedPriceProducts() > 0)
            ShoppingCart.i(SLAlertLayout.this.mContext).resetUpdatedPriceProducts();
          if (SLAlertLayout.this.mItem.getDiscontinuedProducts() > 0)
            ShoppingCart.i(SLAlertLayout.this.mContext).resetDiscontinuedProducts();
        }
        SLAlertLayout.this.setViewTransientState(false);
      }
    });
    localValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
    {
      public void onAnimationUpdate(ValueAnimator paramAnonymousValueAnimator)
      {
        localLayoutParams.height = ((Integer)paramAnonymousValueAnimator.getAnimatedValue()).intValue();
        SLAlertLayout.this.setLayoutParams(localLayoutParams);
      }
    });
    localValueAnimator.start();
  }

  private void removeItem(boolean paramBoolean)
  {
    if (paramBoolean)
      this.mFrontView.animate().translationXBy(this.mWidth);
    while (true)
    {
      L.D("Remove operation strat");
      setViewTransientState(true);
      handleRemoveItemFromSL();
      return;
      this.mFrontView.animate().translationXBy(-this.mWidth);
    }
  }

  private void setViewTransientState(boolean paramBoolean)
  {
    ViewCompat.setHasTransientState(this, paramBoolean);
  }

  private void translateTo(float paramFloat)
  {
    this.mFrontView.setTranslationX(paramFloat);
    this.mFrontView.setAlpha(1.0F - Math.abs(paramFloat) / this.mWidth);
  }

  private void updatePressedState(boolean paramBoolean)
  {
    View localView = this.mFadeView;
    if (paramBoolean);
    for (int i = 0; ; i = 8)
    {
      localView.setVisibility(i);
      return;
    }
  }

  public void closeQuickMenu()
  {
    L.D("closeQuickMenu");
    if (0.0F != this.mFrontView.getTranslationX())
      moveToDefault();
  }

  protected void onFinishInflate()
  {
    super.onFinishInflate();
    initSLALertItem();
  }

  protected void onSizeChanged(int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    super.onSizeChanged(paramInt1, paramInt2, paramInt3, paramInt4);
    this.mWidth = paramInt1;
  }

  public void updateSLAlertView(Context paramContext, RetailItemCommunication paramRetailItemCommunication)
  {
    this.mItem = paramRetailItemCommunication;
    this.mContext = paramContext;
    int i = paramRetailItemCommunication.getUpdatedPriceProducts();
    int j = paramRetailItemCommunication.getDiscontinuedProducts();
    Object localObject2;
    String str4;
    if (i > 0)
    {
      localObject2 = "";
      str4 = this.mContext.getResources().getString(2131165722);
      if (i != 1);
    }
    while (true)
    {
      try
      {
        StringBuilder localStringBuilder4 = new StringBuilder();
        Resources localResources4 = this.mContext.getResources();
        Object[] arrayOfObject4 = new Object[1];
        arrayOfObject4[0] = Integer.valueOf(i);
        String str6 = localResources4.getString(2131165419, arrayOfObject4) + " " + str4;
        localObject2 = str6;
        localSpannableString = new SpannableString((CharSequence)localObject2);
        localSpannableString.setSpan(new StyleSpan(1), ((String)localObject2).indexOf(str4), ((String)localObject2).length(), 33);
        k = 0;
        m = 8;
        if (localSpannableString != null)
          this.mAlertText.setText(localSpannableString);
        this.mImageAlertPrice.setVisibility(k);
        this.mImageAlertDiscontinued.setVisibility(m);
        return;
        StringBuilder localStringBuilder3 = new StringBuilder();
        Resources localResources3 = this.mContext.getResources();
        Object[] arrayOfObject3 = new Object[1];
        arrayOfObject3[0] = Integer.valueOf(i);
        String str5 = localResources3.getString(2131165418, arrayOfObject3) + " " + str4;
        localObject2 = str5;
        continue;
      }
      catch (UnknownFormatConversionException localUnknownFormatConversionException2)
      {
        localUnknownFormatConversionException2.printStackTrace();
        continue;
      }
      catch (Exception localException2)
      {
        localException2.printStackTrace();
        continue;
      }
      int k = 0;
      int m = 0;
      SpannableString localSpannableString = null;
      if (j <= 0)
        continue;
      Object localObject1 = "";
      String str1 = this.mContext.getResources().getString(2131165308);
      if (i == 1);
      try
      {
        StringBuilder localStringBuilder2 = new StringBuilder();
        Resources localResources2 = this.mContext.getResources();
        Object[] arrayOfObject2 = new Object[1];
        arrayOfObject2[0] = Integer.valueOf(j);
        String str3 = localResources2.getString(2131165421, arrayOfObject2) + " " + str1;
        String str2;
        for (localObject1 = str3; ; localObject1 = str2)
        {
          localSpannableString = new SpannableString((CharSequence)localObject1);
          localSpannableString.setSpan(new StyleSpan(1), ((String)localObject1).indexOf(str1), ((String)localObject1).length(), 33);
          k = 8;
          m = 0;
          break;
          StringBuilder localStringBuilder1 = new StringBuilder();
          Resources localResources1 = this.mContext.getResources();
          Object[] arrayOfObject1 = new Object[1];
          arrayOfObject1[0] = Integer.valueOf(j);
          str2 = localResources1.getString(2131165420, arrayOfObject1) + " " + str1;
        }
      }
      catch (UnknownFormatConversionException localUnknownFormatConversionException1)
      {
        while (true)
          localUnknownFormatConversionException1.printStackTrace();
      }
      catch (Exception localException1)
      {
        while (true)
          localException1.printStackTrace();
      }
    }
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.ikea.kompis.view.SLAlertLayout
 * JD-Core Version:    0.6.2
 */