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.

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