Example #1
0
 public void initAd(PictureAd ad)
 {
     _ad = ad;
     updateRects(ad);
     updateTextures(ad);
     _isClosed = false;
 }
Example #2
0
        void executeRequestForResource(PictureAd ad, ImageOrientation imageOrientation, ImageType imageType)
        {
            string filePath = ad.getLocalImageURL(imageOrientation, imageType);

            if (System.IO.File.Exists(filePath))
            {
                downloadedResourcesCount++;
                if (downloadedResourcesCount == PictureAd.expectedResourcesCount)
                {
                    _resourcesAvailable();
                    _operationCompleteDelegate();
                }
                return;
            }
            string      url = ad.getRemoteImageURL(imageOrientation, imageType);
            HTTPRequest pictureURLRequest = new HTTPRequest(url);

            pictureURLRequest.execute(pictureURLRequestResponse => {
                downloadedResourcesCount++;
                if (pictureURLRequestResponse.dataLength != 0)
                {
                    System.IO.File.WriteAllBytes(ad.getLocalImageURL(imageOrientation, imageType), pictureURLRequestResponse.data);
                }

                if (downloadedResourcesCount == PictureAd.expectedResourcesCount)
                {
                    _resourcesAvailable();
                    _operationCompleteDelegate();
                }
            });
        }
 public void jsonAvailableDelegate(string jsonData)
 {
     jsonDownloaded = true;
       currentAd = PictureAdsParser.parseJSONString(jsonData, Application.temporaryCachePath + "/");
     if(currentAd == null || !currentAd.adIsValid()) {pictureAdFailed();return;}
       	requestManager.downloadResourcesForAd(_network, this, currentAd);
 }
		public void downloadAssetsForPictureAd(PictureAd ad) {
			downloadedResourcesCount = 0;
			executeRequestForResource(ad, ImageOrientation.Landscape, ImageType.Base);
			executeRequestForResource(ad, ImageOrientation.Landscape, ImageType.Frame);
			executeRequestForResource(ad, ImageOrientation.Landscape, ImageType.Close);
			executeRequestForResource(ad, ImageOrientation.Portrait, ImageType.Base);
			executeRequestForResource(ad, ImageOrientation.Portrait, ImageType.Frame);
		}
Example #5
0
 void updateTextures(PictureAd ad)
 {
     textures.Clear();
     textures[ImageOrientation.Landscape] = new Dictionary <ImageType, Texture2D>();
     textures[ImageOrientation.Portrait]  = new Dictionary <ImageType, Texture2D>();
     initTextureForOrientation(ad, ImageOrientation.Landscape);
     initTextureForOrientation(ad, ImageOrientation.Portrait);
 }
Example #6
0
    public void init() {
			EventManager.sendAdreqEvent(Engine.Instance.AppId);
      currentAd = null;
	  	jsonDownloaded = false;
	  	resourcesAreDownloaded = false;
      if (requestManager != null)
	  		requestManager.downloadJson(_network, this);
   	}
Example #7
0
 void initTextureForOrientation(PictureAd ad, ImageOrientation imageOrientation)
 {
     blackTex = new Texture2D(1, 1, TextureFormat.ARGB32, false);
     blackTex.SetPixel(0, 0, new Color(0.0f, 0.0f, 0.0f, 0.7f));
     blackTex.Apply();
     initTexture(imageOrientation, ImageType.Base, ad);
     initTexture(imageOrientation, ImageType.Frame, ad);
     initTexture(imageOrientation, ImageType.Close, ad);
 }
Example #8
0
 void updateRects(PictureAd ad)
 {
     texturesRects.Clear();
     texturesRects[ImageOrientation.Landscape] = new Dictionary <ImageType, Rect>();
     texturesRects[ImageOrientation.Portrait]  = new Dictionary <ImageType, Rect>();
     initRectsForOrientation(ad, ImageOrientation.Landscape);
     initRectsForOrientation(ad, ImageOrientation.Portrait);
     getScreenOrientation();
 }
