<commit_before>//
//  predictboardBanner.swift
//  TastyImitationKeyboard
//
//  Created by <NAME> on 10/5/14.
//  Copyright (c) 2014 <NAME> ("Archagon"). All rights reserved.
//

import UIKit

/*
 This is the demo banner. The banner is needed so that the top row popups have somewhere to go. Might as well fill it
 with something (or leave it blank if you like.)
 */

class predictboardBanner: ExtraView {
    
    //var predictSwitch: UISwitch = UISwitch()
    //var predictLabel: UILabel = UILabel()
    let numButtons = 5
    var buttons = [UIButton]()
    let recommendationEngine = WordList()
    var outFunc: (String) -> ()
    
    required init(globalColors: GlobalColors.Type?, darkMode: Bool, solidColorMode: Bool, outputFunc: @escaping (String)->()) {
        
        self.outFunc = outputFunc //needs to be declared before the super.init
        
        super.init(globalColors: globalColors, darkMode: darkMode, solidColorMode: solidColorMode)
        
        for _ in 0..<self.numButtons {
            let button: UIButton = UIButton()
            buttons.append(button)
            self.addSubview(button)
            button.backgroundColor = UIColor.blue
            //button.setTitle("Hello", for: UIControlState())
            //self.predictSwitch.on = NSUserDefaults.standardUserDefaults().boolForKey(predictionEnabled)
            //self.predictSwitch.transform = CGAffineTransformMakeScale(0.75, 0.75)
            //self.predictSwitch.addTarget(self, action: Selector("respondToSwitch"), forControlEvents: UIControlEvents.ValueChanged)
            button.addTarget(self, action: #selector(runOutputFunc), for: .touchUpInside)
        }
        updateButtons(prevWord: "")
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    required init(globalColors: GlobalColors.Type?, darkMode: Bool, solidColorMode: Bool) {
        fatalError("init(globalColors:darkMode:solidColorMode:) has not been implemented")
    }
    
    override func setNeedsLayout() {
        super.setNeedsLayout()
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        //self.predictSwitch.center = self.center
        //self.predictLabel.center = self.center
        //self.predictLabel.frame.origin = CGPointMake(self.predictSwitch.frame.origin.x + self.predictSwitch.frame.width + 20, self.predictLabel.frame.origin.y)
        
        let yMax = self.getMaxY()
        let yMin = self.getMinY()
        let xMax = self.getMaxX()
        let xMin = self.getMinX()
        
        var widthBut = (self.getMaxX() - self.getMinX()) / CGFloat(self.numButtons)
        let heightBut = self.getMaxY() - self.getMinY()
        let halfWidth = widthBut / CGFloat(2)
        
        var offset = CGFloat(0)
        for button in self.buttons {
            button.frame = CGRect(x: (self.getMinX() + offset), y: self.getMinY(), width: widthBut, height: heightBut)
            offset += widthBut
            //button.center = self.center
        }
        //self.predictButton.frame.origin = CGPointMake(self.predictSwitch.frame.origin.x + self.predictSwitch.frame.width + 8, self.predictButton.frame.origin.y)
    }
    
    func runOutputFunc(_ sender:UIButton) {
        let wordToAdd = sender.titleLabel!.text!
        if wordToAdd != " "
        {
            self.outFunc(wordToAdd)
            updateButtons(prevWord: "")
        }

        
    }
    
    func updateButtons(prevWord: String) {
        let recommendations = recommendationEngine.recommendWords(input: prevWord)
        for index in 0..<self.numButtons {
            if index < recommendations.count {
                self.buttons[index].setTitle(recommendations[index], for: UIControlState())
            }
            else {
                self.buttons[index].setTitle(" ", for: UIControlState())
            }
        }
    }
    
    /*
    func respondToSwitch() {
        NSUserDefaults.standardUserDefaults().setBool(self.predictSwitch.on, forKey: predictionEnabled)
        //self.updateAppearance()
    }
    
    
    func updateAppearance() {
        if self.predictSwitch.on {
            self.predictLabel.text = "auto"
            self.predictLabel.alpha = 1
        }
        else {
            self.predictLabel.text = "🐱"
            self.predictLabel.alpha = 0.5
        }
        
        self.predictLabel.sizeToFit()
    }*/
    
}




<commit_msg>made autocomplete buttons look like those on normal ios keyboard<commit_after>//
//  predictboardBanner.swift
//  TastyImitationKeyboard
//
//  Created by <NAME> on 10/5/14.
//  Copyright (c) 2014 <NAME> ("Archagon"). All rights reserved.
//

import UIKit

/*
 This is the demo banner. The banner is needed so that the top row popups have somewhere to go. Might as well fill it
 with something (or leave it blank if you like.)
 */

class predictboardBanner: ExtraView {
    
    //var predictSwitch: UISwitch = UISwitch()
    //var predictLabel: UILabel = UILabel()
    let numButtons = 5
    var buttons = [UIButton]()
    let recommendationEngine = WordList()
    var outFunc: (String) -> ()
    
    required init(globalColors: GlobalColors.Type?, darkMode: Bool, solidColorMode: Bool, outputFunc: @escaping (String)->()) {
        
        self.outFunc = outputFunc //needs to be declared before the super.init
        
        super.init(globalColors: globalColors, darkMode: darkMode, solidColorMode: solidColorMode)
        
        for _ in 0..<self.numButtons {
            let button: UIButton = UIButton()
            buttons.append(button)
            self.addSubview(button)
            button.backgroundColor = UIColor.lightGray
            button.layer.borderWidth = 1
            button.layer.borderColor = UIColor.clear.cgColor
            button.addTarget(self, action: #selector(runOutputFunc), for: .touchUpInside)
        }
        updateButtons(prevWord: "")
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    required init(globalColors: GlobalColors.Type?, darkMode: Bool, solidColorMode: Bool) {
        fatalError("init(globalColors:darkMode:solidColorMode:) has not been implemented")
    }
    
    override func setNeedsLayout() {
        super.setNeedsLayout()
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        //self.predictSwitch.center = self.center
        //self.predictLabel.center = self.center
        //self.predictLabel.frame.origin = CGPointMake(self.predictSwitch.frame.origin.x + self.predictSwitch.frame.width + 20, self.predictLabel.frame.origin.y)
        
        let yMax = self.getMaxY()
        let yMin = self.getMinY()
        let xMax = self.getMaxX()
        let xMin = self.getMinX()
        
        var widthBut = (self.getMaxX() - self.getMinX()) / CGFloat(self.numButtons)
        let heightBut = self.getMaxY() - self.getMinY()
        let halfWidth = widthBut / CGFloat(2)
        
        var offset = CGFloat(0)
        for button in self.buttons {
            button.frame = CGRect(x: (self.getMinX() + offset), y: self.getMinY(), width: widthBut - 1, height: heightBut)
            offset += widthBut
            //button.center = self.center
        }
        //self.predictButton.frame.origin = CGPointMake(self.predictSwitch.frame.origin.x + self.predictSwitch.frame.width + 8, self.predictButton.frame.origin.y)
    }
    
    func runOutputFunc(_ sender:UIButton) {
        let wordToAdd = sender.titleLabel!.text!
        if wordToAdd != " "
        {
            self.outFunc(wordToAdd)
            updateButtons(prevWord: "")
        }

        
    }
    
    func updateButtons(prevWord: String) {
        let recommendations = recommendationEngine.recommendWords(input: prevWord)
        for index in 0..<self.numButtons {
            if index < recommendations.count {
                self.buttons[index].setTitle(recommendations[index], for: UIControlState())
            }
            else {
                self.buttons[index].setTitle(" ", for: UIControlState())
            }
        }
    }
    
    /*
    func respondToSwitch() {
        NSUserDefaults.standardUserDefaults().setBool(self.predictSwitch.on, forKey: predictionEnabled)
        //self.updateAppearance()
    }
    
    
    func updateAppearance() {
        if self.predictSwitch.on {
            self.predictLabel.text = "auto"
            self.predictLabel.alpha = 1
        }
        else {
            self.predictLabel.text = "🐱"
            self.predictLabel.alpha = 0.5
        }
        
        self.predictLabel.sizeToFit()
    }*/
    
}





{'fraction_non_alphanumeric': 0.10875576036866359, 'fraction_numerical': 0.005529953917050691, 'mean_word_length': 2.189199118295371, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '225356', 'n_tokens_mistral': 2565, 'n_tokens_neox': 2513, 'n_words': 539}