~rockstar/ubuntuone-ios-music/remote-controls

« back to all changes in this revision

Viewing changes to Music/Controls/UODownloadPanGestureRecognizer.m

  • Committer: Tarmac
  • Author(s): Paul Hummer
  • Date: 2013-01-31 02:38:50 UTC
  • mfrom: (240.2.8 download-song)
  • Revision ID: tarmac-20130131023850-1n3q310ebc88v7mk
Add a Downloader utility, along with the SongCell gesture for downloading individual songs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
//  UOPanGestureRecognizer.m
 
3
//  U1Music
 
4
//
 
5
//  Created by Paul Hummer on 1/26/13.
 
6
//  Copyright (c) 2013 Canonical. All rights reserved.
 
7
//
 
8
 
 
9
#import "UODownloadPanGestureRecognizer.h"
 
10
#import <UIKit/UIGestureRecognizerSubclass.h>
 
11
 
 
12
@interface UODownloadPanGestureRecognizer () {
 
13
    CGPoint start;
 
14
}
 
15
@end
 
16
 
 
17
@implementation UODownloadPanGestureRecognizer
 
18
@synthesize threshold;
 
19
 
 
20
- (id)initWithTarget:(id)target action:(SEL)action {
 
21
    self = [super initWithTarget:target action:action];
 
22
    if (self == nil) { return self; }
 
23
 
 
24
    threshold = 64.f;
 
25
    return self;
 
26
}
 
27
 
 
28
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
 
29
    CGPoint touch = [[touches anyObject] locationInView:self.view];
 
30
    if (!CGRectEqualToRect(self.handle.bounds, CGRectZero) &&
 
31
        !CGRectContainsPoint(self.handle.bounds, touch)) {
 
32
        self.state = UIGestureRecognizerStateCancelled;
 
33
        return;
 
34
    }
 
35
    
 
36
    [super touchesBegan:touches withEvent:event];
 
37
    start = [[touches anyObject] locationInView:nil];
 
38
}
 
39
 
 
40
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
 
41
    for (UITouch *touch in touches) {
 
42
        CGPoint point = [touch locationInView:nil];
 
43
        CGFloat offset = point.x - start.x;
 
44
        if (offset < 0) {
 
45
            self.state = UIGestureRecognizerStateCancelled;
 
46
            return;
 
47
        }
 
48
        
 
49
        /* If we want to fire the event as soon as the threshold is reached,
 
50
           we do it here. As it is, we require a release of the finger.
 
51
         */
 
52
    }
 
53
    [super touchesMoved:touches withEvent:event];
 
54
}
 
55
 
 
56
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
 
57
    CGPoint point = [[touches anyObject] locationInView:nil];
 
58
    CGFloat offset = point.x - start.x;
 
59
    
 
60
    if (fabs(offset) > self.threshold) {
 
61
        [super touchesEnded:touches withEvent:event];
 
62
    } else {
 
63
        self.state = UIGestureRecognizerStateCancelled;
 
64
    }
 
65
}
 
66
 
 
67
 
 
68
 
 
69
@end