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(Time other) 

Source Link

Document

A copy constructor.

Usage

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

/**
 * Sends SMS Alarms to the telephone numbers specified in mSMSNumbers[]
 *///w  w  w . ja  va2  s.c om
public void sendSMSAlarm() {
    if (mSMSAlarm) {
        Log.v(TAG, "sendSMSAlarm() - Sending to " + mSMSNumbers.length + " Numbers");
        Time tnow = new Time(Time.getCurrentTimezone());
        tnow.setToNow();
        String dateStr = tnow.format("%Y-%m-%d %H-%M-%S");
        SmsManager sm = SmsManager.getDefault();
        for (int i = 0; i < mSMSNumbers.length; i++) {
            Log.v(TAG, "sendSMSAlarm() - Sending to " + mSMSNumbers[i]);
            sm.sendTextMessage(mSMSNumbers[i], null, mSMSMsgStr + " - " + dateStr, null, null);
        }
    } else {
        Log.v(TAG, "sendSMSAlarm() - SMS Alarms Disabled - not doing anything!");
        Toast toast = Toast.makeText(getApplicationContext(), "SMS Alarms Disabled - not doing anything!",
                Toast.LENGTH_SHORT);
        toast.show();
    }
}

From source file:com.android.yijiang.kzx.widget.betterpickers.calendardatepicker.SimpleMonthView.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.//from ww w .j  av a2 s .co  m
 *
 * @param params A map of the new parameters, see {@link #VIEW_PARAMS_HEIGHT}
 * @param tz The time zone this view should reference times in
 */
public void setMonthParams(HashMap<String, Integer> params) {
    if (!params.containsKey(VIEW_PARAMS_MONTH) && !params.containsKey(VIEW_PARAMS_YEAR)) {
        throw new InvalidParameterException("You must specify the 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.
    mNodeProvider.invalidateParent();
}

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

private boolean initialiseSunMoon() {
    boolean isDay = false;
    sunOffset = mViewHeight;//  ww  w . j  a va2  s.c  om
    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 va  2 s  . c o m*/
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:com.xandy.calendar.AllInOneActivity.java

@Override
protected void onCreate(Bundle icicle) {
    if (Utils.getSharedPreference(this, OtherPreferences.KEY_OTHER_1, false)) {
        setTheme(R.style.CalendarTheme_WithActionBarWallpaper);
    }/*from w  w w.ja va 2 s  .  c  om*/
    super.onCreate(icicle);

    if (icicle != null && icicle.containsKey(BUNDLE_KEY_CHECK_ACCOUNTS)) {
        mCheckForAccounts = icicle.getBoolean(BUNDLE_KEY_CHECK_ACCOUNTS);
    }
    // Launch add google account if this is first time and there are no
    // accounts yet
    if (mCheckForAccounts && !Utils.getSharedPreference(this, GeneralPreferences.KEY_SKIP_SETUP, false)) {

        mHandler = new QueryHandler(this.getContentResolver());
        mHandler.startQuery(0, null, Calendars.CONTENT_URI, new String[] { Calendars._ID }, null,
                null /* selection args */, null /* sort order */);
    }

    // This needs to be created before setContentView
    mController = CalendarController.getInstance(this);

    // Get time from intent or icicle
    long timeMillis = -1;
    int viewType = -1;
    final Intent intent = getIntent();
    if (icicle != null) {
        timeMillis = icicle.getLong(BUNDLE_KEY_RESTORE_TIME);
        viewType = icicle.getInt(BUNDLE_KEY_RESTORE_VIEW, -1);
    } else {
        String action = intent.getAction();
        if (Intent.ACTION_VIEW.equals(action)) {
            // Open EventInfo later
            timeMillis = parseViewAction(intent);
        }

        if (timeMillis == -1) {
            timeMillis = Utils.timeFromIntentInMillis(intent);
        }
    }

    if (viewType == -1 || viewType > ViewType.MAX_VALUE) {
        viewType = Utils.getViewTypeFromIntentAndSharedPref(this);
    }
    mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater);
    Time t = new Time(mTimeZone);
    t.set(timeMillis);

    if (DEBUG) {
        if (icicle != null && intent != null) {
            Log.d(TAG, "both, icicle:" + icicle.toString() + "  intent:" + intent.toString());
        } else {
            Log.d(TAG, "not both, icicle:" + icicle + " intent:" + intent);
        }
    }

    Resources res = getResources();
    mHideString = res.getString(R.string.hide_controls);
    mShowString = res.getString(R.string.show_controls);
    mOrientation = res.getConfiguration().orientation;
    if (mOrientation == Configuration.ORIENTATION_LANDSCAPE) {
        mControlsAnimateWidth = (int) res.getDimension(R.dimen.calendar_controls_width);
        if (mControlsParams == null) {
            mControlsParams = new LayoutParams(mControlsAnimateWidth, 0);
        }
        mControlsParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    } else {
        // Make sure width is in between allowed min and max width values
        mControlsAnimateWidth = Math.max(res.getDisplayMetrics().widthPixels * 45 / 100,
                (int) res.getDimension(R.dimen.min_portrait_calendar_controls_width));
        mControlsAnimateWidth = Math.min(mControlsAnimateWidth,
                (int) res.getDimension(R.dimen.max_portrait_calendar_controls_width));
    }

    mControlsAnimateHeight = (int) res.getDimension(R.dimen.calendar_controls_height);

    mHideControls = !Utils.getSharedPreference(this, GeneralPreferences.KEY_SHOW_CONTROLS, true);
    mIsMultipane = Utils.getConfigBool(this, R.bool.multiple_pane_config);
    mIsTabletConfig = Utils.getConfigBool(this, R.bool.tablet_config);
    mShowAgendaWithMonth = Utils.getConfigBool(this, R.bool.show_agenda_with_month);
    mShowCalendarControls = Utils.getConfigBool(this, R.bool.show_calendar_controls);
    mShowEventDetailsWithAgenda = Utils.getConfigBool(this, R.bool.show_event_details_with_agenda);
    mShowEventInfoFullScreenAgenda = Utils.getConfigBool(this, R.bool.agenda_show_event_info_full_screen);
    mShowEventInfoFullScreen = Utils.getConfigBool(this, R.bool.show_event_info_full_screen);
    mCalendarControlsAnimationTime = res.getInteger(R.integer.calendar_controls_animation_time);
    Utils.setAllowWeekForDetailView(mIsMultipane);

    // setContentView must be called before configureActionBar
    setContentView(R.layout.all_in_one);

    if (mIsTabletConfig) {
        mDateRange = (TextView) findViewById(R.id.date_bar);
        mWeekTextView = (TextView) findViewById(R.id.week_num);
    } else {
        mDateRange = (TextView) getLayoutInflater().inflate(R.layout.date_range_title, null);
    }

    // configureActionBar auto-selects the first tab you add, so we need to
    // call it before we set up our own fragments to make sure it doesn't
    // overwrite us
    configureActionBar(viewType);

    mHomeTime = (TextView) findViewById(R.id.home_time);
    mMiniMonth = findViewById(R.id.mini_month);
    if (mIsTabletConfig && mOrientation == Configuration.ORIENTATION_PORTRAIT) {
        mMiniMonth.setLayoutParams(
                new RelativeLayout.LayoutParams(mControlsAnimateWidth, mControlsAnimateHeight));
    }
    mCalendarsList = findViewById(R.id.calendar_list);
    mMiniMonthContainer = findViewById(R.id.mini_month_container);
    mSecondaryPane = findViewById(R.id.secondary_pane);

    // Must register as the first activity because this activity can modify
    // the list of event handlers in it's handle method. This affects who
    // the rest of the handlers the controller dispatches to are.
    mController.registerFirstEventHandler(HANDLER_KEY, this);

    initFragments(timeMillis, viewType, icicle);

    // Listen for changes that would require this to be refreshed
    SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this);
    prefs.registerOnSharedPreferenceChangeListener(this);

    mContentResolver = getContentResolver();
}

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}/*from www.  j a  va2 s .  co  m*/
 */
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:com.granita.tasks.notification.NotificationActionUtils.java

private static Time makeTime(long timestamp, boolean allday) {
    Time result = new Time(allday ? Time.TIMEZONE_UTC : TimeZone.getDefault().getID());
    result.set(timestamp);/* w  ww .j  av  a2  s.  c  om*/
    result.allDay = allday;
    return result;
}

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./*  w  ww .j ava2 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  ava2  s  .  c o 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.agenda.AgendaFragment.java

@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
    int julianDay = mAgendaListView
            .getJulianDayFromPosition(firstVisibleItem - mAgendaListView.getHeaderViewsCount());
    // On error - leave the old view
    if (julianDay == 0) {
        return;/*from  w  w w.j a  va  2  s . c o m*/
    }
    // If the day changed, update the ActionBar
    if (mJulianDayOnTop != julianDay) {
        mJulianDayOnTop = julianDay;
        Time t = new Time(mTimeZone);
        t.setJulianDay(mJulianDayOnTop);
        mController.setTime(t.toMillis(true));
        // Cannot sent a message that eventually may change the layout of the views
        // so instead post a runnable that will run when the layout is done
        if (!mIsTabletConfig) {
            view.post(new Runnable() {
                @Override
                public void run() {
                    Time t = new Time(mTimeZone);
                    t.setJulianDay(mJulianDayOnTop);
                    mController.sendEvent(this, EventType.UPDATE_TITLE, t, t, null, -1, ViewType.CURRENT, 0,
                            null, null);
                }
            });
        }
    }
}