Example #9
0
 public void downloadAssetsForPictureAd(PictureAd ad)
 {
     downloadedResourcesCount = 0;
     executeRequestForResource(ad, ImageOrientation.Landscape, ImageType.Base);
     executeRequestForResource(ad, ImageOrientation.Landscape, ImageType.Frame);
     executeRequestForResource(ad, ImageOrientation.Landscape, ImageType.Close);
     executeRequestForResource(ad, ImageOrientation.Portrait, ImageType.Base);
     executeRequestForResource(ad, ImageOrientation.Portrait, ImageType.Frame);
 }
 public void jsonAvailableDelegate(string jsonData)
 {
     jsonDownloaded = true;
     currentAd      = PictureAdsParser.parseJSONString(jsonData, Application.temporaryCachePath + "/");
     if (currentAd == null || !currentAd.adIsValid())
     {
         pictureAdFailed(); return;
     }
     requestManager.downloadResourcesForAd(_network, this, currentAd);
 }
 public void init()
 {
     EventManager.sendAdreqEvent(Engine.Instance.AppId);
     currentAd              = null;
     jsonDownloaded         = false;
     resourcesAreDownloaded = false;
     if (requestManager != null)
     {
         requestManager.downloadJson(_network, this);
     }
 }
 void removeLocalResources(PictureAd ad)
 {
     if (!ad.adIsValid())
     {
         return;
     }
     System.IO.File.Delete(ad.getLocalImageURL(ImageOrientation.Landscape, ImageType.Close));
     System.IO.File.Delete(ad.getLocalImageURL(ImageOrientation.Landscape, ImageType.Frame));
     System.IO.File.Delete(ad.getLocalImageURL(ImageOrientation.Landscape, ImageType.Base));
     System.IO.File.Delete(ad.getLocalImageURL(ImageOrientation.Portrait, ImageType.Close));
     System.IO.File.Delete(ad.getLocalImageURL(ImageOrientation.Portrait, ImageType.Base));
     System.IO.File.Delete(ad.getLocalImageURL(ImageOrientation.Portrait, ImageType.Frame));
 }
Example #13
0
        void initRectsForOrientation(PictureAd ad, ImageOrientation imageOrientation)
        {
            Rect  frameRect       = rectWithPrecentage(ad.getImageSpace(ImageType.Frame), imageOrientation);
            Rect  baseRect        = rectWithPrecentage(ad.getImageSpace(ImageType.Base), imageOrientation);
            Rect  closeButtonRect = rectWithPrecentage(ad.getImageSpace(ImageType.Close), imageOrientation);
            float maxV            = Math.Max(closeButtonRect.width, closeButtonRect.height);

            closeButtonRect = new Rect((baseRect.x + baseRect.width) - closeButtonRect.width / 2, baseRect.y - closeButtonRect.height / 2, maxV, maxV);
            Rect closeActiveAreaRect = new Rect((float)(closeButtonRect.x - closeButtonRect.width * 0.3),
                                                (float)(closeButtonRect.y - closeButtonRect.height * 0.3),
                                                (float)(closeButtonRect.width + closeButtonRect.width * 0.3),
                                                (float)(closeButtonRect.height + closeButtonRect.height * 0.3));

            initRect(imageOrientation, ImageType.Base, baseRect);
            initRect(imageOrientation, ImageType.Frame, frameRect);
            initRect(imageOrientation, ImageType.Close, closeButtonRect);
            initRect(imageOrientation, ImageType.CloseActiveArea, closeActiveAreaRect);
        }
