<commit_before>//
//  RJSignView.swift
//  SwiftPractice
//
//  Created by 吴蕾君 on 16/1/15.
//  Copyright © 2016年 rayjuneWu. All rights reserved.
//

import UIKit
import SnapKit


protocol RJSignViewDelegate{
    /**
     save current image
     */
    func signViewDidSave(image :UIImage?)
}

class RJSignView: UIView {

    // MARK: Private Var
    private var drawingPath:UIBezierPath!
    //Keep track the four points of bezierPath segment
    private var points = [CGPoint](count: 4, repeatedValue: CGPointZero)
    private var currentTrackIndex = 0
    
    
    private lazy var clearButton : UIButton = {
        let button:UIButton = UIButton()
        button.setTitle("重签", forState:.Normal)
        button.setTitleColor(UIColor.blackColor(), forState: .Normal)
        button.backgroundColor = UIColor.lightGrayColor()
        button.addTarget(self, action: "clearAction", forControlEvents:.TouchUpInside)
        return button
    }()
    private lazy var saveButton : UIButton = {
        let saveButton : UIButton = UIButton()
        saveButton.setTitle("保存", forState: .Normal)
        saveButton.setTitleColor(UIColor.blackColor(), forState: .Normal)
        saveButton.backgroundColor = UIColor.lightGrayColor()
        saveButton.addTarget(self, action: "saveAction", forControlEvents: .TouchUpInside)
        return saveButton
    }()
    private lazy var indicatorLabel : UILabel = {
       let label = UILabel()
        label.text = "请在此签名"
        label.textColor = UIColor.init(red: 200/255, green: 200/255, blue: 200/255, alpha: 1)
        return label
    }()
    
    // MARK: Public Var
    var lineWidth:CGFloat = 2.0{
        didSet{
            self.drawingPath?.lineWidth = lineWidth
        }
    }
    var cacheImage:UIImage?
    var delegate:RJSignViewDelegate?
    var isCleanAfterSave = true
    
    // MARK: Init
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.setup()
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.setup()
    }
    
    // MARK: Actions
    func clearAction(){
        cacheImage = nil
        self.drawingPath.removeAllPoints()
        self.setNeedsDisplay()
        indicatorLabel.hidden = false
    }
    
    func saveAction(){
        self.delegate?.signViewDidSave(self.cacheImage)
        if(isCleanAfterSave){<commit_msg>update skills: only getter is public<commit_after>//
//  RJSignView.swift
//  SwiftPractice
//
//  Created by 吴蕾君 on 16/1/15.
//  Copyright © 2016年 rayjuneWu. All rights reserved.
//

import UIKit
import SnapKit


protocol RJSignViewDelegate{
    /**
     save current image
     */
    func signViewDidSave(image :UIImage?)
}

class RJSignView: UIView {

    // MARK: Private Var
    private var drawingPath:UIBezierPath!
    //Keep track the four points of bezierPath segment
    private var points = [CGPoint](count: 4, repeatedValue: CGPointZero)
    private var currentTrackIndex = 0
    
    
    private lazy var clearButton : UIButton = {
        let button:UIButton = UIButton()
        button.setTitle("重签", forState:.Normal)
        button.setTitleColor(UIColor.blackColor(), forState: .Normal)
        button.backgroundColor = UIColor.lightGrayColor()
        button.addTarget(self, action: "clearAction", forControlEvents:.TouchUpInside)
        return button
    }()
    private lazy var saveButton : UIButton = {
        let saveButton : UIButton = UIButton()
        saveButton.setTitle("保存", forState: .Normal)
        saveButton.setTitleColor(UIColor.blackColor(), forState: .Normal)
        saveButton.backgroundColor = UIColor.lightGrayColor()
        saveButton.addTarget(self, action: "saveAction", forControlEvents: .TouchUpInside)
        return saveButton
    }()
    private lazy var indicatorLabel : UILabel = {
       let label = UILabel()
        label.text = "请在此签名"
        label.textColor = UIColor.init(red: 200/255, green: 200/255, blue: 200/255, alpha: 1)
        return label
    }()
    
    // MARK: Public Var
    var lineWidth:CGFloat = 2.0{
        didSet{
            self.drawingPath?.lineWidth = lineWidth
        }
    }
    //only getter is public,setter is private
    private (set) var cacheImage:UIImage?
    var delegate:RJSignViewDelegate?
    var isCleanAfterSave = true
    
    // MARK: Init
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.setup()
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.setup()
    }
    
    // MARK: Actions
    func clearAction(){
        cacheImage = nil
        self.drawingPath.removeAllPoints()
        self.setNeedsDisplay()
        indicatorLabel.hidden = false
    }
    
    func saveAction(){
        self.delegate?.signViewDidSave(self.cacheImage)
        if(isCleanAfterSave){
{'fraction_non_alphanumeric': 0.10101428275719312, 'fraction_numerical': 0.013247774787828607, 'mean_word_length': 2.5014492753623188, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '765', 'n_tokens_mistral': 1537, 'n_tokens_neox': 1460, 'n_words': 344}