-
Notifications
You must be signed in to change notification settings - Fork 12
/
SMFClockController.m
107 lines (94 loc) · 2.52 KB
/
SMFClockController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// SMFClockController.m
// SMFramework
//
// Created by Thomas Cool on 10/31/10.
// Copyright 2010 tomcool.org. All rights reserved.
//
#import "SMFClockController.h"
@implementation SMFClockController
@synthesize textAttributes;
-(id)init
{
self=[super init];
_timer = [[NSTimer scheduledTimerWithTimeInterval:5
target:self
selector:@selector(timerRun)
userInfo:nil
repeats:YES] retain];
_formatter = [[NSDateFormatter alloc]init];
[_formatter setTimeStyle:NSDateFormatterShortStyle];
[_formatter setDateStyle:NSDateFormatterShortStyle];
[self setTextAttributes:[[BRThemeInfo sharedTheme] menuItemTextAttributes]];
[self setText:[_formatter stringFromDate:[NSDate date]]
withAttributes:[[BRThemeInfo sharedTheme]menuTitleTextAttributes]];
[self setTimeZone:[NSTimeZone timeZoneWithName:@"America/Chicago"]];
[self setCurrentlocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]autorelease]];
return self;
}
-(void)setColor:(UIColor *)c
{
[color release];
color=c;
[color retain];
}
-(void)setCurrentlocale:(NSLocale *)l
{
[_currentlocale release];
_currentlocale=nil;
_currentlocale = [l retain];
[_formatter setLocale:l];
}
-(NSLocale *)currentlocale
{
return _currentlocale;
}
-(void)setTimeZone:(NSTimeZone *)tz
{
[timeZone release];
timeZone=nil;
timeZone=[tz retain];
[_formatter setTimeZone:timeZone];
}
-(NSTimeZone *)timeZone
{
return timeZone;
}
-(void)timerRun
{
BRController *tc= [[[BRApplicationStackManager singleton] stack] peekController];
BOOL done=FALSE;
BRControl *c=self;
while (done == FALSE) {
c=[c parent];
if ([c isKindOfClass:[BRController class]]) {
done = TRUE;
}
if (c==nil) {
done = TRUE;
}
}
if (c!=nil)
{
if (tc==c) {
[self setText:[_formatter stringFromDate:[NSDate date]]
withAttributes:[[BRThemeInfo sharedTheme]menuTitleTextAttributes]];
}
// NSLog(@"timer run: %@ %@,parent: %@ %@ %@",self,[NSDate date],c,[self parent],tc);
}
}
-(CGSize)renderedSize
{
CGSize s = [super renderedSize];
s.width=s.width*1.2;
return s;
}
-(void)dealloc
{
[_timer invalidate];
[_timer release];
_timer = nil;
[_formatter release];
[super dealloc];
}
@end