-
-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get FragmentActivity from ContextWrapper
- Loading branch information
Showing
2 changed files
with
18 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
cropper/src/main/java/com/canhub/cropper/utils/GetFragmentActivityFromContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.canhub.cropper.utils | ||
|
||
import android.content.Context | ||
import android.content.ContextWrapper | ||
import androidx.fragment.app.FragmentActivity | ||
|
||
internal fun getFragmentActivityFrom(context: Context): FragmentActivity { | ||
var unpackContext = context | ||
while (unpackContext !is FragmentActivity && unpackContext is ContextWrapper) { | ||
unpackContext = unpackContext.baseContext | ||
} | ||
|
||
return unpackContext as FragmentActivity | ||
} |