<commit_before>package de.fu_berlin.cdv.chasingpictures;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.location.Location;
import android.widget.TextView;

import java.io.File;

import de.fu_berlin.cdv.chasingpictures.api.Place;


/**
 * A simple {@link Fragment} subclass.
 * Activities that contain this fragment must implement the
 * {@link PictureCard.OnFragmentInteractionListener} interface
 * to handle interaction events.
 * Use the {@link PictureCard#newInstance} factory method to
 * create an instance of this fragment.
 */
public class PictureCard extends Fragment {
    public static final String PLACE = "place_param";
    public static final String USER_LOCATION = "user_location";

    private Place[] places;
    private int currentPlace = 0;
    private SwipeDetector mSwipeDetector;
    private View view;
    private Location userLocation;

    private OnFragmentInteractionListener mListener;

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param places a list of places
     * @return A new instance of fragment PictureCard.
     */
    // TODO: Rename and change types and number of parameters
    public static PictureCard newInstance(Location userLocation, Place... places) {
        PictureCard fragment = new PictureCard();
        Bundle args = new Bundle();
        args.putSerializable(PLACE, places);
        args.putParcelable(USER_LOCATION, userLocation);
        fragment.setArguments(args);
        return fragment;
    }

    public PictureCard() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            this.places = (Place[]) getArguments().getSerializable(PLACE);
            this.userLocation = getArguments().getParcelable(USER_LOCATION);
        }
        mSwipeDetector = new SwipeDetector();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_picture_card, container, false);
        view.setOnTouchListener(mSwipeDetector);

        view.setOnClickListener(new ClickListener());

        updatePicture();
        showDelayedPlaceInfo(currentPlace);

        return view;
    }

    private void updatePicture() {
        File cachedFile = places[currentPlace].getPicture().getCachedFile();
        if (cachedFile != null) {
            Bitmap bitmap = BitmapFactory.decodeFile(cachedFile.getPath());
            ((ImageView) view.findViewById(R.id.picture_card_image)).setImageBitmap(bitmap);
        }
    }

    // not actually delayed yet
    private void showDelayedPlaceInfo(int placeNr) {
        ((TextView) view.findViewById(R.id.place_info)).setText(
                String.valueOf(Math.round(places[placeNr].distanceTo(userLocation))) + "m"
        );
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        try {
            mListener = (OnFragmentInteractionListener) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString()
                    + " must implement OnFragmentInteractionListener");
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mListener = null;
    }<commit_msg>Add 1s delay to showing the distance to a place.<commit_after>package de.fu_berlin.cdv.chasingpictures;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.app.Fragment;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.location.Location;
import android.widget.TextView;

import java.io.File;

import de.fu_berlin.cdv.chasingpictures.api.Place;


/**
 * A simple {@link Fragment} subclass.
 * Activities that contain this fragment must implement the
 * {@link PictureCard.OnFragmentInteractionListener} interface
 * to handle interaction events.
 * Use the {@link PictureCard#newInstance} factory method to
 * create an instance of this fragment.
 */
public class PictureCard extends Fragment {
    public static final String PLACE = "place_param";
    public static final String USER_LOCATION = "user_location";

    private Place[] places;
    private int currentPlace = 0;
    private SwipeDetector mSwipeDetector;
    private View view;
    private Location userLocation;

    private OnFragmentInteractionListener mListener;

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param places a list of places
     * @return A new instance of fragment PictureCard.
     */
    // TODO: Rename and change types and number of parameters
    public static PictureCard newInstance(Location userLocation, Place... places) {
        PictureCard fragment = new PictureCard();
        Bundle args = new Bundle();
        args.putSerializable(PLACE, places);
        args.putParcelable(USER_LOCATION, userLocation);
        fragment.setArguments(args);
        return fragment;
    }

    public PictureCard() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            this.places = (Place[]) getArguments().getSerializable(PLACE);
            this.userLocation = getArguments().getParcelable(USER_LOCATION);
        }
        mSwipeDetector = new SwipeDetector();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_picture_card, container, false);
        view.setOnTouchListener(mSwipeDetector);

        view.setOnClickListener(new ClickListener());

        updatePicture();
        showDelayedPlaceInfo(currentPlace);

        return view;
    }

    private void updatePicture() {
        File cachedFile = places[currentPlace].getPicture().getCachedFile();
        if (cachedFile != null) {
            Bitmap bitmap = BitmapFactory.decodeFile(cachedFile.getPath());
            ((ImageView) view.findViewById(R.id.picture_card_image)).setImageBitmap(bitmap);
        }
    }

    private void showDelayedPlaceInfo(final int placeNr) {
        final TextView placeInfo = (TextView) view.findViewById(R.id.place_info);
        placeInfo.setText("");
        new Handler().postDelayed(
                new Runnable() {
                    @Override
                    public void run() {
                        placeInfo.setText(String.valueOf(Math.round(places[placeNr].distanceTo(userLocation))) + "m");
                    }
                },
                1000
        );
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        try {
            mListener = (OnFragmentInteractionListener) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString()
                    + " must implement OnFragmentInteractionListener");
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mListener = null;
    }
{'fraction_non_alphanumeric': 0.08820564516129033, 'fraction_numerical': 0.0008820564516129032, 'mean_word_length': 2.8361527307878203, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '143495', 'n_tokens_mistral': 2106, 'n_tokens_neox': 2002, 'n_words': 541}