// Path: app/src/main/java/com/wonderful/ishow/app/App.java
// public class App extends android.app.Application {
// 	private static final String TAG = App.class.getSimpleName();
// 	private static final boolean DEBUG = BuildConfig.DEBUG;
// 
// 	public static final String PACKAGE_NAME = "com.wonderful.ishow";
// 	
// 	// Please change SIGNATURE according to your release .keystore file.
// 	private static final String SIGNATURE = "WwINm6WD6tN1Ao7juOkmWt3plow=";
// 	
// 	private ArrayList<Activity> runningActivities;
// 
// 	@Override
// 	public void onCreate() {
// 		super.onCreate();
// 
// 		if(DEBUG) {
// 			final String package_name = getApplicationContext().getPackageName();
// 			if(!PACKAGE_NAME.equals(package_name))
// 				throw new SecurityException("Cached package name doesn't match with App's package name");
// 		} else {
// 			if(!checkAppSignature(this))
// 				throw new RuntimeException("wrong signature");
// 		}
// 	}
// 
// 	private String getVersion() {
// 		try {
// 			PackageManager pm = this.getPackageManager();
// 			PackageInfo pi = pm.getPackageInfo(this.getPackageName(), PackageManager.GET_ACTIVITIES);
// 			return pi.versionName;
// 		} catch(PackageManager.NameNotFoundException e) {
// 			e.printStackTrace();
// 		}
// 		return "1.0.0";
// 	}
// 
// 	public static boolean checkAppSignature(Context context) {
// 		MessageDigest md;
// 		try {
// 			md = MessageDigest.getInstance("SHA");
// 		} catch(NoSuchAlgorithmException e) {
// 			if(DEBUG)
// 				e.printStackTrace();
// 			return false;
// 		}
// 		
// 		try {
// 			PackageManager pm = context.getPackageManager();
// 			PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);
// 			
// 			for(Signature signature : packageInfo.signatures) {
// 				md.update(signature.toByteArray());
// 				byte[] signatureBytes = md.digest();
// 				
// 				final String currentSignature = Base64.encodeToString(signatureBytes, Base64.DEFAULT);
// //				Log.d(TAG, "signature: " + currentSignature);  // show signature
// 				if(SIGNATURE.equals(currentSignature))
// 					return true;
// 			}
// 		} catch(NameNotFoundException e) {
// 			if(DEBUG)
// 				e.printStackTrace();
// 		}
// 		
// 		return false;
// 	}
// 	
// 	public static String getWorkingDirectory() {
// 		final File pictures = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
// 		File file = new File(pictures, "PerfectShow");
// 		if(!file.exists())
// 			file.mkdir();
// 		else if(file.isFile()) {
// 			Log.w(TAG, file.getPath() + " is occupied");
// 			return pictures.getPath();
// 		}
// 		
// 		return file.getPath();
// 	}
// 	
// 	public boolean isApplicationInstalled(String packageName) {
// 		try {
// 			PackageManager pm = this.getPackageManager();
// 			pm.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
// 			return true;
// 		} catch(PackageManager.NameNotFoundException e) {
// 			return false;
// 		}
// 	}
// 
// 	public void exit() {
// 		// stopService(intent);
// 		// this.finishAffinity();
// 		android.os.Process.killProcess(android.os.Process.myPid());
// //		System.exit(0);
// 	}
// }


import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory.Options;
import android.graphics.BitmapFactory;
import android.graphics.BitmapRegionDecoder;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.Build;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.util.Pair;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.view.View.MeasureSpec;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.ref.WeakReference;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import com.wonderful.ishow.app.App;
import com.wonderful.ishow.BuildConfig;
	public static void fixRectForAspectRatio(Rect rect, int aspectRatioX, int aspectRatioY) {
		if(aspectRatioX == aspectRatioY && rect.width() != rect.height()) {
			if(rect.height() > rect.width()) {
				rect.bottom -= rect.height() - rect.width();
			} else {
				rect.right -= rect.width() - rect.height();
			}
		}
	}

	/**
	 * Write the given bitmap to the given uri using the given compression.
	 */
	public static void writeBitmapToUri(Context context, Bitmap bitmap, Uri uri, Bitmap.CompressFormat compressFormat,
			int compressQuality) throws FileNotFoundException {
		OutputStream outputStream = null;
		try {
			outputStream = context.getContentResolver().openOutputStream(uri);
			bitmap.compress(compressFormat, compressQuality, outputStream);
		} finally {
			closeSafe(outputStream);
		}
	}

	// region: Private methods

	/**
	 * Decode image from uri using "inJustDecodeBounds" to get the image dimensions.
	 */
	private static BitmapFactory.Options decodeImageForOption(ContentResolver resolver, Uri uri)
