Example usage for android.text.format Time toMillis

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

Introduction

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

Prototype

public long toMillis(boolean ignoreDst) 

Source Link

Document

Converts this time to milliseconds.

Usage

From source file:com.tdispatch.passenger.model.BookingData.java

public BookingData setPickupDate(String stamp) {
    // date is RFC 3339
    Time time = new Time();
    time.parse3339(stamp);/*from   www .  java  2s.  c om*/

    mPickupDateString = stamp;
    mPickupDate = new Date(time.toMillis(false));

    return this;
}

From source file:com.jogden.spunkycharts.pricebyvolumechart.PriceByVolumeChartFragmentAdapter.java

private Time _truncateTime(Time t, long msInterval, boolean ignoreDST, boolean inPlace) {
    long ms = t.toMillis(ignoreDST);
    ms /= msInterval;/*from  w  ww.  j av  a2  s .c o m*/
    ms *= msInterval;
    if (inPlace) {
        t.set(ms);
        return t;
    } else {
        Time nTime = new Time();
        nTime.set(ms);
        return nTime;
    }
}

From source file:com.jogden.spunkycharts.pricebyvolumechart.PriceByVolumeChartFragmentAdapter.java

private ContentValues _createContentValues(OHLC price, int volume, Time t) {
    ContentValues tmp = new ContentValues();
    tmp.put(DataConsumerInterface.primaryKey, t.toMillis(true));
    tmp.put(columns[0], price.open);/*w w w  . j  a  va 2 s  .  c om*/
    tmp.put(columns[1], price.high);
    tmp.put(columns[2], price.low);
    tmp.put(columns[3], price.close);
    tmp.put(columns[4], volume);
    return tmp;
}

From source file:org.dmfs.webcal.fragments.CalendarItemFragment.java

@Override
public View onCreateItemView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View returnView = inflater.inflate(R.layout.fragment_calendar_item, container, false);

    // TODO: don't put the progress indicator into the header view
    View progressView = inflater.inflate(R.layout.progress_indicator, null, false);

    mProgressBar = (ProgressBar) progressView.findViewById(android.R.id.progress);

    mListView = (ListView) returnView.findViewById(android.R.id.list);

    mListView.addHeaderView(progressView);
    mListView.setOnItemClickListener(this);
    mListView.setHeaderDividersEnabled(false);
    mListAdapter = new EventListAdapter(inflater.getContext(), null);
    mListView.setAdapter(mSectionAdapter = new SectionTitlesAdapter(inflater.getContext(), mListAdapter,
            new SectionIndexer() {

                @Override//from  w w w. j  a v a  2  s  .  c om
                public String getSectionTitle(int index) {
                    Time start = new Time(TimeZone.getDefault().getID());
                    start.set(index & 0x00ff, (index >> 8) & 0x00ff, (index >> 16) & 0x0ffff);

                    return DateUtils.formatDateTime(getActivity(), start.toMillis(true),
                            DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR
                                    | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_ABBREV_WEEKDAY);
                }

                @Override
                public int getSectionIndex(Object object) {
                    Cursor cursor = (Cursor) object;

                    Time start = new Time(
                            cursor.getString(cursor.getColumnIndex(WebCalReaderContract.Events.TIMZONE)));
                    start.set(cursor.getLong(cursor.getColumnIndex(WebCalReaderContract.Events.DTSTART)));
                    boolean allday = cursor
                            .getInt(cursor.getColumnIndex(WebCalReaderContract.Events.IS_ALLDAY)) == 1;
                    start.allDay = allday;

                    // we return an encoded date as index
                    return (start.year << 16) + (start.month << 8) + start.monthDay;

                }
            }, R.layout.events_preview_list_section_header));

    FragmentManager fm = getChildFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();

    mTitleFragment = (CalendarTitleFragment) fm.findFragmentById(R.id.calendar_title_fragment_container);
    if (mTitleFragment == null) {
        mTitleFragment = CalendarTitleFragment.newInstance();
        ft.replace(R.id.calendar_title_fragment_container, mTitleFragment);
    }

    if (!ft.isEmpty()) {
        ft.commit();
    }

    LoaderManager lm = getLoaderManager();
    lm.initLoader(LOADER_CALENDAR_ITEM, null, this);
    lm.initLoader(LOADER_SUBSCRIBED_CALENDAR, null, this);
    lm.initLoader(LOADER_SUBSCRIPTION, null, this);

    // set this to true, so the menu is cleared automatically when leaving the fragment, otherwise the star icon will stay visible
    setHasOptionsMenu(true);

    return returnView;
}

