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.?
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'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!!
I have been searching everywhere for a list of supported methods in RemoteViews but come up empty. Can anyone link a resource or list all available methods supported by RemoteViews? Thanks.
I am assuming that you are referring to the methods that can be used by RemoteViews methods like setBoolean().
The way to determine if a method is supported is to look at the source code and see whether the method has the #RemotableViewMethod annotation. If it does, that is available for those ad-hoc RemoteViews "setters".
So for example, the first #RemotableViewMethod-annotated method in the Android 7.1 edition of View is setContentDescription().
Note that these annotations may change over time. They should not be removed (unless perhaps the underlying method is deprecated), but ones can be added. So, you will want to check the source associated with your minSdkVersion.
Here is the image that show the objects that are depreciated...?
What does this mean?
Deprecated means that you should not use it anymore but a new implementation of it, because it will be removed from framework / language whatever in future releases. In most cases there is a description at this method or documentation what you have to use instead.
I'm using Robolectric to test an activity that inflates a custom view, but when fetching values from the TypedArray everything comes back null or an empty string. What needs to be done in order to get the correct value from the typed array?
Robolectric doesn't re-implement the entire Android standard library.
Here is a link to the TypeArray Shadow class:
https://github.com/pivotal/robolectric/blob/master/src/main/java/com/xtremelabs/robolectric/shadows/ShadowTypedArray.java
It seems to be missing some things. You can use this function to confirm that it is indeed missing those functions:
http://pivotal.github.com/robolectric/javadoc/com/xtremelabs/robolectric/Robolectric.html#logMissingInvokedShadowMethods()
That said, there is hope. Robolectric 2.0 Alpha 1 was recently released. While I haven't used it yet, it claims that less shadow implementations will be needed as it will use the Android implementations directly.
Try using getStringArray() instead. For example:
String[] myStringArray = Robolectric.getShadowApplication().getResources()
.getStringArray(R.array.MyStringArrayIdentifier)