FocusStrategy.java 9.94 KB
package android.support.v4.widget;

import android.graphics.Rect;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

final class FocusStrategy
{
  private static int a(int paramInt1, int paramInt2)
  {
    return paramInt1 * 13 * paramInt1 + paramInt2 * paramInt2;
  }
  
  public static <L, T> T a(@NonNull L paramL, @NonNull CollectionAdapter<L, T> paramCollectionAdapter, @NonNull BoundsAdapter<T> paramBoundsAdapter, @Nullable T paramT, int paramInt, boolean paramBoolean)
  {
    Object localObject = null;
    int j = paramCollectionAdapter.size(paramL);
    ArrayList localArrayList = new ArrayList(j);
    int i = 0;
    while (i < j)
    {
      localArrayList.add(paramCollectionAdapter.get(paramL, i));
      i += 1;
    }
    Collections.sort(localArrayList, new a(paramBoolean, paramBoundsAdapter));
    switch (paramInt)
    {
    default: 
      throw new IllegalArgumentException("direction must be one of {FOCUS_FORWARD, FOCUS_BACKWARD}.");
    case 2: 
      i = localArrayList.size();
      if (paramT == null) {}
      for (paramInt = -1;; paramInt = localArrayList.lastIndexOf(paramT))
      {
        paramInt += 1;
        paramL = (L)localObject;
        if (paramInt < i) {
          paramL = localArrayList.get(paramInt);
        }
        return paramL;
      }
    }
    paramInt = localArrayList.size();
    if (paramT == null) {}
    for (;;)
    {
      paramInt -= 1;
      paramL = (L)localObject;
      if (paramInt < 0) {
        break;
      }
      return (T)localArrayList.get(paramInt);
      paramInt = localArrayList.indexOf(paramT);
    }
  }
  
  public static <L, T> T a(@NonNull L paramL, @NonNull CollectionAdapter<L, T> paramCollectionAdapter, @NonNull BoundsAdapter<T> paramBoundsAdapter, @Nullable T paramT, @NonNull Rect paramRect, int paramInt)
  {
    Rect localRect1 = new Rect(paramRect);
    Object localObject1;
    Rect localRect2;
    int j;
    label103:
    int i;
    switch (paramInt)
    {
    default: 
      throw new IllegalArgumentException("direction must be one of {FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT}.");
    case 17: 
      localRect1.offset(paramRect.width() + 1, 0);
      localObject1 = null;
      int k = paramCollectionAdapter.size(paramL);
      localRect2 = new Rect();
      j = 0;
      if (j < k)
      {
        Object localObject2 = paramCollectionAdapter.get(paramL, j);
        if (localObject2 == paramT) {
          break label333;
        }
        paramBoundsAdapter.obtainBounds(localObject2, localRect2);
        if (a(paramRect, localRect2, paramInt)) {
          if (!a(paramRect, localRect1, paramInt))
          {
            i = 1;
            label164:
            if (i == 0) {
              break label333;
            }
            localRect1.set(localRect2);
            localObject1 = localObject2;
          }
        }
      }
      break;
    }
    label333:
    for (;;)
    {
      j += 1;
      break label103;
      localRect1.offset(-(paramRect.width() + 1), 0);
      break;
      localRect1.offset(0, paramRect.height() + 1);
      break;
      localRect1.offset(0, -(paramRect.height() + 1));
      break;
      if (a(paramInt, paramRect, localRect2, localRect1))
      {
        i = 1;
        break label164;
      }
      if ((!a(paramInt, paramRect, localRect1, localRect2)) && (a(b(paramInt, paramRect, localRect2), c(paramInt, paramRect, localRect2)) < a(b(paramInt, paramRect, localRect1), c(paramInt, paramRect, localRect1))))
      {
        i = 1;
        break label164;
      }
      i = 0;
      break label164;
      return (T)localObject1;
    }
  }
  
  private static boolean a(int paramInt, @NonNull Rect paramRect1, @NonNull Rect paramRect2)
  {
    switch (paramInt)
    {
    default: 
      throw new IllegalArgumentException("direction must be one of {FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT}.");
    case 17: 
    case 66: 
      if ((paramRect2.bottom < paramRect1.top) || (paramRect2.top > paramRect1.bottom)) {
        break;
      }
    }
    do
    {
      return true;
      return false;
    } while ((paramRect2.right >= paramRect1.left) && (paramRect2.left <= paramRect1.right));
    return false;
  }
  
