Java Code Examples for com.gianlu.commonutils.CommonUtils#isDebug()
The following examples show how to use
com.gianlu.commonutils.CommonUtils#isDebug() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PyxDiscoveryApi.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 6 votes |
public final void getWelcomeMessage(@Nullable Activity activity, @NonNull Pyx.OnResult<String> listener) { String cached = Prefs.getString(PK.WELCOME_MSG_CACHE, null); if (cached != null && !CommonUtils.isDebug()) { long age = Prefs.getLong(PK.WELCOME_MSG_CACHE_AGE, 0); if (System.currentTimeMillis() - age < TimeUnit.HOURS.toMillis(12)) { listener.onDone(cached); return; } } executor.execute(new LifecycleAwareRunnable(handler, activity == null ? listener : activity) { @Override public void run() { try { JSONObject obj = new JSONObject(requestSync(WELCOME_MSG_URL)); final String msg = obj.getString("msg"); Prefs.putString(PK.WELCOME_MSG_CACHE, msg); Prefs.putLong(PK.WELCOME_MSG_CACHE_AGE, System.currentTimeMillis()); post(() -> listener.onDone(msg)); } catch (JSONException | IOException ex) { post(() -> listener.onException(ex)); } } }); }
Example 2
Source File: Toaster.java From CommonUtils with Apache License 2.0 | 5 votes |
public void show(@NonNull Context context) { if (shown) { if (CommonUtils.isDebug()) System.out.println("Skipping toast, already shown!"); return; } if (!DialogUtils.isContextValid(context)) { if (CommonUtils.isDebug()) System.out.println("Skipping toast, context is invalid: " + context); return; } if (msg == null) { if (msgRes != 0) { msg = context.getString(msgRes, args); msgRes = 0; args = null; } else { throw new IllegalArgumentException("Missing toast message!"); } } final int duration; if (msg.length() > 48) duration = Toast.LENGTH_LONG; else duration = Toast.LENGTH_SHORT; Runnable action = () -> { if (DialogUtils.isContextValid(context)) Toast.makeText(context, msg, duration).show(); }; if (Looper.myLooper() == Looper.getMainLooper()) action.run(); else handler.post(action); Log.v(TAG, buildLogMessage(context)); shown = true; }
Example 3
Source File: TrackersListFetch.java From Aria2App with GNU General Public License v3.0 | 5 votes |
public void getTrackers(@NonNull Type type, @Nullable Activity activity, @NonNull Listener listener) { if (Prefs.has(PK.TRACKERS_LIST_CACHE) && !CommonUtils.isDebug()) { long age = Prefs.getLong(PK.TRACKERS_LIST_CACHE_AGE, 0); if (System.currentTimeMillis() - age < TimeUnit.DAYS.toMillis(1)) { Set<String> set = Prefs.getSet(PK.TRACKERS_LIST_CACHE, null); if (set != null && set.size() > 0) listener.onDone(new ArrayList<>(set)); } } executorService.execute(new LifecycleAwareRunnable(handler, activity == null ? listener : activity) { @Override public void run() { try { Response resp = client.newCall(new Request.Builder().get().url(String.format(BASE_URL, type.getId())).build()).execute(); if (resp.code() != 200) throw new IOException(resp.code() + ": " + resp.message()); ResponseBody body = resp.body(); if (body == null) throw new IOException("Body is empty!"); List<String> trackers = new ArrayList<>(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(body.byteStream()))) { String line; while ((line = reader.readLine()) != null && !line.isEmpty()) trackers.add(line); } Prefs.putLong(PK.TRACKERS_LIST_CACHE_AGE, System.currentTimeMillis()); Prefs.putSet(PK.TRACKERS_LIST_CACHE, new HashSet<>(trackers)); post(() -> listener.onDone(trackers)); } catch (IOException ex) { post(() -> listener.onFailed(ex)); } } }); }
Example 4
Source File: PyxDiscoveryApi.java From PretendYoureXyzzyAndroid with GNU General Public License v3.0 | 5 votes |
private void loadDiscoveryApiServersSync() throws IOException, JSONException { try { if (!CommonUtils.isDebug() && Prefs.has(PK.API_SERVERS) && !JsonStoring.intoPrefs().isJsonArrayEmpty(PK.API_SERVERS)) { long age = Prefs.getLong(PK.API_SERVERS_CACHE_AGE, 0); if (System.currentTimeMillis() - age < TimeUnit.HOURS.toMillis(6)) return; } JSONArray array = new JSONArray(requestSync(DISCOVERY_API_LIST)); if (array.length() > 0) Pyx.Server.parseAndSave(array); } catch (IOException | JSONException ex) { if (JsonStoring.intoPrefs().isJsonArrayEmpty(PK.API_SERVERS)) throw ex; else Log.e(TAG, "Failed loading servers, but list isn't empty.", ex); } }
Example 5
Source File: Toaster.java From CommonUtils with Apache License 2.0 | 4 votes |
@Override protected void finalize() throws Throwable { super.finalize(); if (!shown && CommonUtils.isDebug()) System.err.println("Leaked " + this); }
Example 6
Source File: UpdaterFramework.java From Aria2App with GNU General Public License v3.0 | 4 votes |
private static void debug(String msg) { if (CommonUtils.isDebug() && ThisApplication.DEBUG_UPDATER) System.out.println(UpdaterFramework.class.getSimpleName() + ": " + msg); }
Example 7
Source File: PayloadProvider.java From Aria2App with GNU General Public License v3.0 | 4 votes |
private static void debug(String msg) { if (CommonUtils.isDebug() && ThisApplication.DEBUG_UPDATER) System.out.println(PayloadProvider.class.getSimpleName() + ": " + msg); }
Example 8
Source File: NotificationService.java From Aria2App with GNU General Public License v3.0 | 4 votes |
private static void debug(String msg) { if (CommonUtils.isDebug() && ThisApplication.DEBUG_NOTIFICATION) System.out.println(NotificationService.class.getSimpleName() + ": " + msg); }