From source file:com.dgsd.android.ShiftTracker.Fragment.EditShiftFragment.java

private void prepopulate() {
    if (mInitialShift != null) {
        mName.setText(mInitialShift.name);
        mNotes.setText(mInitialShift.note);
        mSaveAsTemplate.setChecked(mInitialShift.isTemplate);
        if (mInitialShift.julianDay >= 0)
            onDateSelected(TYPE_CODE_START, mInitialShift.julianDay);

        if (mInitialShift.endJulianDay >= 0)
            onDateSelected(TYPE_CODE_END, mInitialShift.endJulianDay);

        if (mInitialShift.getStartTime() != -1)
            setStartTime(mInitialShift.getStartTime());

        if (mInitialShift.getEndTime() != -1)
            setEndTime(mInitialShift.getEndTime());

        if (mInitialShift.breakDuration >= 0)
            mUnpaidBreak.setText(String.valueOf(mInitialShift.breakDuration));

        if (mInitialShift.payRate >= 0)
            mPayRate.setText(String.valueOf(mInitialShift.payRate));

        for (int i = 0, len = mRemindersValues.length; i < len; i++) {
            if (String.valueOf(mInitialShift.reminder).equals(mRemindersValues[i])) {
                setSelection(mReminders, i);
                break;
            }//from  w w  w.ja v a  2s .  co m
        }

        getSherlockActivity().invalidateOptionsMenu();
    } else {
        //No initial shift, just set up our date/time values
        final int jd = mInitialJulianDay < 0 ? TimeUtils.getCurrentJulianDay() : mInitialJulianDay;
        onDateSelected(TYPE_CODE_START, jd);
        onDateSelected(TYPE_CODE_END, jd);

        //Default 9 - 5 shift
        Time t = new Time();
        t.setToNow();
        t.hour = 9;
        t.minute = 0;
        t.second = 0;
        t.normalize(true);

        final Prefs p = Prefs.getInstance(getActivity());
        setStartTime(p.get(getString(R.string.settings_key_default_start_time), t.toMillis(true)));

        t.hour = 17;
        t.normalize(true);

        setEndTime(p.get(getString(R.string.settings_key_default_end_time), t.toMillis(true)));

        mUnpaidBreak.setText(p.get(getString(R.string.settings_key_default_break_duration), null));
        mPayRate.setText(p.get(getString(R.string.settings_key_default_pay_rate), null));

        String remindersVal = p.get(getString(R.string.settings_key_default_reminder), "None");
        int index = 0;
        for (int i = 0, len = mRemindersLabels.length; i < len; i++) {
            if (TextUtils.equals(remindersVal, mRemindersLabels[i])) {
                index = i;
                break;
            }
        }

        setSelection(mReminders, index);
    }
}

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.
 *///  w  w w. j  av  a2 s.c  om
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:com.cloverstudio.spika.MyProfileActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case GET_IMAGE_DIALOG:
        mGetImageDialog = new Dialog(MyProfileActivity.this, R.style.TransparentDialogTheme);
        mGetImageDialog.getWindow().setGravity(Gravity.BOTTOM);
        mGetImageDialog.setContentView(R.layout.dialog_get_image);
        WindowManager.LayoutParams params = new WindowManager.LayoutParams();
        Window window = mGetImageDialog.getWindow();
        params.copyFrom(window.getAttributes());
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(params);//from  ww  w.j av  a 2 s .  c  om

        final Button btnGallery = (Button) mGetImageDialog.findViewById(R.id.btnGallery);
        btnGallery.setTypeface(SpikaApp.getTfMyriadProBold(), Typeface.BOLD);
        btnGallery.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                Intent galleryIntent = new Intent(MyProfileActivity.this, CameraCropActivity.class);
                galleryIntent.putExtra("type", "gallery");
                galleryIntent.putExtra("profile", true);
                MyProfileActivity.this.startActivityForResult(galleryIntent, UPDATE_IMAGE_REQUEST_CODE);
                mGetImageDialog.dismiss();

            }
        });

        final Button btnCamera = (Button) mGetImageDialog.findViewById(R.id.btnCamera);
        btnCamera.setTypeface(SpikaApp.getTfMyriadProBold(), Typeface.BOLD);
        btnCamera.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                Intent cameraIntent = new Intent(MyProfileActivity.this, CameraCropActivity.class);
                cameraIntent.putExtra("type", "camera");
                cameraIntent.putExtra("profile", true);
                MyProfileActivity.this.startActivityForResult(cameraIntent, UPDATE_IMAGE_REQUEST_CODE);
                mGetImageDialog.dismiss();

            }
        });

        final Button btnRemovePhoto = (Button) mGetImageDialog.findViewById(R.id.btnRemovePhoto);
        btnRemovePhoto.setTypeface(SpikaApp.getTfMyriadProBold(), Typeface.BOLD);
        btnRemovePhoto.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                mNewAvatarId = "";
                gProfileImage = null;
                Utils.displayImage(mNewAvatarId, mIvProfileImage, mPbLoading, ImageLoader.LARGE,
                        R.drawable.user_stub_large, false);
                mGetImageDialog.dismiss();

            }
        });

        return mGetImageDialog;
    case GET_BIRTHDAY_DIALOG:

        int intMaxYear = Calendar.getInstance().get(Calendar.YEAR);
        int intMaxMonth = Calendar.getInstance().get(Calendar.MONTH);
        int intMaxDay = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);

        mGetBirthdayDialog = new DatePickerDialogWithRange(this, new DatePickerDialog.OnDateSetListener() {
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                Time chosenDate = new Time();
                chosenDate.set(dayOfMonth, monthOfYear, year);
                mNewBirthday = chosenDate.toMillis(true) / 1000;
                CharSequence stringDate = DateFormat.format(getString(R.string.hookup_date_format),
                        chosenDate.toMillis(true));
                mEtUserBirthday.setText(stringDate.toString());
            }
        }, intMaxYear, intMaxMonth, intMaxDay);
        mGetBirthdayDialog.setMessage(getString(R.string.when_is_your_birthday));
        return mGetBirthdayDialog;
    default:
        return null;
    }
}

