Example usage for android.text.format DateUtils formatDateTime

List of usage examples for android.text.format DateUtils formatDateTime

Introduction

In this page you can find the example usage for android.text.format DateUtils formatDateTime.

Prototype

public static String formatDateTime(Context context, long millis, int flags) 

Source Link

Document

Formats a date or a time according to the local conventions.

Usage

From source file:com.google.android.apps.iosched.ui.ScheduleFragment.java

private void setupDay(LayoutInflater inflater, long startMillis) {
    Day day = new Day();

    // Setup data
    day.index = mDays.size();//from   w  ww .ja  v  a 2  s . co  m
    day.timeStart = startMillis;
    day.timeEnd = startMillis + DateUtils.DAY_IN_MILLIS;
    day.blocksUri = ScheduleContract.Blocks.buildBlocksBetweenDirUri(day.timeStart, day.timeEnd);

    // Setup views
    day.rootView = (ViewGroup) inflater.inflate(R.layout.blocks_content, null);

    day.scrollView = (ObservableScrollView) day.rootView.findViewById(R.id.blocks_scroll);
    day.scrollView.setOnScrollListener(this);

    day.blocksView = (BlocksLayout) day.rootView.findViewById(R.id.blocks);
    day.nowView = day.rootView.findViewById(R.id.blocks_now);

    day.blocksView.setDrawingCacheEnabled(true);
    day.blocksView.setAlwaysDrawnWithCacheEnabled(true);

    TimeZone.setDefault(UIUtils.CONFERENCE_TIME_ZONE);
    day.label = DateUtils.formatDateTime(getActivity(), startMillis, TIME_FLAGS);

    mWorkspace.addView(day.rootView);
    mDays.add(day);
}

From source file:com.infine.android.devoxx.ui.ScheduleFragment.java

private void setupDay(LayoutInflater inflater, long startMillis) {
    Day day = new Day();

    // Setup data
    day.index = mDays.size();//  ww w.  ja  v a2s  .co  m
    day.timeStart = startMillis;
    day.timeEnd = startMillis + DateUtils.DAY_IN_MILLIS;
    day.blocksUri = ScheduleContract.Blocks.buildBlocksBetweenDirUri(day.timeStart, day.timeEnd);

    // Setup views
    day.rootView = (ViewGroup) inflater.inflate(R.layout.blocks_content, null);

    day.scrollView = (ObservableScrollView) day.rootView.findViewById(R.id.blocks_scroll);
    day.scrollView.setOnScrollListener(this);

    day.blocksView = (BlocksLayout) day.rootView.findViewById(R.id.blocks);
    day.nowView = day.rootView.findViewById(R.id.blocks_now);

    //      day.blocksView.setDrawingCacheEnabled(true);
    //      day.blocksView.setAlwaysDrawnWithCacheEnabled(true);

    TimeZone.setDefault(UIUtils.CONFERENCE_TIME_ZONE);
    day.label = DateUtils.formatDateTime(getActivity(), startMillis, TIME_FLAGS);

    mWorkspace.addView(day.rootView);
    mDays.add(day);
}

From source file:nl.atcomputing.spacetravelagency.fragments.PlaceOrderFragment.java

private void setDepartureTime(long departureTime) {
    CharSequence dateString = DateUtils.formatDateTime(getActivity(), departureTime * 1000,
            DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME);
    TextView tv = (TextView) this.view.findViewById(R.id.departure_time_value);
    tv.setText(dateString);/*from w  ww  . j  ava2 s  . co m*/

    View v = this.view.findViewById(R.id.linearlayout_departure_time);
    v.setVisibility(View.VISIBLE);
}

From source file:org.pixmob.droidlink.ui.EventDetailsFragment.java

private void initFields() {
    if (eventUri == null) {
        return;/*from   w w  w .  ja v a  2 s .c  o  m*/
    }
    final Cursor cursor = getActivity().getContentResolver().query(eventUri, EVENT_PROJECTION, null, null,
            null);
    if (cursor == null) {
        throw new IllegalArgumentException("Cannot event: " + eventUri);
    }
    if (!cursor.moveToNext()) {
        cursor.close();
        throw new IllegalArgumentException("Cannot find event: " + eventUri);
    }

    final long date;
    final int type;
    final String name;
    String message;
    try {
        date = cursor.getLong(cursor.getColumnIndexOrThrow(CREATED));
        type = cursor.getInt(cursor.getColumnIndexOrThrow(TYPE));
        name = cursor.getString(cursor.getColumnIndexOrThrow(NAME));
        number = cursor.getString(cursor.getColumnIndexOrThrow(NUMBER));
        message = cursor.getString(cursor.getColumnIndexOrThrow(MESSAGE));
    } finally {
        cursor.close();
    }

    if (number != null) {
        number = PhoneNumberUtils.formatNumber(number);
    }

    final String dateStr = DateUtils.formatDateTime(getActivity(), date,
            DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME);
    dateView.setText(dateStr);

    final Integer typeResourceId = EVENT_ICONS.get(type);
    typeView.setVisibility(typeResourceId == null ? View.GONE : View.VISIBLE);
    if (typeResourceId != null) {
        typeView.setImageResource(typeResourceId);
    }

    final String eventName;
    final String eventNumber;
    if (number == null) {
        eventName = getActivity().getString(R.string.unknown_number);
        eventNumber = null;
    } else if (name == null) {
        eventName = number;
        eventNumber = null;
    } else {
        eventName = name;
        eventNumber = number;
    }
    nameView.setText(eventName);
    numberView.setText(eventNumber);

    if (EventsContract.MISSED_CALL_TYPE == type) {
        message = getString(R.string.missed_call);
    }
    messageView.setText(message);

    new GetContactPictureTask(this, eventNumber).execute();
}

From source file:org.dalmasso.ietfsched.ui.ScheduleFragment.java

private void setupDay(LayoutInflater inflater, long startMillis) {
    Day day = new Day();
    if (debbug)/*from www  . ja v  a2 s.co m*/
        Log.d(TAG, "Setup day");
    // Setup data
    day.index = mDays.size();
    day.timeStart = startMillis;
    day.timeEnd = startMillis + DateUtils.DAY_IN_MILLIS;
    day.blocksUri = ScheduleContract.Blocks.buildBlocksBetweenDirUri(day.timeStart, day.timeEnd);
    if (debbug)
        Log.d(TAG, "day block uri " + day.blocksUri);

    // Setup views
    day.rootView = (ViewGroup) inflater.inflate(R.layout.blocks_content, null);

    day.scrollView = (ObservableScrollView) day.rootView.findViewById(R.id.blocks_scroll);
    day.scrollView.setOnScrollListener(this);

    day.blocksView = (BlocksLayout) day.rootView.findViewById(R.id.blocks);
    day.nowView = day.rootView.findViewById(R.id.blocks_now);

    day.blocksView.setDrawingCacheEnabled(true);
    day.blocksView.setAlwaysDrawnWithCacheEnabled(true);

    TimeZone.setDefault(UIUtils.CONFERENCE_TIME_ZONE);
    day.label = DateUtils.formatDateTime(getActivity(), startMillis, TIME_FLAGS);

    mWorkspace.addView(day.rootView);
    mDays.add(day);
}

From source file:com.google.android.apps.iosched2.ui.ScheduleFragment.java

private void setupDay(LayoutInflater inflater, long startMillis) {
    Day day = new Day();

    // Setup data
    day.index = mDays.size();/*  w w  w  . j  a  v  a2s. c o  m*/
    day.timeStart = startMillis;
    day.timeEnd = startMillis + DateUtils.DAY_IN_MILLIS;
    day.blocksUri = ScheduleContract.Blocks.buildBlocksBetweenDirUri(day.timeStart, day.timeEnd);

    // Setup views
    day.rootView = (ViewGroup) inflater.inflate(R.layout.blocks_content, null);

    day.scrollView = (ObservableScrollView) day.rootView.findViewById(R.id.blocks_scroll);
    day.scrollView.setOnScrollListener(this);

    day.blocksView = (BlocksLayout) day.rootView.findViewById(R.id.blocks);
    day.nowView = day.rootView.findViewById(R.id.blocks_now);

    day.blocksView.setDrawingCacheEnabled(true);
    day.blocksView.setAlwaysDrawnWithCacheEnabled(true);

    TimeZone.setDefault(UIUtils.getConferenceTimeZone());
    day.label = DateUtils.formatDateTime(getActivity(), startMillis, TIME_FLAGS);

    mWorkspace.addView(day.rootView);
    mDays.add(day);
}

From source file:org.openintents.openpgp.util.OpenPgpKeyPreference.java

private void refreshTitleAndSummary() {
    boolean isConfigured = openPgpApiManager != null
            && openPgpApiManager.getOpenPgpProviderState() != OpenPgpProviderState.UNCONFIGURED;
    setEnabled(isConfigured);//  ww  w  . j a  v  a 2 s .  c  om

    if (this.keyId == NO_KEY) {
        setTitle(R.string.openpgp_key_title);
        setSummary(R.string.openpgp_no_key_selected);

        return;
    }

    if (this.keyPrimaryUserId != null && this.keyCreationTime != 0) {
        Context context = getContext();

        UserId userId = OpenPgpUtils.splitUserId(keyPrimaryUserId);
        if (userId.email != null) {
            setTitle(context.getString(R.string.openpgp_key_using, userId.email));
        } else if (userId.name != null) {
            setTitle(context.getString(R.string.openpgp_key_using, userId.name));
        } else {
            setTitle(R.string.openpgp_key_using_no_name);
        }

        String creationTimeStr = DateUtils.formatDateTime(context, keyCreationTime, DateUtils.FORMAT_SHOW_DATE
                | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_ABBREV_MONTH);
        setSummary(context.getString(R.string.openpgp_key_created, creationTimeStr));
    } else {
        setTitle(R.string.openpgp_key_title);
        setSummary(R.string.openpgp_key_selected);
    }
}

From source file:com.google.android.apps.muzei.gallery.GalleryArtSource.java

private void publishNextArtwork(Uri forceUri) {
    // schedule next
    scheduleNext();/*from  w  w w .  j a  va  2 s  .  co m*/

    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:org.onebusaway.android.report.ui.SimpleArrivalListFragment.java

private void loadArrivalList(ObaArrivalInfo[] info, final ObaReferences refs, long currentTime) {
    LinearLayout contentLayout = (LinearLayout) getActivity().findViewById(R.id.simple_arrival_content);
    contentLayout.removeAllViews();/*w  w w  .  ja  v  a  2  s .  com*/

    ArrayList<ArrivalInfo> arrivalInfos = ArrivalInfoUtils.convertObaArrivalInfo(getActivity(), info,
            new ArrayList<String>(), currentTime, false);

    for (ArrivalInfo stopInfo : arrivalInfos) {

        final ObaArrivalInfo arrivalInfo = stopInfo.getInfo();

        LayoutInflater inflater = LayoutInflater.from(getActivity());
        LinearLayout view = (LinearLayout) inflater.inflate(R.layout.arrivals_list_item, null, false);
        view.setBackgroundColor(getResources().getColor(R.color.material_background));
        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);

        view.findViewById(R.id.more_horizontal).setVisibility(View.INVISIBLE);
        view.findViewById(R.id.route_favorite).setVisibility(View.INVISIBLE);

        String routeShortName = arrivalInfo.getShortName();
        route.setText(routeShortName);
        UIUtils.maybeShrinkRouteName(getActivity(), route, routeShortName);

        destination.setText(UIUtils.formatDisplayText(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 = getActivity().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(getActivity(), 5);
        int pTopBottom = UIUtils.dpToPixels(getActivity(), 2);
        status.setPadding(pSides, pTopBottom, pSides, pTopBottom);

        time.setText(DateUtils.formatDateTime(getActivity(), stopInfo.getDisplayTime(),
                DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT));
        View reminder = view.findViewById(R.id.reminder);
        reminder.setVisibility(View.GONE);

        contentLayout.addView(view);

        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String agencyName = findAgencyNameByRouteId(refs, arrivalInfo.getRouteId());
                mCallback.onArrivalItemClicked(arrivalInfo, agencyName);
            }
        });
    }
}

From source file:com.numenta.taurus.service.TaurusNotificationService.java

/**
 * Format anomaly title/*from ww  w  . j  a v  a2  s. c o  m*/
 *
 * @param company   The company name
 * @param types     The anomaly types triggering the anomaly
 * @param timestamp The time the anomaly was fired
 * @return The formatted text suitable for OS notification
 */
String formatAnomalyTitle(String company, EnumSet<MetricType> types, long timestamp) {
    Context ctx = getService();
    String anomalyTypes = "";

    if (!Collections.disjoint(types, MetricType.STOCK_TYPES)) {
        if (types.contains(MetricType.TwitterVolume)) {
            anomalyTypes = ctx.getString(R.string.header_stock_twitter);
        } else {
            anomalyTypes = ctx.getString(R.string.header_stock);
        }
    } else if (types.contains(MetricType.TwitterVolume)) {
        anomalyTypes = ctx.getString(R.string.header_twitter);
    }
    return String.format(ctx.getString(R.string.taurus_notification_description_template), company,
            DateUtils.formatDateTime(ctx, timestamp, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME),
            anomalyTypes);
}