public class UserApi extends AbsOpenApi {
	/**
	 * user vertification
	 */
	private static final String USER_VERIFICATION = "/v1/users/verification";
	/**
	 * user register
	 */
	private static final String USER_REGISTER = "/v1/users/registration";
	
	/**
	 * user login
	 */
	private static final String USER_LOGIN = "/v1/users/authentication";
	
	/**
	 * user reset password
	 */
	private static final String USER_RESET_PWD = "/v1/users/reset";
	
	/**
	 * user change password
	 */
	private static final String USER_CHANGE_PWD = "/v1/users/password";
	
	/**
	 * user logout
	 */
	private static final String USER_LOGOUT = "/v1/users/logout";

    /**
     * user vertify(/v1/users/verification)
     * send vertification code to mobile or email.
     * @param context
     * @param productKey
     * @param vendorKey
     * @param mobile
     * @param mail
     * @param responseHandler
     */
	public static void verification(Context context, String productKey,String vendorKey,
                   String mobile, String mail, AsyncHttpResponseHandler responseHandler) {
		List<Header> headerList = new ArrayList<Header>();
        if (!TextUtils.isEmpty(productKey)) {
            headerList.add(new BasicHeader(ApiKey.HeadKey.PRODUCT_KEY, productKey));
        }
		if (!TextUtils.isEmpty(vendorKey)) {
            headerList.add(new BasicHeader(ApiKey.HeadKey.VENDOR_KEY, vendorKey));
        }
		try {
//			String jsonParams = new JSONStringer().object()
//						.key(ApiKey.MOBILE).value(mobile)
//						.endObject().toString();
            String jsonParams = "";
            JSONStringer jsonStringer = new JSONStringer().object();
            if (!TextUtils.isEmpty(mobile)) {
                jsonStringer.key(ApiKey.MOBILE).value(mobile);
            } else {
                jsonStringer.key(ApiKey.MAIL).value(mail);
            }
            jsonParams = jsonStringer.endObject().toString();
			if (DEBUG) {
				LogUtils.d(jsonParams);
			}
			post(context, getApiServerUrl() + USER_VERIFICATION, headerList, jsonParams, responseHandler);
		} catch (JSONException e) {
			e.printStackTrace();
			responseHandler.onFailure(INNER_ERROR_CODE, null, null, e);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			responseHandler.onFailure(INNER_ERROR_CODE, null, null, e);
		}
		
	}

    /**
     * user register(/v1/users/registration)
     * register with phone number
     * @param context
     * @param productKey
     * @param vendorKey
     * @param mobile
     * @param password
     * @param verification
     * @param responseHandler
     */
	public static void mobileRegister(Context context, String productKey, String vendorKey,
                   String mobile, String password, String verification, AsyncHttpResponseHandler responseHandler) {
		List<Header> headerList = new ArrayList<Header>();
        if (!TextUtils.isEmpty(productKey)) {
            headerList.add(new BasicHeader(ApiKey.HeadKey.PRODUCT_KEY, productKey));
        }
        if (!TextUtils.isEmpty(vendorKey)) {
            headerList.add(new BasicHeader(ApiKey.HeadKey.VENDOR_KEY, vendorKey));
        }
		try {
			String jsonParams = new JSONStringer()
							.object()
							.key(ApiKey.MOBILE).value(mobile)
							.key(ApiKey.PASSWORD).value(password)
							.key(ApiKey.VERTIFICATION).value(verification)
							.endObject().toString();
			if (DEBUG) {
				LogUtils.d(jsonParams);
			}
			post(context, getApiServerUrl() + USER_REGISTER, headerList, jsonParams, responseHandler);
		} catch (JSONException e) {
			e.printStackTrace();
			responseHandler.onFailure(INNER_ERROR_CODE, null, null, e);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			responseHandler.onFailure(INNER_ERROR_CODE, null, null, e);
		}
		
	}

