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:com.dwdesign.tweetings.util.Utils.java

public static String formatTimeStampString(final Context context, final long timestamp) {
    if (context == null)
        return null;
    final Time then = new Time();
    then.set(timestamp);/*from w  w w  . j a va 2s  . co  m*/
    final Time now = new Time();
    now.setToNow();

    int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL
            | DateUtils.FORMAT_CAP_AMPM;

    if (then.year != now.year) {
        format_flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE;
    } else if (then.yearDay != now.yearDay) {
        format_flags |= DateUtils.FORMAT_SHOW_DATE;
    } else {
        format_flags |= DateUtils.FORMAT_SHOW_TIME;
    }

    return DateUtils.formatDateTime(context, timestamp, format_flags);
}

From source file:com.tdispatch.passenger.fragment.ControlCenterFragment.java

/**[ BookingConfirmationDialogClickListener ]**********************************************************************/

@Override//from w  ww .  j a v  a 2 s. co m
public void bookingConfirmed(LocationData pickup, LocationData dropoff, Long pickupMillis) {

    int maxDaysAhead = getResources().getInteger(R.integer.caboffice_settings_new_bookings_max_days_ahead);

    Boolean result = false;
    Boolean pickupMillisInvalid = false;
    String pickupMillisBodyId = "";

    if (pickupMillis != null) {
        Long diff = (pickupMillis - System.currentTimeMillis());

        if (diff > 0) {

            if (diff > (WebnetTools.MILLIS_PER_MINUTE * 5)) {
                if (diff < (WebnetTools.MILLIS_PER_DAY * maxDaysAhead)) {
                    //    keep it
                } else {
                    pickupMillisBodyId = getString(R.string.new_booking_pickup_date_too_ahead_body_fmt,
                            maxDaysAhead);
                    pickupMillisInvalid = true;
                }
            } else {
                pickupMillis = null;
            }

        } else {
            pickupMillisBodyId = getString(R.string.new_booking_pickup_date_already_passed);
            pickupMillisInvalid = true;
        }

    }

    if (pickupMillisInvalid == false) {
        if (mPickupAddress != null) {
            mCommonHostActivity.lockUI();

            // prepare booking
            try {
                AccountData user = TDApplication.getSessionManager().getAccountData();

                JSONObject json = new JSONObject();

                JSONObject passenger = new JSONObject();
                passenger.put("name", user.getFullName());
                passenger.put("phone", (user.getPhone() != null) ? user.getPhone() : "");
                passenger.put("email", (user.getEmail() != null) ? user.getEmail() : "");
                json.put("passenger", passenger);

                // pickup location
                json.put("pickup_location", pickup.toJSON());

                if (pickupMillis != null) {
                    Time t = new Time();
                    t.set(pickupMillis);

                    String timeStr = t.format3339(false).replace(".000+", "+"); // FIXME API BUG
                    json.put("pickup_time", timeStr);
                }

                // dropoff
                if (mDropoffAddress != null) {
                    json.put("dropoff_location", dropoff.toJSON());
                }

                json.put("passengers", 1);
                json.put("status", "incoming");

                WebnetTools.executeAsyncTask(new NewBookingAsyncTask(), json);

                result = true;

            } catch (Exception e) {
                e.printStackTrace();
            }

        } else {
            showDialog(GenericDialogFragment.DIALOG_TYPE_ERROR, R.string.dialog_error_title,
                    R.string.new_booking_no_pickup_location_body);
        }

    } else {
        showDialog(GenericDialogFragment.DIALOG_TYPE_ERROR, getString(R.string.dialog_error_title),
                pickupMillisBodyId);
    }

    if (result == false) {
        mCommonHostActivity.unlockUI();
    }

}

