Guest User

ColorFlow v1.2.1 Developer Support

a guest
Jan 5th, 2015
1,828
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3. As of v1.1.0, ColorFlow has Lockscreen support. It will by default colorize the NowPlaying UI and some of the Lockscreen elements.
  4. However, it will most likely not colorize UI elements added by other tweaks.
  5.  
  6. If you're a developer, you can add ColorFlow LS support to your tweak. ColorFlow will post notifications when colorizing the UI:
  7. - @"ColorFlowLockScreenColorReversionNotification" : posted when the UI controls should revert to normal
  8. - @"ColorFlowLockScreenColorizationNotification" : posted when UI controls should colorize, containing the following keys
  9.    + @"BackgroundColor" : UIColor *
  10.    + @"PrimaryColor" : UIColor *
  11.    + @"SecondaryColor" : UIColor *
  12.    + @"IsBackgroundDark" : NSNumber * (with boolValue)
  13.  
  14. Thus, you can just register for these notifications within the SpringBoard process (to [NSNotificationCenter defaultCenter]). Some example code is below. Depending on the lifetime of your objects, elements themselves should register for these notifications, or you should have an ever present ColorManager which manages the proper colors (needed if your objects can be created/destroyed between notifications) - this is because repeated reversion/colorize notifications are not sent (once reversion is called, it will not be called again until after a colorize; once a colorize for a song is called, it will not be called again until the album artwork changes).
  15.  
  16. As of v1.2.1, ColorFlow has an API for music tweaks as well. It will post notifications inside the Music app process:
  17. - @"ColorFlowMusicAppColorReversionNotification" : posted when the UI controls should revert to normal
  18. - @"ColorFlowMusicAppColorizationNotification" : posted when UI controls should colorize, containing the following keys
  19.    + @"BackgroundColor" : UIColor *
  20.    + @"PrimaryColor" : UIColor *
  21.    + @"SecondaryColor" : UIColor *
  22.    + @"IsBackgroundDark" : NSNumber * (with boolValue)
  23.  
  24. Below is some sample code.
  25. */
  26.  
  27. - (instancetype)init {
  28.     self = [super init];
  29.     if (self) {
  30.         // Do your init...
  31.         [[NSNotificationCenter defaultCenter] addObserver:self
  32.                                                  selector:@selector(revertUI:)
  33.                                                      name:@"ColorFlowLockScreenColorReversionNotification"
  34.                                                    object:nil];
  35.         [[NSNotificationCenter defaultCenter] addObserver:self
  36.                                                  selector:@selector(colorizeUI:)
  37.                                                      name:@"ColorFlowLockScreenColorizationNotification"
  38.                                                    object:nil];
  39.     }
  40.     return self;
  41. }
  42.  
  43. - (void)revertUI:(NSNotification *)notification {
  44.     /* Revert your UI colors. i.e.
  45.         self.tintColor = [UIColor whiteColor];
  46.     */
  47. }
  48.  
  49. - (void)colorizeUI:(NSNotification *)notification {
  50.     NSDictionary *userInfo = [notification userInfo];
  51.     UIColor *backgroundColor = userInfo[@"BackgroundColor"];
  52.     UIColor *primaryColor = userInfo[@"PrimaryColor"];
  53.     UIColor *secondaryColor = userInfo[@"SecondaryColor"];
  54.     BOOL isBackgroundDark = [userInfo[@"IsBackgroundDark"] boolValue];
  55.     /* Colorize your UI colors. i.e.
  56.         self.tintColor = primary;
  57.     */
  58. }
  59.  
  60. - (void)dealloc {
  61.     [[NSNotificationCenter defaultCenter] removeObserver:self];
  62.     [super dealloc];
  63. }
Advertisement
Add Comment
Please, Sign In to add comment