    /**
     *  user register(/v1/users/registration)
     * register with email
     * @param context
     * @param productKey
     * @param vendorKey
     * @param mail
     * @param password
     * @param responseHandler
     */
    public static void mailRegister(Context context, String productKey, String vendorKey, String mail,
                          String password,  AsyncHttpResponseHandler responseHandler) {
        List<Header> headerList = new ArrayList<Header>();
        if (!TextUtils.isEmpty(productKey)) {
            headerList.add(new BasicHeader(ApiKey.HeadKey.PRODUCT_KEY, productKey));
        }
        if (!TextUtils.isEmpty(vendorKey)) {
            headerList.add(new BasicHeader(ApiKey.HeadKey.VENDOR_KEY, vendorKey));
        }
        try {
            String jsonParams = new JSONStringer()
                    .object()
                    .key(ApiKey.MAIL).value(mail)
                    .key(ApiKey.PASSWORD).value(password)
                    .endObject().toString();
            if (DEBUG) {
                LogUtils.d(jsonParams);
            }
            post(context, getApiServerUrl() + USER_REGISTER, headerList, jsonParams, responseHandler);
        } catch (JSONException e) {
            e.printStackTrace();
            responseHandler.onFailure(INNER_ERROR_CODE, null, null, e);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            responseHandler.onFailure(INNER_ERROR_CODE, null, null, e);
        }
    }

    /**
     * user login(/v1/users/authentication)
     * user login with phone number or email.
     * @param context
     * @param productKey
     * @param vendorKey
     * @param mobile
     * @param password
     * @param responseHandler
     */
	public static void login(Context context, String productKey, String vendorKey, String mobile,
                          String mail, String password, AsyncHttpResponseHandler responseHandler) {
		List<Header> headerList = new ArrayList<Header>();
        if (!TextUtils.isEmpty(productKey)) {
            headerList.add(new BasicHeader(ApiKey.HeadKey.PRODUCT_KEY, productKey));
        }
        if (!TextUtils.isEmpty(vendorKey)) {
            headerList.add(new BasicHeader(ApiKey.HeadKey.VENDOR_KEY, vendorKey));
        }
		try {
			String jsonParams = "";
            JSONStringer jsonStringer = new JSONStringer().object();
            if (!TextUtils.isEmpty(mobile)) {
                jsonStringer.key(ApiKey.MOBILE).value(mobile);
            } else {
                jsonStringer.key(ApiKey.MAIL).value(mail);
            }
            jsonStringer.key(ApiKey.PASSWORD).value(password);
			jsonParams = jsonStringer.endObject().toString();
			if (DEBUG) {
				LogUtils.d(jsonParams);
			}
			post(context, getApiServerUrl() + USER_LOGIN, headerList, jsonParams, responseHandler);
		} catch (JSONException e) {
			e.printStackTrace();
			responseHandler.onFailure(INNER_ERROR_CODE, null, null, e);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			responseHandler.onFailure(INNER_ERROR_CODE, null, null, e);
		}
	}


    /**
     * user logout (/v1/users/logout)
     * @param context
     * @param accessToken
     * @param responseHandler
     */
    public static void logout(Context context, String accessToken, AsyncHttpResponseHandler responseHandler) {
        List<Header> headerList = new ArrayList<Header>();
        headerList.add(new BasicHeader(ApiKey.HeadKey.ACCESS_TOKEN, accessToken));
        try {
            post(context, getApiServerUrl() + USER_LOGOUT, headerList, null, responseHandler);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            responseHandler.onFailure(INNER_ERROR_CODE, null, null, e);
        }
    }

