use of java.util.Calendar in project head by mifos.
the class QuestionnaireServiceIntegrationTest method verifyCreationDate.
private void verifyCreationDate(QuestionGroup questionGroup) {
Calendar creationDate = Calendar.getInstance();
creationDate.setTime(questionGroup.getDateOfCreation());
Calendar currentDate = Calendar.getInstance();
assertThat(creationDate.get(Calendar.DATE), is(currentDate.get(Calendar.DATE)));
assertThat(creationDate.get(Calendar.MONTH), is(currentDate.get(Calendar.MONTH)));
assertThat(creationDate.get(Calendar.YEAR), is(currentDate.get(Calendar.YEAR)));
}
use of java.util.Calendar in project head by mifos.
the class QuestionnaireServiceTest method assertDate.
private void assertDate(Date date, int year, int month, int day) {
assertThat(date, is(notNullValue()));
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
assertThat(calendar.get(Calendar.YEAR), is(year));
assertThat(calendar.get(Calendar.MONTH), is(month));
assertThat(calendar.get(Calendar.DATE), is(day));
}
use of java.util.Calendar in project qksms by moezbhatti.
the class Transaction method sendSmsMessage.
private void sendSmsMessage(String text, String[] addresses, long threadId, int delay) {
if (LOCAL_LOGV)
Log.v(TAG, "message text: " + text);
Uri messageUri = null;
int messageId = 0;
if (saveMessage) {
if (LOCAL_LOGV)
Log.v(TAG, "saving message");
// add signature to original text to be saved in database (does not strip unicode for saving though)
if (!settings.getSignature().equals("")) {
text += "\n" + settings.getSignature();
}
// save the message for each of the addresses
for (int i = 0; i < addresses.length; i++) {
Calendar cal = Calendar.getInstance();
ContentValues values = new ContentValues();
values.put("address", addresses[i]);
values.put("body", settings.getStripUnicode() ? StripAccents.stripAccents(text) : text);
values.put("date", cal.getTimeInMillis() + "");
values.put("read", 1);
values.put("type", 4);
// attempt to create correct thread id if one is not supplied
if (threadId == NO_THREAD_ID || addresses.length > 1) {
threadId = Utils.getOrCreateThreadId(context, addresses[i]);
}
if (LOCAL_LOGV)
Log.v(TAG, "saving message with thread id: " + threadId);
values.put("thread_id", threadId);
messageUri = context.getContentResolver().insert(Uri.parse("content://sms/"), values);
if (LOCAL_LOGV)
Log.v(TAG, "inserted to uri: " + messageUri);
Cursor query = context.getContentResolver().query(messageUri, new String[] { "_id" }, null, null, null);
if (query != null && query.moveToFirst()) {
messageId = query.getInt(0);
}
if (LOCAL_LOGV)
Log.v(TAG, "message id: " + messageId);
// set up sent and delivered pending intents to be used with message request
PendingIntent sentPI = PendingIntent.getBroadcast(context, messageId, new Intent(SMS_SENT).putExtra("message_uri", messageUri == null ? "" : messageUri.toString()), PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent deliveredPI = PendingIntent.getBroadcast(context, messageId, new Intent(SMS_DELIVERED).putExtra("message_uri", messageUri == null ? "" : messageUri.toString()), PendingIntent.FLAG_UPDATE_CURRENT);
ArrayList<PendingIntent> sPI = new ArrayList<>();
ArrayList<PendingIntent> dPI = new ArrayList<>();
String body = text;
// edit the body of the text if unicode needs to be stripped
if (settings.getStripUnicode()) {
body = StripAccents.stripAccents(body);
}
if (!settings.getPreText().equals("")) {
body = settings.getPreText() + " " + body;
}
SmsManager smsManager = SmsManager.getDefault();
if (LOCAL_LOGV)
Log.v(TAG, "found sms manager");
if (QKPreferences.getBoolean(QKPreference.SPLIT_SMS)) {
if (LOCAL_LOGV)
Log.v(TAG, "splitting message");
// figure out the length of supported message
int[] splitData = SmsMessage.calculateLength(body, false);
// we take the current length + the remaining length to get the total number of characters
// that message set can support, and then divide by the number of message that will require
// to get the length supported by a single message
int length = (body.length() + splitData[2]) / splitData[0];
if (LOCAL_LOGV)
Log.v(TAG, "length: " + length);
boolean counter = false;
if (settings.getSplitCounter() && body.length() > length) {
counter = true;
length -= 6;
}
// get the split messages
String[] textToSend = splitByLength(body, length, counter);
// send each message part to each recipient attached to message
for (int j = 0; j < textToSend.length; j++) {
ArrayList<String> parts = smsManager.divideMessage(textToSend[j]);
for (int k = 0; k < parts.size(); k++) {
sPI.add(saveMessage ? sentPI : null);
dPI.add(settings.getDeliveryReports() && saveMessage ? deliveredPI : null);
}
if (LOCAL_LOGV)
Log.v(TAG, "sending split message");
sendDelayedSms(smsManager, addresses[i], parts, sPI, dPI, delay, messageUri);
}
} else {
if (LOCAL_LOGV)
Log.v(TAG, "sending without splitting");
// send the message normally without forcing anything to be split
ArrayList<String> parts = smsManager.divideMessage(body);
for (int j = 0; j < parts.size(); j++) {
sPI.add(saveMessage ? sentPI : null);
dPI.add(settings.getDeliveryReports() && saveMessage ? deliveredPI : null);
}
try {
if (LOCAL_LOGV)
Log.v(TAG, "sent message");
sendDelayedSms(smsManager, addresses[i], parts, sPI, dPI, delay, messageUri);
} catch (Exception e) {
// whoops...
if (LOCAL_LOGV)
Log.v(TAG, "error sending message");
Log.e(TAG, "exception thrown", e);
try {
((Activity) context).getWindow().getDecorView().findViewById(android.R.id.content).post(new Runnable() {
@Override
public void run() {
Toast.makeText(context, "Message could not be sent", Toast.LENGTH_LONG).show();
}
});
} catch (Exception f) {
}
}
}
}
}
}
use of java.util.Calendar in project cordova-plugin-local-notifications by katzer.
the class AbstractTriggerReceiver method isFirstAlarmInFuture.
/*
* If you set a repeating alarm at 11:00 in the morning and it
* should trigger every morning at 08:00 o'clock, it will
* immediately fire. E.g. Android tries to make up for the
* 'forgotten' reminder for that day. Therefore we ignore the event
* if Android tries to 'catch up'.
*/
private Boolean isFirstAlarmInFuture(Options options) {
Notification notification = new Builder(options).build();
if (!notification.isRepeating())
return false;
Calendar now = Calendar.getInstance();
Calendar alarm = Calendar.getInstance();
alarm.setTime(notification.getOptions().getTriggerDate());
int alarmHour = alarm.get(Calendar.HOUR_OF_DAY);
int alarmMin = alarm.get(Calendar.MINUTE);
int currentHour = now.get(Calendar.HOUR_OF_DAY);
int currentMin = now.get(Calendar.MINUTE);
return (currentHour != alarmHour && currentMin != alarmMin);
}
use of java.util.Calendar in project head by mifos.
the class ClientTest method verifyQuestionGroupInstanceListing.
private void verifyQuestionGroupInstanceListing(int expectedSize) {
questionGroupInstancesOfClient = viewClientDetailsPage.getQuestionGroupInstances();
QuestionGroup latestInstance = getLatestQuestionGroupInstance();
Assert.assertEquals(expectedSize, questionGroupInstancesOfClient.size());
Calendar calendar = Calendar.getInstance();
String expectedDate = String.format(EXPECTED_DATE_FORMAT, calendar.get(Calendar.DATE), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.YEAR));
Assert.assertEquals(questionGroupTitle, latestInstance.getName());
Assert.assertEquals(expectedDate, latestInstance.getDate());
}
Aggregations