f.java 7.43 KB
package com.instabug.library;

import android.app.Activity;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffColorFilter;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.instabug.library.internal.b.b;
import com.instabug.library.util.InstabugSDKLogger;
import com.instabug.library.util.k;
import com.instabug.library.util.l;
import java.util.Timer;
import java.util.TimerTask;

public class f
  extends Fragment
  implements View.OnTouchListener
{
  private ImageView a;
  private boolean b = false;
  private ImageView c;
  private PorterDuffColorFilter d;
  private Timer e;
  private b f;
  private int g;
  private TimerTask h = new a();
  private TextView i;
  private TextView j;
  private boolean k;
  private boolean l = false;
  private b m;
  
  public static Fragment a(String paramString)
  {
    f localf = new f();
    Bundle localBundle = new Bundle();
    localBundle.putString("com.instabug.library.audio_attachment_path", paramString);
    localf.setArguments(localBundle);
    return localf;
  }
  
  private void a()
  {
    k.a(this, "android.permission.RECORD_AUDIO", 1, new Runnable()new Runnable
    {
      public final void run()
      {
        if (f.a(f.this))
        {
          InstabugSDKLogger.d(f.this, "Shouldn't try to explain why get this permission, either first time or never again selected OR permission not in manifest");
          Toast.makeText(f.this.getContext(), f.b(f.this), 0).show();
          Instabug.setShouldAudioRecordingOptionAppear(false);
          return;
        }
        f.c(f.this);
      }
    }, new Runnable()
    {
      public final void run()
      {
        InstabugSDKLogger.d(f.this, "Audio recording permission already granted before");
        f.d(f.this);
      }
    });
  }
  
  private void b()
  {
    if (this.m != null) {
      this.m.a(getArguments().getString("com.instabug.library.audio_attachment_path"));
    }
  }
  
  private boolean c()
  {
    try
    {
      this.h.cancel();
      this.e.cancel();
      this.h = new a();
      this.e = new Timer();
      this.b = false;
      this.a.setImageResource(R.drawable.instabug_record_default_bk);
      this.c.setColorFilter(this.d);
      this.i.setText(String.format("00:%02d", new Object[] { Integer.valueOf(0) }));
      this.j.setText(l.a(IBGCustomTextPlaceHolder.Key.VOICE_MESSAGE_PRESS_AND_HOLD_TO_RECORD, getString(R.string.instabug_str_hold_to_record)));
      this.f.b();
      int n = this.g;
      return n > 3;
    }
    catch (RuntimeException localRuntimeException)
    {
      if (this.g > 1) {
        Toast.makeText(getActivity(), "Unknown error occurred", 0).show();
      }
      InstabugSDKLogger.e(this, "Error capturing audio stream", localRuntimeException);
    }
    return false;
  }
  
  private String d()
  {
    return l.a(IBGCustomTextPlaceHolder.Key.AUDIO_RECORDING_PERMISSION_DENIED, getString(R.string.instabug_audio_recorder_permission_denied));
  }
  
  public void onAttach(Activity paramActivity)
  {
    super.onAttach(paramActivity);
    try
    {
      this.m = ((b)paramActivity);
      return;
    }
    catch (ClassCastException localClassCastException)
    {
      throw new ClassCastException(paramActivity.toString() + " must implement InstabugAudioRecordingFragment.Callbacks");
    }
  }
  
  @Nullable
  public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle)
  {
    this.k = false;
    this.e = new Timer();
    this.f = new b(getArguments().getString("com.instabug.library.audio_attachment_path"));
    paramLayoutInflater = paramLayoutInflater.inflate(R.layout.instabug_lyt_record_audio, paramViewGroup, false);
    paramLayoutInflater.findViewById(R.id.instabug_btn_record_audio).setOnTouchListener(this);
    this.a = ((ImageView)paramLayoutInflater.findViewById(R.id.instabug_bk_record_audio));
    this.c = ((ImageView)paramLayoutInflater.findViewById(R.id.instabug_img_record_audio));
    this.d = new PorterDuffColorFilter(Instabug.getSettingsBundle().y(), PorterDuff.Mode.SRC_IN);
    this.a.setColorFilter(this.d);
    this.c.setColorFilter(this.d);
    this.i = ((TextView)paramLayoutInflater.findViewById(R.id.instabug_txt_timer));
    this.i.setText(String.format("00:%02d", new Object[] { Integer.valueOf(0) }));
    this.j = ((TextView)paramLayoutInflater.findViewById(R.id.instabug_txt_recording_title));
    this.j.setText(l.a(IBGCustomTextPlaceHolder.Key.VOICE_MESSAGE_PRESS_AND_HOLD_TO_RECORD, getString(R.string.instabug_str_hold_to_record)));
    return paramLayoutInflater;
  }
  
  public void onDetach()
  {
    super.onDetach();
    this.m = null;
  }
  
  public void onRequestPermissionsResult(int paramInt, @NonNull String[] paramArrayOfString, @NonNull int[] paramArrayOfInt)
  {
    switch (paramInt)
    {
    default: 
      super.onRequestPermissionsResult(paramInt, paramArrayOfString, paramArrayOfInt);
      return;
    }
    if (paramArrayOfInt[0] == 0)
    {
      InstabugSDKLogger.d(this, "Audio recording permission granted by user");
      this.k = true;
      return;
    }
    InstabugSDKLogger.d(this, "Audio recording permission denied by user");
    this.k = false;
    Toast.makeText(getContext(), d(), 0).show();
  }
  
  public boolean onTouch(View paramView, MotionEvent paramMotionEvent)
  {
    switch (paramMotionEvent.getAction())
    {
    }
    do
    {
      do
      {
        return true;
        if ((!this.b) && (this.k))
        {
          this.g = 0;
          this.e.scheduleAtFixedRate(this.h, 0L, 1000L);
          this.f.a();
          this.b = true;
          this.a.setImageResource(R.drawable.instabug_record_default_active);
          this.c.setColorFilter(null);
          this.j.setText(l.a(IBGCustomTextPlaceHolder.Key.VOICE_MESSAGE_RELEASE_TO_ATTACH, getString(R.string.instabug_str_release_stop_record)));
        }
      } while (this.k);
      a();
      return true;
    } while ((!this.b) || (!this.k) || (!c()) || (paramMotionEvent.getAction() != 1));
    b();
    return true;
  }
  
  public void onViewCreated(View paramView, @Nullable Bundle paramBundle)
  {
    super.onViewCreated(paramView, paramBundle);
    a();
  }
  
  final class a
    extends TimerTask
  {
    a() {}
    
    public final void run()
    {
      f.this.getActivity().runOnUiThread(new Runnable()
      {
        public final void run()
        {
          if (f.e(f.this) >= 50)
          {
            f.f(f.this).setTextColor(-65536);
            if (f.e(f.this) != 60) {
              break label89;
            }
            f.g(f.this);
          }
          for (;;)
          {
            f.h(f.this);
            return;
            f.f(f.this).setTextColor(Instabug.getSettingsBundle().y());
            break;
            label89:
            f.f(f.this).setText(String.format("00:%02d", new Object[] { Integer.valueOf(f.e(f.this)) }));
          }
        }
      });
    }
  }
  
  public static abstract interface b
  {
    public abstract void a(String paramString);
  }
}


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