    /**
     * user reset password(/v1/users/reset)
     * @param context
     * @param productKey
     * @param vendorKey
     * @param mobile
     * @param mail
     * @param password
     * @param verification
     * @param responseHandler
     */
	public static void reset(Context context, String productKey, String vendorKey, String mobile,
            String mail, String password, String verification, AsyncHttpResponseHandler responseHandler) {
		List<Header> headerList = new ArrayList<Header>();
        if (!TextUtils.isEmpty(productKey)) {
            headerList.add(new BasicHeader(ApiKey.HeadKey.PRODUCT_KEY, productKey));
        }
        if (!TextUtils.isEmpty(vendorKey)) {
            headerList.add(new BasicHeader(ApiKey.HeadKey.VENDOR_KEY, vendorKey));
        }
		try {
			String jsonParams = "";
            JSONStringer jsonStringer = new JSONStringer().object();
            if (!TextUtils.isEmpty(mobile)) {
                jsonStringer.key(ApiKey.MOBILE).value(mobile);
            } else {
                jsonStringer.key(ApiKey.MAIL).value(mail);
            }
			jsonParams = jsonStringer
                    .key(ApiKey.PASSWORD)
                    .value(password)
                    .key(ApiKey.VERTIFICATION).value(verification)
					.endObject().toString();
			if (DEBUG) {
				LogUtils.d(jsonParams);
			}
			post(context, getApiServerUrl() + USER_RESET_PWD, headerList, jsonParams, responseHandler);
		} catch (JSONException e) {
			e.printStackTrace();
			responseHandler.onFailure(INNER_ERROR_CODE, null, null, e);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			responseHandler.onFailure(INNER_ERROR_CODE, null, null, e);
		}
	}


