You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
4.8KB

  1. #define kScreenWidth [[UIScreen mainScreen] bounds].size.width
  2. @interface SBTodayTableHeaderView : UIView
  3. -(NSString *)lunarDateHeaderString;
  4. @end
  5. @interface SBAnimationSettings
  6. @end
  7. @interface SBFadeAnimationSettings
  8. @property(retain, nonatomic) SBAnimationSettings *dateInSettings;
  9. @end
  10. @interface SBFLockScreenDateView : UIView
  11. @property (nonatomic, retain) UILabel *duplexCalendarLabel;
  12. @property (nonatomic, assign) NSString *todayHeaderViewText;
  13. @property bool dateHidden;
  14. -(id)_dateFont;
  15. -(id)_dateColor;
  16. -(BOOL)isDateHidden;
  17. -(void)layoutDuplexCalendarLabel;
  18. @end
  19. @interface _UILegibilityView : UIView
  20. @end
  21. @interface _UILegibilityLabel : _UILegibilityView
  22. @end
  23. extern "C" CFNotificationCenterRef CFNotificationCenterGetDistributedCenter(void);
  24. static NSString *myObserver=@"duplexcalendarObserver";
  25. static NSString *settingsPath = @"/var/mobile/Library/Preferences/com.gilshahar7.duplexcalendarprefs.plist";
  26. static NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
  27. static void savePressed(){
  28. prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
  29. }
  30. static void savePressed(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo){
  31. prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
  32. }
  33. static BOOL isLunarDateRefreshed = NO;
  34. static SBTodayTableHeaderView *stattodayHeaderView;
  35. static SBFLockScreenDateView *lockScreenDateView;
  36. static float originx = 0.0;
  37. static float originy = 0.0;
  38. static float sizewidth = 0.0;
  39. static float sizeheight = 0.0;
  40. %hook SBTodayTableHeaderView
  41. -(SBTodayTableHeaderView *)initWithFrame:(CGRect)arg1{
  42. stattodayHeaderView = %orig();
  43. return stattodayHeaderView;
  44. }
  45. -(void)_layoutLunarDateLabel{
  46. %orig;
  47. if(!isLunarDateRefreshed) {
  48. isLunarDateRefreshed = YES;
  49. [lockScreenDateView _updateLabels];
  50. lockScreenDateView = nil;
  51. }
  52. }
  53. %end
  54. %hook SBFLockScreenDateView
  55. %property (nonatomic, retain) UILabel *duplexCalendarLabel;
  56. %property (nonatomic, assign) NSString *todayHeaderViewText;
  57. -(SBFLockScreenDateView *)initWithFrame:(id)arg1{
  58. lockScreenDateView = %orig(arg1);
  59. if(!self.duplexCalendarLabel){
  60. self.duplexCalendarLabel = [[UILabel alloc] initWithFrame:CGRectMake(originx-50, originy + 19, sizewidth+100, sizeheight)];
  61. self.duplexCalendarLabel.font = [[self _dateFont] fontWithSize:16];
  62. [self addSubview:self.duplexCalendarLabel];
  63. self.duplexCalendarLabel.textColor = [self _dateColor];
  64. self.duplexCalendarLabel.textAlignment = 1;
  65. }
  66. return lockScreenDateView;
  67. }
  68. %new
  69. -(void)layoutDuplexCalendarLabel{
  70. NSString *offsetXTextField = [prefs objectForKey:@"offsetXTextField"];
  71. NSString *offsetYTextField = [prefs objectForKey:@"offsetYTextField"];
  72. NSString *FontSizeTextField = [prefs objectForKey:@"FontSizeTextField"];
  73. //if(originx <= 0.0)
  74. //{
  75. UILabel *originalLabel = MSHookIvar<UILabel *>(self, "_dateLabel");
  76. originx = originalLabel.frame.origin.x;
  77. originy = originalLabel.frame.origin.y;
  78. sizewidth = originalLabel.frame.size.width;
  79. sizeheight = originalLabel.frame.size.height;
  80. self.duplexCalendarLabel.textColor = [self _dateColor];
  81. //}
  82. [self.duplexCalendarLabel setFrame:CGRectMake(originx-50+ [offsetXTextField floatValue], originy + 19 + [offsetYTextField floatValue], sizewidth+100, sizeheight)];
  83. UIFont *font = self.duplexCalendarLabel.font;
  84. if([FontSizeTextField floatValue] == 0){
  85. self.duplexCalendarLabel.font = [font fontWithSize:16.0];
  86. }else{
  87. self.duplexCalendarLabel.font = [font fontWithSize:[FontSizeTextField floatValue]];
  88. }
  89. }
  90. -(void)_updateLabels{
  91. %orig;
  92. [self layoutDuplexCalendarLabel];
  93. //if(!self.todayHeaderViewText){
  94. self.todayHeaderViewText = [stattodayHeaderView lunarDateHeaderString];
  95. //}
  96. self.duplexCalendarLabel.text = self.todayHeaderViewText;
  97. }
  98. -(void)_layoutDateLabel {
  99. %orig;
  100. [self layoutDuplexCalendarLabel];
  101. _UILegibilityLabel *originalLegibilityLabel = MSHookIvar<_UILegibilityLabel *>(self, "_legibilityDateLabel");
  102. [originalLegibilityLabel setFrame:CGRectMake(originx, originy - 3, sizewidth, sizeheight)];
  103. }
  104. -(void)updateFormat{
  105. %orig;
  106. [self layoutDuplexCalendarLabel];
  107. }
  108. -(void)layoutSubviews {
  109. %orig;
  110. [self layoutDuplexCalendarLabel];
  111. }
  112. -(void)_setDateAlpha:(double)arg1{
  113. %orig(arg1);
  114. if(self.duplexCalendarLabel){
  115. UILabel *originalLabel = MSHookIvar<UILabel *>(self, "_dateLabel");
  116. self.duplexCalendarLabel.alpha = originalLabel.alpha;
  117. }
  118. }
  119. %end
  120. %hook SBFadeAnimationSettings
  121. - (void)setDefaultValues {
  122. %orig;
  123. self.dateInSettings = nil;
  124. }
  125. %end
  126. %ctor{
  127. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
  128. (void*)myObserver,
  129. savePressed,
  130. CFSTR("duplexcalendar.savepressed"),
  131. NULL,
  132. CFNotificationSuspensionBehaviorDeliverImmediately);
  133. savePressed();
  134. }