List of usage examples for android.text.format DateFormat getTimeFormat
public static java.text.DateFormat getTimeFormat(Context context)
From source file:com.heightechllc.breakify.AlarmNotifications.java
/** * Shows an ongoing notification for an upcoming alarm * @param context The context to create the notification from * @param ringTime The time that the alarm will ring, based on `SystemClock.elapsedRealtime()` * @param workState The work state of the timer *///from ww w . j a v a2 s . c o m public static void showUpcomingNotification(Context context, long ringTime, int workState) { // Create the notification NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(R.drawable.ic_notification).setOngoing(true) .setPriority(NotificationCompat.PRIORITY_LOW); // Get the appropriate title based on the current work state int titleId = workState == MainActivity.WORK_STATE_WORKING ? R.string.notif_upcoming_title_working : R.string.notif_upcoming_title_breaking; builder.setContentTitle(context.getString(titleId)); // Get formatted time for when the alarm will ring. We need to convert `ringTime`, which // is based on `SystemClock.elapsedRealtime()`, to a regular Unix / epoch time long timeFromNow = ringTime - SystemClock.elapsedRealtime(); long ringUnixTime = System.currentTimeMillis() + timeFromNow; // Construct the text, e.g., "Until 11:30" String contentText = context.getString(R.string.notif_upcoming_content_text) + " "; contentText += DateFormat.getTimeFormat(context).format(new Date(ringUnixTime)); builder.setContentText(contentText); // Set up the action for the when the notification is clicked - to open MainActivity Intent mainIntent = new Intent(context, MainActivity.class); mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pi = PendingIntent.getActivity(context, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pi); // Show the notification NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(notificationID, builder.build()); }
From source file:cz.maresmar.sfm.utils.MenuUtils.java
/** * Translate date to user readable String using current locale * * @param context Valid context used to get locale * @param date Date to be translated/*from ww w. j a v a 2 s . com*/ * @return String with date with time */ @NonNull public static String getDateTimeStr(Context context, long date) { return getDateStr(context, date) + " " + DateFormat.getTimeFormat(context).format(date); }
From source file:com.abhijitvalluri.android.fitnotifications.TimePickerFragment.java
@Override @NonNull/* w w w . java2 s.c om*/ public Dialog onCreateDialog(Bundle savedInstanceState) { int hour = getArguments().getInt(ARG_HOUR); int minute = getArguments().getInt(ARG_MINUTE); mOtherHour = getArguments().getInt(ARG_OTHER_HOUR); mOtherMinute = getArguments().getInt(ARG_OTHER_MINUTE); mOtherTimeFormatted = DateFormat.getTimeFormat(getActivity()) .format(Func.convertHourMinute2Date(mOtherHour, mOtherMinute)); mRequestCode = getArguments().getInt(ARG_REQUEST_CODE); View v = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_time, null); mTimePicker = (TimePicker) v.findViewById(R.id.dialog_time_time_picker); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { mTimePicker.setHour(hour); mTimePicker.setMinute(minute); } else { //noinspection deprecation mTimePicker.setCurrentHour(hour); //noinspection deprecation mTimePicker.setCurrentMinute(minute); } mTimePicker.setIs24HourView(DateFormat.is24HourFormat(getActivity())); @StringRes int titleStringId = mRequestCode == AppSettingsActivity.START_TIME_REQUEST ? R.string.start_time_heading : R.string.stop_time_heading; final AlertDialog dialog = new AlertDialog.Builder(getActivity()).setView(v).setTitle(titleStringId) .setNegativeButton(android.R.string.cancel, null) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int hour, minute; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { hour = mTimePicker.getHour(); minute = mTimePicker.getMinute(); } else { //noinspection deprecation hour = mTimePicker.getCurrentHour(); //noinspection deprecation minute = mTimePicker.getCurrentMinute(); } sendResult(mRequestCode, hour, minute); } }).create(); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { int hour, minute; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { hour = mTimePicker.getHour(); minute = mTimePicker.getMinute(); } else { //noinspection deprecation hour = mTimePicker.getCurrentHour(); //noinspection deprecation minute = mTimePicker.getCurrentMinute(); } Button positiveButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE); sanityCheckTimeChoice(positiveButton, hour, minute); } }); mTimePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Override public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE); sanityCheckTimeChoice(positiveButton, hourOfDay, minute); } }); return dialog; }
From source file:com.joefernandez.irrduino.android.remote.ViewReportActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.report);//from w w w . j av a 2s . c o m reportText = (TextView) findViewById(id.report_text); reportText.setMovementMethod(new ScrollingMovementMethod()); settingsChanged = true; // get settings settings = PreferenceManager.getDefaultSharedPreferences(this); // set time zone settings and date formatter priorDate.setTimeZone(TimeZone.getDefault()); nextDate.setTimeZone(TimeZone.getDefault()); dateFormat = DateFormat.getDateFormat(this); // set localized date-only format timeFormat = DateFormat.getTimeFormat(this); // set localized time-only format //send the report request if (settings.getString(Settings.SERVER_HOST_NAME, Settings.DEFAULT_SERVER_HOST) .compareTo(Settings.DEFAULT_SERVER_HOST) == 0) { // default setting, warn user reportText.setText("Report server is not set,\n specify a server in Settings."); } else { reportText.setText("Requesting report..."); new IrrduinoServerRequestTask().execute(getReportServerUrl() + REPORT_JSON_FORMAT); } }
From source file:com.woodblockwithoutco.quickcontroldock.prefs.ui.fragments.GeneralPrefsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.misc_prefs); mPackPreference = (ListPreference) findPreference(Keys.ExternalResources.EXTERNAL_RESOURCE_PACKAGE); mPrefsKeysDialog = new PrefsKeysDialog(); mXmlPrefsDialog = new PrefsXmlDialog(); findPreference("force_crash").setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override//w w w .j a v a 2 s . co m public boolean onPreferenceClick(Preference preference) { String date = DateFormat.getTimeFormat(getActivity()).format(Calendar.getInstance().getTime()); throw new RuntimeException("App has been crashed manually[" + date + "]"); } }); findPreference("list_prefs").setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { mPrefsKeysDialog.show(getFragmentManager(), TAG); return true; } }); findPreference("list_prefs_xml").setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { mXmlPrefsDialog.show(getFragmentManager(), TAG_XML); return true; } }); findPreference("save_prefs_xml").setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { saveXmlToFile(); return true; } }); findPreference("post_notification_dismissable") .setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { NotificationCompat.Builder builder = new NotificationCompat.Builder( getActivity().getApplicationContext()); int id = 0; final int MAX_NOTIFICATIONS = 50; Random r = new Random(); id = 10000 + r.nextInt(MAX_NOTIFICATIONS); builder.setContentTitle("TEST"); builder.setOngoing(false); builder.setContentText("TEST TEXT " + id); builder.setDefaults(Notification.DEFAULT_SOUND); builder.setSmallIcon(R.drawable.ic_notification); NotificationManager mgr = (NotificationManager) getActivity() .getSystemService(Context.NOTIFICATION_SERVICE); mgr.notify(id, builder.build()); return true; } }); findPreference("post_notification_dismissable_delay") .setOnPreferenceClickListener(new OnPreferenceClickListener() { private Handler mHandler = new Handler(); @Override public boolean onPreferenceClick(Preference preference) { mHandler.postDelayed(new Runnable() { @Override public void run() { NotificationCompat.Builder builder = new NotificationCompat.Builder( getActivity().getApplicationContext()); int id = 0; final int MAX_NOTIFICATIONS = 50; Random r = new Random(); id = 10000 + r.nextInt(MAX_NOTIFICATIONS); builder.setContentTitle("TEST"); builder.setOngoing(false); builder.setDefaults(Notification.DEFAULT_SOUND); builder.setContentText("TEST TEXT " + id); builder.setSmallIcon(R.drawable.ic_notification); NotificationManager mgr = (NotificationManager) getActivity() .getSystemService(Context.NOTIFICATION_SERVICE); mgr.notify(id, builder.build()); } }, 5000); return true; } }); if (!ConstantHolder.getIsDebug()) { Preference debugCat = findPreference("debug_cat"); getPreferenceScreen().removePreference(debugCat); } }
From source file:de.t_animal.journeyapp.InformationFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { fragmentRootView = inflater.inflate(R.layout.fragment_information, container, false); JourneyProperties prop = JourneyProperties.getInstance(getActivity()); String journeyDateString = DateFormat.getDateFormat(getActivity()).format(prop.getJourneyDate()) + " " + DateFormat.getTimeFormat(getActivity()).format(prop.getJourneyDate()); ((TextView) fragmentRootView.findViewById(R.id.info_journeyName_value)).setText(prop.getJourneyName()); ((TextView) fragmentRootView.findViewById(R.id.info_journeyDate_value)).setText(journeyDateString); ((TextView) fragmentRootView.findViewById(R.id.info_journeyLocation_value)) .setText(prop.getJourneyStartLocation()); ((TextView) fragmentRootView.findViewById(R.id.info_journeyFurtherInformation_value)) .setText(prop.getJourneyFurtherInformation()); locationServiceButton = (Switch) fragmentRootView.findViewById(R.id.locationServiceButton); info_mapFollowingUserButton = (Switch) fragmentRootView.findViewById(R.id.info_mapFollowingUserButton); locationServiceButton.setOnClickListener(this); info_mapFollowingUserButton.setOnClickListener(this); ((Button) fragmentRootView.findViewById(R.id.info_resetJourneyButton)).setOnClickListener(this); ((TextView) fragmentRootView.findViewById(R.id.info_flattr)).setOnClickListener(this); ((TextView) fragmentRootView.findViewById(R.id.info_acknowledgement)).setOnClickListener(this); ((TextView) fragmentRootView.findViewById(R.id.info_license)).setOnClickListener(this); return fragmentRootView; }
From source file:com.yeldi.yeldibazaar.ManageRepo.java
@Override protected void onCreate(Bundle savedInstanceState) { if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("lightTheme", false)) setTheme(R.style.AppThemeLight); super.onCreate(savedInstanceState); setContentView(R.layout.repolist);//from w w w . j av a2 s.c o m SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); TextView tv_lastCheck = (TextView) findViewById(R.id.lastUpdateCheck); long lastUpdate = prefs.getLong("lastUpdateCheck", 0); String s_lastUpdateCheck = ""; if (lastUpdate == 0) { s_lastUpdateCheck = getString(R.string.never); } else { Date d = new Date(lastUpdate); s_lastUpdateCheck = DateFormat.getDateFormat(this).format(d) + " " + DateFormat.getTimeFormat(this).format(d); } tv_lastCheck.setText(getString(R.string.last_update_check, s_lastUpdateCheck)); reposToRemove = new ArrayList<String>(); reposToDisable = new ArrayList<String>(); }
From source file:com.androzic.GPSInfo.java
private void updateGPSInfo() { switch (application.gpsStatus) { case LocationService.GPS_OK: satsValue.setText(String.valueOf(application.gpsFSats) + "/" + String.valueOf(application.gpsTSats)); break;/*from w w w . ja va 2 s. com*/ case LocationService.GPS_OFF: satsValue.setText(R.string.sat_stop); break; case LocationService.GPS_SEARCHING: satsValue.setText(String.valueOf(application.gpsFSats) + "/" + String.valueOf(application.gpsTSats)); satsValue.startAnimation(shake); break; } float hdop = application.getHDOP(); if (!Float.isNaN(hdop)) hdopValue.setText(String.format("%.1f", hdop)); float vdop = application.getVDOP(); if (!Float.isNaN(vdop)) vdopValue.setText(String.format("%.1f", vdop)); if (application.lastKnownLocation != null) { Date date = new Date(application.lastKnownLocation.getTime()); lastfixValue.setText(DateFormat.getDateFormat(application).format(date) + " " + DateFormat.getTimeFormat(application).format(date)); accuracyValue.setText(application.lastKnownLocation.hasAccuracy() ? StringFormatter.distanceH(application.lastKnownLocation.getAccuracy(), "%.1f", 1000) : "N/A"); } }
From source file:in.andres.kandroid.ui.ProjectOverviewFragment.java
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); KanboardProject project = ((MainActivity) getActivity()).getProject(); if (project != null) { assert getView() != null : "ProjectOverviewFragment: getView() returned null"; TextView projectDescription = (TextView) getView().findViewById(R.id.project_description); TextView projectNBActiveTasks = (TextView) getView().findViewById(R.id.project_active_tasks); TextView projectNBInactiveTasks = (TextView) getView().findViewById(R.id.project_inactive_tasks); TextView projectNBOverdueTasks = (TextView) getView().findViewById(R.id.project_overdue_tasks); TextView projectNBTotalTasks = (TextView) getView().findViewById(R.id.project_total_tasks); TextView projectModifyDate = (TextView) getView().findViewById(R.id.project_modify_date); TextView projectMembers = (TextView) getView().findViewById(R.id.project_members); TextView projectColumns = (TextView) getView().findViewById(R.id.project_columns); TextView projectSwimlanes = (TextView) getView().findViewById(R.id.project_swimlanes); if (!project.getDescription().contentEquals("")) { projectDescription//ww w. java 2s . c om .setText(Utils.fromHtml(mRenderer.render(mParser.parse(project.getDescription())))); } else { getView().findViewById(R.id.card_description).setVisibility(View.GONE); } projectMembers.setText(Utils.fromHtml(TextUtils.join(" <big><b>|</b></big> ", Collections.list(project.getProjectUsers().elements())))); projectColumns.setText(Utils.fromHtml(TextUtils.join(" <big><b>|</b></big> ", project.getColumns()))); projectSwimlanes .setText(Utils.fromHtml(TextUtils.join(" <big><b>|</b></big> ", project.getSwimlanes()))); projectNBActiveTasks .setText(getContext().getResources().getQuantityString(R.plurals.format_nb_active_tasks, project.getActiveTasks().size(), project.getActiveTasks().size())); projectNBInactiveTasks .setText(getContext().getResources().getQuantityString(R.plurals.format_nb_inactive_tasks, project.getInactiveTasks().size(), project.getInactiveTasks().size())); projectNBOverdueTasks .setText(getContext().getResources().getQuantityString(R.plurals.format_nb_overdue_tasks, project.getOverdueTasks().size(), project.getOverdueTasks().size())); projectNBTotalTasks .setText(getContext().getResources().getQuantityString(R.plurals.format_nb_total_tasks, project.getActiveTasks().size() + project.getInactiveTasks().size(), project.getActiveTasks().size() + project.getInactiveTasks().size())); projectModifyDate.setText(DateFormat.getLongDateFormat(getContext()).format(project.getLastModified()) + " " + DateFormat.getTimeFormat(getContext()).format(project.getLastModified())); } }
From source file:mx.udlap.is522.tedroid.activity.ScoresActivity.java
/** * Convierte un objeto Score en objeto TableRow. * // w ww .j a va2s. c o m * @param score el objeto Score a convertir. * @return un objeto TableRow. */ private TableRow toTableRow(Score score) { TableRow row = new TableRow(this); TextView pointsText = new TextView(this); pointsText.setText(String.valueOf(score.getPoints())); applySecondaryStyleTo(pointsText); pointsText.setLayoutParams(layoutParams); TextView levelText = new TextView(this); levelText.setText(String.valueOf(score.getLevel())); applySecondaryStyleTo(levelText); TextView linesText = new TextView(this); linesText.setText(String.valueOf(score.getLines())); applySecondaryStyleTo(linesText); TextView dateText = new TextView(this); String dateStr = getString(R.string.datetime_format, DateFormat.getDateFormat(getApplicationContext()).format(score.getObtainedAt()), DateFormat.getTimeFormat(getApplicationContext()).format(score.getObtainedAt())); dateText.setText(dateStr); applySecondaryStyleTo(dateText); row.addView(pointsText); row.addView(levelText); row.addView(linesText); row.addView(dateText); return row; }