@@ -10,7 +10,6 @@ import android.graphics.Color
1010import android.graphics.drawable.Drawable
1111import android.os.Build
1212import android.os.Process
13- import android.view.KeyEvent
1413import android.view.Menu
1514import android.view.MenuItem
1615import android.view.View
@@ -22,6 +21,10 @@ interface ActivityExtensions: ServiceExtensions {
2221
2322 /* *
2423 * If function is supported, call it safely.
24+ *
25+ * @param minSDK The minimum supported SDK
26+ * @param block Methods
27+ * @return Only if not supported, return null
2528 */
2629 fun ifSupportSDK (minSDK : Int , block : () -> Unit ) : (() -> Unit )? {
2730 if (Build .VERSION .SDK_INT >= minSDK) {
@@ -45,13 +48,17 @@ interface ActivityExtensions: ServiceExtensions {
4548
4649 /* *
4750 * Tint color for a menu item
51+ *
52+ * @param color Color value
4853 */
4954 fun MenuItem.tintColor (color : Int ) {
5055 this .icon?.setTint(color)
5156 }
5257
5358 /* *
5459 * Tint color for all menu items
60+ *
61+ * @param color Color value
5562 */
5663 fun Menu.tintItemsColor (color : Int ) {
5764 for (i in 0 .. size() - 1 ) getItem(i).tintColor(color)
@@ -130,6 +137,11 @@ interface ActivityExtensions: ServiceExtensions {
130137 /* *
131138 * If you use Activity.runWithPermissions to request permission,
132139 * please call this method in onRequestPermissionsResult method of your activity
140+ *
141+ * @param requestCode The result of request code
142+ * @param permissions Permissions string array
143+ * @param grantResults Permissions result array
144+ * @param deniedCallback Denied permission callback
133145 */
134146 fun Activity.handleOnRequestPermissionsResult (requestCode : Int ,
135147 permissions : Array <out String >,
@@ -146,6 +158,12 @@ interface ActivityExtensions: ServiceExtensions {
146158
147159 // Kotlin-style builders
148160
161+ /* *
162+ * Build AlertDialog in Activity
163+ *
164+ * @param process The process of building AlertDialog
165+ * @see android.app.AlertDialog
166+ */
149167 fun Activity.buildAlertDialog (process : AlertDialog .Builder .() -> Unit ) : AlertDialog {
150168 val builder = AlertDialog .Builder (this )
151169 builder.process()
@@ -212,26 +230,80 @@ interface ActivityExtensions: ServiceExtensions {
212230 get() { throw NoSuchMethodException (" View res id getter is not supported" )}
213231 set(value) { this .setView(value) }
214232
233+ /* *
234+ * Set ok button for AlertDialog
235+ *
236+ * @param onClick onClick callback
237+ */
238+ fun AlertDialog.Builder.okButton (onClick : (DialogInterface , Int ) -> Unit = {_, _ -> }) {
239+ setPositiveButton(android.R .string.ok, onClick)
240+ }
241+
242+ /* *
243+ * Set cancel button for AlertDialog
244+ *
245+ * @param onClick onClick callback
246+ */
247+ fun AlertDialog.Builder.cancelButton (onClick : (DialogInterface , Int ) -> Unit = {_, _ -> }) {
248+ setNegativeButton(android.R .string.cancel, onClick)
249+ }
250+
251+ /* *
252+ * Set positive button for AlertDialog
253+ *
254+ * @param textId Text resource id
255+ * @param onClick onClick callback
256+ */
215257 fun AlertDialog.Builder.positiveButton (textId : Int , onClick : (DialogInterface , Int ) -> Unit ) {
216258 setPositiveButton(textId, onClick)
217259 }
218260
261+ /* *
262+ * Set positive button for AlertDialog
263+ *
264+ * @param text Text string
265+ * @param onClick onClick callback
266+ */
219267 fun AlertDialog.Builder.positiveButton (text : String , onClick : (DialogInterface , Int ) -> Unit ) {
220268 setPositiveButton(text, onClick)
221269 }
222270
271+ /* *
272+ * Set negative button for AlertDialog
273+ *
274+ * @param textId Text resource id
275+ * @param onClick onClick callback
276+ */
223277 fun AlertDialog.Builder.negativeButton (textId : Int , onClick : (DialogInterface , Int ) -> Unit ) {
224278 setNegativeButton(textId, onClick)
225279 }
226280
281+ /* *
282+ * Set negative button for AlertDialog
283+ *
284+ * @param text Text string
285+ * @param onClick onClick callback
286+ */
227287 fun AlertDialog.Builder.negativeButton (text : String , onClick : (DialogInterface , Int ) -> Unit ) {
228288 setNegativeButton(text, onClick)
229289 }
230290
291+ /* *
292+ * Set neutral button for AlertDialog
293+ *
294+ * @param textId Text resource id
295+ * @param onClick onClick callback
296+ */
231297 fun AlertDialog.Builder.neutralButton (textId : Int , onClick : (DialogInterface , Int ) -> Unit ) {
232298 setNeutralButton(textId, onClick)
233299 }
234300
301+ /* *
302+ * Set neutral button for AlertDialog
303+ *
304+ * @param text Text string
305+ * @param onClick onClick callback
306+ */
235307 fun AlertDialog.Builder.neutralButton (text : String , onClick : (DialogInterface , Int ) -> Unit ) {
236308 setNeutralButton(text, onClick)
237309 }
0 commit comments