I have no clue as how to set string path - android

I am using a third party library for splash screen. I got it from https://github.com/ViksaaSkool/AwesomeSplash. I have followed the whole tutorial but i am getting error while setting string path. It has a line
"configSplash.setPathSplash(SyncStateContract.Constants.DROID_LOGO); //set path String". Android studio is unable to resolve DROID_LOGO and i am getting error. I replaced DROID_LOGO with DATA and got this error.
As suggested on the post i have written this code.
public class splashex extends AwesomeSplash {
//DO NOT OVERRIDE onCreate()!
//if you need to start some services do it in initSplash()!
#Override
public void initSplash(ConfigSplash configSplash) {
/* you don't have to override every property */
//Customize Circular Reveal
configSplash.setBackgroundColor(R.color.colorPrimary); //any color you want form colors.xml
configSplash.setAnimCircularRevealDuration(2000); //int ms
configSplash.setRevealFlagX(Flags.REVEAL_RIGHT); //or Flags.REVEAL_LEFT
configSplash.setRevealFlagY(Flags.REVEAL_BOTTOM); //or Flags.REVEAL_TOP
//Choose LOGO OR PATH; if you don't provide String value for path it's logo by default
//Customize Logo
configSplash.setLogoSplash(R.mipmap.ic_launcher); //or any other drawable
configSplash.setAnimLogoSplashDuration(2000); //int ms
configSplash.setAnimLogoSplashTechnique(Techniques.Bounce); //choose one form Techniques (ref: https://github.com/daimajia/AndroidViewAnimations)
//Customize Path
configSplash.setPathSplash(SyncStateContract.Constants.DROID_LOGO); //set path String(**I am getting error here**)
// configSplash.setOriginalHeight(400); //in relation to your svg (path) resource
configSplash.setOriginalWidth(400); //in relation to your svg (path) resource
configSplash.setAnimPathStrokeDrawingDuration(3000);
configSplash.setPathSplashStrokeSize(3); //I advise value be <5
configSplash.setPathSplashStrokeColor(R.color.colorPrimaryDark); //any color you want form colors.xml
configSplash.setAnimPathFillingDuration(3000);
configSplash.setPathSplashFillColor(R.color.colorPrimaryDark); //path object filling color
//Customize Title
configSplash.setTitleSplash("My Awesome App");
configSplash.setTitleTextColor(R.color.colorAccent);
configSplash.setTitleTextSize(30f); //float value
configSplash.setAnimTitleDuration(3000);
configSplash.setAnimTitleTechnique(Techniques.FlipInX);
configSplash.setTitleFont("fonts/myfont.ttf"); //provide string to your font located in assets/fonts/
}
#Override
public void animationsFinished() {
//transit to another activity here
//or do whatever you want
}
}
The error i am getting is
java.lang.RuntimeException: Font asset not found fonts/myfont.ttf
at android.graphics.Typeface.createFromAsset(Typeface.java:190)
I searched various links and all suggested to add assets folder but i dont know where to make assets folder and what to store in that.
please help me with all the details about assets and fonts.
Still i am getting this.

You have to create folder named fonts according to the following path:
your_android_project_folder > app > src > main > assets > fonts
Now within your fonts folder,you need to store your myfont.ttf file.

I had the same problem and here is how I solved it :
For the missing DROID_LOGO, you can rewrite the line from this:
configSplash.setPathSplash(SyncStateContract.Constants.DROID_LOGO);
to this :
configSplash.setPathSplash(SyncStateContract.Constants.DROID_LOGO);
Here, make sure you add to your project the Constants.java class which can be found here
And for the missing font, go to the line
configSplash.setTitleFont("fonts/myfont.ttf"); //provide string to your font located in assets/fonts/
and replace myfont.ttf with another font present in your assets/font folder for example fonts/diti_sweet.ttf(which can be found on the AwesomeSplash repository) and averything might work fine

Comment out this line:
configSplash.setPathSplash(SyncStateContract.Constants.DROID_LOGO);
and rename myfont.ttf to your font in folder assets.

Related

Processing Android: java.lang.IllegalArgumentException: File contains a path sepator

