package com.usai.util;

import java.io.File;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

import com.usai.apex.ApexTrackingApplication;

import android.content.Context;
import android.os.Environment;
import android.telephony.TelephonyManager;
import android.util.Log;

public class commonUtil
{
	private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);

	
	
	public static boolean localdirExist()
	{

		File folder = new File(Environment.getExternalStorageDirectory().getPath()+"/Apex Mobile");
		return (folder.exists() && folder.isDirectory()) ? true : folder.mkdirs();
	}
	/**
	 * Generate a value suitable for use in {@link #setId(int)}.
	 * This value will not collide with ID values generated at build time by aapt for R.id.
	 *
	 * @return a generated ID value
	 */
	public static int generateViewId() {
	    for (;;) {
	        final int result = sNextGeneratedId.get();
	        // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
	        int newValue = result + 1;
	        if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
	        if (sNextGeneratedId.compareAndSet(result, newValue)) {
	            return result;
	        }
	    }
	}
	public static  String getDUID(){
		  final TelephonyManager tm = (TelephonyManager) ApexTrackingApplication.get_instance().getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);    
		  final String tmDevice, tmSerial, androidId;    
		  tmDevice = "" + tm.getDeviceId();   
		  tmSerial = "" + tm.getSimSerialNumber();    
		  androidId = "" + android.provider.Settings.Secure.getString(ApexTrackingApplication.get_instance().getContentResolver(),android.provider.Settings.Secure.ANDROID_ID);    
		  UUID deviceUuid = new UUID(androidId.hashCode(), ((long)tmDevice.hashCode() << 32) | tmSerial.hashCode());    
		  String uniqueId = deviceUuid.toString();
		  Log.d("debug","uuid="+uniqueId);
		  return uniqueId;
		 }
}
