//
//  Utils.h
//  UPayProject
//
//  Created by 张建伟 on 15/1/6.
//  Copyright (c) 2015年 张建伟. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <MBProgressHUD/MBProgressHUD.h>
#import <CoreLocation/CoreLocation.h>
#import "FileUtils.h"
#import "AFNetworking.h"
#import "Reachability.h"
//#import "UserGroupEntity.h"
//#import "UserGroupObject.h"
#define kAudioType_AMR @"amr"
#define kAudioType_WAV @"wav"

/**
 *  工具类
 */
@interface Utils : NSObject<MBProgressHUDDelegate>
+(id)ifNullToNil:(id)objc;

+ (NSDictionary *)DeviceInfo;
+ (NSString*)DeviceModel;
+(UIBarButtonItem*)createRightbarbutton:(NSString*)title target:(id)target sel:(SEL)sel;

+(UIBarButtonItem*)createRightbarbuttonWithIcon:(NSString*)imageName target:(id)target sel:(SEL)sel;

+(NSString*) uuid;

//+(void)addBack2Navigationitem:(UINavigationItem*)item sel:(SEL)sel  res:(id)res;
#pragma mark  - - if isMobileNumber and Email kill
//+ (BOOL)isMobileNumber:(NSString *)mobileNum;
//+ (BOOL)isValidEmail:(NSString*)email;

/*
 创建一个新的透明的view  并将他添加到 FootView
 */
+(void)setExtraCellLineHidden: (UITableView *)tableView;
/*
 等比缩放图片
 */
+ (UIImage *)scaleImage:(UIImage *)image toScale:(float)scaleSize;

/**
 *  缩放到指定大小图片（省内存）
 *
 *  @param img  <#img description#>
 *  @param size <#size description#>
 *
 *  @return <#return value description#>
 */
+ (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size;

/*
 通过颜色创建image
 */
+ (UIImage *)creatImageWithPureColor:(UIColor *)color;

//返回高度一致,不变形的图片.
+ (UIImage *)scaleRigthSizeImageWithTargetView:(UIView *)targetView origionlImage:(UIImage *)origionalImage;
/**
 *  根据文字计算长度
 *
 *  @return size
 */
+ (CGSize)getSizeFromText:(NSString *)text maxWidth:(CGFloat)maxWidth withFloatFont:(float)floatFont;

+(NSString *)avatarPath;
//+(NSString *)avatarPathWithUserID:(NSString *)userID;

//登录页面根据上次记住的用户名头像获取
+(NSString *)avatarPathWithLoginName:(NSString *)loginname;
//读取用户头像图片
+(void)loadUserAvatar:(UIImageView *)headerImageView imageUrl:(NSString*) imageUrl;
////从缓存中获取自己的头像
//+(void)loadMyAvatar:(UIImageView *)headerImageView;

/**
 *  解析pc图文混编消息
 *
 *  @param expression  正则表达式
 *  @param content     原始内容
 *  @param resultBlock array content
 */
+ (void)getPCScreenPhotoAndTextWithExpression:(NSString *)expression content:(NSString *)content resultBlock:(void(^)(NSArray *subData))resultBlock;

+(NSData*)getScaledPhotoData:(UIImage*) theImage;

/**
 *  查询addrbook获取用户默认头像，如果没有则创建
 *
 *  @param uuid 唯一识别号，serverid+loginname
 *
 *  @return image
 */
+ (UIImage *)getDefaultAvatarWithUserUUID:(NSString *)uuid isOffLine:(BOOL)isoffline;

/**
 *  根据已知view生成image
 *
 *  @param view <#view description#>
 *
 *  @return <#return value description#>
 */
+ (UIImage *) imageWithView:(UIView *)view;
/**
 *  根据群获取群头像
 *
 *  @param group UserGroupEntity
 *
 *  @return uiimage
 */
//+ (UIImage *)getGroupHeaderImageWithGroup:(UserGroupEntity *)group;
//+ (UIImage *)getGroupHeaderImageWithGroupWithObject:(UserGroupObject *)group;
//
//+ (UIImageView *)getGroupHeaderImageViewWithGroupWithObject:(UserGroupObject *)group;
/**
 *  net work status check
 *
 *  @param success_block yes
 *  @param fail_block    no
 */
+ (void) netWorkType:(void(^)(AFNetworkReachabilityStatus status))success_block fail:(void(^)())fail_block;

/**
 *  系统级判断是否有网络
 *
 *  @return yes/no
 */
+ (BOOL)isEnableNetWork;
/**
 *  MBHUDView show
 */

/**
 *  根据文件名返回对应的图标
 *
 *  @param fileName xx.yy
 *
 *  @return 图标名
 */
+ (NSString *)getIconWithFileName:(NSString *)fileName;


+ (void)showSuccessToView:(UIView *)view;
+ (void)showFailureToView:(UIView *)view;
+ (void)showError:(NSString *)error ToView:(UIView *)view;
+ (void)showWaitingToView:(UIView *)view;
+ (void)showWaitingWithMessage:(NSString *)message ToView:(UIView *)view;
+ (void)HiddenWaitingToView:(UIView *)view;
+ (void)showError:(NSString *)error toView:(UIView *)view finish:(void(^)())block;
+ (void)showSuccess:(NSString *)success toView:(UIView *)view finish:(void(^)())block;
/**
 *  重新排序数组
 *
 *  @param orinalArray 原始数组
 *  @param fromIndex   原地址
 *  @param toIndex     目标地址
 *
 *  @return 排序后数组
 */
+ (NSMutableArray *)sortArray:(NSMutableArray *)orinalArray FromIndex:(NSUInteger)fromIndex ToIndex:(NSUInteger)toIndex;
@end
