Android Library Project -
how can use android library project, , overwrite classes in "final project".
in other words, want reference library project, , @ same time, change of code..
probably not quite android library projects achieve using interface , class inheritance features of java language itself.
library project seem deal merging/overriding resources parent in child , letting use 1 codebase varying app package names.
given updated comment using library projects have 1 edition of app uses admob , 1 doesnt, i've revised answer...
assuming dont mind packaging admob library (~138kb) in full/paid edition, simplest thing extend applcation class , therein declare enum , static method decide whether admob ads should shown.
public class application extends android.app.application { public enum editiontype { lite, full}; public static int getadvisibilityforedition(context ctx) { if (editiontype.valueof(ctx.getstring(r.string.edition)) == editiontype.full) { return view.gone; } return view.visible; } } you'll add class library project only. in 3 of projects you'll need add entry /res/strings.xml such:
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="edition">lite</string> </resources> it doesnt matter value of string in library project, you'll vary in paid vs. ad supported editions using full , lite respectively.
finally, make activities responsive these values call in oncreate() or onresume():
view ad = (view)this.findviewbyid(r.id.your_admob_view_id) ad.setvisibility(application.getadvisibilityforedition (this.getapplicationcontext())); this work fine admob admob code wont try ad if view not visible.
if dont want have 138k admob jar , manifest permissions needed in full edition, there more elegant ways involve using kind of wrapper around admob stuff , either varying xml layouts between editions (to include admob view or not) or inject admob view layout programatically.
hope helps.
Comments
Post a Comment