How can i call perspectiveM static method in Matrix class?
As said here:
http://developer.android.com/reference/android/opengl/Matrix.html
Сode completion suggests me frustumM, invertM, length, multiplyMM, multiplyMV, orthoM and others and no perspectiveM.
Details that could be important: last eclipse and java, android 2.3 as target, last sdk updates.
p.s. i know that i can tune matrix manually. it's just really interesting where method is.
The method is api lvl 14. If you scroll down to perspectiveM on the page you linked, you'll see in faint grey writing the api level where the method was included from:
Related
I have read the dozens of questions here on SO regarding recycling TypedArrays, but I guess they are a bit too old and written before we could widely use try-with-resource statements, so none of them talk about using the AutoCloseable implementation of the TypedArray, which is present since API Level 31
So the question remains: is this a false positive in Lint?
If anything, that warning should be a minSDK warning if applicable, right?
Can we simply write the following since the full try-with support (if we do it after SDK Level >= 31 check)?
try (TypedArray array = getContext().obtainStyledAttributes(attrs) {
// Do someting
}
// End of method
My guess is yes, as this is the AutoCloseable implementation of TypedArray
So the question remains: is this a false positive in Lint?
No, it is not. Because close method in AutoCloseable interface is not magically called when using try/catch.
Instead you have to use use method and then and only then you can get rid of try/catch like following:
getContext().obtainStyledAttributes(attrs).use({
// Do something
});
But, be aware that use method from TypedArray class is available only since Android 31
If you prefer a backwards compatible solution, you can use use method from androidx.core:core-ktx library.
As TypedArray also provides of a use method you will have to take care of adding the following import:
import androidx.core.content.res.use
I recently came across the deprecation of clipRect(Rect,Region.Op), which I would like to use with DIFFERENCE. This was replaced with clipOutRect(Rect) and thus I implemented:
#Suppress("DEPRECATION")
fun clipOutRect(canvas: Canvas, rect: Rect) =
if (SDK_INT >= O) canvas.clipOutRect(rect)
else canvas.clipRect(rect, DIFFERENCE)
Now this looks like it could be a compatibility method in AndroidX, but for some reason I was not able to figure out, where I could find it exactly.
Is there a class already providing a compatibility method for clipOutRect(Rect)?
Short answer is - no. The only thing related to Canvas in AndroidX is this file: https://github.com/aosp-mirror/platform_frameworks_support/blob/androidx-master-dev/core/core-ktx/src/main/java/androidx/core/graphics/Canvas.kt
Long answer.
First of all, Canvas is passed to view by native code, so it will be awkward to have something like onDrawCompat(canvas: CanvasCompat) in ViewCompat class. And I think there is no reason to do that at all.
Also, it's really not that type of deprecation you should worry about.
For example WifiManager.startScan() is noted with
This method was deprecated in API level 28. The ability for apps to
trigger scan requests will be removed in a future release.
That says Change this code now, or it will be broken year later
That not the case with clipRect, it will be kept for backward compatibility with apps that won't be ever updated for years or even tenth of years. Deprecation warning for this is just like Hey, we have new method with better functionality/name, if you target minimum is API 26 you can use that
I am new to android programming and I have been doing lots of tutorials all over the internet but I keep bumping into deprecated methods, like for example when I call BitmapFactory.Options.inPurgeable, android studio crosses out inPurgeable, giving message that method is deprecated.
Where do I find alternatives to deprecated methods?
It's deprecated because this flag is ignored starting Lollipop. Also use of it can lead to dropped frames. As documentation mentions - use inBitmap method instead.
The documentation says:
This field was deprecated in API level 21. As of
Build.VERSION_CODES.LOLLIPOP, this is ignored. In
Build.VERSION_CODES.KITKAT and below, if this is set to true, then the
resulting bitmap will allocate its pixels such that they can be purged
if the system needs to reclaim memory. In that instance, when the
pixels need to be accessed again (e.g. the bitmap is drawn,
getPixels() is called), they will be automatically re-decoded.
So there should be no need to add this anymore...
... however, according to Romain Guy, it still makes sense when decodeByteArray() is used:
This flag is currently completely ignored' is true in certain cases only - in other cases (e.g. when using decodeByteArray on downloaded data) then this flag is not ignored and is very, very useful
I want to use a Master-Detail-Flow with a GridView on the left (master) side.
According to the documentation, GridView has a method setItemChecked(position, value) that was added in API level 1. Eclipse however states that the method requires API level 11.
Which one is true? If I want to have checked items in my GridView, do I need to implement the logic (with background changes etc) myelf?
From my experience, the official documentation is wrong.
AbsListView.setItemChecked(position, value) only exists from HoneyComb (API 11) onwards. What makes it confusing is that ListView.setItemChecked(position, value) did exist from API 1 while GridView.setItemChecked(position, value) didn't. I think it was just bad API design that was fixed in API 11.
Maybe it's due to a limitation in the documentation generator because the method was moved up the inheritance chain to AbsListView in API 11. The method in AbsListView should be marked as Added in API level 11 while the method in ListView should be marked as Added in API level 1.
I haven't used it but someone has created a GridViewCompat to fix this issue.
https://github.com/paramvir-b/AndroidGridViewCompatLib
I believe the documentation is wrong. Testing on an emulator, the method was not available on API level 8. This applies for all extensions of the AbsListView setItemChecked() method as far as I can tell (ListView etc). I think it's safe to assume it's only available on API level 11+
I have a problem and it is really doing my head in. All I want to do is a very simple task, determine the rotation of the screen. Now Display.getRotation() does exactly this.
http://developer.android.com/reference/android/view/Display.html#getRotation%28%29
However when I try to use it I just get "The method getRotation() is undefined for the type Display" and Eclipse tells me to change it to the deprecated function getOrientation() which will not work for what I need because it only returns Landscape/Portrait, not 0/90/180/270.
Does anyone have an idea why this might not be working?
Display.getRotation() is only available as of API8 (Froyo / 2.2). Your app project probably specifies an earlier API level.
public int getRotation () Since: API Level 8
Use getOrientation() instead. The two functions seem to be identical; I have no idea why they deprecated getOrientation in 2.2.