Search in sources :

Example 36 with Time

use of android.text.format.Time in project android-betterpickers by code-troopers.

the class RecurrencePickerDialogFragment method onDateSet.

@Override
public void onDateSet(CalendarDatePickerDialogFragment view, int year, int monthOfYear, int dayOfMonth) {
    if (mModel.endDate == null) {
        mModel.endDate = new Time(mTime.timezone);
        mModel.endDate.hour = mModel.endDate.minute = mModel.endDate.second = 0;
    }
    mModel.endDate.year = year;
    mModel.endDate.month = monthOfYear;
    mModel.endDate.monthDay = dayOfMonth;
    mModel.endDate.normalize(false);
    updateDialog();
}
Also used : Time(android.text.format.Time)

Example 37 with Time

use of android.text.format.Time in project Android-Developers-Samples by johnjohndoe.

the class FeedParser method readEntry.

/**
     * Parses the contents of an entry. If it encounters a title, summary, or link tag, hands them
     * off to their respective "read" methods for processing. Otherwise, skips the tag.
     */
private Entry readEntry(XmlPullParser parser) throws XmlPullParserException, IOException, ParseException {
    parser.require(XmlPullParser.START_TAG, ns, "entry");
    String id = null;
    String title = null;
    String link = null;
    long publishedOn = 0;
    while (parser.next() != XmlPullParser.END_TAG) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }
        String name = parser.getName();
        if (name.equals("id")) {
            // Example: <id>urn:uuid:218AC159-7F68-4CC6-873F-22AE6017390D</id>
            id = readTag(parser, TAG_ID);
        } else if (name.equals("title")) {
            // Example: <title>Article title</title>
            title = readTag(parser, TAG_TITLE);
        } else if (name.equals("link")) {
            // Example: <link rel="alternate" type="text/html" href="http://example.com/article/1234"/>
            //
            // Multiple link types can be included. readAlternateLink() will only return
            // non-null when reading an "alternate"-type link. Ignore other responses.
            String tempLink = readTag(parser, TAG_LINK);
            if (tempLink != null) {
                link = tempLink;
            }
        } else if (name.equals("published")) {
            // Example: <published>2003-06-27T12:00:00Z</published>
            Time t = new Time();
            t.parse3339(readTag(parser, TAG_PUBLISHED));
            publishedOn = t.toMillis(false);
        } else {
            skip(parser);
        }
    }
    return new Entry(id, title, link, publishedOn);
}
Also used : Time(android.text.format.Time)

Example 38 with Time

use of android.text.format.Time in project cornerstone by Onskreen.

the class ActivityManagerService method logAppTooSlow.

final void logAppTooSlow(ProcessRecord app, long startTime, String msg) {
    if (true || IS_USER_BUILD) {
        return;
    }
    String tracesPath = SystemProperties.get("dalvik.vm.stack-trace-file", null);
    if (tracesPath == null || tracesPath.length() == 0) {
        return;
    }
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    StrictMode.allowThreadDiskWrites();
    try {
        final File tracesFile = new File(tracesPath);
        final File tracesDir = tracesFile.getParentFile();
        final File tracesTmp = new File(tracesDir, "__tmp__");
        try {
            if (!tracesDir.exists())
                tracesFile.mkdirs();
            // drwxrwxr-x
            FileUtils.setPermissions(tracesDir.getPath(), 0775, -1, -1);
            if (tracesFile.exists()) {
                tracesTmp.delete();
                tracesFile.renameTo(tracesTmp);
            }
            StringBuilder sb = new StringBuilder();
            Time tobj = new Time();
            tobj.set(System.currentTimeMillis());
            sb.append(tobj.format("%Y-%m-%d %H:%M:%S"));
            sb.append(": ");
            TimeUtils.formatDuration(SystemClock.uptimeMillis() - startTime, sb);
            sb.append(" since ");
            sb.append(msg);
            FileOutputStream fos = new FileOutputStream(tracesFile);
            fos.write(sb.toString().getBytes());
            if (app == null) {
                fos.write("\n*** No application process!".getBytes());
            }
            fos.close();
            // -rw-rw-rw-
            FileUtils.setPermissions(tracesFile.getPath(), 0666, -1, -1);
        } catch (IOException e) {
            Slog.w(TAG, "Unable to prepare slow app traces file: " + tracesPath, e);
            return;
        }
        if (app != null) {
            ArrayList<Integer> firstPids = new ArrayList<Integer>();
            firstPids.add(app.pid);
            dumpStackTraces(tracesPath, firstPids, null, null, null);
        }
        File lastTracesFile = null;
        File curTracesFile = null;
        for (int i = 9; i >= 0; i--) {
            String name = String.format("slow%02d.txt", i);
            curTracesFile = new File(tracesDir, name);
            if (curTracesFile.exists()) {
                if (lastTracesFile != null) {
                    curTracesFile.renameTo(lastTracesFile);
                } else {
                    curTracesFile.delete();
                }
            }
            lastTracesFile = curTracesFile;
        }
        tracesFile.renameTo(curTracesFile);
        if (tracesTmp.exists()) {
            tracesTmp.renameTo(tracesFile);
        }
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
}
Also used : StrictMode(android.os.StrictMode) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) Time(android.text.format.Time) IOException(java.io.IOException) File(java.io.File)

