Example usage for android.text.format Time getCurrentTimezone

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

Introduction

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

Prototype

public static String getCurrentTimezone() 

Source Link

Document

Returns the timezone string that is currently set for the device.

Usage

From source file:com.google.android.apps.santatracker.village.Village.java

private boolean initialiseSunMoon() {
    boolean isDay = false;
    sunOffset = mViewHeight;/*from  w  w w . j av a2  s. com*/
    moonOffset = 0;
    // 6am till 6pm is considered day time;
    Time today = new Time(Time.getCurrentTimezone());
    today.setToNow();
    if (today.hour >= 6 || today.hour < 18) {
        isDay = true;
        sunOffset = 0;
        moonOffset = -mViewHeight;
    }
    return isDay;
}

From source file:com.android.datetimepicker.date.MonthView.java

/**
 * Sets all the parameters for displaying this week. The only required
 * parameter is the week number. Other parameters have a default value and
 * will only update if a new value is included, except for focus month,
 * which will always default to no focus month if no value is passed in. See
 * {@link #VIEW_PARAMS_HEIGHT} for more info on parameters.
 *
 * @param params A map of the new parameters, see
 *            {@link #VIEW_PARAMS_HEIGHT}
 *//*from  w  w  w. ja  va2s.com*/
public void setMonthParams(HashMap<String, Integer> params) {
    if (!params.containsKey(VIEW_PARAMS_MONTH) && !params.containsKey(VIEW_PARAMS_YEAR)) {
        throw new InvalidParameterException("You must specify month and year for this view");
    }
    setTag(params);
    // We keep the current value for any params not present
    if (params.containsKey(VIEW_PARAMS_HEIGHT)) {
        mRowHeight = params.get(VIEW_PARAMS_HEIGHT);
        if (mRowHeight < MIN_HEIGHT) {
            mRowHeight = MIN_HEIGHT;
        }
    }
    if (params.containsKey(VIEW_PARAMS_SELECTED_DAY)) {
        mSelectedDay = params.get(VIEW_PARAMS_SELECTED_DAY);
    }

    // Allocate space for caching the day numbers and focus values
    mMonth = params.get(VIEW_PARAMS_MONTH);
    mYear = params.get(VIEW_PARAMS_YEAR);

    // Figure out what day today is
    final Time today = new Time(Time.getCurrentTimezone());
    today.setToNow();
    mHasToday = false;
    mToday = -1;

    mCalendar.set(Calendar.MONTH, mMonth);
    mCalendar.set(Calendar.YEAR, mYear);
    mCalendar.set(Calendar.DAY_OF_MONTH, 1);
    mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK);

    if (params.containsKey(VIEW_PARAMS_WEEK_START)) {
        mWeekStart = params.get(VIEW_PARAMS_WEEK_START);
    } else {
        mWeekStart = mCalendar.getFirstDayOfWeek();
    }

    mNumCells = Utils.getDaysInMonth(mMonth, mYear);
    for (int i = 0; i < mNumCells; i++) {
        final int day = i + 1;
        if (sameDay(day, today)) {
            mHasToday = true;
            mToday = day;
        }
    }
    mNumRows = calculateNumRows();

    // Invalidate cached accessibility information.
    mTouchHelper.invalidateRoot();
}

From source file:org.holoeverywhere.widget.datetimepicker.date.SimpleMonthView.java

private String getMonthAndYearString() {
    int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NO_MONTH_DAY;
    mStringBuilder.setLength(0);/*  w  ww  . j  a  v a2  s  .  c  o  m*/
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        long millis = mCalendar.getTimeInMillis();
        return DateUtils
                .formatDateRange(getContext(), mFormatter, millis, millis, flags, Time.getCurrentTimezone())
                .toString();
    } else {
        if (mMonthAndYearFormatter == null) {
            mMonthAndYearFormatter = new SimpleDateFormat("MMMM yyyy", Locale.getDefault());
            mMonthAndYearFormatter.setTimeZone(TimeZone.getDefault());
        }
        return mMonthAndYearFormatter.format(mCalendar.getTime());
    }
}

From source file:com.appsimobile.appsii.module.appsiagenda.MonthView.java

/**
 * Sets all the parameters for displaying this week. The only required
 * parameter is the week number. Other parameters have a default value and
 * will only update if a new value is included, except for focus month,
 * which will always default to no focus month if no value is passed in. See
 * {@link #VIEW_PARAMS_HEIGHT} for more info on parameters.
 *
 * @param params A map of the new parameters, see
 * {@link #VIEW_PARAMS_HEIGHT}//w  w  w  .ja v  a  2  s.  c  om
 */
