|
9 | 9 | import android.net.Uri; |
10 | 10 | import android.os.Build; |
11 | 11 | import android.provider.Settings; |
12 | | -import android.view.Gravity; |
13 | | -import android.widget.TextView; |
14 | 12 | import android.widget.Toast; |
15 | 13 |
|
16 | 14 | import androidx.annotation.RequiresApi; |
@@ -128,18 +126,21 @@ public static boolean checkSystemAlertWindowPermission(final Context context) { |
128 | 126 | } |
129 | 127 | } |
130 | 128 |
|
131 | | - public static boolean isPopupEnabled(final Context context) { |
132 | | - return Build.VERSION.SDK_INT < Build.VERSION_CODES.M |
133 | | - || checkSystemAlertWindowPermission(context); |
134 | | - } |
135 | | - |
136 | | - public static void showPopupEnablementToast(final Context context) { |
137 | | - final Toast toast = |
138 | | - Toast.makeText(context, R.string.msg_popup_permission, Toast.LENGTH_LONG); |
139 | | - final TextView messageView = toast.getView().findViewById(android.R.id.message); |
140 | | - if (messageView != null) { |
141 | | - messageView.setGravity(Gravity.CENTER); |
| 129 | + /** |
| 130 | + * Determines whether the popup is enabled, and if it is not, starts the system activity to |
| 131 | + * request the permission with {@link #checkSystemAlertWindowPermission(Context)} and shows a |
| 132 | + * toast to the user explaining why the permission is needed. |
| 133 | + * |
| 134 | + * @param context the Android context |
| 135 | + * @return whether the popup is enabled |
| 136 | + */ |
| 137 | + public static boolean isPopupEnabledElseAsk(final Context context) { |
| 138 | + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M |
| 139 | + || checkSystemAlertWindowPermission(context)) { |
| 140 | + return true; |
| 141 | + } else { |
| 142 | + Toast.makeText(context, R.string.msg_popup_permission, Toast.LENGTH_LONG).show(); |
| 143 | + return false; |
142 | 144 | } |
143 | | - toast.show(); |
144 | 145 | } |
145 | 146 | } |
0 commit comments