From source file:info.hl.mediam.MyProfileActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case GET_IMAGE_DIALOG:
        mGetImageDialog = new Dialog(MyProfileActivity.this, R.style.TransparentDialogTheme);
        mGetImageDialog.getWindow().setGravity(Gravity.BOTTOM);
        mGetImageDialog.setContentView(R.layout.dialog_get_image);
        WindowManager.LayoutParams params = new WindowManager.LayoutParams();
        Window window = mGetImageDialog.getWindow();
        params.copyFrom(window.getAttributes());
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(params);/*from   w  w w .  j  a va2s. c o m*/

        final Button btnGallery = (Button) mGetImageDialog.findViewById(R.id.btnGallery);
        btnGallery.setTypeface(MediamApp.getTfMyriadProBold(), Typeface.BOLD);
        btnGallery.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                Intent galleryIntent = new Intent(MyProfileActivity.this, CameraCropActivity.class);
                galleryIntent.putExtra("type", "gallery");
                galleryIntent.putExtra("profile", true);
                MyProfileActivity.this.startActivityForResult(galleryIntent, UPDATE_IMAGE_REQUEST_CODE);
                mGetImageDialog.dismiss();

            }
        });

        final Button btnCamera = (Button) mGetImageDialog.findViewById(R.id.btnCamera);
        btnCamera.setTypeface(MediamApp.getTfMyriadProBold(), Typeface.BOLD);
        btnCamera.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                Intent cameraIntent = new Intent(MyProfileActivity.this, CameraCropActivity.class);
                cameraIntent.putExtra("type", "camera");
                cameraIntent.putExtra("profile", true);
                MyProfileActivity.this.startActivityForResult(cameraIntent, UPDATE_IMAGE_REQUEST_CODE);
                mGetImageDialog.dismiss();

            }
        });

        final Button btnRemovePhoto = (Button) mGetImageDialog.findViewById(R.id.btnRemovePhoto);
        btnRemovePhoto.setTypeface(MediamApp.getTfMyriadProBold(), Typeface.BOLD);
        btnRemovePhoto.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                mNewAvatarId = "";
                gProfileImage = null;
                Utils.displayImage(mNewAvatarId, mIvProfileImage, mPbLoading, ImageLoader.LARGE,
                        R.drawable.user_stub_large, false);
                mGetImageDialog.dismiss();

            }
        });

        return mGetImageDialog;
    case GET_BIRTHDAY_DIALOG:

        int intMaxYear = Calendar.getInstance().get(Calendar.YEAR);
        int intMaxMonth = Calendar.getInstance().get(Calendar.MONTH);
        int intMaxDay = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);

        mGetBirthdayDialog = new DatePickerDialogWithRange(this, new DatePickerDialog.OnDateSetListener() {
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                Time chosenDate = new Time();
                chosenDate.set(dayOfMonth, monthOfYear, year);
                mNewBirthday = chosenDate.toMillis(true) / 1000;
                CharSequence stringDate = DateFormat.format(getString(R.string.hookup_date_format),
                        chosenDate.toMillis(true));
                mEtUserBirthday.setText(stringDate.toString());
            }
        }, intMaxYear, intMaxMonth, intMaxDay);
        mGetBirthdayDialog.setMessage(getString(R.string.when_is_your_birthday));
        return mGetBirthdayDialog;
    default:
        return null;
    }
}