Im currently trying to save some values in a text file in Processing Android (APDE). I want to later use this in another context, so it's important to use a complete file path. From Processing documentation for loadStrings():
... Alternatively, the file maybe be loaded from anywhere on the local
computer using an absolute path (something that starts with / on Unix
and Linux, or a drive letter on Windows)
So it must be possible.
I already searched for a answer, but never found something for Processing.
So my code is:
String[] saveData;
int score;
void setup(){
saveData=loadStrings("/storage/emulated/0/dataP/hi.txt");
score=parseInt(saveData[0]);
fullScreen();
frameRate(60);
noStroke();
noSmooth();
textAlign(CENTER);
textSize(height/20);
}
void draw(){
background(0);
fill(255) ;
text(score, width/2,height/2);
}
void mousePressed(){
score--;
saveData[0]=str(score);
println(saveData[0]);
saveStrings("/storage/emulated/0/hi.txt" ,saveData);
}
and I get the following error:
java.lang.IllegalArgumentException: File
/storage/emulated/0/dataP/hi.txt contains a path separator
I believe the confusion stems from the fact that loadStrings() method works differently for Java mode and Android mode. In Java mode, it is definitely possible to give loadStrings() an absolute Path with included separators, but in Android mode, loadStrings() will only work if you only specify a name without any separator (assumes by default to be looking into the data folder). Therefore, having any separator inside loadStrings() will throw the error.
One simple workaround you can try is to first create a separate path variable:
String path = "/storage/emulated/0/dataP/hi.txt";
And then give that as parameter to the loadStrings() method:
saveData = loadStrings(path);
If you were to use an SD card for storage, for example, you could do something like:
String SDCARD = Environment.getExternalStorageDirectory().getAbsolutePath();
File file = new File(SDCARD + File.separator + "mytext.txt");
String[] s = loadStrings(file.getPath());
As explained in the link in the comment I posted, loadStrings() and saveStrings() does not take absolute path as argument. What it means is that it can only access files with path "name.txt" and not "folder/name.txt". You have to do it using a FileInputStream and FileOutputStream if you must use absolute path. There are many examples of both these files on StackOverflow.

How to access to a file inside resource folder different from standard 'res' - Android

In Android Studio, I need to use some resources (image, audio, etc...) from a folder different from the standard 'res',
Let's suppose that I have:
the '_Resources' folder containing the image 'aaa.png' .
the standard 'res' folder containing the image 'bbb.png'
I have put inside gradle file:
android {
sourceSets {
main.resources.srcDirs += 'C:/..../myLibrary/src/_Resources'
}
}
After that I see in Android window (top left of Android Studio) correctly both the standard 'res' folder and the 'resources' folder.
if I have to access to 'bbb.png' of 'res' standard folder, I use:
import com.myproject.R
.....
int xxx = R.drawable.bbb
THE QUESTION IS:
how can access now to aaa.png?
It is not seen in R. ; so I tried to import something else, but what?
Thank you in Advance
Fausto
This is not possible. If you define two png file with the same name in multiple resource folders android will load just one of them (not sure which one).
The name of them are actually their ID. And the concept of ID is sensful if its unique. So you cant do this.
Having multiple resource folders is just something to separate files and make everything more clear and better. Just foldering and nothing more.
for those that could have the same problem:
I didn't have success in accessing to resource folder, but I found another solution that fits my needs:
I added the '_Resources' folder in Assets, writing in gradle file:
main.assets.srcDirs += 'C:/..../myLibrary/src/_Resources'
then I get access in code to resources by:
AssetManager assetManager = getAssets();
InputStream myInputStream = assetManager.open("aaa.png");
That's all...

How to load Textures with Unity3d on Android

