<commit_before>//
//  ViewMonitor.swift
//  ViewMonitor
//

import UIKit
import Foundation

final public class ViewMonitor{
    
    static var sharedInstance = ViewMonitor()
    
    /** target rootView */
    private var rootView:UIView?
    
    //show target view detail
    private var infoView:InfoView?
    
    private var executeButton:MonitorButton?
    
    /** retain my objects */
    private var buttons:[UIButton] = [UIButton]()
    
    private var started:Bool = false
    
    /** do not get these views */
    private let rejectClassNames:[String] = ["MonitorButton","UITabBar","UINavigationBar","InfoView","_UILayoutGuide"]
    private let kRejectTag = 5292739
    
    /* userInteractionEnabled */
    private var enabledViews:[UIView] = [UIView]()
    
    /** monitor these views */
    private let targetClassNames:[String] = [""]
    
    public class func start(){
        if !sharedInstance.started{
            sharedInstance.fookViewEvent()
            sharedInstance.started = true
        }
    }
    
    public class func stop(){
        if sharedInstance.started{
            sharedInstance.terminate()
            sharedInstance.started = false
        }
    }
    
    private func execute(){
        makeMonitorView()
        analyzeAllViews()
    }
    
    private func terminate(){
        deleteAllMonitorViews()
        deleteInfoView()
        resetAllInteractionEnabled()
    }

    private func makeMonitorView(){
        addInfoView()
    }
    
    private func deleteExecuteButton(){
        if let executeButton = executeButton{
            executeButton.removeFromSuperview()
            self.executeButton = nil
        }
    }
    
    private func deleteInfoView(){
        if let infoView = infoView{
            infoView.removeFromSuperview()
        }
    }

    // swizzling viewDidAppear and viewWillDisappear
    private func fookViewEvent(){
        UIViewController.monitor_methodSwizzling_didAppearWillDisappear()
    }
    
    //viewDidAppear event handling
    public class func detectedViewDidAppear(vc:AnyObject){
        if sharedInstance.started{
            sharedInstance.deleteInfoView()
            sharedInstance.deleteExecuteButton()
            sharedInstance.deleteAllMonitorViews()
            sharedInstance.resetAllInteractionEnabled()
            let window = UIApplication.sharedApplication().keyWindow
            sharedInstance.rootView = window?.rootViewController?.view
            sharedInstance.addExecuteButton()
        }
    }
    
    private func addExecuteButton(){
        if executeButton == nil{
            let deviceSize:CGSize = UIScreen.mainScreen().bounds.size
            executeButton = MonitorButton(frame: CGRectMake(deviceSize.width - 100.0, 20.0, 72.0, 49.0))
            let frameworkBundle = NSBundle(forClass: ViewMonitor.self)
            if let buttonPath = frameworkBundle.pathForResource("button", ofType: "png"),let buttonImage = UIImage(named: buttonPath){
                executeButton?.setBackgroundImage(buttonImage, forState: UIControlState.Normal)
            }else{
                executeButton?.setBackgroundImage(createImageFromUIColor(UIColor.blackColor()), forState: UIControlState.Normal)
            }
            if let selectedButtonPath = frameworkBundle.pathForResource("button_selected", ofType: "png"),let buttonSelectedImage = UIImage(named: selectedButtonPath){
                executeButton?.setBackgroundImage(buttonSelectedImage, forState: UIControlState.Selected)
            }else{
                executeButton?.setBackgroundImage(createImageFromUIColor(UIColor.redColor()), forState: UIControlState.Selected)<commit_msg>fixed a execute button scroll problem.<commit_after>//
//  ViewMonitor.swift
//  ViewMonitor
//

import UIKit
import Foundation

final public class ViewMonitor{
    
    static var sharedInstance = ViewMonitor()
    
    /** target rootView */
    private var rootView:UIView?
    
    //show target view detail
    private var infoView:InfoView?
    
    private var executeButton:MonitorButton?
    
    /** retain my objects */
    private var buttons:[UIButton] = [UIButton]()
    
    private var started:Bool = false
    
    /** do not get these views */
    private let rejectClassNames:[String] = ["MonitorButton","UITabBar","UINavigationBar","InfoView","_UILayoutGuide"]
    private let kRejectTag = 5292739
    
    /* userInteractionEnabled */
    private var enabledViews:[UIView] = [UIView]()
    
    /** monitor these views */
    private let targetClassNames:[String] = [""]
    
    public class func start(){
        if !sharedInstance.started{
            sharedInstance.fookViewEvent()
            sharedInstance.started = true
        }
    }
    
    public class func stop(){
        if sharedInstance.started{
            sharedInstance.terminate()
            sharedInstance.started = false
        }
    }
    
    private func execute(){
        makeMonitorView()
        analyzeAllViews()
    }
    
    private func terminate(){
        deleteAllMonitorViews()
        deleteInfoView()
        resetAllInteractionEnabled()
    }

    private func makeMonitorView(){
        addInfoView()
    }
    
    private func deleteExecuteButton(){
        if let executeButton = executeButton{
            executeButton.removeFromSuperview()
            self.executeButton = nil
        }
    }
    
    private func deleteInfoView(){
        if let infoView = infoView{
            infoView.removeFromSuperview()
        }
    }

    // swizzling viewDidAppear and viewWillDisappear
    private func fookViewEvent(){
        UIViewController.monitor_methodSwizzling_didAppearWillDisappear()
    }
    
    //viewDidAppear event handling
    public class func detectedViewDidAppear(vc:AnyObject){
        if sharedInstance.started{
            sharedInstance.deleteInfoView()
            sharedInstance.deleteExecuteButton()
            sharedInstance.deleteAllMonitorViews()
            sharedInstance.resetAllInteractionEnabled()
            let window = UIApplication.sharedApplication().keyWindow
            sharedInstance.rootView = window?.viewForBaselineLayout()
            sharedInstance.addExecuteButton()
        }
    }
    
    private func addExecuteButton(){
        if executeButton == nil{
            let deviceSize:CGSize = UIScreen.mainScreen().bounds.size
            executeButton = MonitorButton(frame: CGRectMake(deviceSize.width - 100.0, 20.0, 72.0, 49.0))
            let frameworkBundle = NSBundle(forClass: ViewMonitor.self)
            if let buttonPath = frameworkBundle.pathForResource("button", ofType: "png"),let buttonImage = UIImage(named: buttonPath){
                executeButton?.setBackgroundImage(buttonImage, forState: UIControlState.Normal)
            }else if let buttonImage = UIImage(named: "button"){
                executeButton?.setBackgroundImage(buttonImage, forState: UIControlState.Normal)
            }else{
                executeButton?.setBackgroundImage(createImageFromUIColor(UIColor.blackColor()), forState: UIControlState.Normal)
            }
            if let selectedButtonPath = frameworkBundle.pathForResource("button_selected", ofType: "png"),let buttonSelectedImage = UIImage(named: selectedButtonPath){
                executeButton?.setBackgroundImage(buttonSelectedImage, forState: UIControlState.Selected)
            }else if let buttonSelectedImage = UIImage(named: "button_selected"){
                executeButton?.setBackgroundImage(buttonSelectedImage, forState: UIControlState.Selected)
            }else{
                executeButton?.setBackgroundImage(createImageFromUIColor(UIColor.redColor()), forState: UIControlState.Selected)
{'fraction_non_alphanumeric': 0.08684927950149292, 'fraction_numerical': 0.005192782032974166, 'mean_word_length': 2.6033676333021516, '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': '5685313', 'n_tokens_mistral': 1995, 'n_tokens_neox': 1929, 'n_words': 412}