public void setMonthParams(SimpleArrayMap<String, Integer> params) {
    if (!params.containsKey(VIEW_PARAMS_MONTH) && !params.containsKey(VIEW_PARAMS_YEAR)) {
        throw new InvalidParameterException("You must specify month and year for this view");
    }
    setTag(params);
    // We keep the current value for any params not present
    if (params.containsKey(VIEW_PARAMS_HEIGHT)) {
        mRowHeight = params.get(VIEW_PARAMS_HEIGHT);
        if (mRowHeight < MIN_HEIGHT) {
            mRowHeight = MIN_HEIGHT;
        }
    }
    if (params.containsKey(VIEW_PARAMS_SELECTED_DAY)) {
        mSelectedDay = params.get(VIEW_PARAMS_SELECTED_DAY);
    }

    mStartJulianDay = params.get(VIEW_PARAMS_START_JULIAN_DAY);

    // Allocate space for caching the day numbers and focus values
    mMonth = params.get(VIEW_PARAMS_MONTH);
    mYear = params.get(VIEW_PARAMS_YEAR);

    // Figure out what day today is
    final Time today = new Time(Time.getCurrentTimezone());
    today.setToNow();
    mHasToday = false;
    mToday = -1;

    mCalendar.set(Calendar.MONTH, mMonth);
    mCalendar.set(Calendar.YEAR, mYear);
    mCalendar.set(Calendar.DAY_OF_MONTH, 1);
    mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK);

    if (params.containsKey(VIEW_PARAMS_WEEK_START)) {
        mWeekStart = params.get(VIEW_PARAMS_WEEK_START);
    } else {
        mWeekStart = mCalendar.getFirstDayOfWeek();
    }

    mNumCells = Utils.getDaysInMonth(mMonth, mYear);
    for (int i = 0; i < mNumCells; i++) {
        final int day = i + 1;
        if (sameDay(day, today)) {
            mHasToday = true;
            mToday = day;
        }
    }
    mNumRows = calculateNumRows();

    // Invalidate cached accessibility information.
    mTouchHelper.invalidateRoot();
}

From source file:app.android.datetimepicker.date.SimpleMonthView.java

private String getMonthAndYearString() {
    int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NO_MONTH_DAY;
    mStringBuilder.setLength(0);//  w  ww  .j av  a2  s .  c  o m
    long millis = mCalendar.getTimeInMillis();
    return DateUtils.formatDateRange(getContext(), mFormatter, millis, millis, flags, Time.getCurrentTimezone())
            .toString();
}

From source file:io.n7.calendar.caldav.CalDAVService.java