Example #14
0
        void executeRequestForResource(PictureAd ad, ImageOrientation imageOrientation, ImageType imageType)
        {
            string filePath = ad.getLocalImageURL(imageOrientation, imageType);

            if (System.IO.File.Exists(filePath))
            {
                downloadedResourcesCount++;
                if (downloadedResourcesCount == PictureAd.expectedResourcesCount)
                {
                    _resourcesAvailable();
                    _operationCompleteDelegate();
                }
                return;
            }
            string      url = ad.getRemoteImageURL(imageOrientation, imageType);
            HTTPRequest pictureURLRequest = new HTTPRequest(url);

            imageTypes[url]        = imageType;
            imageOrientations[url] = imageOrientation;
            HTTPManager.sendFileRequest(pictureURLRequest, HTTPFileCallback, retryDelays, 20 * 60);
        }
		void executeRequestForResource(PictureAd ad, ImageOrientation imageOrientation, ImageType imageType) {
			string filePath = ad.getLocalImageURL(imageOrientation, imageType);
			if (System.IO.File.Exists(filePath)) {
				downloadedResourcesCount++;
				if(downloadedResourcesCount == PictureAd.expectedResourcesCount) {
					_resourcesAvailable ();
					_operationCompleteDelegate();
				}
				return;
			}
			string url = ad.getRemoteImageURL(imageOrientation, imageType);
			HTTPRequest pictureURLRequest = new HTTPRequest(url);
			pictureURLRequest.execute(pictureURLRequestResponse => {
				downloadedResourcesCount ++;
				if(pictureURLRequestResponse.dataLength != 0)
					System.IO.File.WriteAllBytes(ad.getLocalImageURL(imageOrientation, imageType), pictureURLRequestResponse.data);
				
				if(downloadedResourcesCount == PictureAd.expectedResourcesCount) {
					_resourcesAvailable ();
					_operationCompleteDelegate();
				}
			});
		}
        static void setImageSpace(PictureAd ad, ImageType imageType, Dictionary <string, object> dict)
        {
            string key = null;

            switch (imageType)
            {
            case ImageType.Base:
                key = baseSpace__KEY;
                break;

            case ImageType.Frame:
                key = frameSpace__KEY;
                break;

            case ImageType.Close:
                key = closeSpace__KEY;
                break;
            }
            if (dict == null || !dict.ContainsKey(key))
            {
                return;
            }
            ad.setImageSpace(imageType, stringToInt((string)dict[key].ToString()));
        }
 void initRectsForOrientation(PictureAd ad, ImageOrientation imageOrientation) {
   Rect frameRect = rectWithPrecentage(ad.getImageSpace(ImageType.Frame), imageOrientation);
   Rect baseRect = rectWithPrecentage(ad.getImageSpace(ImageType.Base), imageOrientation);
   Rect closeButtonRect = rectWithPrecentage(ad.getImageSpace(ImageType.Close), imageOrientation);
   float maxV = Math.Max(closeButtonRect.width, closeButtonRect.height);
   closeButtonRect = new Rect((baseRect.x + baseRect.width) - closeButtonRect.width / 2, baseRect.y - closeButtonRect.height / 2, maxV, maxV);
   Rect closeActiveAreaRect = new Rect((float)(closeButtonRect.x - closeButtonRect.width * 0.3), 
                                        (float)(closeButtonRect.y - closeButtonRect.height * 0.3),
                                        (float)(closeButtonRect.width + closeButtonRect.width * 0.3),
                                        (float)(closeButtonRect.height + closeButtonRect.height * 0.3));
   initRect(imageOrientation, ImageType.Base, baseRect);
   initRect(imageOrientation, ImageType.Frame, frameRect);
   initRect(imageOrientation, ImageType.Close, closeButtonRect);
   initRect(imageOrientation, ImageType.CloseActiveArea, closeActiveAreaRect);
 }
 void initTexture(ImageOrientation imageOrientation, ImageType imageType, PictureAd ad) {
   textures[imageOrientation][imageType] = textureFromBytes(textureBytesForFrame(ad.getLocalImageURL(imageOrientation, imageType)));
 }
 static void setupPathsForAd(PictureAd ad, string localCachePath, string remotePath, ImageOrientation orientation, ImageType imageType)
 {
     ad.setImageURL(remotePath, ImageURLType.Remote, orientation, imageType);
     ad.setImageURL(localPathForResource(localCachePath, remotePath), ImageURLType.Local, orientation, imageType);
 }
