GithubHelp home page GithubHelp logo

atomikpanda / libcolorpicker Goto Github PK

View Code? Open in Web Editor NEW
38.0 6.0 18.0 767 KB

Color Picker Library For iOS

License: MIT License

Objective-C 47.59% Makefile 0.94% Objective-C++ 21.36% Logos 30.11%
cydia color-picker jailbreak objective-c

libcolorpicker's Introduction

libcolorpicker

The new libcolorpicker:

The new libcolorpicker PFColorAlert is focused on being lightweight, portable, and easy to use.

How to implement:

  • Search and install the latest libcolorpicker from Cydia.

  • Copy /usr/lib/libcolorpicker.dylib from your iOS device to your $THEOS/lib folder.

  • Add TWEAKNAME_LIBRARIES = colorpicker to your Tweak's Makefile if needed

  • Add TWEAKNAMEPREFS_LIBRARIES = colorpicker to your Pref's Makefile if needed

  • Download libcolorpicker.h from the root of this git and place in $THEOS/include folder.

Adding libcolorpicker into your tweak prefs bundle (Simple)

This simple method is for devs that don't need much customization.

add a new dictionary in your preference's specifier plist like this (also see example below)

** Preferences Plist Specifier Format **

		<dict>
			<key>cell</key>
			<string>PSLinkCell</string>
			<key>cellClass</key>
			<string>PFSimpleLiteColorCell</string>
			<key>libcolorpicker</key>
			<dict>
				<key>defaults</key>
				<string>YOUR PREFS PLIST IDENTIFIER</string>
				<key>key</key>
				<string>SAVE KEY</string>
				<key>fallback</key>
				<string>FALLBACK HEX COLOR</string>
				<key>PostNotification</key>
				<string>NOTIFICATION TO POST (OPTIONAL)</string>
				<key>alpha</key>
				<true/> <!-- <true/> or <false/> Show alpha slider -->
			</dict>
			<key>label</key>
			<string>COLOR TEXT LABEL</string>
		</dict>

** Example Preferences Plist**

		<dict>
			<key>cell</key>
			<string>PSLinkCell</string>
			<key>cellClass</key>
			<string>PFSimpleLiteColorCell</string>
			<key>libcolorpicker</key>
			<dict>
				<key>defaults</key>
				<string>com.baileyseymour.someawesometweak</string>
				<key>key</key>
				<string>favoriteColor</string>
				<key>fallback</key>
				<string>#ff0000</string>
				<key>alpha</key>
				<false/>
			</dict>
			<key>label</key>
			<string>Favorite Color 1</string>
		</dict>

Advanced

Showing the alert (Advanced):

this way can be used inside any application like a UIAlertView and is fully customizable.

NSString *readFromKey = @"someCoolKey"; //  (You want to load from prefs probably)
NSString *fallbackHex = @"#ff0000";  // (You want to load from prefs probably)

UIColor *startColor = LCPParseColorString(readFromKey, fallbackHex); // this color will be used at startup
PFColorAlert *alert = [PFColorAlert colorAlertWithStartColor:startColor showAlpha:YES];

// show alert and set completion callback
[alert displayWithCompletion:
	^void (UIColor *pickedColor) {
		// save pickedColor or do something with it
		NSString *hexString = [UIColor hexFromColor:pickedColor];
		hexString = [hexString stringByAppendingFormat:@":%f", pickedColor.alpha];
		// you probably want to save hexString to your prefs
		// maybe post a notification here if you need to
	}];
Reading saved color later on (From Tweak):
NSDictionary *prefsDict = ... // assuming this holds your prefs
NSString *coolColorHex = [prefsDict objectForKey:@"someCoolKey"]; // assuming that the key has a value saved like #FFFFFF:0.75423

UIColor *coolColor = LCPParseColorString(coolColorHex, @"#ff0000"); // fallback to red (#ff0000)
// do something with coolColor

Example Tweak to change UILabel text's color and shadow:

https://bitbucket.org/rob311/pflibcolorpickerexample

screen shot

The old libcolorpicker:

