Android: Display.getRotation(); - android

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.

Related

Canvas clipOutRect compatibility in AndroidX

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

Unable to increase the output volume

Tried endpoint.audDevManager().setOutputVolume(percentage), with values ranging between 100-1999. Unfortunately, it's not resulting in any increase in volume.
The documentation suggests that:
This method is only valid if the device has PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING capability in AudioDevInfo.caps flags.
And I've already ensured that this flag is set. Is there anything else that I need to take care of?
Sauw Ming suggested (over mail) to use AudioMedia::adjustRxLevel(float level) instead, and that fixed the issue for values of level over 3.0. At least that's when there was perceivable difference in volume.
I also worked with endpoint.audDevManager().setOutputVolume(percentage) and it works after the call start.I got the change of volume.Also i used the range 1-100.Please check it with this settings.

GridView.setItemChecked(position, value)

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+

Android equivalent work-around for View.getX() before API 11?

I'm using the getX() and getY() method on a view for some special dragging logic (not animation, i.e. I never use setX/Y methods, I just need the getters to check).
However, I've come to realize that these are only available post-API 11.
The docs for getX() say that is it the addition of the 'left' property and the 'translationX' property. All well and good, except get/setTranslationX() is only around since API 11 as well.
I was wondering if there was any knowledge on what this method returns behind the scenes, so I could maybe put in a workaround.
Use nineOldAndroid.jar file in your project And use this way
import com.nineoldandroids.view.ViewHelper;
ViewHelper.setTranslationX(myView, translation);
ViewHelper.getX(myView);
How about getLeft() and getTop(). Looks to me like these are valid as long as the view hasn't been translated (setTranslationX() and setTranslationY()) which also aren't valid in the older API.
Using android.support.v4.view.ViewCompat the solution is:
ViewCompat.getY(mView);
which is compatible with old android devices.
i suppose it's not relevant anymore, but just in case somebody is looking for it:
http://nineoldandroids.com/

Where is perspectiveM method in android.opengl.Matrix?

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:

Categories

Resources