package cn.net.caoyao.cpzshandset.common.bitmap.config;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;


import android.content.Context;
import android.os.Environment;
import android.widget.Toast;

public class BitmapPathConfig {

	public static final String SDPATH = Environment
			.getExternalStorageDirectory().getPath();

	public static String date2Str(Date d, String format) { // yyyy-MM-dd
															// HH:mm:ss
		if (d == null) {
			return null;
		}
		if (format == null || format.length() == 0) {
			format = "yyyy-MM-dd HH:mm:ss";
		}
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		String s = sdf.format(d);
		return s;
	}
	public static String CREATE_USER_NAME = "admin";
	public static String getSDPath(Context context) {
		return getAppInfo(context) + "/" + CREATE_USER_NAME;
	}

	public static void CreateInitialize(Context context) {
		createSDCardDir(context);
		// createSDCardDataBase(context);
		createSDCardFile(context);
		createSDCardMeida(context);

	}

	// 创建一个对应于该帐号的文件夹
	public static void createSDCardDir(Context context) {
		if (Environment.MEDIA_MOUNTED.equals(Environment
				.getExternalStorageState())) {
			File path1 = new File(OpenCardPath(context));
			if (!path1.exists()) {
				path1.mkdirs();
			}
		} else {
			return;
		}
	}

	/**
	 * 在SD卡中创建对应于图片文件夹
	 */
	public static void createSDCardFile(Context context) {
		if (Environment.MEDIA_MOUNTED.equals(Environment
				.getExternalStorageState())) {
			File path1 = new File(OpenCardPath(context) + "/" + photographic);
			if (!path1.exists()) {
				path1.mkdirs();
			}
		} else {
			return;
		}
	}

	public static final String photographic = "Photographic"; // Picture storage
																// path
	public static final String voiceManagement = "VoiceManagement"; // Path
																	// voice
																	// file
																	// storage

	/**
	 * 在SD卡中创建对应于视频音频文件夹
	 */
	public static void createSDCardMeida(Context context) {
		if (Environment.MEDIA_MOUNTED.equals(Environment
				.getExternalStorageState())) {
			File path1 = new File(OpenCardPath(context) + "/" + voiceManagement);
			if (!path1.exists()) {
				path1.mkdirs();
			}
		} else {
			return;
		}
	}

	// 获取SD卡文件夹中的文件
	public static String getSDCardFile(Context context, String fileName) {
		return OpenCardPath(context) + "/" + photographic + "/" + fileName;
	}

	// 获取SD卡文件夹中Image文件夹路径
	public static String getSDCardFile(Context context) {
		return OpenCardPath(context) + "/" + photographic + "/";
	}
	// 获取SD卡文件夹中AWonder模式下的Image文件夹路径
	public static String getSDCardFileA(Context context) {
		return OpenCardPath(context) + "/" + photographic + "/" + photographic;
	}

	// 获取SD卡文件夹中Video文件夹路径
	public static String getSDCardVideo(Context context) {
		return OpenCardPath(context) + "/" + voiceManagement + "/";
	}

	// 判断SD卡是否存在
	public static boolean checksdCard(Context context) {
		boolean sdCardExist = Environment.getExternalStorageState().equals(
				Environment.MEDIA_MOUNTED);
		if (!sdCardExist) {
			Toast.makeText(context, "SD卡不存在，请检查SD卡！", Toast.LENGTH_SHORT)
					.show();
			return false;
		}
		return true;

	}

	// 获取包名
	public static String getAppInfo(Context context) {
		try {
			return context.getPackageName();
		} catch (Exception e) {
		}
		return null;
	}

	public static String OpenCardPath(Context context) {
		return Environment.getExternalStorageDirectory().getPath() + "/"
				+ getAppInfo(context) + "/" + CREATE_USER_NAME;
	}

}