libcolorpicker is a iOS library that provides an easy to implement Color Picker. Here are some of it's main features:

  • iPhone & iPad Compatible
  • HSB touch color picker
  • Option to Use HSB or RGB sliders
  • Option for color transparency/opacity/alpha
  • No images or "extra components" just the library
  • Post settings changed notifications on save (Optional)
  • Enter a hex color or copy one to your clipboard
  • Made for iOS 7 & 8, Compatible with iOS 6
  • Saves colors instantly to your preferences plist
  • iPhone 3.5 inch & 4inch screen compatibility
  • Open Source

How to add libcolorpicker into your tweak:

First add a this into your Tweaks Preferences specifier plist and modify to your liking:

		<dict>
			<key>cell</key>
			<string>PSLinkCell</string>
			<key>cellClass</key>
			<string>PFColorCell</string>
			<key>label</key>
			<string>A Color</string>
			<key>color_defaults</key>
			<string>com.yourcompany.tweak</string>
			<key>color_key</key>
			<string>aColor</string>
			<key>title</key>
			<string>A Color</string>
			<key>color_fallback</key>
			<string>#10b6ec</string>
			<key>usesRGB</key>
			<false/>
			<key>usesAlpha</key>
			<true/>
			<key>color_postNotification</key>
			<string>com.yourcompany.tweak.settingschanged</string>
		</dict>

Using Version on BigBoss (Recommended)

  • Search and install libcolorpicker from Cydia.

  • Copy /usr/lib/libcolorpicker.dylib from your iOS device to your $THEOS/lib folder.

  • Add TWEAKNAME_LIBRARIES = colorpicker to your Tweak's Makefile

  • Add TWEAKNAMEPREFS_LIBRARIES = colorpicker to your Pref's Makefile

  • Next Add the following to to your Preference Bundle's PSListController @implementation

      - (void)viewWillAppear:(BOOL)animated
      {
      	[self clearCache];
      	[self reload];
      	[super viewWillAppear:animated];
      }
    

PLEASE DO NOT DO THIS :P It will result in loading different versions of libcolorpicker.

Using Custom Build

Next, Place the libcolorpicker.dylib in TweakPreferencesFolder/lib/

Next, Add the following to your Preference Bundle's Makefile:

$(shell install_name_tool -id /usr/lib/libcolorpicker_PUTTWEAKNAMEHERE.dylib lib/libcolorpicker.dylib)

TWEAKNAMEPREFERENCES_LDFLAGS = -Llib -lcolorpicker

include $(THEOS_MAKE_PATH)/bundle.mk

internal-stage::
$(ECHO_NOTHING)mkdir -p $(THEOS_STAGING_DIR)/Library/PreferenceLoader/Preferences$(ECHO_END)
$(ECHO_NOTHING)mkdir -p $(THEOS_STAGING_DIR)/usr/lib/$(ECHO_END)
$(ECHO_NOTHING)cp lib/libcolorpicker.dylib $(THEOS_STAGING_DIR)/usr/lib/libcolorpicker_PUTTWEAKNAMEHERE.dylib$(ECHO_END)

Next, Add the following to to your Preference Bundle's PSListController @implementation:

- (void)viewWillAppear:(BOOL)animated
{
	[self clearCache];
	[self reload];  
	[super viewWillAppear:animated];
}

Getting the color from the plist:

To get the color from your tweak you can use the UIColor *colorFromDefaultsWithKey(NSString *defaults, NSString *key, NSString *fallback) function found in libcolorpicker.mm

First you need to define the function in your header (.h) file: UIColor *colorFromDefaultsWithKey(NSString *defaults, NSString *key, NSString *fallback);

An example on how to use it would be: UIColor *someColor = colorFromDefaultsWithKey(@"com.example.tweak", @"someColor", @"#ffffff");

