package com.jakewharton.telecine;

import android.app.Activity;
import android.content.Intent;
import android.media.projection.MediaProjectionManager;
import android.os.Bundle;
import butterknife.ButterKnife;
import butterknife.OnClick;
import timber.log.Timber;

public final class TelecineActivity extends Activity {
  private static final int CREATE_SCREEN_CAPTURE = 4242;

  @Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.inject(this);
  }

  @OnClick(R.id.launch) void onLaunchClicked() {
    Timber.d("Attempting to acquire permission to screen capture.");

    MediaProjectionManager manager =
        (MediaProjectionManager) getSystemService(MEDIA_PROJECTION_SERVICE);
    Intent intent = manager.createScreenCaptureIntent();
    startActivityForResult(intent, CREATE_SCREEN_CAPTURE);
  }

  @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
      case CREATE_SCREEN_CAPTURE:
        Timber.d("Acquired permission to screen capture. Starting service.");
        startService(TelecineService.newIntent(this, resultCode, data));
        break;

      default:
        super.onActivityResult(requestCode, resultCode, data);
    }
  }
}

@@ -1061,16 +1061,137 @@
 APTURE:%0A
+        if (resultCode == 0) %7B%0A          Timber.d(%22Failed to acquire permission to screen capture.%22);%0A        %7D else %7B%0A  
         
@@ -1256,24 +1256,26 @@
 service.%22);%0A
+  
         star
@@ -1335,16 +1335,26 @@
 data));%0A
+        %7D%0A
         

Handle when the user presses cancel on the permission prompt.