	/**
	 * user change password（/v1/users/password）
	 * <p>Method: put</p>
	 * @param context
	 * @param accessToken
	 * @param mobile
	 * @param password
	 * @param newPassword
	 * @param responseHandler
	 */
	public static void changePassword(Context context, String accessToken, String mobile,
			String password, String newPassword, AsyncHttpResponseHandler responseHandler) {
		List<Header> headerList = new ArrayList<Header>();
		headerList.add(new BasicHeader(ApiKey.HeadKey.ACCESS_TOKEN, accessToken));
		try {
			String jsonParams = new JSONStringer()
							.object()
							.key(ApiKey.MOBILE).value(mobile)
							.key(ApiKey.PASSWORD).value(password)
							.key(ApiKey.NEW_PASSWORD).value(newPassword)
							.endObject().toString();
			if (DEBUG) {
				LogUtils.d(jsonParams);
			}
			put(context, getApiServerUrl() + USER_CHANGE_PWD, headerList, jsonParams, responseHandler);
		} catch (JSONException e) {
			e.printStackTrace();
			responseHandler.onFailure(INNER_ERROR_CODE, null, null, e);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			responseHandler.onFailure(INNER_ERROR_CODE, null, null, e);
		}
	}

} public abstract class WrapperBaseJsonHttpResponseHandler<T extends BaseResponse> extends
		BaseJsonHttpResponseHandler<T> {
	private Activity context;
	
	public WrapperBaseJsonHttpResponseHandler(Activity context) {
		this.context = context;
	}
	
	@Override
	public void onFailure(int statusCode, Header[] headers,
			Throwable throwable, String rawJsonData, T errorResponse) {
		handlerFailedToast(context, statusCode, throwable);
	}

	@Override
	public void onSuccess(int statusCode, Header[] headers, String rawJsonData, T response) {
		if (!response.isSuccess()) {
			int code = response.code;
			CommonUtils.ToastMsg(context, ErrorCodeHelper.getInstances(context).getErrorMessage(code));
			BusinessUtils.checkTokenAvailable(context, code);
		}
	}

	@Override
	protected T parseResponse(String rawJsonData, boolean isFailure) throws Throwable {
		return parseResponse2(rawJsonData, isFailure);
	}
	
	protected abstract T parseResponse2(String rawJsonData, boolean isFailure) throws Throwable;
	
	
	public static void handlerFailedToast(Context context, int statusCode, Throwable throwable) {
		if (!NetworkUtil.isNetworkAvailable(context) || statusCode == 0) {
			CommonUtils.ToastMsg(context, context.getString(R.string.http_error_message));
		} else {
			if (statusCode >= 500) {
				CommonUtils.ToastMsg(context, context.getString(R.string.http_server_error));
			} else {
				if (throwable != null) {
					CommonUtils.ToastMsg(context, throwable.getMessage());
				}
			}
		}
	}
} public class AppConstants {
	
	public static final String VENDOR_KEY = "570f93557db3532727b54336e47f1a3500b3c0e564";
	
    //FreeIOT
    public static final String PRODUCT_KEY = "f07fd3f2782ff4964b74d51e89ad0aabf0192ec066";
}
 public class UserState {
	
	private static final String USER_PREFS_NAME = "pando_user_prefs";
	
	private SharedPreferences mPrefs;
	
	private String accessToken;
	
	private static UserState sInstances;
	
	private void init(Context context) {
		if (mPrefs == null) {
			mPrefs = context.getApplicationContext()
					.getSharedPreferences(USER_PREFS_NAME, Context.MODE_MULTI_PROCESS);
		}
	}
	
	private UserState(Context context) {
		init(context);
	}
	
	public static UserState getInstances(Context context) {
		if (sInstances == null) {
			synchronized (UserState.class) {
				if (sInstances == null) {
					sInstances = new UserState(context);
				}
			}
		}
		return sInstances;
	}
	
	public void saveAccessToken(String value) {
		this.accessToken = value;
		mPrefs.edit().putString("accessToken", value).commit();
	}
	
	public String getAccessToken(String defValue) {
		if (TextUtils.isEmpty(accessToken)) {
			accessToken = mPrefs.getString("accessToken", defValue);
		}
		return accessToken;
	}
	
	public boolean isLogin() {
		return getAccessToken(null) != null;
	}
	
	public void logout(Context context) {
		accessToken = null;
		mPrefs.edit().clear().commit();
		ProductInfoPrefs.getInstances(context).clear();
//		DeviceState.getInstances(context).clear();
	}
	
	public void clear() {
		mPrefs.edit().clear().commit();
	}
	
	public void putString(String key, String value) {
		mPrefs.edit().putString(key, value).commit();
	}
	
	public String getString(String key, String defValue) {
		return mPrefs.getString(key, defValue);
	}
	
	public void putInt(String key, int value) {
		mPrefs.edit().putInt(key, value).commit();
	}
	
	public int getInt(String key, int defValue) {
		return mPrefs.getInt(key, defValue);
	}
	
	public void putBoolean(String key, boolean value) {
		mPrefs.edit().putBoolean(key, value).commit();
	}
	
	public boolean getBoolean(String key, boolean defValue) {
		return mPrefs.getBoolean(key, defValue);
	}
	
	private SharedPreferences getSharedPreferences() {
		return mPrefs;
	}
	
	public static class Builder {
		
		private SharedPreferences.Editor mEditor;
		
		public Builder(Context context) {
			if (mEditor == null) {
				mEditor = UserState.getInstances(context).getSharedPreferences().edit();
			}
		}
		
		public Builder saveString(String key, String value) {
			mEditor.putString(key, value);
			return this;
		}
		
		public Builder saveLong(String key, long value) {
			mEditor.putLong(key, value);
			return this;
		}
		
		public Builder saveInt(String key, int value) {
			mEditor.putInt(key, value);
			return this;
		}
		
		public void commit(){
			mEditor.commit();
		}
	}

} public class BaseActivity extends FragmentActivity {


    @Override
    public void onBackPressed() {
        super.onBackPressed();
        ActivityUtils.animFinish(this, R.anim.slide_in_from_left, R.anim.slide_out_to_right);
    }
}
 public class BaseResponse {
    public static final int CODE_SUCCESS = 0;

    public int code;

    public String message;

    public boolean isSuccess() {
        return code == CODE_SUCCESS;
    }
} public class UserRegisterResponse extends BaseResponse {
	
	public UserRegisterResponseData data;
	
	public class UserRegisterResponseData {
		
		public String access_token;
	
	}
} public class ActivityUtils {
    
    public static final int REQUEST_CODE_INVALID = -1;
    
    public static void start(Fragment fragment, Class<?> cls) {
        start(null, fragment, cls, null, REQUEST_CODE_INVALID, 0, 0);
    }
    
    public static void start(Fragment fragment, Class<?> cls, Bundle extras) {
        start(null, fragment, cls, extras, REQUEST_CODE_INVALID, 0, 0);
    }
    
    public static void start(Fragment fragment, Class<?> cls, int req_code) {
        start(null, fragment, cls, null, req_code, 0, 0);
    }
    
    public static void start(Fragment fragment, Class<?> cls, Bundle extras, int req_code) {
        start(null, fragment, cls, extras, req_code, 0, 0);
    }
    
    public static void start(Activity activity, Class<?> cls) {
        start(activity, null, cls, null, REQUEST_CODE_INVALID, 0, 0);
    }
    
    public static void start(Activity activity, Class<?> cls, Bundle extras) {
        start(activity, null, cls, extras, REQUEST_CODE_INVALID, 0, 0);
    }
    
    public static void start(Activity activity, Class<?> cls, int req_code) {
        start(activity, null, cls, null, req_code, 0, 0);
    }
    
    public static void start(Activity activity, Class<?> cls, Bundle extras, int req_code) {
        start(activity, null, cls, extras, req_code, 0, 0);
    }
    
    public static void start(Activity activity, Class<?> cls, int enterAnim, int exitAnim) {
        start(activity, null, cls, null, REQUEST_CODE_INVALID, enterAnim, exitAnim);
    }
    
    public static void start(Activity activity, Class<?> cls, Bundle extras, int enterAnim, int exitAnim) {
        start(activity, null, cls, extras, REQUEST_CODE_INVALID, enterAnim, exitAnim);
    }
    
    public static void start(Activity activity, Class<?> cls, int req_code, int enterAnim, int exitAnim) {
        start(activity, null, cls, null, req_code, enterAnim, exitAnim);
    }
    
    public static void start(Activity activity, Class<?> cls, Bundle extras, int req_code, int enterAnim, int exitAnim) {
        start(activity, null, cls, extras, req_code, enterAnim, exitAnim);
    }
    
    public static void start(Activity activity, Fragment fragment, Class<?> cls, Bundle extras, int req_code,
            int enterAnim, int exitAnim) {
        if (null != activity) {
            Intent intent = new Intent(activity, cls);
            if (null != extras) {
                intent.putExtras(extras);
            }
            
            if (REQUEST_CODE_INVALID == req_code) {
                activity.startActivity(intent);
            } else {
                activity.startActivityForResult(intent, req_code);
            }
            
            if (0 != enterAnim || 0 != exitAnim) {
                activity.overridePendingTransition(enterAnim, exitAnim);
            }
        } else if (null != fragment) {
            activity = fragment.getActivity();
            
            if (null != activity) {
                Intent intent = new Intent(activity, cls);
                if (null != extras) {
                    intent.putExtras(extras);
                }
                if (REQUEST_CODE_INVALID == req_code) {
                    fragment.startActivity(intent);
                } else {
                    fragment.startActivityForResult(intent, req_code);
                }
                
                if (0 != enterAnim || 0 != exitAnim) {
                    activity.overridePendingTransition(enterAnim, exitAnim);
                }
            }
        }
    }
    
    public static void animFinish(Activity activity, int enterAnim, int exitAnim) {
    	if (activity == null) {
			return;
		}
    	activity.finish();
    	activity.overridePendingTransition(enterAnim, exitAnim);
    }
}
 public class AnalyticsUtils {
	
	public static void init() {
		
		MobclickAgent.setDebugMode(false);
		
		MobclickAgent.openActivityDurationTrack(false);
	}
	
	public static final class AnalyticsViewKeys {
		
		public static final String VIEW_SPLASH_ACTIVITY = "Splash";
		
		public static final String VIEW_MAIN_ACTIIVTY = "Main";
		
		public static final String VIEW_REGISTER_ACTIVITY = "Register";

        public static final String VIEW_EMAIL_REGISTER_ACTIVITY = "EmailRegister";
		
		public static final String VIEW_RESET_PWD_ACTIVITY = "ResetPassword";

        public static final String VIEW_EMAIL_RESET_PWD_ACTIVITY = "EmailResetPassword";
		
		public static final String VIEW_LOGIN_ACTIVITY = "Login";

        public static final String VIEW_EMAIL_LOGIN_ACTIVITY = "EmailLogin";
		
		public static final String VIEW_GATEWAY_CONFIG_ACTIVITY = "GatewayConfigActivity";
		
		public static final String VIEW_APCONNECT_FGMENT = "ApConnect";
		
		public static final String VIEW_APSSID_CONFIG_FGMENT = "ApSsidConfig";
		
		public static final String VIEW_DEVICE_CONTROL_ACTIVITY = "DeviceControl";
		
		public static final String VIEW_DEVICE_AUTH_ACTIVITY = "DeviceAuth";
	}
	
	public static final class AnalyticsEventKeys {
		
		/**
		 * vertification code click event
		 */
		public static final String EVENT_VERTIFY = "vertify";


		public static final String EVENT_RESET_PWD_VERTIFY = "reset_password_vertify";
		
		/**
		 * register click
		 */
		public static final String EVENT_REGISTER = "register";

        /**
         * reset password click event
         */
		public static final String EVENT_RESET_PWD = "reset_password";
		
		/**
		 * login click event
		 */
		public static final String EVENT_LOGIN = "login";
		
		/**
		 * add device click event
		 */
		public static final String EVENT_ADD_DEVICE = "add_device";
		
		/**
		 * exit config click event
		 */
		public static final String EVENT_EXIT_CONFIG = "exit_config";
		
		/**
		 * complete device online config event
		 */
		public static final String EVENT_APCONFIG = "apconfig";
		
		/**
		 * device auth click event
		 */
		public static final String EVENT_DEVICE_AUTH = "device_auth";
	}
} public class CommonUtils {
	
	private static Dialog mProgressDialog;
	
	private static Toast mToast;
	
	private static boolean needExit = false;
	
	public static void ToastMsg(Context context, String msg) {
		if (context == null || TextUtils.isEmpty(msg)) {
			return;
		}
		if (mToast != null) {
			mToast.cancel();
			mToast = null;
		}
		mToast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
		mToast.show();
	}
	
	
	public static void ToastMsg(Context context, int resourceId) {
		if (context == null) {
			return;
		}
		if (mToast != null) {
			mToast.cancel();
			mToast = null;
		}
		mToast = Toast.makeText(context, resourceId, Toast.LENGTH_SHORT);
		mToast.show();
	}

	public static void ToastMsg(final Activity activity, final String msg) {
		if (activity == null || TextUtils.isEmpty(msg)) {
			return;
		}
		activity.runOnUiThread(new Runnable() {
			
			@Override
			public void run() {
				if (mToast != null) {
					mToast.cancel();
					mToast = null;
				}
				mToast = Toast.makeText(activity, msg, Toast.LENGTH_SHORT);
				mToast.show();
			}
		});
	}
	
	public static final void setNeedExit(Boolean exit) {
		needExit = exit;
	}
	
	public static final boolean getNeedExit() {
		return needExit;
	}
	
	public static final void showProgressDialog(Context context, String title,
			String message, OnDismissListener onDismissListener) {
		if (context == null) {
			return;
		}
		dismissDialog();
		if (TextUtils.isEmpty(title)) {
			title = "";
		}
		if (TextUtils.isEmpty(message)) {
			message = context.getString(R.string.loading);
		}
		mProgressDialog = ProgressDialog.show(context, title, message);
		mProgressDialog.setCancelable(true);
		mProgressDialog.setCanceledOnTouchOutside(false);
		mProgressDialog.setOnDismissListener(onDismissListener);
	}

	public static final void showProgressDialog(Context context, String title,
			String message) {
		showProgressDialog(context, title, message, null);
	}
	
	public static boolean showingProgressDialog() {
		if (mProgressDialog != null && mProgressDialog.isShowing()) {
			return true;
		}
		return false;
	}
	
	public static final void dismissDialog() {
		if (mProgressDialog != null) {
			mProgressDialog.dismiss();
			mProgressDialog = null;
		}
	}
}
 public class GsonUtils {
	
	private static GsonUtils sInstance;
	
	public static GsonUtils getInstance() {
		if (sInstance == null) {
			sInstance = new GsonUtils();
		}
		return sInstance;
	}
	
	private Gson mGson;
	
	private GsonUtils() {
//		mGson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation()
//				.enableComplexMapKeySerialization()
//				.create();
		mGson = new Gson();
	}
	
	public String toJson(Object object) {
		return mGson.toJson(object);
	}
	
	public Gson getGson() {
		return mGson;
	}
}
 public class LogUtils {
	public static final int VERBOSE = 0x0001;
	public static final int DEBUG = 0x0002;
	public static final int INFO = 0x0004;
	public static final int WARN = 0x0008;
	public static final int ERROR = 0x0010;
	
	public static final int LEVEL_RELEASE = 0x0000;

	public static final int LEVEL_TEST = VERBOSE | DEBUG | INFO | WARN | ERROR;
	
	private static int LEVEL = LEVEL_TEST;//上线时改成LEVEL_RELEASE
	
	private static final String TAG = "PANDO_LOG";
	
	public static final void setLevel(int level) {
		LEVEL = level;
	}
	
	private static boolean check(int level) {
		if ((LEVEL & level) > 0) {
			return true;
		}
		return false;
	}
	
	public static void v(String text) {
		if (check(VERBOSE)) android.util.Log.v(TAG, text);
	}
	
	public static void v(String tag, String text) {
		if (check(VERBOSE)) android.util.Log.v(tag, text);
	}
	
	public static void d(String text) {
		if (check(DEBUG)) android.util.Log.d(TAG, text);
	}

	public static void d(String text, Throwable tr) {
		if (check(DEBUG)) android.util.Log.d(TAG, text, tr);
	}
	
	public static void d(String tag, String text) {
		if (check(DEBUG)) android.util.Log.d(tag, text);
	}

	public static void d(String tag, String text, Throwable tr) {
		if (check(DEBUG)) android.util.Log.d(tag, text, tr);
	}

	public static void i(String text) {
		if (check(INFO)) android.util.Log.i(TAG, text);
	}

	public static void i(String text, Throwable tr) {
		if (check(INFO)) android.util.Log.i(TAG, text, tr);
	}

	public static void i(String tag, String text) {
		if (check(INFO)) android.util.Log.i(tag, text);
	}
	
	public static void i(String tag, String text, Throwable tr) {
		if (check(INFO)) android.util.Log.i(tag, text, tr);
	}
	
	public static void w(String text) {
		if (check(WARN)) android.util.Log.w(TAG, text);
	}
	
	public static void w(String text, Throwable tr) {
		if (check(WARN)) android.util.Log.w(TAG, text, tr);
	}
	
	public static void w(String tag, String text) {
		if (check(WARN)) android.util.Log.w(tag, text);
	}
	
	public static void w(String tag, String text, Throwable tr) {
		if (check(WARN)) android.util.Log.w(tag, text, tr);
	}
	
	public static void e(String text) {
		if (check(ERROR)) android.util.Log.e(TAG, text);
	}
	
	public static void e(Throwable e) {
		e(getStringFromThrowable(e));
	}
	
	public static void e(Throwable e, String message) {
		e(message +"\n" + getStringFromThrowable(e));
	}
	
	public static void e(String text, Throwable tr) {
		if (check(ERROR)) android.util.Log.e(TAG, text, tr);
	}
	
	public static void e(String tag, String text) {
		if (check(ERROR)) android.util.Log.e(tag, text);
	}
	
	public static void e(String tag, String text, Throwable tr) {
		if (check(ERROR)) android.util.Log.e(tag, text, tr);
	}

    public static String getStackTraceString(Throwable tr) {
        return android.util.Log.getStackTraceString(tr);
    }

    public static int println(int priority, String tag, String msg) {
        return android.util.Log.println(priority, tag, msg);
    }
    
    public static String getStringFromThrowable(Throwable e) {
		StringWriter sw = new StringWriter();
	    PrintWriter pw = new PrintWriter(sw);
	    e.printStackTrace(pw);
	    return sw.toString();
	}
    
    public static void e(String tag, byte[] data) {
    	if (data == null) {
			return;
		}
    	StringBuffer sBuffer = new StringBuffer();
		for (int i = 0; i< data.length; i++) {
			sBuffer.append(Integer.toHexString(data[i])).append(" ");
		}
		LogUtils.e("body length: " + sBuffer.toString());
    }
}

