List of usage examples for android.text.format Time set
public void set(int monthDay, int month, int year)
From source file:org.dmfs.tasks.notification.NotificationActionUtils.java
/** * Returns a string representation for the time, with a relative date and an absolute time *//*from w w w . j av a 2 s . com*/ public static String formatTime(Context context, Time time) { Time now = new Time(); now.setToNow(); String dateString; if (time.allDay) { Time allDayNow = new Time("UTC"); allDayNow.set(now.monthDay, now.month, now.year); dateString = DateUtils.getRelativeTimeSpanString(time.toMillis(false), allDayNow.toMillis(false), DateUtils.DAY_IN_MILLIS).toString(); } else { dateString = DateUtils .getRelativeTimeSpanString(time.toMillis(false), now.toMillis(false), DateUtils.DAY_IN_MILLIS) .toString(); } // return combined date and time String timeString = new DateFormatter(context).format(time, DateFormatContext.NOTIFICATION_VIEW_TIME); return new StringBuilder().append(dateString).append(", ").append(timeString).toString(); }
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//from w w w. j a va 2 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; }
From source file:com.cloverstudio.spika.MyProfileActivity.java
@Override protected Dialog onCreateDialog(int id) { switch (id) { case GET_IMAGE_DIALOG: mGetImageDialog = new Dialog(MyProfileActivity.this, R.style.TransparentDialogTheme); mGetImageDialog.getWindow().setGravity(Gravity.BOTTOM); mGetImageDialog.setContentView(R.layout.dialog_get_image); WindowManager.LayoutParams params = new WindowManager.LayoutParams(); Window window = mGetImageDialog.getWindow(); params.copyFrom(window.getAttributes()); params.width = WindowManager.LayoutParams.MATCH_PARENT; params.height = WindowManager.LayoutParams.WRAP_CONTENT; window.setAttributes(params);// w w w .ja va2s .c om final Button btnGallery = (Button) mGetImageDialog.findViewById(R.id.btnGallery); btnGallery.setTypeface(SpikaApp.getTfMyriadProBold(), Typeface.BOLD); btnGallery.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent galleryIntent = new Intent(MyProfileActivity.this, CameraCropActivity.class); galleryIntent.putExtra("type", "gallery"); galleryIntent.putExtra("profile", true); MyProfileActivity.this.startActivityForResult(galleryIntent, UPDATE_IMAGE_REQUEST_CODE); mGetImageDialog.dismiss(); } }); final Button btnCamera = (Button) mGetImageDialog.findViewById(R.id.btnCamera); btnCamera.setTypeface(SpikaApp.getTfMyriadProBold(), Typeface.BOLD); btnCamera.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent cameraIntent = new Intent(MyProfileActivity.this, CameraCropActivity.class); cameraIntent.putExtra("type", "camera"); cameraIntent.putExtra("profile", true); MyProfileActivity.this.startActivityForResult(cameraIntent, UPDATE_IMAGE_REQUEST_CODE); mGetImageDialog.dismiss(); } }); final Button btnRemovePhoto = (Button) mGetImageDialog.findViewById(R.id.btnRemovePhoto); btnRemovePhoto.setTypeface(SpikaApp.getTfMyriadProBold(), Typeface.BOLD); btnRemovePhoto.setOnClickListener(new OnClickListener() { public void onClick(View v) { mNewAvatarId = ""; gProfileImage = null; Utils.displayImage(mNewAvatarId, mIvProfileImage, mPbLoading, ImageLoader.LARGE, R.drawable.user_stub_large, false); mGetImageDialog.dismiss(); } }); return mGetImageDialog; case GET_BIRTHDAY_DIALOG: int intMaxYear = Calendar.getInstance().get(Calendar.YEAR); int intMaxMonth = Calendar.getInstance().get(Calendar.MONTH); int intMaxDay = Calendar.getInstance().get(Calendar.DAY_OF_MONTH); mGetBirthdayDialog = new DatePickerDialogWithRange(this, new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Time chosenDate = new Time(); chosenDate.set(dayOfMonth, monthOfYear, year); mNewBirthday = chosenDate.toMillis(true) / 1000; CharSequence stringDate = DateFormat.format(getString(R.string.hookup_date_format), chosenDate.toMillis(true)); mEtUserBirthday.setText(stringDate.toString()); } }, intMaxYear, intMaxMonth, intMaxDay); mGetBirthdayDialog.setMessage(getString(R.string.when_is_your_birthday)); return mGetBirthdayDialog; default: return null; } }
From source file:info.hl.mediam.MyProfileActivity.java
@Override protected Dialog onCreateDialog(int id) { switch (id) { case GET_IMAGE_DIALOG: mGetImageDialog = new Dialog(MyProfileActivity.this, R.style.TransparentDialogTheme); mGetImageDialog.getWindow().setGravity(Gravity.BOTTOM); mGetImageDialog.setContentView(R.layout.dialog_get_image); WindowManager.LayoutParams params = new WindowManager.LayoutParams(); Window window = mGetImageDialog.getWindow(); params.copyFrom(window.getAttributes()); params.width = WindowManager.LayoutParams.MATCH_PARENT; params.height = WindowManager.LayoutParams.WRAP_CONTENT; window.setAttributes(params);/*from w ww.j av a2 s . co m*/ final Button btnGallery = (Button) mGetImageDialog.findViewById(R.id.btnGallery); btnGallery.setTypeface(MediamApp.getTfMyriadProBold(), Typeface.BOLD); btnGallery.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent galleryIntent = new Intent(MyProfileActivity.this, CameraCropActivity.class); galleryIntent.putExtra("type", "gallery"); galleryIntent.putExtra("profile", true); MyProfileActivity.this.startActivityForResult(galleryIntent, UPDATE_IMAGE_REQUEST_CODE); mGetImageDialog.dismiss(); } }); final Button btnCamera = (Button) mGetImageDialog.findViewById(R.id.btnCamera); btnCamera.setTypeface(MediamApp.getTfMyriadProBold(), Typeface.BOLD); btnCamera.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent cameraIntent = new Intent(MyProfileActivity.this, CameraCropActivity.class); cameraIntent.putExtra("type", "camera"); cameraIntent.putExtra("profile", true); MyProfileActivity.this.startActivityForResult(cameraIntent, UPDATE_IMAGE_REQUEST_CODE); mGetImageDialog.dismiss(); } }); final Button btnRemovePhoto = (Button) mGetImageDialog.findViewById(R.id.btnRemovePhoto); btnRemovePhoto.setTypeface(MediamApp.getTfMyriadProBold(), Typeface.BOLD); btnRemovePhoto.setOnClickListener(new OnClickListener() { public void onClick(View v) { mNewAvatarId = ""; gProfileImage = null; Utils.displayImage(mNewAvatarId, mIvProfileImage, mPbLoading, ImageLoader.LARGE, R.drawable.user_stub_large, false); mGetImageDialog.dismiss(); } }); return mGetImageDialog; case GET_BIRTHDAY_DIALOG: int intMaxYear = Calendar.getInstance().get(Calendar.YEAR); int intMaxMonth = Calendar.getInstance().get(Calendar.MONTH); int intMaxDay = Calendar.getInstance().get(Calendar.DAY_OF_MONTH); mGetBirthdayDialog = new DatePickerDialogWithRange(this, new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Time chosenDate = new Time(); chosenDate.set(dayOfMonth, monthOfYear, year); mNewBirthday = chosenDate.toMillis(true) / 1000; CharSequence stringDate = DateFormat.format(getString(R.string.hookup_date_format), chosenDate.toMillis(true)); mEtUserBirthday.setText(stringDate.toString()); } }, intMaxYear, intMaxMonth, intMaxDay); mGetBirthdayDialog.setMessage(getString(R.string.when_is_your_birthday)); return mGetBirthdayDialog; default: return null; } }
From source file:es.usc.citius.servando.calendula.fragments.ScheduleImportFragment.java
@Override public void onRecurrenceSet(String s) { EventRecurrence event = new EventRecurrence(); LocalDate now = LocalDate.now(); Time startDate = new Time(Time.getCurrentTimezone()); startDate.set(now.getDayOfMonth(), now.getMonthOfYear(), now.getYear()); startDate.normalize(true);// w w w.ja v a 2 s.co m event.parse(s); event.setStartDate(startDate); Log.d(TAG, "OnRecurrenceSet: " + event.startDate); schedule.setRepetition(new RepetitionRule("RRULE:" + s)); setScheduleStart(schedule.start()); LocalDate end = schedule.end(); Log.d(TAG, "ICAL: " + schedule.rule().toIcal()); setScheduleEnd(end); Log.d(TAG, "ICAL: " + schedule.rule().toIcal()); ruleText.setText(getCurrentSchedule()); }