Example usage for org.joda.time DateTime getMillis

List of usage examples for org.joda.time DateTime getMillis

Introduction

In this page you can find the example usage for org.joda.time DateTime getMillis.

Prototype

public long getMillis() 

Source Link

Document

Gets the milliseconds of the datetime instant from the Java epoch of 1970-01-01T00:00:00Z.

Usage

From source file:com.github.terma.gigaspacewebconsole.provider.executor.gigaspace.TimestampPreprocessor.java

License:Apache License

private String timestampString(Matcher matcher, final DateTime timestamp) {
    final int sign = matcher.group(1).equals("-") ? -1 : 1;
    final int quantity = sign * Integer.parseInt(matcher.group(2));
    final String type = matcher.group(3);

    DateTime updatedTimestamp;
    switch (type) {
    case "h":
        updatedTimestamp = timestamp.plusHours(quantity);
        break;//from  w  ww  .ja  va 2 s .  c o m
    case "d":
        updatedTimestamp = timestamp.plusDays(quantity);
        break;
    case "w":
        updatedTimestamp = timestamp.plusWeeks(quantity);
        break;
    default:
        throw new IllegalArgumentException();
    }

    return Long.toString(updatedTimestamp.getMillis());
}

From source file:com.google.android.apps.paco.AlarmCreator2.java

License:Open Source License

void createAlarm(DateTime alarmTime, Experiment experiment) {
    Log.i(PacoConstants.TAG,// www .jav a  2s  .  com
            "Creating alarm: " + alarmTime.toString() + " for experiment: " + experiment.getTitle());
    PendingIntent intent = createAlarmReceiverIntentForExperiment(alarmTime);
    alarmManager.cancel(intent);
    alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime.getMillis(), intent);
}

From source file:com.google.android.apps.paco.AlarmCreator2.java

License:Open Source License

/**
 * Create an AlarmReceiver PendingIntent for the next experiment.
 *  //from ww  w .jav a 2s .c  o  m
 * @param alarmTime Time to trigger notification
 * @return
 */
private PendingIntent createAlarmReceiverIntentForExperiment(DateTime alarmTime) {
    Intent ultimateIntent = new Intent(pendingIntentContext, AlarmReceiver.class);
    ultimateIntent.putExtra(Experiment.SCHEDULED_TIME, alarmTime.getMillis());
    return PendingIntent.getBroadcast(pendingIntentContext, ALARM_RECEIVER_INTENT_REQUEST_CODE, ultimateIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
}

From source file:com.google.android.apps.paco.Experiment.java

License:Open Source License

private void storeSignalTimes(DateMidnight periodStart, List<DateTime> times, AlarmStore alarmStore) {
    long periodStartMillis = periodStart.getMillis();
    for (DateTime alarmTime : times) {
        alarmStore.storeSignal(periodStartMillis, getId(), alarmTime.getMillis());
    }//from  www.j  a  v a 2s.c  o  m
}

From source file:com.google.android.apps.paco.ExperimentExecutorCustomRendering.java

License:Open Source License

private WebViewClient createWebViewClientThatHandlesFileLinksForCharts() {
    WebViewClient webViewClient = new WebViewClient() {

        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Uri uri = Uri.parse(url);//from   ww w  . j  a v  a2  s . c  o m
            if (uri.getScheme().startsWith("http")) {
                return true; // throw away http requests - we don't want 3rd party javascript sending url requests due to security issues.
            }

            String inputIdStr = uri.getQueryParameter("inputId");
            if (inputIdStr == null) {
                return true;
            }
            long inputId = Long.parseLong(inputIdStr);
            JSONArray results = new JSONArray();
            for (Event event : experiment.getEvents()) {
                JSONArray eventJson = new JSONArray();
                DateTime responseTime = event.getResponseTime();
                if (responseTime == null) {
                    continue; // missed signal;
                }
                eventJson.put(responseTime.getMillis());

                // in this case we are looking for one input from the responses that we are charting.
                for (Output response : event.getResponses()) {
                    if (response.getInputServerId() == inputId) {
                        Input inputById = experiment.getInputById(inputId);
                        if (!inputById.isInvisible() && inputById.isNumeric()) {
                            eventJson.put(response.getDisplayOfAnswer(inputById));
                            results.put(eventJson);
                            continue;
                        }
                    }
                }

            }
            env.put("data", results.toString());
            env.put("inputId", inputIdStr);

            view.loadUrl(stripQuery(url));
            return true;
        }
    };
    return webViewClient;
}

From source file:com.google.android.apps.paco.ExperimentProviderUtil.java

License:Open Source License

public Event getEvent(Long experimentServerId, DateTime scheduledTime) {
    if (scheduledTime == null) {
        return null;
    }/*from   w  ww  .  ja  v  a2 s .com*/
    Event event = findEventBy(EventColumns.EXPERIMENT_SERVER_ID + "=" + experimentServerId + " AND "
            + EventColumns.SCHEDULE_TIME + "=" + scheduledTime.getMillis(), EventColumns._ID + " DESC");
    if (event != null) {
        Log.i(PacoConstants.TAG,
                "Found event for experimentId: " + experimentServerId + ", st = " + scheduledTime);
    } else {
        Log.i(PacoConstants.TAG,
                "DID NOT Find event for experimentId: " + experimentServerId + ", st = " + scheduledTime);
    }
    return event;
}

