m.java 9.51 KB
package com.instabug.library.util;

import android.app.Activity;
import android.app.Dialog;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.opengl.GLSurfaceView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import com.instabug.library.internal.a.b;
import com.instabug.library.internal.layer.c;
import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.opengles.GL10;

public class m
{
  private a a;
  private Activity b;
  private Dialog c;
  private int[] d;
  private View e;
  private View f;
  private Bitmap g;
  private GLSurfaceView h;
  private List<c> i;
  private Exception j;
  
  public m(Activity paramActivity, Dialog paramDialog, GLSurfaceView paramGLSurfaceView, List<c> paramList, b paramb)
  {
    this.b = paramActivity;
    this.c = paramDialog;
    this.h = paramGLSurfaceView;
    this.i = paramList;
  }
  
  private void a(ViewGroup paramViewGroup, List<View> paramList)
  {
    LinkedList localLinkedList = new LinkedList();
    int k = 0;
    if (k < paramViewGroup.getChildCount())
    {
      View localView = paramViewGroup.getChildAt(k);
      int m;
      if (((localView.getClass().getCanonicalName() != null) && (localView.getClass().getCanonicalName().startsWith("com.instabug.library"))) || ((localView.getClass().getName() != null) && (localView.getClass().getName().startsWith("com.instabug.library"))))
      {
        m = 1;
        label83:
        if (m == 0) {
          break label117;
        }
        localView.setVisibility(8);
        paramList.add(localView);
      }
      for (;;)
      {
        k += 1;
        break;
        m = 0;
        break label83;
        label117:
        if ((localView instanceof ViewGroup)) {
          localLinkedList.add((ViewGroup)localView);
        }
      }
    }
    paramViewGroup = localLinkedList.iterator();
    while (paramViewGroup.hasNext()) {
      a((ViewGroup)paramViewGroup.next(), paramList);
    }
  }
  
