Example usage for android.text.format Time Time

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

Introduction

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

Prototype

public Time() 

Source Link

Document

Construct a Time object in the default timezone.

Usage

From source file:org.smap.smapTask.android.activities.MainMapsActivity.java

private void formChooser(Intent intent, String instancePath) {
    String formPath = intent.getStringExtra(FormEntryActivity.KEY_FORMPATH);
    Intent i = null;/*from w w w.  j av a 2s .  com*/

    // Create the local task and get the task id as a string to pass to the form entry activity
    Time t = new Time();
    t.setToNow();
    long tid = -1;
    try {
        TaskAssignment ta = new TaskAssignment();
        /*
         * TODO Implement
        task.scheduledStart = t.toMillis(false);
        task.status = "open";
        task.taskForm = STFileUtils.getFileName(formPath);
        tid = mTda.createTask(-1, "local", null, task);
        */
    } catch (Exception e) {
        e.printStackTrace(); // TODO handle exception
    }

    i = new Intent("org.smap.smapTask.android.action.FormEntry");
    i.putExtra(FormEntryActivity.KEY_FORMPATH, formPath);
    i.putExtra(FormEntryActivity.KEY_TASK, tid);
    if (instancePath != null) {
        i.putExtra(FormEntryActivity.KEY_INSTANCEPATH, instancePath);
    }
    startActivity(i);
}

From source file:com.nadmm.airports.DownloadActivity.java

protected void cleanupExpiredData() {
    SQLiteDatabase catalogDb = mDbManager.getCatalogDb();

    Time now = new Time();
    now.setToNow();/*from   w w  w .j a  v a 2s .  co  m*/
    String today = now.format3339(true);

    Cursor c = mDbManager.getAllFromCatalog();
    if (c.moveToFirst()) {
        do {
            // Check and delete all the expired databases
            String end = c.getString(c.getColumnIndex(Catalog.END_DATE));
            if (end.compareTo(today) < 0) {
                // This database has expired, remove it
                Integer _id = c.getInt(c.getColumnIndex(Catalog._ID));
                String dbName = c.getString(c.getColumnIndex(Catalog.DB_NAME));
                File file = new File(DatabaseManager.DATABASE_DIR, dbName);
                if (catalogDb.isOpen() && file.delete()) {
                    // Now delete the catalog entry for the file
                    catalogDb.delete(Catalog.TABLE_NAME, Catalog._ID + "=?",
                            new String[] { Integer.toString(_id) });
                }
            }
        } while (c.moveToNext());
    }
    c.close();
}

From source file:com.towson.wavyleaf.Sighting.java

private void createJSONObject() {
    Time now = new Time();
    now.setToNow();// w  w w.j av a 2  s .  c  om
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    JSONObject sighting = new JSONObject();

    try {
        sighting.put(UploadData.ARG_USER_ID, sp.getString(Settings.KEY_USER_ID, "null"));
        sighting.put(UploadData.ARG_PERCENT, getSelectedToggleButton());
        sighting.put(UploadData.ARG_AREAVALUE, getAreaText());
        sighting.put(UploadData.ARG_AREATYPE, shortenAreaType());
        sighting.put(UploadData.ARG_LATITUDE, currentEditableLocation.getLatitude());
        sighting.put(UploadData.ARG_LONGITUDE, currentEditableLocation.getLongitude());
        sighting.put(UploadData.ARG_NOTES, notes.getText());
        sighting.put(UploadData.ARG_DATE, now.year + "-" + (now.month + 1) + "-" + now.monthDay + " " + now.hour
                + ":" + now.minute + ":" + now.second);
        sighting.put(UploadData.ARG_TREATMENT, sp_treatment.getSelectedItem().toString());

        if (!_64BitEncoding.equals("")) { // Picture was taken
            // Server should also check to see if this value is an empty string
            sighting.put(UploadData.ARG_PICTURE, _64BitEncoding);
        } else // No picture was taken
            sighting.put(UploadData.ARG_PICTURE, "null");

    } catch (JSONException e) {
        Toast.makeText(getApplicationContext(), "Data not saved, try again", Toast.LENGTH_SHORT).show();
    }

    new UploadData(this, UploadData.TASK_SUBMIT_POINT).execute(sighting);
}

From source file:com.yangtsaosoftware.pebblemessenger.services.MessageProcessingService.java

private Long addNewCall(String number, String name, String icon) {
    Time nowTime = new Time();
    nowTime.setToNow();/*from w w  w  . j a va 2  s .  c om*/
    return mdb.addCall(nowTime, number, name, icon);
}

From source file:com.android.calendar.AllInOneActivity.java

