public DataViewController GetViewControllerAt(int index) { var len = regionCodes.Length; if (len == 0 || index >= len) { return(null); } var regionCode = regionCodes [index]; // Return the data view controller for the given index. var dataViewController = (DataViewController)cachedDataViewControllers.ObjectForKey((NSString)regionCode); if (dataViewController != null) { return(dataViewController); } // Create a new view controller and pass suitable data. dataViewController = (DataViewController)storyboard.InstantiateViewController("DataViewController"); dataViewController.RegionCode = regionCodes [index]; // Cache the view controller before returning it. cachedDataViewControllers.SetObjectforKey(dataViewController, (NSString)regionCode); return(dataViewController); }
public Tuple <UIImage, ImageInformation> Get(string key) { var image = (UIImage)_cache.ObjectForKey(new NSString(key)); var imageInformation = GetInfo(key); return(new Tuple <UIImage, ImageInformation>(image, imageInformation)); }
UIImage DrawHamburger() { const string hamburgerKey = "Hamburger"; UIImage img = (UIImage)_nSCache.ObjectForKey((NSString)hamburgerKey); if (img != null) return img; var rect = new CGRect(0, 0, 23f, 23f); UIGraphics.BeginImageContextWithOptions(rect.Size, false, 0); var ctx = UIGraphics.GetCurrentContext(); ctx.SaveState(); ctx.SetStrokeColor(UIColor.Blue.CGColor); float size = 3f; float start = 4f; ctx.SetLineWidth(size); for (int i = 0; i < 3; i++) { ctx.MoveTo(1f, start + i * (size * 2)); ctx.AddLineToPoint(22f, start + i * (size * 2)); ctx.StrokePath(); } ctx.RestoreState(); img = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); _nSCache.SetObjectforKey(img, (NSString)hamburgerKey); return img; }
public Tuple <UIImage, ImageInformation> Get(string key) { ImageInformation imageInformation = null; _imageInformations.TryGetValue(key, out imageInformation); var image = (UIImage)_cache.ObjectForKey(new NSString(key)); return(new Tuple <UIImage, ImageInformation>(image, imageInformation)); }
public UIImage GetCachedImage(NSUrl url) { if (url != null) { return(imageCache.ObjectForKey(new NSString(url.AbsoluteString)) as UIImage); } else { return(new UIImage()); } }
private byte[] GetExisting(string cacheName) { if (!String.IsNullOrEmpty(cacheName)) { var cachedObject = _cache.ObjectForKey(new NSString(cacheName)) as NSData; if (cachedObject != null) { return(cachedObject.ToArray()); } } return(null); }
public void ComposeCell(DataItemCollectionViewCell cell, DataItem dataItem) { var operationQueue = OperationQueueForCell(cell); operationQueue.CancelAllOperations(); cell.RepresentedDataItem = dataItem; cell.Label.Text = dataItem.Title; cell.ImageView.Alpha = 1f; cell.ImageView.Image = (UIImage)processedImageCache.ObjectForKey((NSString)dataItem.Identifier); if (cell.ImageView.Image != null) { return; } var processImageOperation = new NSBlockOperation(); processImageOperation.AddExecutionBlock(() => { if (processImageOperation.IsCancelled) { return; } UIImage image = null; DispatchQueue.MainQueue.DispatchSync(() => { image = ProcessImageNamed(dataItem.ImageName); }); if (image == null) { return; } processedImageCache.SetObjectforKey(image, (NSString)dataItem.Identifier); NSOperationQueue.MainQueue.AddOperation(() => { if (cell.RepresentedDataItem == null) { return; } cell.ImageView.Alpha = 0f; cell.ImageView.Image = image; UIView.Animate(0.25, () => cell.ImageView.Alpha = 1f); }); }); operationQueue.AddOperation(processImageOperation); }
private UIImage GetIconForText(string text, UIImage baseImage) { var nsText = new NSString(text); var icon = iconCache.ObjectForKey(nsText); if (icon != null) { return((UIImage)icon); } var font = UIFont.BoldSystemFontOfSize(12); var size = baseImage.Size; UIGraphics.BeginImageContextWithOptions(size, false, 0.0f); baseImage.Draw(new CGRect(0, 0, size.Width, size.Height)); var rect = new CGRect(0, 0, baseImage.Size.Width, baseImage.Size.Height); var paragraphStyle = NSParagraphStyle.Default; var attributes = new UIStringAttributes(NSDictionary.FromObjectsAndKeys( objects: new NSObject[] { font, paragraphStyle, options.RendererTextColor.ToUIColor() }, keys: new NSObject[] { UIStringAttributeKey.Font, UIStringAttributeKey.ParagraphStyle, UIStringAttributeKey.ForegroundColor } )); var textSize = nsText.GetSizeUsingAttributes(attributes); var textRect = RectangleFExtensions.Inset(rect, (rect.Size.Width - textSize.Width) / 3, (rect.Size.Height - textSize.Height) / 1); nsText.DrawString(RectangleFExtensions.Integral(textRect), attributes); var newImage = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); iconCache.SetObjectforKey(newImage, nsText); return(newImage); }
UIImage FetchImageFromURL(NSUrl url) { var image = (UIImage)imageCache.ObjectForKey(url); if (image != null) { return(image); } else { // MARK: Do not cast the cache to Image as it will crash. // So, get a standard NSObject first and if it's not null then // cast to image. var urlObj = NSObject.FromObject(url.AbsoluteString); var obj = networkImageRequested.ObjectForKey(urlObj); if (obj != null) { return(null); } else { image = (UIImage)obj; networkImageRequested.SetObjectforKey(url, urlObj); } } NSData imageData = NSData.FromUrl(url); if (imageData == null) { return(null); } dataCache.SetObjectforKey(imageData, url); image = UIImage.LoadFromData(imageData); if (image != null) { imageCache.SetObjectforKey(image, url); return(image); } return(null); }
public Tuple <UIImage, ImageInformation> Get(string key) { if (string.IsNullOrWhiteSpace(key)) { return(null); } var image = (UIImage)_cache.ObjectForKey(new NSString(key)); if (image == null) { return(null); } var imageInformation = GetInfo(key); return(new Tuple <UIImage, ImageInformation>(image, imageInformation)); }
public UIImage FetchThumbnailImageFromURL(NSUrl url) { var thumbnailImage = (UIImage)thumbnailImageCache.ObjectForKey(url); if (thumbnailImage == null) { UIImage image = FetchImageFromURL(url); if (image == null) { return(null); } thumbnailImage = CreateThumbNailWithImage(image); if (thumbnailImage != null) { thumbnailImageCache.SetObjectforKey(thumbnailImage, url); } } return(thumbnailImage); }
public Tuple <NSImage, ImageInformation> Get(string key) { if (string.IsNullOrWhiteSpace(key)) { return(null); } var image = (NSImage)_cache.ObjectForKey(new NSString(key)); if (image == null || image.Handle == IntPtr.Zero) { Remove(key, false); return(null); } var imageInformation = GetInfo(key); return(new Tuple <NSImage, ImageInformation>(image, imageInformation)); }
DataItemViewController DataItemViewControllerForPage(int index) { var dataItem = dataItems [index]; var cachedController = dataItemViewControllerCache.ObjectForKey((NSString)dataItem.Identifier) as DataItemViewController; if (cachedController == null) { var viewController = (DataItemViewController)Storyboard.InstantiateViewController(DataItemViewController.StoryboardIdentifier); if (viewController == null) { throw new Exception("Unable to instantiate a DataItemViewController."); } viewController.ConfigureWithDataItem(dataItem); dataItemViewControllerCache.SetObjectforKey(viewController, (NSString)dataItem.Identifier); return(viewController); } else { return(cachedController); } }
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) { UITableViewCell cell; if (chatMessageList[indexPath.Row].Type == 1) { cell = tableView.DequeueReusableCell("MyImage", indexPath); cell.Transform = CGAffineTransform.MakeRotation((nfloat)Math.PI); var iv_MyImageView = (UIImageView)cell.ContentView.Subviews[0]; iv_MyImageView.TranslatesAutoresizingMaskIntoConstraints = true; var DocUrl = Environment.GetFolderPath(Environment.SpecialFolder.Personal); var FilePath = (NSString)System.IO.Path.Combine(DocUrl, chatMessageList[indexPath.Row].Message); try { //從快取取出 var Image = (UIImage)imageCache.ObjectForKey(FilePath); if (Image == null) { var ImageData = NSData.FromFile(FilePath); Image = new UIImage(ImageData); //存入快取 imageCache.SetObjectforKey(Image, FilePath); } nfloat ih; rawValueDictionary.TryGetValue($"{chatMessageList[indexPath.Row].Message}ih", out ih); if (ih == 0) { if (Image.Size.Width > contentMaxWidth) { rawValueDictionary[$"{chatMessageList[indexPath.Row].Message}ih"] = Image.Size.Height / (Image.Size.Width / contentMaxWidth); } else { rawValueDictionary[$"{chatMessageList[indexPath.Row].Message}ih"] = Image.Size.Height * (contentMaxWidth / Image.Size.Width); } } var IVFrame = iv_MyImageView.Frame; IVFrame.Width = contentMaxWidth; IVFrame.Height = rawValueDictionary[$"{chatMessageList[indexPath.Row].Message}ih"]; IVFrame.X = tableView.Frame.Width - contentMaxWidth - 10; iv_MyImageView.Frame = IVFrame; iv_MyImageView.Image = Image; } catch (Exception e) { Console.WriteLine(e.Message); } return(cell); } PaddingLabel l_Message; if (chatMessageList[indexPath.Row].Isme) { cell = tableView.DequeueReusableCell("Right", indexPath); l_Message = (PaddingLabel)cell.ContentView.Subviews[0]; } else { cell = tableView.DequeueReusableCell("Left", indexPath); l_Message = (PaddingLabel)cell.ContentView.Subviews[2]; } cell.Transform = CGAffineTransform.MakeRotation((nfloat)Math.PI); l_Message.TranslatesAutoresizingMaskIntoConstraints = true; l_Message.Text = chatMessageList[indexPath.Row].Message; nfloat lh; rawValueDictionary.TryGetValue($"{chatMessageList[indexPath.Row].Message}lh", out lh); if (lh == 0) { NSString tempText = (NSString)l_Message.Text; var rect = tempText.GetBoundingRect( new CGSize(contentMaxWidth - 40, 1000), NSStringDrawingOptions.UsesLineFragmentOrigin, new UIStringAttributes() { Font = l_Message.Font }, null); rawValueDictionary[$"{chatMessageList[indexPath.Row].Message}lh"] = rect.Height + 40; rawValueDictionary[$"{chatMessageList[indexPath.Row].Message}lw"] = rect.Width + 42; if (chatMessageList[indexPath.Row].Isme) { rawValueDictionary[$"{chatMessageList[indexPath.Row].Message}lx"] = tableView.Frame.Width - rect.Width - 52; } else { rawValueDictionary[$"{chatMessageList[indexPath.Row].Message}lx"] = cell.ContentView.Subviews[0].Frame.Width + 20; } } var Frame = l_Message.Frame; Frame.Height = rawValueDictionary[$"{chatMessageList[indexPath.Row].Message}lh"]; Frame.Width = rawValueDictionary[$"{chatMessageList[indexPath.Row].Message}lw"]; Frame.X = rawValueDictionary[$"{chatMessageList[indexPath.Row].Message}lx"]; l_Message.Frame = Frame; l_Message.Layer.CornerRadius = 20; l_Message.Layer.MasksToBounds = true; if (!isLoading && !isFinishLoad && indexPath.Row > chatMessageList.Count * 0.7) { isLoading = true; ReadData(); } return(cell); }
public UIImage Get(string key) { return((UIImage)_cache.ObjectForKey(new NSString(key))); }