private void doSyncCalendar(Account acc, long calid) throws Exception {
    // Get a list of local events
    String[] evproj1 = new String[] { Events._ID, Events._SYNC_ID, Events.DELETED, Events._SYNC_DIRTY };
    HashMap<String, Long> localevs = new HashMap<String, Long>();
    HashMap<String, Long> removedevs = new HashMap<String, Long>();
    HashMap<String, Long> dirtyevs = new HashMap<String, Long>();
    HashMap<String, Long> newdevevs = new HashMap<String, Long>();

    Cursor c = mCR.query(EVENTS_URI, evproj1, Events.CALENDAR_ID + "=" + calid, null, null);

    long tid;/*from  ww w.j  a v a 2  s  . c  om*/
    String tuid = null;
    if (c.moveToFirst()) {
        do {
            tid = c.getLong(0);
            tuid = c.getString(1);

            if (c.getInt(2) != 0)
                removedevs.put(tuid, tid);
            else if (tuid == null) {
                // generate a UUID
                tuid = UUID.randomUUID().toString();
                newdevevs.put(tuid, tid);
            } else if (c.getInt(3) != 0)
                dirtyevs.put(tuid, tid);
            else
                localevs.put(tuid, tid);
        } while (c.moveToNext());
        c.close();
    }

    CalDAV4jIf caldavif = new CalDAV4jIf(getAssets());
    caldavif.setCredentials(new CaldavCredential(acc.getProtocol(), acc.getHost(), acc.getPort(), acc.getHome(),
            acc.getCollection(), acc.getUser(), acc.getPassword()));

    //add new device events to server
    for (String uid : newdevevs.keySet())
        addEventOnServer(uid, newdevevs.get(uid), caldavif);
    //delete the locally removed events on server
    for (String uid : removedevs.keySet()) {
        removeEventOnServer(uid, caldavif);
        // clean up provider DB?
        removeLocalEvent(removedevs.get(uid));
    }

    //update the dirty events on server
    for (String uid : dirtyevs.keySet())
        updateEventOnServer(uid, dirtyevs.get(uid), caldavif);

    // Get events from server
    VEvent[] evs = caldavif.getEvents();

    // add/update to provider DB
    String[] evproj = new String[] { Events._ID };
    ContentValues cv = new ContentValues();
    String temp, durstr = null;
    for (VEvent v : evs) {
        cv.clear();
        durstr = null;

        String uid = ICalendarUtils.getUIDValue(v);
        // XXX Some times the server seem to return the deleted event if we do get events immediately
        // after removing..
        // So ignore the possibility of deleted event on server was modified on server, for now.
        if (removedevs.containsKey(uid))
            continue;

        //TODO: put etag here
        cv.put(Events._SYNC_ID, uid);
        //UUID
        cv.put(Events._SYNC_DATA, uid);

        cv.put(Events.CALENDAR_ID, calid);
        cv.put(Events.TITLE, ICalendarUtils.getSummaryValue(v));
        cv.put(Events.DESCRIPTION, ICalendarUtils.getPropertyValue(v, Property.DESCRIPTION));
        cv.put(Events.EVENT_LOCATION, ICalendarUtils.getPropertyValue(v, Property.LOCATION));
        String tzid = ICalendarUtils.getPropertyValue(v, Property.TZID);
        if (tzid == null)
            tzid = Time.getCurrentTimezone();
        cv.put(Events.EVENT_TIMEZONE, tzid);
        long dtstart = parseDateTimeToMillis(ICalendarUtils.getPropertyValue(v, Property.DTSTART), tzid);
        cv.put(Events.DTSTART, dtstart);

        temp = ICalendarUtils.getPropertyValue(v, Property.DTEND);
        if (temp != null)
            cv.put(Events.DTEND, parseDateTimeToMillis(temp, tzid));
        else {
            temp = ICalendarUtils.getPropertyValue(v, Property.DURATION);
            durstr = temp;
            if (temp != null) {
                cv.put(Events.DURATION, durstr);

                // We still need to calculate and enter DTEND. Otherwise, the Android is not displaying
                // the event properly
                Duration dur = new Duration();
                dur.parse(temp);
                cv.put(Events.DTEND, dtstart + dur.getMillis());
            }
        }

        //TODO add more fields

        //if the event is already present, update it otherwise insert it
        // TODO find if something changed on server using etag
        Uri euri;
        if (localevs.containsKey(uid) || dirtyevs.containsKey(uid)) {
            if (localevs.containsKey(uid)) {
                tid = localevs.get(uid);
                localevs.remove(uid);
            } else {
                tid = dirtyevs.get(uid);
                dirtyevs.remove(uid);
            }

            mCR.update(ContentUris.withAppendedId(EVENTS_URI, tid), cv, null, null);
            //clear sync dirty flag
            cv.clear();
            cv.put(Events._SYNC_DIRTY, 0);
            mCR.update(ContentUris.withAppendedId(EVENTS_URI, tid), cv, null, null);
            Log.d(TAG, "Updated " + uid);
        } else if (!newdevevs.containsKey(uid)) {
            euri = mCR.insert(EVENTS_URI, cv);
            Log.d(TAG, "Inserted " + uid);
        }
    }
    // the remaining events in local and dirty event list are no longer on the server. So remove them.
    for (String uid : localevs.keySet())
        removeLocalEvent(localevs.get(uid));

    //XXX Is this possible?
    /*
    for (String uid: dirtyevs.keySet ())
    removeLocalEvent (dirtyevs[uid]);
     */
}

From source file:com.codetroopers.betterpickers.calendardatepicker.MonthView.java

