List of usage examples for android.text.format DateUtils FORMAT_SHOW_WEEKDAY
int FORMAT_SHOW_WEEKDAY
To view the source code for android.text.format DateUtils FORMAT_SHOW_WEEKDAY.
Click Source Link
From source file:net.abcdroid.devfest12.ui.MyScheduleFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (getActivity() == null) { return;//from w w w . j a v a 2s . c o m } long currentTime = UIUtils.getCurrentTime(getActivity()); int firstNowPosition = ListView.INVALID_POSITION; List<SimpleSectionedListAdapter.Section> sections = new ArrayList<SimpleSectionedListAdapter.Section>(); cursor.moveToFirst(); long previousBlockStart = -1; long blockStart, blockEnd; while (!cursor.isAfterLast()) { blockStart = cursor.getLong(BlocksQuery.BLOCK_START); blockEnd = cursor.getLong(BlocksQuery.BLOCK_END); if (!UIUtils.isSameDay(previousBlockStart, blockStart)) { sections.add(new SimpleSectionedListAdapter.Section(cursor.getPosition(), DateUtils.formatDateTime(getActivity(), blockStart, DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY))); } if (mScrollToNow && firstNowPosition == ListView.INVALID_POSITION // if we're currently in this block, or we're not in a block // and this // block is in the future, then this is the scroll position && ((blockStart < currentTime && currentTime < blockEnd) || blockStart > currentTime)) { firstNowPosition = cursor.getPosition(); } previousBlockStart = blockStart; cursor.moveToNext(); } mScheduleAdapter.changeCursor(cursor); SimpleSectionedListAdapter.Section[] dummy = new SimpleSectionedListAdapter.Section[sections.size()]; mAdapter.setSections(sections.toArray(dummy)); if (mScrollToNow && firstNowPosition != ListView.INVALID_POSITION) { firstNowPosition = mAdapter.positionToSectionedPosition(firstNowPosition); getListView().setSelectionFromTop(firstNowPosition, getResources().getDimensionPixelSize(R.dimen.list_scroll_top_offset)); mScrollToNow = false; } }
From source file:com.google.android.apps.iosched.ui.MyScheduleFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (getActivity() == null || cursor == null) { return;//w w w. j av a2 s. com } long currentTime = UIUtils.getCurrentTime(getActivity()); int firstNowPosition = ListView.INVALID_POSITION; List<SimpleSectionedListAdapter.Section> sections = new ArrayList<SimpleSectionedListAdapter.Section>(); cursor.moveToFirst(); long previousBlockStart = -1; long blockStart, blockEnd; while (!cursor.isAfterLast()) { blockStart = cursor.getLong(BlocksQuery.BLOCK_START); blockEnd = cursor.getLong(BlocksQuery.BLOCK_END); if (!UIUtils.isSameDay(previousBlockStart, blockStart)) { sections.add(new SimpleSectionedListAdapter.Section(cursor.getPosition(), DateUtils.formatDateTime(getActivity(), blockStart, DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY))); } if (mScrollToNow && firstNowPosition == ListView.INVALID_POSITION // if we're currently in this block, or we're not in a block // and this // block is in the future, then this is the scroll position && ((blockStart < currentTime && currentTime < blockEnd) || blockStart > currentTime)) { firstNowPosition = cursor.getPosition(); } previousBlockStart = blockStart; cursor.moveToNext(); } mScheduleAdapter.changeCursor(cursor); SimpleSectionedListAdapter.Section[] dummy = new SimpleSectionedListAdapter.Section[sections.size()]; mAdapter.setSections(sections.toArray(dummy)); if (mScrollToNow && firstNowPosition != ListView.INVALID_POSITION) { firstNowPosition = mAdapter.positionToSectionedPosition(firstNowPosition); getListView().setSelectionFromTop(firstNowPosition, getResources().getDimensionPixelSize(R.dimen.list_scroll_top_offset)); mScrollToNow = false; } }
From source file:com.hyperaware.conference.android.fragment.SessionDetailFragment.java
private void updateSessionDetail() { tvTopic.setText(agendaItem.getTopic()); host.setTitle(agendaItem.getTopic()); final StringBuilder sb = new StringBuilder(); final Formatter formatter = new Formatter(sb); final long start_ms = TimeUnit.SECONDS.toMillis(agendaItem.getEpochStartTime()); final long end_ms = TimeUnit.SECONDS.toMillis(agendaItem.getEpochEndTime()); sb.setLength(0);//from www. j ava2s .c o m DateUtils.formatDateRange(getActivity(), formatter, start_ms, end_ms, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY, tz.getID()); tvDate.setText(formatter.toString()); sb.setLength(0); DateUtils.formatDateRange(getActivity(), formatter, start_ms, end_ms, DateUtils.FORMAT_SHOW_TIME, tz.getID()); tvTime.setText(formatter.toString()); final String location = agendaItem.getLocation(); if (!Strings.isNullOrEmpty(location)) { tvLocation.setText(agendaItem.getLocation()); } else { tvLocation.setVisibility(View.GONE); } tvDescription.setText(agendaItem.getDescription()); // Only sessions with speakers can have feedback final View feedback = vgActions.findViewById(R.id.tv_session_feedback); if (speakerItems.size() > 0) { feedback.setOnClickListener(new SessionFeedbackOnClickListener()); vgActions.setVisibility(View.VISIBLE); } else { vgActions.setVisibility(View.GONE); } if (speakerItems.size() > 0) { vgSpeakers.setVisibility(View.VISIBLE); vgSpeakers.removeAllViews(); final LayoutInflater inflater = getActivity().getLayoutInflater(); for (final SpeakerItem item : speakerItems) { final View view = inflater.inflate(R.layout.item_session_speaker, vgSpeakers, false); ImageView iv = (ImageView) view.findViewById(R.id.iv_pic); Glide.with(SessionDetailFragment.this).load(item.getImage100()).placeholder(R.drawable.nopic) .into(iv); ((TextView) view.findViewById(R.id.tv_name)).setText(item.getName()); if (host != null) { view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Fragment next = SpeakerDetailFragment.instantiate(item.getId()); host.pushFragment(next, "speaker_detail"); } }); } vgSpeakers.addView(view); } } }
From source file:org.jraf.android.piclabel.app.form.FormActivity.java
protected ImageInfo extractImageInfo(File file) { ImageInfo res = new ImageInfo(); ExifInterface exifInterface = null;/*from w w w . jav a 2s . c o m*/ try { exifInterface = new ExifInterface(file.getPath()); } catch (IOException e) { Log.e(TAG, "extractImageInfo Could not read exif", e); } // Date String dateTimeStr = null; if (exifInterface != null) dateTimeStr = exifInterface.getAttribute(ExifInterface.TAG_DATETIME); if (TextUtils.isEmpty(dateTimeStr)) { // No date in exif: use 'local' date res.dateTime = DateUtils.formatDateTime(this, System.currentTimeMillis(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_YEAR); res.isLocalDateTime = true; } else { res.dateTime = parseExifDateTime(dateTimeStr); if (res.dateTime == null) { // Date in exif could not be parsed: use 'local' date DateUtils.formatDateTime(this, System.currentTimeMillis(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_YEAR); res.isLocalDateTime = true; } } // Location float[] latLon = new float[2]; boolean latLonPresent = exifInterface != null && exifInterface.getLatLong(latLon); if (!latLonPresent) { // No location in exif: use 'local' location res.isLocalLocation = true; latLonPresent = getLatestLocalLocation(latLon); if (latLonPresent) res.location = reverseGeocode(latLon[0], latLon[1]); } else { res.location = reverseGeocode(latLon[0], latLon[1]); } if (res.location == null) { res.reverseGeocodeProblem = true; res.location = ""; } return res; }
From source file:com.google.android.apps.muzei.gallery.GalleryArtSource.java
private void publishNextArtwork(Uri forceUri) { // schedule next scheduleNext();/*w ww .j a v a 2s .c om*/ Cursor chosenUris = getContentResolver().query(GalleryContract.ChosenPhotos.CONTENT_URI, new String[] { BaseColumns._ID }, null, null, null); int numChosenUris = (chosenUris != null) ? chosenUris.getCount() : 0; Artwork currentArtwork = getCurrentArtwork(); String lastToken = (currentArtwork != null) ? currentArtwork.getToken() : null; Uri imageUri; Random random = new Random(); if (forceUri != null) { imageUri = forceUri; } else if (numChosenUris > 0) { while (true) { chosenUris.moveToPosition(random.nextInt(chosenUris.getCount())); imageUri = ContentUris.withAppendedId(GalleryContract.ChosenPhotos.CONTENT_URI, chosenUris.getLong(chosenUris.getColumnIndex(BaseColumns._ID))); if (numChosenUris <= 1 || !imageUri.toString().equals(lastToken)) { break; } } } else { if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { Log.w(TAG, "Missing read external storage permission."); return; } Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.MediaColumns._ID }, MediaStore.Images.Media.BUCKET_DISPLAY_NAME + " NOT LIKE '%Screenshots%'", null, null); if (cursor == null) { Log.w(TAG, "Empty cursor."); return; } int count = cursor.getCount(); if (count == 0) { Log.e(TAG, "No photos in the gallery."); return; } while (true) { cursor.moveToPosition(random.nextInt(count)); imageUri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, cursor.getLong(0)); if (!imageUri.toString().equals(lastToken)) { break; } } cursor.close(); } if (chosenUris != null) { chosenUris.close(); } String token = imageUri.toString(); // Retrieve metadata for item ensureMetadataExists(imageUri); String[] projection = { GalleryContract.MetadataCache.COLUMN_NAME_DATETIME, GalleryContract.MetadataCache.COLUMN_NAME_LOCATION }; Cursor metadata = getContentResolver().query(GalleryContract.MetadataCache.CONTENT_URI, projection, GalleryContract.MetadataCache.COLUMN_NAME_URI + "=?", new String[] { imageUri.toString() }, null); long datetime = 0; String location = null; if (metadata != null && metadata.moveToFirst()) { datetime = metadata .getLong(metadata.getColumnIndex(GalleryContract.MetadataCache.COLUMN_NAME_DATETIME)); location = metadata .getString(metadata.getColumnIndex(GalleryContract.MetadataCache.COLUMN_NAME_LOCATION)); } if (metadata != null) { metadata.close(); } // Publish the actual artwork String title; if (datetime > 0) { title = DateUtils.formatDateTime(this, datetime, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_WEEKDAY); } else { title = getString(R.string.gallery_from_gallery); } String byline; if (!TextUtils.isEmpty(location)) { byline = location; } else { byline = getString(R.string.gallery_touch_to_view); } publishArtwork(new Artwork.Builder().imageUri(imageUri).title(title).byline(byline).token(token) .viewIntent(new Intent(Intent.ACTION_VIEW).setDataAndType(imageUri, "image/jpeg")).build()); }
From source file:com.hyperaware.conference.android.fragment.SpeakerDetailFragment.java
private void updateSpeaker() { tvName.setText(speakerItem.getName()); host.setTitle(speakerItem.getName()); final String company = speakerItem.getCompanyName(); tvCompany.setVisibility(Strings.isNullOrEmpty(company) ? View.GONE : View.VISIBLE); tvCompany.setText(company);/*from w w w . j ava 2s . c o m*/ final String title = speakerItem.getTitle(); tvTitle.setVisibility(Strings.isNullOrEmpty(title) ? View.GONE : View.VISIBLE); tvTitle.setText(title); Glide.with(SpeakerDetailFragment.this).load(speakerItem.getImage100()).fitCenter() .placeholder(R.drawable.nopic).into(ivPic); boolean links_visible = false; final String website = speakerItem.getWebsite(); if (!Strings.isNullOrEmpty(website)) { links_visible = true; tvWebsite.setVisibility(View.VISIBLE); tvWebsite.setText(website); } final String twitter = speakerItem.getTwitter(); if (!Strings.isNullOrEmpty(twitter)) { links_visible = true; tvTwitter.setVisibility(View.VISIBLE); tvTwitter.setText(twitter); } final String facebook = speakerItem.getFacebook(); if (!Strings.isNullOrEmpty(facebook)) { links_visible = true; tvFacebook.setVisibility(View.VISIBLE); tvFacebook.setText(facebook); } final String linkedin = speakerItem.getLinkedin(); if (!Strings.isNullOrEmpty(linkedin)) { links_visible = true; tvLinkedin.setVisibility(View.VISIBLE); tvLinkedin.setText(linkedin); } vgDetailLinks.setVisibility(links_visible ? View.VISIBLE : View.GONE); tvAbout.setText(speakerItem.getAbout()); if (agendaItems.size() > 0) { vgSessions.setVisibility(View.VISIBLE); vgSessions.removeAllViews(); final StringBuilder sb = new StringBuilder(); final Formatter formatter = new Formatter(sb); final LayoutInflater inflater = getActivity().getLayoutInflater(); for (final AgendaItem item : agendaItems) { final View view = inflater.inflate(R.layout.item_speaker_session, vgSessions, false); ((TextView) view.findViewById(R.id.tv_topic)).setText(item.getTopic()); sb.setLength(0); DateUtils.formatDateRange(getActivity(), formatter, item.getEpochStartTime() * 1000, item.getEpochEndTime() * 1000, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY, tz.getID()); ((TextView) view.findViewById(R.id.tv_date)).setText(formatter.toString()); sb.setLength(0); DateUtils.formatDateRange(getActivity(), formatter, item.getEpochStartTime() * 1000, item.getEpochEndTime() * 1000, DateUtils.FORMAT_SHOW_TIME, tz.getID()); ((TextView) view.findViewById(R.id.tv_time)).setText(formatter.toString()); final String session_id = item.getId(); final ImageButton ib_favorite = (ImageButton) view.findViewById(R.id.button_favorite_session); favSessionButtonManager.attach(ib_favorite, session_id); if (host != null) { view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Fragment next = SessionDetailFragment.instantiate(item.getId()); host.pushFragment(next, "session_detail"); } }); } vgSessions.addView(view); } } }
From source file:org.jraf.android.bikey.app.ride.detail.RideDetailActivity.java
private void loadData() { new TaskFragment(new Task<RideDetailActivity>() { private String mName; private Date mCreatedDate; private long mDuration; private float mDistance; private float mAverageMovingSpeed; private float mMaxSpeed; private Date mFirstActivatedDate; private Long mMovingDuration; private Float mAverageCadence; private float mMaxCadence; private List<LatLng> mLatLngArray; private float[] mSpeedArray; private float[] mCadenceArray; private float mMinHeartRate; private float mMaxHeartRate; private Float mAverageHeartRate; private float[] mHeartRateArray; @Override/*from w w w.j a v a 2 s .c om*/ protected void doInBackground() throws Throwable { RideManager rideManager = RideManager.get(); Uri rideUri = getActivity().mRideUri; RideCursor rideCursor = rideManager.query(rideUri); mName = rideCursor.getName(); mCreatedDate = rideCursor.getCreatedDate(); mFirstActivatedDate = rideCursor.getFirstActivatedDate(); mDuration = rideCursor.getDuration(); mDistance = rideCursor.getDistance(); rideCursor.close(); LogManager logManager = LogManager.get(); mAverageMovingSpeed = logManager.getAverageMovingSpeed(rideUri); mMaxSpeed = logManager.getMaxSpeed(rideUri); mMovingDuration = logManager.getMovingDuration(rideUri); mAverageCadence = logManager.getAverageCadence(rideUri); mMaxCadence = logManager.getMaxCadence(rideUri); mMinHeartRate = logManager.getMinHeartRate(rideUri); mMaxHeartRate = logManager.getMaxHeartRate(rideUri); mAverageHeartRate = logManager.getAverageHeartRate(rideUri); mLatLngArray = logManager.getLatLngArray(rideUri, POINTS_TO_GRAPH); List<Float> speedList = logManager.getSpeedArray(rideUri, POINTS_TO_GRAPH); mSpeedArray = CollectionUtil.unwrap(speedList.toArray(new Float[speedList.size()])); mSpeedArray = MathUtil.getMovingAverage(mSpeedArray, mSpeedArray.length / 10); List<Float> cadenceList = logManager.getCadenceArray(rideUri, POINTS_TO_GRAPH); mCadenceArray = CollectionUtil.unwrap(cadenceList.toArray(new Float[cadenceList.size()])); mCadenceArray = MathUtil.getMovingAverage(mCadenceArray, mCadenceArray.length / 10); List<Float> heartRateList = logManager.getHeartRateArray(rideUri, POINTS_TO_GRAPH); mHeartRateArray = CollectionUtil.unwrap(heartRateList.toArray(new Float[heartRateList.size()])); mHeartRateArray = MathUtil.getMovingAverage(mHeartRateArray, mHeartRateArray.length / 10); } @Override protected void onPostExecuteOk() { RideDetailActivity a = getActivity(); if (mName != null) a.setTitle(mName); a.mTxtDateTimeDate.setText(DateUtils.formatDateTime(a, mCreatedDate.getTime(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_YEAR)); if (mLatLngArray.isEmpty()) { // Special case: we have no points. Show empty screen. a.mConMap.setVisibility(View.GONE); a.mConDetailedInfo.setVisibility(View.GONE); a.mTxtEmpty.setVisibility(View.VISIBLE); return; } if (mFirstActivatedDate != null) { a.mTxtDateTimeStart.setText( DateUtils.formatDateTime(a, mFirstActivatedDate.getTime(), DateUtils.FORMAT_SHOW_TIME)); a.mTxtDateTimeFinish.setText(DateUtils.formatDateTime(a, mFirstActivatedDate.getTime() + mDuration, DateUtils.FORMAT_SHOW_TIME)); } if (mMovingDuration != null) a.mTxtDurationMoving.setText(DateTimeUtil.formatDuration(a, mMovingDuration.longValue())); a.mTxtDurationTotal.setText(DateTimeUtil.formatDuration(a, mDuration)); a.mTxtDistanceTotal.setText(UnitUtil.formatDistance(mDistance, true, .85f, false)); a.mTxtSpeedAverage.setText(UnitUtil.formatSpeed(mAverageMovingSpeed, true, .85f, false)); a.mTxtSpeedMax.setText(UnitUtil.formatSpeed(mMaxSpeed, true, .85f, false)); // Cadence if (mAverageCadence == null) { a.mTxtCadenceSectionTitle.setVisibility(View.GONE); a.mTxtCadenceAverage.setVisibility(View.GONE); a.mTxtCadenceMax.setVisibility(View.GONE); a.mGrpCadence.setVisibility(View.GONE); } else { a.mTxtCadenceSectionTitle.setVisibility(View.VISIBLE); a.mTxtCadenceAverage.setVisibility(View.VISIBLE); a.mTxtCadenceAverage.setText(UnitUtil.formatCadence(mAverageCadence, true)); a.mTxtCadenceMax.setVisibility(View.VISIBLE); a.mTxtCadenceMax.setText(UnitUtil.formatCadence(mMaxCadence, true)); a.mGrpCadence.setVisibility(View.VISIBLE); a.mGrpCadence.setColor(0, a.getResources().getColor(R.color.graph_line)); a.mGrpCadence.setValues(0, mCadenceArray); } // Map if (mLatLngArray.size() > 0) { PolylineOptions polylineOptions = new PolylineOptions().addAll(mLatLngArray); polylineOptions.color(getResources().getColor(R.color.map_polyline)); a.getMap().addPolyline(polylineOptions); // Calculate bounds LatLngBounds bounds = new LatLngBounds(mLatLngArray.get(0), mLatLngArray.get(0)); for (LatLng latLng : mLatLngArray) { bounds = bounds.including(latLng); } int padding = getResources().getDimensionPixelSize(R.dimen.ride_detail_map_padding); a.getMap().moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, padding)); a.mConMap.setVisibility(View.VISIBLE); } // Speed graph a.mGrpSpeed.setColor(0, a.getResources().getColor(R.color.graph_line)); a.mGrpSpeed.setValues(0, mSpeedArray); // Heart rate if (mAverageHeartRate == null) { a.mTxtHeartRateSectionTitle.setVisibility(View.GONE); a.mTxtHeartRateAverage.setVisibility(View.GONE); a.mTxtHeartRateMin.setVisibility(View.GONE); a.mTxtHeartRateMax.setVisibility(View.GONE); a.mGrpHeartRate.setVisibility(View.GONE); } else { a.mTxtHeartRateSectionTitle.setVisibility(View.VISIBLE); a.mTxtHeartRateAverage.setVisibility(View.VISIBLE); a.mTxtHeartRateAverage.setText(UnitUtil.formatHeartRate(mAverageHeartRate.intValue(), true)); a.mTxtHeartRateMin.setVisibility(View.VISIBLE); a.mTxtHeartRateMin.setText(UnitUtil.formatHeartRate((int) mMinHeartRate, true)); a.mTxtHeartRateMax.setVisibility(View.VISIBLE); a.mTxtHeartRateMax.setText(UnitUtil.formatHeartRate((int) mMaxHeartRate, true)); a.mGrpHeartRate.setVisibility(View.VISIBLE); a.mGrpHeartRate.setColor(0, a.getResources().getColor(R.color.graph_line)); a.mGrpHeartRate.setValues(0, mHeartRateArray); } } }).execute(getSupportFragmentManager()); }
From source file:com.conferenceengineer.android.iosched.ui.ScheduleFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (!isAdded()) { return;/*w w w . j a v a2 s . c om*/ } Context context = getActivity(); long currentTime = UIUtils.getCurrentTime(getActivity()); int firstNowPosition = ListView.INVALID_POSITION; String displayTimeZone = PrefUtils.getDisplayTimeZone(context).getID(); List<SimpleSectionedListAdapter.Section> sections = new ArrayList<SimpleSectionedListAdapter.Section>(); cursor.moveToFirst(); long previousBlockStart = -1; long blockStart, blockEnd; while (!cursor.isAfterLast()) { blockStart = cursor.getLong(BlocksQuery.BLOCK_START); blockEnd = cursor.getLong(BlocksQuery.BLOCK_END); if (!UIUtils.isSameDayDisplay(previousBlockStart, blockStart, context)) { mBuffer.setLength(0); sections.add( new SimpleSectionedListAdapter.Section(cursor.getPosition(), DateUtils .formatDateRange(context, mFormatter, blockStart, blockStart, DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY, displayTimeZone) .toString())); } if (mScrollToNow && firstNowPosition == ListView.INVALID_POSITION // if we're currently in this block, or we're not in a block // and this block is in the future, then this is the scroll position && ((blockStart < currentTime && currentTime < blockEnd) || blockStart > currentTime)) { firstNowPosition = cursor.getPosition(); } previousBlockStart = blockStart; cursor.moveToNext(); } mScheduleAdapter.swapCursor(cursor); SimpleSectionedListAdapter.Section[] dummy = new SimpleSectionedListAdapter.Section[sections.size()]; mAdapter.setSections(sections.toArray(dummy)); if (mScrollToNow && firstNowPosition != ListView.INVALID_POSITION) { firstNowPosition = mAdapter.positionToSectionedPosition(firstNowPosition); getListView().setSelectionFromTop(firstNowPosition, getResources().getDimensionPixelSize(R.dimen.list_scroll_top_offset)); mScrollToNow = false; } }
From source file:org.jraf.android.piclabel.app.form.FormActivity.java
private String parseExifDateTime(String s) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy':'MM':'dd' 'HH':'mm':'ss", Locale.US); Date date;//from w w w.j a va2 s . c om try { date = sdf.parse(s); } catch (ParseException e) { Log.e(TAG, "decodeExifDateTime Could not parse " + s, e); return null; } return DateUtils.formatDateTime(this, date.getTime(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_YEAR); }
From source file:org.dmfs.webcal.fragments.CalendarItemFragment.java
@Override public View onCreateItemView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View returnView = inflater.inflate(R.layout.fragment_calendar_item, container, false); // TODO: don't put the progress indicator into the header view View progressView = inflater.inflate(R.layout.progress_indicator, null, false); mProgressBar = (ProgressBar) progressView.findViewById(android.R.id.progress); mListView = (ListView) returnView.findViewById(android.R.id.list); mListView.addHeaderView(progressView); mListView.setOnItemClickListener(this); mListView.setHeaderDividersEnabled(false); mListAdapter = new EventListAdapter(inflater.getContext(), null); mListView.setAdapter(mSectionAdapter = new SectionTitlesAdapter(inflater.getContext(), mListAdapter, new SectionIndexer() { @Override// w w w . ja va2 s. c om public String getSectionTitle(int index) { Time start = new Time(TimeZone.getDefault().getID()); start.set(index & 0x00ff, (index >> 8) & 0x00ff, (index >> 16) & 0x0ffff); return DateUtils.formatDateTime(getActivity(), start.toMillis(true), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_ABBREV_WEEKDAY); } @Override public int getSectionIndex(Object object) { Cursor cursor = (Cursor) object; Time start = new Time( cursor.getString(cursor.getColumnIndex(WebCalReaderContract.Events.TIMZONE))); start.set(cursor.getLong(cursor.getColumnIndex(WebCalReaderContract.Events.DTSTART))); boolean allday = cursor .getInt(cursor.getColumnIndex(WebCalReaderContract.Events.IS_ALLDAY)) == 1; start.allDay = allday; // we return an encoded date as index return (start.year << 16) + (start.month << 8) + start.monthDay; } }, R.layout.events_preview_list_section_header)); FragmentManager fm = getChildFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); mTitleFragment = (CalendarTitleFragment) fm.findFragmentById(R.id.calendar_title_fragment_container); if (mTitleFragment == null) { mTitleFragment = CalendarTitleFragment.newInstance(); ft.replace(R.id.calendar_title_fragment_container, mTitleFragment); } if (!ft.isEmpty()) { ft.commit(); } LoaderManager lm = getLoaderManager(); lm.initLoader(LOADER_CALENDAR_ITEM, null, this); lm.initLoader(LOADER_SUBSCRIBED_CALENDAR, null, this); lm.initLoader(LOADER_SUBSCRIPTION, null, this); // set this to true, so the menu is cleared automatically when leaving the fragment, otherwise the star icon will stay visible setHasOptionsMenu(true); return returnView; }