package com.ikea.kompis.util;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.SparseIntArray;
import android.view.MotionEvent;
import android.view.View.MeasureSpec;
import android.view.ViewConfiguration;
import android.view.ViewParent;
import android.widget.ImageView;
import com.ikea.shared.util.L;
import java.util.ArrayList;

public class RangeSeekBar extends ImageView
{
  public static final int ACTION_POINTER_INDEX_MASK = 65280;
  public static final int ACTION_POINTER_INDEX_SHIFT = 8;
  public static final int ACTION_POINTER_UP = 6;
  public static final int INVALID_POINTER_ID = 255;
  private double currentmax;
  private double currentmin;
  private int mActivePointerId = 255;
  private float mDownMotionX;
  private final double mInitialMaxValue;
  private final double mInitialMinValue;
  private boolean mIsDragging;
  private OnPriceSeekBarChangeListener mListener;
  private double mNormalizedMaxValue = 1.0D;
  private double mNormalizedMinValue = 0.0D;
  private boolean mNotifyWhileDragging = false;
  private final Paint mPaint = new Paint(1);
  private Thumb mPressedSeek = null;
  private ArrayList<Integer> mPriceRange;
  private int mScaledTouchSlop;
  private float mSeekBarGap;
  private float mSeekBarLineHeight;
  private int mStepValue;
  private float mThumbHalfHeight;
  private float mThumbHalfWidth;
  private float mThumbIcomPadding;
  private Bitmap mThumbIconNormal = null;
  private Bitmap mThumbIconPressed = null;
  int maxIndex = -1 + this.step.size();
  int minIndex = 0;
  final SparseIntArray step = new SparseIntArray();

  public RangeSeekBar(int paramInt1, int paramInt2, int paramInt3, int paramInt4, ArrayList<Integer> paramArrayList, Context paramContext)
  {
    super(paramContext);
    this.mInitialMinValue = paramInt1;
    this.mInitialMaxValue = paramInt2;
    setFocusable(true);
    setFocusableInTouchMode(true);
    Drawable localDrawable1 = getContext().getResources().getDrawable(2130837874);
    Drawable localDrawable2 = getContext().getResources().getDrawable(2130837875);
    this.mThumbIconNormal = drawableToBitmap(localDrawable1);
    this.mThumbIconPressed = drawableToBitmap(localDrawable2);
    this.mThumbHalfWidth = (0.5F * this.mThumbIconPressed.getWidth());
    this.mThumbHalfHeight = (0.5F * this.mThumbIconPressed.getHeight());
    this.mSeekBarLineHeight = UiUtil.pxFromDp(getContext(), 4.0F);
    this.mSeekBarGap = UiUtil.pxFromDp(getContext(), 3.0F);
    this.mThumbIcomPadding = this.mThumbHalfWidth;
    L.I("seekbar line height " + this.mSeekBarLineHeight);
    setCurrentMaxValue(paramInt4);
    setCurrentMinValue(paramInt3);
    if (paramArrayList != null)
      this.mPriceRange = paramArrayList;
    this.mScaledTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
    setStepValue();
  }

  private float convertNormalizedToScreenPoint(double paramDouble)
  {
    return (float)(this.mThumbIcomPadding + paramDouble * (getWidth() - 2.0F * this.mThumbIcomPadding));
  }

  private double convertScreenPointToNormalized(float paramFloat)
  {
    int i = getWidth();
    if (i <= 2.0F * this.mThumbIcomPadding)
      return 0.0D;
    return Math.min(1.0D, Math.max(0.0D, (paramFloat - this.mThumbIcomPadding) / (i - 2.0F * this.mThumbIcomPadding)));
  }

  private Thumb detectPressedThumb(float paramFloat)
  {
    boolean bool1 = isInThumbRange(paramFloat, this.mNormalizedMinValue);
    boolean bool2 = isInThumbRange(paramFloat, this.mNormalizedMaxValue);
    Thumb localThumb;
    if ((bool1) && (bool2))
      if (paramFloat / getWidth() > 0.5F)
        localThumb = Thumb.MIN_THUMB;
    do
    {
      return localThumb;
      return Thumb.MAX_THUMB;
      if (bool1)
        return Thumb.MIN_THUMB;
      localThumb = null;
    }
    while (!bool2);
    return Thumb.MAX_THUMB;
  }

