Loading packages/DocumentsUI/src/com/android/documentsui/Shared.java +24 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,8 @@ package com.android.documentsui; import android.content.Context; import android.text.format.DateUtils; import android.text.format.Time; /** @hide */ public final class Shared { Loading @@ -40,4 +42,26 @@ public final class Shared { public static final String getQuantityString(Context context, int resourceId, int quantity) { return context.getResources().getQuantityString(resourceId, quantity, quantity); } public static String formatTime(Context context, long when) { // TODO: DateUtils should make this easier Time then = new Time(); then.set(when); Time now = new Time(); now.setToNow(); int flags = DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL; if (then.year != now.year) { flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE; } else if (then.yearDay != now.yearDay) { flags |= DateUtils.FORMAT_SHOW_DATE; } else { flags |= DateUtils.FORMAT_SHOW_TIME; } return DateUtils.formatDateTime(context, when, flags); } } Loading
packages/DocumentsUI/src/com/android/documentsui/Shared.java +24 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,8 @@ package com.android.documentsui; import android.content.Context; import android.text.format.DateUtils; import android.text.format.Time; /** @hide */ public final class Shared { Loading @@ -40,4 +42,26 @@ public final class Shared { public static final String getQuantityString(Context context, int resourceId, int quantity) { return context.getResources().getQuantityString(resourceId, quantity, quantity); } public static String formatTime(Context context, long when) { // TODO: DateUtils should make this easier Time then = new Time(); then.set(when); Time now = new Time(); now.setToNow(); int flags = DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL; if (then.year != now.year) { flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE; } else if (then.yearDay != now.yearDay) { flags |= DateUtils.FORMAT_SHOW_DATE; } else { flags |= DateUtils.FORMAT_SHOW_TIME; } return DateUtils.formatDateTime(context, when, flags); } }