How to read Asset resources from "Android Library Project" - android

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");

Related

Using another project as a library

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.

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.

Android: Refer a property value into string.xml

Consider following project hierarchy
Base
Common
Flix
We have Base and Common as library project which we are using in several other projects like Flix. We would like to define some sort of property file into Base and Common project and would like to refer the properties defined at Base or Common level into string.xml file of Flix project.
For example
Consider we have a property file named base.properties under "Base/assets" folder with following content
app.props.cms.url=http://test.flixv2.dev.com/api
We have string.xml file into Flix project, where we have a string resource
<string name="cms_url">HERE WE WOULD LIKE TO REFER THE PROPERTY</string>
we have tried following which is not working
<string name="cms_url">${app.props.cms.url}</string>
Please let know your views.
Thanks
Are you using any kind of build system like Maven or Gradle? This seems to me like a dependency thing.
There is another way out, which is not exact solution of my question
Ref: Concatenate multiple strings in XML?
we tried following:
created a string resource in Base project as below
<string name="app.props.cms.url">http://test.popcornflixv2.device.screenmedia.net/api/</string>
And refer the same into Flix project as shown below:
<string name="cmsservice_url">#string/app.props.cms.url</string>
There seems to be a suggestion that the "official way" of doing this (where you insert the package name prefix) does not work. However, this is a very old report, so I would try that first, before the "reflection" approach - both of which are described here:
android import ressources from library project

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 ;)

Type R is already defined error

How do I fix this? I already tried removing the R.java and cleaning the project via eclipse, but it doesn't help.
FYI I am trying to get PhotoStream from here: http://code.google.com/p/apps-for-android/, but so far it has been very difficult to get things work.
Okay..... 5 mins later google tells me the correct answer...
http://www.fairtec.at/en/it-blog-mainmenu-16/168-the-type-r-is-already-defined
I just didnt search hard enough.
"The type R is already defined"
That's the message you get in Eclipse if you try to build the Funambol Android Sync Client.
Reason is that you have checked two Builders that try to generate the same class.
You just have to uncheck the Java-Builder from Project->Properties->Builders.
Then the application even works fine in the Emulator.
Delete the R.java from the src folder and rebuild the project. This file will be automatically rebuit during this process.
http://www.fairtec.at/en/it-blog-mainmenu-16/168-the-type-r-is-already-defined
click right to project click properties
Project->Properties->Builders.
unckeck java Builder
delete file R.java
You may want to change your package names. It looks like you are using a 'PhotoStream'.jar which has it's R.class defined at the same package structure as you.
Here is a link to the R.java from the project on Google Code. Notice you are using the same package:
http://code.google.com/p/apps-for-android/source/browse/trunk/Photostream/src/com/google/android/photostream/R.java?r=83
I had the same issue when I imported a project from work. Turning off the Java builder as suggested in the article you found fixed my problem, but when I made code updates they were not reflected in the running app. In my case there was an R.java in my source which I deleted and that fixed my problem.
In my case,
as i m not using any IDE for programming but using command line Android..
i had two xml files, one in layout and other in layout-land. i was using same id "XXX" for both but while declaring i made small mistake
android:id="#+id/XXX" (in layout xml)
android:id="#+id/XXX " (in layout-land xml)
please observe extra space in second id declaration, so while creating R.java they were different and in R.java i had
public static final int XXX=0x7f040046;
public static final int XXX =0x7f040045;
which are same, so please be aware of extra spaces. Thank you

Categories

Resources