List of usage examples for java.util Calendar clear
public final void clear()
Calendar
undefined. From source file:org.telegram.ui.ChannelAdminLogActivity.java
@Override public View createView(Context context) { if (chatMessageCellsCache.isEmpty()) { for (int a = 0; a < 8; a++) { chatMessageCellsCache.add(new ChatMessageCell(context)); }/* w ww .j ava2 s. c o m*/ } searchWas = false; hasOwnBackground = true; Theme.createChatResources(context, false); actionBar.setAddToContainer(false); actionBar.setOccupyStatusBar(Build.VERSION.SDK_INT >= 21 && !AndroidUtilities.isTablet()); actionBar.setBackButtonDrawable(new BackDrawable(false)); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(final int id) { if (id == -1) { finishFragment(); } } }); avatarContainer = new ChatAvatarContainer(context, null, false); avatarContainer.setOccupyStatusBar(!AndroidUtilities.isTablet()); actionBar.addView(avatarContainer, 0, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 56, 0, 40, 0)); ActionBarMenu menu = actionBar.createMenu(); searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true) .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { @Override public void onSearchCollapse() { searchQuery = ""; avatarContainer.setVisibility(View.VISIBLE); if (searchWas) { searchWas = false; loadMessages(true); } /*highlightMessageId = Integer.MAX_VALUE; updateVisibleRows(); scrollToLastMessage(false); */ updateBottomOverlay(); } @Override public void onSearchExpand() { avatarContainer.setVisibility(View.GONE); updateBottomOverlay(); } @Override public void onSearchPressed(EditText editText) { searchWas = true; searchQuery = editText.getText().toString(); loadMessages(true); //updateSearchButtons(0, 0, 0); } }); searchItem.setSearchFieldHint(LocaleController.getString("Search", R.string.Search)); avatarContainer.setEnabled(false); avatarContainer.setTitle(currentChat.title); avatarContainer.setSubtitle(LocaleController.getString("EventLogAllEvents", R.string.EventLogAllEvents)); avatarContainer.setChatAvatar(currentChat); fragmentView = new SizeNotifierFrameLayout(context) { @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject(); if (messageObject != null && messageObject.isRoundVideo() && messageObject.eventId != 0 && messageObject.getDialogId() == -currentChat.id) { MediaController.getInstance().setTextureView(createTextureView(false), aspectRatioFrameLayout, roundVideoContainer, true); } } @Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { boolean result = super.drawChild(canvas, child, drawingTime); if (child == actionBar && parentLayout != null) { parentLayout.drawHeaderShadow(canvas, actionBar.getVisibility() == VISIBLE ? actionBar.getMeasuredHeight() : 0); } return result; } @Override protected boolean isActionBarVisible() { return actionBar.getVisibility() == VISIBLE; } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int allHeight; int widthSize = MeasureSpec.getSize(widthMeasureSpec); int heightSize = MeasureSpec.getSize(heightMeasureSpec); setMeasuredDimension(widthSize, heightSize); heightSize -= getPaddingTop(); measureChildWithMargins(actionBar, widthMeasureSpec, 0, heightMeasureSpec, 0); int actionBarHeight = actionBar.getMeasuredHeight(); if (actionBar.getVisibility() == VISIBLE) { heightSize -= actionBarHeight; } int keyboardSize = getKeyboardHeight(); int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { View child = getChildAt(i); if (child == null || child.getVisibility() == GONE || child == actionBar) { continue; } if (child == chatListView || child == progressView) { int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY); int contentHeightSpec = MeasureSpec.makeMeasureSpec( Math.max(AndroidUtilities.dp(10), heightSize - AndroidUtilities.dp(48 + 2)), MeasureSpec.EXACTLY); child.measure(contentWidthSpec, contentHeightSpec); } else if (child == emptyViewContainer) { int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY); int contentHeightSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY); child.measure(contentWidthSpec, contentHeightSpec); } else { measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0); } } } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { final int count = getChildCount(); for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int width = child.getMeasuredWidth(); final int height = child.getMeasuredHeight(); int childLeft; int childTop; int gravity = lp.gravity; if (gravity == -1) { gravity = Gravity.TOP | Gravity.LEFT; } final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: childLeft = (r - l - width) / 2 + lp.leftMargin - lp.rightMargin; break; case Gravity.RIGHT: childLeft = r - width - lp.rightMargin; break; case Gravity.LEFT: default: childLeft = lp.leftMargin; } switch (verticalGravity) { case Gravity.TOP: childTop = lp.topMargin + getPaddingTop(); if (child != actionBar && actionBar.getVisibility() == VISIBLE) { childTop += actionBar.getMeasuredHeight(); } break; case Gravity.CENTER_VERTICAL: childTop = (b - t - height) / 2 + lp.topMargin - lp.bottomMargin; break; case Gravity.BOTTOM: childTop = (b - t) - height - lp.bottomMargin; break; default: childTop = lp.topMargin; } if (child == emptyViewContainer) { childTop -= AndroidUtilities.dp(24) - (actionBar.getVisibility() == VISIBLE ? actionBar.getMeasuredHeight() / 2 : 0); } else if (child == actionBar) { childTop -= getPaddingTop(); } child.layout(childLeft, childTop, childLeft + width, childTop + height); } updateMessagesVisisblePart(); notifyHeightChanged(); } }; contentView = (SizeNotifierFrameLayout) fragmentView; contentView.setOccupyStatusBar(!AndroidUtilities.isTablet()); contentView.setBackgroundImage(Theme.getCachedWallpaper(), Theme.isWallpaperMotion()); emptyViewContainer = new FrameLayout(context); emptyViewContainer.setVisibility(View.INVISIBLE); contentView.addView(emptyViewContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); emptyViewContainer.setOnTouchListener((v, event) -> true); emptyView = new TextView(context); emptyView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); emptyView.setGravity(Gravity.CENTER); emptyView.setTextColor(Theme.getColor(Theme.key_chat_serviceText)); emptyView.setBackgroundDrawable( Theme.createRoundRectDrawable(AndroidUtilities.dp(10), Theme.getServiceMessageColor())); emptyView.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(16), AndroidUtilities.dp(16), AndroidUtilities.dp(16)); emptyViewContainer.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 16, 0, 16, 0)); chatListView = new RecyclerListView(context) { @Override public boolean drawChild(Canvas canvas, View child, long drawingTime) { boolean result = super.drawChild(canvas, child, drawingTime); if (child instanceof ChatMessageCell) { ChatMessageCell chatMessageCell = (ChatMessageCell) child; ImageReceiver imageReceiver = chatMessageCell.getAvatarImage(); if (imageReceiver != null) { int top = child.getTop(); if (chatMessageCell.isPinnedBottom()) { ViewHolder holder = chatListView.getChildViewHolder(child); if (holder != null) { holder = chatListView .findViewHolderForAdapterPosition(holder.getAdapterPosition() + 1); if (holder != null) { imageReceiver.setImageY(-AndroidUtilities.dp(1000)); imageReceiver.draw(canvas); return result; } } } if (chatMessageCell.isPinnedTop()) { ViewHolder holder = chatListView.getChildViewHolder(child); if (holder != null) { while (true) { holder = chatListView .findViewHolderForAdapterPosition(holder.getAdapterPosition() - 1); if (holder != null) { top = holder.itemView.getTop(); if (!(holder.itemView instanceof ChatMessageCell) || !((ChatMessageCell) holder.itemView).isPinnedTop()) { break; } } else { break; } } } } int y = child.getTop() + chatMessageCell.getLayoutHeight(); int maxY = chatListView.getHeight() - chatListView.getPaddingBottom(); if (y > maxY) { y = maxY; } if (y - AndroidUtilities.dp(48) < top) { y = top + AndroidUtilities.dp(48); } imageReceiver.setImageY(y - AndroidUtilities.dp(44)); imageReceiver.draw(canvas); } } return result; } }; chatListView.setOnItemClickListener((view, position) -> createMenu(view)); chatListView.setTag(1); chatListView.setVerticalScrollBarEnabled(true); chatListView.setAdapter(chatAdapter = new ChatActivityAdapter(context)); chatListView.setClipToPadding(false); chatListView.setPadding(0, AndroidUtilities.dp(4), 0, AndroidUtilities.dp(3)); chatListView.setItemAnimator(null); chatListView.setLayoutAnimation(null); chatLayoutManager = new LinearLayoutManager(context) { @Override public boolean supportsPredictiveItemAnimations() { return false; } @Override public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) { LinearSmoothScrollerMiddle linearSmoothScroller = new LinearSmoothScrollerMiddle( recyclerView.getContext()); linearSmoothScroller.setTargetPosition(position); startSmoothScroll(linearSmoothScroller); } }; chatLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); chatLayoutManager.setStackFromEnd(true); chatListView.setLayoutManager(chatLayoutManager); contentView.addView(chatListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); chatListView.setOnScrollListener(new RecyclerView.OnScrollListener() { private float totalDy = 0; private final int scrollValue = AndroidUtilities.dp(100); @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { if (newState == RecyclerView.SCROLL_STATE_DRAGGING) { scrollingFloatingDate = true; checkTextureViewPosition = true; } else if (newState == RecyclerView.SCROLL_STATE_IDLE) { scrollingFloatingDate = false; checkTextureViewPosition = false; hideFloatingDateView(true); } } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { chatListView.invalidate(); if (dy != 0 && scrollingFloatingDate && !currentFloatingTopIsNotMessage) { if (floatingDateView.getTag() == null) { if (floatingDateAnimation != null) { floatingDateAnimation.cancel(); } floatingDateView.setTag(1); floatingDateAnimation = new AnimatorSet(); floatingDateAnimation.setDuration(150); floatingDateAnimation.playTogether(ObjectAnimator.ofFloat(floatingDateView, "alpha", 1.0f)); floatingDateAnimation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (animation.equals(floatingDateAnimation)) { floatingDateAnimation = null; } } }); floatingDateAnimation.start(); } } checkScrollForLoad(true); updateMessagesVisisblePart(); } }); if (scrollToPositionOnRecreate != -1) { chatLayoutManager.scrollToPositionWithOffset(scrollToPositionOnRecreate, scrollToOffsetOnRecreate); scrollToPositionOnRecreate = -1; } progressView = new FrameLayout(context); progressView.setVisibility(View.INVISIBLE); contentView.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); progressView2 = new View(context); progressView2.setBackgroundResource(R.drawable.system_loader); progressView2.getBackground().setColorFilter(Theme.colorFilter); progressView.addView(progressView2, LayoutHelper.createFrame(36, 36, Gravity.CENTER)); progressBar = new RadialProgressView(context); progressBar.setSize(AndroidUtilities.dp(28)); progressBar.setProgressColor(Theme.getColor(Theme.key_chat_serviceText)); progressView.addView(progressBar, LayoutHelper.createFrame(32, 32, Gravity.CENTER)); floatingDateView = new ChatActionCell(context); floatingDateView.setAlpha(0.0f); contentView.addView(floatingDateView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 4, 0, 0)); contentView.addView(actionBar); bottomOverlayChat = new FrameLayout(context) { @Override public void onDraw(Canvas canvas) { int bottom = Theme.chat_composeShadowDrawable.getIntrinsicHeight(); Theme.chat_composeShadowDrawable.setBounds(0, 0, getMeasuredWidth(), bottom); Theme.chat_composeShadowDrawable.draw(canvas); canvas.drawRect(0, bottom, getMeasuredWidth(), getMeasuredHeight(), Theme.chat_composeBackgroundPaint); } }; bottomOverlayChat.setWillNotDraw(false); bottomOverlayChat.setPadding(0, AndroidUtilities.dp(3), 0, 0); contentView.addView(bottomOverlayChat, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 51, Gravity.BOTTOM)); bottomOverlayChat.setOnClickListener(view -> { if (getParentActivity() == null) { return; } AdminLogFilterAlert adminLogFilterAlert = new AdminLogFilterAlert(getParentActivity(), currentFilter, selectedAdmins, currentChat.megagroup); adminLogFilterAlert.setCurrentAdmins(admins); adminLogFilterAlert.setAdminLogFilterAlertDelegate((filter, admins) -> { currentFilter = filter; selectedAdmins = admins; if (currentFilter != null || selectedAdmins != null) { avatarContainer.setSubtitle( LocaleController.getString("EventLogSelectedEvents", R.string.EventLogSelectedEvents)); } else { avatarContainer.setSubtitle( LocaleController.getString("EventLogAllEvents", R.string.EventLogAllEvents)); } loadMessages(true); }); showDialog(adminLogFilterAlert); }); bottomOverlayChatText = new TextView(context); bottomOverlayChatText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); bottomOverlayChatText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); bottomOverlayChatText.setTextColor(Theme.getColor(Theme.key_chat_fieldOverlayText)); bottomOverlayChatText.setText(LocaleController.getString("SETTINGS", R.string.SETTINGS).toUpperCase()); bottomOverlayChat.addView(bottomOverlayChatText, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); bottomOverlayImage = new ImageView(context); bottomOverlayImage.setImageResource(R.drawable.log_info); bottomOverlayImage.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_fieldOverlayText), PorterDuff.Mode.MULTIPLY)); bottomOverlayImage.setScaleType(ImageView.ScaleType.CENTER); bottomOverlayChat.addView(bottomOverlayImage, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP, 3, 0, 0, 0)); bottomOverlayImage.setOnClickListener(v -> { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); if (currentChat.megagroup) { builder.setMessage(AndroidUtilities.replaceTags( LocaleController.getString("EventLogInfoDetail", R.string.EventLogInfoDetail))); } else { builder.setMessage(AndroidUtilities.replaceTags(LocaleController .getString("EventLogInfoDetailChannel", R.string.EventLogInfoDetailChannel))); } builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); builder.setTitle(LocaleController.getString("EventLogInfoTitle", R.string.EventLogInfoTitle)); showDialog(builder.create()); }); searchContainer = new FrameLayout(context) { @Override public void onDraw(Canvas canvas) { int bottom = Theme.chat_composeShadowDrawable.getIntrinsicHeight(); Theme.chat_composeShadowDrawable.setBounds(0, 0, getMeasuredWidth(), bottom); Theme.chat_composeShadowDrawable.draw(canvas); canvas.drawRect(0, bottom, getMeasuredWidth(), getMeasuredHeight(), Theme.chat_composeBackgroundPaint); } }; searchContainer.setWillNotDraw(false); searchContainer.setVisibility(View.INVISIBLE); searchContainer.setFocusable(true); searchContainer.setFocusableInTouchMode(true); searchContainer.setClickable(true); searchContainer.setPadding(0, AndroidUtilities.dp(3), 0, 0); contentView.addView(searchContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 51, Gravity.BOTTOM)); /*searchUpButton = new ImageView(context); searchUpButton.setScaleType(ImageView.ScaleType.CENTER); searchUpButton.setImageResource(R.drawable.search_up); searchUpButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_searchPanelIcons), PorterDuff.Mode.MULTIPLY)); searchContainer.addView(searchUpButton, LayoutHelper.createFrame(48, 48)); searchUpButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { MessagesSearchQuery.searchMessagesInChat(null, dialog_id, mergeDialogId, classGuid, 1); } }); searchDownButton = new ImageView(context); searchDownButton.setScaleType(ImageView.ScaleType.CENTER); searchDownButton.setImageResource(R.drawable.search_down); searchDownButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_searchPanelIcons), PorterDuff.Mode.MULTIPLY)); searchContainer.addView(searchDownButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP, 48, 0, 0, 0)); searchDownButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { MessagesSearchQuery.searchMessagesInChat(null, dialog_id, mergeDialogId, classGuid, 2); } });*/ searchCalendarButton = new ImageView(context); searchCalendarButton.setScaleType(ImageView.ScaleType.CENTER); searchCalendarButton.setImageResource(R.drawable.search_calendar); searchCalendarButton.setColorFilter(new PorterDuffColorFilter( Theme.getColor(Theme.key_chat_searchPanelIcons), PorterDuff.Mode.MULTIPLY)); searchContainer.addView(searchCalendarButton, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP)); searchCalendarButton.setOnClickListener(view -> { if (getParentActivity() == null) { return; } AndroidUtilities.hideKeyboard(searchItem.getSearchField()); Calendar calendar = Calendar.getInstance(); int year = calendar.get(Calendar.YEAR); int monthOfYear = calendar.get(Calendar.MONTH); int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); try { DatePickerDialog dialog = new DatePickerDialog(getParentActivity(), (view1, year1, month, dayOfMonth1) -> { Calendar calendar1 = Calendar.getInstance(); calendar1.clear(); calendar1.set(year1, month, dayOfMonth1); int date = (int) (calendar1.getTime().getTime() / 1000); loadMessages(true); }, year, monthOfYear, dayOfMonth); final DatePicker datePicker = dialog.getDatePicker(); datePicker.setMinDate(1375315200000L); datePicker.setMaxDate(System.currentTimeMillis()); dialog.setButton(DialogInterface.BUTTON_POSITIVE, LocaleController.getString("JumpToDate", R.string.JumpToDate), dialog); dialog.setButton(DialogInterface.BUTTON_NEGATIVE, LocaleController.getString("Cancel", R.string.Cancel), (dialog12, which) -> { }); if (Build.VERSION.SDK_INT >= 21) { dialog.setOnShowListener(dialog1 -> { int count = datePicker.getChildCount(); for (int a = 0; a < count; a++) { View child = datePicker.getChildAt(a); ViewGroup.LayoutParams layoutParams = child.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; child.setLayoutParams(layoutParams); } }); } showDialog(dialog); } catch (Exception e) { FileLog.e(e); } }); searchCountText = new SimpleTextView(context); searchCountText.setTextColor(Theme.getColor(Theme.key_chat_searchPanelText)); searchCountText.setTextSize(15); searchCountText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); searchContainer.addView(searchCountText, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.CENTER_VERTICAL, 108, 0, 0, 0)); chatAdapter.updateRows(); if (loading && messages.isEmpty()) { progressView.setVisibility(View.VISIBLE); chatListView.setEmptyView(null); } else { progressView.setVisibility(View.INVISIBLE); chatListView.setEmptyView(emptyViewContainer); } updateEmptyPlaceholder(); return fragmentView; }
From source file:de.schildbach.pte.AbstractEfaProvider.java
private QueryDeparturesResult xsltDepartureMonitorRequest(final String stationId, final @Nullable Date time, final int maxDepartures, final boolean equivs) throws IOException { final HttpUrl.Builder url = departureMonitorEndpoint.newBuilder(); appendXsltDepartureMonitorRequestParameters(url, stationId, time, maxDepartures, equivs); final AtomicReference<QueryDeparturesResult> result = new AtomicReference<>(); final HttpClient.Callback callback = new HttpClient.Callback() { @Override/*from ww w. j a v a 2 s . co m*/ public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException { try { final XmlPullParser pp = parserFactory.newPullParser(); pp.setInput(body.byteStream(), null); // Read encoding from XML declaration final ResultHeader header = enterItdRequest(pp); final QueryDeparturesResult r = new QueryDeparturesResult(header); XmlPullUtil.enter(pp, "itdDepartureMonitorRequest"); XmlPullUtil.optSkipMultiple(pp, "itdMessage"); final String nameState = processItdOdv(pp, "dm", new ProcessItdOdvCallback() { @Override public void location(final String nameState, final Location location, final int matchQuality) { if (location.type == LocationType.STATION) if (findStationDepartures(r.stationDepartures, location.id) == null) r.stationDepartures.add(new StationDepartures(location, new LinkedList<Departure>(), new LinkedList<LineDestination>())); } }); if ("notidentified".equals(nameState) || "list".equals(nameState)) { result.set(new QueryDeparturesResult(header, QueryDeparturesResult.Status.INVALID_STATION)); return; } XmlPullUtil.optSkip(pp, "itdDateTime"); XmlPullUtil.optSkip(pp, "itdDMDateTime"); XmlPullUtil.optSkip(pp, "itdDateRange"); XmlPullUtil.optSkip(pp, "itdTripOptions"); XmlPullUtil.optSkip(pp, "itdMessage"); if (XmlPullUtil.test(pp, "itdServingLines")) { if (!pp.isEmptyElementTag()) { XmlPullUtil.enter(pp, "itdServingLines"); while (XmlPullUtil.test(pp, "itdServingLine")) { final String assignedStopId = XmlPullUtil.optAttr(pp, "assignedStopID", null); final LineDestinationAndCancelled lineDestinationAndCancelled = processItdServingLine( pp); final LineDestination lineDestination = new LineDestination( lineDestinationAndCancelled.line, lineDestinationAndCancelled.destination); StationDepartures assignedStationDepartures; if (assignedStopId == null) assignedStationDepartures = r.stationDepartures.get(0); else assignedStationDepartures = findStationDepartures(r.stationDepartures, assignedStopId); if (assignedStationDepartures == null) assignedStationDepartures = new StationDepartures( new Location(LocationType.STATION, assignedStopId), new LinkedList<Departure>(), new LinkedList<LineDestination>()); final List<LineDestination> assignedStationDeparturesLines = checkNotNull( assignedStationDepartures.lines); if (!assignedStationDeparturesLines.contains(lineDestination)) assignedStationDeparturesLines.add(lineDestination); } XmlPullUtil.skipExit(pp, "itdServingLines"); } else { XmlPullUtil.next(pp); } } else { result.set(new QueryDeparturesResult(header, QueryDeparturesResult.Status.INVALID_STATION)); return; } XmlPullUtil.require(pp, "itdDepartureList"); if (XmlPullUtil.optEnter(pp, "itdDepartureList")) { final Calendar plannedDepartureTime = new GregorianCalendar(timeZone); final Calendar predictedDepartureTime = new GregorianCalendar(timeZone); while (XmlPullUtil.test(pp, "itdDeparture")) { final String assignedStopId = XmlPullUtil.attr(pp, "stopID"); StationDepartures assignedStationDepartures = findStationDepartures(r.stationDepartures, assignedStopId); if (assignedStationDepartures == null) { final Point coord = processCoordAttr(pp); // final String name = normalizeLocationName(XmlPullUtil.attr(pp, "nameWO")); assignedStationDepartures = new StationDepartures( new Location(LocationType.STATION, assignedStopId, coord), new LinkedList<Departure>(), new LinkedList<LineDestination>()); } final Position position = parsePosition(XmlPullUtil.optAttr(pp, "platformName", null)); XmlPullUtil.enter(pp, "itdDeparture"); XmlPullUtil.require(pp, "itdDateTime"); plannedDepartureTime.clear(); processItdDateTime(pp, plannedDepartureTime); predictedDepartureTime.clear(); if (XmlPullUtil.test(pp, "itdRTDateTime")) processItdDateTime(pp, predictedDepartureTime); XmlPullUtil.optSkip(pp, "itdFrequencyInfo"); XmlPullUtil.require(pp, "itdServingLine"); final boolean isRealtime = XmlPullUtil.attr(pp, "realtime").equals("1"); final LineDestinationAndCancelled lineDestinationAndCancelled = processItdServingLine( pp); if (isRealtime && !predictedDepartureTime.isSet(Calendar.HOUR_OF_DAY)) predictedDepartureTime.setTimeInMillis(plannedDepartureTime.getTimeInMillis()); XmlPullUtil.skipExit(pp, "itdDeparture"); if (!lineDestinationAndCancelled.cancelled) { final Departure departure = new Departure(plannedDepartureTime.getTime(), predictedDepartureTime.isSet(Calendar.HOUR_OF_DAY) ? predictedDepartureTime.getTime() : null, lineDestinationAndCancelled.line, position, lineDestinationAndCancelled.destination, null, null); assignedStationDepartures.departures.add(departure); } } XmlPullUtil.skipExit(pp, "itdDepartureList"); } result.set(r); } catch (final XmlPullParserException x) { throw new ParserException("cannot parse xml: " + bodyPeek, x); } } }; if (httpPost) httpClient.getInputStream(callback, url.build(), url.build().encodedQuery(), "application/x-www-form-urlencoded", httpReferer); else httpClient.getInputStream(callback, url.build(), httpReferer); return result.get(); }
From source file:ddf.catalog.source.solr.SolrProviderTest.java
private Date getCannedTime(int year, int month, int day, int hour) { Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")); calendar.clear(); calendar.set(year, month, day, hour, 59, 56); calendar.set(Calendar.MILLISECOND, 765); return calendar.getTime(); }
From source file:de.schildbach.pte.AbstractHafasMobileProvider.java
protected final QueryDeparturesResult jsonStationBoard(final String stationId, final @Nullable Date time, final int maxDepartures, final boolean equivs) throws IOException { final Calendar c = new GregorianCalendar(timeZone); c.setTime(time);/* w w w . ja v a 2 s . co m*/ final CharSequence jsonDate = jsonDate(c); final CharSequence jsonTime = jsonTime(c); final CharSequence normalizedStationId = normalizeStationId(stationId); final CharSequence stbFltrEquiv = Boolean.toString(!equivs); final CharSequence maxJny = Integer.toString(maxDepartures != 0 ? maxDepartures : DEFAULT_MAX_DEPARTURES); final CharSequence getPasslist = Boolean.toString(true); // traffic expensive final String request = wrapJsonApiRequest("StationBoard", "{\"type\":\"DEP\"," // + "\"date\":\"" + jsonDate + "\"," // + "\"time\":\"" + jsonTime + "\"," // + "\"stbLoc\":{\"type\":\"S\"," + "\"state\":\"F\"," // F/M + "\"extId\":" + JSONObject.quote(normalizedStationId.toString()) + "}," // + "\"stbFltrEquiv\":" + stbFltrEquiv + ",\"maxJny\":" + maxJny + ",\"getPasslist\":" + getPasslist + "}", false); final HttpUrl url = checkNotNull(mgateEndpoint); final CharSequence page = httpClient.get(url, request, "application/json"); try { final JSONObject head = new JSONObject(page.toString()); final String headErr = head.optString("err", null); if (headErr != null) throw new RuntimeException(headErr); final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT, head.getString("ver"), null, 0, null); final QueryDeparturesResult result = new QueryDeparturesResult(header); final JSONArray svcResList = head.getJSONArray("svcResL"); checkState(svcResList.length() == 1); final JSONObject svcRes = svcResList.optJSONObject(0); checkState("StationBoard".equals(svcRes.getString("meth"))); final String err = svcRes.getString("err"); if (!"OK".equals(err)) { final String errTxt = svcRes.getString("errTxt"); log.debug("Hafas error: {} {}", err, errTxt); if ("LOCATION".equals(err) && "HCI Service: location missing or invalid".equals(errTxt)) return new QueryDeparturesResult(header, QueryDeparturesResult.Status.INVALID_STATION); if ("FAIL".equals(err) && "HCI Service: request failed".equals(errTxt)) return new QueryDeparturesResult(header, QueryDeparturesResult.Status.SERVICE_DOWN); throw new RuntimeException(err + " " + errTxt); } else if ("1.10".equals(apiVersion) && svcRes.toString().length() == 170) { // horrible hack, because API version 1.10 doesn't signal invalid stations via error return new QueryDeparturesResult(header, QueryDeparturesResult.Status.INVALID_STATION); } final JSONObject res = svcRes.getJSONObject("res"); final JSONObject common = res.getJSONObject("common"); /* final List<String[]> remarks = */ parseRemList(common.getJSONArray("remL")); final List<String> operators = parseOpList(common.getJSONArray("opL")); final List<Line> lines = parseProdList(common.getJSONArray("prodL"), operators); final JSONArray locList = common.getJSONArray("locL"); final List<Location> locations = parseLocList(locList); final JSONArray jnyList = res.optJSONArray("jnyL"); if (jnyList != null) { for (int iJny = 0; iJny < jnyList.length(); iJny++) { final JSONObject jny = jnyList.getJSONObject(iJny); final JSONObject stbStop = jny.getJSONObject("stbStop"); final String stbStopPlatformS = stbStop.optString("dPlatfS", null); c.clear(); ParserUtils.parseIsoDate(c, jny.getString("date")); final Date baseDate = c.getTime(); final Date plannedTime = parseJsonTime(c, baseDate, stbStop.getString("dTimeS")); final Date predictedTime = parseJsonTime(c, baseDate, stbStop.optString("dTimeR", null)); final Line line = lines.get(stbStop.getInt("dProdX")); final Location location = equivs ? locations.get(stbStop.getInt("locX")) : new Location(LocationType.STATION, stationId); final Position position = normalizePosition(stbStopPlatformS); final String jnyDirTxt = jny.getString("dirTxt"); final JSONArray stopList = jny.optJSONArray("stopL"); final Location destination; if (stopList != null) { final int lastStopIdx = stopList.getJSONObject(stopList.length() - 1).getInt("locX"); final String lastStopName = locList.getJSONObject(lastStopIdx).getString("name"); if (jnyDirTxt.equals(lastStopName)) destination = locations.get(lastStopIdx); else destination = new Location(LocationType.ANY, null, null, jnyDirTxt); } else { destination = new Location(LocationType.ANY, null, null, jnyDirTxt); } final Departure departure = new Departure(plannedTime, predictedTime, line, position, destination, null, null); StationDepartures stationDepartures = findStationDepartures(result.stationDepartures, location); if (stationDepartures == null) { stationDepartures = new StationDepartures(location, new ArrayList<Departure>(8), null); result.stationDepartures.add(stationDepartures); } stationDepartures.departures.add(departure); } } // sort departures for (final StationDepartures stationDepartures : result.stationDepartures) Collections.sort(stationDepartures.departures, Departure.TIME_COMPARATOR); return result; } catch (final JSONException x) { throw new ParserException("cannot parse json: '" + page + "' on " + url, x); } }
From source file:de.schildbach.pte.AbstractHafasMobileProvider.java
protected final QueryTripsResult jsonTripSearch(Location from, @Nullable Location via, Location to, final Date time, final boolean dep, final @Nullable Set<Product> products, final String moreContext) throws IOException { if (!from.hasId()) { from = jsonTripSearchIdentify(from); if (from == null) return new QueryTripsResult(new ResultHeader(network, SERVER_PRODUCT), QueryTripsResult.Status.UNKNOWN_FROM); }//from w w w . jav a 2 s.c o m if (via != null && !via.hasId()) { via = jsonTripSearchIdentify(via); if (via == null) return new QueryTripsResult(new ResultHeader(network, SERVER_PRODUCT), QueryTripsResult.Status.UNKNOWN_VIA); } if (!to.hasId()) { to = jsonTripSearchIdentify(to); if (to == null) return new QueryTripsResult(new ResultHeader(network, SERVER_PRODUCT), QueryTripsResult.Status.UNKNOWN_TO); } final Calendar c = new GregorianCalendar(timeZone); c.setTime(time); final CharSequence outDate = jsonDate(c); final CharSequence outTime = jsonTime(c); final CharSequence outFrwdKey = "1.11".equals(apiVersion) ? "outFrwd" : "frwd"; final CharSequence outFrwd = Boolean.toString(dep); final CharSequence jnyFltr = productsString(products); final CharSequence jsonContext = moreContext != null ? "\"ctxScr\":" + JSONObject.quote(moreContext) + "," : ""; final String request = wrapJsonApiRequest("TripSearch", "{" // + jsonContext // + "\"depLocL\":[" + jsonLocation(from) + "]," // + "\"arrLocL\":[" + jsonLocation(to) + "]," // + (via != null ? "\"viaLocL\":[{\"loc\":" + jsonLocation(via) + "}]," : "") // + "\"outDate\":\"" + outDate + "\"," // + "\"outTime\":\"" + outTime + "\"," // + "\"" + outFrwdKey + "\":" + outFrwd + "," // + "\"jnyFltrL\":[{\"value\":\"" + jnyFltr + "\",\"mode\":\"BIT\",\"type\":\"PROD\"}]," // + "\"gisFltrL\":[{\"mode\":\"FB\",\"profile\":{\"type\":\"F\",\"linDistRouting\":false,\"maxdist\":2000},\"type\":\"P\"}]," // + "\"getPolyline\":false,\"getPasslist\":true,\"getIST\":false,\"getEco\":false,\"extChgTime\":-1}", // false); final HttpUrl url = checkNotNull(mgateEndpoint); final CharSequence page = httpClient.get(url, request, "application/json"); try { final JSONObject head = new JSONObject(page.toString()); final String headErr = head.optString("err", null); if (headErr != null) throw new RuntimeException(headErr); final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT, head.getString("ver"), null, 0, null); final JSONArray svcResList = head.getJSONArray("svcResL"); checkState(svcResList.length() == 1); final JSONObject svcRes = svcResList.optJSONObject(0); checkState("TripSearch".equals(svcRes.getString("meth"))); final String err = svcRes.getString("err"); if (!"OK".equals(err)) { final String errTxt = svcRes.getString("errTxt"); log.debug("Hafas error: {} {}", err, errTxt); if ("H890".equals(err)) // No connections found. return new QueryTripsResult(header, QueryTripsResult.Status.NO_TRIPS); if ("H891".equals(err)) // No route found (try entering an intermediate station). return new QueryTripsResult(header, QueryTripsResult.Status.NO_TRIPS); if ("H895".equals(err)) // Departure/Arrival are too near. return new QueryTripsResult(header, QueryTripsResult.Status.TOO_CLOSE); if ("H9220".equals(err)) // Nearby to the given address stations could not be found. return new QueryTripsResult(header, QueryTripsResult.Status.UNRESOLVABLE_ADDRESS); if ("H9240".equals(err)) // HAFAS Kernel: Internal error. return new QueryTripsResult(header, QueryTripsResult.Status.SERVICE_DOWN); if ("H9360".equals(err)) // Date outside of the timetable period. return new QueryTripsResult(header, QueryTripsResult.Status.INVALID_DATE); if ("H9380".equals(err)) // Departure/Arrival/Intermediate or equivalent stations def'd more // than once. return new QueryTripsResult(header, QueryTripsResult.Status.TOO_CLOSE); if ("FAIL".equals(err) && "HCI Service: request failed".equals(errTxt)) return new QueryTripsResult(header, QueryTripsResult.Status.SERVICE_DOWN); throw new RuntimeException(err + " " + errTxt); } final JSONObject res = svcRes.getJSONObject("res"); final JSONObject common = res.getJSONObject("common"); /* final List<String[]> remarks = */ parseRemList(common.getJSONArray("remL")); final List<Location> locations = parseLocList(common.getJSONArray("locL")); final List<String> operators = parseOpList(common.getJSONArray("opL")); final List<Line> lines = parseProdList(common.getJSONArray("prodL"), operators); final JSONArray outConList = res.optJSONArray("outConL"); final List<Trip> trips = new ArrayList<>(outConList.length()); for (int iOutCon = 0; iOutCon < outConList.length(); iOutCon++) { final JSONObject outCon = outConList.getJSONObject(iOutCon); final Location tripFrom = locations.get(outCon.getJSONObject("dep").getInt("locX")); final Location tripTo = locations.get(outCon.getJSONObject("arr").getInt("locX")); c.clear(); ParserUtils.parseIsoDate(c, outCon.getString("date")); final Date baseDate = c.getTime(); final JSONArray secList = outCon.optJSONArray("secL"); final List<Trip.Leg> legs = new ArrayList<>(secList.length()); for (int iSec = 0; iSec < secList.length(); iSec++) { final JSONObject sec = secList.getJSONObject(iSec); final String secType = sec.getString("type"); final JSONObject secDep = sec.getJSONObject("dep"); final Stop departureStop = parseJsonStop(secDep, locations, c, baseDate); final JSONObject secArr = sec.getJSONObject("arr"); final Stop arrivalStop = parseJsonStop(secArr, locations, c, baseDate); final Trip.Leg leg; if ("JNY".equals(secType)) { final JSONObject jny = sec.getJSONObject("jny"); final Line line = lines.get(jny.getInt("prodX")); final String dirTxt = jny.optString("dirTxt", null); final Location destination = dirTxt != null ? new Location(LocationType.ANY, null, null, dirTxt) : null; final JSONArray stopList = jny.getJSONArray("stopL"); checkState(stopList.length() >= 2); final List<Stop> intermediateStops = new ArrayList<>(stopList.length()); for (int iStop = 1; iStop < stopList.length() - 1; iStop++) { final JSONObject stop = stopList.getJSONObject(iStop); final Stop intermediateStop = parseJsonStop(stop, locations, c, baseDate); intermediateStops.add(intermediateStop); } leg = new Trip.Public(line, destination, departureStop, arrivalStop, intermediateStops, null, null); } else if ("WALK".equals(secType) || "TRSF".equals(secType)) { final JSONObject gis = sec.getJSONObject("gis"); final int distance = gis.optInt("dist", 0); leg = new Trip.Individual(Trip.Individual.Type.WALK, departureStop.location, departureStop.getDepartureTime(), arrivalStop.location, arrivalStop.getArrivalTime(), null, distance); } else { throw new IllegalStateException("cannot handle type: " + secType); } legs.add(leg); } final JSONObject trfRes = outCon.optJSONObject("trfRes"); final List<Fare> fares = new LinkedList<>(); if (trfRes != null) { final JSONArray fareSetList = trfRes.getJSONArray("fareSetL"); for (int iFareSet = 0; iFareSet < fareSetList.length(); iFareSet++) { final JSONObject fareSet = fareSetList.getJSONObject(iFareSet); final String fareSetName = fareSet.optString("name", null); final String fareSetDescription = fareSet.optString("desc", null); if (fareSetName != null || fareSetDescription != null) { final JSONArray fareList = fareSet.getJSONArray("fareL"); for (int iFare = 0; iFare < fareList.length(); iFare++) { final JSONObject jsonFare = fareList.getJSONObject(iFare); final String name = jsonFare.getString("name"); final JSONArray ticketList = jsonFare.optJSONArray("ticketL"); if (ticketList != null) { for (int iTicket = 0; iTicket < ticketList.length(); iTicket++) { final JSONObject jsonTicket = ticketList.getJSONObject(iTicket); final String ticketName = jsonTicket.getString("name"); final Currency currency = Currency.getInstance(jsonTicket.getString("cur")); final float price = jsonTicket.getInt("prc") / 100f; final Fare fare = parseJsonTripFare(name, fareSetDescription, ticketName, currency, price); if (fare != null) fares.add(fare); } } else { final Currency currency = Currency.getInstance(jsonFare.getString("cur")); final float price = jsonFare.getInt("prc") / 100f; final Fare fare = parseJsonTripFare(fareSetName, fareSetDescription, name, currency, price); if (fare != null) fares.add(fare); } } } } } final Trip trip = new Trip(null, tripFrom, tripTo, legs, fares, null, null); trips.add(trip); } final JsonContext context = new JsonContext(from, via, to, time, dep, products, res.optString("outCtxScrF"), res.optString("outCtxScrB")); return new QueryTripsResult(header, null, from, null, to, context, trips); } catch (final JSONException x) { throw new ParserException("cannot parse json: '" + page + "' on " + url, x); } }
From source file:de.schildbach.pte.AbstractEfaProvider.java
private QueryTripsResult queryTripsMobile(final HttpUrl url, final Location from, final @Nullable Location via, final Location to, final InputStream is) throws XmlPullParserException, IOException { final XmlPullParser pp = parserFactory.newPullParser(); pp.setInput(is, null); // Read encoding from XML declaration final ResultHeader header = enterEfa(pp); final Calendar plannedTimeCal = new GregorianCalendar(timeZone); final Calendar predictedTimeCal = new GregorianCalendar(timeZone); final List<Trip> trips = new ArrayList<>(); if (XmlPullUtil.optEnter(pp, "ts")) { while (XmlPullUtil.optEnter(pp, "tp")) { XmlPullUtil.optSkip(pp, "attrs"); XmlPullUtil.valueTag(pp, "d"); // duration final int numChanges = Integer.parseInt(XmlPullUtil.valueTag(pp, "ic")); final String tripId = XmlPullUtil.valueTag(pp, "de"); XmlPullUtil.optValueTag(pp, "optval", null); XmlPullUtil.optValueTag(pp, "alt", null); XmlPullUtil.optValueTag(pp, "gix", null); XmlPullUtil.enter(pp, "ls"); final List<Trip.Leg> legs = new LinkedList<>(); Location firstDepartureLocation = null; Location lastArrivalLocation = null; while (XmlPullUtil.test(pp, "l")) { XmlPullUtil.enter(pp, "l"); XmlPullUtil.enter(pp, "ps"); Stop departure = null;// w w w . j av a 2 s .c o m Stop arrival = null; while (XmlPullUtil.optEnter(pp, "p")) { final String name = XmlPullUtil.valueTag(pp, "n"); final String usage = XmlPullUtil.valueTag(pp, "u"); XmlPullUtil.optValueTag(pp, "de", null); XmlPullUtil.requireSkip(pp, "dt"); parseMobileSt(pp, plannedTimeCal, predictedTimeCal); XmlPullUtil.requireSkip(pp, "lis"); XmlPullUtil.enter(pp, "r"); final String id = XmlPullUtil.valueTag(pp, "id"); XmlPullUtil.optValueTag(pp, "a", null); final Position position = parsePosition(XmlPullUtil.optValueTag(pp, "pl", null)); final String place = normalizeLocationName(XmlPullUtil.optValueTag(pp, "pc", null)); final Point coord = parseCoord(XmlPullUtil.optValueTag(pp, "c", null)); XmlPullUtil.skipExit(pp, "r"); final Location location; if (id.equals("99999997") || id.equals("99999998")) location = new Location(LocationType.ADDRESS, null, coord, place, name); else location = new Location(LocationType.STATION, id, coord, place, name); XmlPullUtil.skipExit(pp, "p"); final Date plannedTime = plannedTimeCal.isSet(Calendar.HOUR_OF_DAY) ? plannedTimeCal.getTime() : null; final Date predictedTime = predictedTimeCal.isSet(Calendar.HOUR_OF_DAY) ? predictedTimeCal.getTime() : null; if ("departure".equals(usage)) { departure = new Stop(location, true, plannedTime, predictedTime, position, null); if (firstDepartureLocation == null) firstDepartureLocation = location; } else if ("arrival".equals(usage)) { arrival = new Stop(location, false, plannedTime, predictedTime, position, null); lastArrivalLocation = location; } else { throw new IllegalStateException("unknown usage: " + usage); } } checkState(departure != null); checkState(arrival != null); XmlPullUtil.skipExit(pp, "ps"); final boolean isRealtime = XmlPullUtil.valueTag(pp, "realtime").equals("1"); final LineDestination lineDestination = parseMobileM(pp, false); final List<Point> path; if (XmlPullUtil.test(pp, "pt")) path = processCoordinateStrings(pp, "pt"); else path = null; final List<Stop> intermediateStops; XmlPullUtil.require(pp, "pss"); if (XmlPullUtil.optEnter(pp, "pss")) { intermediateStops = new LinkedList<>(); while (XmlPullUtil.test(pp, "s")) { plannedTimeCal.clear(); predictedTimeCal.clear(); final String s = XmlPullUtil.valueTag(pp, "s"); final String[] intermediateParts = s.split(";"); final String id = intermediateParts[0]; if (!id.equals(departure.location.id) && !id.equals(arrival.location.id)) { final String name = normalizeLocationName(intermediateParts[1]); if (!("0000-1".equals(intermediateParts[2]) && "000-1".equals(intermediateParts[3]))) { ParserUtils.parseIsoDate(plannedTimeCal, intermediateParts[2]); ParserUtils.parseIsoTime(plannedTimeCal, intermediateParts[3]); if (isRealtime) { ParserUtils.parseIsoDate(predictedTimeCal, intermediateParts[2]); ParserUtils.parseIsoTime(predictedTimeCal, intermediateParts[3]); if (intermediateParts.length > 5 && intermediateParts[5].length() > 0) { final int delay = Integer.parseInt(intermediateParts[5]); predictedTimeCal.add(Calendar.MINUTE, delay); } } } final String coordPart = intermediateParts[4]; final Point coords; if (!"::".equals(coordPart)) { final String[] coordParts = coordPart.split(":"); if ("WGS84".equals(coordParts[2])) { final int lat = (int) Math.round(Double.parseDouble(coordParts[1])); final int lon = (int) Math.round(Double.parseDouble(coordParts[0])); coords = new Point(lat, lon); } else { coords = null; } } else { coords = null; } final Location location = new Location(LocationType.STATION, id, coords, null, name); final Date plannedTime = plannedTimeCal.isSet(Calendar.HOUR_OF_DAY) ? plannedTimeCal.getTime() : null; final Date predictedTime = predictedTimeCal.isSet(Calendar.HOUR_OF_DAY) ? predictedTimeCal.getTime() : null; final Stop stop = new Stop(location, false, plannedTime, predictedTime, null, null); intermediateStops.add(stop); } } XmlPullUtil.skipExit(pp, "pss"); } else { intermediateStops = null; } XmlPullUtil.optSkip(pp, "interchange"); XmlPullUtil.requireSkip(pp, "ns"); // TODO messages XmlPullUtil.skipExit(pp, "l"); if (lineDestination.line == Line.FOOTWAY) { legs.add(new Trip.Individual(Trip.Individual.Type.WALK, departure.location, departure.getDepartureTime(), arrival.location, arrival.getArrivalTime(), path, 0)); } else if (lineDestination.line == Line.TRANSFER) { legs.add(new Trip.Individual(Trip.Individual.Type.TRANSFER, departure.location, departure.getDepartureTime(), arrival.location, arrival.getArrivalTime(), path, 0)); } else if (lineDestination.line == Line.SECURE_CONNECTION || lineDestination.line == Line.DO_NOT_CHANGE) { // ignore } else { legs.add(new Trip.Public(lineDestination.line, lineDestination.destination, departure, arrival, intermediateStops, path, null)); } } XmlPullUtil.skipExit(pp, "ls"); XmlPullUtil.optSkip(pp, "seqroutes"); final List<Fare> fares; if (XmlPullUtil.optEnter(pp, "tcs")) { fares = new ArrayList<>(2); XmlPullUtil.optSkipMultiple(pp, "tc"); // TODO fares XmlPullUtil.skipExit(pp, "tcs"); } else { fares = null; } final Trip trip = new Trip(tripId, firstDepartureLocation, lastArrivalLocation, legs, fares, null, numChanges); trips.add(trip); XmlPullUtil.skipExit(pp, "tp"); } XmlPullUtil.skipExit(pp, "ts"); } if (trips.size() > 0) { final String[] context = (String[]) header.context; return new QueryTripsResult(header, url.toString(), from, via, to, new Context(commandLink(context[0], context[1]).toString()), trips); } else { return new QueryTripsResult(header, QueryTripsResult.Status.NO_TRIPS); } }