From source file:com.nextgis.firereporter.GetFiresService.java

protected void GetScanexData(boolean bShowProgress) {
    //2 hours = 120 min = 7200 sec = 7200000
    Time testTime = new Time();
    testTime.setToNow();/*from   w w w . j  ava 2  s . co m*/
    if (msScanexLoginCookie.equals("setting"))
        return;
    if (msScanexLoginCookie.equals("not_set") || msScanexLoginCookie.length() == 0
            || testTime.toMillis(true) - mSanextCookieTime.toMillis(true) > 7200000) {
        SharedPreferences prefs = getSharedPreferences(MainActivity.PREFERENCES,
                MODE_PRIVATE | MODE_MULTI_PROCESS);
        String sLogin = prefs.getString(SettingsActivity.KEY_PREF_SRV_SCAN_USER, "new@kosmosnimki.ru");
        String sPass = prefs.getString(SettingsActivity.KEY_PREF_SRV_SCAN_PASS, "test123");
        msScanexLoginCookie = "setting";
        mnCurrentExec++;
        new ScanexHttpLogin(this, 4, getResources().getString(R.string.stChecking), mFillDataHandler,
                bShowProgress).execute(sLogin, sPass);
        return;
    }
    //5. send updates to client
    mnCurrentExec++;
    new HttpGetter(this, 3, getResources().getString(R.string.stDownLoading), mFillDataHandler, bShowProgress)
            .execute(SCANEX_API + "/Subscribe/Get/?CallBackName=" + USER_ID, msScanexLoginCookie);

    if (mmoSubscriptions.size() > 0)
        StoreScanexData();
}

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

/**
 * Set this server to receive pebble data by registering it as
 * A PebbleDataReceiver/* w w  w.ja va  2s  .  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);
}