Repository: square/leakcanary
File: leakcanary-android/src/main/java/com/squareup/leakcanary/internal/DisplayLeakActivity.java (Java)

Code before:
        actionButton.setText(R.string.leak_canary_delete_all);
        actionButton.setOnClickListener(new View.OnClickListener() {
          @Override public void onClick(View v) {
            new AlertDialog.Builder(DisplayLeakActivity.this).setIcon(
                android.R.drawable.ic_dialog_alert)
                .setTitle(R.string.leak_canary_delete_all)
                .setMessage(R.string.leak_canary_delete_all_leaks_title)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                  @Override public void onClick(DialogInterface dialog, int which) {
                    deleteAllLeaks();
                  }
                })
                .setNegativeButton(android.R.string.cancel, null)
                .show();
          }
        });
      }
      actionButton.setVisibility(leaks.size() == 0 ? GONE : VISIBLE);
      shareButton.setVisibility(GONE);
    }
  }

  private void shareLeakToStackOverflow() {
    AnalyzedHeap visibleLeak = getVisibleLeak();
    final String leakInfo = LeakCanary.INSTANCE.leakInfo(this, visibleLeak.heapDump, visibleLeak.result, false);
    final Toast toast = Toast.makeText(this, R.string.leak_canary_leak_copied, Toast.LENGTH_SHORT);
    final ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    AsyncTask.execute(new Runnable() {
      public void run() {
        clipboard.setPrimaryClip(
            ClipData.newPlainText(getString(R.string.leak_canary_leak_clipdata_label),
                "```\n" + leakInfo + "```"));
        toast.show();
      }
    });
    Intent browserIntent =
        new Intent(Intent.ACTION_VIEW,
            Uri.parse("http://www.stackoverflow.com/questions/ask?guided=false"));
    startActivity(browserIntent);
  }

  private void setDisplayHomeAsUpEnabled(boolean enabled) {
    ActionBar actionBar = getActionBar();
    if (actionBar == null) {
      // https://github.com/square/leakcanary/issues/967
      return;
    }
    actionBar.setDisplayHomeAsUpEnabled(enabled);
  }

  AnalyzedHeap getVisibleLeak() {

Review comment (suggestion):
LENGTH_SHORT => LENGTH_LONG? People are going to miss this. Another option might be a dialog that explains what's up but that could be annoying.

Code after:
        setTitle(getString(R.string.leak_canary_leak_list_title, getPackageName()));
        setDisplayHomeAsUpEnabled(false);
        actionButton.setText(R.string.leak_canary_delete_all);
        actionButton.setOnClickListener(new View.OnClickListener() {
          @Override public void onClick(View v) {
            new AlertDialog.Builder(DisplayLeakActivity.this).setIcon(
                android.R.drawable.ic_dialog_alert)
                .setTitle(R.string.leak_canary_delete_all)
                .setMessage(R.string.leak_canary_delete_all_leaks_title)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                  @Override public void onClick(DialogInterface dialog, int which) {
                    deleteAllLeaks();
                  }
                })
                .setNegativeButton(android.R.string.cancel, null)
                .show();
          }
        });
      }
      actionButton.setVisibility(leaks.size() == 0 ? GONE : VISIBLE);
      shareButton.setVisibility(GONE);
    }
  }

  private void shareLeakToStackOverflow() {
    AnalyzedHeap visibleLeak = getVisibleLeak();
    final String leakInfo =
        LeakCanary.INSTANCE.leakInfo(this, visibleLeak.heapDump, visibleLeak.result, false);
    final ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    // AsyncTask was needed here due to setPrimaryClip making a disk write which
    // violated StrictMode if on the main thread
    AsyncTask.execute(new Runnable() {
      public void run() {
        clipboard.setPrimaryClip(
            ClipData.newPlainText(getString(R.string.leak_canary_leak_clipdata_label),
                "```\n" + leakInfo + "```"));
      }
    });
    Toast.makeText(this, R.string.leak_canary_leak_copied, Toast.LENGTH_LONG).show();
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(STACKOVERFLOW_QUESTION_URL));
    startActivity(browserIntent);
  }

  private void setDisplayHomeAsUpEnabled(boolean enabled) {
    ActionBar actionBar = getActionBar();
    if (actionBar == null) {
      // https://github.com/square/leakcanary/issues/967
      return;
    }
    actionBar.setDisplayHomeAsUpEnabled(enabled);
  }