import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import com.pandocloud.freeiot.R;
import com.pandocloud.freeiot.api.UserApi;
import com.pandocloud.freeiot.api.WrapperBaseJsonHttpResponseHandler;
import com.pandocloud.freeiot.ui.app.AppConstants;
import com.pandocloud.freeiot.ui.app.UserState;
import com.pandocloud.freeiot.ui.base.BaseActivity;
import com.pandocloud.freeiot.ui.bean.http.BaseResponse;
import com.pandocloud.freeiot.ui.bean.http.UserRegisterResponse;
import com.pandocloud.freeiot.utils.ActivityUtils;
import com.pandocloud.freeiot.utils.AnalyticsUtils;
import com.pandocloud.freeiot.utils.CommonUtils;
import com.pandocloud.freeiot.utils.GsonUtils;
import com.pandocloud.freeiot.utils.LogUtils;
import com.umeng.analytics.MobclickAgent;
import org.apache.http.Header;
import java.util.Timer;
import java.util.TimerTask;
package com.pandocloud.freeiot.ui.login;





/**
 * Created by ywen on 15/5/20.
 */
public class EmailResetPwdActivity extends BaseActivity implements View.OnClickListener {

    private EditText mEmailEditView;

    private EditText mAuthCodeEditView;

    private EditText mPasswordEditView;

    private Timer mTimer;

    private int mDexTime = 60;

    private TextView mAuthCodeEidtView;

    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler() {
        public void handleMessage(android.os.Message msg) {
            mDexTime--;
            if (mDexTime <=0) {
                mAuthCodeEidtView.setEnabled(true);
                mAuthCodeEidtView.setText(R.string.get_authcode);
            } else {
                mAuthCodeEidtView.setText(getString(R.string.reget_authcode, mDexTime));
            }
        };
    };

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);

        setContentView(R.layout.activity_email_reset_pwd);

        mEmailEditView = (EditText)findViewById(R.id.email);
        mAuthCodeEditView = (EditText)findViewById(R.id.authcode);
        mPasswordEditView = (EditText)findViewById(R.id.pwd);

        mAuthCodeEidtView = (TextView) findViewById(R.id.authcode_btn);
        mAuthCodeEidtView.setOnClickListener(this);
        findViewById(R.id.reset_btn).setOnClickListener(this);
        findViewById(R.id.back).setOnClickListener(this);
    }

    public void userVertify() {
        String email = mEmailEditView.getText().toString().trim();
        if (TextUtils.isEmpty(email)) {
            CommonUtils.ToastMsg(this, R.string.error_email_empty);