package com.app.paintingstool.myuntils;

import android.app.Application;
import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.Range;
import android.view.MotionEvent;
import android.view.WindowManager;

import androidx.camera.core.Camera;

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

public class Keys extends Application {
    public static final String tatab="favorite_images";
    public static final int ababa=1;
    public static String Class_Animals = "png_Animals";
    public static String Class_birds = "png_Birds";
    public static String Class_butterfly = "png_Butterfly";
    public static String Class_cafe = "png_Cafe";
    public static String Class_cartoons = "png_Cartoons";
    public static String Class_christmas = "png_Christmas";
    public static String Class_festivals = "png_Festivals";
    public static String Class_flowers = "png_Flowers";
    public static String Class_fruits = "png_Fruits";
    public static String Class_general = "png_General";
    public static String Class_mehndi = "png_Mehndi";
    public static String Class_nature = "png_Nature";
    public static String Class_properties = "png_Properties";
    public static String Class_rangoli = "png_Rangoli";
    public static String Class_sports = "png_Sports";
    public static String Class_vehicles = "png_Vehicles";

    public static List<String> getAllDir() {
        ArrayList<String> list = new ArrayList<>();
        list.add(Class_Animals);
        list.add(Class_birds);
        list.add(Class_butterfly);
        list.add(Class_cafe);
        list.add(Class_cartoons);
        list.add(Class_christmas);
        list.add(Class_festivals);
        list.add(Class_flowers);
        list.add(Class_fruits);
        list.add(Class_general);
        list.add(Class_mehndi);
        list.add(Class_nature);
        list.add(Class_properties);
        list.add(Class_rangoli);
        list.add(Class_sports);
        list.add(Class_vehicles);
        return list;

    }

    public static List<String> fileExistsInAssets(Context context, String dir) {

        List<String> pathList = new ArrayList<String>();
        try {
            AssetManager assetManager = context.getAssets();
            String[] files = assetManager.list(dir);
            if (files != null) {
                for (String name : files) {
                    pathList.add(dir + "/" + name);
                }
                return pathList;
            }
        } catch (IOException e) {

            return pathList;
        }
        return pathList;
    }
    public static Bitmap loadImageFromAssets(Context context, String fileName) {
        Bitmap bitmap = null;
        AssetManager assetManager = context.getAssets();
        try (InputStream is = assetManager.open(fileName)) {
            bitmap = BitmapFactory.decodeStream(is);
        } catch (IOException e) {
            return bitmap;
        }
        return bitmap;
    }
    public static float getDistance(MotionEvent event) {
        float x = event.getX(0) - event.getX(1);
        float y = event.getY(0) - event.getY(1);
        return (float) Math.sqrt(x * x + y * y);
    }
    public static Point getScreen(Context context) {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        windowManager.getDefaultDisplay().getMetrics(displayMetrics);
        int width = displayMetrics.widthPixels;
        int height = displayMetrics.heightPixels;
        Point point = new Point();
        point.x = width;
        point.y = height;
        return point;
    }

    public static int getRange(Camera camera) {
        Range<Integer> exposureCompensationRange = camera.getCameraInfo().getExposureState().getExposureCompensationRange();
        Integer upper = exposureCompensationRange.getUpper();
        Integer lower = exposureCompensationRange.getLower();
        return upper;
    }

}
