<commit_before>package com.example.android.eyebody.gallery

import android.os.Bundle
import android.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

import com.example.android.eyebody.R
import kotlinx.android.synthetic.main.fragment_image_collage.*
import android.graphics.Bitmap
import android.os.Environment
import android.widget.Toast
import java.io.*


class ImageCollageFragment : Fragment() {
    lateinit var collage: CollageActivity
    lateinit var photoList: ArrayList<Photo>
    lateinit var selected: ArrayList<Int>

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        collage = activity as CollageActivity
        photoList = collage.photoList
        selected = collage.selectedPhotoList
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
        return inflater.inflate(R.layout.fragment_image_collage, container, false)
    }

    override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        makeGifButton.setOnClickListener {
            val bos = ByteArrayOutputStream()
            val encoder = AnimatedGifEncoder()
            encoder.setDelay(500)
            encoder.setRepeat(0)
            encoder.start(bos)

            try {
                val bmp1: Bitmap
                val bmp2: Bitmap
                val bmp3: Bitmap

                bmp1 = photoList[selected[0]].getBitmap()
                encoder.addFrame(bmp1)
                bmp1.recycle()

                bmp2 = photoList[selected[1]].getBitmap()
                encoder.addFrame(bmp2)
                bmp2.recycle()

                bmp3 = photoList[selected[2]].getBitmap()
                encoder.addFrame(bmp3)
                bmp3.recycle()

            } catch (e: FileNotFoundException) {
                e.printStackTrace()
            }

            encoder.finish()

            val filePath = File(Environment.getExternalStorageDirectory().absolutePath + "/EyeBody/sample.gif")
            val outputStream: FileOutputStream
            try {
                if(!filePath.exists()){
                    if(!filePath.mkdirs()){
                        var test = 1
                    }
                }
                outputStream = FileOutputStream(filePath)
                outputStream.write(bos.toByteArray())
            } catch (e: FileNotFoundException) {
                e.printStackTrace()
                Toast.makeText(activity, "오류: " + e.toString(), Toast.LENGTH_SHORT)
            } catch (e: IOException) {
                e.printStackTrace()
                Toast.makeText(activity, "오류: " + e.toString(), Toast.LENGTH_SHORT)
            }
        }
    }

}<commit_msg>gif 만들기 샘플코드 작성 외부저장소 쓰기 권한 획득<commit_after>package com.example.android.eyebody.gallery

import android.Manifest
import android.os.Bundle
import android.app.Fragment
import android.content.pm.PackageManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

import com.example.android.eyebody.R
import kotlinx.android.synthetic.main.fragment_image_collage.*
import android.graphics.Bitmap
import android.os.Environment
import android.support.v4.app.ActivityCompat
import android.support.v4.content.ContextCompat
import android.widget.Toast
import java.io.*
import android.graphics.BitmapFactory




class ImageCollageFragment : Fragment() {
    lateinit var collage: CollageActivity
    lateinit var photoList: ArrayList<Photo>
    lateinit var selected: ArrayList<Int>

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        collage = activity as CollageActivity
        photoList = collage.photoList
        selected = collage.selectedPhotoList
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
        return inflater.inflate(R.layout.fragment_image_collage, container, false)
    }

    override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        //WRITE_EXTERNAL_STORAGE 권한 요청
        if(ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){
            ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 1)
        }

        makeGifButton.setOnClickListener {
            makeGif()
        }
    }

    fun makeGif(){
        val bos = ByteArrayOutputStream()
        val encoder = AnimatedGifEncoder()
        encoder.setDelay(500)
        encoder.setRepeat(0)
        encoder.start(bos)

        try {
            val bmp1: Bitmap
            val bmp2: Bitmap
            val bmp3: Bitmap

            bmp1 = BitmapFactory.decodeStream(FileInputStream(photoList[selected[0]].imageURL))
            encoder.addFrame(bmp1)
            bmp1.recycle()

            bmp2 = BitmapFactory.decodeStream(FileInputStream(photoList[selected[1]].imageURL))
            encoder.addFrame(bmp2)
            bmp2.recycle()

            bmp3 = BitmapFactory.decodeStream(FileInputStream(photoList[selected[2]].imageURL))
            encoder.addFrame(bmp3)
            bmp3.recycle()

        } catch (e: FileNotFoundException) {
            Toast.makeText(activity, "GIF 파일을 만들지 못하였습니다", Toast.LENGTH_SHORT).show()
            return
        }


        encoder.finish()


        //폴더 만들기(외부저장소/Pictures/EyeBody)
        var filePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).absolutePath + "/EyeBody"
        var file = File(filePath)

        if(!file.exists()){
            if(!file.mkdirs()){
                Toast.makeText(activity, "디렉토리가 만들어지지 않음", Toast.LENGTH_SHORT).show()
                return
            }
        }

        //파일 만들기
        file = File(filePath, "sample.gif")
        try {
            var fos = FileOutputStream(file)
            fos.write(bos.toByteArray())
            fos.close()
        } catch (e: FileNotFoundException) {
            Toast.makeText(activity, "파일을 찾을 수 없습니다", Toast.LENGTH_SHORT).show()
            return
        } catch (e: IOException) {
            Toast.makeText(activity, "쓰기 오류", Toast.LENGTH_SHORT).show()
            return
        }

        Toast.makeText(activity, "GIF 이미지를 저장하였습니다", Toast.LENGTH_SHORT).show()
    }

}
{'fraction_non_alphanumeric': 0.0914662172514172, 'fraction_numerical': 0.006434809253868546, 'mean_word_length': 2.349409953822473, 'pattern_counts': {'":': 0, '<': 7, '<?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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1698810', 'n_tokens_mistral': 1966, 'n_tokens_neox': 1881, 'n_words': 338}