List of usage examples for android.graphics Paint setFakeBoldText
public void setFakeBoldText(boolean fakeBoldText)
From source file:fr.magistry.taigime.CandidateView.java
/** * If the canvas is null, then only touch calculations are performed to pick the target * candidate./* w w w .j a v a2 s .c o m*/ */ @Override protected void onDraw(Canvas canvas) { if (canvas != null) { super.onDraw(canvas); } mTotalWidth = 0; if (mSuggestions == null) return; if (mBgPadding == null) { mBgPadding = new Rect(0, 0, 0, 0); if (getBackground() != null) { getBackground().getPadding(mBgPadding); } } int x = 0; final int count = mSuggestions.size(); final int height = getHeight(); final Rect bgPadding = mBgPadding; final Paint paint = mPaint; final int touchX = mTouchX; final int scrollX = getScrollX(); final boolean scrolled = mScrolled; final int y; //= (int) ( - mPaint.ascent() + mVerticalPadding); final int y2; //= (int) (height - mPaintTRS.descent()); // (y - mVerticalPadding - mPaint.descent() - mPaintTRS.ascent()) ; final float initialTRSsize = mPaintTRS.getTextSize(); if (mOutputTRS) { y2 = (int) (-mPaintTRS.ascent() + mVerticalPadding); y = (int) (height - mPaint.descent()); } else { y = (int) (-mPaint.ascent() + mVerticalPadding); y2 = (int) (height - mPaintTRS.descent()); } for (int i = 0; i < count; i++) { Candidate suggestion = mSuggestions.get(i); String hanji = suggestion.getWord().getHanji(); String trs = ""; switch (ROMANISATION_OUTPUT_MODE) { case 0: trs = suggestion.getWord().getTailuo(); break; case 1: trs = suggestion.getWord().getPOJ(); break; case 2: trs = suggestion.getWord().getPOJ_safe(); break; default: trs = suggestion.getWord().getTailuo(); } float textWidth; if (i == 0) { hanji = ""; trs = "";//hanji;//TODO: conversion? //if(mOutputTRS){ trs = suggestion.getWord().getBopomo(); if (trs != "") textWidth = mPaintBPM.measureText(trs); else textWidth = 3; //} //else { // hanji = suggestion.getWord().getBopomo(); // textWidth = paint.measureText(hanji); //} } else textWidth = paint.measureText(hanji); if (textWidth == 0.0) textWidth = paint.measureText(" "); final int wordWidth = (int) textWidth + X_GAP * 2; mWordX[i] = x; mWordWidth[i] = wordWidth; mPaintTRS.setTextSize(initialTRSsize); mPaintTRS.setTextSize(reduceTextSizeFromWidth(mPaintTRS, trs, textWidth)); paint.setColor(mColorNormal); if (touchX + scrollX >= x && touchX + scrollX < x + wordWidth && !scrolled) { if (canvas != null) { canvas.translate(x, 0); mSelectionHighlight.setBounds(0, bgPadding.top, wordWidth, height); mSelectionHighlight.draw(canvas); canvas.translate(-x, 0); } mSelectedIndex = i; } if (canvas != null) { Paint activePaint = null; Paint secondPaint = null; if (mOutputTRS) { activePaint = mPaintTRS; secondPaint = paint; } else { activePaint = paint; secondPaint = mPaintTRS; } if (i == 0) { activePaint = mPaintBPM; } secondPaint.setAlpha(150); if ((i == mCursor)) { activePaint.setFakeBoldText(true); activePaint.setColor(mColorRecommended); } else if (i != 0) { activePaint.setColor(mColorOther); } if (i == 0) { canvas.drawText(trs, x + X_GAP, y2, mPaintBPM); } else { canvas.drawText(hanji, x + X_GAP, y, paint); canvas.drawText(trs, x + X_GAP, y2, mPaintTRS); } activePaint.setColor(mColorOther); canvas.drawLine(x + wordWidth + 0.5f, bgPadding.top, x + wordWidth + 0.5f, height + 1, paint); activePaint.setFakeBoldText(false); secondPaint.setAlpha(255); } x += wordWidth; mPaintTRS.setTextSize(initialTRSsize); } mTotalWidth = x; if (mTargetScrollX != getScrollX()) { scrollToTarget(); } }
From source file:com.metinkale.prayerapp.vakit.fragments.MainFragment.java
private void export(int csvpdf, LocalDate from, LocalDate to) throws IOException { File outputDir = getActivity().getCacheDir(); if (!outputDir.exists()) outputDir.mkdirs();/*from w w w.ja v a2 s. c o m*/ File outputFile = new File(outputDir, mTimes.getName().replace(" ", "_") + (csvpdf == 0 ? ".csv" : ".pdf")); if (outputDir.exists()) outputFile.delete(); FileOutputStream outputStream; outputStream = new FileOutputStream(outputFile); if (csvpdf == 0) { outputStream.write("Date;Fajr;Shuruq;Dhuhr;Asr;Maghrib;Ishaa\n".getBytes()); do { outputStream.write((from.toString("yyyy-MM-dd") + ";").getBytes()); outputStream.write((mTimes.getTime(from, 0) + ";").getBytes()); outputStream.write((mTimes.getTime(from, 1) + ";").getBytes()); outputStream.write((mTimes.getTime(from, 2) + ";").getBytes()); outputStream.write((mTimes.getTime(from, 3) + ";").getBytes()); outputStream.write((mTimes.getTime(from, 4) + ";").getBytes()); outputStream.write((mTimes.getTime(from, 5) + "\n").getBytes()); } while (!(from = from.plusDays(1)).isAfter(to)); outputStream.close(); } else { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { PdfDocument document = new PdfDocument(); PdfDocument.PageInfo pageInfo = null; int pw = 595; int ph = 842; pageInfo = new PdfDocument.PageInfo.Builder(pw, ph, 1).create(); PdfDocument.Page page = document.startPage(pageInfo); Drawable launcher = Drawable.createFromStream(getActivity().getAssets().open("pdf/launcher.png"), null); Drawable qr = Drawable.createFromStream(getActivity().getAssets().open("pdf/qrcode.png"), null); Drawable badge = Drawable.createFromStream( getActivity().getAssets().open("pdf/badge_" + Prefs.getLanguage() + ".png"), null); launcher.setBounds(30, 30, 30 + 65, 30 + 65); qr.setBounds(pw - 30 - 65, 30 + 65 + 5, pw - 30, 30 + 65 + 5 + 65); int w = 100; int h = w * badge.getIntrinsicHeight() / badge.getIntrinsicWidth(); badge.setBounds(pw - 30 - w, 30 + (60 / 2 - h / 2), pw - 30, 30 + (60 / 2 - h / 2) + h); Canvas canvas = page.getCanvas(); Paint paint = new Paint(); paint.setARGB(255, 0, 0, 0); paint.setTextSize(10); paint.setTextAlign(Paint.Align.CENTER); canvas.drawText("com.metinkale.prayer", pw - 30 - w / 2, 30 + (60 / 2 - h / 2) + h + 10, paint); launcher.draw(canvas); qr.draw(canvas); badge.draw(canvas); paint.setARGB(255, 61, 184, 230); canvas.drawRect(30, 30 + 60, pw - 30, 30 + 60 + 5, paint); if (mTimes.getSource().resId != 0) { Drawable source = getResources().getDrawable(mTimes.getSource().resId); h = 65; w = h * source.getIntrinsicWidth() / source.getIntrinsicHeight(); source.setBounds(30, 30 + 65 + 5, 30 + w, 30 + 65 + 5 + h); source.draw(canvas); } paint.setARGB(255, 0, 0, 0); paint.setTextSize(40); paint.setTextAlign(Paint.Align.LEFT); canvas.drawText(getText(R.string.appName).toString(), 30 + 65 + 5, 30 + 50, paint); paint.setTextAlign(Paint.Align.CENTER); paint.setFakeBoldText(true); canvas.drawText(mTimes.getName(), pw / 2.0f, 30 + 65 + 50, paint); paint.setTextSize(12); int y = 30 + 65 + 5 + 65 + 30; int p = 30; int cw = (pw - p - p) / 7; canvas.drawText(getString(R.string.date), 30 + (0.5f * cw), y, paint); canvas.drawText(Vakit.IMSAK.getString(), 30 + (1.5f * cw), y, paint); canvas.drawText(Vakit.GUNES.getString(), 30 + (2.5f * cw), y, paint); canvas.drawText(Vakit.OGLE.getString(), 30 + (3.5f * cw), y, paint); canvas.drawText(Vakit.IKINDI.getString(), 30 + (4.5f * cw), y, paint); canvas.drawText(Vakit.AKSAM.getString(), 30 + (5.5f * cw), y, paint); canvas.drawText(Vakit.YATSI.getString(), 30 + (6.5f * cw), y, paint); paint.setFakeBoldText(false); do { y += 20; canvas.drawText((from.toString("dd.MM.yyyy")), 30 + (0.5f * cw), y, paint); canvas.drawText((mTimes.getTime(from, 0)), 30 + (1.5f * cw), y, paint); canvas.drawText((mTimes.getTime(from, 1)), 30 + (2.5f * cw), y, paint); canvas.drawText((mTimes.getTime(from, 2)), 30 + (3.5f * cw), y, paint); canvas.drawText((mTimes.getTime(from, 3)), 30 + (4.5f * cw), y, paint); canvas.drawText((mTimes.getTime(from, 4)), 30 + (5.5f * cw), y, paint); canvas.drawText((mTimes.getTime(from, 5)), 30 + (6.5f * cw), y, paint); } while (!(from = from.plusDays(1)).isAfter(to)); document.finishPage(page); document.writeTo(outputStream); // close the document document.close(); } else { Toast.makeText(getActivity(), R.string.versionNotSupported, Toast.LENGTH_LONG).show(); } } Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setType(csvpdf == 0 ? "text/csv" : "application/pdf"); Uri uri = FileProvider.getUriForFile(getActivity(), "com.metinkale.prayer.fileprovider", outputFile); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.export))); }
From source file:net.toload.main.hd.candidate.CandidateView.java
private void doDraw(Canvas canvas) { if (mSuggestions == null) return;//from w w w . ja v a2s .co m if (DEBUG) Log.i(TAG, "CandidateView:doDraw():Suggestion mCount:" + mCount + " mSuggestions.size:" + mSuggestions.size()); mTotalWidth = 0; updateFontSize(); if (mBgPadding == null) { mBgPadding = new Rect(0, 0, 0, 0); if (getBackground() != null) { getBackground().getPadding(mBgPadding); } } final int height = mHeight; final Rect bgPadding = mBgPadding; final Paint candidatePaint = mCandidatePaint; final Paint candidateEmojiPaint = mCandidatePaint; candidateEmojiPaint.setTextSize((float) (candidateEmojiPaint.getTextSize() * 0.9)); final Paint selKeyPaint = mSelKeyPaint; final int touchX = mTouchX; final int scrollX = getScrollX(); final boolean scrolled = mScrolled; final int textBaseLine = (int) (((height - mCandidatePaint.getTextSize()) / 2) - mCandidatePaint.ascent()); // Modified by jeremy '10, 3, 29. Update mselectedindex if touched and build wordX[i] and wordwidth[i] int x = 0; final int count = mCount; //Cache count here '11,8,18 for (int i = 0; i < count; i++) { if (count != mCount || mSuggestions == null || count != mSuggestions.size() || mSuggestions.size() == 0 || i >= mSuggestions.size()) return; // mSuggestion is updated, force abort String suggestion = mSuggestions.get(i).getWord(); if (i == 0 && mSuggestions.size() > 1 && mSuggestions.get(1).isRuntimeBuiltPhraseRecord() && suggestion.length() > 8) { suggestion = suggestion.substring(0, 2) + ".."; } float base = (suggestion == null) ? 0 : candidatePaint.measureText(""); float textWidth = (suggestion == null) ? 0 : candidatePaint.measureText(suggestion); if (textWidth < base) { textWidth = base; } final int wordWidth = (int) textWidth + X_GAP * 2; mWordX[i] = x; mWordWidth[i] = wordWidth; if (touchX + scrollX >= x && touchX + scrollX < x + wordWidth && !scrolled) { mSelectedIndex = i; } x += wordWidth; } mTotalWidth = x; if (DEBUG) Log.i(TAG, "CandidateView:doDraw():mTotalWidth :" + mTotalWidth + " this.getWidth():" + this.getWidth()); //Jeremy '11,8,11. If the candidate list is within 1 page and has more records, get full records first. if (mTotalWidth < this.getWidth()) checkHasMoreRecords(); // Paint all the suggestions and lines. if (canvas != null) { // Moved from above by jeremy '10 3, 29. Paint mSelectedindex in highlight here if (count > 0 && mSelectedIndex >= 0) { // candidatePaint.setColor(mColorComposingCode); // canvas.drawRect(mWordX[mSelectedIndex],bgPadding.top, mWordWidth[mSelectedIndex] , height, candidatePaint); canvas.translate(mWordX[mSelectedIndex], 0); mDrawableSuggestHighlight.setBounds(0, bgPadding.top, mWordWidth[mSelectedIndex], height); mDrawableSuggestHighlight.draw(canvas); canvas.translate(-mWordX[mSelectedIndex], 0); } if (mTransparentCandidateView) { canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); Paint backgroundPaint = new Paint(); backgroundPaint.setColor(ContextCompat.getColor(mContext, R.color.third_background_light)); backgroundPaint.setAlpha(33); backgroundPaint.setStyle(Paint.Style.FILL); canvas.drawRect(0.5f, bgPadding.top, mScreenWidth, height, backgroundPaint); } for (int i = 0; i < count; i++) { if (count != mCount || mSuggestions == null || count != mSuggestions.size() || mSuggestions.size() == 0 || i >= mSuggestions.size()) break; boolean isEmoji = mSuggestions.get(i).isEmojiRecord(); String suggestion = mSuggestions.get(i).getWord(); if (i == 0 && mSuggestions.size() > 1 && mSuggestions.get(1).isRuntimeBuiltPhraseRecord() && suggestion.length() > 8) { suggestion = suggestion.substring(0, 2) + ".."; } int c = i + 1; switch (mSuggestions.get(i).getRecordType()) { case Mapping.RECORD_COMPOSING_CODE: if (mSelectedIndex == 0) { if (mTransparentCandidateView) { candidatePaint.setColor(mColorInvertedTextTransparent); } else { candidatePaint.setColor(mColorComposingCodeHighlight); } } else candidatePaint.setColor(mColorComposingCode); break; case Mapping.RECORD_CHINESE_PUNCTUATION_SYMBOL: case Mapping.RECORD_RELATED_PHRASE: selKeyPaint.setColor(mColorSelKeyShifted); if (i == mSelectedIndex) candidatePaint.setColor(mColorNormalTextHighlight); else candidatePaint.setColor(mColorNormalText); break; case Mapping.RECORD_EXACT_MATCH_TO_CODE: case Mapping.RECORD_PARTIAL_MATCH_TO_CODE: case Mapping.RECORD_RUNTIME_BUILT_PHRASE: case Mapping.RECORD_ENGLISH_SUGGESTION: default: selKeyPaint.setColor(mColorSelKey); if (i == mSelectedIndex) candidatePaint.setColor(mColorNormalTextHighlight); else candidatePaint.setColor(mColorNormalText); break; } if (isEmoji) { canvas.drawText(suggestion, mWordX[i] + X_GAP, Math.round(textBaseLine * 0.95), candidateEmojiPaint); } else { canvas.drawText(suggestion, mWordX[i] + X_GAP, textBaseLine, candidatePaint); } if (mShowNumber) { //Jeremy '11,6,17 changed from <=10 to mDisplaySelkey length. The length maybe 11 or 12 if shifted with space. if (c <= mDisplaySelkey.length()) { //Jeremy '11,6,11 Drawing text using relative font dimensions. canvas.drawText(mDisplaySelkey.substring(c - 1, c), mWordX[i] + mWordWidth[i] - height * 0.3f, height * 0.4f, selKeyPaint); } } //Draw spacer candidatePaint.setColor(mColorSpacer); canvas.drawLine(mWordX[i] + mWordWidth[i] + 0.5f, bgPadding.top + (mVerticalPadding / 2), mWordX[i] + mWordWidth[i] + 0.5f, height - (mVerticalPadding / 2), candidatePaint); candidatePaint.setFakeBoldText(false); } if (mTargetScrollX != getScrollX()) { if (DEBUG) Log.i(TAG, "CandidateView:doDraw():mTargetScrollX :" + mTargetScrollX + " getScrollX():" + getScrollX()); scrollToTarget(); } } }