Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions GammaTest/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[[NSUserDefaults standardUserDefaults] registerDefaults:@{
@"enabled": @NO,
@"maxOrange": @0.7,
@"dim": @0,
@"colorChangingEnabled": @YES,
@"lastAutoChangeDate": [NSDate distantPast],
@"autoStartHour": @19,
Expand Down
1 change: 1 addition & 0 deletions GammaTest/GammaController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

+ (void)setGammaWithRed:(float)red green:(float)green blue:(float)blue;
+ (void)setGammaWithOrangeness:(float)percentOrange;
+ (void)setGammaWithOrangenessAndDim:(float)percentOrange percentDim:(float)percentDim;
+ (void)enableOrangeness;
+ (void)disableOrangeness;

Expand Down
34 changes: 33 additions & 1 deletion GammaTest/GammaController.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

@implementation GammaController

float dimCap = 0.85; //only allows you to dim to this percent to prevent completetely blacking out the screen


//This function is largely the same as the one in iomfsetgamma.c from Saurik's UIKitTools package. The license is pasted below.

/* UIKit Tools - command-line utilities for UIKit
Expand Down Expand Up @@ -162,10 +165,39 @@ + (void)setGammaWithOrangeness:(float)percentOrange {
[self setGammaWithRed:red green:green blue:blue];
}

+ (void)setGammaWithOrangenessAndDim:(float)percentOrange percentDim:(float)percentDim {
if (percentOrange > 1)
percentOrange = 1;
else if (percentOrange < 0)
percentOrange = 0;

if (percentDim > 1)
percentDim = 1;
else if (percentDim < 0)
percentDim = 0;
percentDim = 1-percentDim * dimCap;

// float red = 0.3;
// float blue = 0.3;
// float green = 0.3;

float red = (1.0);
float blue = (1 - percentOrange);
float green = (red + blue)/2.0*percentDim;
red *= percentDim;
blue *= percentDim;

if (percentOrange == 0) {
red = blue = green = 0.99*percentDim;
}

[self setGammaWithRed:red green:green blue:blue];
}

+ (void)enableOrangeness {
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
[self wakeUpScreenIfNeeded];
[GammaController setGammaWithOrangeness:[defaults floatForKey:@"maxOrange"]];
[GammaController setGammaWithOrangenessAndDim:[defaults floatForKey:@"maxOrange"] percentDim:[defaults floatForKey:@"dim"]];
[defaults setObject:[NSDate date] forKey:@"lastOnDate"];
[defaults setBool:YES forKey:@"enabled"];
}
Expand Down
21 changes: 19 additions & 2 deletions GammaTest/MainViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,22 @@ @interface MainViewController ()
@property (weak, nonatomic) IBOutlet UISwitch *colorChangingEnabledSwitch;
@property (weak, nonatomic) IBOutlet UITextField *startTimeTextField;
@property (weak, nonatomic) IBOutlet UITextField *endTimeTextField;
@property (weak, nonatomic) IBOutlet UISlider *dimSlider;

@end

@implementation MainViewController

@synthesize enabledSwitch;
@synthesize orangeSlider;
@synthesize dimSlider;
@synthesize colorChangingEnabledSwitch;
@synthesize startTimeTextField;
@synthesize endTimeTextField;

float orange;
float dim;

- (void)viewDidLoad {
[super viewDidLoad];

Expand All @@ -38,6 +43,9 @@ - (void)viewDidLoad {
self.tableView.alwaysBounceVertical = NO;
enabledSwitch.on = [defaults boolForKey:@"enabled"];
orangeSlider.value = [defaults floatForKey:@"maxOrange"];
dimSlider.value = [defaults floatForKey:@"dim"];
orange = [defaults floatForKey:@"maxOrange"];
dim = [defaults floatForKey:@"dim"];
colorChangingEnabledSwitch.on = [defaults boolForKey:@"colorChangingEnabled"];

NSDate *date = [self dateForHour:[defaults integerForKey:@"autoStartHour"] andMinute:[defaults integerForKey:@"autoStartMinute"]];
Expand All @@ -63,18 +71,27 @@ - (void)viewDidLoad {

- (IBAction)enabledSwitchChanged:(UISwitch *)sender {
if (sender.on)
[GammaController setGammaWithOrangeness:[[NSUserDefaults standardUserDefaults] floatForKey:@"maxOrange"]];
[GammaController setGammaWithOrangenessAndDim:[[NSUserDefaults standardUserDefaults] floatForKey:@"maxOrange"] percentDim:[[NSUserDefaults standardUserDefaults] floatForKey:@"dim"]];
else
[GammaController setGammaWithOrangeness:0];

[[NSUserDefaults standardUserDefaults] setBool:sender.on forKey:@"enabled"];
}


- (IBAction)maxOrangeSliderChanged:(UISlider *)sender {
[[NSUserDefaults standardUserDefaults] setFloat:sender.value forKey:@"maxOrange"];
orange = sender.value;

if (enabledSwitch.on)
[GammaController setGammaWithOrangenessAndDim:orange percentDim:dim];
}
- (IBAction)dimSliderChanged:(UISlider *)sender {
[[NSUserDefaults standardUserDefaults] setFloat:sender.value forKey:@"dim"];
dim = sender.value;

if (enabledSwitch.on)
[GammaController setGammaWithOrangeness:sender.value];
[GammaController setGammaWithOrangenessAndDim:orange percentDim:dim];
}

- (IBAction)colorChangingEnabledSwitchChanged:(UISwitch *)sender {
Expand Down
52 changes: 39 additions & 13 deletions GammaTest/Storyboard.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8191" systemVersion="15A284" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="CgH-V7-RF3">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8121.17" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="CgH-V7-RF3">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8101.14"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -39,7 +39,7 @@
<rect key="frame" x="0.0" y="99" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Zs9-8L-hUf" id="snd-z7-AzZ">
<rect key="frame" x="0.0" y="0.0" width="600" height="44"/>
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="NcL-B3-6n9">
Expand Down Expand Up @@ -75,10 +75,10 @@
<tableViewSection headerTitle="Orange-ness" id="L9A-Rq-Viz">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="7VE-VY-qs7">
<rect key="frame" x="0.0" y="193" width="600" height="44"/>
<rect key="frame" x="0.0" y="194" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="7VE-VY-qs7" id="8Wt-5u-Fxf">
<rect key="frame" x="0.0" y="0.0" width="600" height="44"/>
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.5" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="5MF-0c-fvX">
Expand All @@ -100,14 +100,39 @@
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection headerTitle="Dim percent" id="sNU-KR-FAi">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="UVK-qQ-wOk">
<rect key="frame" x="0.0" y="289" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="UVK-qQ-wOk" id="IHO-PP-ggA">
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.5" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="wsa-E7-c8L">
<rect key="frame" x="13" y="7" width="574" height="31"/>
<connections>
<action selector="dimSliderChanged:" destination="Vnk-uF-9HF" eventType="valueChanged" id="Uj4-YJ-eQa"/>
</connections>
</slider>
</subviews>
<constraints>
<constraint firstItem="wsa-E7-c8L" firstAttribute="centerY" secondItem="IHO-PP-ggA" secondAttribute="centerY" id="7Q4-CC-H2k"/>
<constraint firstItem="wsa-E7-c8L" firstAttribute="leading" secondItem="IHO-PP-ggA" secondAttribute="leadingMargin" constant="7" id="oxq-6g-OBS"/>
<constraint firstAttribute="trailingMargin" secondItem="wsa-E7-c8L" secondAttribute="trailing" constant="7" id="twU-sV-OVv"/>
</constraints>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection headerTitle="Automatic Color Changing" id="ywG-jw-Vjt">
<string key="footerTitle">Automatic color changing uses the background fetch feature to turn on or off orangeness. It doesn't happen immediately when the start or end times are passed, and won't work if background app refresh is disabled or iOS 9 low power mode is on. If your device's screen turns on randomly, that's the app making sure the screen is on before changing the color.</string>
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="99n-2q-Sjq">
<rect key="frame" x="0.0" y="287" width="600" height="44"/>
<rect key="frame" x="0.0" y="384" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="99n-2q-Sjq" id="yoE-IK-jwS">
<rect key="frame" x="0.0" y="0.0" width="600" height="44"/>
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="Of2-4s-WYp">
Expand Down Expand Up @@ -139,13 +164,13 @@
<animations/>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="N2R-yZ-Fb9">
<rect key="frame" x="0.0" y="331" width="600" height="44"/>
<rect key="frame" x="0.0" y="428" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="N2R-yZ-Fb9" id="OdI-04-Y5l">
<rect key="frame" x="0.0" y="0.0" width="600" height="43.5"/>
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Start Time" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Eq5-bo-kgF">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="Start Time" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Eq5-bo-kgF">
<rect key="frame" x="15" y="12" width="100" height="20"/>
<animations/>
<constraints>
Expand Down Expand Up @@ -177,13 +202,13 @@
<animations/>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="DS7-wR-Dzo">
<rect key="frame" x="0.0" y="375" width="600" height="44"/>
<rect key="frame" x="0.0" y="472" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="DS7-wR-Dzo" id="WlN-Pd-ofh">
<rect key="frame" x="0.0" y="0.0" width="600" height="43.5"/>
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="End Time" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="RxA-j5-K8M">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="End Time" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="RxA-j5-K8M">
<rect key="frame" x="15" y="12" width="100" height="20"/>
<animations/>
<constraints>
Expand Down Expand Up @@ -225,6 +250,7 @@
<navigationItem key="navigationItem" title="Gamma Thingy" id="0Ef-dU-b7I"/>
<connections>
<outlet property="colorChangingEnabledSwitch" destination="Of2-4s-WYp" id="XPK-Qi-z5v"/>
<outlet property="dimSlider" destination="wsa-E7-c8L" id="cQP-Qm-mg2"/>
<outlet property="enabledSwitch" destination="NcL-B3-6n9" id="DIM-Ld-znm"/>
<outlet property="endTimeTextField" destination="Jf8-p3-7EZ" id="Uah-71-Kpk"/>
<outlet property="orangeSlider" destination="5MF-0c-fvX" id="QnL-pJ-jaJ"/>
Expand Down