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.codetroopers.betterpickers.calendardatepicker.MonthView.java

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

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

private long createCalendar(Account acc) {
    String name = acc.getName(), account = acc.getEmail(), collection = acc.getCollection(), url = acc.getUrl();
    // Create a Calendar object
    ContentValues cv = new ContentValues();
    cv.put(Calendars.NAME, name);/*from   w w  w.j a  va 2s  .c  om*/
    cv.put(Calendars.DISPLAY_NAME, name);
    cv.put(Calendars.URL, url);
    cv.put(Calendars._SYNC_ACCOUNT, account);
    cv.put(Calendars._SYNC_ACCOUNT_TYPE, CALDAV_ACC_TYPE);
    cv.put(Calendars._SYNC_ID, collection);
    cv.put(Calendars.SYNC_EVENTS, 1);
    cv.put(Calendars.SELECTED, 0);
    cv.put(Calendars.HIDDEN, 0);
    cv.put(Calendars.COLOR, 0xFF9d50a4);
    cv.put(Calendars.SELECTED, 1);
    // Don't show attendee status if we're the organizer
    cv.put(Calendars.ORGANIZER_CAN_RESPOND, 0);

    cv.put(Calendars.TIMEZONE, Time.getCurrentTimezone());
    cv.put(Calendars.ACCESS_LEVEL, Calendars.OWNER_ACCESS);
    cv.put(Calendars.OWNER_ACCOUNT, account);

    Uri uri = mCR.insert(Calendars.CONTENT_URI, cv);
    if (uri != null) {
        String stringId = uri.getPathSegments().get(1);
        return Long.parseLong(stringId);
    }
    return -1;
}

From source file:com.abiansoftware.lib.reader.AbianReaderData.java

public AbianReaderData() {
    m_itemVector = new Vector<AbianReaderItem>();
    m_newItemVector = new Vector<AbianReaderItem>();
    m_itemVector.clear();//from  w  ww . ja  v a2 s .c om
    m_lastUpdateTime = new Time(Time.getCurrentTimezone());
    m_lastUpdateTime.set(0);
    m_pageNumber = 1;
    m_autoUpdateTimeInMinutes = 0;
}

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

/** 
 * Checks the status of the connection to the pebble watch,
 * and sets class variables for use by other functions.
 * If the watch app is not running, it attempts to re-start it.
 *//*from  w  w  w.  j  av  a2 s  .co m*/
public void getPebbleStatus() {
    Time tnow = new Time(Time.getCurrentTimezone());
    tnow.setToNow();
    // Check we are actually connected to the pebble.
    sdData.pebbleConnected = PebbleKit.isWatchConnected(this);
    // And is the pebble_sd app running?
    // set mPebbleAppRunningCheck has been false for more than 10 seconds
    // the app is not talking to us
    // mPebbleAppRunningCheck is set to true in the receiveData handler. 
    if (!mPebbleAppRunningCheck && ((tnow.toMillis(false) - mPebbleStatusTime.toMillis(false)) > 10000)) {
        Log.v(TAG, "tdiff = " + (tnow.toMillis(false) - mPebbleStatusTime.toMillis(false)));
        sdData.pebbleAppRunning = false;
        Log.v(TAG, "Pebble App Not Running - Attempting to Re-Start");
        startWatchApp();
        getPebbleSdSettings();
        if (mAudibleFaultWarning) {
            faultWarningBeep();
        }
    } else {
        sdData.pebbleAppRunning = true;
    }

    // if we have confirmation that the app is running, reset the
    // status time to now and initiate another check.
    if (mPebbleAppRunningCheck) {
        mPebbleAppRunningCheck = false;
        mPebbleStatusTime.setToNow();
    }

    if (!sdData.haveSettings) {
        Log.v(TAG, "getPebbleStatus() - no settings received yet - requesting");
        getPebbleSdSettings();
    }
}

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

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

    // Select filename depending on 'alarm' parameter.
    String fname;
    if (alarm)
        fname = "AlarmLog";
    else
        fname = "DataLog";

    fname = fname + "_" + dateStr + ".txt";
    // Open output directory on SD Card.
    if (isExternalStorageWritable()) {
        try {
            FileWriter of = new FileWriter(getDataStorageDir().toString() + "/" + fname, true);
            if (sdData != null) {
                Log.v(TAG, "writing sdData.toString()");
                of.append(sdData.toString() + "\n");
            }
            of.close();
        } catch (Exception ex) {
            Log.e(TAG, "writeAlarmToSD - error " + ex.toString());
        }
    } else {
        Log.e(TAG, "ERROR - Can not Write to External Folder");
    }
}

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