Example 39 with Time

use of android.text.format.Time in project android_frameworks_base by ParanoidAndroid.

the class ActivityManagerService method logAppTooSlow.

final void logAppTooSlow(int pid, long startTime, String msg) {
    if (true || IS_USER_BUILD) {
        return;
    }
    String tracesPath = SystemProperties.get("dalvik.vm.stack-trace-file", null);
    if (tracesPath == null || tracesPath.length() == 0) {
        return;
    }
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    StrictMode.allowThreadDiskWrites();
    try {
        final File tracesFile = new File(tracesPath);
        final File tracesDir = tracesFile.getParentFile();
        final File tracesTmp = new File(tracesDir, "__tmp__");
        try {
            if (!tracesDir.exists()) {
                tracesFile.mkdirs();
                if (!SELinux.restorecon(tracesDir.getPath())) {
                    return;
                }
            }
            // drwxrwxr-x
            FileUtils.setPermissions(tracesDir.getPath(), 0775, -1, -1);
            if (tracesFile.exists()) {
                tracesTmp.delete();
                tracesFile.renameTo(tracesTmp);
            }
            StringBuilder sb = new StringBuilder();
            Time tobj = new Time();
            tobj.set(System.currentTimeMillis());
            sb.append(tobj.format("%Y-%m-%d %H:%M:%S"));
            sb.append(": ");
            TimeUtils.formatDuration(SystemClock.uptimeMillis() - startTime, sb);
            sb.append(" since ");
            sb.append(msg);
            FileOutputStream fos = new FileOutputStream(tracesFile);
            fos.write(sb.toString().getBytes());
            if (pid <= 0) {
                fos.write("\n*** No application process!".getBytes());
            }
            fos.close();
            // -rw-rw-rw-
            FileUtils.setPermissions(tracesFile.getPath(), 0666, -1, -1);
        } catch (IOException e) {
            Slog.w(TAG, "Unable to prepare slow app traces file: " + tracesPath, e);
            return;
        }
        if (pid > 0) {
            ArrayList<Integer> firstPids = new ArrayList<Integer>();
            firstPids.add(pid);
            dumpStackTraces(tracesPath, firstPids, null, null, null);
        }
        File lastTracesFile = null;
        File curTracesFile = null;
        for (int i = 9; i >= 0; i--) {
            String name = String.format("slow%02d.txt", i);
            curTracesFile = new File(tracesDir, name);
            if (curTracesFile.exists()) {
                if (lastTracesFile != null) {
                    curTracesFile.renameTo(lastTracesFile);
                } else {
                    curTracesFile.delete();
                }
            }
            lastTracesFile = curTracesFile;
        }
        tracesFile.renameTo(curTracesFile);
        if (tracesTmp.exists()) {
            tracesTmp.renameTo(tracesFile);
        }
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
}
Also used : StrictMode(android.os.StrictMode) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) Time(android.text.format.Time) IOException(java.io.IOException) File(java.io.File)

Example 40 with Time

use of android.text.format.Time in project android_frameworks_base by ParanoidAndroid.

the class SyncManager method formatTime.

static String formatTime(long time) {
    Time tobj = new Time();
    tobj.set(time);
    return tobj.format("%Y-%m-%d %H:%M:%S");
}
Also used : Time(android.text.format.Time)

Aggregations

Time (android.text.format.Time)395 SmallTest (android.test.suitebuilder.annotation.SmallTest)97 Test (org.junit.Test)25 ArrayList (java.util.ArrayList)23 Date (java.util.Date)21 NetworkPolicy (android.net.NetworkPolicy)16 TrustedTime (android.util.TrustedTime)16 TextView (android.widget.TextView)15 Bundle (android.os.Bundle)13 TimeFormatException (android.util.TimeFormatException)13 Suppress (android.test.suitebuilder.annotation.Suppress)12 View (android.view.View)12 Paint (android.graphics.Paint)11 IOException (java.io.IOException)11 Matcher (java.util.regex.Matcher)9 IntentFilter (android.content.IntentFilter)7 File (java.io.File)7 DateFormat (java.text.DateFormat)7 SimpleDateFormat (java.text.SimpleDateFormat)7 ContentValues (android.content.ContentValues)6