use of java.text.ParseException in project qksms by moezbhatti.
the class SettingsFragment method updateAlarmManager.
public static void updateAlarmManager(Context context, boolean enabled) {
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("H:mm");
Calendar calendar = Calendar.getInstance();
Calendar dayCalendar = Calendar.getInstance();
dayCalendar.setTimeInMillis(System.currentTimeMillis());
try {
calendar.setTime(simpleDateFormat.parse(PreferenceManager.getDefaultSharedPreferences(context).getString(DAY_START, "6:00")));
} catch (ParseException e) {
e.printStackTrace();
}
dayCalendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY));
dayCalendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE));
Intent day = new Intent(context, NightModeAutoReceiver.class);
PendingIntent dayIntent = PendingIntent.getBroadcast(context, 0, day, 0);
Calendar nightCalendar = Calendar.getInstance();
nightCalendar.setTimeInMillis(System.currentTimeMillis());
try {
calendar.setTime(simpleDateFormat.parse(PreferenceManager.getDefaultSharedPreferences(context).getString(NIGHT_START, "21:00")));
} catch (ParseException e) {
e.printStackTrace();
}
nightCalendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY));
nightCalendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE));
Intent night = new Intent(context, NightModeAutoReceiver.class);
PendingIntent nightIntent = PendingIntent.getBroadcast(context, 1, night, 0);
context.sendBroadcast(night);
if (enabled) {
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, dayCalendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, dayIntent);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, nightCalendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, nightIntent);
} else {
alarmManager.cancel(dayIntent);
alarmManager.cancel(nightIntent);
}
}
use of java.text.ParseException in project qksms by moezbhatti.
the class TimePickerFragment method onCreateDialog.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
if (mPreference == null) {
Log.w(TAG, "No preference set");
return null;
}
mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("H:mm");
// Use the current time as the default values for the picker
final Calendar c = Calendar.getInstance();
try {
Date date = simpleDateFormat.parse(mPrefs.getString(mPreference.getKey(), "6:00"));
c.setTime(date);
} catch (ParseException e) {
e.printStackTrace();
}
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
boolean isUsing24HourTime = DateFormat.is24HourFormat(getActivity());
return new TimePickerDialog(getActivity(), this, hour, minute, isUsing24HourTime);
}
use of java.text.ParseException in project OpenGrok by OpenGrok.
the class Results method prettyPrint.
/**
* Prints out results in html form. The following search helper fields are
* required to be properly initialized: <ul>
* <li>{@link SearchHelper#dataRoot}</li>
* <li>{@link SearchHelper#contextPath}</li>
* <li>{@link SearchHelper#searcher}</li> <li>{@link SearchHelper#hits}</li>
* <li>{@link SearchHelper#historyContext} (ignored if {@code null})</li>
* <li>{@link SearchHelper#sourceContext} (ignored if {@code null})</li>
* <li>{@link SearchHelper#summarizer} (if sourceContext is not
* {@code null})</li> <li>{@link SearchHelper#compressed} (if sourceContext
* is not {@code null})</li> <li>{@link SearchHelper#sourceRoot} (if
* sourceContext or historyContext is not {@code null})</li> </ul>
*
* @param out write destination
* @param sh search helper which has all required fields set
* @param start index of the first hit to print
* @param end index of the last hit to print
* @throws HistoryException
* @throws IOException
* @throws ClassNotFoundException
*/
public static void prettyPrint(Writer out, SearchHelper sh, int start, int end) throws HistoryException, IOException, ClassNotFoundException {
Project p;
String ctxE = Util.URIEncodePath(sh.contextPath);
String xrefPrefix = sh.contextPath + Prefix.XREF_P;
String morePrefix = sh.contextPath + Prefix.MORE_P;
String xrefPrefixE = ctxE + Prefix.XREF_P;
File xrefDataDir = new File(sh.dataRoot, Prefix.XREF_P.toString());
for (Map.Entry<String, ArrayList<Document>> entry : createMap(sh.searcher, sh.hits, start, end).entrySet()) {
String parent = entry.getKey();
out.write("<tr class=\"dir\"><td colspan=\"3\"><a href=\"");
out.write(xrefPrefixE);
out.write(Util.URIEncodePath(parent));
out.write("/\">");
// htmlize ???
out.write(parent);
out.write("/</a>");
if (sh.desc != null) {
out.write(" - <i>");
// htmlize ???
out.write(sh.desc.get(parent));
out.write("</i>");
}
JSONArray messages;
if ((p = Project.getProject(parent)) != null && (messages = Util.messagesToJson(p, RuntimeEnvironment.MESSAGES_MAIN_PAGE_TAG)).size() > 0) {
out.write(" <a ");
out.write("href=\"" + xrefPrefix + "/" + p.getName() + "\">");
out.write("<span class=\"important-note important-note-rounded\" data-messages='" + messages + "'>!</span>");
out.write("</a>");
}
out.write("</td></tr>");
for (Document doc : entry.getValue()) {
String rpath = doc.get(QueryBuilder.PATH);
String rpathE = Util.URIEncodePath(rpath);
DateFormat df;
out.write("<tr>");
Util.writeHAD(out, sh.contextPath, rpathE, false);
out.write("<td class=\"f\"><a href=\"");
out.write(xrefPrefixE);
out.write(rpathE);
out.write("\"");
if (RuntimeEnvironment.getInstance().isLastEditedDisplayMode()) {
try {
// insert last edited date if possible
df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
String dd = df.format(DateTools.stringToDate(doc.get("date")));
out.write(" class=\"result-annotate\" title=\"");
out.write("Last modified: ");
out.write(dd);
out.write("\"");
} catch (ParseException ex) {
LOGGER.log(Level.WARNING, "An error parsing date information", ex);
}
}
out.write(">");
// htmlize ???
out.write(rpath.substring(rpath.lastIndexOf('/') + 1));
out.write("</a>");
out.write("</td><td><tt class=\"con\">");
if (sh.sourceContext != null) {
Genre genre = Genre.get(doc.get("t"));
Definitions tags = null;
IndexableField tagsField = doc.getField(QueryBuilder.TAGS);
if (tagsField != null) {
tags = Definitions.deserialize(tagsField.binaryValue().bytes);
}
Scopes scopes;
IndexableField scopesField = doc.getField(QueryBuilder.SCOPES);
if (scopesField != null) {
scopes = Scopes.deserialize(scopesField.binaryValue().bytes);
} else {
scopes = new Scopes();
}
if (Genre.XREFABLE == genre && sh.summarizer != null) {
String xtags = getTags(xrefDataDir, rpath, sh.compressed);
// FIXME use Highlighter from lucene contrib here,
// instead of summarizer, we'd also get rid of
// apache lucene in whole source ...
out.write(sh.summarizer.getSummary(xtags).toString());
} else if (Genre.HTML == genre && sh.summarizer != null) {
String htags = getTags(sh.sourceRoot, rpath, false);
out.write(sh.summarizer.getSummary(htags).toString());
} else {
FileReader r = genre == Genre.PLAIN ? new FileReader(new File(sh.sourceRoot, rpath)) : null;
sh.sourceContext.getContext(r, out, xrefPrefix, morePrefix, rpath, tags, true, sh.builder.isDefSearch(), null, scopes);
}
}
if (sh.historyContext != null) {
sh.historyContext.getContext(new File(sh.sourceRoot, rpath), rpath, out, sh.contextPath);
}
out.write("</tt></td></tr>\n");
}
}
}
use of java.text.ParseException in project jersey by jersey.
the class FormDataContentDispositionTest method testCreate.
@Test
@Override
public void testCreate() {
final Date date = new Date();
FormDataContentDisposition contentDisposition;
contentDisposition = FormDataContentDisposition.name("testData").fileName("test.file").creationDate(date).modificationDate(date).readDate(date).size(1222).build();
assertFormDataContentDisposition(contentDisposition, date);
try {
final String dateString = HttpDateFormat.getPreferredDateFormat().format(date);
final String header = contentDispositionType + ";filename=\"test.file\";creation-date=\"" + dateString + "\";modification-date=\"" + dateString + "\";read-date=\"" + dateString + "\";size=1222" + ";name=\"testData\"";
contentDisposition = new FormDataContentDisposition(contentDisposition.toString());
assertFormDataContentDisposition(contentDisposition, date);
contentDisposition = new FormDataContentDisposition(header);
assertFormDataContentDisposition(contentDisposition, date);
contentDisposition = new FormDataContentDisposition(HttpHeaderReader.newInstance(header), true);
assertFormDataContentDisposition(contentDisposition, date);
} catch (final ParseException ex) {
fail(ex.getMessage());
}
try {
new FormDataContentDisposition((HttpHeaderReader) null, true);
fail("NullPointerException was expected to be thrown.");
} catch (final ParseException exception) {
fail(exception.getMessage());
} catch (final NullPointerException exception) {
//expected
}
try {
new FormDataContentDisposition("form-data;filename=\"test.file\"");
fail("IllegalArgumentException was expected to be thrown.");
} catch (final ParseException exception) {
fail(exception.getMessage());
} catch (final IllegalArgumentException exception) {
//expected
}
try {
FormDataContentDisposition.name(null).build();
fail("IllegalArgumentException was expected to be thrown.");
} catch (final IllegalArgumentException exception) {
//expected
} catch (final Exception exception) {
fail(exception.getMessage());
}
}
use of java.text.ParseException in project Openfire by igniterealtime.
the class SimpleSession method contactSubscribed.
// private Request prepareNotifyRequest(Dialog dialog, SimplePresence simplePresence) throws ParseException {
// Request request = prepareNotifyRequest(dialog);
// request.setContent(simplePresence.toXML(), headerFactory.createContentTypeHeader("application", "pidf+xml"));
//
// return request;
// }
public void contactSubscribed(String targetSipAddress) {
try {
// Roster roster = getTransport().getRosterManager().getRoster(getJID().getNode());
JID contactJID = getTransport().convertIDToJID(targetSipAddress);
// RosterItem item = roster.getRosterItem(contactJID);
Log.debug("SimpleSession(" + jid.getNode() + ").contactSubscribed: Preparing presence packet...");
Presence presence = new Presence();
presence.setFrom(contactJID);
presence.setTo(getJID());
presence.setType(Presence.Type.subscribed);
getTransport().sendPacket(presence);
Log.debug("SimpleSession(" + jid.getNode() + ").contactSubscribed: Presence packet sent ==> \n" + presence.toXML());
// Log.debug("SimpleSession(" + jid.getNode() + ").contactSubscribed: Synchronizing SIP user roster...");
// String rosteruserid = ((SimpleTransport) transport).convertJIDToID(item.getJid());
// if (myRoster.getEntry(rosteruserid) == null) {
// SimpleBuddy simpleRosterItem = new SimpleBuddy(rosteruserid, item.getNickname(), 1L);
// myRoster.addEntry(rosteruserid, simpleRosterItem);
// }
// Log.debug("SimpleSession(" + jid.getNode() + ").contactSubscribed: Finished synchronizing SIP user roster.");
// syncContactGroups(contact, item.getGroups());
} catch (Exception e) {
Log.debug("SimpleSession(" + jid.getNode() + ").contactSubscribed: Exception occured when adding pending contact " + targetSipAddress, e);
// JID contactJID = getTransport().convertIDToJID(targetSipAddress);
}
}
Aggregations