java - conditionally implement an interface -
so i'm trying animations in app , had way without using objectanimator , animatorlistener api 11. however, they're not smooth , robust doing animations using classes.
so made changes code in object's class check api level, objectanimator , animatorlistener stuff wouldn't called unless api level 11+.
the problem object implementing animatorlistener though functionality isn't being used in versions of code. think leading verifyerror on start of app because crashes on devices api level 10 , down.
is there way conditionally implement interface based on api level or different way achieve same thing?
thanks!
actually, ok if build against or higher sdk target, issue when code run on device missing classes higher sdk. others suggested, can go factory
public class factory { public static <t> t getimplementation(){ if(<sdk_level_incompatible>){ return (t)new <package>.oldschoolanimator(); }else{ return (t)new <package>.superanimator(); } } } ... someimplementation impl = new factory().getimplementation(); ... watchout, "someimplementation" has common super-type or interface of oldschoolanimator , superanimator classes! dont use "imports" implementation classes in factory, rather use full-qualified classnames.
Comments
Post a Comment