Post Reply

[Q] Instagram toggle slide button - Smali to Java Problems

2nd April 2014, 03:59 AM   |  #1  
OP Junior Member
Thanks Meter: 1
 
7 posts
Join Date:Joined: Dec 2013
I need a help to create a toggle slide button like the one in the instagram android app. With smaliToJava tool i got the code, but, some methods came very messy.

If we succeed, we may create a github project for everyone who want use this feature too //Sorry about the english :P

Smali2Java Code:

Code:
package com.instagram.ui.widget.switchbutton;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.ViewConfiguration;
import android.view.ViewParent;
import android.widget.CompoundButton;

public class IgSwitch
  extends CompoundButton
{
  private Drawable a;
  private Drawable b;
  private Drawable c;
  private Rect d = new Rect();
  private int e;
  private float f;
  private int g;
  private VelocityTracker h;
  private float i;
  private float j;
  private int k;
  private int l;
  private int m;
  private boolean n;
  
  public IgSwitch(Context paramContext)
  {
    super(paramContext);
    a();
  }
  
  public IgSwitch(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
    a();
  }
  
  public IgSwitch(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
  {
    super(paramContext, paramAttributeSet, paramInt);
    a();
  }
  
  private void a()
  {
    setClickable(true);
    ViewConfiguration localViewConfiguration = ViewConfiguration.get(getContext());
    this.l = localViewConfiguration.getScaledTouchSlop();
    this.m = localViewConfiguration.getScaledMinimumFlingVelocity();
    this.a = getResources().getDrawable(R.drawable.toggle);
    this.b = getResources().getDrawable(R.drawable.toggle_active);
    this.c = getResources().getDrawable(R.drawabletoggle_nub);
    this.e = this.c.getIntrinsicWidth();
    this.g = (this.a.getIntrinsicWidth() - this.e);
  }
  
  private void a(MotionEvent paramMotionEvent)
  {
    MotionEvent localMotionEvent = MotionEvent.obtain(paramMotionEvent);
    localMotionEvent.setAction(3);
    super.onTouchEvent(localMotionEvent);
    localMotionEvent.recycle();
  }
  
  private void a(boolean paramBoolean)
  {
    this.n = true;
    setChecked(paramBoolean);
  }
  
  private boolean a(float paramFloat1, float paramFloat2)
  {
    int i1 = getPaddingTop() - this.l;
    int i2 = (int)(getPaddingLeft() + (0.5F + this.f) - this.l);
    int i3 = i2 + this.e + 2 * this.l;
    int i4 = i1 + this.c.getIntrinsicHeight() + 2 * this.l;
    return (paramFloat1 > i2) && (paramFloat1 < i3) && (paramFloat2 > i1) && (paramFloat2 < i4);
  }
  
  private void b(MotionEvent paramMotionEvent)
  {
    int i1 = 1;
    this.k = 0;
    if ((paramMotionEvent.getAction() == i1) && (isEnabled()))
    {
      int i2 = i1;
      a(paramMotionEvent);
      if (i2 == 0) {
        break label97;
      }
      this.h.computeCurrentVelocity(1000);
      float f1 = this.h.getXVelocity();
      if (Math.abs(f1) <= this.m) {
        break label89;
      }
      if (f1 <= 0.0F) {
        break label84;
      }
    }
    for (;;)
    {
      a(i1);
      return;
      int i3 = 0;
      break;
      label84:
      boolean bool = false;
      continue;
      label89:
      bool = getTargetCheckedState();
    }
    label97:
    a(isChecked());
  }
  
  private boolean getTargetCheckedState()
  {
    return this.f >= this.g / 2;
  }
  
  protected void onDetachedFromWindow()
  {
    super.onDetachedFromWindow();
    if (this.h != null)
    {
      this.h.recycle();
      this.h = null;
    }
  }
  
  protected void onDraw(Canvas paramCanvas)
  {
    super.onDraw(paramCanvas);
    float f1 = this.f / this.g;
    this.b.setAlpha((int)(f1 * 255.0F));
    this.a.draw(paramCanvas);
    this.b.draw(paramCanvas);
    int i1 = (int)(0.5F + this.f);
    this.c.setBounds(i1 + getPaddingLeft(), getPaddingTop(), i1 + this.e + getPaddingLeft(), getPaddingTop() + this.c.getIntrinsicHeight());
    this.c.draw(paramCanvas);
  }
  
  protected void onLayout(boolean paramBoolean, int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    super.onLayout(paramBoolean, paramInt1, paramInt2, paramInt3, paramInt4);
    this.d.set(getPaddingLeft(), getPaddingTop(), this.a.getIntrinsicWidth() + getPaddingLeft(), this.a.getIntrinsicHeight() + getPaddingTop());
    this.a.setBounds(this.d);
    this.b.setBounds(this.d);
    if (isChecked()) {}
    for (float f1 = this.g;; f1 = 0.0F)
    {
      this.f = f1;
      return;
    }
  }
  
  protected void onMeasure(int paramInt1, int paramInt2)
  {
    setMeasuredDimension(this.b.getIntrinsicWidth() + getPaddingLeft() + getPaddingRight(), this.b.getIntrinsicHeight() + getPaddingTop() + getPaddingBottom());
  }
  
  public boolean onTouchEvent(MotionEvent paramMotionEvent)
  {
    int i1 = 1;
    if (this.h == null) {
      this.h = VelocityTracker.obtain();
    }
    this.h.addMovement(paramMotionEvent);
    switch (paramMotionEvent.getActionMasked())
    {
    }
    for (;;)
    {
      i1 = super.onTouchEvent(paramMotionEvent);
      float f1;
      float f2;
      do
      {
        return i1;
        float f5 = paramMotionEvent.getX();
        float f6 = paramMotionEvent.getY();
        if ((!isEnabled()) || (!a(f5, f6))) {
          break;
        }
        this.k = i1;
        this.i = f5;
        this.j = f6;
        break;
        switch (this.k)
        {
        case 0: 
        default: 
          break;
        case 1: 
          float f3 = paramMotionEvent.getX();
          float f4 = paramMotionEvent.getY();
          if ((Math.abs(f3 - this.i) <= this.l) && (Math.abs(f4 - this.j) <= this.l)) {
            break;
          }
          this.k = 2;
          getParent().requestDisallowInterceptTouchEvent(i1);
          this.i = f3;
          this.j = f4;
          return i1;
        case 2: 
          f1 = paramMotionEvent.getX();
          f2 = Math.max(0.0F, Math.min(f1 - this.i + this.f, this.g));
        }
      } while (f2 == this.f);
      this.f = f2;
      this.i = f1;
      invalidate();
      return i1;
      if (this.k == 2)
      {
        b(paramMotionEvent);
        return i1;
      }
      this.k = 0;
      this.h.clear();
      this.h.recycle();
      this.h = null;
    }
  }
  
  public boolean performClick()
  {
    this.n = true;
    return super.performClick();
  }
  
  public void setChecked(boolean paramBoolean)
  {
    super.setChecked(paramBoolean);
    int i1;
    if (paramBoolean)
    {
      i1 = this.g;
      if ((!this.n) || (getWindowToken() == null)) {
        break label62;
      }
      clearAnimation();
      startAnimation(new b(this, this.f, i1, null));
    }
    for (;;)
    {
      this.n = false;
      return;
      i1 = 0;
      break;
      label62:
      this.f = i1;
      invalidate();
    }
  }
}
2nd April 2014, 04:08 AM   |  #2  
OP Junior Member
Thanks Meter: 1
 
7 posts
Join Date:Joined: Dec 2013
Smali Code:

Code:
.class public Lcom/instagram/ui/widget/switchbutton/IgSwitch;
.super Landroid/widget/CompoundButton;
.source "IgSwitch.java"


# instance fields
.field private a:Landroid/graphics/drawable/Drawable;

.field private b:Landroid/graphics/drawable/Drawable;

.field private c:Landroid/graphics/drawable/Drawable;

.field private d:Landroid/graphics/Rect;

.field private e:I

.field private f:F

.field private g:I

.field private h:Landroid/view/VelocityTracker;

.field private i:F

.field private j:F

.field private k:I

.field private l:I

.field private m:I

.field private n:Z


# direct methods
.method public constructor <init>(Landroid/content/Context;)V
    .locals 1
    .parameter "context"

    .prologue
    .line 56
    invoke-direct {p0, p1}, Landroid/widget/CompoundButton;-><init>(Landroid/content/Context;)V

    .line 33
    new-instance v0, Landroid/graphics/Rect;

    invoke-direct {v0}, Landroid/graphics/Rect;-><init>()V

    iput-object v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->d:Landroid/graphics/Rect;

    .line 57
    invoke-direct {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->a()V

    .line 58
    return-void
.end method

.method public constructor <init>(Landroid/content/Context;Landroid/util/AttributeSet;)V
    .locals 1
    .parameter "context"
    .parameter "attrs"

    .prologue
    .line 61
    invoke-direct {p0, p1, p2}, Landroid/widget/CompoundButton;-><init>(Landroid/content/Context;Landroid/util/AttributeSet;)V

    .line 33
    new-instance v0, Landroid/graphics/Rect;

    invoke-direct {v0}, Landroid/graphics/Rect;-><init>()V

    iput-object v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->d:Landroid/graphics/Rect;

    .line 62
    invoke-direct {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->a()V

    .line 63
    return-void
.end method

.method public constructor <init>(Landroid/content/Context;Landroid/util/AttributeSet;I)V
    .locals 1
    .parameter "context"
    .parameter "attrs"
    .parameter "defStyle"

    .prologue
    .line 66
    invoke-direct {p0, p1, p2, p3}, Landroid/widget/CompoundButton;-><init>(Landroid/content/Context;Landroid/util/AttributeSet;I)V

    .line 33
    new-instance v0, Landroid/graphics/Rect;

    invoke-direct {v0}, Landroid/graphics/Rect;-><init>()V

    iput-object v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->d:Landroid/graphics/Rect;

    .line 67
    invoke-direct {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->a()V

    .line 68
    return-void
.end method

.method static synthetic a(Lcom/instagram/ui/widget/switchbutton/IgSwitch;F)F
    .locals 0
    .parameter
    .parameter

    .prologue
    .line 20
    iput p1, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->f:F

    return p1
.end method

.method static synthetic a(Lcom/instagram/ui/widget/switchbutton/IgSwitch;)I
    .locals 1
    .parameter

    .prologue
    .line 20
    iget v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->g:I

    return v0
.end method

.method private a()V
    .locals 2

    .prologue
    .line 71
    const/4 v0, 0x1

    invoke-virtual {p0, v0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->setClickable(Z)V

    .line 73
    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->getContext()Landroid/content/Context;

    move-result-object v0

    invoke-static {v0}, Landroid/view/ViewConfiguration;->get(Landroid/content/Context;)Landroid/view/ViewConfiguration;

    move-result-object v0

    .line 74
    invoke-virtual {v0}, Landroid/view/ViewConfiguration;->getScaledTouchSlop()I

    move-result v1

    iput v1, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->l:I

    .line 75
    invoke-virtual {v0}, Landroid/view/ViewConfiguration;->getScaledMinimumFlingVelocity()I

    move-result v0

    iput v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->m:I

    .line 77
    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->getResources()Landroid/content/res/Resources;

    move-result-object v0

    sget v1, Lcom/facebook/av;->toggle:I

    invoke-virtual {v0, v1}, Landroid/content/res/Resources;->getDrawable(I)Landroid/graphics/drawable/Drawable;

    move-result-object v0

    iput-object v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->a:Landroid/graphics/drawable/Drawable;

    .line 78
    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->getResources()Landroid/content/res/Resources;

    move-result-object v0

    sget v1, Lcom/facebook/av;->toggle_active:I

    invoke-virtual {v0, v1}, Landroid/content/res/Resources;->getDrawable(I)Landroid/graphics/drawable/Drawable;

    move-result-object v0

    iput-object v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->b:Landroid/graphics/drawable/Drawable;

    .line 80
    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->getResources()Landroid/content/res/Resources;

    move-result-object v0

    sget v1, Lcom/facebook/av;->toggle_nub:I

    invoke-virtual {v0, v1}, Landroid/content/res/Resources;->getDrawable(I)Landroid/graphics/drawable/Drawable;

    move-result-object v0

    iput-object v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->c:Landroid/graphics/drawable/Drawable;

    .line 81
    iget-object v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->c:Landroid/graphics/drawable/Drawable;

    invoke-virtual {v0}, Landroid/graphics/drawable/Drawable;->getIntrinsicWidth()I

    move-result v0

    iput v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->e:I

    .line 82
    iget-object v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->a:Landroid/graphics/drawable/Drawable;

    invoke-virtual {v0}, Landroid/graphics/drawable/Drawable;->getIntrinsicWidth()I

    move-result v0

    iget v1, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->e:I

    sub-int/2addr v0, v1

    iput v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->g:I

    .line 83
    return-void
.end method

.method private a(Landroid/view/MotionEvent;)V
    .locals 2
    .parameter

    .prologue
    .line 254
    invoke-static {p1}, Landroid/view/MotionEvent;->obtain(Landroid/view/MotionEvent;)Landroid/view/MotionEvent;

    move-result-object v0

    .line 255
    const/4 v1, 0x3

    invoke-virtual {v0, v1}, Landroid/view/MotionEvent;->setAction(I)V

    .line 256
    invoke-super {p0, v0}, Landroid/widget/CompoundButton;->onTouchEvent(Landroid/view/MotionEvent;)Z

    .line 257
    invoke-virtual {v0}, Landroid/view/MotionEvent;->recycle()V

    .line 258
    return-void
.end method

.method private a(Z)V
    .locals 1
    .parameter

    .prologue
    .line 288
    const/4 v0, 0x1

    iput-boolean v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->n:Z

    .line 289
    invoke-virtual {p0, p1}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->setChecked(Z)V

    .line 290
    return-void
.end method

.method private a(FF)Z
    .locals 5
    .parameter
    .parameter

    .prologue
    .line 173
    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->getPaddingTop()I

    move-result v0

    iget v1, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->l:I

    sub-int/2addr v0, v1

    .line 174
    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->getPaddingLeft()I

    move-result v1

    int-to-float v1, v1

    iget v2, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->f:F

    const/high16 v3, 0x3f00

    add-float/2addr v2, v3

    add-float/2addr v1, v2

    iget v2, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->l:I

    int-to-float v2, v2

    sub-float/2addr v1, v2

    float-to-int v1, v1

    .line 175
    iget v2, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->e:I

    add-int/2addr v2, v1

    iget v3, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->l:I

    mul-int/lit8 v3, v3, 0x2

    add-int/2addr v2, v3

    .line 176
    iget-object v3, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->c:Landroid/graphics/drawable/Drawable;

    invoke-virtual {v3}, Landroid/graphics/drawable/Drawable;->getIntrinsicHeight()I

    move-result v3

    add-int/2addr v3, v0

    iget v4, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->l:I

    mul-int/lit8 v4, v4, 0x2

    add-int/2addr v3, v4

    .line 177
    int-to-float v1, v1

    cmpl-float v1, p1, v1

    if-lez v1, :cond_0

    int-to-float v1, v2

    cmpg-float v1, p1, v1

    if-gez v1, :cond_0

    int-to-float v0, v0

    cmpl-float v0, p2, v0

    if-lez v0, :cond_0

    int-to-float v0, v3

    cmpg-float v0, p2, v0

    if-gez v0, :cond_0

    const/4 v0, 0x1

    :goto_0
    return v0

    :cond_0
    const/4 v0, 0x0

    goto :goto_0
.end method

.method private b(Landroid/view/MotionEvent;)V
    .locals 5
    .parameter

    .prologue
    const/4 v1, 0x1

    const/4 v2, 0x0

    .line 266
    iput v2, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->k:I

    .line 268
    invoke-virtual {p1}, Landroid/view/MotionEvent;->getAction()I

    move-result v0

    if-ne v0, v1, :cond_0

    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->isEnabled()Z

    move-result v0

    if-eqz v0, :cond_0

    move v0, v1

    .line 270
    :goto_0
    invoke-direct {p0, p1}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->a(Landroid/view/MotionEvent;)V

    .line 272
    if-eqz v0, :cond_3

    .line 274
    iget-object v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->h:Landroid/view/VelocityTracker;

    const/16 v3, 0x3e8

    invoke-virtual {v0, v3}, Landroid/view/VelocityTracker;->computeCurrentVelocity(I)V

    .line 275
    iget-object v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->h:Landroid/view/VelocityTracker;

    invoke-virtual {v0}, Landroid/view/VelocityTracker;->getXVelocity()F

    move-result v0

    .line 276
    invoke-static {v0}, Ljava/lang/Math;->abs(F)F

    move-result v3

    iget v4, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->m:I

    int-to-float v4, v4

    cmpl-float v3, v3, v4

    if-lez v3, :cond_2

    .line 277
    const/4 v3, 0x0

    cmpl-float v0, v0, v3

    if-lez v0, :cond_1

    .line 281
    :goto_1
    invoke-direct {p0, v1}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->a(Z)V

    .line 285
    :goto_2
    return-void

    :cond_0
    move v0, v2

    .line 268
    goto :goto_0

    :cond_1
    move v1, v2

    .line 277
    goto :goto_1

    .line 279
    :cond_2
    invoke-direct {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->getTargetCheckedState()Z

    move-result v1

    goto :goto_1

    .line 283
    :cond_3
    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->isChecked()Z

    move-result v0

    invoke-direct {p0, v0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->a(Z)V

    goto :goto_2
.end method

.method private getTargetCheckedState()Z
    .locals 2

    .prologue
    .line 293
    iget v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->f:F

    iget v1, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->g:I

    div-int/lit8 v1, v1, 0x2

    int-to-float v1, v1

    cmpl-float v0, v0, v1

    if-ltz v0, :cond_0

    const/4 v0, 0x1

    :goto_0
    return v0

    :cond_0
    const/4 v0, 0x0

    goto :goto_0
.end method


# virtual methods
.method protected onDetachedFromWindow()V
    .locals 1

    .prologue
    .line 161
    invoke-super {p0}, Landroid/widget/CompoundButton;->onDetachedFromWindow()V

    .line 163
    iget-object v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->h:Landroid/view/VelocityTracker;

    if-eqz v0, :cond_0

    .line 164
    iget-object v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->h:Landroid/view/VelocityTracker;

    invoke-virtual {v0}, Landroid/view/VelocityTracker;->recycle()V

    .line 165
    const/4 v0, 0x0

    iput-object v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->h:Landroid/view/VelocityTracker;

    .line 167
    :cond_0
    return-void
.end method

.method protected onDraw(Landroid/graphics/Canvas;)V
    .locals 6
    .parameter "canvas"

    .prologue
    .line 110
    invoke-super {p0, p1}, Landroid/widget/CompoundButton;->onDraw(Landroid/graphics/Canvas;)V

    .line 115
    iget v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->f:F

    iget v1, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->g:I

    int-to-float v1, v1

    div-float/2addr v0, v1

    .line 116
    iget-object v1, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->b:Landroid/graphics/drawable/Drawable;

    const/high16 v2, 0x437f

    mul-float/2addr v0, v2

    float-to-int v0, v0

    invoke-virtual {v1, v0}, Landroid/graphics/drawable/Drawable;->setAlpha(I)V

    .line 118
    iget-object v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->a:Landroid/graphics/drawable/Drawable;

    invoke-virtual {v0, p1}, Landroid/graphics/drawable/Drawable;->draw(Landroid/graphics/Canvas;)V

    .line 119
    iget-object v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->b:Landroid/graphics/drawable/Drawable;

    invoke-virtual {v0, p1}, Landroid/graphics/drawable/Drawable;->draw(Landroid/graphics/Canvas;)V

    .line 124
    iget v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->f:F

    const/high16 v1, 0x3f00

    add-float/2addr v0, v1

    float-to-int v0, v0

    .line 125
    iget-object v1, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->c:Landroid/graphics/drawable/Drawable;

    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->getPaddingLeft()I

    move-result v2

    add-int/2addr v2, v0

    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->getPaddingTop()I

    move-result v3

    iget v4, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->e:I

    add-int/2addr v0, v4

    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->getPaddingLeft()I

    move-result v4

    add-int/2addr v0, v4

    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->getPaddingTop()I

    move-result v4

    iget-object v5, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->c:Landroid/graphics/drawable/Drawable;

    invoke-virtual {v5}, Landroid/graphics/drawable/Drawable;->getIntrinsicHeight()I

    move-result v5

    add-int/2addr v4, v5

    invoke-virtual {v1, v2, v3, v0, v4}, Landroid/graphics/drawable/Drawable;->setBounds(IIII)V

    .line 131
    iget-object v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->c:Landroid/graphics/drawable/Drawable;

    invoke-virtual {v0, p1}, Landroid/graphics/drawable/Drawable;->draw(Landroid/graphics/Canvas;)V

    .line 132
    return-void
.end method

.method protected onLayout(ZIIII)V
    .locals 6
    .parameter "changed"
    .parameter "left"
    .parameter "top"
    .parameter "right"
    .parameter "bottom"

    .prologue
    .line 144
    invoke-super/range {p0 .. p5}, Landroid/widget/CompoundButton;->onLayout(ZIIII)V

    .line 146
    iget-object v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->d:Landroid/graphics/Rect;

    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->getPaddingLeft()I

    move-result v1

    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->getPaddingTop()I

    move-result v2

    iget-object v3, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->a:Landroid/graphics/drawable/Drawable;

    invoke-virtual {v3}, Landroid/graphics/drawable/Drawable;->getIntrinsicWidth()I

    move-result v3

    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->getPaddingLeft()I

    move-result v4

    add-int/2addr v3, v4

    iget-object v4, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->a:Landroid/graphics/drawable/Drawable;

    invoke-virtual {v4}, Landroid/graphics/drawable/Drawable;->getIntrinsicHeight()I

    move-result v4

    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->getPaddingTop()I

    move-result v5

    add-int/2addr v4, v5

    invoke-virtual {v0, v1, v2, v3, v4}, Landroid/graphics/Rect;->set(IIII)V

    .line 153
    iget-object v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->a:Landroid/graphics/drawable/Drawable;

    iget-object v1, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->d:Landroid/graphics/Rect;

    invoke-virtual {v0, v1}, Landroid/graphics/drawable/Drawable;->setBounds(Landroid/graphics/Rect;)V

    .line 154
    iget-object v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->b:Landroid/graphics/drawable/Drawable;

    iget-object v1, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->d:Landroid/graphics/Rect;

    invoke-virtual {v0, v1}, Landroid/graphics/drawable/Drawable;->setBounds(Landroid/graphics/Rect;)V

    .line 156
    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->isChecked()Z

    move-result v0

    if-eqz v0, :cond_0

    iget v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->g:I

    int-to-float v0, v0

    :goto_0
    iput v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->f:F

    .line 157
    return-void

    .line 156
    :cond_0
    const/4 v0, 0x0

    goto :goto_0
.end method

.method protected onMeasure(II)V
    .locals 3
    .parameter "widthMeasureSpec"
    .parameter "heightMeasureSpec"

    .prologue
    .line 136
    iget-object v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->b:Landroid/graphics/drawable/Drawable;

    invoke-virtual {v0}, Landroid/graphics/drawable/Drawable;->getIntrinsicWidth()I

    move-result v0

    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->getPaddingLeft()I

    move-result v1

    add-int/2addr v0, v1

    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->getPaddingRight()I

    move-result v1

    add-int/2addr v0, v1

    iget-object v1, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->b:Landroid/graphics/drawable/Drawable;

    invoke-virtual {v1}, Landroid/graphics/drawable/Drawable;->getIntrinsicHeight()I

    move-result v1

    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->getPaddingTop()I

    move-result v2

    add-int/2addr v1, v2

    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->getPaddingBottom()I

    move-result v2

    add-int/2addr v1, v2

    invoke-virtual {p0, v0, v1}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->setMeasuredDimension(II)V

    .line 140
    return-void
.end method

.method public onTouchEvent(Landroid/view/MotionEvent;)Z
    .locals 6
    .parameter "ev"

    .prologue
    const/4 v5, 0x2

    const/4 v0, 0x1

    .line 182
    iget-object v1, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->h:Landroid/view/VelocityTracker;

    if-nez v1, :cond_0

    .line 183
    invoke-static {}, Landroid/view/VelocityTracker;->obtain()Landroid/view/VelocityTracker;

    move-result-object v1

    iput-object v1, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->h:Landroid/view/VelocityTracker;

    .line 186
    :cond_0
    iget-object v1, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->h:Landroid/view/VelocityTracker;

    invoke-virtual {v1, p1}, Landroid/view/VelocityTracker;->addMovement(Landroid/view/MotionEvent;)V

    .line 187
    invoke-virtual {p1}, Landroid/view/MotionEvent;->getActionMasked()I

    move-result v1

    .line 188
    packed-switch v1, :pswitch_data_0

    .line 250
    :cond_1
    :goto_0
    :pswitch_0
    invoke-super {p0, p1}, Landroid/widget/CompoundButton;->onTouchEvent(Landroid/view/MotionEvent;)Z

    move-result v0

    :cond_2
    :goto_1
    return v0

    .line 190
    :pswitch_1
    invoke-virtual {p1}, Landroid/view/MotionEvent;->getX()F

    move-result v1

    .line 191
    invoke-virtual {p1}, Landroid/view/MotionEvent;->getY()F

    move-result v2

    .line 192
    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->isEnabled()Z

    move-result v3

    if-eqz v3, :cond_1

    invoke-direct {p0, v1, v2}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->a(FF)Z

    move-result v3

    if-eqz v3, :cond_1

    .line 193
    iput v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->k:I

    .line 194
    iput v1, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->i:F

    .line 195
    iput v2, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->j:F

    goto :goto_0

    .line 201
    :pswitch_2
    iget v1, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->k:I

    packed-switch v1, :pswitch_data_1

    goto :goto_0

    .line 207
    :pswitch_3
    invoke-virtual {p1}, Landroid/view/MotionEvent;->getX()F

    move-result v1

    .line 208
    invoke-virtual {p1}, Landroid/view/MotionEvent;->getY()F

    move-result v2

    .line 209
    iget v3, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->i:F

    sub-float v3, v1, v3

    invoke-static {v3}, Ljava/lang/Math;->abs(F)F

    move-result v3

    iget v4, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->l:I

    int-to-float v4, v4

    cmpl-float v3, v3, v4

    if-gtz v3, :cond_3

    iget v3, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->j:F

    sub-float v3, v2, v3

    invoke-static {v3}, Ljava/lang/Math;->abs(F)F

    move-result v3

    iget v4, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->l:I

    int-to-float v4, v4

    cmpl-float v3, v3, v4

    if-lez v3, :cond_1

    .line 211
    :cond_3
    iput v5, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->k:I

    .line 213
    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->getParent()Landroid/view/ViewParent;

    move-result-object v3

    invoke-interface {v3, v0}, Landroid/view/ViewParent;->requestDisallowInterceptTouchEvent(Z)V

    .line 214
    iput v1, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->i:F

    .line 215
    iput v2, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->j:F

    goto :goto_1

    .line 222
    :pswitch_4
    invoke-virtual {p1}, Landroid/view/MotionEvent;->getX()F

    move-result v1

    .line 223
    iget v2, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->i:F

    sub-float v2, v1, v2

    .line 224
    const/4 v3, 0x0

    iget v4, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->f:F

    add-float/2addr v2, v4

    iget v4, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->g:I

    int-to-float v4, v4

    invoke-static {v2, v4}, Ljava/lang/Math;->min(FF)F

    move-result v2

    invoke-static {v3, v2}, Ljava/lang/Math;->max(FF)F

    move-result v2

    .line 225
    iget v3, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->f:F

    cmpl-float v3, v2, v3

    if-eqz v3, :cond_2

    .line 226
    iput v2, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->f:F

    .line 227
    iput v1, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->i:F

    .line 228
    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->invalidate()V

    goto :goto_1

    .line 238
    :pswitch_5
    iget v1, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->k:I

    if-ne v1, v5, :cond_4

    .line 239
    invoke-direct {p0, p1}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->b(Landroid/view/MotionEvent;)V

    goto/16 :goto_1

    .line 242
    :cond_4
    const/4 v0, 0x0

    iput v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->k:I

    .line 243
    iget-object v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->h:Landroid/view/VelocityTracker;

    invoke-virtual {v0}, Landroid/view/VelocityTracker;->clear()V

    .line 244
    iget-object v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->h:Landroid/view/VelocityTracker;

    invoke-virtual {v0}, Landroid/view/VelocityTracker;->recycle()V

    .line 245
    const/4 v0, 0x0

    iput-object v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->h:Landroid/view/VelocityTracker;

    goto/16 :goto_0

    .line 188
    :pswitch_data_0
    .packed-switch 0x0
        :pswitch_1
        :pswitch_5
        :pswitch_2
        :pswitch_5
    .end packed-switch

    .line 201
    :pswitch_data_1
    .packed-switch 0x0
        :pswitch_0
        :pswitch_3
        :pswitch_4
    .end packed-switch
.end method

.method public performClick()Z
    .locals 1

    .prologue
    .line 87
    const/4 v0, 0x1

    iput-boolean v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->n:Z

    .line 88
    invoke-super {p0}, Landroid/widget/CompoundButton;->performClick()Z

    move-result v0

    return v0
.end method

.method public setChecked(Z)V
    .locals 5
    .parameter "checked"

    .prologue
    const/4 v1, 0x0

    .line 93
    invoke-super {p0, p1}, Landroid/widget/CompoundButton;->setChecked(Z)V

    .line 95
    if-eqz p1, :cond_0

    iget v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->g:I

    .line 97
    :goto_0
    iget-boolean v2, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->n:Z

    if-eqz v2, :cond_1

    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->getWindowToken()Landroid/os/IBinder;

    move-result-object v2

    if-eqz v2, :cond_1

    .line 98
    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->clearAnimation()V

    .line 99
    new-instance v2, Lcom/instagram/ui/widget/switchbutton/b;

    iget v3, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->f:F

    int-to-float v0, v0

    const/4 v4, 0x0

    invoke-direct {v2, p0, v3, v0, v4}, Lcom/instagram/ui/widget/switchbutton/b;-><init>(Lcom/instagram/ui/widget/switchbutton/IgSwitch;FFLcom/instagram/ui/widget/switchbutton/a;)V

    invoke-virtual {p0, v2}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->startAnimation(Landroid/view/animation/Animation;)V

    .line 105
    :goto_1
    iput-boolean v1, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->n:Z

    .line 106
    return-void

    :cond_0
    move v0, v1

    .line 95
    goto :goto_0

    .line 101
    :cond_1
    int-to-float v0, v0

    iput v0, p0, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->f:F

    .line 102
    invoke-virtual {p0}, Lcom/instagram/ui/widget/switchbutton/IgSwitch;->invalidate()V

    goto :goto_1
.end method
The button:

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in Android Q&A, Help & Troubleshooting by ThreadRank