Search in sources :

Example 91 with Time

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

the class DropBoxManagerService method dump.

public synchronized void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    if (getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) {
        pw.println("Permission Denial: Can't dump DropBoxManagerService");
        return;
    }
    try {
        init();
    } catch (IOException e) {
        pw.println("Can't initialize: " + e);
        Slog.e(TAG, "Can't init", e);
        return;
    }
    if (PROFILE_DUMP)
        Debug.startMethodTracing("/data/trace/dropbox.dump");
    StringBuilder out = new StringBuilder();
    boolean doPrint = false, doFile = false;
    ArrayList<String> searchArgs = new ArrayList<String>();
    for (int i = 0; args != null && i < args.length; i++) {
        if (args[i].equals("-p") || args[i].equals("--print")) {
            doPrint = true;
        } else if (args[i].equals("-f") || args[i].equals("--file")) {
            doFile = true;
        } else if (args[i].startsWith("-")) {
            out.append("Unknown argument: ").append(args[i]).append("\n");
        } else {
            searchArgs.add(args[i]);
        }
    }
    out.append("Drop box contents: ").append(mAllFiles.contents.size()).append(" entries\n");
    if (!searchArgs.isEmpty()) {
        out.append("Searching for:");
        for (String a : searchArgs) out.append(" ").append(a);
        out.append("\n");
    }
    int numFound = 0, numArgs = searchArgs.size();
    Time time = new Time();
    out.append("\n");
    for (EntryFile entry : mAllFiles.contents) {
        time.set(entry.timestampMillis);
        String date = time.format("%Y-%m-%d %H:%M:%S");
        boolean match = true;
        for (int i = 0; i < numArgs && match; i++) {
            String arg = searchArgs.get(i);
            match = (date.contains(arg) || arg.equals(entry.tag));
        }
        if (!match)
            continue;
        numFound++;
        if (doPrint)
            out.append("========================================\n");
        out.append(date).append(" ").append(entry.tag == null ? "(no tag)" : entry.tag);
        if (entry.file == null) {
            out.append(" (no file)\n");
            continue;
        } else if ((entry.flags & DropBoxManager.IS_EMPTY) != 0) {
            out.append(" (contents lost)\n");
            continue;
        } else {
            out.append(" (");
            if ((entry.flags & DropBoxManager.IS_GZIPPED) != 0)
                out.append("compressed ");
            out.append((entry.flags & DropBoxManager.IS_TEXT) != 0 ? "text" : "data");
            out.append(", ").append(entry.file.length()).append(" bytes)\n");
        }
        if (doFile || (doPrint && (entry.flags & DropBoxManager.IS_TEXT) == 0)) {
            if (!doPrint)
                out.append("    ");
            out.append(entry.file.getPath()).append("\n");
        }
        if ((entry.flags & DropBoxManager.IS_TEXT) != 0 && (doPrint || !doFile)) {
            DropBoxManager.Entry dbe = null;
            InputStreamReader isr = null;
            try {
                dbe = new DropBoxManager.Entry(entry.tag, entry.timestampMillis, entry.file, entry.flags);
                if (doPrint) {
                    isr = new InputStreamReader(dbe.getInputStream());
                    char[] buf = new char[4096];
                    boolean newline = false;
                    for (; ; ) {
                        int n = isr.read(buf);
                        if (n <= 0)
                            break;
                        out.append(buf, 0, n);
                        newline = (buf[n - 1] == '\n');
                        // Flush periodically when printing to avoid out-of-memory.
                        if (out.length() > 65536) {
                            pw.write(out.toString());
                            out.setLength(0);
                        }
                    }
                    if (!newline)
                        out.append("\n");
                } else {
                    String text = dbe.getText(70);
                    out.append("    ");
                    if (text == null) {
                        out.append("[null]");
                    } else {
                        boolean truncated = (text.length() == 70);
                        out.append(text.trim().replace('\n', '/'));
                        if (truncated)
                            out.append(" ...");
                    }
                    out.append("\n");
                }
            } catch (IOException e) {
                out.append("*** ").append(e.toString()).append("\n");
                Slog.e(TAG, "Can't read: " + entry.file, e);
            } finally {
                if (dbe != null)
                    dbe.close();
                if (isr != null) {
                    try {
                        isr.close();
                    } catch (IOException unused) {
                    }
                }
            }
        }
        if (doPrint)
            out.append("\n");
    }
    if (numFound == 0)
        out.append("(No entries found.)\n");
    if (args == null || args.length == 0) {
        if (!doPrint)
            out.append("\n");
        out.append("Usage: dumpsys dropbox [--print|--file] [YYYY-mm-dd] [HH:MM:SS] [tag]\n");
    }
    pw.write(out.toString());
    if (PROFILE_DUMP)
        Debug.stopMethodTracing();
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) Time(android.text.format.Time) IOException(java.io.IOException) DropBoxManager(android.os.DropBoxManager)

Example 92 with Time

use of android.text.format.Time in project MaterialCalendar by Haoxiqiang.

the class WeatherProxy method getTodayWeather.

public static Weather getTodayWeather() {
    Time time = new Time();
    time.setToNow();
    int month = time.month + 1;
    String todayDate = String.valueOf(time.year) + String.valueOf(month < 10 ? "0" + month : month) + String.valueOf(time.monthDay < 10 ? "0" + time.monthDay : time.monthDay);
    return getWeatherByDate(todayDate);
}
Also used : Time(android.text.format.Time)

Example 93 with Time

use of android.text.format.Time in project MaterialCalendar by Haoxiqiang.

the class CalendarFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
    sensibility = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, displayMetrics);
    Time time = new Time();
    time.setToNow();
    year_c = time.year;
    month_c = time.month + 1;
    gestureDetector = new GestureDetector(this.getActivity(), new MyGestureListener());
    mFlipper.removeAllViews();
    calV = new CalendarAdapter(this.getActivity(), jumpMonth, year_c, month_c);
    addGridView();
    gridView.setAdapter(calV);
    mFlipper.addView(gridView, 0);
    addTextToTopTextView();
    setWeatherValue();
    setTodayLunarInfo(calV.getSysDay());
}
Also used : CalendarAdapter(info.hxq.materialcalendar.tool.CalendarAdapter) Time(android.text.format.Time) GestureDetector(android.view.GestureDetector) DisplayMetrics(android.util.DisplayMetrics)

Example 94 with Time

use of android.text.format.Time in project MaterialCalendar by Haoxiqiang.

the class MemoProxy method getTodayMemo.

public static ArrayList<Memo> getTodayMemo() {
    Time time = new Time();
    time.setToNow();
    int month = time.month + 1;
    String todayDate = String.valueOf(time.year) + String.valueOf(month < 10 ? "0" + month : month) + String.valueOf(time.monthDay);
    return getMemoByDate(todayDate);
}
Also used : Time(android.text.format.Time)

Example 95 with Time

use of android.text.format.Time in project MaterialCalendar by Haoxiqiang.

the class TabooProxy method getTodayTaboo.

public static Taboo getTodayTaboo() {
    Time time = new Time();
    time.setToNow();
    int month = time.month + 1;
    String todayDate = String.valueOf(time.year) + String.valueOf(month < 10 ? "0" + month : month) + String.valueOf(time.monthDay);
    return getTabooByDate(todayDate);
}
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