本文整理汇总了Java中android.text.format.DateUtils.formatDateRange方法的典型用法代码示例。如果您正苦于以下问题:Java DateUtils.formatDateRange方法的具体用法?Java DateUtils.formatDateRange怎么用?Java DateUtils.formatDateRange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.format.DateUtils
的用法示例。
在下文中一共展示了DateUtils.formatDateRange方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMonthAndYearString
import android.text.format.DateUtils; //导入方法依赖的package包/类
private String getMonthAndYearString() {
int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NO_MONTH_DAY;
mStringBuilder.setLength(0);
long millis = mCalendar.getTimeInMillis();
return DateUtils.formatDateRange(getContext(), millis, millis, flags);
}
示例2: getMonthAndYearString
import android.text.format.DateUtils; //导入方法依赖的package包/类
/**
* 获取年份和月份
*
* @return
*/
private String getMonthAndYearString() {
int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NO_MONTH_DAY;
mStringBuilder.setLength(0);
long millis = mCalendar.getTimeInMillis();
return DateUtils.formatDateRange(getContext(), millis, millis, flags);
}
示例3: formatTime
import android.text.format.DateUtils; //导入方法依赖的package包/类
/**
* @param startTime The start time of a session in millis.
* @param context The context to be used for getting the display timezone.
* @return Formats a given startTime to the specific short time.
* example: 12:00 AM
*/
public static String formatTime(long startTime, Context context) {
StringBuilder sb = new StringBuilder();
DateUtils.formatDateRange(context, new Formatter(sb), startTime, startTime,
DateUtils.FORMAT_SHOW_TIME,
SettingsUtils.getDisplayTimeZone(context).getID());
return sb.toString();
}
示例4: getMonthAndYearString
import android.text.format.DateUtils; //导入方法依赖的package包/类
private String getMonthAndYearString() {
int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR
| DateUtils.FORMAT_NO_MONTH_DAY;
mStringBuilder.setLength(0);
long millis = mCalendar.getTimeInMillis();
return DateUtils.formatDateRange(getContext(), millis, millis, flags);
}
示例5: getMonthAndYearString
import android.text.format.DateUtils; //导入方法依赖的package包/类
private String getMonthAndYearString() {
int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NO_MONTH_DAY;
mStringBuilder.setLength(0);
long millis = mCalendar.getTimeInMillis();
return DateUtils.formatDateRange(getContext(), millis, millis, flags); // 지역화된 포멧으로 출력
}
示例6: scheduleToString
import android.text.format.DateUtils; //导入方法依赖的package包/类
private String scheduleToString(Schedule s) {
if(!s.open) {
return getContext().getString(R.string.lobby_schedule_closed);
}
Formatter f = new Formatter();
DateUtils.formatDateRange(getContext(), f, s.openTime, s.openTime, DateUtils.FORMAT_SHOW_TIME, Time.TIMEZONE_UTC);
f.format(getContext().getString(R.string.lobby_schedule_range_separator));
DateUtils.formatDateRange(getContext(), f, s.openTime + s.duration, s.openTime + s.duration, DateUtils.FORMAT_SHOW_TIME, Time.TIMEZONE_UTC);
return f.toString();
}
示例7: updateClosedWarning
import android.text.format.DateUtils; //导入方法依赖的package包/类
private void updateClosedWarning() {
if (network.isOpen()) {
layoutNetworkClosed.setVisibility(View.GONE);
} else {
Formatter f = new Formatter();
DateUtils.formatDateRange(getContext(), f, network.getNextOpenTime(), network.getNextOpenTime(), DateUtils.FORMAT_SHOW_TIME, Time.TIMEZONE_UTC);
viewNetworkClosed.setText(String.format(getString(R.string.warning_network_closed), f.toString()));
layoutNetworkClosed.setVisibility(View.VISIBLE);
}
}
示例8: onBindViewHolder
import android.text.format.DateUtils; //导入方法依赖的package包/类
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
holder.mItem = mValues.get(position);
holder.mNameView.setText(holder.mItem.name);
if(holder.mItem.down) {
long downMinutes = (((new Date()).getTime() / 60000) - (holder.mItem.downSince.getTime() / 60000));
holder.mStatusDescView.setVisibility(View.VISIBLE);
holder.mStatusDescView.setText(String.format(holder.mView.getContext().getString(R.string.frag_lines_duration), downMinutes));
holder.mStatusView.setImageResource(R.drawable.ic_warning_white);
setDownGradient(holder);
} else if (holder.mItem.exceptionallyClosed) {
setDownGradient(holder);
Formatter f = new Formatter();
DateUtils.formatDateRange(context, f, holder.mItem.closedUntil, holder.mItem.closedUntil, DateUtils.FORMAT_SHOW_TIME, Time.TIMEZONE_UTC);
holder.mStatusDescView.setText(String.format(holder.mView.getContext().getString(R.string.frag_lines_until), f.toString()));
holder.mStatusView.setImageResource(R.drawable.ic_close_white_24dp);
} else {
holder.mView.setBackgroundColor(holder.mItem.color);
holder.mStatusDescView.setVisibility(View.GONE);
holder.mStatusView.setImageResource(R.drawable.ic_done_white);
}
holder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (null != mListener) {
// Notify the active callbacks interface (the activity, if the
// fragment is attached to one) that an item has been selected.
mListener.onListFragmentInteraction(holder.mItem);
}
}
});
}
示例9: getView
import android.text.format.DateUtils; //导入方法依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Make sure we have a valid convertView to start with
final View result = convertView == null
? mLayoutInflater.inflate(R.layout.call_detail_history_item, parent, false)
: convertView;
PhoneCallDetails details = (PhoneCallDetails) getItem(position);
CallTypeIconsView callTypeIconView =
(CallTypeIconsView) result.findViewById(R.id.call_type_icon);
TextView callTypeTextView = (TextView) result.findViewById(R.id.call_type_text);
TextView dateView = (TextView) result.findViewById(R.id.date);
TextView durationView = (TextView) result.findViewById(R.id.duration);
int callType = details.callTypes[0];
callTypeIconView.clear();
callTypeIconView.add(callType);
StringBuilder typeSb = new StringBuilder();
typeSb.append(mContext.getResources().getString(getCallTypeText(callType)));
// If not 200, we add text for user feedback about what went wrong
if(details.statusCode != 200) {
typeSb.append(" - ");
typeSb.append(details.statusCode);
if(!TextUtils.isEmpty(details.statusText)) {
typeSb.append(" / ");
typeSb.append(details.statusText);
}
}
callTypeTextView.setText(typeSb.toString());
// Set the date.
CharSequence dateValue = DateUtils.formatDateRange(mContext, details.date, details.date,
DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE |
DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_YEAR);
dateView.setText(dateValue);
// Set the duration
if (callType == Calls.MISSED_TYPE) {
durationView.setVisibility(View.GONE);
} else {
durationView.setVisibility(View.VISIBLE);
durationView.setText(formatDuration(details.duration));
}
return result;
}
示例10: refresh
import android.text.format.DateUtils; //导入方法依赖的package包/类
private void refresh(boolean requestOnlineUpdate) {
Realm realm = Realm.getDefaultInstance();
boolean hasTripsToConfirm = Trip.getMissingConfirmTrips(realm).size() > 0;
realm.close();
if (hasTripsToConfirm) {
if (unconfirmedTripsCard.getVisibility() == View.GONE) {
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
Fragment newFragment = UnconfirmedTripsFragment.newInstance(1);
transaction.replace(R.id.unconfirmed_trips_card, newFragment);
transaction.commitAllowingStateLoss();
unconfirmedTripsCard.setVisibility(View.VISIBLE);
}
} else {
unconfirmedTripsCard.setVisibility(View.GONE);
}
if (mListener == null)
return;
MainService m = mListener.getMainService();
if (m == null)
return;
if (requestOnlineUpdate) {
m.getLineStatusCache().updateLineStatus();
m.getStatsCache().updateStats();
}
Network net = m.getNetwork(MainService.PRIMARY_NETWORK_ID);
if (net == null) {
networkClosedCard.setVisibility(View.GONE);
unconfirmedTripsCard.setVisibility(View.GONE);
m.checkForTopologyUpdates();
} else if (net.isOpen()) {
networkClosedCard.setVisibility(View.GONE);
} else {
Formatter f = new Formatter();
DateUtils.formatDateRange(getContext(), f, net.getNextOpenTime(), net.getNextOpenTime(), DateUtils.FORMAT_SHOW_TIME, Time.TIMEZONE_UTC);
networkClosedView.setText(String.format(getString(R.string.warning_network_closed), f.toString()));
networkClosedCard.setVisibility(View.VISIBLE);
}
}
示例11: onServiceConnected
import android.text.format.DateUtils; //导入方法依赖的package包/类
@Override
public void onServiceConnected(ComponentName className,
IBinder service) {
// We've bound to LocalService, cast the IBinder and get LocalService instance
binder = (MainService.LocalBinder) service;
mainService = binder.getService();
locBound = true;
Network net = mainService.getNetwork(networkId);
Line line = net.getLine(lineId);
String title = String.format(getString(R.string.act_line_title), line.getName());
setTitle(title);
getSupportActionBar().setTitle(title);
AppBarLayout abl = (AppBarLayout) findViewById(R.id.app_bar);
final CollapsingToolbarLayout ctl = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
ctl.setTitle(title);
int color = line.getColor();
ctl.setContentScrimColor(color);
ctl.setStatusBarScrimColor(color);
abl.setBackgroundColor(color);
Drawable drawable = ContextCompat.getDrawable(LineActivity.this, Util.getDrawableResourceIdForLineId(line.getId()));
drawable.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 35, getResources().getDisplayMetrics());
FrameLayout iconFrame = new FrameLayout(LineActivity.this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(height, height);
int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, getResources().getDisplayMetrics());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
params.setMarginEnd(margin);
}
params.setMargins(0, 0, margin, 0);
iconFrame.setLayoutParams(params);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
iconFrame.setBackgroundDrawable(drawable);
} else {
iconFrame.setBackground(drawable);
}
lineIconsLayout.addView(iconFrame);
abl.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
if (ctl.getHeight() + verticalOffset < 2.5 * ViewCompat.getMinimumHeight(ctl)) {
lineIconsLayout.animate().alpha(0);
} else {
lineIconsLayout.animate().alpha(1);
}
}
});
Map<String, LineStatusCache.Status> statuses = mainService.getLineStatusCache().getLineStatus();
if (statuses.get(line.getId()) != null &&
statuses.get(line.getId()).down) {
disturbancesWarningLayout.setVisibility(View.VISIBLE);
} else {
disturbancesWarningLayout.setVisibility(View.GONE);
}
LinearLayout closedLayout = (LinearLayout) findViewById(R.id.closed_info_layout);
if (line.isExceptionallyClosed(new Date())) {
TextView closedView = (TextView) findViewById(R.id.closed_info_view);
Formatter f = new Formatter();
DateUtils.formatDateRange(LineActivity.this, f, line.getNextOpenTime(), line.getNextOpenTime(), DateUtils.FORMAT_SHOW_TIME, Time.TIMEZONE_UTC);
closedView.setText(String.format(getString(R.string.act_line_closed_schedule), f.toString()));
closedLayout.setVisibility(View.VISIBLE);
} else {
closedLayout.setVisibility(View.GONE);
}
populateLineView(LineActivity.this, getLayoutInflater(), net, line, lineLayout);
}