// Path: app/src/main/java/com/wonderful/ishow/app/App.java
// public class App extends android.app.Application {
// 	private static final String TAG = App.class.getSimpleName();
// 	private static final boolean DEBUG = BuildConfig.DEBUG;
// 
// 	public static final String PACKAGE_NAME = "com.wonderful.ishow";
// 	
// 	// Please change SIGNATURE according to your release .keystore file.
// 	private static final String SIGNATURE = "WwINm6WD6tN1Ao7juOkmWt3plow=";
// 	
// 	private ArrayList<Activity> runningActivities;
// 
// 	@Override
// 	public void onCreate() {
// 		super.onCreate();
// 
// 		if(DEBUG) {
// 			final String package_name = getApplicationContext().getPackageName();
// 			if(!PACKAGE_NAME.equals(package_name))
// 				throw new SecurityException("Cached package name doesn't match with App's package name");
// 		} else {
// 			if(!checkAppSignature(this))
// 				throw new RuntimeException("wrong signature");
// 		}
// 	}
// 
// 	private String getVersion() {
// 		try {
// 			PackageManager pm = this.getPackageManager();
// 			PackageInfo pi = pm.getPackageInfo(this.getPackageName(), PackageManager.GET_ACTIVITIES);
// 			return pi.versionName;
// 		} catch(PackageManager.NameNotFoundException e) {
// 			e.printStackTrace();
// 		}
// 		return "1.0.0";
// 	}
// 
// 	public static boolean checkAppSignature(Context context) {
// 		MessageDigest md;
// 		try {
// 			md = MessageDigest.getInstance("SHA");
// 		} catch(NoSuchAlgorithmException e) {
// 			if(DEBUG)
// 				e.printStackTrace();
// 			return false;
// 		}
// 		
// 		try {
// 			PackageManager pm = context.getPackageManager();
// 			PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);
// 			
// 			for(Signature signature : packageInfo.signatures) {
// 				md.update(signature.toByteArray());
// 				byte[] signatureBytes = md.digest();
// 				
// 				final String currentSignature = Base64.encodeToString(signatureBytes, Base64.DEFAULT);
// //				Log.d(TAG, "signature: " + currentSignature);  // show signature
// 				if(SIGNATURE.equals(currentSignature))
// 					return true;
// 			}
// 		} catch(NameNotFoundException e) {
// 			if(DEBUG)
// 				e.printStackTrace();
// 		}
// 		
// 		return false;
// 	}
// 	
// 	public static String getWorkingDirectory() {
// 		final File pictures = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
// 		File file = new File(pictures, "PerfectShow");
// 		if(!file.exists())
// 			file.mkdir();
// 		else if(file.isFile()) {
// 			Log.w(TAG, file.getPath() + " is occupied");
// 			return pictures.getPath();
// 		}
// 		
// 		return file.getPath();
// 	}
// 	
// 	public boolean isApplicationInstalled(String packageName) {
// 		try {
// 			PackageManager pm = this.getPackageManager();
// 			pm.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
// 			return true;
// 		} catch(PackageManager.NameNotFoundException e) {
// 			return false;
// 		}
// 	}
// 
// 	public void exit() {
// 		// stopService(intent);
// 		// this.finishAffinity();
// 		android.os.Process.killProcess(android.os.Process.myPid());
// //		System.exit(0);
// 	}
// }


// Path: app/src/main/java/com/wonderful/ishow/util/BitmapUtils.java
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory.Options;
import android.graphics.BitmapFactory;
import android.graphics.BitmapRegionDecoder;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.Build;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.util.Pair;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.view.View.MeasureSpec;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.ref.WeakReference;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import com.wonderful.ishow.app.App;
import com.wonderful.ishow.BuildConfig;

	public static void fixRectForAspectRatio(Rect rect, int aspectRatioX, int aspectRatioY) {
		if(aspectRatioX == aspectRatioY && rect.width() != rect.height()) {
			if(rect.height() > rect.width()) {
				rect.bottom -= rect.height() - rect.width();
			} else {
				rect.right -= rect.width() - rect.height();
			}
		}
	}

	/**
	 * Write the given bitmap to the given uri using the given compression.
	 */
	public static void writeBitmapToUri(Context context, Bitmap bitmap, Uri uri, Bitmap.CompressFormat compressFormat,
			int compressQuality) throws FileNotFoundException {
		OutputStream outputStream = null;
		try {
			outputStream = context.getContentResolver().openOutputStream(uri);
			bitmap.compress(compressFormat, compressQuality, outputStream);
		} finally {
			closeSafe(outputStream);
		}
	}

	// region: Private methods

	/**
	 * Decode image from uri using "inJustDecodeBounds" to get the image dimensions.
	 */
	private static BitmapFactory.Options decodeImageForOption(ContentResolver resolver, Uri uri)
			throws FileNotFoundException {