view.invalidate not working on phone - android

I have a Custom view, made up of several view and label components. When the user touches the view, I draw a frame around the view to indicate selected status, and the background changes on double tap. The frame is drawn using the overridden draw function of the view by passing the view a frame color different from the background and calling view.invalidate(). Same for the background change.
This used to work perfectly as long as I was developing for API 7. Even on my phone that runs API 16. I recently migrated the code to API 11+ and now the selected frame is not showing anymore and the background does not change on my phone even though it is still working in the emulator (API 14).
A afternoon of trying to trace where the error is, I figured out that on my phone, calling view.invalidate() is not triggering a redraw of the view. I also tried view.requestLayout() and view.postInvalidate() (just to make sure) with the same result. Putting the invalidate command in a separate thread did not work either.
To summarize:
Code API 7 - Phone API 16 - Emulator API 7 to 14 view.invalidate works
Code API 11 - Phone API 16 - Emulator API 11 to 14 view.invalidate does not work on Phone but on emulator.
I have a Motorola RAZR M from Verizon
Is this a known bug or was there a change in handling of things like that in API 11?
Any help is appreciated.

Related

Android API 30 Cannot Detect multi-touch on the Android Emulator

I have a view and I want to implement detection of multi-touch gestures, so I override the onTouch() event and there I implement the logic. I have tested it and it work on actual device with Android API 28, and it works on Android Emulator up to API 29. As seen on the image below, on the emulator when I use [Ctrl+Clicks] to detect multi-touch for two fingers, I receive an event ACTION_POINTER_DOWN indicating that the second finger was down on the screen.
But on Android Emulator using API 30, I never receive the ACTION_POINTER_DOWN event and the multi-touch does not work. When I change the API version to lower version < 30, for the same emulated device it starts working. So the problem only occurs for devices that use API30 (I don't have an actual device that runs Android API30, so I am not sure if this only happens on the emulator or not). Is it somehow disabled by default from the developer options or the settings?

SurfaceView refuses to create a 32-bit surface for me

I'm moving my app away from NativeActivity because I want to do more things on the Java side and less things in C. However, I still want to keep the renderer in C. That's why I'm using an Activity which has a SurfaceView as its main view.
When I used NativeActivity, ANativeWindow_getFormat() returned RGBX_8888 which was just fine. With my new renderer based on SurfaceView, however, my surfaceChanged() callback always receives RGB_565 as the pixel format which looks really ugly because it only has 65536 colors and gradients look pretty cheap in 16 bits.
So I tried to add the following code to my Activity's onCreate() before calling setContentView():
getWindow().setFormat(PixelFormat.RGBX_8888);
This indeed solves the problem on my Nexus 5X device running Android 8 but on my Nexus 9 tablet running Android 7 it doesn't work and I still get 16-bit surfaces.
What is confusing me, however, is the fact that when using NativeActivity on my Nexus 9 tablet running Android 7 I actually get RGBX_8888 surfaces! So this definitely is not a hardware/system limitation on Nexus 9/Android 7. It works for NativeActivity, but not for my SurfaceView.
What is even more confusing is that when peeking into the Android source codes, you can see that NativeActivity actually explicitly request RGB_565 in its onCreate (see here) but still I get RGBX_8888 when I call ANativeWindow_getFormat() on my Nexus 9/Android 7. This is of course fine with me but of course it makes me wonder where the RGBX_8888 surface actually comes from because NativeActivity requests a RGB_565 surface.
To cut a long story short: Basically, all I need to know is how I can force my SurfaceView to use a RGBX_8888 surface on my Nexus 9/Android 7. On my Nexus 5X/Android 8 the code shown above does the trick but it doesn't work on the Nexus 9. But since NativeActivity can do it on the Nexus 9, it must be possible on this device as well. I just don't know how.
For the record, I was able to solve this by setting EGL_RED_SIZE, EGL_GREEN_SIZE and EGL_BLUE_SIZE to 8 when calling eglChooseConfig() on the native side.

canvas.drawText seems does not work properly in Android api >19

I have an issue that is making me crazy.
I created an Android library for a Custom gauge view of a car applicaction.
On this gauge view there's a scale with values drawn with function Canvas.drawText().
Everything was working fine when running whis view on devices with API 19 and 22, up to when last week I updated Android Studio 2.2.
Since that time the values on the scale are not properly written if I run it on a device with API >19. If I run it on device with API =< 19 everything is fine.
This is the test project that can be cloned from Github:
https://github.com/dequadelisonz/CarDashDemo.git
This is what I should correctly see (on device with API <=19):
And this is what I see on device with API >19:
As you can see in the 2 gauges there are only few digits in one of the two. All the other texts seems to be disappeared.
Hope someone can do the trick to fix this thing....
Thanks!
Fixed thanks to this post
https://stackoverflow.com/a/14989037/746068
It seems there is a bug on Android APIs > 15 so that text is not properly drawn on canvas.

Android WebView PictureListener Deprecated - Still no alternative?

This is similar to other questions already asked in the past, but with a new twist. The notification for WebView's capturePicture() completion is onNewPicture, but the latest documentation says that the picture returned in this will always be null from API 18 onwards (Android 4.3).
WebView.PictureListener
So far, I've checked that it still works on Android 4.0.3 (and trying to use the captured image fails unless I wait for the notification).
What are we supposed to use as a replacement? Will the picture be returned immediately in onPageFinished or when WebChromeClient's progress notifies 100%?
Update
API-18 (Android 4.3) appeared on the SDK a couple of days ago. onNewPicture still sends the captured picture on the emulator. Unfortunately I have no actual device with Android 4.3.
It actually depends on the targetSdkLevel of your app. For compatibility, onNewPicture still sends the picture if the target level is < 18 (JB MR2).
The preferred approach for capturing WebView image is to cause it do draw on a Canvas provided by you, see for example Which can replace capturePicture function

Android AVD- modifying API level, changing the APP view

Hi I was using Google API level 7 for my App.
I coded all layouts in dip unit. Now I installed Google API 8, changed my project to use level 8.
But, after launching the App, getting modified view. For e.g- the length increased for a list-view. Also, service call is not working. Restarting eclipse didn't solve the issue.
Then again switched back to Google API 7, now the service calls working fine. But, having layout issues like- font-size got bigger and list-view having increased height.
so, is there anything am missing? or why the layout is changing in different API Level! I don't have a device; will all the element measurements change in device?
which layout are you use? if linear layout then no problem because when you check it on device it will get in proper manner.now you got problem of size of emulator so click on avd > click on avd item(Google api 8) > click edit button > set built in : HVGA >edit AVD > then run
dont worry check it in device it will get properly.

Categories

Resources