hardwareAccelerated="true" vs. partial drawing - android

I needed days to figure out why invalidate(Rect dirty) doesn't set the correct clip on newer devices.
The problem is that hardwareAccelerated="true" is set by default.
When I set this hardwareAccelerated="false",
I get my right clip in my onDraw.
Now my question is:
What is better for performance:
Use hardwareAccelerated="false" and draw only the part of my view which is dirty and run only the code in my onDraw that is needed for this
OR
allow hardwareAcceleration and let android draw my entire view over and over again?
I guess this question may be answered for every application individually so I add a screenshot of my app.
As you can see I draw a calendar and each time a user clicks a entry this should get a red border.
Can you give me any suggestions whats best for this requirement?
Cheers,
Stefan

Related

Hide/remove/change color of a canvas circle When toched in Android

this is my first question here, so maybe I'll make some mistakes.
I want to create an Android app for touch test, and draw a cross on the screen, however I'm succeeded to draw cross, but now I want to implement test screen login.
What I want to do is that, When user clicks on any circle it should be removed/hidden or change color to transparent.
Any kind of help would be appreciated.
this is the link to my code.
https://github.com/akhlaqshah36/stackoverflow_questions/blob/master/drawCicles
and attached screenshot.
I got the solution by using some formulas of distance and Using Pointer objects.
check the solution here if someone need it.
Solution Link drawing cross in canvas

How to drawing bezier curve with animation in Android using cubicTo?

I've been searching for simple example and solution in stackoverflow, but I couldn't find one. So, I'll ask a new one and my apologies if this question have been asked before.
First, I want to make an apps that draw a Japanese Kanji Stroke using bezier curve, I already have 1 starting point, with 3 curves, for example :
M(11,54.25)
c(3.19,0.62) (6.25,0.75) (9.73,0.5)
c(20.64,-1.5) (50.39,-5.12) (68.58,-5.24)
c(3.6,-0.02) (5.77,0.24) (7.57,0.49)
What I have been found during searching in internet is, it looks like I could use Path.cubicTo() and use canvas as to draw it (using canvas.drawPath()).
And also, I want the canvas to draw it using animation at given frame rate or speed.
Anyone could give me a simple example or maybe some clue or anything that I can work with ?
Thanks !
You can find great example here:
http://www.jayway.com/2012/08/29/creating-custom-android-views-part-3-animating-your-custom-views-smoothly/
The sources are also there so it's very easy.
Your approach is good- you basically use Path.cubicTo in your View's onDraw and invalidate views while changing input coordinates. You can do it in another thread or create ValueAnimator and invalidate view in AnimatorUpdateListener.

Android partial invalidation doesn't work as expected with hardware acceleration

I know this is quite the same question as partial-invalidation-in-custom-android-view-with-hardware-acceleration but I thought I will explain my problem more detailled and hope someone will have an answer on how to solve the problem.
I wrote a simple TicTacToe app which was working fine on the emulator. But wasn't working on the device since I found out it was working as expected on the device when I disabled hardware acceleration.
All the fields are drawn with Canvas.drawBitmap(), also the "empty" fields with an empty white image. The lines are drawn with Canvas.drawLine()
I'm using partial invalidation with invalidate(Rect) because I want to redraw only the area which was choosen to set a cross/circle with the according image using again Canvas.drawBitmap(). But then the whole area is invalidated, means I see the whole area/screen is gray (the white images and lines disappeared) and only the image for the cross/circle is set in the choosen area.
When I print out the invalidated field rect with Canvas.getClipBounds() in the method onDraw(), with hardware acceleration it is the whole area (example "0,0,320,407") and without hardware acceleration the same rect which I invalidated with invalidate(Rect) (e.g. "106,135,106,135").
At the moment as workaround I redraw all the fields whith the according image and lines. How can I prevent to have the whole area invalidated with hardware acceleration?
If this matters: I'm using Android version 4.1.2 on Samsung Galaxy Young Duos S6312.
Regards
Sandro
I have post my answer in your given link. To understand the problem , you should know the difference between software rendering and hardware rendering. That's really a big topic which I won't cover here. I think the best approach is to read the source code(I did the same thing a few days ago). The key question is "what is DisplayList and when it is used"
. Repeat my answer here, the Canvas in onDraw is simply used to rebuild the DisplayList. That doesn't mean everything in your View will be redrawn.

Efficiently draw a trail after a moving object, depicting a few seconds of position history

I have an app where users are moving on a View background, I'm drawing the users, but would also like to display a trail after them with a few seconds of history.
I could do it using a bunch of line segments, but I worry that would be inneffective.
I would like some preimplemented class that performs this, so I don't have to get my hands dirty with making the actual drawing efficient. I was thinking in the lines of a of a android.graphics.Path, but I can't find a way to contonously remove the oldest parts of it. Is there a way to achieve this using a path?
If not does anyone have any other tips? Anywhere I could look for a handy and efficient solution?
Grateful for any help!
You could take the current view, mix it with the original background and use that as the new canvas to draw your users on for the next/upcoming frame. This will give a blurry trail (depending on the way you combine it with the original background) of the users.

Android concertina/accordian/folding animation

I'm trying to create an interactive accordian/concertina/folding animation so that a view folds/unfolds on itself when interacted with - in the same way flipboard folds the view, but both sides fold
The way I thought I could do it was to override the onDraw method, somehow duplicate the canvas or the information on the canvas, then draw the first half of the canvas rotated one way, then draw the other half of the canvas rotated the other way so that they meet in the middle, however I can't seem to grab the information from the canvas! Is it possible to grab a bitmap/snapshot from a canvas?
The only other way I think it's possible to achieve this kind of animation is with OpenGL.
Any help are greatly appreciated.
EDIT heres a good example of what i want to achieve http://www.nytimes.com/interactive/2008/03/28/arts/20080330_FOLD_IN_FEATURE.html
check this archive to acheive fold animation
code: http://developer.android.com/shareables/devbytes/FoldingLayout.zip
modifies it to make it work for lower version up till API level11

Categories

Resources