Example usage for android.text.format Time setJulianDay

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

Introduction

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

Prototype

public long setJulianDay(int julianDay) 

Source Link

Document

Sets the time from the given Julian day number, which must be based on the same timezone that is set in this Time object.

Usage

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

public Time getSelectedDay() {
    Time time = new Time(mBaseDate);
    time.setJulianDay(mSelectionDay);
    time.hour = mSelectionHour;//  w ww  . ja  va2  s . co  m

    // We ignore the "isDst" field because we want normalize() to figure
    // out the correct DST value and not adjust the selected time based
    // on the current setting of DST.
    time.normalize(true /* ignore isDst */);
    return time;
}

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

private void doSingleTapUp(MotionEvent ev) {
    if (!mHandleActionUp || mScrolling) {
        return;//from w  w  w  .  j  a v a  2s  .  c  om
    }

    int x = (int) ev.getX();
    int y = (int) ev.getY();

    boolean validPosition = setSelectionFromPosition(x, y, false);
    if (!validPosition) {
        if (y < DAY_HEADER_HEIGHT) {
            Time selectedTime = new Time(mBaseDate);
            selectedTime.setJulianDay(mSelectionDay);
            selectedTime.hour = mSelectionHour;
            selectedTime.normalize(true /* ignore isDst */);
        }
        return;
    }

    if (mSelectedEvent != null) {
        long clearDelay = (CLICK_DISPLAY_DURATION + mOnDownDelay)
                - (System.currentTimeMillis() - mDownTouchTime);
        if (clearDelay > 0) {
            this.postDelayed(mClearClick, clearDelay);
        } else {
            this.post(mClearClick);
        }

    }
    invalidate();
}

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

