List of usage examples for android.graphics Canvas drawCircle
public void drawCircle(float cx, float cy, float radius, @NonNull Paint paint)
From source file:com.bolaa.medical.view.banner.CirclePageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return;/* w ww . j ava 2s .com*/ } final int count = mViewPager.getAdapter().getCount(); if (count == 0) { return; } if (mCurrentPage >= count) { setCurrentItem(count - 1); return; } int longSize; int longPaddingBefore; int longPaddingAfter; int shortPaddingBefore; if (mOrientation == HORIZONTAL) { longSize = getWidth(); longPaddingBefore = getPaddingLeft(); longPaddingAfter = getPaddingRight(); shortPaddingBefore = getPaddingTop(); } else { longSize = getHeight(); longPaddingBefore = getPaddingTop(); longPaddingAfter = getPaddingBottom(); shortPaddingBefore = getPaddingLeft(); } final float threeRadius = mRadius * 3; final float shortOffset = shortPaddingBefore + mRadius; float longOffset = longPaddingBefore + mRadius; int longPaddingRight = count * 15; if (mRight) { //todo 1? 2??Indicator longOffset += ((longSize - longPaddingBefore - (longPaddingAfter + longPaddingRight))) - ((count * threeRadius) / 2.0f); } else { longOffset += ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f) - ((count * threeRadius) / 2.0f); } float dX; float dY; float pageFillRadius = mRadius + 1; // if (mPaintStroke.getStrokeWidth() > 0) { // pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f; // } //Draw stroked circle for (int iLoop = 0; iLoop < count; iLoop++) { float drawLong = longOffset + (iLoop * threeRadius); if (mOrientation == HORIZONTAL) { dX = drawLong; dY = shortOffset; } else { dX = shortOffset; dY = drawLong; } // Only paint fill if not completely transparent if (mPaintPageFill.getAlpha() > 0 && isNeedCircle) { // canvas.drawRect(dX, dY, dX + mRadius, dY + mRadius, mPaintPageFill); canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill); } // Only paint stroke if a stroke width was non-zero if (pageFillRadius != mRadius && isNeedCircle) { // canvas.drawRect(dX, dY, dX + mRadius, dY + mRadius, mPaintStroke); canvas.drawCircle(dX, dY, mRadius, mPaintStroke); } } //Draw the filled rect according to the current scroll float cx = (mSnap ? mSnapPage : mCurrentPage) * threeRadius; if (!mSnap && (mPageSize != 0)) { cx += (mCurrentOffset * 1.0f / mPageSize) * threeRadius; } if (mOrientation == HORIZONTAL) { dX = longOffset + cx; dY = shortOffset; } else { dX = shortOffset; dY = longOffset + cx; } // canvas.drawRect(dX, dY, dX + mRadius, dY + mRadius, mPaintFill); if (isNeedCircle) { canvas.drawCircle(dX, dY, mRadius, mPaintFill); } }
From source file:com.bestdo.bestdoStadiums.control.view.CirclePageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return;/* w w w .j a va 2s .c o m*/ } final int count = mViewPager.getAdapter().getCount(); if (count == 0) { return; } // if (mCurrentPage >= count) { // setCurrentItem(count - 1); // return; // } int longSize; int longPaddingBefore; int longPaddingAfter; int shortPaddingBefore; if (mOrientation == HORIZONTAL) { longSize = getWidth(); longPaddingBefore = getPaddingLeft(); longPaddingAfter = getPaddingRight(); shortPaddingBefore = getPaddingTop(); } else { longSize = getHeight(); longPaddingBefore = getPaddingTop(); longPaddingAfter = getPaddingBottom(); shortPaddingBefore = getPaddingLeft(); } final float threeRadius = mRadius * 3; final float shortOffset = shortPaddingBefore + mRadius; float longOffset = longPaddingBefore + mRadius; if (mCentered) { longOffset += ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f) - ((count * threeRadius) / 2.0f); } /** * ?? */ if (rightStatus) { int width = ConfigUtils.getInstance().getPhoneWidHeigth(context).widthPixels; System.err.println(width + "||||||||||||||||||"); System.err.println(longOffset + "||||||||||||||||||"); longOffset = width * 0.25f - ((count * threeRadius)); if (longOffset < 0) { longOffset = 2; } System.err.println(longOffset + "||||||||||||||||||"); } float dX; float dY; float pageFillRadius = mRadius; if (mPaintStroke.getStrokeWidth() > 0) { pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f; } // Draw stroked circles for (int iLoop = 0; iLoop < count; iLoop++) { float drawLong = longOffset + (iLoop * threeRadius); if (mOrientation == HORIZONTAL) { dX = drawLong; dY = shortOffset; } else { dX = shortOffset; dY = drawLong; } // Only paint fill if not completely transparent if (mPaintPageFill.getAlpha() > 0) { canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill); } // Only paint stroke if a stroke width was non-zero if (pageFillRadius != mRadius) { canvas.drawCircle(dX, dY, mRadius, mPaintStroke); } } // Draw the filled circle according to the current scroll float cx = (mSnap ? mSnapPage : (mCurrentPage % mViewPager.getAdapter().getCount())) * threeRadius; if (!mSnap) { cx += mPageOffset * threeRadius; } if (mOrientation == HORIZONTAL) { dX = longOffset + cx; dY = shortOffset; } else { dX = shortOffset; dY = longOffset + cx; } canvas.drawCircle(dX, dY, mRadius, mPaintFill); }
From source file:com.example.anumbrella.viewpager.CirclePagerIndicator.java
/** * /*from w w w.j ava 2s . c o m*/ * * @param canvas */ @Override public 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; } // int longSize; //?padding int longPaddingBefore; //?padding int longPaddingAfter; //?padding int shortPaddingBefore; if (mOrientation == HORIZONTAL) { longSize = getWidth(); longPaddingBefore = getPaddingLeft(); longPaddingAfter = getPaddingRight(); shortPaddingBefore = getPaddingTop(); } else { longSize = getHeight(); longPaddingBefore = getPaddingTop(); longPaddingAfter = getPaddingBottom(); shortPaddingBefore = getPaddingLeft(); } //????? final float threeRadius = mRadius * 3; //????(horizontal???,vertical????) final float shortOffset = shortPaddingBefore + mRadius; //???? float longOffset = longPaddingAfter + mRadius; if (mCentered) { longOffset += ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f) - ((count * threeRadius) / 2.0f); } //x,y?? float dx; float dy; //??? float pageFillRadius = mRadius; if (mPaintStroke.getStrokeWidth() > 0) { pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f; } // for (int iLoop = 0; iLoop < count; iLoop++) { float drawLong = longOffset + (iLoop * threeRadius); if (mOrientation == HORIZONTAL) { dx = drawLong; dy = shortOffset; } else { dx = shortOffset; dy = drawLong; } //???0 if (mPaintPageFill.getAlpha() > 0) { canvas.drawCircle(dx, dy, pageFillRadius, mPaintPageFill); } //??? if (pageFillRadius != mRadius) { canvas.drawCircle(dx, dy, mRadius, mPaintStroke); } } //? float cx = (mSnap ? mSnapPage : mCurrentPage) * threeRadius; if (!mSnap) { cx += mPositionOffset * threeRadius; } if (mOrientation == HORIZONTAL) { dx = longOffset + cx; dy = shortOffset; } else { dx = shortOffset; dy = longOffset + cx; } canvas.drawCircle(dx, dy, mRadius, mPaintFill); }
From source file:org.telegram.ui.Components.ChatAttachAlert.java
public ChatAttachAlert(Context context, final ChatActivity parentFragment) { super(context, false); baseFragment = parentFragment;/* w w w .ja va2 s.c o m*/ setDelegate(this); setUseRevealAnimation(true); checkCamera(false); if (deviceHasGoodCamera) { CameraController.getInstance().initCamera(); } NotificationCenter.getInstance().addObserver(this, NotificationCenter.albumsDidLoaded); NotificationCenter.getInstance().addObserver(this, NotificationCenter.reloadInlineHints); NotificationCenter.getInstance().addObserver(this, NotificationCenter.cameraInitied); shadowDrawable = context.getResources().getDrawable(R.drawable.sheet_shadow); containerView = listView = new RecyclerListView(context) { private int lastWidth; private int lastHeight; @Override public void requestLayout() { if (ignoreLayout) { return; } super.requestLayout(); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (cameraAnimationInProgress) { return true; } else if (cameraOpened) { return processTouchEvent(ev); } else if (ev.getAction() == MotionEvent.ACTION_DOWN && scrollOffsetY != 0 && ev.getY() < scrollOffsetY) { dismiss(); return true; } return super.onInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent event) { if (cameraAnimationInProgress) { return true; } else if (cameraOpened) { return processTouchEvent(event); } return !isDismissed() && super.onTouchEvent(event); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int height = MeasureSpec.getSize(heightMeasureSpec); if (Build.VERSION.SDK_INT >= 21) { height -= AndroidUtilities.statusBarHeight; } int contentSize = backgroundPaddingTop + AndroidUtilities.dp(294) + (SearchQuery.inlineBots.isEmpty() ? 0 : ((int) Math.ceil(SearchQuery.inlineBots.size() / 4.0f) * AndroidUtilities.dp(100) + AndroidUtilities.dp(12))); int padding = contentSize == AndroidUtilities.dp(294) ? 0 : Math.max(0, (height - AndroidUtilities.dp(294))); if (padding != 0 && contentSize < height) { padding -= (height - contentSize); } if (padding == 0) { padding = backgroundPaddingTop; } if (getPaddingTop() != padding) { ignoreLayout = true; setPadding(backgroundPaddingLeft, padding, backgroundPaddingLeft, 0); ignoreLayout = false; } super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(Math.min(contentSize, height), MeasureSpec.EXACTLY)); } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { int width = right - left; int height = bottom - top; int newPosition = -1; int newTop = 0; int count = listView.getChildCount(); int lastVisibleItemPosition = -1; int lastVisibleItemPositionTop = 0; if (count > 0) { View child = listView.getChildAt(listView.getChildCount() - 1); Holder holder = (Holder) listView.findContainingViewHolder(child); if (holder != null) { lastVisibleItemPosition = holder.getAdapterPosition(); lastVisibleItemPositionTop = child.getTop(); } } if (lastVisibleItemPosition >= 0 && height - lastHeight != 0) { newPosition = lastVisibleItemPosition; newTop = lastVisibleItemPositionTop + height - lastHeight - getPaddingTop(); } super.onLayout(changed, left, top, right, bottom); if (newPosition != -1) { ignoreLayout = true; layoutManager.scrollToPositionWithOffset(newPosition, newTop); super.onLayout(false, left, top, right, bottom); ignoreLayout = false; } lastHeight = height; lastWidth = width; updateLayout(); checkCameraViewPosition(); } @Override public void onDraw(Canvas canvas) { if (useRevealAnimation && Build.VERSION.SDK_INT <= 19) { canvas.save(); canvas.clipRect(backgroundPaddingLeft, scrollOffsetY, getMeasuredWidth() - backgroundPaddingLeft, getMeasuredHeight()); if (revealAnimationInProgress) { canvas.drawCircle(revealX, revealY, revealRadius, ciclePaint); } else { canvas.drawRect(backgroundPaddingLeft, scrollOffsetY, getMeasuredWidth() - backgroundPaddingLeft, getMeasuredHeight(), ciclePaint); } canvas.restore(); } else { shadowDrawable.setBounds(0, scrollOffsetY - backgroundPaddingTop, getMeasuredWidth(), getMeasuredHeight()); shadowDrawable.draw(canvas); } } @Override public void setTranslationY(float translationY) { super.setTranslationY(translationY); checkCameraViewPosition(); } }; listView.setWillNotDraw(false); listView.setClipToPadding(false); listView.setLayoutManager(layoutManager = new LinearLayoutManager(getContext())); layoutManager.setOrientation(LinearLayoutManager.VERTICAL); listView.setAdapter(adapter = new ListAdapter(context)); listView.setVerticalScrollBarEnabled(false); listView.setEnabled(true); listView.setGlowColor(0xfff5f6f7); listView.addItemDecoration(new RecyclerView.ItemDecoration() { @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { outRect.left = 0; outRect.right = 0; outRect.top = 0; outRect.bottom = 0; } }); listView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { if (listView.getChildCount() <= 0) { return; } if (hintShowed) { if (layoutManager.findLastVisibleItemPosition() > 1) { hideHint(); hintShowed = false; ApplicationLoader.applicationContext .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).edit() .putBoolean("bothint", true).commit(); } } updateLayout(); checkCameraViewPosition(); } }); containerView.setPadding(backgroundPaddingLeft, 0, backgroundPaddingLeft, 0); attachView = new FrameLayout(context) { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(294), MeasureSpec.EXACTLY)); } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { int width = right - left; int height = bottom - top; int t = AndroidUtilities.dp(8); attachPhotoRecyclerView.layout(0, t, width, t + attachPhotoRecyclerView.getMeasuredHeight()); progressView.layout(0, t, width, t + progressView.getMeasuredHeight()); lineView.layout(0, AndroidUtilities.dp(96), width, AndroidUtilities.dp(96) + lineView.getMeasuredHeight()); hintTextView.layout(width - hintTextView.getMeasuredWidth() - AndroidUtilities.dp(5), height - hintTextView.getMeasuredHeight() - AndroidUtilities.dp(5), width - AndroidUtilities.dp(5), height - AndroidUtilities.dp(5)); int diff = (width - AndroidUtilities.dp(85 * 4 + 20)) / 3; for (int a = 0; a < 8; a++) { int y = AndroidUtilities.dp(105 + 95 * (a / 4)); int x = AndroidUtilities.dp(10) + (a % 4) * (AndroidUtilities.dp(85) + diff); views[a].layout(x, y, x + views[a].getMeasuredWidth(), y + views[a].getMeasuredHeight()); } } }; views[8] = attachPhotoRecyclerView = new RecyclerListView(context); attachPhotoRecyclerView.setVerticalScrollBarEnabled(true); attachPhotoRecyclerView.setAdapter(photoAttachAdapter = new PhotoAttachAdapter(context)); attachPhotoRecyclerView.setClipToPadding(false); attachPhotoRecyclerView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), 0); attachPhotoRecyclerView.setItemAnimator(null); attachPhotoRecyclerView.setLayoutAnimation(null); attachPhotoRecyclerView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER); attachView.addView(attachPhotoRecyclerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 80)); attachPhotoLayoutManager = new LinearLayoutManager(context) { @Override public boolean supportsPredictiveItemAnimations() { return false; } }; attachPhotoLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); attachPhotoRecyclerView.setLayoutManager(attachPhotoLayoutManager); attachPhotoRecyclerView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() { @SuppressWarnings("unchecked") @Override public void onItemClick(View view, int position) { if (baseFragment == null || baseFragment.getParentActivity() == null) { return; } if (!deviceHasGoodCamera || position != 0) { if (deviceHasGoodCamera) { position--; } if (MediaController.allPhotosAlbumEntry == null) { return; } ArrayList<Object> arrayList = (ArrayList) MediaController.allPhotosAlbumEntry.photos; if (position < 0 || position >= arrayList.size()) { return; } PhotoViewer.getInstance().setParentActivity(baseFragment.getParentActivity()); PhotoViewer.getInstance().openPhotoForSelect(arrayList, position, 0, ChatAttachAlert.this, baseFragment); AndroidUtilities.hideKeyboard(baseFragment.getFragmentView().findFocus()); } else { openCamera(); } } }); attachPhotoRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { checkCameraViewPosition(); } }); views[9] = progressView = new EmptyTextProgressView(context); if (Build.VERSION.SDK_INT >= 23 && getContext().checkSelfPermission( Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { progressView.setText(LocaleController.getString("PermissionStorage", R.string.PermissionStorage)); progressView.setTextSize(16); } else { progressView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos)); progressView.setTextSize(20); } attachView.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 80)); attachPhotoRecyclerView.setEmptyView(progressView); views[10] = lineView = new View(getContext()) { @Override public boolean hasOverlappingRendering() { return false; } }; lineView.setBackgroundColor(ContextCompat.getColor(context, R.color.divider)); attachView.addView(lineView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1, Gravity.TOP | Gravity.LEFT)); CharSequence[] items = new CharSequence[] { LocaleController.getString("ChatCamera", R.string.ChatCamera), LocaleController.getString("ChatGallery", R.string.ChatGallery), LocaleController.getString("ChatVideo", R.string.ChatVideo), LocaleController.getString("AttachMusic", R.string.AttachMusic), LocaleController.getString("ChatDocument", R.string.ChatDocument), LocaleController.getString("AttachContact", R.string.AttachContact), LocaleController.getString("ChatLocation", R.string.ChatLocation), "" }; for (int a = 0; a < 8; a++) { AttachButton attachButton = new AttachButton(context); attachButton.setTextAndIcon(items[a], Theme.attachButtonDrawables[a]); attachView.addView(attachButton, LayoutHelper.createFrame(85, 90, Gravity.LEFT | Gravity.TOP)); attachButton.setTag(a); views[a] = attachButton; if (a == 7) { sendPhotosButton = attachButton; sendPhotosButton.imageView.setPadding(0, AndroidUtilities.dp(4), 0, 0); } attachButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { delegate.didPressedButton((Integer) v.getTag()); } }); } hintTextView = new TextView(context); hintTextView.setBackgroundResource(R.drawable.tooltip); hintTextView.setTextColor(Theme.CHAT_GIF_HINT_TEXT_COLOR); hintTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); hintTextView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0); hintTextView.setText(LocaleController.getString("AttachBotsHelp", R.string.AttachBotsHelp)); hintTextView.setGravity(Gravity.CENTER_VERTICAL); hintTextView.setVisibility(View.INVISIBLE); hintTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.scroll_tip, 0, 0, 0); hintTextView.setCompoundDrawablePadding(AndroidUtilities.dp(8)); attachView.addView(hintTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 32, Gravity.RIGHT | Gravity.BOTTOM, 5, 0, 5, 5)); for (int a = 0; a < 8; a++) { viewsCache.add(photoAttachAdapter.createHolder()); } if (loading) { progressView.showProgress(); } else { progressView.showTextView(); } if (Build.VERSION.SDK_INT >= 16) { recordTime = new TextView(context); recordTime.setBackgroundResource(R.drawable.system); recordTime.getBackground() .setColorFilter(new PorterDuffColorFilter(0x66000000, PorterDuff.Mode.MULTIPLY)); recordTime.setText("00:00"); recordTime.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); recordTime.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); recordTime.setAlpha(0.0f); recordTime.setTextColor(0xffffffff); recordTime.setPadding(AndroidUtilities.dp(10), AndroidUtilities.dp(5), AndroidUtilities.dp(10), AndroidUtilities.dp(5)); container.addView(recordTime, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, 16, 0, 0)); cameraPanel = new FrameLayout(context) { @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { int cx = getMeasuredWidth() / 2; int cy = getMeasuredHeight() / 2; int cx2; int cy2; shutterButton.layout(cx - shutterButton.getMeasuredWidth() / 2, cy - shutterButton.getMeasuredHeight() / 2, cx + shutterButton.getMeasuredWidth() / 2, cy + shutterButton.getMeasuredHeight() / 2); if (getMeasuredWidth() == AndroidUtilities.dp(100)) { cx = cx2 = getMeasuredWidth() / 2; cy2 = cy + cy / 2 + AndroidUtilities.dp(17); cy = cy / 2 - AndroidUtilities.dp(17); } else { cx2 = cx + cx / 2 + AndroidUtilities.dp(17); cx = cx / 2 - AndroidUtilities.dp(17); cy = cy2 = getMeasuredHeight() / 2; } switchCameraButton.layout(cx2 - switchCameraButton.getMeasuredWidth() / 2, cy2 - switchCameraButton.getMeasuredHeight() / 2, cx2 + switchCameraButton.getMeasuredWidth() / 2, cy2 + switchCameraButton.getMeasuredHeight() / 2); for (int a = 0; a < 2; a++) { flashModeButton[a].layout(cx - flashModeButton[a].getMeasuredWidth() / 2, cy - flashModeButton[a].getMeasuredHeight() / 2, cx + flashModeButton[a].getMeasuredWidth() / 2, cy + flashModeButton[a].getMeasuredHeight() / 2); } } }; cameraPanel.setVisibility(View.GONE); cameraPanel.setAlpha(0.0f); container.addView(cameraPanel, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 100, Gravity.LEFT | Gravity.BOTTOM)); shutterButton = new ShutterButton(context); cameraPanel.addView(shutterButton, LayoutHelper.createFrame(84, 84, Gravity.CENTER)); shutterButton.setDelegate(new ShutterButton.ShutterButtonDelegate() { @Override public void shutterLongPressed() { if (takingPhoto || baseFragment == null || baseFragment.getParentActivity() == null) { return; } if (Build.VERSION.SDK_INT >= 23) { if (baseFragment.getParentActivity().checkSelfPermission( Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) { baseFragment.getParentActivity() .requestPermissions(new String[] { Manifest.permission.RECORD_AUDIO }, 21); return; } } for (int a = 0; a < 2; a++) { flashModeButton[a].setAlpha(0.0f); } switchCameraButton.setAlpha(0.0f); cameraFile = AndroidUtilities.generateVideoPath(); recordTime.setAlpha(1.0f); recordTime.setText("00:00"); videoRecordTime = 0; videoRecordRunnable = new Runnable() { @Override public void run() { if (videoRecordRunnable == null) { return; } videoRecordTime++; recordTime.setText( String.format("%02d:%02d", videoRecordTime / 60, videoRecordTime % 60)); AndroidUtilities.runOnUIThread(videoRecordRunnable, 1000); } }; AndroidUtilities.lockOrientation(parentFragment.getParentActivity()); CameraController.getInstance().recordVideo(cameraView.getCameraSession(), cameraFile, new CameraController.VideoTakeCallback() { @Override public void onFinishVideoRecording(final Bitmap thumb) { if (cameraFile == null || baseFragment == null) { return; } PhotoViewer.getInstance().setParentActivity(baseFragment.getParentActivity()); cameraPhoto = new ArrayList<>(); cameraPhoto.add(new MediaController.PhotoEntry(0, 0, 0, cameraFile.getAbsolutePath(), 0, true)); PhotoViewer.getInstance().openPhotoForSelect(cameraPhoto, 0, 2, new PhotoViewer.EmptyPhotoViewerProvider() { @Override public Bitmap getThumbForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) { return thumb; } @TargetApi(16) @Override public boolean cancelButtonPressed() { if (cameraOpened && cameraView != null && cameraFile != null) { cameraFile.delete(); AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { if (cameraView != null && !isDismissed() && Build.VERSION.SDK_INT >= 21) { cameraView.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN); } } }, 1000); CameraController.getInstance() .startPreview(cameraView.getCameraSession()); cameraFile = null; } return true; } @Override public void sendButtonPressed(int index) { if (cameraFile == null) { return; } AndroidUtilities .addMediaToGallery(cameraFile.getAbsolutePath()); baseFragment.sendMedia( (MediaController.PhotoEntry) cameraPhoto.get(0), PhotoViewer.getInstance().isMuteVideo()); closeCamera(false); dismiss(); cameraFile = null; } }, baseFragment); } }); AndroidUtilities.runOnUIThread(videoRecordRunnable, 1000); shutterButton.setState(ShutterButton.State.RECORDING, true); } @Override public void shutterCancel() { cameraFile.delete(); resetRecordState(); CameraController.getInstance().stopVideoRecording(cameraView.getCameraSession(), true); } @Override public void shutterReleased() { if (takingPhoto) { return; } if (shutterButton.getState() == ShutterButton.State.RECORDING) { resetRecordState(); CameraController.getInstance().stopVideoRecording(cameraView.getCameraSession(), false); shutterButton.setState(ShutterButton.State.DEFAULT, true); return; } cameraFile = AndroidUtilities.generatePicturePath(); takingPhoto = CameraController.getInstance().takePicture(cameraFile, cameraView.getCameraSession(), new Runnable() { @Override public void run() { takingPhoto = false; if (cameraFile == null || baseFragment == null) { return; } PhotoViewer.getInstance().setParentActivity(baseFragment.getParentActivity()); cameraPhoto = new ArrayList<>(); int orientation = 0; try { ExifInterface ei = new ExifInterface(cameraFile.getAbsolutePath()); int exif = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (exif) { case ExifInterface.ORIENTATION_ROTATE_90: orientation = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: orientation = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: orientation = 270; break; } } catch (Exception e) { FileLog.e("tmessages", e); } cameraPhoto.add(new MediaController.PhotoEntry(0, 0, 0, cameraFile.getAbsolutePath(), orientation, false)); PhotoViewer.getInstance().openPhotoForSelect(cameraPhoto, 0, 2, new PhotoViewer.EmptyPhotoViewerProvider() { @TargetApi(16) @Override public boolean cancelButtonPressed() { if (cameraOpened && cameraView != null && cameraFile != null) { cameraFile.delete(); AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { if (cameraView != null && !isDismissed() && Build.VERSION.SDK_INT >= 21) { cameraView.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN); } } }, 1000); CameraController.getInstance() .startPreview(cameraView.getCameraSession()); cameraFile = null; } return true; } @Override public void sendButtonPressed(int index) { if (cameraFile == null) { return; } AndroidUtilities .addMediaToGallery(cameraFile.getAbsolutePath()); baseFragment.sendMedia( (MediaController.PhotoEntry) cameraPhoto.get(0), false); closeCamera(false); dismiss(); cameraFile = null; } @Override public boolean scaleToFill() { return true; } }, baseFragment); } }); } }); switchCameraButton = new ImageView(context); switchCameraButton.setScaleType(ImageView.ScaleType.CENTER); cameraPanel.addView(switchCameraButton, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.CENTER_VERTICAL)); switchCameraButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (takingPhoto || cameraView == null || !cameraView.isInitied()) { return; } cameraInitied = false; cameraView.switchCamera(); ObjectAnimator animator = ObjectAnimator.ofFloat(switchCameraButton, "scaleX", 0.0f) .setDuration(100); animator.addListener(new AnimatorListenerAdapterProxy() { @Override public void onAnimationEnd(Animator animator) { switchCameraButton.setImageResource(cameraView.isFrontface() ? R.drawable.camera_revert1 : R.drawable.camera_revert2); ObjectAnimator.ofFloat(switchCameraButton, "scaleX", 1.0f).setDuration(100).start(); } }); animator.start(); } }); for (int a = 0; a < 2; a++) { flashModeButton[a] = new ImageView(context); flashModeButton[a].setScaleType(ImageView.ScaleType.CENTER); flashModeButton[a].setVisibility(View.INVISIBLE); cameraPanel.addView(flashModeButton[a], LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP)); flashModeButton[a].setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View currentImage) { if (flashAnimationInProgress || cameraView == null || !cameraView.isInitied() || !cameraOpened) { return; } String current = cameraView.getCameraSession().getCurrentFlashMode(); String next = cameraView.getCameraSession().getNextFlashMode(); if (current.equals(next)) { return; } cameraView.getCameraSession().setCurrentFlashMode(next); flashAnimationInProgress = true; ImageView nextImage = flashModeButton[0] == currentImage ? flashModeButton[1] : flashModeButton[0]; nextImage.setVisibility(View.VISIBLE); setCameraFlashModeIcon(nextImage, next); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether( ObjectAnimator.ofFloat(currentImage, "translationY", 0, AndroidUtilities.dp(48)), ObjectAnimator.ofFloat(nextImage, "translationY", -AndroidUtilities.dp(48), 0), ObjectAnimator.ofFloat(currentImage, "alpha", 1.0f, 0.0f), ObjectAnimator.ofFloat(nextImage, "alpha", 0.0f, 1.0f)); animatorSet.setDuration(200); animatorSet.addListener(new AnimatorListenerAdapterProxy() { @Override public void onAnimationEnd(Animator animator) { flashAnimationInProgress = false; currentImage.setVisibility(View.INVISIBLE); } }); animatorSet.start(); } }); } } }
From source file:com.bannisha.yelian.customview.CirclePageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return;// ww w. j a va2 s. c o m } final int count = mViewPager.getAdapter().getCount(); if (count == 0) { return; } if (mCurrentPage >= count) { setCurrentItem(count - 1); return; } int imageLongSize = 0; int imageShortSize = 0; int longSize; int longPaddingBefore; int longPaddingAfter; int shortSize; int shortPaddingBefore; if (mOrientation == HORIZONTAL) { if (flag) { imageLongSize = imageBitmap.getWidth(); imageShortSize = imageBitmap.getHeight(); } longSize = getWidth(); shortSize = getHeight(); longPaddingBefore = getPaddingLeft(); longPaddingAfter = getPaddingRight(); shortPaddingBefore = getPaddingTop(); } else { if (flag) { imageShortSize = imageBitmap.getWidth(); imageLongSize = imageBitmap.getHeight(); } longSize = getHeight(); shortSize = getWidth(); longPaddingBefore = getPaddingTop(); longPaddingAfter = getPaddingBottom(); shortPaddingBefore = getPaddingLeft(); } float shortOffset = 0; if (flag) { shortOffset = (shortSize - imageShortSize) / 2; if (rd == 0) { mRadius = imageLongSize * 2; } else { mRadius = rd; } } else { shortOffset = shortPaddingBefore + mRadius; } float threeRadius = mRadius * 3; float longOffset = longPaddingBefore + mRadius; if (mCentered) { longOffset += ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f) - ((count * threeRadius) / 2.0f); } float dX; float dY; float pageFillRadius = mRadius; if (mPaintStroke.getStrokeWidth() > 0) { pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f; } // Draw stroked circles for (int iLoop = 0; iLoop < count; iLoop++) { float drawLong = longOffset + (iLoop * threeRadius); if (mOrientation == HORIZONTAL) { dX = drawLong; dY = shortOffset; } else { dX = shortOffset; dY = drawLong; } // Only paint fill if not completely transparent if (mPaintPageFill.getAlpha() > 0) { if (flag) { canvas.drawBitmap(imageBitmap, dX, dY, mPaintPageFill); } else { canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill); } } // Only paint stroke if a stroke width was non-zero if (pageFillRadius != mRadius) { if (flag) { canvas.drawBitmap(imageBitmap, dX, dY, mPaintStroke); } else { canvas.drawCircle(dX, dY, mRadius, mPaintStroke); } } } // Draw the filled circle according to the current scroll float cx = (mSnap ? mSnapPage : mCurrentPage) * threeRadius; if (!mSnap) { cx += mPageOffset * threeRadius; } if (mOrientation == HORIZONTAL) { dX = longOffset + cx; dY = shortOffset; } else { dX = shortOffset; dY = longOffset + cx; } if (flag) { canvas.drawBitmap(currentImageBitmap, dX, dY, mPaintFill); } else { canvas.drawCircle(dX, dY, mRadius, mPaintFill); } }
From source file:com.pt.treasuretrash.indicator.CirclePageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return;/*from www.j a va2s . com*/ } final int count = mViewPager.getAdapter().getCount(); if (count == 0) { return; } if (mCurrentPage >= count) { setCurrentItem(count - 1); return; } int longSize; int longPaddingBefore; int longPaddingAfter; int shortPaddingBefore; if (mOrientation == HORIZONTAL) { longSize = getWidth(); longPaddingBefore = getPaddingLeft(); longPaddingAfter = getPaddingRight(); shortPaddingBefore = getPaddingTop(); } else { longSize = getHeight(); longPaddingBefore = getPaddingTop(); longPaddingAfter = getPaddingBottom(); shortPaddingBefore = getPaddingLeft(); } final float threeRadius = mRadius * mDotDistance;// set distance between // dot final float shortOffset = shortPaddingBefore + mRadius; float longOffset = longPaddingBefore + mRadius; if (mCentered) { longOffset += ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f) - ((count * threeRadius) / 2.0f); } float dX; float dY; float pageFillRadius = mRadius; if (mPaintStroke.getStrokeWidth() > 0) { pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f; } // Draw stroked circles for (int iLoop = 0; iLoop < count; iLoop++) { float drawLong = longOffset + (iLoop * threeRadius); if (mOrientation == HORIZONTAL) { dX = drawLong; // dY = shortOffset; /*commented out by console23*/ dY = (mCentered == true ? (this.getHeight() / 2) : shortOffset); /* * added * by * console23 */ } else { // dX = shortOffset; /*commented out by console23*/ dX = (mCentered == true ? (this.getWidth() / 2) : shortOffset); /* * added * by * console23 */ dY = drawLong; } // Only paint fill if not completely transparent if (mPaintPageFill.getAlpha() > 0) { canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill); } // Only paint stroke if a stroke width was non-zero if (pageFillRadius != mRadius) { canvas.drawCircle(dX, dY, mRadius, mPaintStroke); } } // Draw the filled circle according to the current scroll float cx = (mSnap ? mSnapPage : mCurrentPage) * threeRadius; if (!mSnap) { cx += mPageOffset * threeRadius; } if (mOrientation == HORIZONTAL) { dX = longOffset + cx; // dY = shortOffset; /*commented out by console23*/ dY = (mCentered == true ? (this.getHeight() / 2) : shortOffset); /* * added * by * console23 */ } else { // dX = shortOffset; /*commented out by console23*/ dX = (mCentered == true ? (this.getWidth() / 2) : shortOffset); /* * added * by * console23 */ dY = longOffset + cx; } canvas.drawCircle(dX, dY, mRadius, mPaintFill); }
From source file:me.test.zxing.ViewfinderView.java
@SuppressLint("DrawAllocation") @Override// w w w . j a v a 2 s . c om public void onDraw(Canvas canvas) { if (cameraManager == null) { return; // not ready yet, early draw before done configuring } Rect frame = cameraManager.getFramingRect(); Rect previewFrame = cameraManager.getFramingRectInPreview(); if (frame == null || previewFrame == null) { return; } int width = canvas.getWidth(); int height = canvas.getHeight(); if (!isFirst) { isFirst = true; slideTop = frame.top; } // // Draw the exterior (i.e. outside the framing rect) darkened paint.setColor(resultBitmap != null ? resultColor : maskColor); canvas.drawRect(0, 0, width, frame.top, paint); canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint); canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint); canvas.drawRect(0, frame.bottom + 1, width, height, paint); if (resultBitmap != null) { // Draw the opaque result bitmap over the scanning rectangle paint.setAlpha(CURRENT_POINT_OPACITY); canvas.drawBitmap(resultBitmap, null, frame, paint); } else { // paint.setColor(ContextCompat.getColor(getContext(), android.R.color.holo_green_dark)); // canvas.drawRect(frame.left, frame.top, frame.left + 50, frame.top + 10, paint); canvas.drawRect(frame.left, frame.top, frame.left + 10, frame.top + 50, paint); //? canvas.drawRect(frame.right - 50, frame.top, frame.right, frame.top + 10, paint); canvas.drawRect(frame.right - 10, frame.top, frame.right, frame.top + 50, paint); // canvas.drawRect(frame.left, frame.bottom - 10, frame.left + 50, frame.bottom, paint); canvas.drawRect(frame.left, frame.bottom - 50, frame.left + 10, frame.bottom, paint); //? canvas.drawRect(frame.right - 50, frame.bottom - 10, frame.right, frame.bottom, paint); canvas.drawRect(frame.right - 10, frame.bottom - 50, frame.right, frame.bottom, paint); //,??SPEEN_DISTANCE slideTop += 5; if (slideTop >= frame.bottom) { slideTop = frame.top; } canvas.drawRect(frame.left + 5, slideTop - 6 / 2, frame.right - 5, slideTop + 6 / 2, paint); float scaleX = frame.width() / (float) previewFrame.width(); float scaleY = frame.height() / (float) previewFrame.height(); List<ResultPoint> currentPossible = possibleResultPoints; List<ResultPoint> currentLast = lastPossibleResultPoints; int frameLeft = frame.left; int frameTop = frame.top; if (currentPossible.isEmpty()) { lastPossibleResultPoints = null; } else { possibleResultPoints = new ArrayList<>(5); lastPossibleResultPoints = currentPossible; paint.setAlpha(CURRENT_POINT_OPACITY); paint.setColor(resultPointColor); synchronized (currentPossible) { for (ResultPoint point : currentPossible) { canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX), frameTop + (int) (point.getY() * scaleY), POINT_SIZE, paint); } } } if (currentLast != null) { paint.setAlpha(CURRENT_POINT_OPACITY / 2); paint.setColor(resultPointColor); synchronized (currentLast) { float radius = POINT_SIZE / 2.0f; for (ResultPoint point : currentLast) { canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX), frameTop + (int) (point.getY() * scaleY), radius, paint); } } } // Request another update at the animation interval, but only repaint the laser line, // not the entire viewfinder mask. postInvalidateDelayed(ANIMATION_DELAY, frame.left - POINT_SIZE, frame.top - POINT_SIZE, frame.right + POINT_SIZE, frame.bottom + POINT_SIZE); } }
From source file:com.example.SmartBoard.DrawingView.java
public void onDrawCircle(Canvas canvas) { Paint paint = drawPaint;//from ww w .j av a2s . c o m if (points[3] == null) //point4 null when user did not touch and move on screen. return; int left, top, right, bottom; left = points[0].x; top = points[0].y; right = points[0].x; bottom = points[0].y; for (int i = 1; i < points.length; i++) { left = left > points[i].x ? points[i].x : left; top = top > points[i].y ? points[i].y : top; right = right < points[i].x ? points[i].x : right; bottom = bottom < points[i].y ? points[i].y : bottom; } float cx = (left + right) / 2f; float cy = (top + bottom) / 2f; float radius = (float) Math.hypot(top - bottom, right - left) / 2f; //draw stroke paint.setStyle(Paint.Style.STROKE); // paint.setColor(Color.parseColor("#AADB1255")); paint.setStrokeWidth(5); if (finished) { JSONObject objectProperties = new JSONObject(); String key = UUID.randomUUID().toString(); try { objectProperties.put("id", key); objectProperties.put("type", "Circle"); objectProperties.put("color", drawPaint.getColor()); objectProperties.put("size", 5); objectProperties.put("clientId", client.getClientId()); objectProperties.put("radius", radius); objectProperties.put("x", cx); objectProperties.put("y", cy); } catch (JSONException e) { } objectDrawables.put(key, objectProperties); // drawCanvas.drawCircle(cx, cy, radius, paint); // drawCanvas.save(); // mqtt.publishRectangle(objectProperties); mqtt.publishCircle(objectProperties); //reset to start drawing again points = new Point[4]; colorballs.clear(); return; } canvas.drawCircle(cx, cy, radius, paint); // draw the balls on the canvas // paint.setColor(Color.BLUE); paint.setTextSize(18); paint.setStrokeWidth(0); // paint.setColor(Color.BLUE); for (int i = 0; i < colorballs.size(); i++) { ColorBall ball = colorballs.get(i); canvas.drawBitmap(ball.getBitmap(), ball.getX(), ball.getY(), paint); canvas.drawText("" + (i + 1), ball.getX(), ball.getY(), paint); } }
From source file:pt.carlos.alex.rosario.ContasRosario.java
@Override protected void onDraw(final Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return;/*from ww w . j a v a2 s .c o m*/ } final int count = mViewPager.getAdapter().getCount(); if (count == 0) { return; } if (mCurrentPage >= count) { setCurrentItem(count - 1); return; } int longSize; int longPaddingBefore; int longPaddingAfter; int shortPaddingBefore; if (mOrientation == HORIZONTAL) { longSize = getWidth(); longPaddingBefore = getPaddingLeft(); longPaddingAfter = getPaddingRight(); shortPaddingBefore = getPaddingTop(); } else { longSize = getHeight(); longPaddingBefore = getPaddingTop(); longPaddingAfter = getPaddingBottom(); shortPaddingBefore = getPaddingLeft(); } final float threeRadius = mRadius * 3; final float shortOffset = shortPaddingBefore + mRadius; float longOffset = longPaddingBefore + mRadius; if (mCentered) { longOffset += ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f) - ((count * threeRadius) / 2.0f); } float dX; float dY; float pageFillRadius = mRadius; if (mPaintStroke.getStrokeWidth() > 0) { pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f; } //Draw stroked circles for (int iLoop = 0; iLoop < count; iLoop++) { float drawLong = longOffset + (iLoop * threeRadius); if (mOrientation == HORIZONTAL) { dX = drawLong; dY = shortOffset; } else { dX = shortOffset; dY = drawLong; } // Only paint fill if not completely transparent if (mPaintPageFill.getAlpha() > 0) { // iEvangelo.setColor(getResources().getColor(R.color.ics_yellow); // // switch (iLoop) { // case 0: // iPaintPageFill.setColor(); // Texto meditativo (Evangelho) // break; // case 1: // iPaintPageFill.setColor(R.color.ics_green); // Pai Nosso // break; // case 12: // iPaintPageFill.setColor(getResources().getColor(R.color.ics_bold_yellow)); // Glria // break; // case 13: // iPaintPageFill.setColor(R.color.ics_violet); // Jaculatria // break; // default: // iPaintPageFill.setColor(mPaintPageFill.getColor()); // } iPaintPageFill.setColor(coresContas.get(iLoop)); canvas.drawCircle(dX, dY, pageFillRadius, iPaintPageFill); // canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill); } // Only paint stroke if a stroke width was non-zero if (pageFillRadius != mRadius) { canvas.drawCircle(dX, dY, mRadius, mPaintStroke); } } //Draw the filled circle according to the current scroll float cx = (mSnap ? mSnapPage : mCurrentPage) * threeRadius; if (!mSnap) { cx += mPageOffset * threeRadius; } if (mOrientation == HORIZONTAL) { dX = longOffset + cx; dY = shortOffset; } else { dX = shortOffset; dY = longOffset + cx; } canvas.drawCircle(dX, dY, mRadius, mPaintFill); }
From source file:com.example.SmartBoard.DrawingView.java
@Override protected void onDraw(Canvas canvas) { drawCanvas.drawPath(drawPath, drawPaint); drawCanvas.drawPath(drawPathRecv, drawPaintSender); if (rectMode) { //draw rectangle drawPaint.setXfermode(null);// ww w .j av a 2 s . c om onDrawRectangle(canvas); } else if (circleMode) { drawPaint.setXfermode(null); onDrawCircle(canvas); } else if (lineMode) { drawPaint.setXfermode(null); onDrawLine(canvas); } else if (textMode) { drawPaint.setXfermode(null); onDrawText(canvas); } else if (dragMode && !dragFinished) { drawPaint.setXfermode(null); onDragDraw(canvas, dragX, dragY); } else if (colorDropperMode) { drawPaint.setXfermode(null); onDrawColorDropper(canvas, dropperX, dropperY); } else if (textSizeMode) { drawPaint.setXfermode(null); } canvas.drawBitmap(canvasBitmap, 0, 0, canvasPaint); //redraw objects Paint tempPaint = new Paint(); tempPaint.setStyle(Paint.Style.STROKE); for (String key : textObjects.keySet()) { if (key.compareTo("") == 0) { continue; } JSONObject o = textObjects.get(key); tempPaint.setColor(o.optInt("color")); tempPaint.setStrokeWidth(o.optInt("size")); canvas.drawBitmap(mqtt.stringToBitmap(o.optString("textBitmap")), o.optInt("x"), o.optInt("y"), tempPaint); } for (String key : objectDrawables.keySet()) { //hashtable problems no time to explain. But it creates a duplicate of last item I add to the table. //So dont print duplicates which have empty string key values if (key.compareTo("") == 0) { continue; } JSONObject o = objectDrawables.get(key); String objectType = o.optString("type"); tempPaint.setColor(o.optInt("color")); tempPaint.setStrokeWidth(o.optInt("size")); if (objectType.compareTo("Circle") == 0) { canvas.drawCircle(o.optInt("x"), o.optInt("y"), o.optInt("radius"), tempPaint); } else if (objectType.compareTo("Line") == 0) { canvas.drawLine(o.optInt("startx"), o.optInt("starty"), o.optInt("stopx"), o.optInt("stopy"), tempPaint); } else if (objectType.compareTo("Rectangle") == 0) { canvas.drawRect(Rect.unflattenFromString(o.optString("dimens")), tempPaint); } else if (objectType.compareTo("Text") == 0) { //canvas.drawRect(Rect.unflattenFromString(o.optString("region")), drawPaint); canvas.drawBitmap(mqtt.stringToBitmap(o.optString("textBitmap")), o.optInt("x"), o.optInt("y"), tempPaint); } } }