AttachmentView.java 8.35 KB
package net.hockeyapp.android.views;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build.VERSION;
import android.text.TextUtils.TruncateAt;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.io.File;
import net.hockeyapp.android.Constants;
import net.hockeyapp.android.R.color;
import net.hockeyapp.android.R.string;
import net.hockeyapp.android.objects.FeedbackAttachment;
import net.hockeyapp.android.utils.ImageUtils;

@SuppressLint({"ViewConstructor"})
public class AttachmentView
  extends FrameLayout
{
  private final Context a;
  private final ViewGroup b;
  private final FeedbackAttachment c;
  private final Uri d;
  private final String e;
  private ImageView f;
  private TextView g;
  private int h;
  private int i;
  private int j;
  private int k;
  private int l;
  private int m;
  
  public AttachmentView(Context paramContext, ViewGroup paramViewGroup, Uri paramUri, boolean paramBoolean)
  {
    super(paramContext);
    this.a = paramContext;
    this.b = paramViewGroup;
    this.c = null;
    this.d = paramUri;
    this.e = paramUri.getLastPathSegment();
    a(20);
    a(paramContext, paramBoolean);
    this.g.setText(this.e);
    new AsyncTask() {}.execute(new Void[0]);
  }
  
  public AttachmentView(Context paramContext, ViewGroup paramViewGroup, FeedbackAttachment paramFeedbackAttachment, boolean paramBoolean)
  {
    super(paramContext);
    this.a = paramContext;
    this.b = paramViewGroup;
    this.c = paramFeedbackAttachment;
    this.d = Uri.fromFile(new File(Constants.getHockeyAppStorageDir(), paramFeedbackAttachment.getCacheId()));
    this.e = paramFeedbackAttachment.getFilename();
    a(30);
    a(paramContext, paramBoolean);
    this.m = 0;
    this.g.setText(R.string.hockeyapp_feedback_attachment_loading);
    a(false);
  }
  
  private Bitmap a()
  {
    try
    {
      this.m = ImageUtils.determineOrientation(this.a, this.d);
      int n;
      if (this.m == 1)
      {
        n = this.j;
        if (this.m != 1) {
          break label63;
        }
      }
      label63:
      for (int i1 = this.k;; i1 = this.i)
      {
        return ImageUtils.decodeSampledBitmap(this.a, this.d, n, i1);
        n = this.h;
        break;
      }
      return null;
    }
    catch (Throwable localThrowable) {}
  }
  
  private Drawable a(String paramString)
  {
    if (Build.VERSION.SDK_INT >= 21) {
      return getResources().getDrawable(getResources().getIdentifier(paramString, "drawable", "android"), this.a.getTheme());
    }
    return getResources().getDrawable(getResources().getIdentifier(paramString, "drawable", "android"));
  }
  
  private void a(int paramInt)
  {
    DisplayMetrics localDisplayMetrics = getResources().getDisplayMetrics();
    this.l = Math.round(TypedValue.applyDimension(1, 10.0F, localDisplayMetrics));
    paramInt = Math.round(TypedValue.applyDimension(1, paramInt, localDisplayMetrics));
    int n = localDisplayMetrics.widthPixels;
    int i1 = this.l;
    int i2 = this.l;
    this.h = ((n - paramInt * 2 - i1 * 2) / 3);
    this.j = ((n - paramInt * 2 - i2) / 2);
    this.i = (this.h * 2);
    this.k = this.j;
  }
  
  private void a(Context paramContext, boolean paramBoolean)
  {
    setLayoutParams(new FrameLayout.LayoutParams(-2, -2, 80));
    setPadding(0, this.l, 0, 0);
    this.f = new ImageView(paramContext);
    LinearLayout localLinearLayout = new LinearLayout(paramContext);
    localLinearLayout.setLayoutParams(new FrameLayout.LayoutParams(-1, -2, 80));
    localLinearLayout.setGravity(8388611);
    localLinearLayout.setOrientation(1);
    localLinearLayout.setBackgroundColor(Color.parseColor("#80262626"));
    this.g = new TextView(paramContext);
    this.g.setLayoutParams(new FrameLayout.LayoutParams(-1, -2, 17));
    this.g.setGravity(17);
    this.g.setTextColor(paramContext.getResources().getColor(R.color.hockeyapp_text_white));
    this.g.setSingleLine();
    this.g.setEllipsize(TextUtils.TruncateAt.MIDDLE);
    if (paramBoolean)
    {
      paramContext = new ImageButton(paramContext);
      paramContext.setLayoutParams(new FrameLayout.LayoutParams(-1, -2, 80));
      paramContext.setAdjustViewBounds(true);
      paramContext.setImageDrawable(a("ic_menu_delete"));
      paramContext.setBackgroundResource(0);
      paramContext.setOnClickListener(new View.OnClickListener()
      {
        public final void onClick(View paramAnonymousView)
        {
          AttachmentView.this.remove();
        }
      });
      localLinearLayout.addView(paramContext);
    }
    localLinearLayout.addView(this.g);
    addView(this.f);
    addView(localLinearLayout);
  }
  
  private void a(Bitmap paramBitmap, final boolean paramBoolean)
  {
    int n;
    if (this.m == 1)
    {
      n = this.j;
      if (this.m != 1) {
        break label137;
      }
    }
    label137:
    for (int i1 = this.k;; i1 = this.i)
    {
      this.g.setMaxWidth(n);
      this.g.setMinWidth(n);
      this.f.setLayoutParams(new FrameLayout.LayoutParams(-2, -2));
      this.f.setAdjustViewBounds(true);
      this.f.setMinimumWidth(n);
      this.f.setMaxWidth(n);
      this.f.setMaxHeight(i1);
      this.f.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
      this.f.setImageBitmap(paramBitmap);
      this.f.setOnClickListener(new View.OnClickListener()
      {
        public final void onClick(View paramAnonymousView)
        {
          if (!paramBoolean) {
            return;
          }
          paramAnonymousView = new Intent();
          paramAnonymousView.setAction("android.intent.action.VIEW");
          paramAnonymousView.setDataAndType(AttachmentView.c(AttachmentView.this), "image/*");
          AttachmentView.d(AttachmentView.this).startActivity(paramAnonymousView);
        }
      });
      return;
      n = this.h;
      break;
    }
  }
  
  private void a(final boolean paramBoolean)
  {
    this.g.setMaxWidth(this.h);
    this.g.setMinWidth(this.h);
    this.f.setLayoutParams(new FrameLayout.LayoutParams(-2, -2));
    this.f.setAdjustViewBounds(false);
    this.f.setBackgroundColor(Color.parseColor("#eeeeee"));
    this.f.setMinimumHeight((int)(this.h * 1.2F));
    this.f.setMinimumWidth(this.h);
    this.f.setScaleType(ImageView.ScaleType.FIT_CENTER);
    this.f.setImageDrawable(a("ic_menu_attachment"));
    this.f.setOnClickListener(new View.OnClickListener()
    {
      public final void onClick(View paramAnonymousView)
      {
        if (!paramBoolean) {
          return;
        }
        paramAnonymousView = new Intent();
        paramAnonymousView.setAction("android.intent.action.VIEW");
        paramAnonymousView.setDataAndType(AttachmentView.c(AttachmentView.this), "*/*");
        AttachmentView.d(AttachmentView.this).startActivity(paramAnonymousView);
      }
    });
  }
  
  public FeedbackAttachment getAttachment()
  {
    return this.c;
  }
  
  public Uri getAttachmentUri()
  {
    return this.d;
  }
  
  public int getEffectiveMaxHeight()
  {
    if (this.m == 1) {
      return this.k;
    }
    return this.i;
  }
  
  public int getGap()
  {
    return this.l;
  }
  
  public int getMaxHeightLandscape()
  {
    return this.k;
  }
  
  public int getMaxHeightPortrait()
  {
    return this.i;
  }
  
  public int getWidthLandscape()
  {
    return this.j;
  }
  
  public int getWidthPortrait()
  {
    return this.h;
  }
  
  public void remove()
  {
    this.b.removeView(this);
  }
  
  public void setImage(Bitmap paramBitmap, int paramInt)
  {
    this.g.setText(this.e);
    this.m = paramInt;
    if (paramBitmap == null)
    {
      a(true);
      return;
    }
    a(paramBitmap, true);
  }
  
  public void signalImageLoadingError()
  {
    this.g.setText(R.string.hockeyapp_feedback_attachment_error);
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/net/hockeyapp/android/views/AttachmentView.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */