I'm trying to take advantage of the new-ish PrecomputedTextCompat class but it appears that it is missing a method that the framework's version of the class (PrecomputedText) has: getWidth(). Unfortunately, the framework version of the class was added in API 28 so I can't use it, that's way above our minimum SDK level at the moment.
I definitely need this method for what I'm trying to do. Does anyone know of a suitable replacement? The returned value doesn't necessarily have to be a float, could be just an int (pixels).
Places I've looked for a replacement, but haven't found an answer:
AppCompatTextView
MaterialTextView
PrecomputedTextCompat
PrecomputedTextCompat.Params
TextViewCompat
Thank you!!
Related
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 have one custom class having initializeScrollBars() in its constructor.
In API 21, the method was removed, so i am not able to build the app on Lollipop 5.0.I have searched and found that, there is no alternative provided by android officially.
(https://developer.android.com/sdk/api_diff/21/changes/android.view.View.html).
I have checked this link: initializeScrollbars is undefined? and noticed that one developer suggest us to remove the method and let it on the View class by defining R.styleable.View_scrollbars attr which is not internal.
I just don't get it.
Google have answered for this issue as:
"The API has been removed because R.styleable is not public or stable. There is no safe way to pass a TypedArray into that method. Don't call the method."(Ref: https://github.com/GDG-Korea/PinterestLikeAdapterView/issues/31)
Can anyone light me a path how to remove the method
initializeScrollbars() from the custom view?
Can i simply remove initializeScrollbars() from constructor ?
What is the best way to initialize scrollbars of a custom view.?
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+
TextView.setAllCaps() started as of API 14. What is its equivalent for older APIs (e.g. 13 and lowers)?
I cannot find such method on lower APIs. Is maybe setTransformationMethod() responsible for this on older APIs? If yes, how should I use it? TextView.setTransformationMethod(new TransformationMethod() {... is a bit confusing.
Try this:
textView.setText(textToBeSet.toUpperCase());
What about oldskool strtoupper()?
Bottom line is that toUpperCase() is the solution. I can't object that. If you prefer doing the setAllCaps() with TransformationMethod, take a look at my answer.
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/