2

I am having a problem with my Android code. I am developing a game on Android. I first stored my images on resource file. But now I want to store them on Firebase. My plan was to download them using Picasso and add them to an Arraylist. But it doesnt have a method for returning just a drawable object. I tried to fetch BitMap and convert it to a drawable but it didnt work.

    flagImages=new ArrayList<Drawable>();
    flagImages.add(getResources().getDrawable(R.drawable.flag1));
    flagImages.add(getResources().getDrawable(R.drawable.flag2));
    flagImages.add(getResources().getDrawable(R.drawable.flag3));

I want to change the code above. Do you have any ideas? What should I use? My primary aim is to put the images into my ArrayList.

AL.
  • 36,815
  • 10
  • 142
  • 281
b2d2
  • 79
  • 1
  • 12
  • upload the image into firebase storage, and then save the url in firebase, and also, i would suggest glide then picasso, especially for memory performance – Faruk May 08 '17 at 23:27
  • But how do I download the data? Should I use bitmap? thus glide and picasso doesnt output drawable object – b2d2 May 08 '17 at 23:35
  • This link for all Firebase listing data and images in drawable resource https://stackoverflow.com/a/45328201/5973946 – viral 9966 Jul 28 '17 at 13:12

1 Answers1

2

Step 1: Upload all your images into Firebase Storage. Every image that is uploaded has a specific reference which you'll be able to save in the Firebase Database under a node named links.

Step 2: Attach a listener on the link node and get all the reference of your images.

Step3: You will need this build dependency:

compile 'com.firebaseui:firebase-ui-storage:1.2.0'
compile 'com.firebaseui:firebase-ui-database:1.2.0'
compile 'com.github.bumptech.glide:glide:3.7.0'

Step4: Load images from the Firebase StorageReference using Glide instead of Picasso.

Glide.with(MainActivity.this)
    .using(new FirebaseImageLoader()) // <== ADD THIS
    .load(storageReference)
    .signature(new StringSignature(localFile.length() + "@" + localFile.lastModified()))
    .into(images.get(i));

Step 5: Add your images into your ArrayList.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193