  private void drawSeek(float paramFloat, boolean paramBoolean, Canvas paramCanvas)
  {
    if (paramBoolean);
    for (Bitmap localBitmap = this.mThumbIconPressed; ; localBitmap = this.mThumbIconNormal)
    {
      paramCanvas.drawBitmap(localBitmap, paramFloat - this.mThumbHalfWidth, 0.5F * getHeight() - this.mThumbHalfHeight, this.mPaint);
      return;
    }
  }

  private final void handleSecondaryPointerUp(MotionEvent paramMotionEvent)
  {
    int i = (0xFF00 & paramMotionEvent.getAction()) >> 8;
    if (paramMotionEvent.getPointerId(i) == this.mActivePointerId)
      if (i != 0)
        break label48;
    label48: for (int j = 1; ; j = 0)
    {
      this.mDownMotionX = paramMotionEvent.getX(j);
      this.mActivePointerId = paramMotionEvent.getPointerId(j);
      return;
    }
  }

  private boolean isInThumbRange(float paramFloat, double paramDouble)
  {
    return Math.abs(paramFloat - convertNormalizedToScreenPoint(paramDouble)) <= this.mThumbHalfWidth;
  }

  private final void setNormalizedValue(MotionEvent paramMotionEvent)
  {
    float f = paramMotionEvent.getX(paramMotionEvent.findPointerIndex(this.mActivePointerId));
    if (Thumb.MIN_THUMB.equals(this.mPressedSeek))
      setNormalizedMinValue(convertScreenPointToNormalized(f));
    while (!Thumb.MAX_THUMB.equals(this.mPressedSeek))
      return;
    setNormalizedMaxValue(convertScreenPointToNormalized(f));
  }

  private void setStepValue()
  {
    this.mStepValue = ((int)((this.mInitialMaxValue - this.mInitialMinValue) / 100.0D));
    L.D("step Value " + this.mStepValue);
    if (this.mStepValue == 0)
      this.mStepValue = 1;
  }

  private void updateBar()
  {
    if (Thumb.MIN_THUMB.equals(this.mPressedSeek))
    {
      L.D("min testtt iss ");
      j = getMinValue((int)getCurrentMinValue());
      this.currentmin = j;
      setCurrentMinValue(j);
    }
    while (!Thumb.MAX_THUMB.equals(this.mPressedSeek))
    {
      int j;
      return;
    }
    L.D("max testtt iss ");
    int i = getMaxValue((int)getCurrentMaxValue());
    this.currentmax = i;
    setCurrentMaxValue(i);
  }

  private void updateSeekBar()
  {
    int i = this.step.size();
    if (Thumb.MIN_THUMB.equals(this.mPressedSeek))
    {
      n = this.step.keyAt(0);
      i1 = (int)getCurrentMinValue();
      i2 = 0;
      if ((i2 >= i) || (this.step.keyAt(i2) > i1))
      {
        L.I("min value " + i1);
        L.I("min value " + n);
        setCurrentMinValue(n);
      }
    }
    while (!Thumb.MAX_THUMB.equals(this.mPressedSeek))
    {
      int n;
      int i1;
      int i2;
      return;
      if (i2 < this.maxIndex)
      {
        n = this.step.keyAt(i2);
        this.minIndex = i2;
      }
      while (true)
      {
        i2++;
        break;
        if (i2 - 1 > 0)
        {
          n = this.step.keyAt(i2 - 1);
          this.minIndex = (i2 - 1);
        }
        else
        {
          n = this.step.keyAt(0);
          this.minIndex = 0;
        }
      }
    }
    int j = (int)getCurrentMaxValue();
    int k = this.step.keyAt(i - 1);
    int m = i - 1;
    if ((m < 0) || (this.step.keyAt(m) < j))
    {
      L.I("max value " + j);
      L.I("max value " + k);
      setCurrentMaxValue(k);
      return;
    }
    if (m > this.minIndex)
    {
      k = this.step.keyAt(m);
      this.maxIndex = m;
    }
    while (true)
    {
      m--;
      break;
      if (m + 1 < i - 1)
      {
        k = this.step.keyAt(m + 1);
        this.maxIndex = (m + 1);
      }
      else
      {
        k = this.step.keyAt(i - 1);
        this.maxIndex = (i - 1);
      }
    }
  }

