Skip to content

Commit

Permalink
add font size selector
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisballinger committed Apr 24, 2012
1 parent 5a9a465 commit 0098cc4
Show file tree
Hide file tree
Showing 17 changed files with 274 additions and 41 deletions.
22 changes: 16 additions & 6 deletions Off the Record.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
D913A70813FCA9AB00C97C1C /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D913A70713FCA9AB00C97C1C /* QuartzCore.framework */; };
D913A70A13FCA9C200C97C1C /* ImageIO.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D913A70913FCA9C200C97C1C /* ImageIO.framework */; };
D91DAE8615473EB5009D0B74 /* OTRSettingDetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D91DAE8515473EB5009D0B74 /* OTRSettingDetailViewController.m */; };
D91DAE89154740CE009D0B74 /* OTRDoubleSettingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D91DAE88154740CE009D0B74 /* OTRDoubleSettingViewController.m */; };
D92B775514142F150058A789 /* OTREncryptionManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D92B775414142F150058A789 /* OTREncryptionManager.m */; };
D95F8E921419C3D00094A634 /* chatsecure_icon.png in Resources */ = {isa = PBXBuildFile; fileRef = D95F8E911419C3D00094A634 /* chatsecure_icon.png */; };
D95F8E941419C3E10094A634 /* chatsecure_icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = D95F8E931419C3E00094A634 /* chatsecure_icon@2x.png */; };
Expand Down Expand Up @@ -369,6 +370,8 @@
D913A70913FCA9C200C97C1C /* ImageIO.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ImageIO.framework; path = System/Library/Frameworks/ImageIO.framework; sourceTree = SDKROOT; };
D91DAE8415473EB5009D0B74 /* OTRSettingDetailViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OTRSettingDetailViewController.h; sourceTree = "<group>"; };
D91DAE8515473EB5009D0B74 /* OTRSettingDetailViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTRSettingDetailViewController.m; sourceTree = "<group>"; };
D91DAE87154740CD009D0B74 /* OTRDoubleSettingViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OTRDoubleSettingViewController.h; sourceTree = "<group>"; };
D91DAE88154740CE009D0B74 /* OTRDoubleSettingViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTRDoubleSettingViewController.m; sourceTree = "<group>"; };
D92B775314142F150058A789 /* OTREncryptionManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OTREncryptionManager.h; sourceTree = "<group>"; };
D92B775414142F150058A789 /* OTREncryptionManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTREncryptionManager.m; sourceTree = "<group>"; };
D95F8E911419C3D00094A634 /* chatsecure_icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = chatsecure_icon.png; path = ../chatsecure_icon.png; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1012,6 +1015,17 @@
path = MBProgressHUD;
sourceTree = "<group>";
};
D91DAE8A154740D5009D0B74 /* Detail Views */ = {
isa = PBXGroup;
children = (
D91DAE8415473EB5009D0B74 /* OTRSettingDetailViewController.h */,
D91DAE8515473EB5009D0B74 /* OTRSettingDetailViewController.m */,
D91DAE87154740CD009D0B74 /* OTRDoubleSettingViewController.h */,
D91DAE88154740CE009D0B74 /* OTRDoubleSettingViewController.m */,
);
name = "Detail Views";
sourceTree = "<group>";
};
D96219AC14CB765B007EF05D /* XMPPFramework */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2055,8 +2069,7 @@
children = (
D9C7463B15350F62003445ED /* OTRSettingsViewController.h */,
D9C7463C15350F62003445ED /* OTRSettingsViewController.m */,
D91DAE8415473EB5009D0B74 /* OTRSettingDetailViewController.h */,
D91DAE8515473EB5009D0B74 /* OTRSettingDetailViewController.m */,
D91DAE8A154740D5009D0B74 /* Detail Views */,
D9FBD71615472FA700126568 /* OTRSettingTableViewCell.h */,
D9FBD71715472FA700126568 /* OTRSettingTableViewCell.m */,
);
Expand Down Expand Up @@ -2488,6 +2501,7 @@
D9FBD71415472A8400126568 /* OTRDoubleSetting.m in Sources */,
D9FBD71815472FA700126568 /* OTRSettingTableViewCell.m in Sources */,
D91DAE8615473EB5009D0B74 /* OTRSettingDetailViewController.m in Sources */,
D91DAE89154740CE009D0B74 /* OTRDoubleSettingViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -2622,10 +2636,6 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Off the Record/Off the Record-Prefix.pch";
GCC_PREPROCESSOR_DEFINITIONS = (
CRITTERCISM_ENABLED,
"DEBUG=1",
);
GCC_THUMB_SUPPORT = NO;
HEADER_SEARCH_PATHS = /usr/include/libxml2;
INFOPLIST_FILE = "Off the Record/Off the Record-Info.plist";
Expand Down
2 changes: 0 additions & 2 deletions Off the Record/OTRAccountsViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
{
UITableView *accountsTableView;
OTRLoginViewController *loginController;
UIBarButtonItem *aboutButton;

BOOL isAIMloggedIn;
BOOL isXMPPloggedIn;
Expand All @@ -24,7 +23,6 @@
-(void)oscarLoggedInSuccessfully;
-(void)xmppLoggedInSuccessfully;
-(void)accountLoggedIn;
-(void)showAboutScreen;
-(void)aimLoggedOff;
-(void)xmppLoggedOff;

Expand Down
10 changes: 1 addition & 9 deletions Off the Record/OTRAccountsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#import "OTRAccountsViewController.h"
#import "OTRProtocolManager.h"
#import "OTRAboutViewController.h"
#import "Strings.h"

@implementation OTRAccountsViewController
Expand Down Expand Up @@ -52,8 +51,6 @@ - (void)viewDidLoad
self.view.backgroundColor = [UIColor whiteColor];
accountsTableView.backgroundView = nil;
accountsTableView.backgroundColor = [UIColor clearColor];
aboutButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"about_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(showAboutScreen)];
self.navigationItem.rightBarButtonItem = aboutButton;

[[NSNotificationCenter defaultCenter]
addObserver:self
Expand Down Expand Up @@ -98,6 +95,7 @@ -(void)aimLoggedOff
//[[[OTRProtocolManager sharedInstance] buddyList] removeOscarBuddies];
[accountsTableView reloadData];
}

-(void)xmppLoggedOff
{
isXMPPloggedIn = NO;
Expand All @@ -106,12 +104,6 @@ -(void)xmppLoggedOff

}

-(void)showAboutScreen
{
OTRAboutViewController *aboutController = [[OTRAboutViewController alloc] init];
[self.navigationController pushViewController:aboutController animated:YES];
}


-(void)oscarLoggedInSuccessfully
{
Expand Down
19 changes: 6 additions & 13 deletions Off the Record/OTRBuddy.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ +(OTRBuddy*)buddyWithDisplayName:(NSString*)buddyName accountName:(NSString*) ac
return newBuddy;
}

- (int) fontSize {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return 7.0;
} else {
return 5.0;
}
}


-(void)sendMessage:(NSString *)message secure:(BOOL)secure
{
Expand All @@ -81,9 +73,9 @@ -(void)sendMessage:(NSString *)message secure:(BOOL)secure
//NSLog(@"encoded message: %@",encodedMessage.message);
[OTRMessage sendMessage:encodedMessage];

NSString *username = [NSString stringWithFormat:@"<FONT SIZE=%d COLOR=\"#0000ff\"><b>Me:</b></FONT>",[self fontSize]];
NSString *username = [NSString stringWithFormat:@"<p><strong style=\"color:blue\">Me:</strong>"];

[chatHistory appendFormat:@"%@ <FONT SIZE=%d>%@</FONT><br>",username,[self fontSize], message];
[chatHistory appendFormat:@"%@ %@</p>",username, message];
}
}

Expand All @@ -92,13 +84,14 @@ -(void)receiveMessage:(NSString *)message
{
//NSLog(@"received: %@",message);
if (message) {
// Strip the shit out of it, but hoepfully you're talking with someone who is trusted in the first place
// Strip the shit out of it, but hopefully you're talking with someone who is trusted in the first place
// TODO: fix this so it doesn't break some cyrillic encodings
NSString *rawMessage = [[[[message stringByStrippingHTML]stringByConvertingHTMLToPlainText]stringByEncodingHTMLEntities] stringByLinkifyingURLs];
self.lastMessage = rawMessage;

NSString *username = [NSString stringWithFormat:@"<FONT SIZE=%d COLOR=\"#ff0000\"><b>%@:</b></FONT>",[self fontSize],self.displayName];
NSString *username = [NSString stringWithFormat:@"<p><strong style=\"color:red\">%@:</strong>",self.displayName];

[chatHistory appendFormat:@"%@ <FONT SIZE=%d>%@</FONT><br>",username,[self fontSize],rawMessage];
[chatHistory appendFormat:@"%@ %@</p>",username,rawMessage];
[[NSNotificationCenter defaultCenter] postNotificationName:MESSAGE_PROCESSED_NOTIFICATION object:self];
}
}
Expand Down
8 changes: 7 additions & 1 deletion Off the Record/OTRChatViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "privkey.h"
#import <QuartzCore/QuartzCore.h>
#import "Strings.h"
#import "OTRDoubleSetting.h"

#define kTabBarHeight 49
#define kSendButtonWidth 60
Expand Down Expand Up @@ -456,7 +457,11 @@ - (void)sendButtonPressed:(id)sender {

-(void)updateChatHistory
{
[chatHistoryTextView loadHTMLString:buddy.chatHistory baseURL:[NSURL URLWithString:@"/"]];
if (buddy.chatHistory) {
OTRDoubleSetting *fontSizeSetting = (OTRDoubleSetting*)[protocolManager.settingsManager settingForOTRSettingKey:kOTRSettingKeyFontSize];
NSString *htmlString = [NSString stringWithFormat:@"<html><head><style type=\"text/css\">p{font-size:%@;}</style></head><body>%@</body></html>",fontSizeSetting.stringValue, buddy.chatHistory];
[chatHistoryTextView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"/"]];
}
}


Expand Down Expand Up @@ -559,6 +564,7 @@ - (void) refreshView {
-(void)viewWillAppear:(BOOL)animated
{
[self refreshView];
[self updateChatHistory];
}

/*- (void)debugButton:(UIBarButtonItem *)sender
Expand Down
6 changes: 6 additions & 0 deletions Off the Record/OTRDoubleSetting.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
@interface OTRDoubleSetting : OTRValueSetting

@property (nonatomic) double doubleValue;
@property (nonatomic) double minValue;
@property (nonatomic) double maxValue;
@property (nonatomic) double defaultValue;
@property (nonatomic) BOOL isPercentage;
@property (nonatomic) NSUInteger numValues;

- (void) editValue;
- (NSString*) stringValue;

@end
37 changes: 33 additions & 4 deletions Off the Record/OTRDoubleSetting.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,59 @@
//

#import "OTRDoubleSetting.h"
#import "OTRDoubleSettingViewController.h"

@implementation OTRDoubleSetting
@synthesize doubleValue;
@synthesize doubleValue, minValue, maxValue, numValues, defaultValue, isPercentage;

- (id) initWithTitle:(NSString *)newTitle description:(NSString *)newDescription settingsKey:(NSString *)newSettingsKey
{
if (self = [super initWithTitle:newTitle description:newDescription settingsKey:newSettingsKey])
{
self.action = @selector(editValue);
self.defaultValue = 0.0;
self.isPercentage = NO;
}
return self;
}

- (void) editValue {

if(self.delegate && [self.delegate conformsToProtocol:@protocol(OTRSettingDelegate)]) {
[self.delegate otrSetting:self showDetailViewControllerClass:[OTRDoubleSettingViewController class]];
}
}

- (void) setDoubleValue:(double)value {
[self setValue:[NSNumber numberWithDouble:value]];
[self.delegate refreshView];
if(self.delegate && [self.delegate conformsToProtocol:@protocol(OTRSettingDelegate)]) {
[self.delegate refreshView];
}
}

- (double) doubleValue {
return [[self value] doubleValue];
NSNumber *value = [self value];
if (!value)
{
self.doubleValue = defaultValue;
return defaultValue;
}
else
{
return [[self value] doubleValue];
}
}

- (NSString*) stringValue {
NSString *text = nil;
if(isPercentage)
{
text = [NSString stringWithFormat:@"%d%%", (int)([self doubleValue] * 100)];
}
else
{
text = [NSString stringWithFormat:@"%.02f", [self doubleValue]];
}
return text;
}

@end
21 changes: 21 additions & 0 deletions Off the Record/OTRDoubleSettingViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// OTRDoubleSettingDetailViewController.h
// Off the Record
//
// Created by Chris Ballinger on 4/24/12.
// Copyright (c) 2012 Chris Ballinger. All rights reserved.
//

#import "OTRSettingDetailViewController.h"
#import "OTRDoubleSetting.h"

@interface OTRDoubleSettingViewController : OTRSettingDetailViewController <UIPickerViewDelegate, UIPickerViewDataSource>
{
double newValue;
}

@property (nonatomic, retain) UIPickerView *valuePicker;
@property (nonatomic, retain) UILabel *valueLabel;
@property (nonatomic, retain) OTRDoubleSetting *otrSetting;

@end
104 changes: 104 additions & 0 deletions Off the Record/OTRDoubleSettingViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//
// OTRDoubleSettingDetailViewController.m
// Off the Record
//
// Created by Chris Ballinger on 4/24/12.
// Copyright (c) 2012 Chris Ballinger. All rights reserved.
//

#import "OTRDoubleSettingViewController.h"
#import "Strings.h"

@interface OTRDoubleSettingViewController ()

@end

@implementation OTRDoubleSettingViewController
@synthesize valueLabel, valuePicker, otrSetting;

- (void) dealloc {
self.valueLabel = nil;
self.valuePicker = nil;
}

- (id) init {
if (self = [super init]) {
self.valueLabel = [[UILabel alloc] init];
self.valuePicker = [[UIPickerView alloc] init];
self.valuePicker.delegate = self;
self.valuePicker.dataSource = self;
self.title = otrSetting.title;
}
return self;
}

- (void) loadView {
[super loadView];
[self.view addSubview:valueLabel];
[self.view addSubview:valuePicker];
}

- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
valueLabel.frame = CGRectMake(0, 0, 200, 50);
valuePicker.frame = CGRectMake(0, 100, 200, 200);
newValue = otrSetting.doubleValue;
[self setTextForValueLabel];
[valuePicker selectRow:[self indexForValue:otrSetting.doubleValue]+1 inComponent:0 animated:NO];
}

- (void) save:(id)sender {
otrSetting.doubleValue = newValue;
[super save:sender];
}

- (void) setTextForValueLabel {
self.valueLabel.text = [NSString stringWithFormat:@"%@: %@\t%@: %@", OLD_STRING, [self stringForValue:otrSetting.doubleValue], NEW_STRING, [self stringForValue:newValue]];
}

- (NSString*) stringForValue:(double)value {
if (otrSetting.isPercentage) {
return [NSString stringWithFormat:@"%d%%", (int)(value * 100)];
} else {
return [NSString stringWithFormat:@"%.02f", value];
}
}

#pragma mark UIPickerViewDataSource methods

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return otrSetting.numValues + 1;
}

- (double) valueForRow:(int)row {
double range = otrSetting.maxValue - otrSetting.minValue;
double increment = range / otrSetting.numValues;
return otrSetting.minValue + (row*increment);
}

- (int) indexForValue:(double)value {
int index = (value - otrSetting.minValue) / otrSetting.numValues;
return index;
}

#pragma mark UIPickerViewDelegate methods

// tell the picker the title for a given component
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
double value = [self valueForRow:row];
return [self stringForValue:value];
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
newValue = [self valueForRow:row];
[self setTextForValueLabel];
}

@end

0 comments on commit 0098cc4

Please sign in to comment.