Example #20
0
		public static PictureAd parseJSONString(string jsonString, string localCachePath) {
			PictureAd pictureAd = new PictureAd();
			pictureAd.setImageSpace(ImageType.Base, defaultBaseSpace);
			pictureAd.setImageSpace(ImageType.Close, defaultCloseButtonSpace);
			pictureAd.setImageSpace(ImageType.Frame, defaultFrameSpace);
			pictureAd.closeButtonDelay = defaultCloseButtonDelay;
			
			if(jsonString == null || jsonString.Length == 0) return pictureAd;
			
			var dict = Json.Deserialize(jsonString) as Dictionary<string, object>;
			
			if(dict == null) return pictureAd;
			
			if(!dict.ContainsKey("data")) return pictureAd;
			
			Dictionary<string, object> dict2 = (Dictionary<string, object>)dict["data"];
			
			foreach(string assetKey in dict2.Keys) {
				if(assetKey == game__KEY) {
					var gameDict = (Dictionary <string, object>)dict2[assetKey];
					if(gameDict == null) return pictureAd;
					
					if(gameDict.ContainsKey(landscapeFramePicture__KEY))
						setupPathsForAd(pictureAd, localCachePath, (string)gameDict[landscapeFramePicture__KEY], ImageOrientation.Landscape, ImageType.Frame);
					
					if(gameDict.ContainsKey(portraitFramePicture__KEY))
						setupPathsForAd(pictureAd, localCachePath, (string)gameDict[portraitFramePicture__KEY], ImageOrientation.Portrait, ImageType.Frame);
					
					if(gameDict.ContainsKey(closeButtonPicture__KEY)) {
						setupPathsForAd(pictureAd, localCachePath, (string)gameDict[closeButtonPicture__KEY], ImageOrientation.Landscape, ImageType.Close);
						pictureAd.setImageURL(localPathForResource(localCachePath,(string)gameDict[closeButtonPicture__KEY]), 
						                      ImageURLType.Local, ImageOrientation.Portrait, ImageType.Close);
					}
					
					if(gameDict.ContainsKey(closeButtonDelay__KEY))
						pictureAd.closeButtonDelay = stringToInt((string)gameDict[closeButtonDelay__KEY].ToString());
					
					setImageSpace(pictureAd, ImageType.Frame, gameDict);
					setImageSpace(pictureAd, ImageType.Close, gameDict);
				}
				
				if(assetKey == campaign__KEY) {
					var campaignDict = (Dictionary <string, object>)dict2[assetKey];
					if(campaignDict == null) return pictureAd;
					
					if(campaignDict.ContainsKey(landscapePicture__KEY))
						setupPathsForAd(pictureAd, localCachePath, (string)campaignDict[landscapePicture__KEY], ImageOrientation.Landscape, ImageType.Base);
					
					if(campaignDict.ContainsKey(portraitPicture__KEY))
						setupPathsForAd(pictureAd, localCachePath, (string)campaignDict[portraitPicture__KEY], ImageOrientation.Portrait, ImageType.Base);
					
					if(campaignDict.ContainsKey(id__KEY))
						pictureAd.id = (string)campaignDict[id__KEY];
					
					if(campaignDict.ContainsKey(clickActionUrl__KEY))
						pictureAd.clickActionUrl = (string)campaignDict[clickActionUrl__KEY];
					
					setImageSpace(pictureAd, ImageType.Base, campaignDict);
				}
				
				if (assetKey == hasMoreCampaigns__KEY)
					bool.TryParse((string)dict2[assetKey].ToString(), out pictureAd.hasMoreCampaigns);
				
			}
			
			return pictureAd;
		}
