AvatarStyleFragment.java 11.4 KB
package com.bitstrips.imoji.abv3.style;

import android.animation.ArgbEvaluator;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.res.Resources;
import android.graphics.PorterDuff.Mode;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import com.bitstrips.imoji.InjectorApplication;
import com.bitstrips.imoji.abv3.AvatarBuilderStyle;
import com.bitstrips.imoji.abv3.model.AvatarChangeStyle;
import com.bitstrips.imoji.abv3.model.AvatarSaveResponseV3;
import com.bitstrips.imoji.abv3.model.AvatarStyleConfig;
import com.bitstrips.imoji.abv3.model.AvatarStylePreviouslySaved;
import com.bitstrips.imoji.api.BitmojiApi;
import com.bitstrips.imoji.behaviour.BehaviourHelper;
import com.bitstrips.imoji.persistence.MediaCache;
import com.bitstrips.imoji.ui.BmTypefaceLoader;
import com.bitstrips.imoji.ui.BmTypefaceLoader.OnTypefaceLoadedCallback;
import com.bitstrips.imoji.ui.views.BmButton;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import javax.inject.Inject;
import retrofit.Callback;
import retrofit.RetrofitError;

public class AvatarStyleFragment
  extends Fragment
  implements AvatarStyleListener
{
  private static final String e = AvatarStyleFragment.class.getSimpleName();
  List<AvatarStyleConfig> a;
  @Inject
  BitmojiApi b;
  @Inject
  MediaCache c;
  @Inject
  BehaviourHelper d;
  private ViewPager f;
  private AvatarStyleAdapter g;
  private List<ImageView> h;
  private TextView i;
  private ImageView j;
  private BmButton k;
  private int l;
  private AvatarStylePreviouslySaved m;
  
  public static AvatarStyleFragment createFragment(int paramInt, AvatarStylePreviouslySaved paramAvatarStylePreviouslySaved)
  {
    Bundle localBundle = new Bundle();
    localBundle.putInt("ARGUMENT_AVATAR_CURRENT_STYLE", paramInt);
    localBundle.putSerializable("ARGUMENT_AVATAR_STYLE_INFO", paramAvatarStylePreviouslySaved);
    paramAvatarStylePreviouslySaved = new AvatarStyleFragment();
    paramAvatarStylePreviouslySaved.setArguments(localBundle);
    return paramAvatarStylePreviouslySaved;
  }
  
  public AvatarStyleFragmentListener getListener()
  {
    return (AvatarStyleFragmentListener)getActivity();
  }
  
  public List<AvatarStyleConfig> getStyleConfigList()
  {
    Object localObject2 = getResources();
    String str2 = ((Resources)localObject2).getString(2131231330);
    Object localObject1 = ((Resources)localObject2).getString(2131231329);
    String str1 = ((Resources)localObject2).getString(2131231331);
    int n = ((Resources)localObject2).getColor(2131624127);
    int i1 = ((Resources)localObject2).getColor(2131624126);
    int i2 = ((Resources)localObject2).getColor(2131624128);
    localObject2 = new AvatarStyleConfig(1, str2, n);
    localObject1 = new AvatarStyleConfig(4, (String)localObject1, i1);
    return new ArrayList(Arrays.asList(new AvatarStyleConfig[] { new AvatarStyleConfig(5, str1, i2), localObject2, localObject1 }));
  }
  
  public void onAttach(Context paramContext)
  {
    super.onAttach(paramContext);
  }
  
  public void onCreate(@Nullable Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    ((InjectorApplication)getActivity().getApplication()).inject(this);
    this.a = getStyleConfigList();
  }
  
  @Nullable
  public View onCreateView(LayoutInflater paramLayoutInflater, @Nullable ViewGroup paramViewGroup, @Nullable Bundle paramBundle)
  {
    paramBundle = new ViewPager.OnPageChangeListener()
    {
      public final void onPageScrollStateChanged(int paramAnonymousInt) {}
      
      public final void onPageScrolled(int paramAnonymousInt1, float paramAnonymousFloat, int paramAnonymousInt2)
      {
        if (paramAnonymousInt1 < AvatarStyleFragment.a(AvatarStyleFragment.this).getCount() - 1) {}
        for (paramAnonymousInt2 = paramAnonymousInt1 + 1;; paramAnonymousInt2 = paramAnonymousInt1)
        {
          paramAnonymousInt2 = ((Integer)this.a.evaluate(paramAnonymousFloat, Integer.valueOf(((AvatarStyleConfig)AvatarStyleFragment.this.a.get(paramAnonymousInt1)).getBackgroundColor()), Integer.valueOf(((AvatarStyleConfig)AvatarStyleFragment.this.a.get(paramAnonymousInt2)).getBackgroundColor()))).intValue();
          AvatarStyleFragment.b(AvatarStyleFragment.this).setColorFilter(paramAnonymousInt2, PorterDuff.Mode.DST_ATOP);
          AvatarStyleFragment.c(AvatarStyleFragment.this).setTextColor(paramAnonymousInt2);
          paramAnonymousInt2 = Math.round(paramAnonymousInt1 + paramAnonymousFloat);
          paramAnonymousFloat = Math.abs(paramAnonymousInt1 + paramAnonymousFloat - paramAnonymousInt2);
          AvatarStyleFragment.d(AvatarStyleFragment.this).setText(((AvatarStyleConfig)AvatarStyleFragment.this.a.get(paramAnonymousInt2)).getTitle());
          AvatarStyleFragment.d(AvatarStyleFragment.this).setAlpha(1.0F - AvatarStyleFragment.a(paramAnonymousFloat, 1.0F));
          Iterator localIterator = AvatarStyleFragment.e(AvatarStyleFragment.this).iterator();
          while (localIterator.hasNext())
          {
            ImageView localImageView = (ImageView)localIterator.next();
            localImageView.getBackground().clearColorFilter();
            localImageView.getBackground().setColorFilter(-1, PorterDuff.Mode.DST_ATOP);
            localImageView.setAlpha(0.4F);
          }
        }
        ((ImageView)AvatarStyleFragment.e(AvatarStyleFragment.this).get(paramAnonymousInt2)).getBackground().setColorFilter(-1, PorterDuff.Mode.DST_ATOP);
        paramAnonymousFloat = AvatarStyleFragment.a(paramAnonymousFloat, 0.6F);
        ((ImageView)AvatarStyleFragment.e(AvatarStyleFragment.this).get(paramAnonymousInt2)).setAlpha(1.0F - paramAnonymousFloat);
      }
      
      public final void onPageSelected(int paramAnonymousInt)
      {
        AvatarStyleFragment.a(AvatarStyleFragment.this, paramAnonymousInt);
      }
    };
    int i1 = getArguments().getInt("ARGUMENT_AVATAR_CURRENT_STYLE");
    this.m = ((AvatarStylePreviouslySaved)getArguments().getSerializable("ARGUMENT_AVATAR_STYLE_INFO"));
    int n = 0;
    if (n < this.a.size()) {
      if (((AvatarStyleConfig)this.a.get(n)).getStyleNum() != i1) {}
    }
    for (;;)
    {
      paramLayoutInflater = paramLayoutInflater.inflate(2130903110, paramViewGroup, false);
      this.j = ((ImageView)paramLayoutInflater.findViewById(2131689723));
      paramViewGroup = paramLayoutInflater.findViewById(2131689729);
      paramViewGroup.setOnClickListener(new View.OnClickListener()
      {
        public final void onClick(View paramAnonymousView)
        {
          AvatarStyleFragment.this.onSaveSelected();
        }
      });
      paramLayoutInflater.findViewById(2131689699).setOnClickListener(new View.OnClickListener()
      {
        public final void onClick(View paramAnonymousView)
        {
          paramAnonymousView = AvatarStyleFragment.this.getListener();
          if (paramAnonymousView == null) {
            return;
          }
          paramAnonymousView.onStyleExit();
        }
      });
      this.k = ((BmButton)paramViewGroup);
      BmTypefaceLoader.getInstance().loadTypefaceStyle(getContext(), 1, new BmTypefaceLoader.OnTypefaceLoadedCallback()
      {
        public final void onTypefaceLoaded(Typeface paramAnonymousTypeface)
        {
          AvatarStyleFragment.c(AvatarStyleFragment.this).setTypeface(paramAnonymousTypeface);
        }
      });
      this.i = ((TextView)paramLayoutInflater.findViewById(2131689727));
      paramViewGroup = getResources().getDrawable(2130837618);
      this.j.setImageDrawable(paramViewGroup);
      this.f = ((ViewPager)paramLayoutInflater.findViewById(2131689726));
      paramViewGroup = new ArrayList();
      Object localObject = this.a.iterator();
      for (;;)
      {
        if (((Iterator)localObject).hasNext())
        {
          paramViewGroup.add(Integer.valueOf(((AvatarStyleConfig)((Iterator)localObject).next()).getStyleNum()));
          continue;
          n += 1;
          break;
        }
      }
      this.g = new AvatarStyleAdapter(paramViewGroup, this.c, this.m);
      this.f.setAdapter(this.g);
      this.f.addOnPageChangeListener(paramBundle);
      paramViewGroup = (LinearLayout)paramLayoutInflater.findViewById(2131689728);
      this.h = new ArrayList();
      paramBundle = getResources();
      int i2 = paramBundle.getDimensionPixelSize(2131362143);
      int i3 = paramBundle.getDimensionPixelSize(2131362142);
      i1 = 0;
      while (i1 < this.a.size())
      {
        paramBundle = new ImageView(getContext());
        paramBundle.setBackground(getResources().getDrawable(2130837932));
        localObject = new LinearLayout.LayoutParams(i2, i2);
        ((LinearLayout.LayoutParams)localObject).setMargins(i3, 0, i3, 0);
        paramBundle.setLayoutParams((ViewGroup.LayoutParams)localObject);
        paramViewGroup.addView(paramBundle);
        this.h.add(paramBundle);
        i1 += 1;
      }
      this.f.setCurrentItem(n);
      this.l = n;
      setPercentMeasurements();
      return paramLayoutInflater;
      n = 0;
    }
  }
  
  public void onSaveSelected()
  {
    onStyleSelected(((AvatarStyleConfig)this.a.get(this.l)).getStyleNum());
  }
  
  public void onStyleSelected(final int paramInt)
  {
    boolean bool = false;
    Object localObject1 = AvatarBuilderStyle.fromValue(paramInt);
    if (getArguments().getInt("ARGUMENT_AVATAR_CURRENT_STYLE") == paramInt)
    {
      localObject2 = getListener();
      if (localObject2 != null) {}
    }
    do
    {
      return;
      ((AvatarStyleFragmentListener)localObject2).onStyleSelected(false, (AvatarBuilderStyle)localObject1);
      return;
      if (!this.m.isStylePreviouslySaved(paramInt)) {
        bool = true;
      }
      localObject1 = new Callback()
      {
        public final void failure(RetrofitError paramAnonymousRetrofitError)
        {
          Log.e(AvatarStyleFragment.a(), "Failed to change user style");
          AvatarStyleFragment.b(AvatarStyleFragment.this, paramInt);
        }
      };
    } while ((paramInt == AvatarBuilderStyle.STYLE_CM.getValue()) && (!this.d.isCMSaveEnabled()));
    Object localObject2 = new AvatarChangeStyle(paramInt);
    this.b.changeAvatarStyleV3((AvatarChangeStyle)localObject2, (Callback)localObject1);
  }
  
  public void setPercentMeasurements()
  {
    DisplayMetrics localDisplayMetrics = getContext().getResources().getDisplayMetrics();
    int n = (int)(localDisplayMetrics.widthPixels * 0.85D);
    this.f.getLayoutParams().height = n;
    n = (localDisplayMetrics.widthPixels - n) / 2;
    int i1 = (int)(n * 0.9D);
    this.f.setPadding(i1, 0, i1, 0);
    this.f.setPageMargin(n / 2);
    this.f.setClipToPadding(false);
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/bitstrips/imoji/abv3/style/AvatarStyleFragment.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */