Example usage for android.text.format Time format

List of usage examples for android.text.format Time format

Introduction

In this page you can find the example usage for android.text.format Time format.

Prototype

public String format(String format) 

Source Link

Document

Print the current value given the format string provided.

Usage

From source file:com.election.US.basicsyncadapter.EntryListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    mAdapter = new SimpleCursorAdapter(getActivity(), // Current context
            android.R.layout.simple_list_item_activated_2, // Layout for individual rows
            null, // Cursor
            FROM_COLUMNS, // Cursor columns to use
            TO_FIELDS, // Layout fields to use
            0 // No flags
    );//from  ww  w  .  j  a  va 2 s  .com
    mAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int i) {
            if (i == COLUMN_PUBLISHED) {
                // Convert timestamp to human-readable date
                Time t = new Time();
                t.set(cursor.getLong(i));
                ((TextView) view).setText(t.format("%Y-%m-%d %H:%M"));
                return true;
            } else {
                // Let SimpleCursorAdapter handle other fields automatically
                return false;
            }
        }
    });
    setListAdapter(mAdapter);
    setEmptyText(getText(R.string.loading));
    getLoaderManager().initLoader(0, null, this);
}

From source file:uk.org.openseizuredetector.OsdUtil.java

/**
 * Write data to SD card - writes to data log file unless alarm=true,
 * in which case writes to alarm log file.
 *//*from w w  w.  j  a  v a 2  s.co m*/
public void writeToLogFile(String fname, String msgStr) {
    Log.v(TAG, "writeToLogFile(" + fname + "," + msgStr + ")");
    //showToast("Logging " + msgStr);
    Time tnow = new Time(Time.getCurrentTimezone());
    tnow.setToNow();
    String dateStr = tnow.format("%Y-%m-%d");

    fname = fname + "_" + dateStr + ".txt";
    // Open output directory on SD Card.
    if (isExternalStorageWritable()) {
        try {
            FileWriter of = new FileWriter(getDataStorageDir().toString() + "/" + fname, true);
            if (msgStr != null) {
                String dateTimeStr = tnow.format("%Y-%m-%d %H:%M:%S");
                Log.v(TAG, "writing msgStr");
                of.append(dateTimeStr + ", " + tnow.toMillis(true) + ", " + msgStr + "<br/>\n");
            }
            of.close();
        } catch (Exception ex) {
            Log.e(TAG, "writeToLogFile - error " + ex.toString());
            showToast("ERROR Writing to Log File");
        }
    } else {
        Log.e(TAG, "ERROR - Can not Write to External Folder");
    }
}

From source file:securityantennas.viwer.android.mogaworks.securityantenna.FeedListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    int loader_id = getArguments().getInt(ARG_SECTION_NUMBER);
    mAdapter = new SimpleCursorAdapter(getActivity(), // Current context
            android.R.layout.simple_list_item_activated_2, // Layout for individual rows
            null, // Cursor
            FROM_COLUMNS, // Cursor columns to use
            TO_FIELDS, // Layout fields to use
            0 // No flags
    );/*ww w.j a va 2  s.  co  m*/
    mAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int i) {
            if (i == COLUMN_PUBLISHED) {
                // Convert timestamp to human-readable date
                Time t = new Time();
                t.set(cursor.getLong(i));
                ((TextView) view).setText(t.format("%Y-%m-%d %H:%M"));
                return true;
            } else {
                // Let SimpleCursorAdapter handle other fields automatically
                return false;
            }
        }
    });
    setListAdapter(mAdapter);
    setEmptyText(getText(R.string.loading));
    getLoaderManager().initLoader(loader_id, null, this);
}

From source file:ftrimble.kingme.device.file.KingMeGPX.java

/**
 * Adds whatever metadata we're given.//from   ww w.j a va  2 s  .  co m
 */
private void addMetaData(Time time) throws IOException {
    StringBuilder sb = new StringBuilder();

    sb.append(addNewLine());

    sb.append("<metadata>");
    ++mIndentLevel;

    sb.append(addNewLine());

    sb.append("<time>");
    sb.append(time.format("%FT%TZ"));
    sb.append("</time>");
    --mIndentLevel;

    sb.append(addNewLine());

    sb.append("</metadata>");

    mOut.write(sb.toString(), 0, sb.toString().length());
}

From source file:com.example.android.basicsyncadapter.FeedListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    mListView = (ListView) view.findViewById(R.id.list_view);
    mEmpty = view.findViewById(R.id.empty);

    mAdapter = new SimpleCursorAdapter(getActivity(), // Current context
            R.layout.list_item, // Layout for individual rows
            null, // Cursor
            new String[] { // Cursor columns to use
                    FeedContract.Entry.COLUMN_NAME_TITLE, FeedContract.Entry.COLUMN_NAME_PUBLISHED },
            new int[] { // Layout fields to use
                    R.id.title, R.id.date },
            0 // No flags
    );//  w w  w  . j  a v  a2 s.  c  om
    mAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int i) {
            if (i == COLUMN_PUBLISHED) {
                // Convert timestamp to human-readable date
                Time t = new Time();
                t.set(cursor.getLong(i));
                ((TextView) view).setText(t.format("%Y-%m-%d %H:%M"));
                return true;
            } else {
                // Let SimpleCursorAdapter handle other fields automatically
                return false;
            }
        }
    });

    mListView.setAdapter(mAdapter);
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // Load an article in the default browser when selected by the user.

            // Get a URI for the selected item, then start an Activity that displays the URI. Any
            // Activity that filters for ACTION_VIEW and a URI can accept this. In most cases, this will
            // be a browser.

            // Get the item at the selected position, in the form of a Cursor.
            Cursor c = (Cursor) mAdapter.getItem(position);
            // Get the link to the article represented by the item.
            String articleUrlString = c.getString(COLUMN_URL_STRING);
            if (articleUrlString == null) {
                Log.e(TAG, "Attempt to launch entry with null link");
                return;
            }

            Log.i(TAG, "Opening URL: " + articleUrlString);
            // Get a Uri object for the URL string
            Uri articleURL = Uri.parse(articleUrlString);
            Intent i = new Intent(Intent.ACTION_VIEW, articleURL);
            startActivity(i);
        }
    });

    getLoaderManager().initLoader(0, null, this);
}