From source file:com.markupartist.sthlmtraveling.PlannerFragment.java

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    // We only check the state for later radio button.
    if (isChecked && buttonView.getId() == R.id.planner_check_more_choices) {
        // Set time to now, and notify buttons about the new time.
        if (mTime == null) {
            mTime = new Time();
            mTime.setToNow();//from ww w .  j a v  a  2s. c om
            onTimeChanged();
        }

        mChangeTimeLayout.setVisibility(View.VISIBLE);
    } else if (!isChecked && buttonView.getId() == R.id.planner_check_more_choices) {
        mViaPoint = new Site();
        mViaPointAutoComplete.setText("");
        mChangeTimeLayout.setVisibility(View.GONE);
    }
}

From source file:com.dwdesign.tweetings.util.Utils.java

public static String formatToLongTimeString(final Context context, final long timestamp) {
    if (context == null)
        return null;
    final Time then = new Time();
    then.set(timestamp);// w w  w  .j a v a2  s . c  om
    final Time now = new Time();
    now.setToNow();

    int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_CAP_AMPM;

    format_flags |= DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME;

    return DateUtils.formatDateTime(context, timestamp, format_flags);
}

From source file:nz.ac.otago.psyanlab.common.designer.ExperimentDesignerActivity.java

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    switch (requestCode) {
    case REQUEST_EDIT_STAGE: {
        switch (resultCode) {
        case RESULT_OK:
            ArrayList<PropIdPair> props = data.getParcelableArrayListExtra(Args.EXPERIMENT_PROPS);
            long sceneId = data.getLongExtra(Args.SCENE_ID, -1);

            int height = data.getIntExtra(Args.STAGE_HEIGHT, -1);
            int width = data.getIntExtra(Args.STAGE_WIDTH, -1);
            int orientation = data.getIntExtra(Args.STAGE_ORIENTATION, Scene.ORIENTATION_LANDSCAPE);

            updateStageInScene(sceneId, props, orientation, width, height);
            break;

        default:/*from  w w  w .j  av a 2  s .c om*/
            break;
        }
        break;
    }
    case REQUEST_ASSET_IMPORT: {
        switch (resultCode) {
        case RESULT_OK:
            String[] paths = data.getStringArrayExtra(Args.PICKED_PATHS);
            Time t = new Time();
            t.setToNow();
            mExperiment.assets.put(ModelUtils.findUnusedKey(mExperiment.assets),
                    Asset.getFactory().newAsset(paths[0]));
            mAssetAdapter.notifyDataSetChanged();
            break;
        default:
            break;
        }
        break;
    }
    case REQUEST_SOURCE_IMPORT: {
        switch (resultCode) {
        case RESULT_OK:
            String[] paths = data.getStringArrayExtra(Args.PICKED_PATHS);
            Time t = new Time();
            t.setToNow();
            Source newSource = new Source();
            newSource.setExternalFile(new File(paths[0]));
            mExperiment.sources.put(ModelUtils.findUnusedKey(mExperiment.sources), newSource);
            mSourceAdapter.notifyDataSetChanged();
            break;
        default:
            break;
        }
    }
    default:
        break;
    }
}

From source file:com.jogden.spunkycharts.traditionalchart.TraditionalChartFragmentAdapter.java

