Using another project as a library - android

still learning android and this is where i am stuck.
I want to use this project as a tutorial for my app
https://github.com/PaoloRotolo/AppIntro
It has a wiki, and it says i need to add gradle dependency which i'm pretty sure i'll handle properly.
Whats bothering me is how do i extend that app to my class? where do i put that project/library inside my project?
Sorry if this question is newb-ish, i tried alot of things and they didn't work.
Thank you for your help!

Since you said you'd handle adding the gradle dependence I believe you are asking how to implement an Intro screen? Did you read the How to use part on the home page of the library?
Everything is explained there. What to extend and what each method does. For the actual creation of each fragment I will give you a hint.
After creating a new class for your Intro screen, if you don't have a specific layout for your fragment just use that part of the code:
addSlide(AppIntroFragment.newInstance(title, description, image, background_colour));
where the parameters are variables that you choose. For image you could use any of your images inside the drawable folder like R.drawable.intro_ico and for background colour - ContextCompat.getColor(this, R.color.grey)
'grey' color has to be created in your colors.xml or choose anything you like.
EDIT: And if you were wondering whether you should download something and where, no you are all done only by adding these lines of code to your build.gradle. When you add them, Android Studio asks to Sync the gradle file, and then it downloads the library.
For some libraries, you'd need to download a jar file or git clone from a repository and then maybe add the downloaded folder as a Module to your project by going Android Studio>New>Import Module>locate the folder . However, for that one, adding the dependency is enough as it gets downloaded after the Sync.

it's really very simple!
you just add these lines :
repositories {
mavenCentral()
}
dependencies {
compile 'com.github.paolorotolo:appintro:3.4.0'
}
in your build.gradle file under app folder.

Related

How to read Asset resources from "Android Library Project"

I have:
one Main App
one Android Library Project with a Fonts in it in "assets/fonts/Old_English.ttf
The Main App references the Android Library Project and it works fine except the following:
I would like the use the shared asset resource, but I don't know how to do. Can someone help ?
Typeface.createFromAsset(getAssets(), "fonts/Old English.ttf")
These might work:
Storing and accessing assets.
library structure
MyLibProject/src/main/assets/Old_English.ttf
Project Reference
Typeface.createFromAsset("file:///android_asset/Old_English.ttf");
The solution is as per the link mentioned. I didn't try its working. Please comment if it works or not.
Make sure that you store your fonts according to the following structure :
Now use the following line :
Typeface typeface=Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/Old_English.ttf");

Android Studio can't find R.layout.simple_list_item_1, or any other default layout IDs

IDs for things like R.layout.simple_list_item_1 don't show up on autocompletion in Android Studio. Nor can they be resolved when the name is typed in manually. I'm trying to use an ArrayAdapter, and I had to manually create a simple_list_item_1.xml in my project layout directory, and paste in the contents from the Android repository on Github
Am I missing something, or is that what's supposed to be done? Most resources I go to seem to just reference the list item XML without doing anything else
to use android predefined layouts, colors etc. You should use
android.R.layout.simple_list_item_1
probably you try to reach your own resources. Check your imports and you should see your R file.
as #Orhan Obut explained, use
android.R.layout.simple_list_item_1.
Do NOT leave out the word android in the above statement. That is how you access android's predefined resources
It's two years later but never too late because I spent the day reading all posts about this and the answer on the Android Developer site was simple: make sure the google depository is installed for your project in the repositories section of its build.gradle:
maven {
url "https://maven.google.com"
}
Worked for me as soon as the project was synched after adding the .
I got the same error. The error was resolved when I imported android.R.layout and typed layout.simple_list_item_1 instead of R.layout.simple_list_item_1.

Multiple library projects in aide?

