Search in sources :

Example 96 with SimpleDateFormat

use of java.text.SimpleDateFormat in project android_frameworks_base by ParanoidAndroid.

the class VideoEditorHelper method createRandomFile.

/**
     * This method creates a Directory and filename
     *
     * @param location This is path where the file is to be created
     *            "/sdcard/Output/"
     * @return Path in form of /sdcard/Output/200910100000
     */
public String createRandomFile(String location) {
    Random randomGenerator = new Random();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssS");
    Date date = new Date();
    final String filePath = location + dateFormat.format(date) + randomGenerator.nextInt(10);
    Log.i(TAG, ">>>>>>>>>>>>>>>>createRandomFile  Location= " + location + "\t FilePath = " + filePath);
    return filePath;
}
Also used : Random(java.util.Random) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 97 with SimpleDateFormat

use of java.text.SimpleDateFormat in project android_frameworks_base by ParanoidAndroid.

the class Clock method getSmallTime.

public final CharSequence getSmallTime() {
    Context context = getContext();
    boolean is24 = DateFormat.is24HourFormat(context);
    LocaleData d = LocaleData.get(context.getResources().getConfiguration().locale);
    final char MAGIC1 = '';
    final char MAGIC2 = '';
    SimpleDateFormat sdf;
    String format = is24 ? d.timeFormat24 : d.timeFormat12;
    if (!format.equals(mClockFormatString)) {
        /*
             * Search for an unquoted "a" in the format string, so we can
             * add dummy characters around it to let us find it again after
             * formatting and change its size.
             */
        if (AM_PM_STYLE != AM_PM_STYLE_NORMAL) {
            int a = -1;
            boolean quoted = false;
            for (int i = 0; i < format.length(); i++) {
                char c = format.charAt(i);
                if (c == '\'') {
                    quoted = !quoted;
                }
                if (!quoted && c == 'a') {
                    a = i;
                    break;
                }
            }
            if (a >= 0) {
                // Move a back so any whitespace before AM/PM is also in the alternate size.
                final int b = a;
                while (a > 0 && Character.isWhitespace(format.charAt(a - 1))) {
                    a--;
                }
                format = format.substring(0, a) + MAGIC1 + format.substring(a, b) + "a" + MAGIC2 + format.substring(b + 1);
            }
        }
        mClockFormat = sdf = new SimpleDateFormat(format);
        mClockFormatString = format;
    } else {
        sdf = mClockFormat;
    }
    String result = sdf.format(mCalendar.getTime());
    if (AM_PM_STYLE != AM_PM_STYLE_NORMAL) {
        int magic1 = result.indexOf(MAGIC1);
        int magic2 = result.indexOf(MAGIC2);
        if (magic1 >= 0 && magic2 > magic1) {
            SpannableStringBuilder formatted = new SpannableStringBuilder(result);
            if (AM_PM_STYLE == AM_PM_STYLE_GONE) {
                formatted.delete(magic1, magic2 + 1);
            } else {
                if (AM_PM_STYLE == AM_PM_STYLE_SMALL) {
                    CharacterStyle style = new RelativeSizeSpan(0.7f);
                    formatted.setSpan(style, magic1, magic2, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
                }
                formatted.delete(magic2, magic2 + 1);
                formatted.delete(magic1, magic1 + 1);
            }
            return formatted;
        }
    }
    return result;
}
Also used : Context(android.content.Context) LocaleData(libcore.icu.LocaleData) RelativeSizeSpan(android.text.style.RelativeSizeSpan) SimpleDateFormat(java.text.SimpleDateFormat) SpannableStringBuilder(android.text.SpannableStringBuilder) CharacterStyle(android.text.style.CharacterStyle)

Example 98 with SimpleDateFormat

use of java.text.SimpleDateFormat in project android_frameworks_base by ParanoidAndroid.

the class DateView method updateClock.

protected void updateClock() {
    final String weekdayFormat = getContext().getString(R.string.system_ui_weekday_pattern);
    final String dateFormat = getContext().getString(R.string.system_ui_date_pattern);
    final Locale l = Locale.getDefault();
    final Date now = new Date();
    String weekdayFmt = ICU.getBestDateTimePattern(weekdayFormat, l.toString());
    String dateFmt = ICU.getBestDateTimePattern(dateFormat, l.toString());
    StringBuilder builder = new StringBuilder();
    builder.append(new SimpleDateFormat(weekdayFmt, l).format(now));
    builder.append("\n");
    builder.append(new SimpleDateFormat(dateFmt, l).format(now));
    setText(builder.toString());
}
Also used : Locale(java.util.Locale) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 99 with SimpleDateFormat

use of java.text.SimpleDateFormat in project android_frameworks_base by ParanoidAndroid.

the class PiePolicy method getSimpleTime.

public static String getSimpleTime() {
    SimpleDateFormat sdf = new SimpleDateFormat(mContext.getString(is24Hours() ? R.string.pie_hour_format_24 : R.string.pie_hour_format_12));
    String amPm = sdf.format(new Date());
    return amPm.toUpperCase();
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 100 with SimpleDateFormat

use of java.text.SimpleDateFormat in project android_frameworks_base by ParanoidAndroid.

the class AlarmManagerService method dump.

@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) {
        pw.println("Permission Denial: can't dump AlarmManager from from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
        return;
    }
    synchronized (mLock) {
        pw.println("Current Alarm Manager state:");
        if (mRtcWakeupAlarms.size() > 0 || mRtcAlarms.size() > 0) {
            final long now = System.currentTimeMillis();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            pw.println(" ");
            pw.print("  Realtime wakeup (now=");
            pw.print(sdf.format(new Date(now)));
            pw.println("):");
            if (mRtcWakeupAlarms.size() > 0) {
                dumpAlarmList(pw, mRtcWakeupAlarms, "  ", "RTC_WAKEUP", now);
            }
            if (mRtcAlarms.size() > 0) {
                dumpAlarmList(pw, mRtcAlarms, "  ", "RTC", now);
            }
        }
        if (mElapsedRealtimeWakeupAlarms.size() > 0 || mElapsedRealtimeAlarms.size() > 0) {
            final long now = SystemClock.elapsedRealtime();
            pw.println(" ");
            pw.print("  Elapsed realtime wakeup (now=");
            TimeUtils.formatDuration(now, pw);
            pw.println("):");
            if (mElapsedRealtimeWakeupAlarms.size() > 0) {
                dumpAlarmList(pw, mElapsedRealtimeWakeupAlarms, "  ", "ELAPSED_WAKEUP", now);
            }
            if (mElapsedRealtimeAlarms.size() > 0) {
                dumpAlarmList(pw, mElapsedRealtimeAlarms, "  ", "ELAPSED", now);
            }
        }
        pw.println();
        pw.print("  Broadcast ref count: ");
        pw.println(mBroadcastRefCount);
        pw.println();
        if (mLog.dump(pw, "  Recent problems", "    ")) {
            pw.println();
        }
        final FilterStats[] topFilters = new FilterStats[10];
        final Comparator<FilterStats> comparator = new Comparator<FilterStats>() {

            @Override
            public int compare(FilterStats lhs, FilterStats rhs) {
                if (lhs.aggregateTime < rhs.aggregateTime) {
                    return 1;
                } else if (lhs.aggregateTime > rhs.aggregateTime) {
                    return -1;
                }
                return 0;
            }
        };
        int len = 0;
        for (Map.Entry<String, BroadcastStats> be : mBroadcastStats.entrySet()) {
            BroadcastStats bs = be.getValue();
            for (Map.Entry<Pair<String, ComponentName>, FilterStats> fe : bs.filterStats.entrySet()) {
                FilterStats fs = fe.getValue();
                int pos = len > 0 ? Arrays.binarySearch(topFilters, 0, len, fs, comparator) : 0;
                if (pos < 0) {
                    pos = -pos - 1;
                }
                if (pos < topFilters.length) {
                    int copylen = topFilters.length - pos - 1;
                    if (copylen > 0) {
                        System.arraycopy(topFilters, pos, topFilters, pos + 1, copylen);
                    }
                    topFilters[pos] = fs;
                    if (len < topFilters.length) {
                        len++;
                    }
                }
            }
        }
        if (len > 0) {
            pw.println("  Top Alarms:");
            for (int i = 0; i < len; i++) {
                FilterStats fs = topFilters[i];
                pw.print("    ");
                if (fs.nesting > 0)
                    pw.print("*ACTIVE* ");
                TimeUtils.formatDuration(fs.aggregateTime, pw);
                pw.print(" running, ");
                pw.print(fs.numWakeup);
                pw.print(" wakeups, ");
                pw.print(fs.count);
                pw.print(" alarms: ");
                pw.print(fs.mBroadcastStats.mPackageName);
                pw.println();
                pw.print("      ");
                if (fs.mTarget.first != null) {
                    pw.print(" act=");
                    pw.print(fs.mTarget.first);
                }
                if (fs.mTarget.second != null) {
                    pw.print(" cmp=");
                    pw.print(fs.mTarget.second.toShortString());
                }
                pw.println();
            }
        }
        pw.println(" ");
        pw.println("  Alarm Stats:");
        final ArrayList<FilterStats> tmpFilters = new ArrayList<FilterStats>();
        for (Map.Entry<String, BroadcastStats> be : mBroadcastStats.entrySet()) {
            BroadcastStats bs = be.getValue();
            pw.print("  ");
            if (bs.nesting > 0)
                pw.print("*ACTIVE* ");
            pw.print(be.getKey());
            pw.print(" ");
            TimeUtils.formatDuration(bs.aggregateTime, pw);
            pw.print(" running, ");
            pw.print(bs.numWakeup);
            pw.println(" wakeups:");
            tmpFilters.clear();
            for (Map.Entry<Pair<String, ComponentName>, FilterStats> fe : bs.filterStats.entrySet()) {
                tmpFilters.add(fe.getValue());
            }
            Collections.sort(tmpFilters, comparator);
            for (int i = 0; i < tmpFilters.size(); i++) {
                FilterStats fs = tmpFilters.get(i);
                pw.print("    ");
                if (fs.nesting > 0)
                    pw.print("*ACTIVE* ");
                TimeUtils.formatDuration(fs.aggregateTime, pw);
                pw.print(" ");
                pw.print(fs.numWakeup);
                pw.print(" wakes ");
                pw.print(fs.count);
                pw.print(" alarms:");
                if (fs.mTarget.first != null) {
                    pw.print(" act=");
                    pw.print(fs.mTarget.first);
                }
                if (fs.mTarget.second != null) {
                    pw.print(" cmp=");
                    pw.print(fs.mTarget.second.toShortString());
                }
                pw.println();
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Date(java.util.Date) Comparator(java.util.Comparator) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) Map(java.util.Map) Pair(android.util.Pair)

Aggregations

SimpleDateFormat (java.text.SimpleDateFormat)2847 Date (java.util.Date)1590 ParseException (java.text.ParseException)463 DateFormat (java.text.DateFormat)425 Calendar (java.util.Calendar)307 Test (org.junit.Test)305 ArrayList (java.util.ArrayList)232 File (java.io.File)230 IOException (java.io.IOException)185 GregorianCalendar (java.util.GregorianCalendar)139 HashMap (java.util.HashMap)121 Locale (java.util.Locale)70 DateField (edu.uci.ics.textdb.api.field.DateField)64 DoubleField (edu.uci.ics.textdb.api.field.DoubleField)64 IField (edu.uci.ics.textdb.api.field.IField)64 IntegerField (edu.uci.ics.textdb.api.field.IntegerField)64 StringField (edu.uci.ics.textdb.api.field.StringField)63 TextField (edu.uci.ics.textdb.api.field.TextField)63 Map (java.util.Map)63 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)61