List of usage examples for android.graphics Canvas drawRoundRect
public void drawRoundRect(@NonNull RectF rect, float rx, float ry, @NonNull Paint paint)
From source file:com.google.android.apps.muzei.gallery.GalleryEmptyStateGraphicView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (!isShown() || mWidth == 0 || mHeight == 0) { return;/* www . j av a 2s .co m*/ } // tick timer long nowElapsed = SystemClock.elapsedRealtime(); if (nowElapsed > mOnTime + ON_TIME_MILLIS + FADE_TIME_MILLIS * 2 + OFF_TIME_MILLIS) { mOnTime = nowElapsed; while (true) { int x = mRandom.nextInt(COLS); int y = mRandom.nextInt(ROWS); if ((x != mOnX || y != mOnY) && BITMAP[y * COLS + x] == 1) { mOnX = x; mOnY = y; break; } } } int t = (int) (nowElapsed - mOnTime); for (int y = 0; y < ROWS; y++) { for (int x = 0; x < COLS; x++) { if (BITMAP[y * COLS + x] != 1) { continue; } mTempRectF.set(x * (mCellSize + mCellSpacing), y * (mCellSize + mCellSpacing), x * (mCellSize + mCellSpacing) + mCellSize, y * (mCellSize + mCellSpacing) + mCellSize); canvas.drawRoundRect(mTempRectF, mCellRounding, mCellRounding, mOffPaint); if (nowElapsed <= mOnTime + ON_TIME_MILLIS + FADE_TIME_MILLIS * 2 && mOnX == x && mOnY == y) { // draw items if (t < FADE_TIME_MILLIS) { mOnPaint.setAlpha(t * 255 / FADE_TIME_MILLIS); } else if (t < FADE_TIME_MILLIS + ON_TIME_MILLIS) { mOnPaint.setAlpha(255); } else { mOnPaint.setAlpha((255 - (t - ON_TIME_MILLIS - FADE_TIME_MILLIS) * 255 / FADE_TIME_MILLIS)); } canvas.drawRoundRect(mTempRectF, mCellRounding, mCellRounding, mOnPaint); } } } postInvalidateOnAnimation(); }
From source file:kr.wdream.storyshop.AndroidUtilities.java
private static Intent createShortcutIntent(long did, boolean forDelete) { Intent shortcutIntent = new Intent(ApplicationLoader.applicationContext, OpenChatReceiver.class); int lower_id = (int) did; int high_id = (int) (did >> 32); TLRPC.User user = null;//ww w .j av a 2 s.com TLRPC.Chat chat = null; if (lower_id == 0) { shortcutIntent.putExtra("encId", high_id); TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat(high_id); if (encryptedChat == null) { return null; } user = MessagesController.getInstance().getUser(encryptedChat.user_id); } else if (lower_id > 0) { shortcutIntent.putExtra("userId", lower_id); user = MessagesController.getInstance().getUser(lower_id); } else if (lower_id < 0) { chat = MessagesController.getInstance().getChat(-lower_id); shortcutIntent.putExtra("chatId", -lower_id); } else { return null; } if (user == null && chat == null) { return null; } String name; TLRPC.FileLocation photo = null; if (user != null) { name = ContactsController.formatName(user.first_name, user.last_name); if (user.photo != null) { photo = user.photo.photo_small; } } else { name = chat.title; if (chat.photo != null) { photo = chat.photo.photo_small; } } shortcutIntent.setAction("com.tmessages.openchat" + did); shortcutIntent.addFlags(0x4000000); Intent addIntent = new Intent(); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name); addIntent.putExtra("duplicate", false); if (!forDelete) { Bitmap bitmap = null; if (photo != null) { try { File path = FileLoader.getPathToAttach(photo, true); bitmap = BitmapFactory.decodeFile(path.toString()); if (bitmap != null) { int size = AndroidUtilities.dp(58); Bitmap result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); result.eraseColor(Color.TRANSPARENT); Canvas canvas = new Canvas(result); BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); if (roundPaint == null) { roundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); bitmapRect = new RectF(); } float scale = size / (float) bitmap.getWidth(); canvas.save(); canvas.scale(scale, scale); roundPaint.setShader(shader); bitmapRect.set(0, 0, bitmap.getWidth(), bitmap.getHeight()); canvas.drawRoundRect(bitmapRect, bitmap.getWidth(), bitmap.getHeight(), roundPaint); canvas.restore(); Drawable drawable = ApplicationLoader.applicationContext.getResources() .getDrawable(R.drawable.book_logo); int w = AndroidUtilities.dp(15); int left = size - w - AndroidUtilities.dp(2); int top = size - w - AndroidUtilities.dp(2); drawable.setBounds(left, top, left + w, top + w); drawable.draw(canvas); try { canvas.setBitmap(null); } catch (Exception e) { //don't promt, this will crash on 2.x } bitmap = result; } } catch (Throwable e) { FileLog.e("tmessages", e); } } if (bitmap != null) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap); } else { if (user != null) { if (user.bot) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_bot)); } else { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_user)); } } else if (chat != null) { if (ChatObject.isChannel(chat) && !chat.megagroup) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_channel)); } else { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_group)); } } } } return addIntent; }
From source file:com.astir_trotter.atcustom.ui.iconics.core.IconicsDrawable.java
@Override public void draw(Canvas canvas) { if (mIcon != null || mPlainIcon != null) { final Rect viewBounds = getBounds(); updatePaddingBounds(viewBounds); updateTextSize(viewBounds);/*from ww w.ja va 2 s . c o m*/ offsetIcon(viewBounds); if (mBackgroundPaint != null && mRoundedCornerRy > -1 && mRoundedCornerRx > -1) { canvas.drawRoundRect(new RectF(0, 0, viewBounds.width(), viewBounds.height()), mRoundedCornerRx, mRoundedCornerRy, mBackgroundPaint); } mPath.close(); if (mDrawContour) { canvas.drawPath(mPath, mContourPaint); } mIconPaint.setAlpha(mAlpha); mIconPaint.setColorFilter(mColorFilter == null ? mTintFilter : mColorFilter); canvas.drawPath(mPath, mIconPaint); } }
From source file:com.appsummary.luoxf.myappsummary.navigationtabstrip.NavigationTabStrip.java
@Override protected void onDraw(final Canvas canvas) { // Set bound of strip mStripBounds.set(mStripLeft - (mStripType == StripType.POINT ? mStripWeight * 0.5F : 0.0F), mStripGravity == StripGravity.BOTTOM ? mBounds.height() - mStripWeight : 0.0F, mStripRight - (mStripType == StripType.POINT ? mStripWeight * 0.5F : 0.0F), mStripGravity == StripGravity.BOTTOM ? mBounds.height() : mStripWeight); // Draw strip if (mCornersRadius == 0) canvas.drawRect(mStripBounds, mStripPaint); else//from w w w . j a va2 s . com canvas.drawRoundRect(mStripBounds, mCornersRadius, mCornersRadius, mStripPaint); // Draw tab titles for (int i = 0; i < mTitles.length; i++) { final String title = mTitles[i]; final float leftTitleOffset = (mTabSize * i) + (mTabSize * 0.5F); mTitlePaint.getTextBounds(title, 0, title.length(), mTitleBounds); final float topTitleOffset = (mBounds.height() - mStripWeight) * 0.5F + mTitleBounds.height() * 0.5F - mTitleBounds.bottom; // Get interpolated fraction for left last and current tab final float interpolation = mResizeInterpolator.getResizeInterpolation(mFraction, true); final float lastInterpolation = mResizeInterpolator.getResizeInterpolation(mFraction, false); // Check if we handle tab from touch on NTS or from ViewPager // There is a strange logic of ViewPager onPageScrolled method, so it is if (mIsSetIndexFromTabBar) { if (mIndex == i) updateCurrentTitle(interpolation); else if (mLastIndex == i) updateLastTitle(lastInterpolation); else updateInactiveTitle(); } else { if (i != mIndex && i != mIndex + 1) updateInactiveTitle(); else if (i == mIndex + 1) updateCurrentTitle(interpolation); else if (i == mIndex) updateLastTitle(lastInterpolation); } canvas.drawText(title, leftTitleOffset, topTitleOffset + (mStripGravity == StripGravity.TOP ? mStripWeight : 0.0F), mTitlePaint); } }
From source file:com.ferdi2005.secondgram.AndroidUtilities.java
private static Intent createShortcutIntent(long did, boolean forDelete) { Intent shortcutIntent = new Intent(ApplicationLoader.applicationContext, OpenChatReceiver.class); int lower_id = (int) did; int high_id = (int) (did >> 32); TLRPC.User user = null;/*from w w w. ja va 2s .c om*/ TLRPC.Chat chat = null; if (lower_id == 0) { shortcutIntent.putExtra("encId", high_id); TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat(high_id); if (encryptedChat == null) { return null; } user = MessagesController.getInstance().getUser(encryptedChat.user_id); } else if (lower_id > 0) { shortcutIntent.putExtra("userId", lower_id); user = MessagesController.getInstance().getUser(lower_id); } else if (lower_id < 0) { chat = MessagesController.getInstance().getChat(-lower_id); shortcutIntent.putExtra("chatId", -lower_id); } else { return null; } if (user == null && chat == null) { return null; } String name; TLRPC.FileLocation photo = null; if (user != null) { name = ContactsController.formatName(user.first_name, user.last_name); if (user.photo != null) { photo = user.photo.photo_small; } } else { name = chat.title; if (chat.photo != null) { photo = chat.photo.photo_small; } } shortcutIntent.setAction("com.tmessages.openchat" + did); shortcutIntent.addFlags(0x4000000); Intent addIntent = new Intent(); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name); addIntent.putExtra("duplicate", false); if (!forDelete) { Bitmap bitmap = null; if (photo != null) { try { File path = FileLoader.getPathToAttach(photo, true); bitmap = BitmapFactory.decodeFile(path.toString()); if (bitmap != null) { int size = AndroidUtilities.dp(58); Bitmap result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); result.eraseColor(Color.TRANSPARENT); Canvas canvas = new Canvas(result); BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); if (roundPaint == null) { roundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); bitmapRect = new RectF(); } float scale = size / (float) bitmap.getWidth(); canvas.save(); canvas.scale(scale, scale); roundPaint.setShader(shader); bitmapRect.set(0, 0, bitmap.getWidth(), bitmap.getHeight()); canvas.drawRoundRect(bitmapRect, bitmap.getWidth(), bitmap.getHeight(), roundPaint); canvas.restore(); Drawable drawable = ApplicationLoader.applicationContext.getResources() .getDrawable(R.drawable.book_logo); int w = AndroidUtilities.dp(15); int left = size - w - AndroidUtilities.dp(2); int top = size - w - AndroidUtilities.dp(2); drawable.setBounds(left, top, left + w, top + w); drawable.draw(canvas); try { canvas.setBitmap(null); } catch (Exception e) { //don't promt, this will crash on 2.x } bitmap = result; } } catch (Throwable e) { FileLog.e(e); } } if (bitmap != null) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap); } else { if (user != null) { if (user.bot) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_bot)); } else { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_user)); } } else if (chat != null) { if (ChatObject.isChannel(chat) && !chat.megagroup) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_channel)); } else { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_group)); } } } } return addIntent; }
From source file:de.vanita5.twittnuker.view.ShapedImageView.java
private void drawBorder(@NonNull final Canvas canvas) { final RectF transitionSrc = mTransitionSource, transitionDst = mTransitionDestination; if (transitionSrc != null && transitionDst != null) { final float progress = 1 - (mDestination.width() - transitionDst.width()) / (transitionSrc.width() - transitionDst.width()); mBorderPaint.setStrokeWidth(mStrokeWidth * progress); mBorderPaint.setAlpha(Math.round(mBorderAlpha * progress)); ViewCompat.setTranslationZ(this, -ViewCompat.getElevation(this) * (1 - progress)); } else {//from ww w . j ava 2s. c om mBorderPaint.setStrokeWidth(mStrokeWidth); mBorderPaint.setAlpha(mBorderAlpha); ViewCompat.setTranslationZ(this, 0); } if (getStyle() == SHAPE_CIRCLE) { canvas.drawCircle(mDestination.centerX(), mDestination.centerY(), mDestination.width() / 2f - mBorderPaint.getStrokeWidth() / 2, mBorderPaint); } else { final float radius = getCalculatedCornerRadius(); canvas.drawRoundRect(mDestination, radius, radius, mBorderPaint); } }
From source file:com.tbse.mywearapplication.WatchFaceDrawer.java
void onDraw(Context context, IWatchFaceConfig config, Canvas canvas, Rect bounds) { final Calendar calendar = config.getCalendar(); final boolean isAmbient = config.isAmbient(); final boolean isRound = config.isRound(); final boolean useLightTheme = !isAmbient && config.isLightTheme(); mBackgroundPaint.setColor(ContextCompat.getColor(context, useLightTheme ? R.color.watchface_background_light : R.color.watchface_background)); ///////////////////////////////////////////////////////////////////// // Draw your watch face here, using the provided canvas and bounds // ///////////////////////////////////////////////////////////////////// final int width = bounds.width(); final int height = bounds.height(); // Find the center. Ignore the window insets so that, on round // watches with a "chin", the watch face is centered on the entire // screen, not just the usable portion. final float centerX = width / 2f; final float centerY = height / 2f; // Draw the background. if (mIsMobilePreview) { if (isRound) { canvas.drawCircle(centerX, centerY, centerX, mPreviewBorderPaint); } else {/*from www .j a va2 s. c om*/ final float radius = mPreviewSquareRadius; final RectF rectF = new RectF(0, 0, canvas.getWidth(), canvas.getHeight()); canvas.drawRoundRect(rectF, radius, radius, mPreviewBorderPaint); } final float translateXY = width * 0.05f; canvas.translate(translateXY, translateXY); canvas.scale(0.9f, 0.9f); if (isRound) { canvas.drawCircle(centerX, centerY, centerX, mBackgroundPaint); } else { canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), mBackgroundPaint); } } else { canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), mBackgroundPaint); } // Draw weather icon if (image != null) { Matrix matrix = new Matrix(); matrix.setTranslate(50, 90); matrix.preScale(0.2f, 0.2f); canvas.drawBitmap(image, matrix, null); } final float secRot = calendar.get(Calendar.SECOND) / 30f * (float) Math.PI; final int minutes = calendar.get(Calendar.MINUTE); final float minRot = minutes / 30f * (float) Math.PI; final float hrRot = ((calendar.get(Calendar.HOUR) + (minutes / 60f)) / 6f) * (float) Math.PI; final float secLength = centerX - mSecondOuterOffset; final float minLength = centerX - mMinuteOuterOffset; final float hrLength = centerX - mHourOuterOffset; if (!isAmbient) { final float secX = (float) Math.sin(secRot) * secLength; final float secY = (float) -Math.cos(secRot) * secLength; canvas.drawLine(centerX, centerY, centerX + secX, centerY + secY, mSecondHandPaint); } final float minX = (float) Math.sin(minRot) * minLength; final float minY = (float) -Math.cos(minRot) * minLength; canvas.drawLine(centerX, centerY, centerX + minX, centerY + minY, mMinuteHandPaint); final float hrX = (float) Math.sin(hrRot) * hrLength; final float hrY = (float) -Math.cos(hrRot) * hrLength; canvas.drawLine(centerX, centerY, centerX + hrX, centerY + hrY, mHourHandPaint); // Draw weather text canvas.drawText(day, 50, 50, isAmbient ? ambientTextPaint : textPaint); canvas.drawText(low, 50, 65, isAmbient ? ambientTextPaint : textPaint); canvas.drawText(high, 80, 65, isAmbient ? ambientTextPaint : textPaint); canvas.drawText(weatherDescription, 50, 80, isAmbient ? ambientTextPaint : textPaint); }
From source file:com.azhansy.linky.view.PagerSlidingIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode()) { return;/*from w w w. j a va 2 s . c om*/ } final int height = getHeight(); float radius = height / 2.0f; drawBackground(canvas); if (pager != null) { // default: line below current tab View currentTab = tabsContainer.getChildAt(currentPosition); float lineLeft = currentTab.getLeft(); float lineRight = currentTab.getRight(); // if there is an offset, start interpolating left and right coordinates between current and next tab if (currentPositionOffset > 0f && currentPosition < tabCount - 1) { View nextTab = tabsContainer.getChildAt(currentPosition + 1); final float nextTabLeft = nextTab.getLeft(); final float nextTabRight = nextTab.getRight(); lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft); lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight); } mTempRectF.set(lineLeft, 0, lineRight, height); checkedBackgroundPaint.setColor(checkedBackgroundColor); canvas.drawRoundRect(mTempRectF, radius, radius, checkedBackgroundPaint); updateTextColor(); } else { View tab = tabsContainer.getChildAt(mNoPagerPosition); float lineLeft = tab.getLeft(); float lineRight = tab.getRight(); mTempRectF.set(lineLeft, 0, lineRight, height); checkedBackgroundPaint.setColor(checkedBackgroundColor); canvas.drawRoundRect(mTempRectF, radius, radius, checkedBackgroundPaint); } }
From source file:com.andexert.calendarlistview.library.SimpleMonthView.java
protected void drawMonthNums(Canvas canvas) { int y = (mRowHeight + MINI_DAY_NUMBER_TEXT_SIZE) / 2 - DAY_SEPARATOR_WIDTH + MONTH_HEADER_SIZE; int paddingDay = (mWidth - 2 * mPadding) / (2 * mNumDays); int dayOffset = findDayOffset(); int day = 1;/*from w w w . ja va2s. c o m*/ String toDayRes = getResources().getString(R.string.today); while (day <= mNumCells) { boolean isShowTrain = true; int x = paddingDay * (1 + dayOffset * 2) + mPadding; if ((mMonth == mSelectedBeginMonth && mSelectedBeginDay == day && mSelectedBeginYear == mYear) || (mMonth == mSelectedLastMonth && mSelectedLastDay == day && mSelectedLastYear == mYear)) { if (mDrawRect) { RectF rectF = new RectF(x - DAY_SELECTED_CIRCLE_SIZE, (y - MINI_DAY_NUMBER_TEXT_SIZE / 3) - DAY_SELECTED_CIRCLE_SIZE, x + DAY_SELECTED_CIRCLE_SIZE, (y - MINI_DAY_NUMBER_TEXT_SIZE / 3) + DAY_SELECTED_CIRCLE_SIZE); canvas.drawRoundRect(rectF, 10.0f, 10.0f, mSelectedCirclePaint); } else { canvas.drawCircle(x, y - MINI_DAY_NUMBER_TEXT_SIZE / 3, DAY_SELECTED_CIRCLE_SIZE, mSelectedCirclePaint); } isShowTrain = false; } if (mHasToday && (mToday == day)) { mMonthNumPaint.setColor(mCurrentDayTextColor); } else { mMonthNumPaint.setColor(mDayNumColor); mMonthNumPaint.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL)); } if ((mMonth == mSelectedBeginMonth && mSelectedBeginDay == day && mSelectedBeginYear == mYear) || (mMonth == mSelectedLastMonth && mSelectedLastDay == day && mSelectedLastYear == mYear)) mMonthNumPaint.setColor(mMonthTitleBGColor); if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear == mSelectedLastYear && mSelectedBeginMonth == mSelectedLastMonth && mSelectedBeginDay == mSelectedLastDay && day == mSelectedBeginDay && mMonth == mSelectedBeginMonth && mYear == mSelectedBeginYear)) { mMonthNumPaint.setColor(mSelectedDaysColor); } //? if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear == mSelectedLastYear && mSelectedBeginYear == mYear) && (((mMonth == mSelectedBeginMonth && mSelectedLastMonth == mSelectedBeginMonth) && ((mSelectedBeginDay < mSelectedLastDay && day > mSelectedBeginDay && day < mSelectedLastDay) || (mSelectedBeginDay > mSelectedLastDay && day < mSelectedBeginDay && day > mSelectedLastDay))) || ((mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedBeginMonth && day > mSelectedBeginDay) || (mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedLastMonth && day < mSelectedLastDay)) || ((mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedBeginMonth && day < mSelectedBeginDay) || (mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedLastMonth && day > mSelectedLastDay)))) { mMonthNumPaint.setColor(mSelectedDaysColor); } if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear != mSelectedLastYear && ((mSelectedBeginYear == mYear && mMonth == mSelectedBeginMonth) || (mSelectedLastYear == mYear && mMonth == mSelectedLastMonth)) && (((mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedBeginMonth && day < mSelectedBeginDay) || (mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedLastMonth && day > mSelectedLastDay)) || ((mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedBeginMonth && day > mSelectedBeginDay) || (mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedLastMonth && day < mSelectedLastDay))))) { mMonthNumPaint.setColor(mSelectedDaysColor); } if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear == mSelectedLastYear && mYear == mSelectedBeginYear) && ((mMonth > mSelectedBeginMonth && mMonth < mSelectedLastMonth && mSelectedBeginMonth < mSelectedLastMonth) || (mMonth < mSelectedBeginMonth && mMonth > mSelectedLastMonth && mSelectedBeginMonth > mSelectedLastMonth))) { mMonthNumPaint.setColor(mSelectedDaysColor); } if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear != mSelectedLastYear) && ((mSelectedBeginYear < mSelectedLastYear && ((mMonth > mSelectedBeginMonth && mYear == mSelectedBeginYear) || (mMonth < mSelectedLastMonth && mYear == mSelectedLastYear))) || (mSelectedBeginYear > mSelectedLastYear && ((mMonth < mSelectedBeginMonth && mYear == mSelectedBeginYear) || (mMonth > mSelectedLastMonth && mYear == mSelectedLastYear))))) { mMonthNumPaint.setColor(mSelectedDaysColor); } if ((!isPrevDayEnabled && prevDay(day, today)) || nextDay(day)) { mMonthNumPaint.setColor(mPreviousDayColor); } if (mHasToday && (mToday == day)) { canvas.drawText(toDayRes, x, y, mMonthNumPaint); } else { canvas.drawText(String.format("%d", day), x, y, mMonthNumPaint); } dayOffset++; if (dayOffset == mNumDays) { dayOffset = 0; y += mRowHeight; } day++; } }
From source file:com.ymt.demo1.customViews.widget.GuideTabStrip.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return;//w ww.jav a 2 s. c o m } final int height = getHeight(); // draw indicator line rectPaint.setColor(indicatorColor); // default: line below current tab View currentTab = tabsContainer.getChildAt(currentPosition); float lineLeft = currentTab.getLeft(); float lineRight = currentTab.getRight(); // if there is an offset, start interpolating left and right coordinates between current and next tab if (currentPositionOffset > 0f && currentPosition < tabCount - 1) { View nextTab = tabsContainer.getChildAt(currentPosition + 1); final float nextTabLeft = nextTab.getLeft(); final float nextTabRight = nextTab.getRight(); lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft); lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight); } // RectF rectF = new RectF(lineLeft, 0, lineRight, height); canvas.drawRoundRect(rectF, 45, 45, rectPaint); }