/**
 * Sets all the parameters for displaying this week. The only required parameter is the week number. Other
 * parameters have a default value and will only update if a new value is included, except for focus month, which
 * will always default to no focus month if no value is passed in. See {@link #VIEW_PARAMS_HEIGHT} for more info on
 * parameters./* ww  w  . j  ava  2  s .  c o  m*/
 *
 * @param params A map of the new parameters, see {@link #VIEW_PARAMS_HEIGHT}
 */
public void setMonthParams(HashMap<String, Integer> params) {
    if (!params.containsKey(VIEW_PARAMS_MONTH) && !params.containsKey(VIEW_PARAMS_YEAR)) {
        throw new InvalidParameterException("You must specify month and year for this view");
    }
    setTag(params);
    // We keep the current value for any params not present
    if (params.containsKey(VIEW_PARAMS_HEIGHT)) {
        mRowHeight = params.get(VIEW_PARAMS_HEIGHT);
        if (mRowHeight < MIN_HEIGHT) {
            mRowHeight = MIN_HEIGHT;
        }
    }
    if (params.containsKey(VIEW_PARAMS_SELECTED_DAY)) {
        mSelectedDay = params.get(VIEW_PARAMS_SELECTED_DAY);
    }
    if (params.containsKey(VIEW_PARAMS_RANGE_MIN)) {
        mRangeMin = params.get(VIEW_PARAMS_RANGE_MIN);
    }
    if (params.containsKey(VIEW_PARAMS_RANGE_MAX)) {
        mRangeMax = params.get(VIEW_PARAMS_RANGE_MAX);
    }

    // Allocate space for caching the day numbers and focus values
    mMonth = params.get(VIEW_PARAMS_MONTH);
    mYear = params.get(VIEW_PARAMS_YEAR);

    // Figure out what day today is
    final Time today = new Time(Time.getCurrentTimezone());
    today.setToNow();
    mHasToday = false;
    mToday = -1;

    mCalendar.set(Calendar.MONTH, mMonth);
    mCalendar.set(Calendar.YEAR, mYear);
    mCalendar.set(Calendar.DAY_OF_MONTH, 1);
    mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK);

    if (params.containsKey(VIEW_PARAMS_WEEK_START)) {
        mWeekStart = params.get(VIEW_PARAMS_WEEK_START);
    } else {
        mWeekStart = mCalendar.getFirstDayOfWeek();
    }

    mNumCells = Utils.getDaysInMonth(mMonth, mYear);
    for (int i = 0; i < mNumCells; i++) {
        final int day = i + 1;
        if (sameDay(day, today)) {
            mHasToday = true;
            mToday = day;
        }
    }
    mNumRows = calculateNumRows();

    // Invalidate cached accessibility information.
    mTouchHelper.invalidateRoot();
}

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

/**
 * Set this server to receive pebble data by registering it as
 * A PebbleDataReceiver/*from  w w w.j  a v  a  2 s  . co m*/
 */
