Creating an Android UI library that has a customisable front end - android

I have several custom UI elements that are to be used in several projects. Each project will use the same UI elements but have a different looking front end.
eg: Background images for button types will be different depending on the project.
How do I package the UI classes and resources in such a way so that projects can use them while being able to modify the look and feel?

Use Android library project, that will be shared among multiple apps. Provide there default graphics.
When you provide customized graphics in your app for particular file in res folder, it will be used instead of default graphics in library. This way you can replace needed graphics set while using same code base.
Info:
https://developer.android.com/tools/projects/index.html#LibraryProjects

Related

android shared layout from library to app

I am creating three apps that are almost the same except some changes in the assets and raw files between them.
So I wanted to create a library from the first one, that will contain all the logic and activity and all the layouts and resources, and then import this library to the other two apps, and only change the assets and raw files.
the problem is that when the layout from the library loads, it is loading the assets from the library itself, and not the assets of the main app.
I am sure that my design here is wrong then I would also appreciate if someone can explain to me what is the right way to share activities and layouts as libraries in android.
NOTE: I don't want to use flavors. I want to build it as a completely different projects.
cheers

What is the correct approach for developing react native apps

I am new in react-native. I am trying to develop my first app in react-native. I want to know what is the correct project structure for developing react-native apps.
As of now, I have created component in root folder. I want to know what approach should I take for defining model, utils, webservice urls in what structure.
Does it has some kinda framework as like express for creating project structure in nodejs.
From my experience in building quite a large app using react-native. I have followed this approach and it scales pretty well for a team of 5+ people working on it .
App folder : : In this folder I keep all the files/folders related to app. Do not add anything in root folder. the less convoluted the root folder is the better for new person to get started.
uicomponents :
The uicomponents folder holds all the generic controls that app needs. eg : Dropdowns, sliders, buttons, checkboxed. You can avoid this if you are using a external lib.
components :
This folder holds folders for each section of screen. I call it modules for app. Each module is specific area of app, namely : HomePage, UserData, Settings so on so forth. This varies from genre of the app. My happens to be enterprise app, So I have folders for each module for an app.
Utils :
I am big fan of keeping utils at one place. Things like text formatters, Db handers, Oauth Handlers and so on.
Stores, Dispatchers :
Anything related to flux, redux can go in there.
In general the app has to be broken down in appropriate folders and files. One specific part of the app or module as I say has to have its own folder. All the files needed by him has to be in it. This makes it easy to be maintained and reasoned about.
Avoid duplicating code from beginning. Keep reusable things in Utils. All control related components (inputs, buttons, checkboxes) at one place.
Always keep styles at one place. Use constant variables for colors, this makes making changes very easy. The constant file holds colors.

Android complex project organization

Im thinking about trying to build a complex android app structure for a game maybe or just for practice reasons. Im used to code in objective-c, so im not that much experienced in android...
Anyway in work, we structure our app on ios like this:
-core framework: handling all core items, navigation, datahandling, mechanisms, etc. its the same in all of our project
-project framework: its files are mostly relying (including) the core framework's files, extending/modifying them, and doing the project depending stuff
-skin framework: this contains all the resources and images, if we want to do a re-skinned project, we only have to alter this
-main project: this includes everything just bashing together everything into an app. just starts the application, nothing more, anything else is done by the different frameworks
So I wanted to do a similar structure on android, but I'm not sure that I'm even able to do it... I see that there is android project and library project, I can include them into eachother... but my questions are:
1: can I build a similar structure as on ios?
2: can I make for example a "core" library what contains the basics of mechanisms, and another library containing only the resources, and a third one (or the third could be the actual runnable project), what can get resources from the resource library, can distribute jobs to the core library, etc...
3: can I organize the resources as I like (so not to throw every picture into the drawable folder root for example). For example to have somehow a characters folder (i know i cant do forlders in the res folder), and map files into map folder, etc... My only chance to name them "properly"? (map_sheet_type_1, map_sheet_type_2, character_sheet_type_1, etc) (if its going to be a game, it would use opengl, lots of sprite drawing, etc)
or I should do everything in a single project, dividing everything into a lot of packages, and use libraries only for jobs like "how to transcode "A" object into "B" object" ?
Thanks for the answers in advance
although I've never developed a game before, but an app is an app:
yes
as you mention you have executable projects and libraries projects, libraries can use other libraries and the only thing that goes to the device is whatever the executable project is building. It's just important to remark that compiled libraries *.jar files resources cannot be used in your executable project (that's why the ActionBar Sherlock have to be used as a library-project). In order to use a resource placed in a library project the project must be with its full source code open in the Eclipse so it can be compiled together. That is because inside an app, there's only one R (resources) object, and during build all the resources from all the projects are put together.
unfortunately no. As you mentioned yourself the resources cannot be in subfolders and even their file names are restricted as they can only use lower case letters, numbers and _ (underline). Just be clever and organised, write a spec or something.
packages IS the way to organize a single project in Java. If you gonna use multiple or single is your choice. Usually you can encapsulate in a library-project stuff that can easily be re-used in different projects, and the final project will contain everything that is specific to that one app/game. I'll give you an example on the place I work, we have a KicthenLibrary that is a library-project that we use in every single Android app we do. That library already contains an excellent multi-threaded bitmap download and cache classes, we used to have a MapFragment (now deprecated) before Google released their MapFragment, easy Http GET/POST methods, etc. As you can see, all of those are stuff that can easily be re-used in several different projects.
And just as a last trick, http://www.eclipse.org/egit/ IMHO is much easier to use GIT directly from inside Eclipse.
Here are a couple links that should help you get started on this.
http://kasperholtze.com/android/how-to-best-organize-your-android-source/
http://bartinger.at/organization-tips-for-android-projects/
Also, when I worked at a start-up, we made an app for both iOS and Android. We started creating native apps for each, and ended up having somewhat different structure. Global information/variables were handled different, and I couldn't structure my files quite like iOS did. That said, Android structure isn't terribly hard to figure out, and I made a fair amount of sub-folders in my assets folder (for libraries and js and such). And yes, you can definitely have several libraries.
As for having several projects in several in one app, see this link How to create a single application from multiple Android projects