private void initFragments(long timeMillis, int viewType, Bundle icicle) {
    if (DEBUG) {/*  ww w . j  a v  a2s  .  c  o m*/
        Log.d(TAG, "Initializing to " + timeMillis + " for view " + viewType);
    }
    FragmentTransaction ft = getFragmentManager().beginTransaction();

    if (mShowCalendarControls) {
        Fragment miniMonthFrag = new MonthByWeekFragment(timeMillis, true);
        ft.replace(R.id.mini_month, miniMonthFrag);
        mController.registerEventHandler(R.id.mini_month, (EventHandler) miniMonthFrag);

        Fragment selectCalendarsFrag = new SelectVisibleCalendarsFragment();
        ft.replace(R.id.calendar_list, selectCalendarsFrag);
        mController.registerEventHandler(R.id.calendar_list, (EventHandler) selectCalendarsFrag);
    }
    if (!mShowCalendarControls || viewType == ViewType.EDIT) {
        mMiniMonth.setVisibility(View.GONE);
        mCalendarsList.setVisibility(View.GONE);
    }

    EventInfo info = null;
    if (viewType == ViewType.EDIT) {
        mPreviousView = GeneralPreferences.getSharedPreferences(this).getInt(GeneralPreferences.KEY_START_VIEW,
                GeneralPreferences.DEFAULT_START_VIEW);

        long eventId = -1;
        Intent intent = getIntent();
        Uri data = intent.getData();
        if (data != null) {
            try {
                eventId = Long.parseLong(data.getLastPathSegment());
            } catch (NumberFormatException e) {
                if (DEBUG) {
                    Log.d(TAG, "Create new event");
                }
            }
        } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) {
            eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID);
        }

        long begin = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, -1);
        long end = intent.getLongExtra(EXTRA_EVENT_END_TIME, -1);
        info = new EventInfo();
        if (end != -1) {
            info.endTime = new Time();
            info.endTime.set(end);
        }
        if (begin != -1) {
            info.startTime = new Time();
            info.startTime.set(begin);
        }
        info.id = eventId;
        // We set the viewtype so if the user presses back when they are
        // done editing the controller knows we were in the Edit Event
        // screen. Likewise for eventId
        mController.setViewType(viewType);
        mController.setEventId(eventId);
    } else {
        mPreviousView = viewType;
    }

    setMainPane(ft, R.id.main_pane, viewType, timeMillis, true);
    ft.commit(); // this needs to be after setMainPane()

    Time t = new Time(mTimeZone);
    t.set(timeMillis);
    if (viewType == ViewType.AGENDA && icicle != null) {
        mController.sendEvent(this, EventType.GO_TO, t, null, icicle.getLong(BUNDLE_KEY_EVENT_ID, -1),
                viewType);
    } else if (viewType != ViewType.EDIT) {
        mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
    }
}

From source file:com.yangtsaosoftware.pebblemessenger.services.MessageProcessingService.java

private Long addNewMessage(Bundle b, String icon) {
    Time nowTime = new Time();
    nowTime.setToNow();//  w  w  w  .j  a v a2 s .co  m
    return mdb.addMessage(nowTime, b.getString(MessageDbHandler.COL_MESSAGE_APP),
            b.getString(MessageDbHandler.COL_MESSAGE_CONTENT), icon);
}

From source file:ru.otdelit.astrid.opencrx.sync.OpencrxSyncProvider.java

/**
 * Transmit tags/* w w w. j  a  v a  2  s  .  co m*/
 *
 * @param local
 * @param remote
 * @param idTask
 * @param idDashboard
 * @throws ApiServiceException
 * @throws JSONException
 * @throws IOException
 */
