// Path: app/src/main/java/org/xdty/gallery/model/Config.java
// public class Config {
// 
//     public final static String SAMBA_SERVER = "samba_server";
//     public final static String SAMBA_FOLDER = "samba_folder";
//     public final static String SAMBA_USERNAME = "samba_username";
//     public final static String SAMBA_PASSWORD = "samba_password";
//     public final static String ROTATE_TYPE = "rotate_type";
//     public final static String VIEWPAGER_EFFECT = "viewpager_effect";
//     public final static String GRID_EFFECT = "grid_effect";
//     public final static String GRID_EFFECT_DURATION = "grid_effect_duration";
//     public final static String LOCAL_SORT_TYPE = "local_sort_type";
//     public final static String NETWORK_SORT_TYPE = "network_sort_type";
//     public final static String FILE_EXPLORER_MODE = "file_explorer_mode";
//     public final static String SHOW_HIDING_FILES = "show_hiding_files";
//     public final static String REVERSE_LOCAL_SORT = "reverse_local_sort";
//     public final static String REVERSE_NETWORK_SORT = "reverse_network_sort";
// 
//     public final static String thumbnailDir = "thumbnails";
//     public final static String ROOT_PATH = "root://";
// 
//     public final static String SERVERS = "servers";
// 
//     public final static int MAX_IMAGE_SIZE = 2048;
//     public final static int IMAGE_SIMPLE_SIZE = 2;
//     public final static int IMAGE_THUMBNAIL_SIMPLE_SIZE = 2;
// }


import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.preference.PreferenceManager;
import android.util.TypedValue;
import android.webkit.MimeTypeMap;
import org.xdty.gallery.R;
import org.xdty.gallery.model.Config;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(inputStream, null, options);

        // Calculate inSampleSize
        //options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
        options.inSampleSize = calculateLessInSampleSize(options, reqWidth, reqHeight);
        //options.inSampleSize = Config.IMAGE_THUMBNAIL_SIMPLE_SIZE;

        // Decode bitmap with inSampleSize set
        options.inJustDecodeBounds = false;
        options.inPreferredConfig = Bitmap.Config.RGB_565;
        return BitmapFactory.decodeStream(inputStream, null, options);
    }

    public static int calculateInSampleSize(
            BitmapFactory.Options options, int reqWidth, int reqHeight) {
        // Raw height and width of image
        final int height = options.outHeight;
        final int width = options.outWidth;
        int inSampleSize = 1;

        if (height > reqHeight || width > reqWidth) {

            final int halfHeight = height / 2;
            final int halfWidth = width / 2;

            // Calculate the largest inSampleSize value that is a power of 2 and keeps both
            // height and width larger than the requested height and width.
            while ((halfHeight / inSampleSize) > reqHeight
                    && (halfWidth / inSampleSize) > reqWidth) {
// Path: app/src/main/java/org/xdty/gallery/model/Config.java
// public class Config {
// 
//     public final static String SAMBA_SERVER = "samba_server";
//     public final static String SAMBA_FOLDER = "samba_folder";
//     public final static String SAMBA_USERNAME = "samba_username";
//     public final static String SAMBA_PASSWORD = "samba_password";
//     public final static String ROTATE_TYPE = "rotate_type";
//     public final static String VIEWPAGER_EFFECT = "viewpager_effect";
//     public final static String GRID_EFFECT = "grid_effect";
//     public final static String GRID_EFFECT_DURATION = "grid_effect_duration";
//     public final static String LOCAL_SORT_TYPE = "local_sort_type";
//     public final static String NETWORK_SORT_TYPE = "network_sort_type";
//     public final static String FILE_EXPLORER_MODE = "file_explorer_mode";
//     public final static String SHOW_HIDING_FILES = "show_hiding_files";
//     public final static String REVERSE_LOCAL_SORT = "reverse_local_sort";
//     public final static String REVERSE_NETWORK_SORT = "reverse_network_sort";
// 
//     public final static String thumbnailDir = "thumbnails";
//     public final static String ROOT_PATH = "root://";
// 
//     public final static String SERVERS = "servers";
// 
//     public final static int MAX_IMAGE_SIZE = 2048;
//     public final static int IMAGE_SIMPLE_SIZE = 2;
//     public final static int IMAGE_THUMBNAIL_SIMPLE_SIZE = 2;
// }


// Path: app/src/main/java/org/xdty/gallery/utils/Utils.java
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.preference.PreferenceManager;
import android.util.TypedValue;
import android.webkit.MimeTypeMap;
import org.xdty.gallery.R;
import org.xdty.gallery.model.Config;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

        options.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(inputStream, null, options);

        // Calculate inSampleSize
        //options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
        options.inSampleSize = calculateLessInSampleSize(options, reqWidth, reqHeight);
        //options.inSampleSize = Config.IMAGE_THUMBNAIL_SIMPLE_SIZE;

        // Decode bitmap with inSampleSize set
        options.inJustDecodeBounds = false;
        options.inPreferredConfig = Bitmap.Config.RGB_565;
        return BitmapFactory.decodeStream(inputStream, null, options);
    }

    public static int calculateInSampleSize(
            BitmapFactory.Options options, int reqWidth, int reqHeight) {
        // Raw height and width of image
        final int height = options.outHeight;
        final int width = options.outWidth;
        int inSampleSize = 1;

        if (height > reqHeight || width > reqWidth) {

            final int halfHeight = height / 2;
            final int halfWidth = width / 2;

            // Calculate the largest inSampleSize value that is a power of 2 and keeps both
            // height and width larger than the requested height and width.
            while ((halfHeight / inSampleSize) > reqHeight
                    && (halfWidth / inSampleSize) > reqWidth) {
                inSampleSize *= 2;