use of java.text.ParseException in project ZhihuDailyPurify by izzyleung.
the class DateHeaderAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(HeaderViewHolder viewHolder, int position) {
Calendar calendar = Calendar.getInstance();
try {
calendar.setTime(Constants.Dates.simpleDateFormat.parse(newsList.get(position).getDate()));
calendar.add(Calendar.DAY_OF_YEAR, -1);
} catch (ParseException ignored) {
}
viewHolder.title.setText(dateFormat.format(calendar.getTime()));
}
use of java.text.ParseException in project ZhihuDailyPurify by izzyleung.
the class SingleDayNewsActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle = getIntent().getExtras();
Fragment newFragment = new NewsListFragment();
String dateString = bundle.getString(Constants.BundleKeys.DATE);
Calendar calendar = Calendar.getInstance();
try {
Date date = Constants.Dates.simpleDateFormat.parse(dateString);
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_YEAR, -1);
} catch (ParseException ignored) {
}
//noinspection ConstantConditions
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(DateFormat.getDateInstance().format(calendar.getTime()));
bundle.putString(Constants.BundleKeys.DATE, dateString);
bundle.putBoolean(Constants.BundleKeys.IS_FIRST_PAGE, isSameDay(calendar, Calendar.getInstance()));
bundle.putBoolean(Constants.BundleKeys.IS_SINGLE, true);
newFragment.setArguments(bundle);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_frame, newFragment).commit();
}
use of java.text.ParseException in project Openfire by igniterealtime.
the class IQQueryHandler method retrieveMessages.
/**
* Retrieve messages matching query request from server archive
* @param queryRequest
* @return
*/
private Collection<ArchivedMessage> retrieveMessages(QueryRequest queryRequest) {
String withField = null;
String startField = null;
String endField = null;
DataForm dataForm = queryRequest.getDataForm();
if (dataForm != null) {
if (dataForm.getField("with") != null) {
withField = dataForm.getField("with").getFirstValue();
}
if (dataForm.getField("start") != null) {
startField = dataForm.getField("start").getFirstValue();
}
if (dataForm.getField("end") != null) {
endField = dataForm.getField("end").getFirstValue();
}
}
Date startDate = null;
Date endDate = null;
try {
if (startField != null) {
startDate = xmppDateTimeFormat.parseString(startField);
}
if (endField != null) {
endDate = xmppDateTimeFormat.parseString(endField);
}
} catch (ParseException e) {
Log.error("Error parsing query date filters.", e);
}
return getPersistenceManager(queryRequest.getArchive()).findMessages(startDate, endDate, queryRequest.getArchive().toBareJID(), withField, queryRequest.getResultSet());
}
use of java.text.ParseException in project Openfire by igniterealtime.
the class SipIncomingCallAgent method processSdp.
private SdpInfo processSdp(Request request) throws ParseException {
byte[] rawSdp = request.getRawContent();
if (rawSdp == null) {
return null;
}
String sdpBody = new String(rawSdp);
SdpInfo sdpInfo = sipUtil.getSdpInfo(sdpBody);
String remoteHost = sdpInfo.getRemoteHost();
int remotePort = sdpInfo.getRemotePort();
Logger.println("SipIncomingCallAgent: remote socket " + remoteHost + " " + remotePort);
try {
InetSocketAddress isa = new InetSocketAddress(remoteHost, remotePort);
setEndpointAddress(isa, sdpInfo.getMediaInfo().getPayload(), sdpInfo.getTransmitMediaInfo().getPayload(), sdpInfo.getTelephoneEventPayload());
} catch (Exception e) {
Logger.println("SipIncomingCallAgent: can't create isa");
throw new ParseException("SipIncomingCallAgent: can't create isa", 0);
}
return sdpInfo;
}
use of java.text.ParseException in project Openfire by igniterealtime.
the class SipTPCCallAgent method handleCallParticipantInvited.
/**
* handles the INVITED state.
* @param response the response
* @param clientTransaction the client transaction
* @throws SipException SIP stack related error
*/
private void handleCallParticipantInvited(Response response, ClientTransaction clientTransaction) throws ParseException, SipException, InvalidArgumentException {
FromHeader fromHeader = (FromHeader) response.getHeader(FromHeader.NAME);
String displayName = fromHeader.getAddress().getDisplayName();
int statusCode = response.getStatusCode();
Logger.println("handleCallParticipantInvited " + cp + " status " + statusCode + " " + response.getReasonPhrase());
Logger.println("handleCallParticipantInvited , displayname " + displayName);
CallIdHeader callIdHeader = (CallIdHeader) response.getHeader(CallIdHeader.NAME);
if (sipCallId.equals(callIdHeader.getCallId()) && displayName.equals(cp.getDisplayName()) && (statusCode == Response.OK || statusCode == Response.SESSION_PROGRESS) && ((CSeqHeader) response.getHeader(CSeqHeader.NAME)).getMethod().equals(Request.INVITE)) {
if (statusCode == Response.SESSION_PROGRESS) {
if (cp.getHandleSessionProgress() == false) {
Logger.writeFile("Call " + cp + " Ignoring SESSION_PROGRESS");
return;
}
Logger.writeFile("Call " + cp + " Treating SESSION_PROGRESS as OK");
}
if (response.getRawContent() == null) {
Logger.error("Call " + cp + " no SDP in OK Response!");
cancelRequest("SIP error! no SDP in OK Response!");
return;
}
this.clientTransaction = clientTransaction;
if (statusCode == Response.OK) {
gotOk = true;
Logger.writeFile("Call " + cp + " Got OK, call answered\n" + response);
}
ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
if (statusCode == Response.OK) {
sipUtil.sendAck(clientTransaction);
ackSent = true;
}
if (callAnswered) {
Logger.writeFile("Call " + cp + " done processing OK");
return;
}
/*
* Remember the IP and port of where to send data to
* the CallParticipant.
*/
sdpBody = new String(response.getRawContent());
SdpInfo sdpInfo;
try {
sdpInfo = sipUtil.getSdpInfo(sdpBody, false);
} catch (ParseException e) {
Logger.error("Call " + cp + " Invalid SDP in OK Response! " + e.getMessage());
cancelRequest("SIP error! Invalid SDP in OK Response!");
return;
}
MediaInfo mediaInfo = sdpInfo.getMediaInfo();
InetSocketAddress isa = new InetSocketAddress(sdpInfo.getRemoteHost(), sdpInfo.getRemotePort());
InetSocketAddress rtcpAddress = sdpInfo.getRtcpAddress();
setEndpointAddress(isa, mediaInfo.getPayload(), sdpInfo.getTransmitMediaInfo().getPayload(), sdpInfo.getTelephoneEventPayload(), rtcpAddress);
/*
* The CallParticipant has answered.
* If join confirmation is required, we remain in the
* INVITED state. We set the callAnswered flag so that
* if the join confirmation times out we know to
* send a BYE rather than a CANCEL.
*/
callAnswered = true;
if (cp.getJoinConfirmationTimeout() == 0) {
setState(CallState.ANSWERED);
}
/*
* Start treatment if any and wait for it to finish.
* When the treatment finishes, notification will
* be delivered to our parent which will indicate
* we're ready for the conference.
*
* If there's no treatment to be played, we're ready now
* unless we're waiting for join confirmation..
*/
initializeCallAnsweredTreatment();
if (callAnsweredTreatment != null) {
startCallAnsweredTreatment();
} else {
if (cp.getJoinConfirmationTimeout() == 0) {
setState(CallState.ESTABLISHED);
}
}
} else {
Logger.writeFile("Call " + cp + " Ignoring response: " + response.getReasonPhrase());
if (Logger.logLevel >= Logger.LOG_SIP) {
Logger.println("Call " + cp + " Response: " + response);
}
}
}
Aggregations