Example #21
0
        public void downloadResourcesForAd(string network, PictureAdsManager manager, PictureAd ad)
        {
            PictureAdsRequest request = new PictureAdsRequest(network);

            request.setResourcesAvailableDelegate(manager.resourcesAvailableDelegate);
            request.setOperationCompleteDelegate(resourcesOperationComplete);
            request.ad = ad;
            _requestsForResources.Push(request);
            if (_requestsForResources.Count == 1)
            {
                RequestsForResourcesLoop();
            }
        }
 void removeLocalResources(PictureAd ad)
 {
     if (!ad.adIsValid()) return;
     System.IO.File.Delete(ad.getLocalImageURL(ImageOrientation.Landscape, ImageType.Close));
     System.IO.File.Delete(ad.getLocalImageURL(ImageOrientation.Landscape, ImageType.Frame));
     System.IO.File.Delete(ad.getLocalImageURL(ImageOrientation.Landscape, ImageType.Base));
     System.IO.File.Delete(ad.getLocalImageURL(ImageOrientation.Portrait, ImageType.Close));
     System.IO.File.Delete(ad.getLocalImageURL(ImageOrientation.Portrait, ImageType.Base));
     System.IO.File.Delete(ad.getLocalImageURL(ImageOrientation.Portrait, ImageType.Frame));
 }
 void updateTextures(PictureAd ad) {
   textures.Clear();
   textures[ImageOrientation.Landscape] = new Dictionary <ImageType, Texture2D >();
   textures[ImageOrientation.Portrait] = new Dictionary <ImageType, Texture2D >();
   initTextureForOrientation(ad, ImageOrientation.Landscape);
   initTextureForOrientation(ad, ImageOrientation.Portrait);
 }
    void initTextureForOrientation(PictureAd ad, ImageOrientation imageOrientation) {
	  	blackTex = new Texture2D(1, 1, TextureFormat.ARGB32, false);
	  	blackTex.SetPixel(0, 0, new Color(0.0f, 0.0f, 0.0f, 0.7f));
	  	blackTex.Apply();
      initTexture(imageOrientation, ImageType.Base, ad);
      initTexture(imageOrientation, ImageType.Frame, ad);
      initTexture(imageOrientation, ImageType.Close, ad);
    }
Example #25
0
 void initTexture(ImageOrientation imageOrientation, ImageType imageType, PictureAd ad)
 {
     textures[imageOrientation][imageType] = textureFromBytes(textureBytesForFrame(ad.getLocalImageURL(imageOrientation, imageType)));
 }
        public static PictureAd parseJSONString(string jsonString, string localCachePath)
        {
            PictureAd pictureAd = new PictureAd();

            pictureAd.setImageSpace(ImageType.Base, defaultBaseSpace);
            pictureAd.setImageSpace(ImageType.Close, defaultCloseButtonSpace);
            pictureAd.setImageSpace(ImageType.Frame, defaultFrameSpace);
            pictureAd.closeButtonDelay = defaultCloseButtonDelay;

            if (jsonString == null || jsonString.Length == 0)
            {
                return(pictureAd);
            }

            var dict = Json.Deserialize(jsonString) as Dictionary <string, object>;

            if (dict == null)
            {
                return(pictureAd);
            }

            if (!dict.ContainsKey("data"))
            {
                return(pictureAd);
            }

            Dictionary <string, object> dict2 = (Dictionary <string, object>)dict["data"];

            foreach (string assetKey in dict2.Keys)
            {
                if (assetKey == game__KEY)
                {
                    var gameDict = (Dictionary <string, object>)dict2[assetKey];
                    if (gameDict == null)
                    {
                        return(pictureAd);
                    }

                    if (gameDict.ContainsKey(landscapeFramePicture__KEY))
                    {
                        setupPathsForAd(pictureAd, localCachePath, (string)gameDict[landscapeFramePicture__KEY], ImageOrientation.Landscape, ImageType.Frame);
                    }

                    if (gameDict.ContainsKey(portraitFramePicture__KEY))
                    {
                        setupPathsForAd(pictureAd, localCachePath, (string)gameDict[portraitFramePicture__KEY], ImageOrientation.Portrait, ImageType.Frame);
                    }

                    if (gameDict.ContainsKey(closeButtonPicture__KEY))
                    {
                        setupPathsForAd(pictureAd, localCachePath, (string)gameDict[closeButtonPicture__KEY], ImageOrientation.Landscape, ImageType.Close);
                        pictureAd.setImageURL(localPathForResource(localCachePath, (string)gameDict[closeButtonPicture__KEY]),
                                              ImageURLType.Local, ImageOrientation.Portrait, ImageType.Close);
                    }

                    if (gameDict.ContainsKey(closeButtonDelay__KEY))
                    {
                        pictureAd.closeButtonDelay = stringToInt((string)gameDict[closeButtonDelay__KEY].ToString());
                    }

                    setImageSpace(pictureAd, ImageType.Frame, gameDict);
                    setImageSpace(pictureAd, ImageType.Close, gameDict);
                }

                if (assetKey == campaign__KEY)
                {
                    var campaignDict = (Dictionary <string, object>)dict2[assetKey];
                    if (campaignDict == null)
                    {
                        return(pictureAd);
                    }

                    if (campaignDict.ContainsKey(landscapePicture__KEY))
                    {
                        setupPathsForAd(pictureAd, localCachePath, (string)campaignDict[landscapePicture__KEY], ImageOrientation.Landscape, ImageType.Base);
                    }

                    if (campaignDict.ContainsKey(portraitPicture__KEY))
                    {
                        setupPathsForAd(pictureAd, localCachePath, (string)campaignDict[portraitPicture__KEY], ImageOrientation.Portrait, ImageType.Base);
                    }

                    if (campaignDict.ContainsKey(id__KEY))
                    {
                        pictureAd.id = (string)campaignDict[id__KEY];
                    }

                    if (campaignDict.ContainsKey(clickActionUrl__KEY))
                    {
                        pictureAd.clickActionUrl = (string)campaignDict[clickActionUrl__KEY];
                    }

                    setImageSpace(pictureAd, ImageType.Base, campaignDict);
                }

                if (assetKey == hasMoreCampaigns__KEY)
                {
                    bool.TryParse((string)dict2[assetKey].ToString(), out pictureAd.hasMoreCampaigns);
                }
            }

            return(pictureAd);
        }
 void updateRects(PictureAd ad) {
   texturesRects.Clear();
   texturesRects[ImageOrientation.Landscape] = new Dictionary <ImageType, Rect >();
   texturesRects[ImageOrientation.Portrait] = new Dictionary <ImageType, Rect >();
   initRectsForOrientation(ad, ImageOrientation.Landscape);
   initRectsForOrientation(ad, ImageOrientation.Portrait);
   getScreenOrientation();
 }