private void startPebbleServer() {
    Log.v(TAG, "StartPebbleServer()");
    final Handler handler = new Handler();
    msgDataHandler = new PebbleKit.PebbleDataReceiver(SD_UUID) {
        @Override
        public void receiveData(final Context context, final int transactionId, final PebbleDictionary data) {
            Log.v(TAG,
                    "Received message from Pebble - data type=" + data.getUnsignedIntegerAsLong(KEY_DATA_TYPE));
            // If we have a message, the app must be running
            mPebbleAppRunningCheck = true;
            PebbleKit.sendAckToPebble(context, transactionId);
            //Log.v(TAG,"Message is: "+data.toJsonString());
            if (data.getUnsignedIntegerAsLong(KEY_DATA_TYPE) == DATA_TYPE_RESULTS) {
                Log.v(TAG, "DATA_TYPE = Results");
                sdData.dataTime.setToNow();
                Log.v(TAG, "sdData.dataTime=" + sdData.dataTime);

                sdData.alarmState = data.getUnsignedIntegerAsLong(KEY_ALARMSTATE);
                sdData.maxVal = data.getUnsignedIntegerAsLong(KEY_MAXVAL);
                sdData.maxFreq = data.getUnsignedIntegerAsLong(KEY_MAXFREQ);
                sdData.specPower = data.getUnsignedIntegerAsLong(KEY_SPECPOWER);
                sdData.roiPower = data.getUnsignedIntegerAsLong(KEY_ROIPOWER);
                sdData.alarmPhrase = "Unknown";
                if (sdData.alarmState == 0) {
                    sdData.alarmPhrase = "OK";
                }
                if (sdData.alarmState == 1) {
                    sdData.alarmPhrase = "WARNING";
                    if (mLogAlarms) {
                        Log.v(TAG, "WARNING - Loggin to SD Card");
                        writeAlarmToSD();
                        logData();
                    } else {
                        Log.v(TAG, "WARNING");
                    }
                    warningBeep();
                }
                if (sdData.alarmState == 2) {
                    sdData.alarmPhrase = "ALARM";
                    if (mLogAlarms) {
                        Log.v(TAG, "***ALARM*** - Loggin to SD Card");
                        writeAlarmToSD();
                        logData();
                    } else {
                        Log.v(TAG, "***ALARM***");
                    }
                    // Make alarm beep tone
                    alarmBeep();
                    // Send SMS Alarm.
                    if (mSMSAlarm) {
                        Time tnow = new Time(Time.getCurrentTimezone());
                        tnow.setToNow();
                        // limit SMS alarms to one per minute
                        if ((tnow.toMillis(false) - mSMSTime.toMillis(false)) > 60000) {
                            sendSMSAlarm();
                            mSMSTime = tnow;
                        }
                    }
                }

                // Read the data that has been sent, and convert it into
                // an integer array.
                byte[] byteArr = data.getBytes(KEY_SPEC_DATA);
                IntBuffer intBuf = ByteBuffer.wrap(byteArr).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer();
                int[] intArray = new int[intBuf.remaining()];
                intBuf.get(intArray);
                for (int i = 0; i < intArray.length; i++) {
                    sdData.simpleSpec[i] = intArray[i];
                }

            }
            if (data.getUnsignedIntegerAsLong(KEY_DATA_TYPE) == DATA_TYPE_SETTINGS) {
                Log.v(TAG, "DATA_TYPE = Settings");
                sdData.alarmFreqMin = data.getUnsignedIntegerAsLong(KEY_ALARM_FREQ_MIN);
                sdData.alarmFreqMax = data.getUnsignedIntegerAsLong(KEY_ALARM_FREQ_MAX);
                sdData.nMin = data.getUnsignedIntegerAsLong(KEY_NMIN);
                sdData.nMax = data.getUnsignedIntegerAsLong(KEY_NMAX);
                sdData.warnTime = data.getUnsignedIntegerAsLong(KEY_WARN_TIME);
                sdData.alarmTime = data.getUnsignedIntegerAsLong(KEY_ALARM_TIME);
                sdData.alarmThresh = data.getUnsignedIntegerAsLong(KEY_ALARM_THRESH);
                sdData.alarmRatioThresh = data.getUnsignedIntegerAsLong(KEY_ALARM_RATIO_THRESH);
                sdData.batteryPc = data.getUnsignedIntegerAsLong(KEY_BATTERY_PC);
                sdData.haveSettings = true;
            }
        }
    };
    PebbleKit.registerReceivedDataHandler(this, msgDataHandler);
}

From source file:com.android.calendar.alerts.AlertService.java

private static long getNextRefreshTime(NotificationInfo info, long currentTime) {
    long startAdjustedForAllDay = info.startMillis;
    long endAdjustedForAllDay = info.endMillis;
    if (info.allDay) {
        Time t = new Time();
        startAdjustedForAllDay = Utils.convertAlldayUtcToLocal(t, info.startMillis, Time.getCurrentTimezone());
        endAdjustedForAllDay = Utils.convertAlldayUtcToLocal(t, info.startMillis, Time.getCurrentTimezone());
    }/*  w  w  w  . j a  v a  2s. c om*/

    // We change an event's priority bucket at 15 minutes into the event or 1/4 event duration.
    long nextRefreshTime = Long.MAX_VALUE;
    long gracePeriodCutoff = startAdjustedForAllDay
            + getGracePeriodMs(startAdjustedForAllDay, endAdjustedForAllDay, info.allDay);
    if (gracePeriodCutoff > currentTime) {
        nextRefreshTime = Math.min(nextRefreshTime, gracePeriodCutoff);
    }

    // ... and at the end (so expiring ones drop into a digest).
    if (endAdjustedForAllDay > currentTime && endAdjustedForAllDay > gracePeriodCutoff) {
        nextRefreshTime = Math.min(nextRefreshTime, endAdjustedForAllDay);
    }
    return nextRefreshTime;
}

From source file:org.apache.cordova.core.Globalization.java

private JSONObject getIsDayLightSavingsTime(JSONArray options) throws GlobalizationError {
    JSONObject obj = new JSONObject();
    boolean dst = false;
    try {//from w  ww  .j a v  a2 s. c o m
        Date date = new Date((Long) options.getJSONObject(0).get(DATE));
        //TimeZone tz = Calendar.getInstance(Locale.getDefault()).getTimeZone();
        TimeZone tz = TimeZone.getTimeZone(Time.getCurrentTimezone());
        dst = tz.inDaylightTime(date); //get daylight savings data from date object and user timezone settings

        return obj.put("dst", dst);
    } catch (Exception ge) {
        throw new GlobalizationError(GlobalizationError.UNKNOWN_ERROR);
    }
}