private void _populateQueues(final int cursorStartPos) {
    Thread thisThread = new Thread() {
        public void run() {
            /* can't bail(risk deadlocking on the count-down latch) */
            _populateLck.lock();//from  w ww  .  ja  v  a 2 s .co  m
            try {
                if (cursorStartPos > 0) /* back one because moveToNext() ) */
                    _myCursor.moveToPosition(cursorStartPos - 1);
                else
                    _myCursor.moveToPosition(-1);
                int mergeNum = _chartFreq.value / DataClientInterface.TIME_GRANULARITY;
                /* reset _lastPutTime */
                _lastPutTime = null;
                // DEBUG
                DataContentService.dumpDatabaseTableToLogCat(_symbol, _thisConsumer);
                /* start on a clean seg , i.e mod freq == 0 */
                boolean cleanStart = true;
                Time time = new Time();
                while (_myCursor.moveToNext()) {
                    time.set(_myCursor.getLong(0));
                    if (time.minute % mergeNum == 0)
                        break;
                    cleanStart = false;
                }
                _myCursor.moveToPrevious();
                OHLC[] prices = new OHLC[mergeNum];
                int[] vols = new int[mergeNum];

                time.set(0);
                int modCount = 0;
                // issue will null time if cursor is done here !! 
                // we throw a *LogicError if its a problem later.
                while (_myCursor.moveToNext() && !this.isInterrupted()) {
                    prices[modCount] = new OHLC(_myCursor.getFloat(1), _myCursor.getFloat(2),
                            _myCursor.getFloat(3), _myCursor.getFloat(4));
                    vols[modCount] = _myCursor.getInt(5);
                    if (modCount == 0)
                        time.set(_myCursor.getLong(0));
                    if (modCount + 1 >= mergeNum) {
                        OHLC mPrices = _mergePrices(prices);
                        int mVols = _mergeVolumes(vols);
                        //_timeStampQueue.put( time.format("%H:%M") );
                        /* time must come first since it may fill gaps in price/vol */
                        _putTime(time);
                        _ohlcQueue.put(mPrices);
                        _volumeQueue.put(mVols);
                        modCount = 0;/*
                                     Log.d("Data-Consumer-Populate", 
                                     mPrices.toString +"   " +
                                     String.valueOf(mVols) + "   " + time );*/
                    } else
                        ++modCount;
                }
                /* don't forget about an unclean end */
                if (modCount != 0) {
                    // _timeStampQueue.put( time.format("%H:%M") );
                    /* time must come first since it may fill gaps in price/vol */
                    _putTime(time);
                    _ohlcQueue.put(_mergePrices(Arrays.copyOf(prices, modCount)));
                    _volumeQueue.put(_mergeVolumes(Arrays.copyOf(vols, modCount)));
                    /*
                    Log.d("Data-Consumer-Populate", 
                        _lastPriceSeg.toString()  +"   " +
                        String.valueOf(_lastVolSeg) + "   " + time );*/
                }
                if (time.toMillis(true) == 0)
                    throw new TraditionalChartLogicError("attempt to evaluate a null time  in PopulateQueues; "
                            + "its possible there were no granular segs after cleaning "
                            + "the non-logically aligned front segs, and thus no valid time.");
                _lastSegTime.setToNow();
                _lastSegTime.hour = time.hour;
                _lastSegTime.minute = time.minute;
                // _updateTime.setToNow();  
                _streamReady.set(true);
                /* unclean start needs extra counts to avoid deadlock */
                for (int i = 0; !cleanStart && i < 2; ++i)
                    _updateLtch.countDown();
            } catch (InterruptedException e) {
                _clear();
            } catch (RuntimeException e) {
                _clear();
                throw e;
            } finally {
                _activeThreads.remove(this);
                _populateLck.unlock();
            }
        }
    };
    _activeThreads.add(thisThread);
    thisThread.start();
}

From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

private void drawDayHeaderLoop(Rect r, Canvas canvas, Paint p) {
    p.setTypeface(mBold);// w  w w  .  j  av a 2  s.c  o m
    p.setTextAlign(Align.RIGHT);
    int cell = mFirstJulianDay;

    String[] dayNames;
    if (mDateStrWidthLong < mCellWidth && mNumDays == 1) {
        dayNames = mDayStrsLong;
    } else if (mDateStrWidth < mCellWidth) {
        dayNames = mDayStrs;
    } else {
        dayNames = mDayStrs2Letter;
    }

    p.setAntiAlias(true);
    for (int day = 0; day < mNumDays; day++, cell++) {
        int dayOfWeek = day + mFirstVisibleDayOfWeek;
        if (dayOfWeek >= 14) {
            dayOfWeek -= 14;
        }

        int color = mCalendarDateBannerTextColor;
        if (mNumDays == 1) {
            if (dayOfWeek == Time.SATURDAY) {
                color = mWeek_saturdayColor;
            } else if (dayOfWeek == Time.SUNDAY) {
                color = mWeek_sundayColor;
            }
        } else {
            final int column = day % 7;
            if (DayUtils.isSaturday(column, mFirstDayOfWeek)) {
                color = mWeek_saturdayColor;
            } else if (DayUtils.isSunday(column, mFirstDayOfWeek)) {
                color = mWeek_sundayColor;
            }
        }

        p.setColor(color);
        if (mNumDays == 1) {
            Time time = new Time();
            time.setJulianDay(mFirstJulianDay);
            String s = SimpleDateFormat.getDateInstance().format(new Date(time.toMillis(false)));
            drawDayHeader(dayNames[dayOfWeek], day, s, canvas, p);
        } else {
            int dateNum = mFirstVisibleDate + day;
            if (dateNum > mMonthLength) {
                dateNum -= mMonthLength;
            }
            drawDayHeader(dayNames[dayOfWeek], day, String.valueOf(dateNum), canvas, p);
        }
    }
    p.setTypeface(null);
}

