Ocean
platform/apple/ios/Utilities.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_PLATFORM_APPLE_IOS_UTILITIES_H
9 #define META_OCEAN_PLATFORM_APPLE_IOS_UTILITIES_H
10 
12 
13 #include "ocean/base/Callback.h"
14 #include "ocean/base/Frame.h"
15 
16 namespace Ocean
17 {
18 
19 namespace Platform
20 {
21 
22 namespace Apple
23 {
24 
25 namespace IOS
26 {
27 
28 /**
29  * This class implements utilitiy functions for Apple iOS platforms.
30  * @ingroup platformappleios
31  */
32 class Utilities
33 {
34  public:
35 
36  /**
37  * Definition of a callback function for picked images.
38  */
40 
41  public:
42 
43  /**
44  * Loads an image from the photo album of the iPhone.
45  * @param callback The callback function which will be called one the image has been loaded
46  *
47  * The following code shows how to use this function:
48  * @code
49  * void onImage(void* image)
50  * {
51  * UIImage* uiImage = (__bridge UIImage*)image;
52  * CGImageRef cgImage = uiImage.CGImage;
53  *
54  * const size_t imageWidth = CGImageGetWidth(cgImage);
55  *
56  * ...
57  * }
58  *
59  * void function()
60  * {
61  * // let's pick an image from the photo album
62  * Utilities::loadImageFromPhotoAlbum(Utilities::OnPickedImageCallback::createStatic(onImage));
63  * }
64  * @endcode
65  */
66  static void loadImageFromPhotoAlbum(const OnPickedImageCallback& callback);
67 
68  /**
69  * Saves an image to the photos album of the iPhone.
70  * Beware: You may need to add a 'NSPhotoLibraryAddUsageDescription' key to the 'Info.plist' file of the application.
71  * @param frame The image to be saved, must be valid
72  * @return True, if succeeded
73  * @see shareImage(), shareImages().
74  */
75  static bool saveImageToPhotosAlbum(const Frame& frame);
76 
77  /**
78  * Shares an image using iOS' Activity view controller.
79  * The controller allows to copy or to share the provided image.<br>
80  * By calling this function, you will see iPhone's default sharing functionality offering to share the provided image.
81  * @param frame The frame to be shared, must be valid
82  * @return True, if the frame could be shared
83  * @see shareImages(), saveImageToPhotosAlbum().
84  */
85  static bool shareImage(const Frame& frame);
86 
87  /**
88  * Shares images using iOS' Activity view controller.
89  * The controller allows to copy or to share the provided images.<br>
90  * By calling this function, you will see iPhone's default sharing functionality offering to share the provided images.
91  * @param frames The frames to be shared, at least one
92  * @return True, if at least one frame could be shared
93  * @see shareImage(), saveImageToPhotosAlbum().
94  */
95  static bool shareImages(const Frames& frames);
96 
97  /**
98  * Shares a text using iOS' Activity view controller.
99  * The controller allows to copy or to share the provided text.<br>
100  * By calling this function, you will see iPhone's default sharing functionality offering to share the provided text.
101  * @param text The text to share, must not be empty
102  * @return True, if the text could be shared
103  * @see shareFile(), shareImage(), saveImageToPhotosAlbum().
104  */
105  static bool shareText(const std::string& text);
106 
107  /**
108  * Shares a file using iOS' Activity view controller.
109  * The controller allows to copy or to share the provided file.<br>
110  * By calling this function, you will see iPhone's default sharing functionality offering to share the provided file.
111  * @param filename The path of the file to be shared, must be valid
112  * @return True, if the file could be shared
113  * @see shareFiles(), shareText(), shareImage(), saveImageToPhotosAlbum().
114  */
115  static bool shareFile(const std::string& filename);
116 
117  /**
118  * Shares several files using iOS' Activity view controller.
119  * The controller allows to copy or to share the provided files.<br>
120  * By calling this function, you will see iPhone's default sharing functionality offering to share the provided file.
121  * @param filenames The paths of the files to be shared, at least one
122  * @return True, if the files could be shared
123  * @see shareFile(), shareText(), shareImage(), saveImageToPhotosAlbum().
124  */
125  static bool shareFiles(const Strings& filenames);
126 
127  /**
128  * Triggers a vibration.
129  * @param intensity The intensity of the vibration, the higher the stronger, with range [0, 2]
130  */
131  static void triggerVibration(unsigned int intensity = 1u);
132 
133  protected:
134 
135  /**
136  * Casts a given frame with arbitrary pixel format to a frame with pixel format with defined channel layout.
137  * Beware: The resulting frame will not be the owner of the image content!
138  * @param frame The frame to cast, must be valid
139  * @return The resulting frame with supported pixel format, an invalid frame if now valid pixel format exists
140  */
141  static Frame castToSupportedPixelFormat(const Frame& frame);
142 };
143 
144 }
145 
146 }
147 
148 }
149 
150 }
151 
152 #endif // META_OCEAN_PLATFORM_APPLE_IOS_UTILITIES_H
This class implements a container for callback functions.
Definition: Callback.h:3456
This class implements Ocean's image class.
Definition: Frame.h:1792
This class implements utilitiy functions for Apple iOS platforms.
Definition: platform/apple/ios/Utilities.h:33
static void loadImageFromPhotoAlbum(const OnPickedImageCallback &callback)
Loads an image from the photo album of the iPhone.
static bool shareFiles(const Strings &filenames)
Shares several files using iOS' Activity view controller.
static Frame castToSupportedPixelFormat(const Frame &frame)
Casts a given frame with arbitrary pixel format to a frame with pixel format with defined channel lay...
Callback< void, void * > OnPickedImageCallback
Definition of a callback function for picked images.
Definition: platform/apple/ios/Utilities.h:39
static bool shareFile(const std::string &filename)
Shares a file using iOS' Activity view controller.
static bool shareImage(const Frame &frame)
Shares an image using iOS' Activity view controller.
static void triggerVibration(unsigned int intensity=1u)
Triggers a vibration.
static bool shareImages(const Frames &frames)
Shares images using iOS' Activity view controller.
static bool saveImageToPhotosAlbum(const Frame &frame)
Saves an image to the photos album of the iPhone.
static bool shareText(const std::string &text)
Shares a text using iOS' Activity view controller.
std::vector< Frame > Frames
Definition of a vector holding padding frames.
Definition: Frame.h:1755
std::vector< std::string > Strings
Definition of a vector holding strings.
Definition: Base.h:162
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15