  private static boolean a(int paramInt, @NonNull Rect paramRect1, @NonNull Rect paramRect2, @NonNull Rect paramRect3)
  {
    boolean bool = a(paramInt, paramRect1, paramRect2);
    if ((a(paramInt, paramRect1, paramRect3)) || (!bool)) {
      return false;
    }
    switch (paramInt)
    {
    default: 
      throw new IllegalArgumentException("direction must be one of {FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT}.");
    case 17: 
      if (paramRect1.left >= paramRect3.right) {
        i = 1;
      }
      break;
    }
    while (i == 0)
    {
      return true;
      i = 0;
      continue;
      if (paramRect1.right <= paramRect3.left)
      {
        i = 1;
      }
      else
      {
        i = 0;
        continue;
        if (paramRect1.top >= paramRect3.bottom)
        {
          i = 1;
        }
        else
        {
          i = 0;
          continue;
          if (paramRect1.bottom <= paramRect3.top) {
            i = 1;
          } else {
            i = 0;
          }
        }
      }
    }
    if ((paramInt == 17) || (paramInt == 66)) {
      return true;
    }
    int i = b(paramInt, paramRect1, paramRect2);
    switch (paramInt)
    {
    default: 
      throw new IllegalArgumentException("direction must be one of {FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT}.");
    case 17: 
      paramInt = paramRect1.left - paramRect3.left;
    }
    while (i < Math.max(1, paramInt))
    {
      return true;
      paramInt = paramRect3.right - paramRect1.right;
      continue;
      paramInt = paramRect1.top - paramRect3.top;
      continue;
      paramInt = paramRect3.bottom - paramRect1.bottom;
    }
    return false;
  }
  
  private static boolean a(@NonNull Rect paramRect1, @NonNull Rect paramRect2, int paramInt)
  {
    switch (paramInt)
    {
    default: 
      throw new IllegalArgumentException("direction must be one of {FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT}.");
    case 17: 
      if (((paramRect1.right <= paramRect2.right) && (paramRect1.left < paramRect2.right)) || (paramRect1.left <= paramRect2.left)) {
        break;
      }
    }
    do
    {
      do
      {
        do
        {
          return true;
          return false;
        } while (((paramRect1.left < paramRect2.left) || (paramRect1.right <= paramRect2.left)) && (paramRect1.right < paramRect2.right));
        return false;
      } while (((paramRect1.bottom > paramRect2.bottom) || (paramRect1.top >= paramRect2.bottom)) && (paramRect1.top > paramRect2.top));
      return false;
    } while (((paramRect1.top < paramRect2.top) || (paramRect1.bottom <= paramRect2.top)) && (paramRect1.bottom < paramRect2.bottom));
    return false;
  }
  
  private static int b(int paramInt, @NonNull Rect paramRect1, @NonNull Rect paramRect2)
  {
    switch (paramInt)
    {
    default: 
      throw new IllegalArgumentException("direction must be one of {FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT}.");
    case 17: 
      paramInt = paramRect1.left - paramRect2.right;
    }
    for (;;)
    {
      return Math.max(0, paramInt);
      paramInt = paramRect2.left - paramRect1.right;
      continue;
      paramInt = paramRect1.top - paramRect2.bottom;
      continue;
      paramInt = paramRect2.top - paramRect1.bottom;
    }
  }
  
  private static int c(int paramInt, @NonNull Rect paramRect1, @NonNull Rect paramRect2)
  {
    switch (paramInt)
    {
    default: 
      throw new IllegalArgumentException("direction must be one of {FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT}.");
    case 17: 
    case 66: 
      return Math.abs(paramRect1.top + paramRect1.height() / 2 - (paramRect2.top + paramRect2.height() / 2));
    }
    return Math.abs(paramRect1.left + paramRect1.width() / 2 - (paramRect2.left + paramRect2.width() / 2));
  }
  
  public static abstract interface BoundsAdapter<T>
  {
    public abstract void obtainBounds(T paramT, Rect paramRect);
  }
  
  public static abstract interface CollectionAdapter<T, V>
  {
    public abstract V get(T paramT, int paramInt);
    
    public abstract int size(T paramT);
  }
  
  static final class a<T>
    implements Comparator<T>
  {
    private final Rect a = new Rect();
    private final Rect b = new Rect();
    private final boolean c;
    private final FocusStrategy.BoundsAdapter<T> d;
    
    a(boolean paramBoolean, FocusStrategy.BoundsAdapter<T> paramBoundsAdapter)
    {
      this.c = paramBoolean;
      this.d = paramBoundsAdapter;
    }
    
    public final int compare(T paramT1, T paramT2)
    {
      Rect localRect1 = this.a;
      Rect localRect2 = this.b;
      this.d.obtainBounds(paramT1, localRect1);
      this.d.obtainBounds(paramT2, localRect2);
      if (localRect1.top < localRect2.top) {}
      do
      {
        do
        {
          do
          {
            do
            {
              do
              {
                return -1;
                if (localRect1.top > localRect2.top) {
                  return 1;
                }
                if (localRect1.left >= localRect2.left) {
                  break;
                }
              } while (!this.c);
              return 1;
              if (localRect1.left <= localRect2.left) {
                break;
              }
            } while (this.c);
            return 1;
          } while (localRect1.bottom < localRect2.bottom);
          if (localRect1.bottom > localRect2.bottom) {
            return 1;
          }
          if (localRect1.right >= localRect2.right) {
            break;
          }
        } while (!this.c);
        return 1;
        if (localRect1.right <= localRect2.right) {
          break;
        }
      } while (this.c);
      return 1;
      return 0;
    }
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/android/support/v4/widget/FocusStrategy.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */