List of usage examples for android.graphics Canvas getWidth
public int getWidth()
From source file:net.exclaimindustries.geohashdroid.wiki.WikiPictureEditor.java
private static void drawStrings(String[] strings, Canvas c, Paint textPaint, Paint backgroundPaint) { // FIXME: The math here is ugly and blunt and probably not too // efficient or flexible. It might even fail. This needs to be // fixed and made less-ugly later. // We need SOME strings. If we've got nothing, bail out. if (strings.length < 1) return;//from w w w . j a v a 2 s. c o m // First, init our variables. This is as good a place as any to do so. Rect textBounds = new Rect(); int[] heights = new int[strings.length]; int totalHeight = INFOBOX_MARGIN * 2; int longestWidth = 0; // Now, loop through the strings, adding to the height and keeping track // of the longest width. int i = 0; for (String s : strings) { textPaint.getTextBounds(s, 0, s.length(), textBounds); if (textBounds.width() > longestWidth) longestWidth = textBounds.width(); totalHeight += textBounds.height(); heights[i] = textBounds.height(); i++; } // Now, we have us a rectangle. Draw that. Rect drawBounds = new Rect(c.getWidth() - longestWidth - (INFOBOX_MARGIN * 2), 0, c.getWidth(), totalHeight); c.drawRect(drawBounds, backgroundPaint); // Now, place each of the strings. We'll assume the topmost one is in // index 0. They should all be left-justified, too. i = 0; int curHeight = 0; for (String s : strings) { Log.d(DEBUG_TAG, "Drawing " + s + " at " + (drawBounds.left + INFOBOX_MARGIN) + "," + (INFOBOX_MARGIN + (INFOBOX_PADDING * (i + 1)) + curHeight)); c.drawText(s, drawBounds.left + INFOBOX_MARGIN, INFOBOX_MARGIN + (INFOBOX_PADDING * (i + 1)) + curHeight, textPaint); curHeight += heights[i]; i++; } }
From source file:com.semfapp.adamdilger.semf.Take5PdfDocument.java
public PdfDocument createDocument() { //create new document PdfDocument document = new PdfDocument(); // crate a page description PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(A4_WIDTH, A4_HEIGHT, 1).create(); // start a page PdfDocument.Page page = document.startPage(pageInfo); can = page.getCanvas();//www . ja v a2 s.c o m Paint paint = new Paint(); paint.setStrokeWidth(0.5f); paint.setColor(Color.BLACK); paint.setStyle(Paint.Style.STROKE); can.drawRect(1, 1, 594, 395, paint); /** * Page one Text Fields */ drawText("Job Reference:", 9, 21, FONT14, carlitoBold); drawText("Date:", 354, 21, FONT14, carlitoBold); drawText("Time:", 473, 21, FONT14, carlitoBold); drawText("Location:", 9, 48, FONT14, carlitoBold); drawText("Task:", 261, 48, FONT14, carlitoBold); paint.setPathEffect(new DashPathEffect(new float[] { 1.5f, 1 }, 0)); can.drawLine(85, 36, 350, 36, paint); can.drawLine(386, 36, 468, 36, paint); can.drawLine(506, 36, 585, 36, paint); can.drawLine(59, 60, 256, 60, paint); can.drawLine(291, 60, 585, 60, paint); if (mEditTextValues[0] != null) { drawText(mEditTextValues[0], 98, 19, FONT14, roboto); } if (mEditTextValues[1] != null) { drawText(mEditTextValues[1], 65, 44, FONT14, roboto); } if (mEditTextValues[2] != null) { drawText(mEditTextValues[2], 297, 44, FONT14, roboto); } drawText(mDateString, 390, 19, FONT14, roboto); drawText(mTimeString, 509, 19, FONT14, roboto); /** * Section One (Stop, step back...) */ drawHeader1(8, 69, 202, "Stop, step back and think", 1); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(0.35f); paint.setPathEffect(null); int left, top; //draw left boxes left = 177; top = 108; for (int x = 0; x < mCheckBoxSectionOne.size(); x++) { Take5Data.CheckValue isYes = mCheckBoxSectionOne.get(x).getCheckValue(); float topLoc = top + (x * 33); if (x < 1) { //allowing for different 1st row size drawBox(left, topLoc, paint, true, isYes); } else { float newTop = topLoc - 6; if (x < 3) { drawBox(left, newTop, paint, false, isYes); } else { drawBox(left, newTop, paint, true, isYes); } } } DashPathEffect pathEffect = new DashPathEffect(new float[] { 1, 1.5f }, 0); drawText(mCheckBoxSectionOne.get(0).getHeading(), 13, 113, FONT12, carlitoBold); for (int x = 1; x < mCheckBoxSectionOne.size(); x++) { int height = 132 + ((x - 1) * 33); drawText(mCheckBoxSectionOne.get(x).getHeading(), 13, height, FONT12, carlitoBold); paint.setPathEffect(pathEffect); can.drawLine(10, height - 6, 222, height - 6, paint); paint.setPathEffect(null); } /** * Section Two (Identidy the Hazards...) */ drawHeader1(230, 69, 345, "Identify the hazard(s)", 2); //draw right boxes left = 542; top = 104; for (int x = 0; x < mCheckBoxSectionTwo.size(); x++) { float topLoc = top + (x * 20.7f); Take5Data.CheckValue isYes = mCheckBoxSectionTwo.get(x).getCheckValue(); drawBox(left, topLoc, paint, false, isYes); } for (int x = 0; x < mCheckBoxSectionTwo.size(); x++) { float height = 105 + (x * 20.7f); drawText(mCheckBoxSectionTwo.get(x).getHeading(), 238, height + 3, FONT12, carlitoBold); if (x > 0) { paint.setPathEffect(pathEffect); can.drawLine(238, height - 4, 581, height - 4, paint); paint.setPathEffect(null); } } /** * draw section 3,4,5 (including checkboxes) */ drawSmallCircle(8, 331, "Assess the level of risk", 3); drawSmallCircle(202, 331, "Control the hazards", 4); drawSmallCircle(398, 331, "Proceed safely", 5); /** * Draw Page Two */ int xLoc = 7; int yLoc = 420; int height; int width = 565; int RADIUS = 14; float INNER_RADIUS = 13; int centre = yLoc + 7 + RADIUS; width = xLoc + width; int middle = width - 340; can.drawRect(1, 420, 594, 420 + 395, paint); paint.setStyle(Paint.Style.FILL); paint.setTypeface(impact); paint.setTextSize(12); can.drawCircle(xLoc + RADIUS, centre, RADIUS, paint); can.drawRect(xLoc + RADIUS, centre - RADIUS, width, centre + RADIUS, paint); can.drawCircle(width, centre, RADIUS, paint); paint.setColor(Color.WHITE); can.drawCircle(xLoc + RADIUS, centre, INNER_RADIUS, paint); can.drawCircle(width, centre, INNER_RADIUS, paint); can.drawRect(middle, centre - INNER_RADIUS, width, centre + INNER_RADIUS, paint); paint.setColor(Color.BLACK); can.drawCircle(middle, centre, RADIUS, paint); paint.setColor(Color.WHITE); can.drawText("SAFE WORK METHOD STATEMENT (SWMS)", xLoc + 31, centre + 5, paint); paint.setTextSize(16); paint.setColor(Color.BLACK); can.drawText(String.valueOf(4), xLoc + RADIUS - 4, centre + 6, paint); height = 50; drawText("What are the hazards and risks?", 25, yLoc + height, FONT12, carlitoBold); drawText("Risk\nRating", 267, yLoc + 47, FONT12, carlitoBold); drawText("How will hazards and risks be controlled?", 319, yLoc + height, FONT12, carlitoBold); paint.setPathEffect(pathEffect); can.drawLine(262, yLoc + 45, 262, yLoc + 320, paint); can.drawLine(302, yLoc + 45, 302, yLoc + 320, paint); paint.setPathEffect(null); float currentItemHeight = yLoc + 75; float padding = 5; for (int x = 0; x < mRiskElements.size(); x++) { int textHeight = (int) currentItemHeight; float totalItemHeight = drawRiskElement(textHeight, mRiskElements.get(x)); currentItemHeight += totalItemHeight + padding; } paint.setPathEffect(pathEffect); height = yLoc + 350; drawText("Name/s:", 12, height, FONT12, carlitoBold); drawText(mEditTextValues[3], 55, height - 3, FONT14, roboto); paint.setPathEffect(pathEffect); can.drawLine(50, height + 12, 580, height + 12, paint); paint.setPathEffect(null); height = yLoc + 372; drawText("Signatures:", 12, height, FONT12, carlitoBold); drawText("Date:", 468, height, FONT12, carlitoBold); drawText(mDateString, 497, height - 3, FONT14, roboto); paint.setPathEffect(pathEffect); can.drawLine(60, height + 12, 464, height + 12, paint); can.drawLine(492, height + 12, 580, height + 12, paint); paint.setPathEffect(null); // finish the page document.finishPage(page); int imagePageCount = 2; for (Take5RiskElement risk : mRiskElements) { if (risk.imagePath != null) { // crate a page description PdfDocument.PageInfo pageInfo1 = new PdfDocument.PageInfo.Builder(A4_WIDTH, A4_HEIGHT, imagePageCount).create(); PdfDocument.Page imagePage = document.startPage(pageInfo1); Canvas canvas = imagePage.getCanvas(); try { Bitmap original = BitmapFactory.decodeFile(risk.imagePath); Bitmap b = resize(original, canvas.getWidth() - 100, canvas.getHeight() - 100); canvas.drawBitmap(b, 50, 60, new Paint()); // canvas.drawText(risk.getOne(), 50, 40, new Paint()); Path textPath = new Path(); textPath.moveTo(50, 50); textPath.lineTo(canvas.getWidth() - 100, 50); canvas.drawTextOnPath(risk.getOne(), textPath, 0, 0, new Paint()); } catch (Exception e) { e.printStackTrace(); } document.finishPage(imagePage); imagePageCount++; new File(risk.imagePath).delete(); } } // add more pages return document; }
From source file:com.augustopicciani.drawablepageindicator.widget.DrawablePagerIndicator.java
/** * @param canvas/* w ww .j a v a 2 s . c om*/ */ @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return; } final int count = mViewPager.getAdapter().getCount(); if (count == 0) { return; } if (mCurrentPage >= count) { setCurrentItem(count - 1); return; } float dx = -1; Bitmap imageChildDefault = BitmapFactory.decodeResource(mContext.getResources(), drawableDefaultId); Bitmap imageChildSelected = BitmapFactory.decodeResource(mContext.getResources(), drawableSelectedId); Bitmap imageToDraw; int imageSize = imageChildDefault.getWidth(); int canvasWidth = canvas.getWidth(); int circlesWith = (imageSize * count) + imageSpacing * (count - 1); int startingPoint = (canvasWidth - circlesWith) / 2; for (int i = 0; i < count; i++) { if (i == 0) { dx = 0; } /** * position images indicator on the center */ if (mCentered) { dx = startingPoint + i * (imageSize + imageSpacing); } if (mCurrentPage == i) { imageToDraw = imageChildSelected; } else { imageToDraw = imageChildDefault; } canvas.drawBitmap(imageToDraw, dx, 0, null); /** * position images indicator from the left */ if (!mCentered) { dx += imageChildDefault.getWidth() + imageSpacing; } } }
From source file:de.grobox.liberario.activities.MapActivity.java
private Bitmap getBitmap(Drawable drawable) { Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);// www . j a va 2 s . co m Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return bitmap; }
From source file:com.shizhefei.view.coolrefreshview.header.JellyHeader.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int totalDistance = totalDistance(); int headerHeight; int pullHeight; int offsetToKeepHeaderWhileLoading = offsetToKeepHeaderWhileLoading(); if (status == CoolRefreshView.PULL_STATUS_REFRESHING) { headerHeight = offsetToKeepHeaderWhileLoading; pullHeight = currentDistance;//from w w w. j a v a2s. c om } else { headerHeight = Math.min(currentDistance / 2, offsetToKeepHeaderWhileLoading); pullHeight = currentDistance; } if (headerHeight == 0) { return; } int saveCount = canvas.save(); canvas.translate(0, totalDistance - currentDistance); final int width = canvas.getWidth(); //??touchx ????touchx?? mPointX = width / 2; final float mDisplayX = (mPointX - width / 2f) * 0.5f + width / 2f; mPaint.setColor(mColor); mPath.rewind(); // ? mPath.moveTo(0, 0); mPath.lineTo(0, headerHeight); // ??? mPath.quadTo(mDisplayX, pullHeight, width, headerHeight); mPath.lineTo(width, 0); mPath.close(); canvas.drawPath(mPath, mPaint); canvas.restoreToCount(saveCount); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setOutlineProvider(mViewOutlineProvider); } }
From source file:com.hxsn.witwork.ui.ViewfinderView.java
@Override public void onDraw(Canvas canvas) { // ??????CameraManager? if (CameraManager.get() == null) { return;// ww w. j a va 2s . com } Rect frame = CameraManager.get().getFramingRect(); if (frame == null) { return; } // ? if (!isFirst) { isFirst = true; slideTop = frame.top; slideBottom = frame.bottom; } // ?? int width = canvas.getWidth(); int height = canvas.getHeight(); paint.setColor(resultBitmap != null ? resultColor : maskColor); // ????????????? // ????????? canvas.drawRect(0, 0, width, frame.top + 15, paint); canvas.drawRect(0, frame.top + 15, frame.left + 15, frame.bottom - 14, paint); canvas.drawRect(frame.right - 14, frame.top + 15, width, frame.bottom - 14, paint); canvas.drawRect(0, frame.bottom - 14, width, height, paint); if (resultBitmap != null) { // Draw the opaque result bitmap over the scanning rectangle paint.setAlpha(OPAQUE); canvas.drawBitmap(resultBitmap, frame.left, frame.top, paint); } else { // ??8 paint.setColor(Color.rgb(139, 193, 17)); canvas.drawRect(frame.left, frame.top, frame.left + ScreenRate, frame.top + CORNER_WIDTH, paint); canvas.drawRect(frame.left, frame.top, frame.left + CORNER_WIDTH, frame.top + ScreenRate, paint); canvas.drawRect(frame.right - ScreenRate, frame.top, frame.right, frame.top + CORNER_WIDTH, paint); canvas.drawRect(frame.right - CORNER_WIDTH, frame.top, frame.right, frame.top + ScreenRate, paint); canvas.drawRect(frame.left, frame.bottom - CORNER_WIDTH, frame.left + ScreenRate, frame.bottom, paint); canvas.drawRect(frame.left, frame.bottom - ScreenRate, frame.left + CORNER_WIDTH, frame.bottom, paint); canvas.drawRect(frame.right - ScreenRate, frame.bottom - CORNER_WIDTH, frame.right, frame.bottom, paint); canvas.drawRect(frame.right - CORNER_WIDTH, frame.bottom - ScreenRate, frame.right, frame.bottom, paint); // ,??SPEEN_DISTANCE slideTop += SPEEN_DISTANCE; if (slideTop >= frame.bottom) { slideTop = frame.top; } // canvas.drawRect(frame.left + MIDDLE_LINE_PADDING, slideTop - // MIDDLE_LINE_WIDTH/2, frame.right - MIDDLE_LINE_PADDING,slideTop + // MIDDLE_LINE_WIDTH/2, paint); Rect lineRect = new Rect(); lineRect.left = frame.left; lineRect.right = frame.right; lineRect.top = slideTop; lineRect.bottom = slideTop + 18; canvas.drawBitmap(((BitmapDrawable) (getResources().getDrawable(R.drawable.fgx))).getBitmap(), null, lineRect, paint); // ??? paint.setColor(Color.WHITE); paint.setTextSize(TEXT_SIZE * density); // paint.setAlpha(0x40); // paint.setTypeface(Typeface.create("System", Typeface.BOLD)); canvas.drawText("?/??????", frame.left, (float) (frame.bottom + (float) TEXT_PADDING_TOP * density), paint); canvas.drawText("??" + num + "", frame.left, (float) (frame.bottom + (float) TEXT_PADDING_TOP * density + 50), paint); int max = 7; if (name.size() < max) { max = name.size(); for (int i = 0; i < max; i++) { canvas.drawText(name.get(i), frame.left, (float) (frame.bottom + (float) TEXT_PADDING_TOP * density + 100 + 50 * i), paint); } } else { for (int i = 6; i >= 0; i--) { canvas.drawText(name.get((name.size() - 1) - (6 - i)), frame.left, (float) (frame.bottom + (float) TEXT_PADDING_TOP * density + 100 + 50 * i), paint); } } paint.setStyle(Style.STROKE); canvas.drawRect(frame.left + 15, frame.top + 15, frame.right - 15, frame.bottom - 15, paint); setViewY(frame.bottom); paint.setStyle(Style.FILL); Collection<ResultPoint> currentPossible = possibleResultPoints; Collection<ResultPoint> currentLast = lastPossibleResultPoints; if (currentPossible.isEmpty()) { lastPossibleResultPoints = null; } else { possibleResultPoints = new HashSet<ResultPoint>(5); lastPossibleResultPoints = currentPossible; paint.setAlpha(OPAQUE); paint.setColor(resultPointColor); for (ResultPoint point : currentPossible) { canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 6.0f, paint); } } if (currentLast != null) { paint.setAlpha(OPAQUE / 2); paint.setColor(resultPointColor); for (ResultPoint point : currentLast) { canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 3.0f, paint); } } // ???? postInvalidate(); // postInvalidateDelayed(ANIMATION_DELAY, frame.left, frame.top, // frame.right, frame.bottom); } }
From source file:com.concavenp.artistrymuse.fragments.BaseFragment.java
private BitmapImageViewTarget createBitmapImageViewTarget(final ImageView imageView) { return new BitmapImageViewTarget(imageView) { @Override/*from w ww . j a va 2 s . com*/ protected void setResource(Bitmap bitmap) { int bitmapWidth = bitmap.getWidth(); int bitmapHeight = bitmap.getHeight(); int borderWidthHalf = 5; int bitmapSquareWidth = Math.min(bitmapWidth, bitmapHeight); int newBitmapSquare = bitmapSquareWidth + borderWidthHalf; Bitmap roundedBitmap = Bitmap.createBitmap(newBitmapSquare, newBitmapSquare, Bitmap.Config.ARGB_8888); // Initialize a new Canvas to draw empty bitmap Canvas canvas = new Canvas(roundedBitmap); // Calculation to draw bitmap at the circular bitmap center position int x = borderWidthHalf + bitmapSquareWidth - bitmapWidth; int y = borderWidthHalf + bitmapSquareWidth - bitmapHeight; canvas.drawBitmap(bitmap, x, y, null); // Initializing a new Paint instance to draw circular border Paint borderPaint = new Paint(); borderPaint.setStyle(Paint.Style.STROKE); borderPaint.setStrokeWidth(borderWidthHalf * 2); borderPaint.setColor(ResourcesCompat.getColor(getResources(), R.color.myApp_accent_700, null)); canvas.drawCircle(canvas.getWidth() / 2, canvas.getWidth() / 2, newBitmapSquare / 2, borderPaint); RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), roundedBitmap); circularBitmapDrawable.setCircular(true); imageView.setImageDrawable(circularBitmapDrawable); } }; }
From source file:de.gebatzens.sia.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { setTheme(SIAApp.SIA_APP.school.getTheme()); super.onCreate(savedInstanceState); Log.w("ggvp", "CREATE NEW MAINACTIVITY"); //Debug.startMethodTracing("sia3"); SIAApp.SIA_APP.activity = this; savedState = savedInstanceState;// w w w .j a v a2 s . co m final FragmentData.FragmentList fragments = SIAApp.SIA_APP.school.fragments; Intent intent = getIntent(); if (intent != null && intent.getStringExtra("fragment") != null) { FragmentData frag = fragments .getByType(FragmentData.FragmentType.valueOf(intent.getStringExtra("fragment"))).get(0); SIAApp.SIA_APP.setFragmentIndex(fragments.indexOf(frag)); } if (intent != null && intent.getBooleanExtra("reload", false)) { SIAApp.SIA_APP.refreshAsync(null, true, fragments.get(SIAApp.SIA_APP.getFragmentIndex())); intent.removeExtra("reload"); } setContentView(R.layout.activity_main); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); mContent = getFragment(); transaction.replace(R.id.content_fragment, mContent, "gg_content_fragment"); transaction.commit(); Log.d("ggvp", "DATA: " + fragments.get(SIAApp.SIA_APP.getFragmentIndex()).getData()); if (fragments.get(SIAApp.SIA_APP.getFragmentIndex()).getData() == null) SIAApp.SIA_APP.refreshAsync(null, true, fragments.get(SIAApp.SIA_APP.getFragmentIndex())); if ("Summer".equals(SIAApp.SIA_APP.getCurrentThemeName())) { ImageView summerNavigationPalm = (ImageView) findViewById(R.id.summer_navigation_palm); summerNavigationPalm.setImageResource(R.drawable.summer_palm); ImageView summerBackgroundImage = (ImageView) findViewById(R.id.summer_background_image); summerBackgroundImage.setImageResource(R.drawable.summer_background); } mToolBar = (Toolbar) findViewById(R.id.toolbar); mToolBar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.action_refresh: ((SwipeRefreshLayout) mContent.getView().findViewById(R.id.refresh)).setRefreshing(true); SIAApp.SIA_APP.refreshAsync(new Runnable() { @Override public void run() { ((SwipeRefreshLayout) mContent.getView().findViewById(R.id.refresh)) .setRefreshing(false); } }, true, fragments.get(SIAApp.SIA_APP.getFragmentIndex())); return true; case R.id.action_settings: Intent i = new Intent(MainActivity.this, SettingsActivity.class); startActivityForResult(i, 1); return true; case R.id.action_addToCalendar: showExamDialog(); return true; case R.id.action_help: AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle(getApplication().getString(R.string.help)); builder.setMessage(getApplication().getString(R.string.exam_explain)); builder.setPositiveButton(getApplication().getString(R.string.close), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); return true; } return false; } }); updateToolbar(SIAApp.SIA_APP.school.name, fragments.get(SIAApp.SIA_APP.getFragmentIndex()).name); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { SIAApp.SIA_APP.setStatusBarColorTransparent(getWindow()); // because of the navigation drawer } mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolBar, R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.addDrawerListener(mDrawerToggle); navigationView = (NavigationView) findViewById(R.id.navigation_view); mNavigationHeader = navigationView.getHeaderView(0); mNavigationSchoolpictureText = (TextView) mNavigationHeader.findViewById(R.id.drawer_image_text); mNavigationSchoolpictureText.setText(SIAApp.SIA_APP.school.name); mNavigationSchoolpicture = (ImageView) mNavigationHeader.findViewById(R.id.navigation_schoolpicture); mNavigationSchoolpicture.setImageBitmap(SIAApp.SIA_APP.school.loadImage()); mNavigationSchoolpictureLink = mNavigationHeader.findViewById(R.id.navigation_schoolpicture_link); mNavigationSchoolpictureLink.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View viewIn) { mDrawerLayout.closeDrawers(); Intent linkIntent = new Intent(Intent.ACTION_VIEW); linkIntent.setData(Uri.parse(SIAApp.SIA_APP.school.website)); startActivity(linkIntent); } }); final Menu menu = navigationView.getMenu(); menu.clear(); for (int i = 0; i < fragments.size(); i++) { MenuItem item = menu.add(R.id.fragments, Menu.NONE, i, fragments.get(i).name); item.setIcon(fragments.get(i).getIconRes()); } menu.add(R.id.settings, R.id.settings_item, fragments.size(), R.string.settings); menu.setGroupCheckable(R.id.fragments, true, true); menu.setGroupCheckable(R.id.settings, false, false); final Menu navMenu = navigationView.getMenu(); selectedItem = SIAApp.SIA_APP.getFragmentIndex(); if (selectedItem != -1) navMenu.getItem(selectedItem).setChecked(true); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { if (menuItem.getItemId() == R.id.settings_item) { mDrawerLayout.closeDrawers(); Intent i = new Intent(MainActivity.this, SettingsActivity.class); startActivityForResult(i, 1); } else { final int index = menuItem.getOrder(); if (SIAApp.SIA_APP.getFragmentIndex() != index) { SIAApp.SIA_APP.setFragmentIndex(index); menuItem.setChecked(true); updateToolbar(SIAApp.SIA_APP.school.name, menuItem.getTitle().toString()); mContent = getFragment(); Animation fadeOut = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_out); fadeOut.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { FrameLayout contentFrame = (FrameLayout) findViewById(R.id.content_fragment); contentFrame.setVisibility(View.INVISIBLE); if (fragments.get(index).getData() == null) SIAApp.SIA_APP.refreshAsync(null, true, fragments.get(index)); //removeAllFragments(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.content_fragment, mContent, "gg_content_fragment"); transaction.commit(); snowView.updateSnow(); } @Override public void onAnimationRepeat(Animation animation) { } }); FrameLayout contentFrame = (FrameLayout) findViewById(R.id.content_fragment); contentFrame.startAnimation(fadeOut); mDrawerLayout.closeDrawers(); } else { mDrawerLayout.closeDrawers(); } } return true; } }); if (Build.VERSION.SDK_INT >= 25) { ShortcutManager shortcutManager = getSystemService(ShortcutManager.class); shortcutManager.removeAllDynamicShortcuts(); for (int i = 0; i < fragments.size(); i++) { Drawable drawable = getDrawable(fragments.get(i).getIconRes()); Bitmap icon; if (drawable instanceof VectorDrawable) { icon = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(icon); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); } else { icon = BitmapFactory.decodeResource(getResources(), fragments.get(i).getIconRes()); } Bitmap connectedIcon = Bitmap.createBitmap(icon.getWidth(), icon.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(connectedIcon); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.parseColor("#f5f5f5")); canvas.drawCircle(icon.getWidth() / 2, icon.getHeight() / 2, icon.getWidth() / 2, paint); paint.setColorFilter( new PorterDuffColorFilter(SIAApp.SIA_APP.school.getColor(), PorterDuff.Mode.SRC_ATOP)); canvas.drawBitmap(icon, null, new RectF(icon.getHeight() / 4.0f, icon.getHeight() / 4.0f, icon.getHeight() - icon.getHeight() / 4.0f, icon.getHeight() - icon.getHeight() / 4.0f), paint); Intent newTaskIntent = new Intent(this, MainActivity.class); newTaskIntent.setAction(Intent.ACTION_MAIN); newTaskIntent.putExtra("fragment", fragments.get(i).type.toString()); ShortcutInfo shortcut = new ShortcutInfo.Builder(this, fragments.get(i).name) .setShortLabel(fragments.get(i).name).setLongLabel(fragments.get(i).name) .setIcon(Icon.createWithBitmap(connectedIcon)).setIntent(newTaskIntent).build(); shortcutManager.addDynamicShortcuts(Arrays.asList(shortcut)); } } if (SIAApp.SIA_APP.preferences.getBoolean("app_130_upgrade", true)) { if (!SIAApp.SIA_APP.preferences.getBoolean("first_use_filter", true)) { TextDialog.newInstance(R.string.upgrade1_3title, R.string.upgrade1_3) .show(getSupportFragmentManager(), "upgrade_dialog"); } SIAApp.SIA_APP.preferences.edit().putBoolean("app_130_upgrade", false).apply(); } snowView = (SnowView) findViewById(R.id.snow_view); shareToolbar = (Toolbar) findViewById(R.id.share_toolbar); shareToolbar.getMenu().clear(); shareToolbar.inflateMenu(R.menu.share_toolbar_menu); shareToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { toggleShareToolbar(false); for (Shareable s : MainActivity.this.shared) { s.setMarked(false); } MainActivity.this.shared.clear(); mContent.updateFragment(); } }); shareToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { toggleShareToolbar(false); HashMap<Date, ArrayList<Shareable>> dates = new HashMap<Date, ArrayList<Shareable>>(); for (Shareable s : MainActivity.this.shared) { ArrayList<Shareable> list = dates.get(s.getDate()); if (list == null) { list = new ArrayList<Shareable>(); dates.put(s.getDate(), list); } list.add(s); s.setMarked(false); } MainActivity.this.shared.clear(); List<Date> dateList = new ArrayList<Date>(dates.keySet()); Collections.sort(dateList); String content = ""; for (Date key : dateList) { content += SubstListAdapter.translateDay(key) + "\n\n"; Collections.sort(dates.get(key)); for (Shareable s : dates.get(key)) { content += s.getShareContent() + "\n"; } content += "\n"; } content = content.substring(0, content.length() - 1); mContent.updateFragment(); if (item.getItemId() == R.id.action_copy) { ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(getString(R.string.entries), content); clipboard.setPrimaryClip(clip); } else if (item.getItemId() == R.id.action_share) { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, content); sendIntent.setType("text/plain"); startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to))); } return true; } }); if (shared.size() > 0) { shareToolbar.setVisibility(View.VISIBLE); updateShareToolbarText(); } // if a fragment is opened via a notification or a shortcut reset the shared entries // delete extra fragment because the same intent is used when the device gets rotated and the user could have opened a new fragment if (intent != null && intent.hasExtra("fragment")) { resetShareToolbar(); intent.removeExtra("fragment"); } }
From source file:com.astir_trotter.atcustom.ui.iconics.core.IconicsDrawable.java
/** * Creates a BitMap to use in Widgets or anywhere else * * @return bitmap to set/*from w ww. j a va 2 s. co m*/ */ public Bitmap toBitmap() { if (mSizeX == -1 || mSizeY == -1) { this.actionBar(); } final Bitmap bitmap = Bitmap.createBitmap(this.getIntrinsicWidth(), this.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); this.style(Paint.Style.FILL); final Canvas canvas = new Canvas(bitmap); this.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); this.draw(canvas); return bitmap; }
From source file:com.xbm.android.matisse.internal.ui.widget.CheckView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // draw outer and inner shadow initShadowPaint();// w w w .j a v a 2 s . co m canvas.drawCircle((float) SIZE * mDensity / 2, (float) SIZE * mDensity / 2, (STROKE_RADIUS + STROKE_WIDTH / 2 + SHADOW_WIDTH) * mDensity, mShadowPaint); // draw white stroke canvas.drawCircle((float) SIZE * mDensity / 2, (float) SIZE * mDensity / 2, STROKE_RADIUS * mDensity, mStrokePaint); // draw content if (mCountable) { if (mCheckedNum != UNCHECKED) { initBackgroundPaint(); canvas.drawCircle((float) SIZE * mDensity / 2, (float) SIZE * mDensity / 2, BG_RADIUS * mDensity, mBackgroundPaint); initTextPaint(); String text = String.valueOf(mCheckedNum); int baseX = (int) (canvas.getWidth() - mTextPaint.measureText(text)) / 2; int baseY = (int) (canvas.getHeight() - mTextPaint.descent() - mTextPaint.ascent()) / 2; canvas.drawText(text, baseX, baseY, mTextPaint); } } else { if (mChecked) { initBackgroundPaint(); canvas.drawCircle((float) SIZE * mDensity / 2, (float) SIZE * mDensity / 2, BG_RADIUS * mDensity, mBackgroundPaint); mCheckDrawable.setBounds(getCheckRect()); mCheckDrawable.draw(canvas); } } // enable hint setAlpha(mEnabled ? 1.0f : 0.5f); }