package epson.common;

import android.os.Build;

import android.support.annotation.RequiresApi;
import android.support.media.ExifInterface;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ExifCopy {
    private static final String[] COMMON_ATTRIBUTE_TAGS = {ExifInterface.TAG_DATETIME, ExifInterface.TAG_ORIENTATION, ExifInterface.TAG_WHITE_BALANCE, ExifInterface.TAG_EXPOSURE_TIME, ExifInterface.TAG_FLASH};

    public static boolean copyExif(String str, String str2) {
        List<String> tagList = getTagList();
        try {
            android.media.ExifInterface exifInterface = new android.media.ExifInterface(str);
            android.media.ExifInterface exifInterface2 = new android.media.ExifInterface(str2);
            for (String next : tagList) {
                String attribute = exifInterface.getAttribute(next);
                if (attribute != null) {
                    exifInterface2.setAttribute(next, attribute);
                }
            }
            exifInterface2.saveAttributes();
            return true;
        } catch (IOException unused) {
            return false;
        }
    }

    @NonNull
    private static List<String> getTagList() {
        ArrayList arrayList = new ArrayList(Arrays.asList(COMMON_ATTRIBUTE_TAGS));
        if (Build.VERSION.SDK_INT >= 24) {
            arrayList.addAll(getAndroidMTagList());
        }
        return arrayList;
    }

    @RequiresApi(api = 24)
    @NonNull
    private static List<String> getAndroidMTagList() {
        return Arrays.asList(new String[]{ExifInterface.TAG_CUSTOM_RENDERED, ExifInterface.TAG_SCENE_CAPTURE_TYPE, ExifInterface.TAG_EXPOSURE_MODE, ExifInterface.TAG_BRIGHTNESS_VALUE, ExifInterface.TAG_CONTRAST, ExifInterface.TAG_SATURATION, ExifInterface.TAG_SHARPNESS, ExifInterface.TAG_GAIN_CONTROL, ExifInterface.TAG_ISO_SPEED_RATINGS, ExifInterface.TAG_EXPOSURE_BIAS_VALUE, ExifInterface.TAG_METERING_MODE, ExifInterface.TAG_SUBJECT_DISTANCE_RANGE, ExifInterface.TAG_DIGITAL_ZOOM_RATIO});
    }
}
