Ongloballayoutlistener: Deprecation and Compatibility

about cocoa api compatibility

what I can do for this?

At the technical level you test for existence of the API and branch accordingly, in abstract:

if (10.10 API available)
{
// use 10.10 API
}
else
{
// use earlier API or handle not supporting feature
}

In Objective-C Apple recommends testing for availability by testing for the specific method (using respondsToSelector:) or type (using weak linking); you can also test for a specific framework (recommended) or OS version (least favoured by Apple, often used by programmers...). If you get deprecation warnings, but you know the code is OK due to testing, you can locally suppress the warnings with #pragma's.

In Swift Apple provides a test for OS family (macOS, iOS etc.) and version (#available).

Regardless of language you build against the latest SDK you wish to support.

Obviously supporting a single codebase over many changes can get somewhat complex and/or messy, dealing with this is a business decision.

HTH

Android - getting the width of a button which is set to wrap_content

You can add a tree observer to the layout. This should return the correct width and height. onCreate is called before the layout of the child views are done. So the width and height is not calculated yet. To get the height and width. Put this on the onCreate method

LinearLayout layout = (LinearLayout)findViewById(R.id.YOUD VIEW ID); 
ViewTreeObserver vto = layout.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
this.layout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
int width = layout.getMeasuredWidth();
int height = layout.getMeasuredHeight();

}
});

Performance implications of readdir_r deprecation?

In the current POSIX.1 specification (POSIX.1-2008), readdir(3) is
not required to be thread-safe. However, in modern
implementations (including the glibc implementation), concurrent
calls to readdir(3) that specify different directory streams are
thread-safe.

The man page says it's thread safe (assuming you are using glibc, which I think is a fair assumption on Linux) -- provided you are using different directory streams - not different directory.

A directory stream is the DIR * parameter to readdir.

Developing API: balance between new features and back compatibility

When you have to make changes to the API which already has some users, probably the best route is to deprecate the old API calls and encourage use of the new calls.

Removing the capability of the old API calls would probably break the functionality of old code, so that is probably going to cause some developers using your "old" API to become somewhat dissatisfied.

If your language provides ways to indicate that certain functionality has been deprecated, it can serve as a indication for the users to stop using old API calls and transition to new calls instead. In Java, the @deprecated javadoc tag can provide notes in the documentation that a feature has been deprecated, or from Java 5 the @Deprecated annotation can be used to raise compile-time warnings on calls to deprecated APIs features.

Also, it would probably be a good idea to provide some tips and hints on migrating from the old API to the new API to encourage people to use the new way of interacting with the API. Having examples and sample code on what to do and what not to do, the users of the API would be able to write code according to the new, preferred way.

It's going to be difficult to change a public API, but with some care taken in the transition from the old to new, I believe that it the amount of pain inflicted on the users of the API can be mitigated to a certain extent.

Here's an article on How and When to Deprecate APIs from Sun, which might provide some more information on when it would be appropriate to deprecate parts of APIs.

Also, thank you to David Schmitt who added that the Obsolete attribute in .NET is similar to the @Deprecated annotation in Java. (Unfortunately the edit was overwritten by my edit, as we were both editing this answer at the same time.)

get layout height and width at run time android

Suppose I have to get a LinearLayout width defined in XML. I have to get reference of it by XML. Define LinearLayout l as instance.

 l = (LinearLayout)findviewbyid(R.id.l1);
ViewTreeObserver observer = l.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

@Override
public void onGlobalLayout() {
// TODO Auto-generated method stub
init();
l.getViewTreeObserver().removeGlobalOnLayoutListener(
this);
}
});

protected void init() {
int a= l.getHeight();
int b = l.getWidth();
Toast.makeText(getActivity,""+a+" "+b,3000).show();
}
callfragment();
}


Related Topics



Leave a reply



Submit