<commit_before>﻿package {
  import flash.display.*;
  import flash.events.*;
  import flash.text.*;
  import flash.ui.Mouse;
  import flash.notifications.NotificationStyle;
  import com.juankpro.ane.localnotif.*;

  [SWF(backgroundColor="#FFFFFF", width="320", height="480", frameRate="30")]
  public class Sample extends Sprite {

    private var notificationManager:NotificationManager;

    private var postButton:SimpleButton;
    private var cancelButton:SimpleButton;
    private var codeButton:SimpleButton;
    private var badgeButton:SimpleButton;
    private var notificationTF:TextField;
    private var contentsScaleFactor:int = 2;

    private static const NOTIFICATION_CODE:String = "NOTIFICATION_CODE_001";

    public function Sample() {
      addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
    }

    private function addedToStageHandler(event:Event):void {
      stage.align = StageAlign.TOP_LEFT;
      stage.scaleMode = StageScaleMode.NO_SCALE;
      stage.quality = StageQuality.BEST;

      stage.addEventListener(Event.RESIZE, resizeHandler);
    }

    private var initialized:Boolean = false;

    private function resizeHandler(event:Event):void {
      initApp();
      printMessage("Resized");
    }

    private function initApp():void {
      if (initialized) return;
      initialized = true;

      if (NotificationManager.isSupported) {
        notificationManager = new NotificationManager();

        if (NotificationManager.needsSubsciption) {
          var options:LocalNotifierSubscribeOptions = new LocalNotifierSubscribeOptions();
          options.notificationStyles = NotificationManager.supportedNotificationStyles;
          notificationManager.addEventListener(NotificationEvent.SETTINGS_SUBSCRIBED,
                                               settingsSubscribedHandler);
          notificationManager.subscribe(options);
        }
      }

      initUI();
      registerEvents();
    }

    private function settingsSubscribedHandler(event:NotificationEvent):void {
      printMessage("Settings: " + event.subscribeOptions.notificationStyles.join("\n"));
      registerEvents();
    }

    private function initUI():void {
      var top1:int = 20 * contentsScaleFactor;
      var top2:int = 80 * contentsScaleFactor;
      postButton = createButton("Post", 0, top1);
      cancelButton = createButton("Cancel", stage.stageWidth - 100 * contentsScaleFactor, top1);
      codeButton = createButton("By Code", 0, top2);
      badgeButton = createButton("Clear Badge", stage.stageWidth - 100 * contentsScaleFactor, top2);

      addChild(postButton);
      addChild(cancelButton);
      addChild(codeButton);
      addChild(badgeButton);

      notificationTF = createTextField(0, int(stage.stageHeight / 2),
         stage.stageWidth - 1, int(stage.stageHeight / 2) - 1);
      notificationTF.border = true;
      addChild(notificationTF);
    }

    private function printMessage(message:String, title:String = null):void {
      notificationTF.text += "-----\n" + (title? title + "\n" : "") + message + "\n";
      notificationTF.scrollV = notificationTF.maxScrollV;
    }

    private function registerEvents():void {
      notificationManager.addEventListener(NotificationEvent.NOTIFICATION_ACTION, notificationActionHandler);
      postButton.addEventListener(MouseEvent.CLICK, buttonClickHandler);
      cancelButton.addEventListener(MouseEvent.CLICK, buttonClickHandler);
      codeButton.addEventListener(MouseEvent.CLICK, buttonClickHandler);
      badgeButton.addEventListener(MouseEvent.CLICK, buttonClickHandler);
    }

    private function buttonClickHandler(event:MouseEvent):void {
      switch(event.target) {
        case postButton:
          var notification:Notification = new Notification();
          notification.title = "Sample Title";
          notification.body = "Body sample";
          notification.actionLabel = "Rumble";
          notification.soundName = "fx05.caf";
          notification.fireDate = new Date((new Date()).time + (15 * 1000));
          notification.numberAnnotation = 3;
          notification.actionData = {sampleData:"Hello World!"};

          notificationManager.notifyUser(NOTIFICATION_CODE, notification);
          printNotification('Posted Message', notification);
          break;
        case cancelButton:
          notificationManager.cancelAll();
          printMessage("Cancelled all notifications");
          break;
        case codeButton:
          notificationManager.cancel(NOTIFICATION_CODE);
          printMessage("Cancelled notification with code " + NOTIFICATION_CODE);
          break;
        case badgeButton:
          notificationManager.applicationBadgeNumber = 0;
          printMessage("Reset badge number to zero");
          break;<commit_msg>Add clear button to sample<commit_after>﻿package {
  import flash.display.*;
  import flash.events.*;
  import flash.text.*;
  import flash.ui.Mouse;
  import flash.notifications.NotificationStyle;
  import com.juankpro.ane.localnotif.*;

  [SWF(backgroundColor="#FFFFFF", width="320", height="480", frameRate="30")]
  public class Sample extends Sprite {

    private var notificationManager:NotificationManager;

    private var postButton:SimpleButton;
    private var cancelButton:SimpleButton;
    private var codeButton:SimpleButton;
    private var badgeButton:SimpleButton;
    private var clearButton:SimpleButton;
    private var notificationTF:TextField;
    private var contentsScaleFactor:int = 2;

    private static const NOTIFICATION_CODE:String = "NOTIFICATION_CODE_001";

    public function Sample() {
      addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
    }

    private function addedToStageHandler(event:Event):void {
      stage.align = StageAlign.TOP_LEFT;
      stage.scaleMode = StageScaleMode.NO_SCALE;
      stage.quality = StageQuality.BEST;

      stage.addEventListener(Event.RESIZE, resizeHandler);
    }

    private var initialized:Boolean = false;

    private function resizeHandler(event:Event):void {
      initApp();
      printMessage("Resized");
    }

    private function initApp():void {
      if (initialized) return;
      initialized = true;

      if (NotificationManager.isSupported) {
        notificationManager = new NotificationManager();

        if (NotificationManager.needsSubsciption) {
          var options:LocalNotifierSubscribeOptions = new LocalNotifierSubscribeOptions();
          options.notificationStyles = NotificationManager.supportedNotificationStyles;
          notificationManager.addEventListener(NotificationEvent.SETTINGS_SUBSCRIBED,
                                               settingsSubscribedHandler);
          notificationManager.subscribe(options);
        }
      }

      initUI();
      registerEvents();
    }

    private function settingsSubscribedHandler(event:NotificationEvent):void {
      printMessage("Settings: " + event.subscribeOptions.notificationStyles.join("\n"));
      registerEvents();
    }

    private function initUI():void {
      var top1:int = 20 * contentsScaleFactor;
      var top2:int = 80 * contentsScaleFactor;
      postButton = createButton("Post", 0, top1);
      cancelButton = createButton("Cancel", stage.stageWidth - 100 * contentsScaleFactor, top1);
      codeButton = createButton("By Code", 0, top2);
      badgeButton = createButton("Clear Badge", stage.stageWidth - 100 * contentsScaleFactor, top2);
      clearButton = createButton("Clear", 0, int(stage.stageHeight / 2) - 30 * contentsScaleFactor);

      addChild(postButton);
      addChild(cancelButton);
      addChild(codeButton);
      addChild(badgeButton);
      addChild(clearButton);

      notificationTF = createTextField(0, int(stage.stageHeight / 2),
         stage.stageWidth - 1, int(stage.stageHeight / 2) - 1);
      notificationTF.border = true;
      addChild(notificationTF);
    }

    private function printMessage(message:String, title:String = null):void {
      notificationTF.text += "-----\n" + (title? title + "\n" : "") + message + "\n";
      notificationTF.scrollV = notificationTF.maxScrollV;
    }

    private function clearMessages():void {
      notificationTF.text = "";
    }

    private function registerEvents():void {
      notificationManager.addEventListener(NotificationEvent.NOTIFICATION_ACTION, notificationActionHandler);
      postButton.addEventListener(MouseEvent.CLICK, buttonClickHandler);
      cancelButton.addEventListener(MouseEvent.CLICK, buttonClickHandler);
      codeButton.addEventListener(MouseEvent.CLICK, buttonClickHandler);
      badgeButton.addEventListener(MouseEvent.CLICK, buttonClickHandler);
    }

    private function buttonClickHandler(event:MouseEvent):void {
      switch(event.target) {
        case postButton:
          var notification:Notification = new Notification();
          notification.title = "Sample Title";
          notification.body = "Body sample";
          notification.actionLabel = "Rumble";
          notification.soundName = "fx05.caf";
          notification.fireDate = new Date((new Date()).time + (15 * 1000));
          notification.numberAnnotation = 3;
          notification.actionData = {sampleData:"Hello World!"};

          notificationManager.notifyUser(NOTIFICATION_CODE, notification);
          printNotification('Posted Message', notification);
          break;
        case cancelButton:
          notificationManager.cancelAll();
          printMessage("Cancelled all notifications");
          break;
        case codeButton:
          notificationManager.cancel(NOTIFICATION_CODE);
          printMessage("Cancelled notification with code " + NOTIFICATION_CODE);
          break;
        case badgeButton:
          notificationManager.applicationBadgeNumber = 0;
          printMessage("Reset badge number to zero");
          break;
        case clearButton:
          clearMessages();
          break;
{'fraction_non_alphanumeric': 0.09681323114158935, 'fraction_numerical': 0.009479628882613958, 'mean_word_length': 3.2838012958963283, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '328666', 'n_tokens_mistral': 2555, 'n_tokens_neox': 2422, 'n_words': 512}