This repository was archived by the owner on Nov 14, 2018. It is now read-only.
File tree Expand file tree Collapse file tree
src/main/java/androidx/core/view Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818
1919package androidx.core.view
2020
21+ import android.app.Activity
22+ import android.content.ContextWrapper
2123import android.graphics.Bitmap
2224import android.view.View
2325import android.view.ViewGroup
@@ -201,6 +203,22 @@ fun View.toBitmap(config: Bitmap.Config = Bitmap.Config.ARGB_8888): Bitmap {
201203 }
202204}
203205
206+ /* *
207+ * Returns the parent [Activity] of this [View].
208+ *
209+ * If this View is not attached to any [Activity], this method will return null.
210+ */
211+ inline fun <reified T :Activity > View.getParentActivity () : T ? {
212+ var context = this .context
213+ while (context is ContextWrapper ) {
214+ if (context is T ) {
215+ return context
216+ }
217+ context = context.baseContext
218+ }
219+ return null
220+ }
221+
204222/* *
205223 * Returns true when this view's visibility is [View.VISIBLE], false otherwise.
206224 *
You can’t perform that action at this time.
0 commit comments