I am trying to work on my android app from my phone and tablet using Aide. I keep getting hundreds of errors. It seems as if it is only detecting one library project at a time. I can change which errors I get by removing a library and adding a different one (I am using three)
Has anyone successfully used multiple project libraries in aide, and might be able to offer some assistance?
My project . properties looks like this:
[Eclipse references (I think)]
android.library.reference.1=../../../../libraries/android-greendroid/GreenDroid
android.library.reference.2=../../../../libraries/ActionBarSherlock/library
[Aide references]
android.library.reference.1=/storage/extSdCard/code/android-actionbarsherlock/library
android.library.reference.1=/storage/extSdCard/code/android-facebook/facebook
android.library.reference.1=/storage/extSdCard/code/android-greendroid/GreenDroid
android.library.reference.1=/storage/extSdCard/code/android-actionbarsherlock/library
android.library.reference.1=/storage/extSdCard/code/myproject/android/free
So, the aide references are all .1 and there are no new lines between them.
I also had the same problem and fix this formating references like in eclipse.
Like this:
[Eclipse references]
android.library.reference.1=../../../../libraries/android-greendroid/GreenDroid
android.library.reference.2=../../../../libraries/ActionBarSherlock/library
[Aide references]
android.library.reference.1=/storage/extSdCard/code/android-actionbarsherlock/library
android.library.reference.2=/storage/extSdCard/code/android-facebook/facebook
android.library.reference.3=/storage/extSdCard/code/android-greendroid/GreenDroid
android.library.reference.4=/storage/extSdCard/code/android-actionbarsherlock/library
android.library.reference.5=/storage/extSdCard/code/myproject/android/free
You can't edit project.properties in AIDE, so use text edit and fix this. Put enter in right place and fix reference number ;)

How to add my own class inside preloaded-classes which is available in \android\frameworks\base

I am trying to find steps on how to add my own class into preloaded-class?
Please let me know if anyone have tried this.
You can edit the preloaded-classes file inside the framework.jar at any time.
I do this with patches for a project. Just add it to the list, the preloaded-classes file is simply a text file inside the jar.
For a build, the process is the same, you can add those classes to the list at frameworks/base/preloaded-classes
Edit: Since this is my first answer, how about a little documentation...see no less than Diane Hackborn address this here.

Android - Multiple .apk file from single code base

I had developed 3 applications in android where the major functionalities are the same but the UI looks different. Images and the background color of the screens are different.
NOw, i want to create a single code base from which i can generate multiple .apk files for the 3 apps.
I tried creating 3 different packages for src folder for the 3 apps. But i dont know how to set the res folder for these apps.
Need pointers on creating a single code base from which we can generate multiple .apk files which includes only the respective src and res folders.
Use an Android Library Project that contains all your common code.
Create separate Android projects that reference the Library Project (you will need to copy your Manifest into each of these and make sure all components are declared with their full Java package name).
Put any resources specific to each app (drawables, colors etc) into the individual project resource folders and they will override similarly named resources in the library project at build time.
i think the best option is to use ant, you'll need to add an ant target for each build and change the resource folder.
if you use the generated build.xml, the res folder is defined like this
<property name="resource.absolute.dir" location="res" /> so you'll want to override that
Can't you put all of your common code into a library project and then just reference that project from each of the 3 unique projects that each contain the relevant resources.
Update: This answer is now obsolete when using the Gradle build system.
Why don't you use a single application, that does three different things based on SharedPreferences values set by the user, or from context at install time. If you really want to separate, you can have three different activities, and you decide which one to launch from a silent main Activity that redirects to either of the different ones.
An alternative is to have a unique activity that inflates itself dynamically from 3 different layouts at onCreate time.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (...custom check for layout... equals(layout1)) {
setContentView(R.layout.main_layout1);
} else if (... equals(layout2)) {
setContentView(R.layout.main_layout2);
} else if (... equals(layout3)) {
setContentView(R.layout.main_layout3);
} else {
throw new IllegalStateException("Unknown layout!");
}
... your onCreate stuff....
}
It will make code maintenance easier (only one code source to modify, only one version-list and changeset to maintain)
Check here:
How to use SharedPreferences in Android to store, fetch and edit values
I would suggest using Gradle flavors.
It seems to explain all the basics really well. I just finished converting to Gradle today, and it works great. Custom app icons, names, and strings, etc.
As the website explains, part of the purpose behind this design was to make it more dynamic and more easily allow multiple APKs to be created with essentially the same code, which sounds similar what you're doing.
Also see a recent question I had, referring to your project structure and using custom code for each app.

Categories

Resources