use of android.text.StaticLayout in project Notes by Elder-Wu.
the class CountDownView method init.
private void init() {
circlePaint = new Paint();
circlePaint.setAntiAlias(true);
circlePaint.setDither(true);
circlePaint.setColor(backgroundColor);
circlePaint.setStyle(Paint.Style.FILL);
textPaint = new TextPaint();
textPaint.setAntiAlias(true);
textPaint.setDither(true);
textPaint.setColor(textColor);
textPaint.setTextSize(textSize);
textPaint.setTextAlign(Paint.Align.CENTER);
borderPaint = new Paint();
borderPaint.setAntiAlias(true);
borderPaint.setDither(true);
borderPaint.setColor(borderColor);
borderPaint.setStrokeWidth(borderWidth);
borderPaint.setStyle(Paint.Style.STROKE);
int textWidth = (int) textPaint.measureText(text.substring(0, (text.length() + 1) / 2));
staticLayout = new StaticLayout(text, textPaint, textWidth, Layout.Alignment.ALIGN_NORMAL, 1F, 0, false);
}
use of android.text.StaticLayout in project Etar-Calendar by Etar-Group.
the class DayView method drawAllDayEvents.
private void drawAllDayEvents(int firstDay, int numDays, Canvas canvas, Paint p) {
p.setTextSize(NORMAL_FONT_SIZE);
p.setTextAlign(Paint.Align.LEFT);
Paint eventTextPaint = mEventTextPaint;
final float startY = DAY_HEADER_HEIGHT;
final float stopY = startY + mAlldayHeight + ALLDAY_TOP_MARGIN;
float x = 0;
int linesIndex = 0;
// Draw the inner vertical grid lines
p.setColor(mCalendarGridLineInnerVerticalColor);
x = mHoursWidth;
p.setStrokeWidth(GRID_LINE_INNER_WIDTH);
// Line bounding the top of the all day area
mLines[linesIndex++] = GRID_LINE_LEFT_MARGIN;
mLines[linesIndex++] = startY;
mLines[linesIndex++] = computeDayLeftPosition(mNumDays);
mLines[linesIndex++] = startY;
for (int day = 0; day <= mNumDays; day++) {
x = computeDayLeftPosition(day);
mLines[linesIndex++] = x;
mLines[linesIndex++] = startY;
mLines[linesIndex++] = x;
mLines[linesIndex++] = stopY;
}
p.setAntiAlias(false);
canvas.drawLines(mLines, 0, linesIndex, p);
p.setStyle(Style.FILL);
int y = DAY_HEADER_HEIGHT + ALLDAY_TOP_MARGIN;
int lastDay = firstDay + numDays - 1;
final ArrayList<Event> events = mAllDayEvents;
int numEvents = events.size();
// Whether or not we should draw the more events text
boolean hasMoreEvents = false;
// size of the allDay area
float drawHeight = mAlldayHeight;
// max number of events being drawn in one day of the allday area
float numRectangles = mMaxAlldayEvents;
// Where to cut off drawn allday events
int allDayEventClip = DAY_HEADER_HEIGHT + mAlldayHeight + ALLDAY_TOP_MARGIN;
// The number of events that weren't drawn in each day
mSkippedAlldayEvents = new int[numDays];
if (mMaxAlldayEvents > mMaxUnexpandedAlldayEventCount && !mShowAllAllDayEvents && mAnimateDayHeight == 0) {
// We draw one fewer event than will fit so that more events text
// can be drawn
numRectangles = mMaxUnexpandedAlldayEventCount - 1;
// We also clip the events above the more events text
allDayEventClip -= MIN_UNEXPANDED_ALLDAY_EVENT_HEIGHT;
hasMoreEvents = true;
} else if (mAnimateDayHeight != 0) {
// clip at the end of the animating space
allDayEventClip = DAY_HEADER_HEIGHT + mAnimateDayHeight + ALLDAY_TOP_MARGIN;
}
int alpha = eventTextPaint.getAlpha();
eventTextPaint.setAlpha(mEventsAlpha);
for (int i = 0; i < numEvents; i++) {
Event event = events.get(i);
int startDay = event.startDay;
int endDay = event.endDay;
if (startDay > lastDay || endDay < firstDay) {
continue;
}
if (startDay < firstDay) {
startDay = firstDay;
}
if (endDay > lastDay) {
endDay = lastDay;
}
int startIndex = startDay - firstDay;
int endIndex = endDay - firstDay;
float height = mMaxAlldayEvents > mMaxUnexpandedAlldayEventCount ? mAnimateDayEventHeight : drawHeight / numRectangles;
// Prevent a single event from getting too big
if (height > MAX_HEIGHT_OF_ONE_ALLDAY_EVENT) {
height = MAX_HEIGHT_OF_ONE_ALLDAY_EVENT;
}
// Leave a one-pixel space between the vertical day lines and the
// event rectangle.
event.left = computeDayLeftPosition(startIndex);
event.right = computeDayLeftPosition(endIndex + 1) - DAY_GAP;
event.top = y + height * event.getColumn();
event.bottom = event.top + height - ALL_DAY_EVENT_RECT_BOTTOM_MARGIN;
if (mMaxAlldayEvents > mMaxUnexpandedAlldayEventCount) {
// not animating.
if (event.top >= allDayEventClip) {
incrementSkipCount(mSkippedAlldayEvents, startIndex, endIndex);
continue;
} else if (event.bottom > allDayEventClip) {
if (hasMoreEvents) {
incrementSkipCount(mSkippedAlldayEvents, startIndex, endIndex);
continue;
}
event.bottom = allDayEventClip;
}
}
Rect r = drawEventRect(event, canvas, p, eventTextPaint, (int) event.top, (int) event.bottom);
setupAllDayTextRect(r);
StaticLayout layout = getEventLayout(mAllDayLayouts, i, event, eventTextPaint, r);
drawEventText(layout, r, canvas, r.top, r.bottom, true);
// Check if this all-day event intersects the selected day
if (mSelectionAllday && mComputeSelectedEvents) {
if (startDay <= mSelectionDay && endDay >= mSelectionDay) {
mSelectedEvents.add(event);
}
}
}
eventTextPaint.setAlpha(alpha);
if (mMoreAlldayEventsTextAlpha != 0 && mSkippedAlldayEvents != null) {
// If the more allday text should be visible, draw it.
alpha = p.getAlpha();
p.setAlpha(mEventsAlpha);
p.setColor(mMoreAlldayEventsTextAlpha << 24 & mMoreEventsTextColor);
for (int i = 0; i < mSkippedAlldayEvents.length; i++) {
if (mSkippedAlldayEvents[i] > 0) {
drawMoreAlldayEvents(canvas, mSkippedAlldayEvents[i], i, p);
}
}
p.setAlpha(alpha);
}
if (mSelectionAllday) {
// Compute the neighbors for the list of all-day events that
// intersect the selected day.
computeAllDayNeighbors();
// Set the selection position to zero so that when we move down
// to the normal event area, we will highlight the topmost event.
saveSelectionPosition(0f, 0f, 0f, 0f);
}
}
use of android.text.StaticLayout in project Etar-Calendar by Etar-Group.
the class DayView method drawEvents.
private void drawEvents(int date, int dayIndex, int top, Canvas canvas, Paint p) {
Paint eventTextPaint = mEventTextPaint;
int left = computeDayLeftPosition(dayIndex) + 1;
int cellWidth = computeDayLeftPosition(dayIndex + 1) - left + 1;
int cellHeight = mCellHeight;
// Use the selected hour as the selection region
Rect selectionArea = mSelectionRect;
selectionArea.top = top + mSelectionHour * (cellHeight + HOUR_GAP);
selectionArea.bottom = selectionArea.top + cellHeight;
selectionArea.left = left;
selectionArea.right = selectionArea.left + cellWidth;
final ArrayList<Event> events = mEvents;
int numEvents = events.size();
EventGeometry geometry = mEventGeometry;
final int viewEndY = mViewStartY + mViewHeight - DAY_HEADER_HEIGHT - mAlldayHeight;
int alpha = eventTextPaint.getAlpha();
eventTextPaint.setAlpha(mEventsAlpha);
for (int i = 0; i < numEvents; i++) {
Event event = events.get(i);
if (!geometry.computeEventRect(date, left, top, cellWidth, event)) {
continue;
}
// Don't draw it if it is not visible
if (event.bottom < mViewStartY || event.top > viewEndY) {
continue;
}
if (date == mSelectionDay && !mSelectionAllday && mComputeSelectedEvents && geometry.eventIntersectsSelection(event, selectionArea)) {
mSelectedEvents.add(event);
}
Rect r = drawEventRect(event, canvas, p, eventTextPaint, mViewStartY, viewEndY);
setupTextRect(r);
// Don't draw text if it is not visible
if (r.top > viewEndY || r.bottom < mViewStartY) {
continue;
}
StaticLayout layout = getEventLayout(mLayouts, i, event, eventTextPaint, r);
// TODO: not sure why we are 4 pixels off
drawEventText(layout, r, canvas, mViewStartY + 4, mViewStartY + mViewHeight - DAY_HEADER_HEIGHT - mAlldayHeight, false);
}
eventTextPaint.setAlpha(alpha);
if (date == mSelectionDay && !mSelectionAllday && isFocused() && mSelectionMode != SELECTION_HIDDEN) {
computeNeighbors();
}
}
use of android.text.StaticLayout in project Etar-Calendar by Etar-Group.
the class DayView method reloadEvents.
/* package */
void reloadEvents() {
// Protect against this being called before this view has been
// initialized.
// if (mContext == null) {
// return;
// }
// Make sure our time zones are up to date
mTZUpdater.run();
setSelectedEvent(null);
mPrevSelectedEvent = null;
mSelectedEvents.clear();
// The start date is the beginning of the week at 12am
Time weekStart = new Time(Utils.getTimeZone(mContext, mTZUpdater));
weekStart.set(mBaseDate);
weekStart.hour = 0;
weekStart.minute = 0;
weekStart.second = 0;
long millis = weekStart.normalize(true);
// Avoid reloading events unnecessarily.
if (millis == mLastReloadMillis) {
return;
}
mLastReloadMillis = millis;
// load events in the background
// mContext.startProgressSpinner();
final ArrayList<Event> events = new ArrayList<Event>();
mEventLoader.loadEventsInBackground(mNumDays, events, mFirstJulianDay, new Runnable() {
public void run() {
boolean fadeinEvents = mFirstJulianDay != mLoadedFirstJulianDay;
mEvents = events;
mLoadedFirstJulianDay = mFirstJulianDay;
if (mAllDayEvents == null) {
mAllDayEvents = new ArrayList<Event>();
} else {
mAllDayEvents.clear();
}
// Create a shorter array for all day events
for (Event e : events) {
if (e.drawAsAllday()) {
mAllDayEvents.add(e);
}
}
// New events, new layouts
if (mLayouts == null || mLayouts.length < events.size()) {
mLayouts = new StaticLayout[events.size()];
} else {
Arrays.fill(mLayouts, null);
}
if (mAllDayLayouts == null || mAllDayLayouts.length < mAllDayEvents.size()) {
mAllDayLayouts = new StaticLayout[events.size()];
} else {
Arrays.fill(mAllDayLayouts, null);
}
computeEventRelations();
mRemeasure = true;
mComputeSelectedEvents = true;
recalc();
// Start animation to cross fade the events
if (fadeinEvents) {
if (mEventsCrossFadeAnimation == null) {
mEventsCrossFadeAnimation = ObjectAnimator.ofInt(DayView.this, "EventsAlpha", 0, 255);
mEventsCrossFadeAnimation.setDuration(EVENTS_CROSS_FADE_DURATION);
}
mEventsCrossFadeAnimation.start();
} else {
invalidate();
}
}
}, mCancelCallback);
}
use of android.text.StaticLayout in project android_frameworks_base by DirtyUnicorns.
the class Editor method chooseSize.
private void chooseSize(PopupWindow pop, CharSequence text, TextView tv) {
int wid = tv.getPaddingLeft() + tv.getPaddingRight();
int ht = tv.getPaddingTop() + tv.getPaddingBottom();
int defaultWidthInPixels = mTextView.getResources().getDimensionPixelSize(com.android.internal.R.dimen.textview_error_popup_default_width);
Layout l = new StaticLayout(text, tv.getPaint(), defaultWidthInPixels, Layout.Alignment.ALIGN_NORMAL, 1, 0, true);
float max = 0;
for (int i = 0; i < l.getLineCount(); i++) {
max = Math.max(max, l.getLineWidth(i));
}
/*
* Now set the popup size to be big enough for the text plus the border capped
* to DEFAULT_MAX_POPUP_WIDTH
*/
pop.setWidth(wid + (int) Math.ceil(max));
pop.setHeight(ht + l.getHeight());
}
Aggregations