  private void c()
  {
    InstabugSDKLogger.d(this, "ScreenshotProcessor: start capturing " + Thread.currentThread().getName());
    for (;;)
    {
      Object localObject1;
      Object localObject2;
      int k;
      int m;
      final int i1;
      final int i2;
      Object localObject4;
      final Object localObject5;
      try
      {
        this.e = this.b.getWindow().getDecorView();
        if ((this.c != null) && (this.c.isShowing()))
        {
          this.f = this.c.getWindow().getDecorView();
          this.d = new int[2];
          this.f.getLocationOnScreen(this.d);
        }
        this.g = Bitmap.createBitmap(this.e.getWidth(), this.e.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas localCanvas = new Canvas();
        localCanvas.setBitmap(this.g);
        localObject1 = new ArrayList(3);
        if ((this.b.getWindow().getDecorView().getRootView() instanceof ViewGroup)) {
          a((ViewGroup)this.b.getWindow().getDecorView().getRootView(), (List)localObject1);
        }
        localObject2 = this.b.getWindow().getDecorView().getBackground();
        if (localObject2 != null)
        {
          this.b.getWindow().setBackgroundDrawable(null);
          ((Drawable)localObject2).draw(localCanvas);
        }
        k = 0;
        m = 0;
        if (this.i != null)
        {
          localObject3 = this.i.iterator();
          k = m;
          if (((Iterator)localObject3).hasNext())
          {
            c localc = (c)((Iterator)localObject3).next();
            try
            {
              localc.a(localCanvas);
              k = 1;
            }
            catch (Exception localException2)
            {
              InstabugSDKLogger.e(this, "drawing screenshot error", localException2);
              k = 1;
            }
            continue;
          }
        }
        m = k;
        if (this.h != null)
        {
          m = k;
          if (this.h.getVisibility() == 0)
          {
            m = k;
            if (this.h.getWindowToken() != null)
            {
              localObject3 = new int[2];
              this.h.getLocationOnScreen((int[])localObject3);
              i1 = this.h.getWidth();
              i2 = this.h.getHeight();
              localObject4 = new int[(i2 + 0) * i1];
              localObject5 = IntBuffer.wrap((int[])localObject4);
              ((IntBuffer)localObject5).position(0);
              final CountDownLatch localCountDownLatch = new CountDownLatch(1);
              this.h.queueEvent(new Runnable()
              {
                public final void run()
                {
                  Object localObject = (EGL10)EGLContext.getEGL();
                  ((EGL10)localObject).eglWaitGL();
                  localObject = (GL10)((EGL10)localObject).eglGetCurrentContext().getGL();
                  ((GL10)localObject).glFinish();
                  try
                  {
                    Thread.sleep(200L);
                    ((GL10)localObject).glReadPixels(0, 0, i1, i2 + 0, 6408, 5121, localObject5);
                    localCountDownLatch.countDown();
                    return;
                  }
                  catch (InterruptedException localInterruptedException)
                  {
                    for (;;)
                    {
                      localInterruptedException.printStackTrace();
                    }
                  }
                }
              });
              localCountDownLatch.await();
              localObject5 = new int[i1 * i2];
              m = 0;
              k = 0;
              break label854;
              localObject4 = Bitmap.createBitmap((int[])localObject5, i1, i2, Bitmap.Config.ARGB_8888);
              localCanvas.drawBitmap((Bitmap)localObject4, localObject3[0], localObject3[1], null);
              ((Bitmap)localObject4).recycle();
              m = 1;
            }
          }
        }
        if (m == 0) {
          break label700;
        }
        boolean bool = this.e.isDrawingCacheEnabled();
        if (!bool) {
          this.e.setDrawingCacheEnabled(true);
        }
        this.e.setDrawingCacheBackgroundColor(0);
        Object localObject3 = this.e.getDrawingCache(true);
        localCanvas.drawBitmap((Bitmap)localObject3, 0.0F, 0.0F, null);
        ((Bitmap)localObject3).recycle();
        this.e.destroyDrawingCache();
        this.e.setDrawingCacheEnabled(bool);
        this.b.getWindow().setBackgroundDrawable((Drawable)localObject2);
        localObject1 = ((List)localObject1).iterator();
        if (!((Iterator)localObject1).hasNext()) {
          break label712;
        }
        ((View)((Iterator)localObject1).next()).setVisibility(0);
        continue;
        this.e.setDrawingCacheEnabled(false);
      }
      catch (Exception localException1)
      {
        this.j = localException1;
        this.a.a(Log.getStackTraceString(localException1.getCause()), this.j);
      }
      label629:
      if (this.g != null) {
        if (!a().isFinishing())
        {
          InstabugSDKLogger.d(this, "ScreenShot ready");
          this.a.a(this.g);
        }
      }
      for (;;)
      {
        this.b = null;
        this.a = null;
        this.c = null;
        this.e = null;
        this.f = null;
        return;
        label700:
        this.e.draw(localException1);
        break;
        label712:
        if (this.f == null) {
          break label629;
        }
        localObject1 = Bitmap.createBitmap(this.f.getWidth(), this.f.getHeight(), Bitmap.Config.ARGB_8888);
        localObject2 = new Canvas((Bitmap)localObject1);
        this.f.draw((Canvas)localObject2);
        localException1.drawBitmap((Bitmap)localObject1, this.d[0], this.d[1], null);
        ((Canvas)localObject2).setBitmap(null);
        this.f = null;
        ((Bitmap)localObject1).recycle();
        break label629;
        InstabugSDKLogger.d(this, "ScreenShot Error");
        this.a.a("Top most activity changed while capturing screenshot. Aborting feedback process.", this.j);
        continue;
        InstabugSDKLogger.d(this, "ScreenShot Error equal null");
        this.a.a("Could not capture screenshot", this.j);
      }
      label854:
      while (m < i2)
      {
        int n = 0;
        while (n < i1)
        {
          int i3 = localObject4[(m * i1 + n)];
          localObject5[((i2 - k - 1) * i1 + n)] = (i3 & 0xFF00FF00 | i3 << 16 & 0xFF0000 | i3 >> 16 & 0xFF);
          n += 1;
        }
        m += 1;
        k += 1;
      }
    }
  }
  
  protected Activity a()
  {
    return this.b;
  }
  
  public void a(a parama)
  {
    this.a = parama;
  }
  
  public void b()
  {
    if (this.a == null) {
      throw new IllegalStateException("OnScreenshotReady Listener cannot be null. Make sure you call setListener or pass a listener through the constructor");
    }
    if (this.b.isFinishing())
    {
      InstabugSDKLogger.d(this, "ScreenshotProcessor: Activity.isFinishing()");
      this.a.a("Top most activity changed before capturing screenshot", this.j);
      return;
    }
    c();
  }
  
  public static abstract interface a
  {
    public abstract void a(Bitmap paramBitmap);
    
    public abstract void a(String paramString, Exception paramException);
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/instabug/library/util/m.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */