Example usage for android.text.format DateUtils FORMAT_SHOW_TIME

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

Introduction

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

Prototype

int FORMAT_SHOW_TIME

To view the source code for android.text.format DateUtils FORMAT_SHOW_TIME.

Click Source Link

Usage

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;/*  w  w w.j  a va  2  s.c  om*/
    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 www. j  ava 2  s .  c o 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(//w w w.j ava2s .  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:com.dgsd.android.ShiftTracker.Adapter.DayAdapter.java

private String getTimeText(Shift shift) {
    String time = mIdToTimeArray.get((int) shift.id);
    if (!TextUtils.isEmpty(time))
        return time;

    int flags = DateUtils.FORMAT_SHOW_TIME;
    if (mIs24Hour)
        flags |= DateUtils.FORMAT_24HOUR;

    mStringBuilder.setLength(0);/*from  w  w w  . j  a  v  a  2 s. c  om*/
    time = DateUtils.formatDateRange(mContext, mFormatter, shift.getStartTime(), shift.getEndTime(), flags)
            .toString();

    time += " (" + UIUtils.getDurationAsHours(shift.getDurationInMinutes()) + ")";

    mIdToTimeArray.put((int) shift.id, time);
    return time;
}

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.adam.aslfms.util.Util.java

public static String timeFromLocalMillis(Context ctx, long millis) {
    return DateUtils.formatDateTime(ctx, millis,
            DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NUMERIC_DATE);
}

From source file:de.incoherent.suseconferenceclient.app.SocialWrapper.java

public static ArrayList<SocialItem> getGooglePlusItems(Context context, String tag, int maximum) {
    String twitterSearch = "https://www.googleapis.com/plus/v1/activities?orderBy=recent&query=" + tag + "&key="
            + Config.PLUS_KEY;//  ww  w . j a  v a  2s . c  o  m
    Log.d("SUSEConferences", "Google search: " + twitterSearch);
    ArrayList<SocialItem> socialItems = new ArrayList<SocialItem>();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'");
    formatter.setTimeZone(TimeZone.getTimeZone("UTC"));

    Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.google_icon);

    try {
        JSONObject result = HTTPWrapper.get(twitterSearch);
        JSONArray items = result.getJSONArray("items");
        int len = items.length();
        if ((len > 0) && (maximum > 0) && (len > maximum))
            len = maximum;

        for (int i = 0; i < len; i++) {
            JSONObject jsonItem = items.getJSONObject(i);
            JSONObject actorItem = jsonItem.getJSONObject("actor");
            JSONObject imageItem = actorItem.getJSONObject("image");
            JSONObject objectItem = jsonItem.getJSONObject("object");
            Bitmap image = HTTPWrapper.getImage(imageItem.getString("url"));
            String content = Html.fromHtml(objectItem.getString("content")).toString();
            Date formattedDate = new Date();
            try {
                formattedDate = formatter.parse(jsonItem.getString("published"));
            } catch (ParseException e) {
                e.printStackTrace();
            }

            SocialItem newItem = new SocialItem(SocialItem.GOOGLE, actorItem.getString("displayName"), content,
                    formattedDate,
                    DateUtils
                            .formatDateTime(context, formattedDate.getTime(),
                                    DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_NUMERIC_DATE
                                            | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE),
                    image, icon);
            newItem.setLink(jsonItem.getString("url"));
            socialItems.add(newItem);
        }
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (SocketException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return socialItems;
}

From source file:com.socialdisasters.other.MessageAdapter.java

public static String formatTimeStampString(Context context, long when, boolean fullFormat) {
    Time then = new Time();
    then.set(when);/* ww w .j av  a  2s .co  m*/
    Time now = new Time();
    now.setToNow();

    // Basic settings for formatDateTime() we want for all cases.
    int format_flags = DateUtils.FORMAT_ABBREV_ALL;

    // If the message is from a different year, show the date and year.
    if (then.year != now.year) {
        format_flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE;
    } else if (then.yearDay != now.yearDay) {
        // If it is from a different day than today, show only the date.
        format_flags |= DateUtils.FORMAT_SHOW_DATE;
    } else {
        // Otherwise, if the message is from today, show the time.
        format_flags |= DateUtils.FORMAT_SHOW_TIME;
    }

    // If the caller has asked for full details, make sure to show the date
    // and time no matter what we've determined above (but still make showing
    // the year only happen if it is a different year from today).
    if (fullFormat) {
        format_flags |= (DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME);
    }

    return DateUtils.formatDateTime(context, when, format_flags);
}

From source file:org.jraf.android.cinetoday.mobile.app.main.MainActivity.java

private void updateLastUpdateDateLabel() {
    MainPrefs prefs = MainPrefs.get(this);
    Long lastUpdateDate = prefs.getLastUpdateDate();
    if (lastUpdateDate == null) {
        mBinding.txtStatus.setText(R.string.main_lastUpdateDate_none);
    } else {//from   w  ww  .  j a  va2s  .co m
        String dateStr = DateUtils.formatDateTime(this, lastUpdateDate,
                DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME);
        mBinding.txtStatus.setText(getString(R.string.main_lastUpdateDate, dateStr));
    }
}

From source file:com.numenta.core.utils.NotificationUtils.java

/**
 * Format Notification description based on instance name and timestamp
 *
 * @param instanceName//w  w  w  . ja v  a2  s .  com
 * @param timestamp
 * @return Formatted notification description using
 */
public static String formatSimpleNotificationDescription(String instanceName, long timestamp) {
    // Formatted Notification description:
    // $1=metric.instanceName,
    // $2=timestamp

    // Gets the standard date formatter for the current locale of
    // the device
    String formattedCurrentDate = DateUtils.formatDateTime(HTMApplication.getContext(), timestamp,
            DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME);

    return String.format(
            HTMApplication.getContext().getString(R.string.simple_notification_description_template),
            instanceName, formattedCurrentDate);
}