Example usage for org.eclipse.jface.preference PreferenceStore getLong

List of usage examples for org.eclipse.jface.preference PreferenceStore getLong

Introduction

In this page you can find the example usage for org.eclipse.jface.preference PreferenceStore getLong.

Prototype

@Override
    public long getLong(String name) 

Source Link

Usage

From source file:com.android.sdkstats.DdmsPreferenceStore.java

License:Apache License

/**
 * Retrieves the current ping ID, if set.
 * To know if the ping ID is set, use {@link #hasPingId()}.
 * <p/>/*  w  w  w  .j a v a2 s  . c  om*/
 * There is no magic value reserved for "missing ping id or invalid store".
 * The only proper way to know if the ping id is missing is to use {@link #hasPingId()}.
 */
public long getPingId() {
    PreferenceStore prefs = getPreferenceStore();
    synchronized (DdmsPreferenceStore.class) {
        // Note: getLong() returns 0L if the ID is missing so we do that too when
        // there's no store.
        return prefs == null ? 0L : prefs.getLong(PING_ID);
    }
}

From source file:com.android.sdkstats.DdmsPreferenceStore.java

License:Apache License

/**
 * Retrieves the ping time for the given app from the preference store.
 * Callers should use {@link System#currentTimeMillis()} for time stamps.
 *
 * @param app The app name identifier./*from   w w  w  .j av a2  s  .c o  m*/
 * @return 0L if we don't have a preference store or there was no time
 *  recorded in the store for the requested app. Otherwise the time stamp
 *  from the store.
 */
public long getPingTime(String app) {
    PreferenceStore prefs = getPreferenceStore();
    String timePref = PING_TIME + "." + app; //$NON-NLS-1$
    synchronized (DdmsPreferenceStore.class) {
        return prefs == null ? 0 : prefs.getLong(timePref);
    }
}

From source file:com.android.sdkstats.SdkStatsService.java

License:Apache License

/**
 * Pings the usage stats server, as long as the prefs contain the opt-in boolean
 * @param app name to report in the ping
 * @param version to report in the ping//  www  . ja v a  2  s .  c  o  m
 * @param prefs the preference store where the opt-in value and ping times are store
 */
private static void doPing(final String app, String version, PreferenceStore prefs) {
    // Validate the application and version input.
    final String normalVersion = normalizeVersion(app, version);

    // If the user has not opted in, do nothing and quietly return.
    if (!prefs.getBoolean(PING_OPT_IN)) {
        // user opted out.
        return;
    }

    // If the last ping *for this app* was too recent, do nothing.
    String timePref = PING_TIME + "." + app; //$NON-NLS-1$
    long now = System.currentTimeMillis();
    long then = prefs.getLong(timePref);
    if (now - then < PING_INTERVAL_MSEC) {
        // too soon after a ping.
        return;
    }

    // Record the time of the attempt, whether or not it succeeds.
    prefs.setValue(timePref, now);
    try {
        prefs.save();
    } catch (IOException ioe) {
    }

    // Send the ping itself in the background (don't block if the
    // network is down or slow or confused).
    final long id = prefs.getLong(PING_ID);
    new Thread() {
        @Override
        public void run() {
            try {
                actuallySendPing(app, normalVersion, id);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }.start();
}