i am trying to get this really easy setup to work, and it works on my computer but not on Android.
After trying it for the whole day im now asking since i cant find a single example on the internet.
The setup:
I have a lot of *.png files in a folder. Since the problem is with android i put them into a "StreamingAssets" folder
I have a RawImage called "Overlay"
I have a Dropdown called "Dropdown"
What should happen:
1. The Dropdown_script checks the StreamingAssets folder for all *.png files and adds every Filename to the dropdown options menu.
2. Once the user chooses one of the dropdown values my "Overlay" image changes its texture to the according file.
Pretty easy on PC ... impossible on android(with unity3d) as it seems.
My Dropdown Script:
public class DDScript : MonoBehaviour {
void Start () {
GameObject obj = GameObject.Find("Dropdown");
//Get all filenames
var info = new DirectoryInfo(Application.streamingAssetsPath);
var fileInfo = info.GetFiles("*.png");
//Clear the DropDown Menu Items from the Inspector
obj.GetComponent<Dropdown>().options.Clear();
//Make the first chosen item the first filename
obj.GetComponent<Dropdown>().captionText.text = fileInfo[0].Name.Substring(0, fileInfo[0].Name.IndexOf("."));
foreach (var file in fileInfo)
{
Dropdown.OptionData list = new Dropdown.OptionData(file.Name.Substring(0, file.Name.IndexOf(".")));
obj.GetComponent<Dropdown>().options.Add(list);
}
}
Its not working. It is working on my Computer but it is just not working on Android. I know that under Android everything gets packed into a jar file and there is nothing like a folderstructure. StreamingAssets should still have the files but i can understand that this part maybe cant work. Which would not be that bad, since it just finds the names and puts it into an array, i could do that within the program by hand. Since i know from beforehand how much and which files will be in the folder and it wont change ever.
This is my Change Texture Method
It is invoked by the Dropdown OnValueChange so the "newOverlay" is simply the int from the Dropdown. For debugging purposes i set the filepath to a specific file. later it will change depending on newOverlay
public IENumerator SetOverlay(int newOverlay)
{
GameObject obj = GameObject.Find("Overlay");
img = (RawImage)obj.GetComponent<RawImage>();
string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "testfile.png");
WWW www = new WWW(filePath);
yield return www;
img.texture = www.texture;
}
And i do not understand why this is not working!
The Documentation reads:
" This means that if you do not use Unity’s WWW class to retrieve the file then you will need to use additional software"
So using www is the right way. But it is not working!
No Texture gets loaded. i dont get the red questionmark, my image is just plain white. Please can someone help me here? Maybe i just cant see the forest due to all of the trees or the day was too long.
I really just cant believe that it is this hard to load a bunch of images that are within my apk file wiht unity :(
Thank you very much in advance
Edit: Solution (somehow)
First of all the problem was that System.IO.Path.Combine adds a back-slash between file and folder, but not between the folders themself!!!!
public void SetOverlay(int newOverlay)
{
GameObject obj = GameObject.Find("Overlay");
img = (RawImage)obj.GetComponent<RawImage>();
string filePath = Application.streamingAssetsPath + "/testfile.png";
WWW www = new WWW(filePath);
while (!www.isDone)
{}
img.texture = www.texture;
GameObject.Find("DebugText").GetComponent<Text>().text = filePath;
}
Havent found a solution to the Filename problem yet but im glad that this stupid "bug" is resolved
Have you tried putting the png files into the drawable folder and accessing them with BitmapFactory.decodeResources()?

Integrate a specific font with Android apk

I have built an application which displays the news in Nepali (Devnagari) font.
Everything is fine but the problem is that the font is not displayed properly in some Android phones.
Here I have posted two images showing the variation of the same content in different phones. The first one is perfect but the second one is incorrectly displayed.
1st Image with correct fonts
2nd Image with incorrect fonts
The problem I realized is that the second phone does not contained the correct font installed in it.
How can we get rid of this problem?
I have got no proper idea regarding this, but a solution that came in my mind is that - What if we integrate the necessary font along with the apk file and the font too gets downloaded with the apk.
Please pass me suggestion for this and would be grateful to know how to implement any solution that exists.
If you are using the native Android Textview Component you could use the method:
public void setTypeface (Typeface tf)
And create the typeface this way :
static Typeface createFromAsset(AssetManager mgr, String path)
Create a new typeface from the specified font data.
Typeface.createFromAsset(getAssetManager(),"RELATIVE_PATH_TO_YOUR_TYPFACE_IN_THE_ASSET_FOLDER");
If you are using Android Studio the asset folder should be created under src/main/assets.
Make 1 folder in assets named "fonts", put your font files inside that folder. e.g. see following image
import android.graphics.Typeface;
Then declare Typeface object
Typeface allFontType, allFontTypeNormal, allFontTypeLight;
try
{
allFontType = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/Dosis-Bold.ttf");
allFontTypeNormal = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/Dosis-Medium.ttf");
allFontTypeLight = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/Dosis-ExtraLight.ttf");
}
catch (Exception e1)
{
e1.printStackTrace();
allFontType = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD);
allFontTypeNormal = Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL);
allFontTypeLight = Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL);
}
To apply font in TextView use following code
TextView lblDaysName = (TextView)view.findViewById(R.id.lblDaysName);
lblDaysName.setTypeface(allFontTypeNormal);

I have there is no resources error in my xml file

I have an Android xml file that added to create a splash, for this splash I uploaded a image and set xxhdpı, xhddi, mdpı, hdpı formats from nine patch then I added each one to each format (I mean xxhdpı to xxhdpı format and mdpı to mdpı format folder under resources) then it gives an error
no resources found the given name(at backround with value '#drawable tesbihsplashh.9.png'
Set Background image like:
android:background="#drawable/tesbihsplashh"
Make sure tesbihsplashh.png image avialable into your drawable folder.

Categories

Resources