Android : creating drawables with CSS input

I am new to Android but not to Java. Is there already a little framework which allows me to create layouts, custom views and drawables programmatically using CSS sheets for padding, borders etc; just like Nimbus/Three20 for iOS ?
We've working on an "App-Studio" so all the views, lists etc. are rather dynamic, basing on the CSS the user created by a visual style template editor.
And if not, would you recommend to create such Android layout xml files on the fly and then load them from file, or is it better to create the drawables by hand ? We'can't bake such files just into the build because the user needs to be able to change the style in real-time on the device.
Thank you.
Partial ans only to:
And if not, would you recommend to create such Android layout xml files on the flyand then
load them from file, or is it better to create the drawables by hand ?
I dont think you can create layout xml files on the fly and load them in the running app. They have to be created prior to compilation of the app.
Android uses Styles and Themes. Reading about these will help you generate some common patterns which you can use in your context. Once you have some patterns you can create these xmls using some automation tool prior to compilation (and avoid writing them by hand...:), funny computer changed the definition of by hand).

Tips on organizing larger Android projects?

My current project is getting awfully large. I have dozens of activities, adapters, fragments, layout xmls, and other resources.
In my (smaller) previous projects I organized stuff with a 1 package / 1 category style. So I had com.stuff.xy.adapter, com.stuff.xy.activity, and so on. Now these packages contain too many items, and I find myself wasting considerable amounts of time searching for a specific class in the package hierarchy.
I use Eclipse, and there are some shortcuts one can use (go to class definition e.g.), but those tend to be situational (I can't use that to quickly jump to a layout definiton xml).
Could you share some tips on organizing large scale projects efficiently? Or some plugins for this perhaps? (It might help for example if I could group together source files that deal with a specific application screen - adapters, layouts, activity and fragment code - so I can quickly open them)
EDIT: After many months developing large projects
First I tried to go with working sets with Eclipse. It didn't really cut it for me, my problem was that our single Android project was simply too big, containing many resources, classes, interfaces, etc. Messing around with working sets in the context of a single project just took too much time, I think that they're mainly useful to organize projects in a single workspace.
On the long run we separated our huge single project into many smaller android-library projects and a single "main application" project that depended on all these smaller ones. This way we could split the resources among these library projects (there were many layouts, values, styles that were only used in certain parts in the application) and code of course. I also created a Base library, that all other libraries depended upon, and contained resources and (base)classes that every part of the application needed.
For all my android projects I prefer to sort code in the following structure:
com.company.projectname is the package of the application.
Underlying packages:
model - all my business-objects
logic - services and objects implementing business logic
screens - all the activities of the project. If activities require adapters and so on, then each activity is placed in a separate package under screens package and the related stuff is placed to the same project.
tools - package with Utility class. SettingsUtil and so on.
In the root of the package I usually have Constants.java interface with constants.
In Eclipse, you can use Working Sets to filter your source/layout/resource files in the Project Explorer view. This is a bit more powerful than packages, since it operates on all files including layout and image assets, not just java source files.
For example, you could create a Home working set which contains HomeActivity.java, HomeAdapter.java, res/layout/home.xml, res/drawable/home_icon.png, etc.
Just another tip.
Use Ctrl-Shift-R to quickly open a resource (you get an autocomplete drop down) and Ctrl-Shift-T to quickly open a java class. The list will also auto-populate using the most recent opened files.
Maybe a tip: to quickly go to a declaration in Eclipse
Hold Ctrl while hovering over a class or method. After 1 sec you get a popup with open declaration / open implementation.
Very useful in large project.
For the rest i recommend just making it intuitive and sort all Activities in a package aswell as all calculations e.g.
for your concern "I can't use that to quickly jump to a layout definiton xml", you can click the name of the layout xml, then ctrl+shift+R will lead you to that definition page.

Categories

Resources