std.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. //
  2. // std.h
  3. // IOSDuoduo
  4. //
  5. // Created by 东邪 on 14-5-23.
  6. // Copyright (c) 2014年 dujia. All rights reserved.
  7. //
  8. /**
  9. * 系统字体调整
  10. */
  11. typedef enum{
  12. FontTypeChooseLarger = 1,
  13. FontTypeChooseSmail = 0//默认为小字体
  14. }FontTypeChoose;
  15. #import <Foundation/Foundation.h>
  16. //#import "XLog.h"
  17. #import "Utils.h"
  18. #import "MD5.h"
  19. #import "SettingUserDefaultKey.h"
  20. #import "GlobalData.h"
  21. #import "HostConfig.h"
  22. #import "NSString+Additions.h"
  23. #import "CoreDataSelectStatusModel.h"
  24. #import "GeneralSetting.h"
  25. #define USERDEFAULT_APP_NAME (@"USERDEFAULT_APP_NAME")
  26. #define USERDEFAULT_USER_NAME (@"USERDEFAULT_USER_NAME")
  27. #define USERDEFAULT_LOGIN_NAME (@"USERDEFAULT_LOGIN_NAME")
  28. #define USERDEFAULT_USER_ID (@"USERDEFAULT_USER_ID")
  29. #define USERDEFAULT_PASSWORD (@"USERDEFAULT_PASSWORD")
  30. #define USERDEFAULT_SERVER_ID (@"USERDEFAULT_SERVER_ID")
  31. #define USERDEFAULT_APP_TOKEN (@"USERDEFAULT_APP_TOKEN")
  32. #define USERDEFAULT_ROOT_NAME (@"USERDEFAULT_ROOT_NAME")
  33. //联系人VC 单位 全市(服务端 rootName) 通讯录
  34. #define ROOT_NAME [userDefaults objectForKey:USERDEFAULT_ROOT_NAME]
  35. #define USERDEFAULT_REMBER_LOGIN_NAME (@"USERDEFAULT_REMBER_LOGIN_NAME")
  36. //
  37. #define USERDEFAULT_NEW_VERSION (@"USERDEFAULT_NEW_VERSION")
  38. //#define APP_NAME (@"办公微助手")
  39. #define APP_NAME [userDefaults objectForKey:USERDEFAULT_APP_NAME]
  40. #define DEFAULT_AVATAR ([UIImage imageNamed:@"avatar"])
  41. #define TICK NSDate *startTime = [NSDate date];
  42. #define TOCK NSLog(@"Time: %f ms", -[startTime timeIntervalSinceNow] * 1000);
  43. #define objectOrNull(obj) ((obj) ? (obj) : [NSNull null])
  44. #define objectOrEmptyStr(obj) ((obj) ? (obj) : @"")
  45. #define isNull(x) (!x || [x isKindOfClass:[NSNull class]])
  46. #define toInt(x) (isNull(x) ? 0 : [x intValue])
  47. #define isEmptyString(x) (isNull(x) || [x isEqual:@""] || [x isEqual:@"(null)"])
  48. #define sleep(s); [NSThread sleepForTimeInterval:s];
  49. #define Syn(x) @synthesize x = _##x
  50. #define LineForDrawColor [UIColor lightGrayColor]
  51. #define LineForSubLineViewColor RGB(214, 215, 217)
  52. #define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
  53. #define RGB(r,g,b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0]
  54. #define SahreColorRGB(r,g,b) [UIColor colorWithRed:r green:g blue:b alpha:1.000]
  55. #define BoldSystemFont(size) [UIFont boldSystemFontOfSize:size]
  56. #define systemFont(size) [UIFont systemFontOfSize:size]
  57. #define beginAutoPool NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; {
  58. #define endAutoPool } [pool release];
  59. #define skipspace(c) while (isspace(*c)) ++c
  60. #define skipUntil(c,x) while (x != *c) ++c
  61. #define TheWindowHeight ([UIDevice isAfterOS7] ? [UIScreen mainScreen].bounds.size.height : ([UIScreen mainScreen].bounds.size.height - 20))
  62. #define IntToNumber(int) ([NSNumber numberWithInt:int])
  63. #define isIOS7 [[UIDevice currentDevice].systemVersion doubleValue]>=7.0?YES:NO
  64. #define isIOS8 [[UIDevice currentDevice].systemVersion doubleValue]>=8.0?YES:NO
  65. #define SYSTEM_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
  66. #define STATUSBAR_HEIGHT [[UIApplication sharedApplication] statusBarFrame].size.height
  67. #define NAVBAR_HEIGHT ((SYSTEM_VERSION >= 7) ? 44 : 20)
  68. #define FULL_WIDTH SCREEN_WIDTH
  69. #define FULL_HEIGHT (SCREEN_HEIGHT - ((SYSTEM_VERSION >= 7) ? 0 : STATUSBAR_HEIGHT))
  70. #define CONTENT_HEIGHT (FULL_HEIGHT - NAVBAR_HEIGHT)
  71. // 屏幕高度
  72. #define SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height
  73. // 屏幕宽度
  74. #define SCREEN_WIDTH [[UIScreen mainScreen] bounds].size.width
  75. //([[NSString documentPath] stringByAppendingPathComponent:@"/PhotosMessageDir/"])
  76. #define IPHONE4 ( [ [ UIScreen mainScreen ] bounds ].size.height == 480 )
  77. //字体颜色
  78. #define GRAYCOLOR RGB(137, 139, 144)
  79. #define FileManager ([NSFileManager defaultManager])
  80. #define TheUserDefaults ([NSUserDefaults standardUserDefaults])
  81. #define VoiceMessageDir ([[NSString documentPath] stringByAppendingPathComponent:@"/VoiceMessageDir/"])
  82. #define BlacklistDir ([[NSString documentPath] stringByAppendingPathComponent:@"/BlacklistDir/"])
  83. #define Departmentlist ([[NSString documentPath] stringByAppendingPathComponent:@"/department.plist"])
  84. #define fixedlist ([[NSString documentPath] stringByAppendingPathComponent:@"/fixed.plist"])
  85. #define shieldinglist ([[NSString documentPath] stringByAppendingPathComponent:@"/shieldingArray.plist"])
  86. #define TheBundleVerison (bundleVerison())
  87. #undef AS_SINGLETON
  88. #define AS_SINGLETON( __class ) \
  89. + (__class *)sharedInstance;
  90. #undef DEF_SINGLETON
  91. #define DEF_SINGLETON( __class ) \
  92. + (__class *)sharedInstance \
  93. { \
  94. static dispatch_once_t once; \
  95. static __class * __singleton__; \
  96. dispatch_once( &once, ^{ __singleton__ = [[__class alloc] init]; } ); \
  97. return __singleton__; \
  98. }
  99. #define userDefaults [NSUserDefaults standardUserDefaults]
  100. #define Server_ID [userDefaults objectForKey:USERDEFAULT_SERVER_ID]
  101. //#define FontTypeUserDetaultKey @"FontTypeUserDetaultKey"
  102. //#define FontTypeUserDetaultValue [userDefaults objectForKey:FontTypeUserDetaultKey]
  103. //#define SetFontTypeUserDefault(FontTypeChoose) [userDefaults setObject:@(FontTypeChoose) forKey:FontTypeUserDetaultKey]
  104. /**
  105. * 动态返回字体Font
  106. *
  107. * @param LargeFont 大字体
  108. * @param SmailFont 小字体
  109. *
  110. * @return 最终Font
  111. */
  112. //#define FontType(LargeFloatFont,SmailFloatFont) [FontTypeUserDetaultValue intValue] == FontTypeChooseLarger?[UIFont systemFontOfSize:LargeFloatFont]:[UIFont systemFontOfSize:SmailFloatFont]
  113. #define FontType(LargeFloatFont,SmailFloatFont) [GeneralSetting returnGeneralSetting].appFontModel.intValue == FontTypeChooseLarger?[UIFont systemFontOfSize:LargeFloatFont]:[UIFont systemFontOfSize:SmailFloatFont]
  114. //#define FontTypeWithFontName(FontName,LargeFloatFont,SmailFloatFont) [FontTypeUserDetaultValue intValue] == FontTypeChooseLarger?[UIFont fontWithName:FontName size:LargeFloatFont]:[UIFont fontWithName:FontName size:SmailFloatFont]
  115. #define FontTypeWithFontName(FontName,LargeFloatFont,SmailFloatFont) [GeneralSetting returnGeneralSetting].appFontModel.intValue == FontTypeChooseLarger?[UIFont fontWithName:FontName size:LargeFloatFont]:[UIFont fontWithName:FontName size:SmailFloatFont]
  116. //User_Name格式 : serverId-loginName
  117. #define User_Name [userDefaults objectForKey:USERDEFAULT_USER_NAME]
  118. #define Login_Word [userDefaults objectForKey: USERDEFAULT_PASSWORD]
  119. #define User_ID [userDefaults objectForKey:USERDEFAULT_USER_ID]
  120. #define Login_Name [userDefaults objectForKey:USERDEFAULT_LOGIN_NAME]
  121. #define SESSION_ID(serverId, loginName) [NSString stringWithFormat:@"%@-%@",serverId,loginName]
  122. //获取服务器编号和+,如0578+
  123. #define ContentServerID(userdefault_serverId) [NSString stringWithFormat:@"%@+",[userDefaults objectForKey:userdefault_serverId]]
  124. #define GET_LOGIN_NAME [userDefaults objectForKey:USERDEFAULT_REMBER_LOGIN_NAME]
  125. /**
  126. * 文件相关的绝对路径.
  127. */
  128. #define FileAbsoluteSaveRouter [NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/%@/%@",@"Library",Login_Name]]
  129. #define CloudStorageFullRouter [NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/%@/%@/%@",@"Library",Login_Name,@"cloudstorage"]]
  130. #define FileFolderFullRouter [NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/%@/%@/%@",@"Library",Login_Name,@"file"]]
  131. #define VoiceFolderFullRouter [NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/%@/%@/%@",@"Library",Login_Name,@"voice"]]
  132. #define PhotosMessageDir [NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/%@/%@/%@",@"Library",Login_Name,@"photo"]]
  133. /**
  134. * 检查字典中是否有该key
  135. *
  136. * @param A 字典
  137. * @param B key
  138. *
  139. * @return 字典A中是否包含key为B的内容
  140. */
  141. #define CheckDictionaryKey(A,B) ((!!A)&&(![A isKindOfClass:[NSNull class]])&&A.count>0&&[A.allKeys containsObject:B]&&(![[A objectForKey:B] isKindOfClass:[NSNull class]]))
  142. #define DateStringFromDictionary(DIC,KEY) ([Utils getDateFromString:[DIC objectForKey:KEY]])
  143. #define DateFromSecDic(DIC,KEY) ([Utils getDateFromNumber:[DIC objectForKey:KEY]])
  144. //通过key 从字典中获取对象
  145. #define Dictionary2Object(DIC,KEY,OBJ) if (CheckDictionaryKey(DIC, KEY)) { \
  146. OBJ = [DIC objectForKey:KEY];\
  147. }
  148. #define Dictionary2TimeObject(DIC,KEY,OBJ) if (CheckDictionaryKey(DIC, KEY)) { \
  149. if ([[DIC objectForKey:KEY ] isKindOfClass:[NSString class]]) {\
  150. OBJ = DateStringFromDictionary(DIC, KEY);\
  151. }else{\
  152. OBJ = DateFromSecDic(DIC, KEY);\
  153. }\
  154. }
  155. #define CURRENT_VERSION [[NSBundle mainBundle]objectForInfoDictionaryKey:@"CFBundleVersion"]
  156. //AppDelegate
  157. #define APPDELEGATE (AppDelegate*)[[UIApplication sharedApplication] delegate]
  158. @protocol DDShareObjDelegate <NSObject>
  159. - (NSString*)shareTypeName;
  160. @end
  161. char pinyinFirstLetter(unsigned short hanzi);
  162. char getFirstChar(const NSString * str);