From source file:com.google.android.apps.paco.ExploreDataActivity.java

License:Open Source License

/**
 * @param inputId//  www  .  j ava  2 s  .c om
 * @param localExperiment
 * @return
 */
private JSONArray getResultsForInputAsJsonString(long inputId, Experiment localExperiment) {
    JSONArray results = new JSONArray();
    for (Event event : localExperiment.getEvents()) {
        JSONArray eventJson = new JSONArray();
        DateTime responseTime = event.getResponseTime();
        if (responseTime == null) {
            continue; // missed signal;
        }
        eventJson.put(responseTime.getMillis());

        // in this case we are looking for one input from the responses that we are charting.
        for (Output response : event.getResponses()) {
            if (response.getInputServerId() == inputId) {
                Input inputById = localExperiment.getInputById(inputId);
                if (!inputById.isInvisible() && inputById.isNumeric()) {
                    eventJson.put(response.getDisplayOfAnswer(inputById));
                    results.put(eventJson);
                    continue;
                }
            }
        }

    }
    return results;
}

From source file:com.google.android.apps.paco.FeedbackActivity.java

License:Open Source License

private WebViewClient createWebViewClientThatHandlesFileLinksForCharts(final Feedback feedback) {
    WebViewClient webViewClient = new WebViewClient() {

        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Uri uri = Uri.parse(url);/*  www  .ja  v  a2 s.  co m*/
            if (uri.getScheme().startsWith("http")) {
                return true; // throw away http requests - we don't want 3rd party javascript sending url requests due to security issues.
            }

            String inputIdStr = uri.getQueryParameter("inputId");
            if (inputIdStr == null) {
                return true;
            }
            long inputId = Long.parseLong(inputIdStr);
            JSONArray results = new JSONArray();
            for (Event event : experiment.getEvents()) {
                JSONArray eventJson = new JSONArray();
                DateTime responseTime = event.getResponseTime();
                if (responseTime == null) {
                    continue; // missed signal;
                }
                eventJson.put(responseTime.getMillis());

                // in this case we are looking for one input from the responses that we are charting.
                for (Output response : event.getResponses()) {
                    if (response.getInputServerId() == inputId) {
                        Input inputById = experiment.getInputById(inputId);
                        if (!inputById.isInvisible() && inputById.isNumeric()) {
                            eventJson.put(response.getDisplayOfAnswer(inputById));
                            results.put(eventJson);
                            continue;
                        }
                    }
                }

            }
            env.put("data", results.toString());
            env.put("inputId", inputIdStr);

            view.loadUrl(stripQuery(url));
            return true;
        }

    };
    return webViewClient;
}

From source file:com.google.android.apps.paco.NotificationCreator.java

License:Open Source License

private NotificationHolder createNewNotificationWithDetails(Context context, DateTime time,
        Experiment experiment, String source, long expirationTimeInMillis, String message) {
    NotificationHolder notificationHolder = new NotificationHolder(time.getMillis(), experiment.getId(), 0,
            expirationTimeInMillis, source, message);
    experimentProviderUtil.insertNotification(notificationHolder);
    fireNotification(context, notificationHolder, experiment, message);
    return notificationHolder;
}

From source file:com.google.android.apps.paco.NotificationCreator.java

License:Open Source License

private void createAlarmToCancelNotificationAtTimeout(Context context, NotificationHolder notificationHolder) {
    DateTime alarmTime = new DateTime(notificationHolder.getAlarmTime());
    int timeoutMinutes = (int) (notificationHolder.getTimeoutMillis() / MILLIS_IN_MINUTE);
    DateTime timeoutTime = new DateTime(alarmTime).plusMinutes(timeoutMinutes);
    long elapsedDurationInMillis = timeoutTime.getMillis();

    Log.i(PacoConstants.TAG,/*  w  w  w  .  j  av a  2 s .c  o  m*/
            "Creating cancel alarm to timeout notification for holder: " + notificationHolder.getId()
                    + ". experiment = " + notificationHolder.getExperimentId() + ". alarmtime = "
                    + new DateTime(alarmTime).toString() + " timing out in " + timeoutMinutes + " minutes");

    Intent ultimateIntent = new Intent(context, AlarmReceiver.class);
    Uri uri = Uri.withAppendedPath(NotificationHolderColumns.CONTENT_URI,
            notificationHolder.getId().toString());
    ultimateIntent.setData(uri);
    ultimateIntent.putExtra(NOTIFICATION_ID, notificationHolder.getId().longValue());

    PendingIntent intent = PendingIntent.getBroadcast(context.getApplicationContext(), 2, ultimateIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(intent);
    alarmManager.set(AlarmManager.RTC_WAKEUP, elapsedDurationInMillis, intent);
}