Example #28
0
		static void setImageSpace(PictureAd ad, ImageType imageType, Dictionary <string, object> dict) {
      string key = null;
      switch(imageType) {
        case ImageType.Base:
          key = baseSpace__KEY;
          break;

        case ImageType.Frame:
          key = frameSpace__KEY;
          break;

        case ImageType.Close:
          key = closeSpace__KEY;
          break;
      }
      if(dict == null || !dict.ContainsKey(key)) return;
      ad.setImageSpace(imageType, stringToInt((string)dict[key].ToString()));
    }
		public void initAd(PictureAd ad) {
			_ad = ad;
			updateRects(ad);
			updateTextures(ad);
			_isClosed = false;
		}
 public void downloadResourcesForAd(string network, PictureAdsManager manager, PictureAd ad)
 {
     PictureAdsRequest request = new PictureAdsRequest(network);
     request.setResourcesAvailableDelegate(manager.resourcesAvailableDelegate);
     request.setOperationCompleteDelegate(resourcesOperationComplete);
     request.ad = ad;
     _requestsForResources.Push(request);
     if(_requestsForResources.Count == 1)
         RequestsForResourcesLoop();
 }
 void executeRequestForResource(PictureAd ad, ImageOrientation imageOrientation, ImageType imageType)
 {
     string filePath = ad.getLocalImageURL(imageOrientation, imageType);
     if (System.IO.File.Exists(filePath)) {
         downloadedResourcesCount++;
         if(downloadedResourcesCount == PictureAd.expectedResourcesCount) {
             _resourcesAvailable ();
             _operationCompleteDelegate();
         }
         return;
     }
     string url = ad.getRemoteImageURL(imageOrientation, imageType);
     HTTPRequest pictureURLRequest = new HTTPRequest(url);
     imageTypes[url] = imageType;
     imageOrientations[url] = imageOrientation;
     HTTPManager.sendFileRequest(pictureURLRequest, HTTPFileCallback, retryDelays, 20 * 60);
 }
Example #32
0
		static void setupPathsForAd(PictureAd ad, string localCachePath, string remotePath, ImageOrientation orientation, ImageType imageType) {
			ad.setImageURL(remotePath, ImageURLType.Remote, orientation, imageType);
			ad.setImageURL(localPathForResource(localCachePath, remotePath), ImageURLType.Local, orientation, imageType);
		}