-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
73 additions
and
68 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
32 changes: 32 additions & 0 deletions
32
...gramslibrary/src/main/java/com/stonefacesoft/pictogramslibrary/utils/ValidateContext.java
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,32 @@ | ||
package com.stonefacesoft.pictogramslibrary.utils; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
|
||
public class ValidateContext { | ||
|
||
|
||
public static boolean isValidContextFromGlide(Context context) { | ||
Activity activity = getmActivityFromContext(context); | ||
if (activity == null){ | ||
return false;} | ||
return !isActivityDestroyed(activity); | ||
} | ||
|
||
/** | ||
* @return call the activity by context and return that | ||
*/ | ||
private static Activity getmActivityFromContext(Context context) { | ||
if (context instanceof Activity) { | ||
return (Activity) context; | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* @return show if the activity exist or not. | ||
*/ | ||
private static boolean isActivityDestroyed(Activity activity) { | ||
return activity.isDestroyed() || activity.isFinishing() || activity.isChangingConfigurations(); | ||
} | ||
} |