  private void updateValue()
  {
    if (Thumb.MIN_THUMB.equals(this.mPressedSeek))
    {
      int k = (int)getCurrentMinValue();
      if (k == (int)getCurrentMaxValue())
        setCurrentMinValue(k - this.mStepValue);
    }
    int i;
    int j;
    do
    {
      do
        return;
      while (!Thumb.MAX_THUMB.equals(this.mPressedSeek));
      i = (int)getCurrentMinValue();
      j = (int)getCurrentMaxValue();
    }
    while (i != j);
    setCurrentMaxValue(j + this.mStepValue);
  }

  public Bitmap drawableToBitmap(Drawable paramDrawable)
  {
    if ((paramDrawable instanceof BitmapDrawable))
      return ((BitmapDrawable)paramDrawable).getBitmap();
    Bitmap localBitmap = Bitmap.createBitmap(paramDrawable.getIntrinsicWidth(), paramDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas localCanvas = new Canvas(localBitmap);
    paramDrawable.setBounds(0, 0, localCanvas.getWidth(), localCanvas.getHeight());
    paramDrawable.draw(localCanvas);
    return localBitmap;
  }

  public double getCurrentMaxValue()
  {
    return this.mInitialMinValue + this.mNormalizedMaxValue * (this.mInitialMaxValue - this.mInitialMinValue);
  }

  public double getCurrentMinValue()
  {
    return this.mInitialMinValue + this.mNormalizedMinValue * (this.mInitialMaxValue - this.mInitialMinValue);
  }

  public double getInitialMaxValue()
  {
    return this.mInitialMaxValue;
  }

  public double getInitialMinValue()
  {
    return this.mInitialMinValue;
  }

  int getMaxValue(int paramInt)
  {
    int i = (int)this.mInitialMaxValue;
    int j = paramInt / this.mStepValue;
    int k = paramInt % this.mStepValue;
    L.D("value maxx " + j);
    if (j > 0)
      if (k <= 0)
        break label130;
    label130: for (i = (j + 1) * this.mStepValue; ; i = j * this.mStepValue)
    {
      if ((i == this.currentmin) || (i < this.currentmin))
        i += this.mStepValue;
      if (i > this.mInitialMaxValue)
        i = (int)this.mInitialMaxValue;
      L.D("value max " + i);
      return i;
    }
  }

  int getMinValue(int paramInt)
  {
    L.D("value 000 " + paramInt);
    int i = (int)this.mInitialMinValue;
    int j;
    if (paramInt > this.mStepValue)
    {
      int k = (paramInt - i) / this.mStepValue;
      L.D("value iss " + k);
      j = i + k * this.mStepValue;
      L.D("value min " + j);
    }
    while (true)
    {
      if (j > this.currentmax)
        j -= this.mStepValue;
      if ((j == this.currentmax) && (j > 0))
        j -= this.mStepValue;
      return j;
      j = (int)this.mInitialMinValue;
    }
  }

  public boolean isNotifyWhileDragging()
  {
    return this.mNotifyWhileDragging;
  }

  protected void onDraw(Canvas paramCanvas)
  {
    try
    {
      super.onDraw(paramCanvas);
      RectF localRectF = new RectF(this.mThumbIcomPadding, 0.5F * (getHeight() - this.mSeekBarLineHeight), getWidth() - this.mThumbIcomPadding, 0.5F * (getHeight() + this.mSeekBarLineHeight));
      this.mPaint.setStyle(Paint.Style.FILL);
      this.mPaint.setColor(getContext().getResources().getColor(2131492913));
      this.mPaint.setAntiAlias(true);
      float f = UiUtil.pxFromDp(getContext(), 2.0F);
      paramCanvas.drawRoundRect(localRectF, f, f, this.mPaint);
      localRectF.left = convertNormalizedToScreenPoint(this.mNormalizedMinValue);
      localRectF.right = convertNormalizedToScreenPoint(this.mNormalizedMaxValue);
      this.mPaint.setColor(getContext().getResources().getColor(2131492870));
      paramCanvas.drawRoundRect(localRectF, f, f, this.mPaint);
      drawSeek(convertNormalizedToScreenPoint(this.mNormalizedMinValue), Thumb.MIN_THUMB.equals(this.mPressedSeek), paramCanvas);
      drawSeek(convertNormalizedToScreenPoint(this.mNormalizedMaxValue), Thumb.MAX_THUMB.equals(this.mPressedSeek), paramCanvas);
      return;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  protected void onMeasure(int paramInt1, int paramInt2)
  {
    int i = 200;
    try
    {
      if (View.MeasureSpec.getMode(paramInt1) != 0)
        i = View.MeasureSpec.getSize(paramInt1);
      int j = this.mThumbIconPressed.getHeight();
      if (View.MeasureSpec.getMode(paramInt2) != 0)
        j = Math.min(j, View.MeasureSpec.getSize(paramInt2));
      setMeasuredDimension(i, j);
      return;
    }
    finally
    {
    }
  }

  public boolean onTouchEvent(MotionEvent paramMotionEvent)
  {
    if (!isEnabled())
      return false;
    switch (0xFF & paramMotionEvent.getAction())
    {
    case 4:
    default:
    case 0:
    case 2:
    case 1:
    case 5:
    case 6:
    case 3:
    }
    while (true)
    {
      return true;
      this.mActivePointerId = paramMotionEvent.getPointerId(-1 + paramMotionEvent.getPointerCount());
      this.mDownMotionX = paramMotionEvent.getX(paramMotionEvent.findPointerIndex(this.mActivePointerId));
      this.mPressedSeek = detectPressedThumb(this.mDownMotionX);
      if (this.mPressedSeek == null)
        return super.onTouchEvent(paramMotionEvent);
      setPressed(true);
      invalidate();
      this.mIsDragging = true;
      setNormalizedValue(paramMotionEvent);
      getParent().requestDisallowInterceptTouchEvent(true);
      continue;
      if (this.mPressedSeek != null)
      {
        label168: OnPriceSeekBarChangeListener localOnPriceSeekBarChangeListener2;
        double d3;
        double d4;
        if (this.mIsDragging)
        {
          setNormalizedValue(paramMotionEvent);
          if ((this.mNotifyWhileDragging) && (this.mListener != null))
          {
            updateBar();
            localOnPriceSeekBarChangeListener2 = this.mListener;
            d3 = this.currentmin;
            d4 = this.currentmax;
            if (this.mPressedSeek != Thumb.MIN_THUMB);
          }
        }
        else
        {
          for (boolean bool2 = true; ; bool2 = false)
          {
            localOnPriceSeekBarChangeListener2.onPriceSeekBarValuesChanged(this, d3, d4, bool2, false);
            break;
            if (Math.abs(paramMotionEvent.getX(paramMotionEvent.findPointerIndex(this.mActivePointerId)) - this.mDownMotionX) <= this.mScaledTouchSlop)
              break label168;
            setPressed(true);
            invalidate();
            this.mIsDragging = true;
            setNormalizedValue(paramMotionEvent);
            getParent().requestDisallowInterceptTouchEvent(true);
            break label168;
          }
          label328: label338: OnPriceSeekBarChangeListener localOnPriceSeekBarChangeListener1;
          double d1;
          double d2;
          if (this.mIsDragging)
          {
            setNormalizedValue(paramMotionEvent);
            this.mIsDragging = false;
            setPressed(false);
            updateBar();
            if (this.mPressedSeek == Thumb.MIN_THUMB)
            {
              this.mPressedSeek = null;
              invalidate();
              if (this.mListener == null)
                continue;
              localOnPriceSeekBarChangeListener1 = this.mListener;
              d1 = this.currentmin;
              d2 = this.currentmax;
              if (this.mPressedSeek != Thumb.MIN_THUMB)
                break label426;
            }
          }
          else
          {
            label426: for (boolean bool1 = true; ; bool1 = false)
            {
              localOnPriceSeekBarChangeListener1.onPriceSeekBarValuesChanged(this, d1, d2, bool1, true);
              break;
              this.mIsDragging = true;
              setNormalizedValue(paramMotionEvent);
              this.mIsDragging = false;
              updateBar();
              break label328;
              break label338;
            }
            int i = -1 + paramMotionEvent.getPointerCount();
            this.mDownMotionX = paramMotionEvent.getX(i);
            this.mActivePointerId = paramMotionEvent.getPointerId(i);
            invalidate();
            continue;
            handleSecondaryPointerUp(paramMotionEvent);
            invalidate();
            continue;
            if (this.mIsDragging)
            {
              this.mIsDragging = false;
              setPressed(false);
            }
            invalidate();
          }
        }
      }
    }
  }

  public void setCurrentMaxValue(double paramDouble)
  {
    this.currentmax = paramDouble;
    if (0.0D == this.mInitialMaxValue - this.mInitialMinValue)
    {
      setNormalizedMaxValue(1.0D);
      return;
    }
    setNormalizedMaxValue((paramDouble - this.mInitialMinValue) / (this.mInitialMaxValue - this.mInitialMinValue));
  }

  public void setCurrentMinValue(double paramDouble)
  {
    this.currentmin = paramDouble;
    if (0.0D == this.mInitialMaxValue - this.mInitialMinValue)
    {
      setNormalizedMinValue(0.0D);
      return;
    }
    setNormalizedMinValue((paramDouble - this.mInitialMinValue) / (this.mInitialMaxValue - this.mInitialMinValue));
  }

  public void setNormalizedMaxValue(double paramDouble)
  {
    int i = getWidth();
    this.mNormalizedMaxValue = Math.max(0.0D, Math.min(1.0D, Math.max(paramDouble, (this.mSeekBarGap + 2.0F * this.mThumbHalfWidth) / (i - 2.0F * this.mThumbIcomPadding) + this.mNormalizedMinValue)));
    invalidate();
  }

  public void setNormalizedMinValue(double paramDouble)
  {
    int i = getWidth();
    double d = (this.mSeekBarGap + 2.0F * this.mThumbHalfWidth) / (i - 2.0F * this.mThumbIcomPadding);
    this.mNormalizedMinValue = Math.max(0.0D, Math.min(1.0D, Math.min(paramDouble, this.mNormalizedMaxValue - d)));
    invalidate();
  }

  public void setNotifyWhileDragging(boolean paramBoolean)
  {
    this.mNotifyWhileDragging = paramBoolean;
  }

  public void setOnRangeSeekBarChangeListener(OnPriceSeekBarChangeListener paramOnPriceSeekBarChangeListener)
  {
    this.mListener = paramOnPriceSeekBarChangeListener;
  }

  public static abstract interface OnPriceSeekBarChangeListener
  {
    public abstract void onPriceSeekBarValuesChanged(RangeSeekBar paramRangeSeekBar, double paramDouble1, double paramDouble2, boolean paramBoolean1, boolean paramBoolean2);
  }

  private static enum Thumb
  {
    static
    {
      MAX_THUMB = new Thumb("MAX_THUMB", 1);
      Thumb[] arrayOfThumb = new Thumb[2];
      arrayOfThumb[0] = MIN_THUMB;
      arrayOfThumb[1] = MAX_THUMB;
    }
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.ikea.kompis.util.RangeSeekBar
 * JD-Core Version:    0.6.2
 */