1/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *       http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17@file:Suppress("NOTHING_TO_INLINE")
18
19package androidx.core.widget
20
21import android.content.Context
22import android.widget.Toast
23import androidx.annotation.StringRes
24
25/**
26 * Creates and shows a [Toast] with the given [text]
27 *
28 * @param duration Toast duration, defaults to [Toast.LENGTH_SHORT]
29 */
30inline fun Context.toast(text: CharSequence, duration: Int = Toast.LENGTH_SHORT): Toast {
31    return Toast.makeText(this, text, duration).apply { show() }
32}
33
34/**
35 * Creates and shows a [Toast] with text from a resource
36 *
37 * @param resId Resource id of the string resource to use
38 * @param duration Toast duration, defaults to [Toast.LENGTH_SHORT]
39 */
40inline fun Context.toast(@StringRes resId: Int, duration: Int = Toast.LENGTH_SHORT): Toast {
41    return Toast.makeText(this, resId, duration).apply { show() }
42}
43