private static UICollectionViewFlowLayout CollectionViewFlowLayoutForOrientation (UIInterfaceOrientation orientation, GMImagePickerController picker) { nfloat screenWidth; nfloat screenHeight; //Ipad popover is not affected by rotation! if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) { screenWidth = picker.View.Bounds.Width; screenHeight = picker.View.Bounds.Height; } else { if (UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeLeft || UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeRight) { screenHeight = picker.View.Bounds.Width; screenWidth = picker.View.Bounds.Height; } else { screenWidth = picker.View.Bounds.Width; screenHeight = picker.View.Bounds.Height; } } if ((UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) || (UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.Portrait || UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.PortraitUpsideDown)) { if (_portraitLayout == null) { var cellTotalUsableWidth = screenWidth - (picker.ColsInPortrait - 1) * picker.MinimumInteritemSpacing; var itemSize = new CGSize (cellTotalUsableWidth / picker.ColsInPortrait, cellTotalUsableWidth / picker.ColsInPortrait); var cellTotalUsedWidth = (double)itemSize.Width * picker.ColsInPortrait; var spaceTotalWidth = (double)screenWidth - cellTotalUsedWidth; var spaceWidth = spaceTotalWidth / (picker.ColsInPortrait - 1); _portraitLayout = new UICollectionViewFlowLayout { MinimumInteritemSpacing = picker.MinimumInteritemSpacing, ItemSize = itemSize, MinimumLineSpacing = (nfloat) spaceWidth }; } return _portraitLayout; } else { if (_landscapeLayout == null) { var cellTotalUsableWidth = screenHeight - (picker.ColsInLandscape - 1) * picker.MinimumInteritemSpacing; var itemSize = new CGSize (cellTotalUsableWidth / picker.ColsInLandscape, cellTotalUsableWidth / picker.ColsInLandscape); var cellTotalUsedWidth = (double)itemSize.Width * picker.ColsInLandscape; var spaceTotalWidth = (double)screenHeight - cellTotalUsedWidth; var spaceWidth = spaceTotalWidth / (picker.ColsInLandscape - 1); _landscapeLayout = new UICollectionViewFlowLayout { MinimumInteritemSpacing = picker.MinimumInteritemSpacing, ItemSize = itemSize, MinimumLineSpacing = (nfloat) spaceWidth }; } return _landscapeLayout; } }
public GMGridViewController (GMImagePickerController picker) : base(CollectionViewFlowLayoutForOrientation(UIApplication.SharedApplication.StatusBarOrientation, picker)) { //Custom init. The picker contains custom information to create the FlowLayout this._picker = picker; //Compute the thumbnail pixel size: var scale = UIScreen.MainScreen.Scale; var layout = (UICollectionViewFlowLayout)Layout; AssetGridThumbnailSize = new CGSize (layout.ItemSize.Width * scale, layout.ItemSize.Height * scale); CollectionView.AllowsMultipleSelection = _picker.AllowsMultipleSelection; CollectionView.RegisterClassForCell (typeof(GMGridViewCell), GMGridViewCollectionViewSource.GMGridViewCellIdentifier); PreferredContentSize = GMImagePickerController.PopoverContentSize; }
public GMGridViewController(GMImagePickerController picker) : base(CollectionViewFlowLayoutForOrientation(UIApplication.SharedApplication.StatusBarOrientation, picker)) { //Custom init. The picker contains custom information to create the FlowLayout _picker = picker; //Compute the thumbnail pixel size: var scale = UIScreen.MainScreen.Scale; var layout = (UICollectionViewFlowLayout)Layout; AssetGridThumbnailSize = new CGSize(layout.ItemSize.Width * scale, layout.ItemSize.Height * scale); CollectionView.AllowsMultipleSelection = _picker.AllowsMultipleSelection; CollectionView.RegisterClassForCell(typeof(GMGridViewCell), GMGridViewCollectionViewSource.GMGridViewCellIdentifier); PreferredContentSize = GMImagePickerController.PopoverContentSize; }
private static UICollectionViewFlowLayout CollectionViewFlowLayoutForOrientation(UIInterfaceOrientation orientation, GMImagePickerController picker) { nfloat screenWidth; nfloat screenHeight; //Ipad popover is not affected by rotation! if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) { screenWidth = picker.View.Bounds.Width; screenHeight = picker.View.Bounds.Height; } else { var insets = UIEdgeInsets.Zero; if (picker.View.RespondsToSelector(new ObjCRuntime.Selector("safeAreaInsets"))) { insets = picker.View.SafeAreaInsets; } var horizontalInsets = insets.Right + insets.Left; var verticalInsets = insets.Bottom + insets.Top; if (UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeLeft || UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeRight) { screenHeight = picker.View.Bounds.Width - horizontalInsets; screenWidth = picker.View.Bounds.Height - verticalInsets; } else { screenWidth = picker.View.Bounds.Width - horizontalInsets; screenHeight = picker.View.Bounds.Height - verticalInsets; } } if ((UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) || (UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.Portrait || UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.PortraitUpsideDown)) { if (_portraitLayout == null) { var cellTotalUsableWidth = screenWidth - (picker.ColsInPortrait - 1) * picker.MinimumInteritemSpacing; var itemSize = new CGSize(cellTotalUsableWidth / picker.ColsInPortrait, cellTotalUsableWidth / picker.ColsInPortrait); var cellTotalUsedWidth = (double)itemSize.Width * picker.ColsInPortrait; var spaceTotalWidth = screenWidth - cellTotalUsedWidth; var spaceWidth = spaceTotalWidth / (picker.ColsInPortrait - 1); _portraitLayout = new UICollectionViewFlowLayout { MinimumInteritemSpacing = picker.MinimumInteritemSpacing, ItemSize = itemSize, MinimumLineSpacing = (nfloat)spaceWidth }; if (_portraitLayout.RespondsToSelector(new ObjCRuntime.Selector("sectionInsetReference"))) { _portraitLayout.SectionInsetReference = UICollectionViewFlowLayoutSectionInsetReference.SafeArea; } } return(_portraitLayout); } else { if (_landscapeLayout == null) { var cellTotalUsableWidth = screenHeight - (picker.ColsInLandscape - 1) * picker.MinimumInteritemSpacing; var itemSize = new CGSize(cellTotalUsableWidth / picker.ColsInLandscape, cellTotalUsableWidth / picker.ColsInLandscape); var cellTotalUsedWidth = (double)itemSize.Width * picker.ColsInLandscape; var spaceTotalWidth = screenHeight - cellTotalUsedWidth; var spaceWidth = spaceTotalWidth / (picker.ColsInLandscape - 1); _landscapeLayout = new UICollectionViewFlowLayout { MinimumInteritemSpacing = picker.MinimumInteritemSpacing, ItemSize = itemSize, MinimumLineSpacing = (nfloat)spaceWidth }; if (_landscapeLayout.RespondsToSelector(new ObjCRuntime.Selector("sectionInsetReference"))) { _landscapeLayout.SectionInsetReference = UICollectionViewFlowLayoutSectionInsetReference.SafeArea; } } return(_landscapeLayout); } }
private static UICollectionViewFlowLayout CollectionViewFlowLayoutForOrientation(UIInterfaceOrientation orientation, GMImagePickerController picker) { nfloat screenWidth; nfloat screenHeight; //Ipad popover is not affected by rotation! if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) { screenWidth = picker.View.Bounds.Width; screenHeight = picker.View.Bounds.Height; } else { if (UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeLeft || UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeRight) { screenHeight = picker.View.Bounds.Width; screenWidth = picker.View.Bounds.Height; } else { screenWidth = picker.View.Bounds.Width; screenHeight = picker.View.Bounds.Height; } } if ((UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) || (UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.Portrait || UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.PortraitUpsideDown)) { if (_portraitLayout == null) { var cellTotalUsableWidth = screenWidth - (picker.ColsInPortrait - 1) * picker.MinimumInteritemSpacing; var itemSize = new CGSize(cellTotalUsableWidth / picker.ColsInPortrait, cellTotalUsableWidth / picker.ColsInPortrait); var cellTotalUsedWidth = (double)itemSize.Width * picker.ColsInPortrait; var spaceTotalWidth = screenWidth - cellTotalUsedWidth; var spaceWidth = spaceTotalWidth / (picker.ColsInPortrait - 1); _portraitLayout = new UICollectionViewFlowLayout { MinimumInteritemSpacing = picker.MinimumInteritemSpacing, ItemSize = itemSize, MinimumLineSpacing = (nfloat)spaceWidth }; } return(_portraitLayout); } else { if (_landscapeLayout == null) { var cellTotalUsableWidth = screenHeight - (picker.ColsInLandscape - 1) * picker.MinimumInteritemSpacing; var itemSize = new CGSize(cellTotalUsableWidth / picker.ColsInLandscape, cellTotalUsableWidth / picker.ColsInLandscape); var cellTotalUsedWidth = (double)itemSize.Width * picker.ColsInLandscape; var spaceTotalWidth = screenHeight - cellTotalUsedWidth; var spaceWidth = spaceTotalWidth / (picker.ColsInLandscape - 1); _landscapeLayout = new UICollectionViewFlowLayout { MinimumInteritemSpacing = picker.MinimumInteritemSpacing, ItemSize = itemSize, MinimumLineSpacing = (nfloat)spaceWidth }; } return(_landscapeLayout); } }
public override void ViewDidLoad() { base.ViewDidLoad(); _picker = (GMImagePickerController)NavigationController.ParentViewController; View.BackgroundColor = _picker.PickerBackgroundColor; // Navigation bar customization if (!string.IsNullOrWhiteSpace(_picker.CustomNavigationBarPrompt)) { NavigationItem.Prompt = _picker.CustomNavigationBarPrompt; } _imageManager = new PHCachingImageManager(); // Table view aspect TableView.RowHeight = AlbumRowHeight; TableView.SeparatorStyle = UITableViewCellSeparatorStyle.None; TableView.Source = new GMAlbumsViewTableViewSource(this); // Buttons var barButtonItemAttributes = new UITextAttributes { Font = UIFont.FromName(_picker.PickerFontName, _picker.PickerFontHeaderSize) }; var cancelTitle = _picker.CustomCancelButtonTitle ?? "picker.navigation.cancel-button".Translate(defaultValue: "Cancel"); NavigationItem.LeftBarButtonItem = new UIBarButtonItem(cancelTitle, UIBarButtonItemStyle.Plain, Dismiss); if (_picker.UseCustomFontForNavigationBar) { NavigationItem.LeftBarButtonItem.SetTitleTextAttributes(barButtonItemAttributes, UIControlState.Normal); NavigationItem.LeftBarButtonItem.SetTitleTextAttributes(barButtonItemAttributes, UIControlState.Highlighted); } if (_picker.AllowsMultipleSelection) { var doneTitle = _picker.CustomDoneButtonTitle ?? "picker.navigation.done-button".Translate(defaultValue: "Done"); NavigationItem.RightBarButtonItem = new UIBarButtonItem(doneTitle, UIBarButtonItemStyle.Done, FinishPickingAssets); if (_picker.UseCustomFontForNavigationBar) { NavigationItem.RightBarButtonItem.SetTitleTextAttributes(barButtonItemAttributes, UIControlState.Normal); NavigationItem.RightBarButtonItem.SetTitleTextAttributes(barButtonItemAttributes, UIControlState.Highlighted); } NavigationItem.RightBarButtonItem.Enabled = !_picker.AutoDisableDoneButton || _picker.SelectedAssets.Any(); } // Bottom toolbar ToolbarItems = _picker.GetToolbarItems(); // Title Title = _picker.Title ?? "picker.navigation.title".Translate(defaultValue: "Navigation bar default title"); // Fetch PHAssetCollections var topLevelUserCollections = PHCollection.FetchTopLevelUserCollections(null); var smartAlbums = PHAssetCollection.FetchAssetCollections(PHAssetCollectionType.SmartAlbum, PHAssetCollectionSubtype.AlbumRegular, null); _collectionsFetchResults = new List <PHFetchResult> { topLevelUserCollections, smartAlbums }; _collectionsLocalizedTitles = new List <string> { "picker.table.user-albums-header".Translate(defaultValue: "Albums"), "picker.table.smart-albums-header".Translate("Smart Albums") }; UpdateFetchResults(); // Register for changes PHPhotoLibrary.SharedPhotoLibrary.RegisterChangeObserver(this); }
public GMImagePickerDelegate(GMImagePickerController parent) { _parent = parent; }
public override void ViewDidLoad () { base.ViewDidLoad (); _picker = (GMImagePickerController) NavigationController.ParentViewController; View.BackgroundColor = _picker.PickerBackgroundColor; // Navigation bar customization if (!string.IsNullOrWhiteSpace (_picker.CustomNavigationBarPrompt)) { NavigationItem.Prompt = _picker.CustomNavigationBarPrompt; } _imageManager = new PHCachingImageManager (); // Table view aspect TableView.RowHeight = AlbumRowHeight; TableView.SeparatorStyle = UITableViewCellSeparatorStyle.None; TableView.Source = new GMAlbumsViewTableViewSource (this); // Buttons var barButtonItemAttributes = new UITextAttributes { Font = UIFont.FromName(_picker.PickerFontName, _picker.PickerFontHeaderSize) }; var cancelTitle = _picker.CustomCancelButtonTitle ?? "picker.navigation.cancel-button".Translate(defaultValue: "Cancel"); NavigationItem.LeftBarButtonItem = new UIBarButtonItem (cancelTitle, UIBarButtonItemStyle.Plain, Dismiss); if (_picker.UseCustomFontForNavigationBar) { NavigationItem.LeftBarButtonItem.SetTitleTextAttributes(barButtonItemAttributes, UIControlState.Normal); NavigationItem.LeftBarButtonItem.SetTitleTextAttributes(barButtonItemAttributes, UIControlState.Highlighted); } if (_picker.AllowsMultipleSelection) { var doneTitle = _picker.CustomDoneButtonTitle ?? "picker.navigation.done-button".Translate(defaultValue: "Done"); NavigationItem.RightBarButtonItem = new UIBarButtonItem (doneTitle, UIBarButtonItemStyle.Done, FinishPickingAssets); if (_picker.UseCustomFontForNavigationBar) { NavigationItem.RightBarButtonItem.SetTitleTextAttributes(barButtonItemAttributes, UIControlState.Normal); NavigationItem.RightBarButtonItem.SetTitleTextAttributes(barButtonItemAttributes, UIControlState.Highlighted); } NavigationItem.RightBarButtonItem.Enabled = _picker.AutoDisableDoneButton ? _picker.SelectedAssets.Any () : true; } // Bottom toolbar ToolbarItems = _picker.GetToolbarItems(); // Title Title = _picker.Title ?? "picker.navigation.title".Translate(defaultValue: "Navigation bar default title"); // Fetch PHAssetCollections var topLevelUserCollections = PHCollectionList.FetchTopLevelUserCollections(null); var smartAlbums = PHAssetCollection.FetchAssetCollections (PHAssetCollectionType.SmartAlbum, PHAssetCollectionSubtype.AlbumRegular, null); _collectionsFetchResults = new List<PHFetchResult> { topLevelUserCollections, smartAlbums }; _collectionsLocalizedTitles = new List<string> { "picker.table.user-albums-header".Translate (defaultValue: "Albums"), "picker.table.smart-albums-header".Translate("Smart Albums") }; UpdateFetchResults (); // Register for changes PHPhotoLibrary.SharedPhotoLibrary.RegisterChangeObserver(this); if (UIDevice.CurrentDevice.CheckSystemVersion (7, 0)) { EdgesForExtendedLayout = UIRectEdge.None; } }
async partial void ShowGMImagePicker (NSObject sender) { var picker = new GMImagePickerController { Title = "Custom Title", CustomDoneButtonTitle = "Finished", CustomCancelButtonTitle = "Nope", CustomNavigationBarPrompt = "Take a new photo or select an existing one!", ColsInPortrait = 3, ColsInLandscape = 5, MinimumInteritemSpacing = 2.0f, DisplaySelectionInfoToolbar = true, AllowsMultipleSelection = true, ShowCameraButton = true, AutoSelectCameraImages = true, ModalPresentationStyle = UIModalPresentationStyle.Popover, MediaTypes = new [] { PHAssetMediaType.Image }, // Other customizations to play with: //GridSortOrder = SortOrder.Descending, //ConfirmSingleSelection = true, //ConfirmSingleSelectionPrompt = "Do you want to select the image you have chosen?", //PickerBackgroundColor = UIColor.Black, //PickerTextColor = UIColor.White, //ToolbarBarTintColor = UIColor.DarkGray, //ToolbarTextColor = UIColor.White, //ToolbarTintColor = UIColor.Red, //NavigationBarBackgroundColor = UIColor.Black, //NavigationBarTextColor = UIColor.White, //NavigationBarTintColor = UIColor.Red, //PickerFontName = "Verdana", //PickerBoldFontName = "Verdana-Bold", //PickerFontNormalSize = 14.0f, //PickerFontHeaderSize = 17.0f, //PickerStatusBarStyle = UIStatusBarStyle.LightContent, //UseCustomFontForNavigationBar = true, }; // You can limit which galleries are available to browse through picker.CustomSmartCollections = new [] { PHAssetCollectionSubtype.SmartAlbumUserLibrary, PHAssetCollectionSubtype.AlbumRegular }; if (_preselectedAssets != null) { foreach (var asset in _preselectedAssets) { picker.SelectedAssets.Add(asset); } } // Event handling picker.FinishedPickingAssets += Picker_FinishedPickingAssets; picker.Canceled += Picker_Canceled; // Other events to implement in order to influence selection behavior: // Set EventArgs::Cancel flag to true in order to prevent the action from happening picker.ShouldDeselectAsset += (s, e) => { /* allow deselection of (mandatory) assets */ }; picker.ShouldEnableAsset += (s, e) => { /* determine if a specific asset should be enabled */ }; picker.ShouldHighlightAsset += (s, e) => { /* determine if a specific asset should be highlighted */ }; picker.ShouldShowAsset += (s, e) => { /* determine if a specific asset should be displayed */ }; picker.ShouldSelectAsset += (s, e) => { /* determine if a specific asset can be selected */ }; picker.AssetSelected += (s, e) => { /* keep track of individual asset selection */ }; picker.AssetDeselected += (s, e) => { /* keep track of individual asset de-selection */ }; // GMImagePicker can be treated as a PopOver as well: var popPC = picker.PopoverPresentationController; popPC.PermittedArrowDirections = UIPopoverArrowDirection.Any; popPC.SourceView = gmImagePickerButton; popPC.SourceRect = gmImagePickerButton.Bounds; //popPC.BackgroundColor = UIColor.Black; await PresentViewControllerAsync(picker, true); }