0

I'm working on a standalone Wear app. Everything works but the image loading is too slow.

The way I'm doing it is using Firebase Storage as a back-end. I'm getting the URL and using Glide loading it into an ImageView.

I also try using Picasso with the same result.

I tried to use the DaVinci library but its too old (3 years old). I followed this link: How to load URL image in android wear?

The code that I used is quite simple:

Picasso.get().load(imageUrl).into(iv);

and the Glide version:

Glide.with(iv.getContext()).load(imageUrl).into(iv);

The versions I'm using:

  • Gradle: 3.0.1
  • Google-services: 3.2.0/ 11.8.0 for the dependencies
  • Glide: 4.3.1
  • Picasso: 2.71828

This is the way I'm uploading the image to Firebase-Storage:

String filePath = photoFile.getAbsolutePath();
Bitmap bitmap = BitmapFactory.decodeFile(filePath, options);
mFormActivity.getContentResolver().notifyChange(photoURI, null);
int rotateImage = getCameraPhotoOrientation(filePath);

Matrix matrix = new Matrix();
matrix.postRotate(rotateImage);
Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);

FileOutputStream fos = null;
try {
    fos = new FileOutputStream(photoFile);
    rotatedBitmap.compress(Bitmap.CompressFormat.PNG, 25, fos);
    fos.close();
} catch (IOException e) {
    Log.d(TAG, "fixLandscapeOrientationCamera.error = " + e.toString());
    if (fos != null) {
        try {
            fos.close();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}
Zoe
  • 27,060
  • 21
  • 118
  • 148
  • How big is your image in terms of resolution and also in terms of size in MB / KB it will obviously matter for android wearable devices. – Akshay Katariya Mar 27 '18 at 11:14
  • Hi! The images are 80-90Kb....they are profile images. I m using a Camera Intent – Carlos Cabello Ruiz Mar 27 '18 at 11:16
  • Camera intent for ?? – Akshay Katariya Mar 27 '18 at 11:17
  • No no...sorry!! You re right...The ones takes by the camera are 4Mb!!! I m gonna change that straight away but the mock users has images of 80-90Mb and its still really slow – Carlos Cabello Ruiz Mar 27 '18 at 11:17
  • You need to implement some optimization and compression techniques https://developer.android.com/topic/performance/graphics/load-bitmap.html – Akshay Katariya Mar 27 '18 at 11:23
  • Akshay Katariya..I updated the question adding the way I m compressing the image...I ve just change this `rotatedBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);` to `rotatedBitmap.compress(Bitmap.CompressFormat.PNG, 25, fos);` but the image now instead of being 4Mb is 10MB!!! – Carlos Cabello Ruiz Mar 27 '18 at 11:29
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/167633/discussion-between-akshay-katariya-and-carlos-cabello-ruiz). – Akshay Katariya Mar 27 '18 at 11:33
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Mar 27 '18 at 21:15

1 Answers1

0

I found the issue. Thanks Akshay Katariya for your time!!

I feel ashamed because it was a stupid mistake by my side. I was creating a bitmap and setting it into the ImageView before downloading the image. Anyway now its working perfectly so this is my code fully working for anyone that could try to achieve it.

I m using Picasso and Firebase Storage in a Standalone Wear App:

StorageReference imageReference = App.getStorage().getReference().child("images/" + mUser.getPicture());
imageReference.getDownloadUrl()
        .addOnSuccessListener(uri -> {
            Log.d("Testing", "loadSuggestionFace: setting the image");
            Picasso.get().load(uri.toString()).into(mFace1ProfilePicture);
        })
        .addOnFailureListener(exception -> Log.d(TAG, "getDownloadUrl.addOnFailureListener: error = " + exception.toString()));

App its the class extending Application where I'm initializing Firebase

mUser.getPicture() contains the filename(carlos.png for example)

mFace1ProfilePicture its the ImageView