private boolean transmitTags(OpencrxTaskContainer local, OpencrxTaskContainer remote)
        throws ApiServiceException, IOException {

    boolean transmitted = false;

    String activityId = local.pdvTask.getValue(OpencrxActivity.CRX_ID);

    if (TextUtils.isEmpty(activityId))
        return false;

    HashMap<String, OpencrxResourceAssignment> assignments = new HashMap<String, OpencrxResourceAssignment>();
    for (OpencrxResourceAssignment assignment : invoker.resourceAssignmentsShowForTask(activityId))
        assignments.put(assignment.getResourceId(), assignment);

    HashSet<String> localTags = new HashSet<String>();
    HashSet<String> remoteTags = new HashSet<String>();

    for (Metadata item : local.metadata)
        if (OpencrxDataService.TAG_KEY.equals(item.getValue(Metadata.KEY)))
            localTags.add(item.getValue(OpencrxDataService.TAG));

    if (remote != null && remote.metadata != null)
        for (Metadata item : remote.metadata)
            if (OpencrxDataService.TAG_KEY.equals(item.getValue(Metadata.KEY)))
                remoteTags.add(item.getValue(OpencrxDataService.TAG));

    if (!localTags.equals(remoteTags)) {

        for (String label : localTags) {
            if (labelMap.containsKey(label) && !remoteTags.contains(label)) {
                String resourceId = labelMap.get(label);

                try {
                    invoker.taskAssignResource(activityId, resourceId);
                } catch (ApiServiceException ex) {
                    // Possible internal server error if resource is bad formed - ignore it
                }

                transmitted = true;
            }
        }

        for (String label : remoteTags) {
            if (labelMap.containsKey(label) && !localTags.contains(label)) {
                String resourceId = labelMap.get(label);

                OpencrxResourceAssignment assignment = assignments.get(resourceId);

                if (assignment == null || assignment.getAssignmentDate() == null)
                    continue;

                Time assignTime = new Time();
                assignTime.set(assignment.getAssignmentDate().getTime());

                if (lastSync.after(assignTime)) {
                    try {
                        invoker.resourceAssignmentDelete(activityId, assignment.getAssignmentId());
                    } catch (IOException ex) {
                        // Possible internal server error if we don't have rights to delete this - ignore it
                    }
                }
            }
        }
    }

    return transmitted;
}

From source file:com.a.mirko.android.datetimepicker.time.RadialPickerLayout.java

/**
 * Announce the currently-selected time when launched.
 *//*w w w .  ja  v a2  s  . c o m*/
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        // Clear the event's current text so that only the current time will be spoken.
        event.getText().clear();
        Time time = new Time();
        time.hour = getHours();
        time.minute = getMinutes();
        long millis = time.normalize(true);
        int flags = DateUtils.FORMAT_SHOW_TIME;
        if (mIs24HourMode) {
            flags |= DateUtils.FORMAT_24HOUR;
        }
        String timeString = DateUtils.formatDateTime(getContext(), millis, flags);
        event.getText().add(timeString);
        return true;
    }
    return super.dispatchPopulateAccessibilityEvent(event);
}

From source file:com.redinput.datetimepickercompat.time.RadialPickerLayout.java

private void installAccessibilityDelegate() {
    // The accessibility delegate enables customizing accessibility behavior
    // via composition as opposed as inheritance. The main benefit is that
    // one can write a backwards compatible application by setting the delegate
    // only if the API level is high enough i.e. the delegate is part of the APIs.
    // The easiest way to achieve that is by using the support library which
    // takes the burden of checking API version and knowing which API version
    // introduced the delegate off the developer.
    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegateCompat() {

        @Override/*w  w  w  . j av a 2s .c o m*/
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
            super.onInitializeAccessibilityNodeInfo(host, info);
            // Note that View.onInitializeAccessibilityNodeInfo was introduced in
            // ICS and we would like to tweak a bit the text that is reported to
            // accessibility services via the AccessibilityNodeInfo.
            info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD);
            info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD);
        }

        @Override
        public boolean dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
            if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
                // Clear the event's current text so that only the current time will be spoken.
                event.getText().clear();
                Time time = new Time();
                time.hour = getHours();
                time.minute = getMinutes();
                long millis = time.normalize(true);
                int flags = DateUtils.FORMAT_SHOW_TIME;
                if (mIs24HourMode) {
                    flags |= DateUtils.FORMAT_24HOUR;
                }
                String timeString = DateUtils.formatDateTime(getContext(), millis, flags);
                event.getText().add(timeString);
                return true;
            }

            return super.dispatchPopulateAccessibilityEvent(host, event);
        }

        @Override
        public boolean performAccessibilityAction(View host, int action, Bundle args) {
            if (super.performAccessibilityAction(host, action, args)) {
                return true;
            }

            int changeMultiplier = 0;
            if (action == AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD) {
                changeMultiplier = 1;
            } else if (action == AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD) {
                changeMultiplier = -1;
            }
            if (changeMultiplier != 0) {
                int value = getCurrentlyShowingValue();
                int stepSize = 0;
                int currentItemShowing = getCurrentItemShowing();
                if (currentItemShowing == HOUR_INDEX) {
                    stepSize = HOUR_VALUE_TO_DEGREES_STEP_SIZE;
                    value %= 12;
                } else if (currentItemShowing == MINUTE_INDEX) {
                    stepSize = MINUTE_VALUE_TO_DEGREES_STEP_SIZE;
                }

                int degrees = value * stepSize;
                degrees = snapOnly30s(degrees, changeMultiplier);
                value = degrees / stepSize;
                int maxValue = 0;
                int minValue = 0;
                if (currentItemShowing == HOUR_INDEX) {
                    if (mIs24HourMode) {
                        maxValue = 23;
                    } else {
                        maxValue = 12;
                        minValue = 1;
                    }
                } else {
                    maxValue = 55;
                }
                if (value > maxValue) {
                    // If we scrolled forward past the highest number, wrap around to the
                    // lowest.
                    value = minValue;
                } else if (value < minValue) {
                    // If we scrolled backward past the lowest number, wrap around to the
                    // highest.
                    value = maxValue;
                }
                setItem(currentItemShowing, value);
                mListener.onValueSelected(currentItemShowing, value, false);
                return true;
            }

            return false;
        }
    });
}

