List of usage examples for android.text.format DateUtils formatDateTime
public static String formatDateTime(Context context, long millis, int flags)
From source file:org.dronix.android.unisannio.fragment.TabThree.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.tabone, container, false); TextView title = (TextView) view.findViewById(R.id.title); title.setText(getString(R.string.avvisi_giurisprudenza)); mPullRefreshListView = (PullToRefreshListView) view.findViewById(R.id.pull_refresh_list); // Set a listener to be invoked when the list should be refreshed. mPullRefreshListView.setOnRefreshListener(new OnRefreshListener<ListView>() { @Override/*w ww . j a v a2 s . c o m*/ public void onRefresh(PullToRefreshBase<ListView> refreshView) { mPullRefreshListView.setLastUpdatedLabel(DateUtils.formatDateTime(getActivity(), System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL)); new NewsRetriever().execute(); } }); ListView actualListView = mPullRefreshListView.getRefreshableView(); news = new ArrayList<NewsIng>(); news.add(new NewsIng(getString(R.string.pull), "", null, null, "")); mAdapter = new NewsIngAdapter(getActivity(), news); actualListView.setAdapter(mAdapter); actualListView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent i = new Intent(getActivity(), NewsDetailActivity.class); i.putExtra("newsing", news.get(--position)); startActivity(i); } }); return view; }
From source file:com.dgsd.android.ShiftTracker.Adapter.WeekAdapter.java
@Override protected void bindHeaderView(View view, Context context, Cursor cursor) { HeaderViewHolder holder = (HeaderViewHolder) view.getTag(); final int jd = cursor.getInt(cursor.getColumnIndex(DbField.JULIAN_DAY.name)); String title = mJdToTitleArray.get(jd, null); if (TextUtils.isEmpty(title)) { mTime.setJulianDay(jd);//from w w w . j a v a 2 s . co m title = DateUtils.formatDateTime(getContext(), mTime.toMillis(true), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_NO_YEAR); mJdToTitleArray.put(jd, title); } //Highlight the current day with a bold title if (jd == mCurrentJulianDay) holder.title.setTypeface(null, Typeface.BOLD); else holder.title.setTypeface(null, Typeface.NORMAL); holder.title.setText(title); }
From source file:com.tum.atse.Utils.java
/** * Returns a user-friendly localized date. * * @param context/*from w w w . j a v a 2 s.co m*/ * @param dateTime * @return */ public static String getFormattedDate(Context context, DateTime dateTime) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(dateTime.getValue()); return DateUtils.formatDateTime(context, cal.getTimeInMillis(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH); }
From source file:com.midooo.ui.activitys.ImageListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { layoutView = inflater.inflate(R.layout.ac_image_list, null); imageUrls = Constants.IMAGES;//from w ww. j a v a2s . com options = Constants.options; //listView = (ListView) layoutView.findViewById(android.R.id.list); mPullRefreshListView = (PullToRefreshListView) layoutView.findViewById(R.id.pull_refresh_list); // Set a listener to be invoked when the list should be refreshed. mPullRefreshListView.setOnRefreshListener(new OnRefreshListener<ListView>() { FaXingQuanMainActivity fca = (FaXingQuanMainActivity) getActivity(); @Override public void onRefresh(PullToRefreshBase<ListView> refreshView) { String label = DateUtils.formatDateTime(fca.getApplicationContext(), System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL); // Update the LastUpdatedLabel refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label); // Do work to refresh the list here. new GetDataTask().execute(); } }); // Add an end-of-list listener mPullRefreshListView.setOnLastItemVisibleListener(new OnLastItemVisibleListener() { @Override public void onLastItemVisible() { Toast.makeText((FaXingQuanMainActivity) getActivity(), "End of List!", Toast.LENGTH_SHORT).show(); } }); ListView actualListView = mPullRefreshListView.getRefreshableView(); // Need to use the Actual ListView when registering for Context Menu registerForContextMenu(actualListView); /** * Add Sound Event Listener */ SoundPullEventListener<ListView> soundListener = new SoundPullEventListener<ListView>( (FaXingQuanMainActivity) getActivity()); soundListener.addSoundEvent(State.PULL_TO_REFRESH, R.raw.pull_event); soundListener.addSoundEvent(State.RESET, R.raw.reset_sound); soundListener.addSoundEvent(State.REFRESHING, R.raw.refreshing_sound); mPullRefreshListView.setOnPullEventListener(soundListener); //listView.addHeaderView(new ImagePagerFragment().getView(), null, false); mAdapter = new ItemAdapter(inflater); actualListView.setAdapter(mAdapter); actualListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //startImagePagerActivity(position); Log.w("---doop---", "startImagePagerActivity(position)"); } }); /* listView.setAdapter(new ItemAdapter(inflater)); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //startImagePagerActivity(position); Log.w("---doop---", "startImagePagerActivity(position)"); } }); */ //setListViewHeightBasedOnChildren(listView); return layoutView; }
From source file:com.adam.aslfms.util.Util.java
/** * Converts time from a long to a string in a format set by the user in the * phone's settings./*from ww w . j av a 2s . co m*/ * * @param ctx context to get access to the conversion methods * @param secs time since 1970, UTC, in seconds * @return the time since 1970, UTC, as a string (e.g. 2009-10-23 12:25) */ public static String timeFromUTCSecs(Context ctx, long secs) { return DateUtils.formatDateTime(ctx, secs * 1000, DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NUMERIC_DATE); }
From source file:org.onebusaway.android.ui.ArrivalsListAdapterStyleA.java
@Override protected void initView(View view, ArrivalInfo stopInfo) { final Context context = getContext(); final ObaArrivalInfo arrivalInfo = stopInfo.getInfo(); TextView route = (TextView) view.findViewById(R.id.route); TextView destination = (TextView) view.findViewById(R.id.destination); TextView time = (TextView) view.findViewById(R.id.time); TextView status = (TextView) view.findViewById(R.id.status); TextView etaView = (TextView) view.findViewById(R.id.eta); TextView minView = (TextView) view.findViewById(R.id.eta_min); ViewGroup realtimeView = (ViewGroup) view.findViewById(R.id.eta_realtime_indicator); ImageView moreView = (ImageView) view.findViewById(R.id.more_horizontal); moreView.setColorFilter(context.getResources().getColor(R.color.switch_thumb_normal_material_dark)); ImageView starView = (ImageView) view.findViewById(R.id.route_favorite); starView.setColorFilter(context.getResources().getColor(R.color.navdrawer_icon_tint)); starView.setImageResource(/*from w w w . j a v a2 s . c o m*/ stopInfo.isRouteAndHeadsignFavorite() ? R.drawable.focus_star_on : R.drawable.focus_star_off); route.setText(arrivalInfo.getShortName()); destination.setText(MyTextUtils.toTitleCase(arrivalInfo.getHeadsign())); status.setText(stopInfo.getStatusText()); long eta = stopInfo.getEta(); if (eta == 0) { etaView.setText(R.string.stop_info_eta_now); minView.setVisibility(View.GONE); } else { etaView.setText(String.valueOf(eta)); minView.setVisibility(View.VISIBLE); } status.setBackgroundResource(R.drawable.round_corners_style_b_status); GradientDrawable d = (GradientDrawable) status.getBackground(); Integer colorCode = stopInfo.getColor(); int color = context.getResources().getColor(colorCode); if (stopInfo.getPredicted()) { // Show real-time indicator UIUtils.setRealtimeIndicatorColorByResourceCode(realtimeView, colorCode, android.R.color.transparent); realtimeView.setVisibility(View.VISIBLE); } else { realtimeView.setVisibility(View.INVISIBLE); } etaView.setTextColor(color); minView.setTextColor(color); d.setColor(color); // Set padding on status view int pSides = UIUtils.dpToPixels(context, 5); int pTopBottom = UIUtils.dpToPixels(context, 2); status.setPadding(pSides, pTopBottom, pSides, pTopBottom); time.setText(DateUtils.formatDateTime(context, stopInfo.getDisplayTime(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT)); ContentValues values = null; if (mTripsForStop != null) { values = mTripsForStop.getValues(arrivalInfo.getTripId()); } if (values != null) { String reminderName = values.getAsString(ObaContract.Trips.NAME); TextView reminder = (TextView) view.findViewById(R.id.reminder); if (reminderName.length() == 0) { reminderName = context.getString(R.string.trip_info_noname); } reminder.setText(reminderName); Drawable d2 = reminder.getCompoundDrawables()[0]; d2 = DrawableCompat.wrap(d2); DrawableCompat.setTint(d2.mutate(), view.getResources().getColor(R.color.button_material_dark)); reminder.setCompoundDrawables(d2, null, null, null); reminder.setVisibility(View.VISIBLE); } else { // Explicitly set this to invisible because we might be reusing // this view. View reminder = view.findViewById(R.id.reminder); reminder.setVisibility(View.GONE); } }
From source file:net.peterkuterna.android.apps.devoxxfrsched.ui.BlockScheduleItemsFragment.java
protected void setupDay(ViewGroup rootView) { final int position = getArguments().getInt("id"); final long startMillis = getArguments().getLong("startMillis"); mDay = new Day(); // Setup data mDay.index = position;/*w ww. j av a2 s . c om*/ mDay.timeStart = startMillis; mDay.timeEnd = startMillis + DateUtils.DAY_IN_MILLIS; mDay.loaderUri = CfpContract.Blocks.buildBlocksBetweenDirUri(mDay.timeStart, mDay.timeEnd); // Setup views mDay.rootView = rootView; mDay.scrollView = (ObservableScrollView) mDay.rootView.findViewById(R.id.schedule_items_scroll); mDay.scheduleItemsView = (ScheduleItemsLayout) mDay.rootView.findViewById(R.id.schedule_items); mDay.nowView = mDay.rootView.findViewById(R.id.schedule_items_now); // mDay.blocksView.setDrawingCacheEnabled(true); // mDay.blocksView.setAlwaysDrawnWithCacheEnabled(true); TimeZone.setDefault(UIUtils.CONFERENCE_TIME_ZONE); mDay.label = DateUtils.formatDateTime(getActivity(), startMillis, TIME_FLAGS); }
From source file:com.jaspersoft.android.jaspermobile.activities.storage.adapter.FileAdapter.java
private String getFormattedDateModified(File file) { return DateUtils.formatDateTime(getContext(), file.lastModified(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_24HOUR); }
From source file:com.meiste.tempalarm.ui.CurrentTemp.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.current_temp); ButterKnife.inject(this); mAdapter = new SimpleCursorAdapter(this, R.layout.record, null, FROM_COLUMNS, TO_FIELDS, 0); mAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { @Override//from www.j a v a2s .com public boolean setViewValue(final View view, final Cursor cursor, final int columnIndex) { final TextView textView = (TextView) view; switch (columnIndex) { case COLUMN_TIMESTAMP: // Convert timestamp to human-readable date textView.setText(DateUtils.formatDateTime(getApplicationContext(), cursor.getLong(columnIndex), AppConstants.DATE_FORMAT_FLAGS)); return true; case COLUMN_DEGF: // Restrict to one decimal place textView.setText(String.format("%.1f", cursor.getFloat(columnIndex))); return true; case COLUMN_LIGHT: if (cursor.getInt(columnIndex) < mLightThreshold) { textView.setText(getText(R.string.lights_on)); } else { textView.setText(getText(R.string.lights_off)); } return true; } return false; } }); final View header = getLayoutInflater().inflate(R.layout.record_header, mListView, false); final FrameLayout frameLayout = ButterKnife.findById(header, R.id.graph_placeholder); mGraph = new LineGraphView(this, ""); mGraph.setDrawBackground(true); mGraph.setBackgroundColor(getResources().getColor(R.color.primary_graph)); mGraph.setCustomLabelFormatter(new CustomLabelFormatter() { @Override public String formatLabel(final double value, final boolean isValueX) { if (isValueX) { return DateUtils.formatDateTime(getApplicationContext(), (long) value, AppConstants.DATE_FORMAT_FLAGS_GRAPH); } return String.format(Locale.getDefault(), "%.1f", value); } }); mGraph.getGraphViewStyle().setNumHorizontalLabels(AppConstants.GRAPH_NUM_HORIZONTAL_LABELS); frameLayout.addView(mGraph); mListView.addHeaderView(header, null, false); mListView.setAdapter(mAdapter); getLoaderManager().initLoader(0, null, this); }
From source file:com.qian.weeno.util.UIUtils.java
/** * Format and return the given {@link Blocks} values using * {@link #CONFERENCE_TIME_ZONE}.//from w ww .j a v a 2 s . c om */ public static String formatTimeString(long time, Context context) { TimeZone.setDefault(CONFERENCE_TIME_ZONE); // NOTE: There is an efficient version of formatDateRange in Eclair and // beyond that allows you to recycle a StringBuilder. return DateUtils.formatDateTime(context, time, TIME_FLAGS); }