<commit_before>package cl.monsoon.s1next.view.activity;

import android.Manifest;
import android.app.DownloadManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.databinding.DataBindingUtil;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresPermission;
import android.support.annotation.StringRes;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.WindowInsetsCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

import com.google.common.base.Optional;

import java.lang.reflect.Method;

import cl.monsoon.s1next.R;
import cl.monsoon.s1next.databinding.ActivityGalleryBinding;
import cl.monsoon.s1next.util.IntentUtil;
import cl.monsoon.s1next.view.internal.CoordinatorLayoutAnchorDelegate;
import cl.monsoon.s1next.view.internal.ToolbarDelegate;
import cl.monsoon.s1next.viewmodel.ImageViewModel;

/**
 * An Activity shows an ImageView that supports multi-touch.
 */
public final class GalleryActivity extends AppCompatActivity
        implements CoordinatorLayoutAnchorDelegate {

    private final static int REQUEST_CODE_WRITE_EXTERNAL_STORAGE = 0;

    private static final String ARG_IMAGE_URL = "image_url";

    private String mImageUrl;

    public static void startGalleryActivity(Context context, String imageUrl) {
        Intent intent = new Intent(context, GalleryActivity.class);
        intent.putExtra(GalleryActivity.ARG_IMAGE_URL, imageUrl);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityGalleryBinding binding = DataBindingUtil.setContentView(this,
                R.layout.activity_gallery);

        ToolbarDelegate toolbarDelegate = new ToolbarDelegate(this, binding.toolbar);
        setTitle(null);
        toolbarDelegate.setupNavCrossIcon();

        // set Toolbar's top margin because we use `android:windowTranslucentStatus` in this Activity
        // we only use translucent status if API >= 21
        ViewCompat.setOnApplyWindowInsetsListener(binding.toolbar, (v, insets) -> {
            ((ViewGroup.MarginLayoutParams) v.getLayoutParams()).topMargin =
                    insets.getSystemWindowInsetTop();

            // see CoordinatorLayout#setWindowInsets(WindowInsetsCompat)
            // add CoordinatorLayout's default View.OnApplyWindowInsetsListener implementation
            try {
                Method method = CoordinatorLayout.class.getDeclaredMethod("setWindowInsets",
                        WindowInsetsCompat.class);
                method.setAccessible(true);
                // use 0 px top inset because we want to have translucent status bar
                WindowInsetsCompat insetsWithoutZeroTop = insets.replaceSystemWindowInsets(
                        insets.getSystemWindowInsetLeft(), 0, insets.getSystemWindowInsetRight(),
                        insets.getSystemWindowInsetBottom());
                method.invoke(binding.coordinatorLayout, insetsWithoutZeroTop);
            } catch (Exception e) {
                throw new RuntimeException("Failed to invoke CoordinatorLayout#setWindowInsets(" +
                        "WindowInsetsCompat).", e);
            }
            return insets.consumeSystemWindowInsets();
        });

        mImageUrl = getIntent().getStringExtra(ARG_IMAGE_URL);
        binding.setImageViewModel(new ImageViewModel(mImageUrl));
    }
<commit_msg>Clarify why we use `CoordinatorLayout` in `GalleryActivity`<commit_after>package cl.monsoon.s1next.view.activity;

import android.Manifest;
import android.app.DownloadManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.databinding.DataBindingUtil;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresPermission;
import android.support.annotation.StringRes;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.WindowInsetsCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

import com.google.common.base.Optional;

import java.lang.reflect.Method;

import cl.monsoon.s1next.R;
import cl.monsoon.s1next.databinding.ActivityGalleryBinding;
import cl.monsoon.s1next.util.IntentUtil;
import cl.monsoon.s1next.view.internal.CoordinatorLayoutAnchorDelegate;
import cl.monsoon.s1next.view.internal.ToolbarDelegate;
import cl.monsoon.s1next.viewmodel.ImageViewModel;

/**
 * An Activity shows an ImageView that supports multi-touch.
 */
public final class GalleryActivity extends AppCompatActivity
        implements CoordinatorLayoutAnchorDelegate {

    private final static int REQUEST_CODE_WRITE_EXTERNAL_STORAGE = 0;

    private static final String ARG_IMAGE_URL = "image_url";

    private String mImageUrl;

    public static void startGalleryActivity(Context context, String imageUrl) {
        Intent intent = new Intent(context, GalleryActivity.class);
        intent.putExtra(GalleryActivity.ARG_IMAGE_URL, imageUrl);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityGalleryBinding binding = DataBindingUtil.setContentView(this,
                R.layout.activity_gallery);

        ToolbarDelegate toolbarDelegate = new ToolbarDelegate(this, binding.toolbar);
        setTitle(null);
        toolbarDelegate.setupNavCrossIcon();

        // set Toolbar's top margin because we use `android:windowTranslucentStatus` in this Activity
        // we only use translucent status if API >= 21
        ViewCompat.setOnApplyWindowInsetsListener(binding.toolbar, (v, insets) -> {
            ((ViewGroup.MarginLayoutParams) v.getLayoutParams()).topMargin =
                    insets.getSystemWindowInsetTop();

            // see http://stackoverflow.com/q/31492040
            try {
                // see CoordinatorLayout#setWindowInsets(WindowInsetsCompat)
                // add CoordinatorLayout's default View.OnApplyWindowInsetsListener implementation
                Method method = CoordinatorLayout.class.getDeclaredMethod("setWindowInsets",
                        WindowInsetsCompat.class);
                method.setAccessible(true);
                // use 0 px top inset because we want to have translucent status bar
                WindowInsetsCompat insetsWithoutZeroTop = insets.replaceSystemWindowInsets(
                        insets.getSystemWindowInsetLeft(), 0, insets.getSystemWindowInsetRight(),
                        insets.getSystemWindowInsetBottom());
                method.invoke(binding.coordinatorLayout, insetsWithoutZeroTop);
            } catch (Exception e) {
                throw new RuntimeException("Failed to invoke CoordinatorLayout#setWindowInsets(" +
                        "WindowInsetsCompat).", e);
            }

            return insets.consumeSystemWindowInsets();
        });

        mImageUrl = getIntent().getStringExtra(ARG_IMAGE_URL);
        binding.setImageViewModel(new ImageViewModel(mImageUrl));
    }

{'fraction_non_alphanumeric': 0.08245083207261725, 'fraction_numerical': 0.005042864346949067, 'mean_word_length': 3.5176537585421412, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3110633', 'n_tokens_mistral': 2129, 'n_tokens_neox': 2041, 'n_words': 416}