private void updateSecondaryTitleFields(long visibleMillisSinceEpoch) {
    mShowWeekNum = Utils.getShowWeekNumber(this);
    mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
    if (visibleMillisSinceEpoch != -1) {
        int weekNum = Utils.getWeekNumberFromTime(visibleMillisSinceEpoch, this);
        mWeekNum = weekNum;/* ww  w. j  a  va 2 s.  c o m*/
    }

    if (mShowWeekNum && (mCurrentView == ViewType.WEEK) && mIsTabletConfig && mWeekTextView != null) {
        String weekString = getResources().getQuantityString(R.plurals.weekN, mWeekNum, mWeekNum);
        mWeekTextView.setText(weekString);
        mWeekTextView.setVisibility(View.VISIBLE);
    } else if (visibleMillisSinceEpoch != -1 && mWeekTextView != null && mCurrentView == ViewType.DAY
            && mIsTabletConfig) {
        Time time = new Time(mTimeZone);
        time.set(visibleMillisSinceEpoch);
        int julianDay = Time.getJulianDay(visibleMillisSinceEpoch, time.gmtoff);
        time.setToNow();
        int todayJulianDay = Time.getJulianDay(time.toMillis(false), time.gmtoff);
        String dayString = Utils.getDayOfWeekString(julianDay, todayJulianDay, visibleMillisSinceEpoch, this);
        mWeekTextView.setText(dayString);
        mWeekTextView.setVisibility(View.VISIBLE);
    } else if (mWeekTextView != null && (!mIsTabletConfig || mCurrentView != ViewType.DAY)) {
        mWeekTextView.setVisibility(View.GONE);
    }

    if (mHomeTime != null
            && (mCurrentView == ViewType.DAY || mCurrentView == ViewType.WEEK
                    || mCurrentView == ViewType.AGENDA)
            && !TextUtils.equals(mTimeZone, Time.getCurrentTimezone())) {
        Time time = new Time(mTimeZone);
        time.setToNow();
        long millis = time.toMillis(true);
        boolean isDST = time.isDst != 0;
        int flags = DateUtils.FORMAT_SHOW_TIME;
        if (DateFormat.is24HourFormat(this)) {
            flags |= DateUtils.FORMAT_24HOUR;
        }
        // Formats the time as
        String timeString = (new StringBuilder(Utils.formatDateRange(this, millis, millis, flags))).append(" ")
                .append(TimeZone.getTimeZone(mTimeZone).getDisplayName(isDST, TimeZone.SHORT,
                        Locale.getDefault()))
                .toString();
        mHomeTime.setText(timeString);
        mHomeTime.setVisibility(View.VISIBLE);
        // Update when the minute changes
        mHomeTime.removeCallbacks(mHomeTimeUpdater);
        mHomeTime.postDelayed(mHomeTimeUpdater,
                DateUtils.MINUTE_IN_MILLIS - (millis % DateUtils.MINUTE_IN_MILLIS));
    } else if (mHomeTime != null) {
        mHomeTime.setVisibility(View.GONE);
    }
}

From source file:es.usc.citius.servando.calendula.fragments.ScheduleImportFragment.java

@Override
public void onRecurrenceSet(String s) {

    EventRecurrence event = new EventRecurrence();

    LocalDate now = LocalDate.now();
    Time startDate = new Time(Time.getCurrentTimezone());
    startDate.set(now.getDayOfMonth(), now.getMonthOfYear(), now.getYear());
    startDate.normalize(true);/* w  w w . j  av  a  2 s.c  om*/
    event.parse(s);
    event.setStartDate(startDate);

    Log.d(TAG, "OnRecurrenceSet: " + event.startDate);

    schedule.setRepetition(new RepetitionRule("RRULE:" + s));
    setScheduleStart(schedule.start());
    LocalDate end = schedule.end();
    Log.d(TAG, "ICAL: " + schedule.rule().toIcal());
    setScheduleEnd(end);
    Log.d(TAG, "ICAL: " + schedule.rule().toIcal());
    ruleText.setText(getCurrentSchedule());
}