List of usage examples for android.text.format Time toMillis
public long toMillis(boolean ignoreDst)
From source file:com.cloudkick.monitoring.CheckState.java
public CheckState(JSONObject state) throws JSONException { // Grab the "whence" if available if (state.has("whence")) { whenceWireFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); whenceWireFormat.setTimeZone(TimeZone.getTimeZone("GMT")); String whenceString = state.getString("whence"); try {/* w w w . j av a 2s .c om*/ long whenceMillis = whenceWireFormat.parse(whenceString).getTime(); Time now = new Time(); now.setToNow(); long diffMillis = ((now.toMillis(true)) - whenceMillis); if (whenceMillis == 0) { whence = "never"; } else if (diffMillis < 3600 * 1000) { whence = String.format("%d m", diffMillis / (1000 * 60)); } else if (diffMillis < (24 * 3600 * 1000)) { long mins = (diffMillis / (1000 * 60)) % 60; long hours = (diffMillis / (1000 * 3600)); whence = String.format("%d h, %d m", hours, mins); } else if (diffMillis < (7 * 24 * 3600 * 1000)) { long hours = (diffMillis / (1000 * 60 * 60)) % 24; long days = (diffMillis / (1000 * 60 * 60 * 24)); whence = String.format("%d d, %d h", days, hours); } else { long days = (diffMillis / (1000 * 60 * 60 * 24)) % 7; long weeks = (diffMillis / (1000 * 60 * 60 * 24 * 7)); whence = String.format("%d w, %d d", weeks, days); } } catch (ParseException e) { whence = null; } } else { whence = null; } // Grab the "service_state" if available if (state.has("service_state")) { serviceState = state.getString("service_state"); } else { serviceState = "UNKNOWN"; } // Depending on the serviceState set the status and color if (serviceState.equals("OK")) { status = state.getString("status"); stateColor = 0xFF088A08; stateSymbol = "\u2714"; priority = 4; } else if (serviceState.equals("ERROR")) { status = state.getString("status"); stateColor = 0xFFE34648; stateSymbol = "\u2718"; priority = 0; } else if (serviceState.equals("WARNING")) { status = state.getString("status"); stateColor = 0xFFDF7401; stateSymbol = "!"; priority = 1; } else if (serviceState.equals("NO-AGENT")) { status = "Agent Not Connected"; stateColor = 0xFF6E6E6E; stateSymbol = "?"; priority = 2; } else if (serviceState.equals("UNKNOWN")) { status = "No Data Available"; stateColor = 0xFF6E6E6E; stateSymbol = "?"; priority = 3; } else { Log.e("Check", "Unknown Service State: " + serviceState); status = state.getString("status"); stateColor = 0xFF6E6E6E; stateSymbol = "?"; priority = 3; } }
From source file:net.networksaremadeofstring.rhybudd.ZenossAPI.java
public static boolean shouldRefresh(Context mContext) { Time now = new Time(); now.setToNow();//from w ww.j a va 2 s .c o m if ((now.toMillis(true) - PreferenceManager.getDefaultSharedPreferences(mContext).getLong("lastCheck", now.toMillis(true))) > 900000) { return true; } else { return false; } }
From source file:com.dgsd.android.ShiftTracker.Fragment.HoursAndIncomeSummaryFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { View v = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_hour_and_income_summary, null); mMonth = (TextView) v.findViewById(R.id.month); mThreeMonth = (TextView) v.findViewById(R.id.three_months); mSixMonth = (TextView) v.findViewById(R.id.six_months); mNineMonth = (TextView) v.findViewById(R.id.nine_months); mThisYear = (TextView) v.findViewById(R.id.year); AlertDialog.Builder b = new AlertDialog.Builder(getActivity()); b.setView(v);//from w ww .j a v a2 s . c o m Time time = new Time(); time.setJulianDay(mJulianDay); b.setTitle(DateFormat.getDateFormat(getActivity()).format(time.toMillis(true))); Dialog d = b.create(); d.setCanceledOnTouchOutside(true); return d; }
From source file:net.networksaremadeofstring.rhybudd.ZenossAPI.java
public static void updateLastChecked(Context mContext) { SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(mContext).edit(); Time now = new Time(); now.setToNow();/*from w w w . j a v a2s . c o m*/ Log.e("toMillis", Long.toString(now.toMillis(true))); editor.putLong("lastCheck", now.toMillis(true)); editor.commit(); }
From source file:pro.jariz.reisplanner.fragments.PlannerFragment.java
@Override public void Invoke(Object Result, Integer TaskType) { if (Result == null) { //Result has returned null, which means somethings wrong. //Show feedback to user in form of a Crouton, using NSTask.LastExceptionMessage Crouton.showText(this.getActivity(), "Unable to update station list: " + NSTask.LastExceptionMessage, CroutonStyles.errorStyle); return;//w w w .j av a 2 s.c o m } Object[] stationso = (Object[]) Result; NSStation[] stations = Arrays.copyOf(stationso, stationso.length, NSStation[].class); if (TaskType == NSTask.TYPE_STATIONS) { //update cache time & clear & insert into db Time now = new Time(); now.setToNow(); DB.setLastCacheTime("stations", new BigDecimal(now.toMillis(true)).intValue()); DB.clearStations(); DB.insertStations(stations); Crouton.showText(this.getActivity(), getResources().getString(R.string.updating_station_list_done), CroutonStyles.successStyle); } Render(stations, thisView, this.getActivity()); }
From source file:com.samsung.msf.youtubeplayer.client.util.FeedParser.java
public List<Entry> readJson(InputStream stream) { List<Entry> entries = new ArrayList<Entry>(); // NEW Youtube API V3.0 try {//from www . j ava 2 s .c o m // Convert this response into a readable string String jsonString = convertToString(stream); JSONObject json = new JSONObject(jsonString); JSONArray jsonArray = json.getJSONArray("items"); Log.d(TAG, "readJson jsonArray item count = " + jsonArray.length()); // Loop round our JSON list of videos creating Video objects to use within our app for (int i = 0; i < jsonArray.length(); i++) { long publishedOn = 0; JSONObject jsonObject = jsonArray.getJSONObject(i); // The title of the video String id; try { id = jsonObject.getJSONObject("id").getString("videoId"); } catch (JSONException e) { continue; } JSONObject snippet = jsonObject.getJSONObject("snippet"); String title = snippet.getString("title"); String uploaded = snippet.getString("publishedAt"); Log.d(TAG, "id = " + id + ", title = " + title + "uploaded = " + uploaded); Time t = new Time(); t.parse3339(uploaded); publishedOn = t.toMillis(false); // The url link back to YouTube, this checks if it has a mobile url // if it doesnt it gets the standard url String url = ""; JSONObject thumnail = snippet.getJSONObject("thumbnails"); JSONObject defaultThumnail = thumnail.getJSONObject("default"); JSONObject highThumnail = thumnail.getJSONObject("high"); String thumbUrl; try { thumbUrl = highThumnail.getString("url"); } catch (JSONException ignore) { thumbUrl = defaultThumnail.getString("url"); } Log.d(TAG, "thumbUrl = " + thumbUrl); entries.add(new Entry(id, title, url, publishedOn, thumbUrl, 0)); // installed as default false; } } catch (IOException e) { Log.e(TAG, "Feck", e); } catch (JSONException e) { Log.e(TAG, "Feck", e); } return entries; }
From source file:be.ac.ucl.lfsab1509.llncampus.services.AlarmService.java
/** * Send an alert to the user for the event e. * /*from w w w . j a v a 2 s . com*/ * @param e * Event to notify to the user. */ private void sendAlert(Event e) { final NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); Time currentTime = new Time(); currentTime.setToNow(); long nbMin = e.getBeginTime().toMillis(false) / 60L / 1000L - currentTime.toMillis(false) / 60L / 1000L; final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(android.R.drawable.ic_dialog_alert) .setContentTitle(e.getDetail(Event.COURSE) + " " + getString(R.string.begins_in) + " " + nbMin + " " + getString(R.string.minutes)) .setContentText(e.getDetail(Event.ROOM) + " - " + e.getDetail(Event.TITLE)).setAutoCancel(true); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); String ringtone = preferences.getString(SettingsActivity.NOTIFY_RINGTONE, null); if (ringtone == null) { notificationBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } else { notificationBuilder.setSound(Uri.parse(ringtone)); } notificationManager.notify(1, notificationBuilder.build()); }
From source file:com.android.calendar.event.CreateEventDialogFragment.java
public void setDay(Time day) { mDateString = day.format(EVENT_DATE_FORMAT); mDateInMillis = day.toMillis(true); }
From source file:com.dgsd.android.ShiftTracker.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.settings) { startActivity(new Intent(this, SettingsActivity.class)); } else if (item.getItemId() == R.id.go_to) { if (mGoToFragment != null && mGoToFragment.isResumed()) { //We're showing already! return true; }/*w w w . j ava2s.c om*/ final int centerJd = mWeekPagerAdapter.getJulianDayForPosition(mWeekPagerAdapter.getCenterPosition()); final int count = mWeekPagerAdapter.getCount() * 7; final Time time = new Time(); time.setJulianDay(centerJd - (count / 2)); final long min = time.toMillis(true); time.setJulianDay(centerJd + (count / 2)); final long max = time.toMillis(true); mGoToFragment = DatePickerFragment.newInstance("Go to date..", min, max, -1); mGoToFragment.setOnDateSelectedListener(this); mGoToFragment.show(getSupportFragmentManager(), null); } else if (item.getItemId() == R.id.get_full_version) { Uri uri = Uri.parse("market://details?id=com.dgsd.android.ShiftTracker"); startActivity(new Intent(Intent.ACTION_VIEW, uri)); } else if (item.getItemId() == R.id.stats) { final int selectedItem = getSupportActionBar().getSelectedNavigationIndex(); if (StApp.isFreeApp(this)) { if (mLinkToPaidAppFragment == null || !mLinkToPaidAppFragment.isResumed()) { mLinkToPaidAppFragment = LinkToPaidAppFragment .newInstance(getString(R.string.summary_unavailable_message)); mLinkToPaidAppFragment.show(getSupportFragmentManager(), null); } } else { if (mHoursAndIncomeFragment == null || !mHoursAndIncomeFragment.isResumed()) { final int jd; if (selectedItem == NAV_INDEX_MONTH) jd = mMonthPagerAdapter.getSelectedJulianDay(mPager.getCurrentItem()); else if (selectedItem == NAV_INDEX_WEEK) jd = mWeekPagerAdapter.getJulianDayForPosition(mPager.getCurrentItem()) + 6; else jd = TimeUtils.getCurrentJulianDay(); mHoursAndIncomeFragment = HoursAndIncomeSummaryFragment.newInstance(jd); mHoursAndIncomeFragment.show(getSupportFragmentManager(), null); } } } return super.onOptionsItemSelected(item); }
From source file:com.granita.tasks.groupings.BaseTaskViewDescriptor.java
protected void setDueDate(TextView view, ImageView dueIcon, Time dueDate, boolean isClosed) { if (view != null && dueDate != null) { Time now = mNow; if (now == null) { now = mNow = new Time(); }/*from w ww. ja v a 2 s .c om*/ if (!now.timezone.equals(TimeZone.getDefault().getID())) { now.clear(TimeZone.getDefault().getID()); } if (Math.abs(now.toMillis(false) - System.currentTimeMillis()) > 5000) { now.setToNow(); now.normalize(true); } dueDate.normalize(true); view.setText(new DateFormatter(view.getContext()).format(dueDate, now, DateFormatContext.LIST_VIEW)); if (dueIcon != null) { dueIcon.setVisibility(View.VISIBLE); } // highlight overdue dates & times, handle allDay tasks separately if ((!dueDate.allDay && dueDate.before(now) || dueDate.allDay && (dueDate.year < now.year || dueDate.yearDay <= now.yearDay && dueDate.year == now.year)) && !isClosed) { view.setTextAppearance(view.getContext(), R.style.task_list_overdue_text); } else { view.setTextAppearance(view.getContext(), R.style.task_list_due_text); } } else if (view != null) { view.setText(""); if (dueIcon != null) { dueIcon.setVisibility(View.GONE); } } }