From source file:de.ribeiro.android.gso.dataclasses.Pager.java

/**
 * * Erzeugt aus dem WeekData-Objekt eine List aus TimeTableViewObject
 *
 * @param weekData//  ww w .j a v a2s .c o m
 * @param currentDay
 * @return
 * @author Tobias Janssen
 */
private List<TimetableViewObject> createTimetableDayViewObject(WeekData weekData, Calendar currentDay) {

    List<TimetableViewObject> result = new ArrayList<TimetableViewObject>();

    List<Lesson> schulstunden = GetSchulstunden();

    currentDay.setTimeZone(TimeZone.getTimeZone("UTC"));

    // leeren Stundenplan erstellen
    for (int std = 0; std < schulstunden.size(); std++) {
        result.add(new TimetableViewObject(timeslots[std + 1], "", "#000000"));
    }
    boolean nothingAdded = true;
    // alle events durchgehen
    for (int i = 0; i < weekData.events.size(); i++) {
        ICalEvent event = weekData.events.get(i);
        // prfen, ob event im gewnschten Jahr und tag ist
        if (event.DTSTART.get(Calendar.YEAR) == currentDay.get(Calendar.YEAR)
                && event.DTSTART.get(Calendar.DAY_OF_YEAR) == currentDay.get(Calendar.DAY_OF_YEAR)) {
            // ja, dann schulstunde des events herausfinden
            Time st = new Time();
            st.set(event.DTSTART.getTimeInMillis());
            int start = GetSchulstundeOfDateTime(st);
            Time et = new Time();
            et.set(event.DTEND.getTimeInMillis() - 60000);
            int end = GetSchulstundeOfDateTime(et);
            // ende der schulstunde herausfinden

            if (start != -1) {
                for (int h = start; h <= end; h++) {
                    nothingAdded = false;
                    if (result.get(h).row2 == "") {
                        if (event.UID.equalsIgnoreCase("deleted")) {
                            result.set(h, new TimetableViewObject(timeslots[h + 1], "---" + " --- " + " --- ",
                                    "#FF0000"));
                        } else {
                            String color = "#000000";
                            if (event.UID.equalsIgnoreCase("diff"))
                                color = "#FF0000";
                            if (weekData.typeId.equalsIgnoreCase("4")) {
                                result.set(h, new TimetableViewObject(timeslots[h + 1],
                                        event.DESCRIPTION + " " + event.SUMMARY, color));
                            } else {
                                result.set(h,
                                        new TimetableViewObject(timeslots[h + 1],
                                                event.DESCRIPTION.replace(weekData.elementId, "") + " "
                                                        + event.SUMMARY + " " + event.LOCATION,
                                                color));
                            }
                        }
                    } else {
                        // Stundendoppelbelegung

                        if (weekData.typeId.equalsIgnoreCase("4")) {
                            result.get(h).row2 += "\r\n" + event.DESCRIPTION + " " + event.SUMMARY + " ";
                        } else {
                            result.get(h).row2 += "\r\n" + event.DESCRIPTION.replace(weekData.elementId, "")
                                    + " " + event.SUMMARY + " " + event.LOCATION;
                        }
                    }
                }
            } else
                _logger.Error("No matching lesson hour  for event found " + event.DTSTART.getTime());
        }
    }

    if (hideEmptyHours) {
        int i = 0;
        boolean done = false;
        while (!done) {
            if (i < result.size()) {
                if (result.get(i).row2.equalsIgnoreCase("")) {
                    result.remove(i);
                } else {
                    i++;
                }
            } else
                done = true;

        }
    }

    // prfen, ob gar keine Stunden vorhanden sind
    if (nothingAdded) {
        result.clear();
        result.add(new TimetableViewObject("", "kein Unterricht", "#000000"));
    }

    return result;
}