|
16 | 16 |
|
17 | 17 | package com.otaupdater.utils; |
18 | 18 |
|
19 | | -import android.app.Activity; |
20 | 19 | import android.app.AlertDialog; |
21 | 20 | import android.content.Context; |
22 | 21 | import android.content.DialogInterface; |
|
30 | 29 | import android.provider.Settings; |
31 | 30 | import android.telephony.TelephonyManager; |
32 | 31 | import android.util.Log; |
33 | | -import android.view.View; |
34 | | -import android.widget.Toast; |
35 | 32 |
|
36 | 33 | import com.google.android.gms.common.ConnectionResult; |
37 | 34 | import com.google.android.gms.common.GooglePlayServicesUtil; |
@@ -63,6 +60,8 @@ public class Utils { |
63 | 60 | private static final Random random = new SecureRandom(); |
64 | 61 | private static final SimpleDateFormat OTA_DATE = new SimpleDateFormat("yyyyMMdd-kkmm", Locale.US); |
65 | 62 |
|
| 63 | + private static Boolean cachedPlayServicesCheck = null; |
| 64 | + |
66 | 65 | private Utils() { } |
67 | 66 |
|
68 | 67 | public static int getAppVersion(Context ctx) { |
@@ -139,52 +138,57 @@ public static String hmac(String str, String key) { |
139 | 138 | return null; |
140 | 139 | } |
141 | 140 |
|
142 | | - public static void toastWrapper(final Activity activity, final CharSequence text, final int duration) { |
143 | | - activity.runOnUiThread(new Runnable() { |
144 | | - @Override public void run() { |
145 | | - Toast.makeText(activity, text, duration).show(); |
146 | | - } |
147 | | - }); |
148 | | - } |
149 | | - |
150 | | - public static void toastWrapper(final Activity activity, final int resId, final int duration) { |
151 | | - activity.runOnUiThread(new Runnable() { |
152 | | - @Override public void run() { |
153 | | - Toast.makeText(activity, resId, duration).show(); |
154 | | - } |
155 | | - }); |
156 | | - } |
157 | | - |
158 | | - public static void toastWrapper(final View view, final CharSequence text, final int duration) { |
159 | | - view.post(new Runnable() { |
160 | | - @Override public void run() { |
161 | | - Toast.makeText(view.getContext(), text, duration).show(); |
162 | | - } |
163 | | - }); |
164 | | - } |
165 | | - |
166 | | - public static void toastWrapper(final View view, final int resId, final int duration) { |
167 | | - view.post(new Runnable() { |
168 | | - @Override public void run() { |
169 | | - Toast.makeText(view.getContext(), resId, duration).show(); |
170 | | - } |
171 | | - }); |
172 | | - } |
| 141 | +// public static void toastWrapper(final Activity activity, final CharSequence text, final int duration) { |
| 142 | +// activity.runOnUiThread(new Runnable() { |
| 143 | +// @Override public void run() { |
| 144 | +// Toast.makeText(activity, text, duration).show(); |
| 145 | +// } |
| 146 | +// }); |
| 147 | +// } |
| 148 | +// |
| 149 | +// public static void toastWrapper(final Activity activity, final int resId, final int duration) { |
| 150 | +// activity.runOnUiThread(new Runnable() { |
| 151 | +// @Override public void run() { |
| 152 | +// Toast.makeText(activity, resId, duration).show(); |
| 153 | +// } |
| 154 | +// }); |
| 155 | +// } |
| 156 | +// |
| 157 | +// public static void toastWrapper(final View view, final CharSequence text, final int duration) { |
| 158 | +// view.post(new Runnable() { |
| 159 | +// @Override public void run() { |
| 160 | +// Toast.makeText(view.getContext(), text, duration).show(); |
| 161 | +// } |
| 162 | +// }); |
| 163 | +// } |
| 164 | +// |
| 165 | +// public static void toastWrapper(final View view, final int resId, final int duration) { |
| 166 | +// view.post(new Runnable() { |
| 167 | +// @Override public void run() { |
| 168 | +// Toast.makeText(view.getContext(), resId, duration).show(); |
| 169 | +// } |
| 170 | +// }); |
| 171 | +// } |
173 | 172 |
|
174 | 173 | public static boolean checkPlayServices(Context ctx) { |
175 | | - int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(ctx); |
176 | | - if (resultCode != ConnectionResult.SUCCESS) { |
177 | | - if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) { |
178 | | - Log.v(Config.LOG_TAG + "checkPlayServices", "Play Services error: " + GooglePlayServicesUtil.getErrorString(resultCode)); |
| 174 | + if (cachedPlayServicesCheck == null) { |
| 175 | + int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(ctx); |
| 176 | + if (resultCode == ConnectionResult.SUCCESS) { |
| 177 | + cachedPlayServicesCheck = true; |
| 178 | + } else { |
| 179 | + if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) { |
| 180 | + Log.v(Config.LOG_TAG + "checkPlayServices", "Play Services error: " + GooglePlayServicesUtil.getErrorString(resultCode)); |
179 | 181 | // if (ctx instanceof Activity) { |
180 | 182 | // GooglePlayServicesUtil.getErrorDialog(resultCode, (Activity) ctx, REQUEST_CODE_RECOVER_PLAY_SERVICES).show(); |
181 | 183 | // } |
182 | | - } else { |
183 | | - Log.v(Config.LOG_TAG + "checkPlayServices", "Device not supported"); |
| 184 | + } else { |
| 185 | + Log.v(Config.LOG_TAG + "checkPlayServices", "Device not supported"); |
| 186 | + } |
| 187 | + cachedPlayServicesCheck = false; |
184 | 188 | } |
185 | | - return false; |
186 | 189 | } |
187 | | - return true; |
| 190 | + |
| 191 | + return cachedPlayServicesCheck; |
188 | 192 | } |
189 | 193 |
|
190 | 194 | public static boolean dataAvailable(Context ctx) { |
|
0 commit comments