From source file:ti.android.ble.devicemonitor.ServiceView.java

private String timeNowStr() {
    Time now = new Time(Time.getCurrentTimezone());
    now.setToNow();/*from ww w  . ja v  a2  s.c om*/
    return now.format("%k:%M:%S") + ": ";
}

From source file:gl.iglou.scenegraph.MatModeInterface.java

public void SaveSnapshot(View v) {

    snapshotIndicator.setVisibility(View.VISIBLE);

    new Thread() {
        public void run() {
            try {
                String iconsStoragePath = Environment.getExternalStorageDirectory() + "/SCENEGRAPH/Snapshots/";
                File sdIconStorageDir = new File(iconsStoragePath);
                Time now = new Time();
                now.setToNow();//  w w w.j a v a 2s.  co  m
                String pic_name = SceneData.GetSceneName() + "_" + now.format("%Y_%m_%d_%H_%M_%S");

                //create storage directories, if they don't exist
                sdIconStorageDir.mkdirs();
                String path = sdIconStorageDir.toString() + "/" + pic_name + ".png";

                try {

                    FileOutputStream fileOutputStream = new FileOutputStream(path);

                    BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);

                    //choose another format if PNG doesn't suit you
                    GLView.mBitmap.compress(CompressFormat.PNG, 100, bos);

                    bos.flush();
                    bos.close();

                    snapshotToast.setText(path);
                    snapshotToast.show();

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            HideSnapshot();
                        }
                    });

                } catch (FileNotFoundException e) {
                    Log.w("TAG", "Error saving image file: " + e.getMessage());
                } catch (IOException e) {
                    Log.w("TAG", "Error saving image file: " + e.getMessage());
                }
            } catch (Exception e) {
                Log.w("TAG", "Error saving image file: " + e.getMessage());
            }

        }
    }.start();
}

From source file:com.intel.RtcPingDownloadTester.java

private void update_conole_writeln(String line) {
    Time today = new Time(Time.getCurrentTimezone());
    today.setToNow();/* w ww  . j a  v  a2 s  . com*/
    if (full_lines >= 10) {
        full_lines = 0;
        string_console_text = "";
    }
    full_lines++;
    string_console_text += today.format("%k:%M:%S") + ": " + line + "\n";
    label_console_box.setText(string_console_text);
}

From source file:pt.up.mobile.syncadapter.SigarraSyncAdapter.java

private void syncSchedule(Account account, SyncResult syncResult)
        throws JSONException, AuthenticationException, IOException {
    final User user = AccountUtils.getUser(getContext(), account.name);
    final String type;
    if (user.getType().equals(SifeupAPI.STUDENT_TYPE))
        type = SigarraContract.Schedule.STUDENT;
    else//from   w  w  w  .  ja v a  2  s . com
        type = SigarraContract.Schedule.EMPLOYEE;
    final Long mondayMillis = DateUtils.firstDayofWeek();
    Time monday = new Time(DateUtils.TIME_REFERENCE);
    monday.set(mondayMillis);
    monday.normalize(false);
    String initialDay = monday.format("%Y%m%d");
    // Friday
    monday.set(DateUtils.moveDayofWeek(mondayMillis, 4));
    monday.normalize(false);
    String finalDay = monday.format("%Y%m%d");
    getSchedule(account, user.getUserCode(), type, initialDay, finalDay, SyncStates.KEEP, syncResult);
}

From source file:ftrimble.kingme.device.file.KingMeGPX.java

/**
 * Adds data about a specific point in a course.
 *//*from w  w w .  j  a v a 2  s  .  co m*/
public void addPoint(Location location, Time time) {
    if (location == null)
        System.out.println("Received a null location");
    StringBuilder sb = new StringBuilder();

    sb.append(addNewLine());
    sb.append("<trkpt lat=\"");
    sb.append(location.getLatitude());
    sb.append("\" lon=\"");
    sb.append(location.getLongitude());
    sb.append("\">");
    ++mIndentLevel;

    sb.append(addNewLine());

    sb.append("<ele>");
    // TODO calculate location more accurately;
    // perhaps using a web service
    sb.append(location.getAltitude());
    sb.append("</ele>");

    sb.append(addNewLine());

    sb.append("<time>");
    sb.append(time.format("%FT%TZ"));
    sb.append("</time>");
    --mIndentLevel;

    sb.append(addNewLine());

    sb.append("</trkpt>");

    try {
        mOut.write(sb.toString(), 0, sb.toString().length());
    } catch (IOException ioe) {
        Log.d("KingMeGPX", "Could not write to GPX file.");
    }
}