This would fallback to white (#ffffff) if the color is nil;

Example Tweak to change UILabel text's color and shadow:

https://bitbucket.org/rob311/pflibcolorpickerexample

Check out the screen shots below

iOS Simulator Screen shot Aug 27, 2014, 3.49.02 PM.pngiOS Simulator Screen shot Aug 27, 2014, 3.55.09 PM.png

License

The MIT License (MIT)

Copyright (c) 2014 PixelFireDev

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

libcolorpicker's People

Contributors

atomikpanda avatar nepeta avatar noeliel avatar nosskirneh avatar rob311fan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

libcolorpicker's Issues

safe mode

latest update is constantly kicking me into safe mode. problem began once i updated libcolorpicker. is there a way to downgrade to previous version? thanks

This is just wrong and causing headaches

This snippet of code has caused many issues since this project's inception:

- (void)setLCPOptions {
self.options = [self.specifier properties][@"libcolorpicker"];
if (!self.options)
self.options = [NSMutableDictionary dictionary];

However, I cannot blame the developers to know about the core cause of the issue because it is an odd behaviour.

The problem is that [self.specifier properties][@"libcolorpicker"] returns an NSDictionary, but the code assumes it will be an NSMutableDictionary. Here's DHowett explaining this issue on June 6 on #theos on saurik's IRC server:

06:01:30 The code in libcolorpicker is doing this:
06:01:47 1. Preferences.framework loads up your "specifier" plist, and it sees that "libcolorpicker" is required for it
06:01:59 2. Preferences gives the loaded NSDictionary from your data to libcolorpicker
06:02:13 3. libcolorpicker tried to edit the dictionary by using setObject:forKey:
06:02:21 this is _critical_. okay.
06:02:28 tries*
06:02:39 It's not allowed to do that.. like, ever. It should never change somebody else's dictionary.
06:02:58 That should always fail. They should be using "[options mutableCopy]" to make an editable copy that's disconnected from the original version
06:03:12 But here's a little quick about how property lists work in Cocoa!
06:03:24 There are three property list formats. The text one, the XML one, and the binary one.
06:03:38 FINALPACKAGE converts all your property lists into binary format. They're WAY faster to load, and a lot smaller too!
06:03:45 so it's great for a release version of the package.
06:03:54 I said "quick;" i meant "quirk"
06:04:11 Here's the quirk: XML property lists are loaded into mutable dictionaries .. and then Cocoa just lies about it and says they're NOT mutable
06:04:18 binary property lists are loaded into IMMUTABLE dictionaries
06:04:32 so when libcolorpicker tries to edit it ........ it either fails or succeeds, depending on what format the plist was in
06:05:12 so because the FINALPACKAGE=1 build rules optimized your property lists, libcolorpicker failed to edit the dictionary..
06:05:21 all because it should not have ever tried. that was their fault. they wrote bad code
06:05:26 bad code that "just worked"
06:05:31 because of a quirk. :)

The solution is to simply change:

self.options = [self.specifier properties][@"libcolorpicker"];

to this:

self.options = [[self.specifier properties][@"libcolorpicker"] mutableCopy];

Can you add a button called Paste From Pasteboard

Can you add a button called Paste From Pasteboard

So if you’ve copied a hex code online you can go to the color picker and just click paste from paste board instead of have to click then paste if that makes sense?

Color Picker instantly closes

When I try to use the color picker in the Settings app ( trying to configure Flame ), it instantly closes and won’t let me interact with it.
If I hold my finger on it, it stays there, but the background semi-transparent black goes away, and when I release, it also entirely goes away.
I tried to re-install but I can’t seem to get it working.
I am running the latest version of libcolorpicker.

Hexadecimal Button Crash

Simply put, the hexadecimal button crashes Settings. I have tested this on several tweak preferences.

I am on iOS 13.4.1 on an iPhone 6S using the latest checkra1n jailbreak.

miscellaneous bug fixes and improvements

I love this library a lot, but I heard from Readme of Alderis's repo that this library was abandoned. Sorry to hear that.
If anyone still wants to use this library. I highly recommend to statically link with my fork version.

Statically linking to your tweak, so it won't conflict with Alderis.
And my fork including miscellaneous bug fixes and improvements listed as below:

  • Using native method to read/write pref value, you can implement your own getter/setter.
  • Providing native reload interface, cell won't re-generate when reloading specifier.
  • fix a bug which cause alpha of fallback is always 1.
  • fix a bug which cause alpha is always 0 on some low version device.
  • fix building issues with specific sdk.
  • fully use arc.
  • add a script by which you can test on simulator.

If needed , I'm willing to create PRs or directly maintain this library.
Thanks, I really love this library.

Settings crash when compiled with FINALPACKAGE = 1. (iOS 13)

Crash Log:
`Date: 25/11/2019, 10:16 pm
Process: Preferences
Bundle id: com.apple.Preferences
Device: iPhone 7, iOS 13.2.2

Exception type: NSInvalidArgumentException
Reason: -[__NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance 0x280139100
Culprit: Unknown
Call stack:
0 CoreFoundation 0x00000001bcd01820 __exceptionPreprocess
1 libobjc.A.dylib 0x00000001bca29fa4 objc_exception_throw
2 CoreFoundation 0x00000001bcc0536c -[NSOrderedSet initWithSet:copyItems:]
3 CoreFoundation 0x00000001bcd05c88 forwarding
4 CoreFoundation 0x00000001bcd07a6c _CF_forwarding_prep_0
5 libcolorpicker.dylib 0x000000010ee4c3e0 LCPParseColorString
6 libcolorpicker.dylib 0x000000010ee4c568 LCPParseColorString
7 UIKitCore 0x00000001c11ea87c __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke
8 UIKitCore 0x00000001c11ea450 -[UIView(Hierarchy) _postMovedFromSuperview:]
9 UIKitCore 0x00000001c11f8d58 -[UIView(Internal) _addSubview:positioned:relativeTo:]
10 UIKitCore 0x00000001c0f1ee78 -[UITableView _addSubview:positioned:relativeTo:]
11 UIKitCore 0x00000001c119310c -[UIScrollView _addContentSubview:atBack:]
12 UIKitCore 0x00000001c0f1ebb0 -[UITableView _addContentSubview:atBack:]
13 UIKitCore 0x00000001c0f3f1a8 __53-[UITableView _configureCellForDisplay:forIndexPath:]_block_invoke
14 UIKitCore 0x00000001c11f209c +[UIView(Animation) performWithoutAnimation:]
15 UIKitCore 0x00000001c0f3e9bc -[UITableView _configureCellForDisplay:forIndexPath:]
16 UIKitCore 0x00000001c0f4fd24 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:]
17 UIKitCore 0x00000001c0f1d348 -[UITableView _updateVisibleCellsNow:]
18 UIKitCore 0x00000001c0f3a510 -[UITableView layoutSubviews]
19 UIKitCore 0x00000001c11ff604 -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
20 QuartzCore 0x00000001c374d78c -[CALayer layoutSublayers]
21 QuartzCore 0x00000001c3753908 CA::Layer::layout_if_needed(CA::Transaction*)
22 QuartzCore 0x00000001c375e528 CA::Layer::layout_and_display_if_needed(CA::Transaction*)
23 QuartzCore 0x00000001c36a6ed0 CA::Context::commit_transaction(CA::Transaction*, double)
24 QuartzCore 0x00000001c36d0bbc CA::Transaction::commit()
25 UIKitCore 0x00000001c0d9391c _afterCACommitHandler
26 CoreFoundation 0x00000001bcc7ec2c CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION
27 CoreFoundation 0x00000001bcc79b18 __CFRunLoopDoObservers
28 CoreFoundation 0x00000001bcc7a0e4 __CFRunLoopRun
29 CoreFoundation 0x00000001bcc798a0 CFRunLoopRunSpecific
30 GraphicsServices 0x00000001c6bd1328 GSEventRunModal
31 UIKitCore 0x00000001c0d6a740 UIApplicationMain
32 Preferences 0x000000010486d94c Preferences + 39244
33 libdyld.dylib 0x00000001bcb04360 start`

libcolorpicker may causes other apps to crash

Hello there, I'm a Chinese user, and I installed libcolorpicker from Bigboss in order to use Sonus12(another tweak on bigboss). However, it seems cause one app on my phone to crash,(a vocabulary app called 墨墨记单词 in AppStore). I try to remove it from Cydia, and then the app can be opened safely...
Since there is no CrashReporter tool for iOS12, I hava no i idea how to solve this issue, Can you fix it?Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.