private void drawDayHeaderLoop(Rect r, Canvas canvas, Paint p) {
    p.setTypeface(mBold);//w ww. java  2s .  co  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:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

private void init(Context context) {
    setFocusable(true);/* www.j  a va 2  s  .  c o m*/

    // Allow focus in touch mode so that we can do keyboard shortcuts
    // even after we've entered touch mode.
    setFocusableInTouchMode(true);
    setClickable(true);
    setOnCreateContextMenuListener(this);

    mFirstDayOfWeek = Time.MONDAY;

    mCurrentTime = new Time(DayUtils.getTimeZone(context, mTZUpdater));
    long currentTime = System.currentTimeMillis();
    mCurrentTime.set(currentTime);
    mTodayJulianDay = Time.getJulianDay(currentTime, mCurrentTime.gmtoff);

    mEventTextPaint.setTextSize(EVENT_TEXT_FONT_SIZE);
    mEventTextPaint.setTextAlign(Align.LEFT);
    mEventTextPaint.setAntiAlias(true);

    int gridLineColor = 0xff707070;
    Paint p = mSelectionPaint;
    p.setColor(gridLineColor);
    p.setStyle(Style.FILL);
    p.setAntiAlias(false);

    p = mPaint;
    p.setAntiAlias(true);

    // Long day names
    mDayStrsLong = new String[14];

    // Allocate space for 2 weeks worth of weekday names so that we can
    // easily start the week display at any week day.
    mDayStrs = new String[14];

    // Also create an array of 2-letter abbreviations.
    mDayStrs2Letter = new String[14];

    for (int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++) {
        int index = i - Calendar.SUNDAY;

        mDayStrsLong[index] = DateUtils.getDayOfWeekString(i, DateUtils.LENGTH_LONG).toUpperCase();
        mDayStrsLong[index + 7] = mDayStrsLong[index];
        // e.g. Tue for Tuesday
        mDayStrs[index] = DateUtils.getDayOfWeekString(i, DateUtils.LENGTH_MEDIUM).toUpperCase();
        mDayStrs[index + 7] = mDayStrs[index];
        // e.g. Tu for Tuesday
        mDayStrs2Letter[index] = DateUtils.getDayOfWeekString(i, DateUtils.LENGTH_SHORT).toUpperCase();

        // If we don't have 2-letter day strings, fall back to 1-letter.
        if (mDayStrs2Letter[index].equals(mDayStrs[index])) {
            mDayStrs2Letter[index] = DateUtils.getDayOfWeekString(i, DateUtils.LENGTH_SHORTEST);
        }

        mDayStrs2Letter[index + 7] = mDayStrs2Letter[index];
    }

    // Figure out how much space we need for the 3-letter abbrev names
    // in the worst case.
    p.setTextSize(DATE_HEADER_FONT_SIZE);
    p.setTypeface(mBold);
    String[] dateStrs = { " 28", " 30" };
    mDateStrWidth = computeMaxStringWidth(0, dateStrs, p);
    Time time = new Time();
    time.setJulianDay(mFirstJulianDay);
    String s = SimpleDateFormat.getDateInstance().format(new Date(time.toMillis(false)));
    mDateStrWidthLong = computeMaxStringWidth(0, new String[] { s }, p);
    p.setTextSize(DAY_HEADER_FONT_SIZE);
    mDateStrWidth += computeMaxStringWidth(0, mDayStrs, p);
    mDateStrWidthLong += computeMaxStringWidth(0, mDayStrsLong, p);

    p.setTextSize(HOURS_TEXT_SIZE);
    p.setTypeface(null);
    handleOnResume();

    mAmString = DateUtils.getAMPMString(Calendar.AM).toUpperCase();
    mPmString = DateUtils.getAMPMString(Calendar.PM).toUpperCase();
    String[] ampm = { mAmString, mPmString };
    p.setTextSize(AMPM_TEXT_SIZE);
    mHoursWidth = Math.max(HOURS_MARGIN, computeMaxStringWidth(mHoursWidth, ampm, p) + HOURS_RIGHT_MARGIN);
    mHoursWidth = Math.max(MIN_HOURS_WIDTH, mHoursWidth);

    LayoutInflater inflater;
    inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    Resources.Theme dialogTheme = getResources().newTheme();
    dialogTheme.applyStyle(android.R.style.Theme_Dialog, true);
    TypedArray ta = dialogTheme.obtainStyledAttributes(new int[] { android.R.attr.windowBackground });

    // Catch long clicks for creating a new event
    mBaseDate = new Time(DayUtils.getTimeZone(context, mTZUpdater));
    long millis = System.currentTimeMillis();
    mBaseDate.set(millis);

    mEarliestStartHour = new int[mNumDays];
    mHasAllDayEvent = new boolean[mNumDays];

    // mLines is the array of points used with Canvas.drawLines() in
    // drawGridBackground() and drawAllDayEvents().  Its size depends
    // on the max number of lines that can ever be drawn by any single
    // drawLines() call in either of those methods.
    final int maxGridLines = (24 + 1) // max horizontal lines we might draw
            + (mNumDays + 1); // max vertical lines we might draw
    mLines = new float[maxGridLines * 4];
}

From source file:com.demo.digit_dayview.EventResourceFromJson.java

@Override
public List<Event> get(int startJulianDay, int numDays, Predicate continueLoading) {

    // Get the data from our separate thread
    try {/* w w w .j  a  v a 2  s  .  c  om*/
        new RetrieveFromJSON().execute().get();
    } catch (InterruptedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (ExecutionException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    // Debug statements
    /*
    Log.d("event array", event_name_list.toString());
    Log.d("start times", start_time_list.toString());
    Log.d("end times", end_time_list.toString());
            
    Log.d("test", event_name_list.get(0));
    Log.d("test2", start_time_list.get(2));
            
    Log.d("sizeof array", "size: " + event_name_list.size());
    */

    List<Event> events = Lists.newArrayList();

    int startHours, endHours, startMinutes, endMinutes;

    for (int i = 0; i < numDays; i++) {

        // Make new time for the day
        Time scratch = new Time();
        Event e;

        // Start adding the list of events from JSON
        for (int j = 0; j < event_name_list.size(); j++) {

            // Create the event
            e = new Event();

            e.setAllDay(false);
            e.setEndDay(startJulianDay + i);
            e.setId(j + 1L);

            // Calculating the height of event by time
            Double endTime = Double.parseDouble(end_time_list.get(j));
            Double startTime = Double.parseDouble(start_time_list.get(j));

            // Check whether or not there is a dot character
            // first for end time, then for start time
            if (end_time_list.get(j).contains(".")) {
                String[] time = end_time_list.get(j).split("\\.");

                // Make into hours and minutes from the time array
                endHours = Integer.parseInt(time[0]);
                endMinutes = Integer.parseInt(time[1]);

                // Append . in minutes
                String myMinute = "." + endMinutes;

                // Parse the minute string
                Double calculatedMinute = Double.parseDouble(myMinute) * 60;
                //Log.d("the end time", "j:" + j + " " + (int) (endHours * 60 + calculatedMinute));

                // Set the end time from the minutes and hours
                e.setEndTime((int) (endHours * 60 + calculatedMinute));
            } else {
                endHours = Integer.parseInt(end_time_list.get(j));
                e.setEndTime(endHours * 60 - 1);
                //Log.d("the end time without min", "j:" + j + " " + (endHours * 60));
            }

            e.setStartDay(startJulianDay + i);

            if (start_time_list.get(j).contains(".")) {
                // Same idea as above in check list
                String[] time = start_time_list.get(j).split("\\.");

                startHours = Integer.parseInt(time[0]);
                startMinutes = Integer.parseInt(time[1]);

                String myMinute = "." + startMinutes;

                Double calculatedMinute = Double.parseDouble(myMinute) * 60;

                e.setStartTime((int) (startHours * 60 + calculatedMinute));
                //Log.d("the start time (Y-coord)", "j:" + j + " " + (int) (startHours * 60 + calculatedMinute));
            } else {
                startHours = Integer.parseInt(start_time_list.get(j));
                e.setStartTime(startHours * 60);
                //Log.d("the start time without min (Y-coord)", "j:" + j + " " + (startHours * 60));
            }

            Log.d("Y coordinate in time", start_time_list.get(j));

            e.setColor(randomColour());

            // At the first event of the day, start the day
            if (j == 0)
                scratch.setJulianDay(startJulianDay + i);

            // Allocate the times
            scratch.hour = startHours;
            scratch.minute = e.getStartTime() % 60;
            e.setStartMillis(scratch.toMillis(false));
            scratch.hour = endHours;
            scratch.minute = e.getEndTime() % 60;
            e.setEndMillis(scratch.toMillis(false));

            Log.d("height in time", ("" + (endTime - startTime)));

            e.setTitle(event_name_list.get(j));
            //Log.d("event name", event_name_list.get(j));
            events.add(e);

        }
    }

    Collections.sort(events, new Comparator<Event>() {

        @Override
        public int compare(Event lhs, Event rhs) {
            long l = lhs.getStartMillis() - rhs.getStartMillis();
            if (l < 0) {
                return -1;
            } else if (l > 0) {
                return 1;
            } else
                return 0;
        }
    });

    return events;

}