From source file:com.jogden.spunkycharts.traditionalchart.TraditionalChartFragmentAdapter.java

private void _putTime(Time t) throws InterruptedException {
    if (_lastPutTime == null) { /* if first, ignore everything else */
        _lastPutTime = new Time();
    } else { /* otherwise fill in the gaps */
        long oldTime = _lastPutTime.toMillis(true);
        long newTime = t.toMillis(true);

        /* round to avoid getting screwed over a few ms */
        int minDiff = Math.round((float) (newTime - oldTime) / (float) (_chartFreq.value * 60000));

        Log.d("DataContentService-1",
                "Old Time: " + _lastPutTime.format("%H:%M:%S") + "    ,    New Time: " + t.format("%H:%M:%S"));

        while (minDiff > _chartFreq.value) {
            _lastPutTime.minute += _chartFreq.value;
            /* the following  'handles' a unique sync issue where the cursor is loaded,
             * a new granular seg is inserted into the database AND THEN a new 
             * full seg is 'put' into the queues leading to the new full seg being skipped.
             *      1) this happens around the minute mark (when segs roll)
             *      2) we could (and may) simply re-load the cursor
             *      3) not sure how this works with full segs > 1 min
             *//*from   w ww.j av  a 2  s  . co m*/
            if (_chartFreq.value == DataClientInterface.TIME_GRANULARITY && minDiff == (2 * _chartFreq.value)) {
                _ohlcQueue.put(new OHLC(_penultGranularPriceSeg));
                _volumeQueue.put(_penultGranularVolSeg);
            } else {
                _ohlcQueue.put(new OHLC(_lastPriceSeg.open));
                _volumeQueue.put(0);
            }

            _timeStampQueue.put(_lastPutTime.format("%H:%M"));
            minDiff -= _chartFreq.value;
        }

    }
    _timeStampQueue.put(t.format("%H:%M"));
    _lastPutTime.set(t);
}

From source file:de.vanita5.twittnuker.util.Utils.java

@SuppressWarnings("deprecation")
public static String formatTimeStampString(final Context context, final long timestamp) {
    if (context == null)
        return null;
    final Time then = new Time();
    then.set(timestamp);/*ww  w . jav a2  s  .c om*/
    final Time now = new Time();
    now.setToNow();

    int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL
            | DateUtils.FORMAT_CAP_AMPM;

    if (then.year != now.year) {
        format_flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE;
    } else if (then.yearDay != now.yearDay) {
        format_flags |= DateUtils.FORMAT_SHOW_DATE;
    } else {
        format_flags |= DateUtils.FORMAT_SHOW_TIME;
    }

    return DateUtils.formatDateTime(context, timestamp, format_flags);
}

From source file:de.vanita5.twittnuker.util.Utils.java

@SuppressWarnings("deprecation")
public static String formatToLongTimeString(final Context context, final long timestamp) {
    if (context == null)
        return null;
    final Time then = new Time();
    then.set(timestamp);//w ww . j  a v  a2 s.  co m
    final Time now = new Time();
    now.setToNow();

    int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL
            | DateUtils.FORMAT_CAP_AMPM;

    format_flags |= DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME;

    return DateUtils.formatDateTime(context, timestamp, format_flags);
}