Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't open on Android studio ? #342

Closed
AndroidDeveloperLB opened this issue Sep 14, 2016 · 45 comments
Closed

Can't open on Android studio ? #342

AndroidDeveloperLB opened this issue Sep 14, 2016 · 45 comments

Comments

@AndroidDeveloperLB
Copy link

This is what I get:

maxthonsnap20160914092936

@koral--
Copy link
Owner

koral-- commented Sep 14, 2016

It seems that something is wrong with your gradle.
Try to follow hints listed at the bottom. If it doesn't help try to invoke gradle projects task with stacktrace option from right panel or from terminal, not sure how to do it exactly on Windows, it should be something like: gradlew.bat projects --stacktraceand paste output.

@AndroidDeveloperLB
Copy link
Author

I've now tested the project at home.
It builds fine, but there is nothing to run. Isn't there a sample there?

@koral--
Copy link
Owner

koral-- commented Sep 18, 2016

Here is a sample application project: https://github.com/koral--/android-gif-drawable-sample

@koral-- koral-- closed this as completed Sep 18, 2016
@AndroidDeveloperLB
Copy link
Author

@koral-- OK, thank you. I think you should merge the 2 projects. Usually library comes with a sample to try...
Also, sample cannot be imported well. It shows an error:

Gradle 'android-gif-drawable-sample' project refresh failed
Error:Configuration with name 'default' not found.

@koral--
Copy link
Owner

koral-- commented Sep 18, 2016

There is a link to sample project in readme: https://github.com/koral--/android-gif-drawable#usage and nobody has reported such issue so far but I'll consider merging repos.

Configuration with name 'default' not found may occur because you have not cloned submodule and library directory inside sample project is empty. You can update sumbodule eg. from commadline:

git submodule init
git sumbodule update

@AndroidDeveloperLB
Copy link
Author

I don't understand. Why can't it just use the library via gradle, and just work ? Why do I have to clone another project?
What exactly do I have to do?

@koral--
Copy link
Owner

koral-- commented Sep 19, 2016

Library is a git submodule of sample project. You can clone them all in one shot using git clone --recursive https://github.com/koral--/android-gif-drawable-sample.git.

@koral--
Copy link
Owner

koral-- commented Sep 19, 2016

Alternatively if just want to play with sample, you can switch dependencies in https://github.com/koral--/android-gif-drawable-sample/blob/master/sample/build.gradle#L51, comment out line 51. and uncomment 52. Library from maven repository will be used instead of local submodule.

@koral-- koral-- reopened this Sep 19, 2016
@koral--
Copy link
Owner

koral-- commented Sep 19, 2016

Reopened until merged project is ready.

koral-- added a commit that referenced this issue Sep 20, 2016
@koral--
Copy link
Owner

koral-- commented Sep 20, 2016

OK, sample is now in the same repo as library, available in dev branch https://github.com/koral--/android-gif-drawable/tree/dev

@koral-- koral-- closed this as completed Sep 20, 2016
@AndroidDeveloperLB
Copy link
Author

@koral-- How do I clone a branch? Cloning using the "clone or download" button uses the normal one...

@koral--
Copy link
Owner

koral-- commented Sep 20, 2016

Clone fetches all branches, you need to checkout dev branch, either from terminal git checkout dev or from Android Studio UI at the lower right corner.
image

@AndroidDeveloperLB
Copy link
Author

When cloning using tortoisegit tool, I entered "dev" as the branch (because that's the recent I've found).
Now it works fine.
Say, are there any restrictions of using the library ? Any hardware issues ? Memory usage?

@koral--
Copy link
Owner

koral-- commented Sep 22, 2016

The only common restriction is minimum API level 9. Some features require API 14 and hardware accelerated canvas or OpenGL ES 2. There is no known hardware issues. Memory usage is proportional to the GIF canvas size but not to the number of frames. Frames are not buffered in general.

@AndroidDeveloperLB
Copy link
Author

So the only memory in Heap that it uses, is of the current frame-bitmap to show?

@koral--
Copy link
Owner

koral-- commented Sep 23, 2016

Apart from metadata (like frame durations, global color table etc.) there are 3 main buffers stored on heap:

  • bitmap to show - contains current entire canvas (it may be equal to current frame in some cases)
  • raster (color indexes) of current frame, size depends on dimensions of the largest frame
  • second bitmap allocated only if GIF uses dispose to previous disposal method

@AndroidDeveloperLB
Copy link
Author

So... can you give an example of how much memory it will use on heap?
I don't get the 2+3 points. Doesn't it just load next image in JNI, dispose of current Bitmap object, and create a new one from JNI to be shown ?

@koral--
Copy link
Owner

koral-- commented Sep 23, 2016

Assume the following GIF:

  • canvas - 100x100px
  • largest frame 20x20px
  • dispose to previous is not used

So you get 100 * 100 * 4 bytes from p. 1. and 20*20 bytes from p 2. and 0 bytes from p. 3.

Those buffers are only disposed at the end of lifetime. During animation they are reused for subsequent frames.

@AndroidDeveloperLB
Copy link
Author

AndroidDeveloperLB commented Sep 24, 2016

shouldn't it be just the canvas size ? meaning 100_100_4 ? I mean, the Bitmap object that Java needs is in this size alone... what would it do with the others?
It could even be as the largest frame size, as you could move it inside the canvas.

or maybe by canvas you mean the one of the view?

@koral--
Copy link
Owner

koral-- commented Sep 25, 2016

ad 1. I mean GIF canvas, in most cases its size is equal to size in logical screen descriptor in the GIF header. It is the entire space which can be used for drawing. It is backed by Bitmap, OpenGL texture etc. It cannot be reduced to size of the largest frame because previous contents of the drawing surface is not preserved between subsequent frames. That means you need to draw entire GIF canvas in Drawable#draw(), Renderer#onDrawFarme() etc. you cannot draw only the difference between frames.

ad 2. Raster works as lookup table. It stores color indexes from color table for each pixel of the frame. It cannot be located at the same place as pixels (RGBA values) because both data are needed at the same time.

ad 3. it is theoretically possible to get rid of this buffer by decoding again relevant part of previous frame however in some cases it will require decoding all the frames from the beginning so it may consume a lot of time.

@AndroidDeveloperLB
Copy link
Author

AndroidDeveloperLB commented Sep 25, 2016

I see.
Do you have a function in the library that will return the max number of bytes the loaded gif file will take at any specific time ?
Something like getAllocationByteCount of Bitmap:
https://developer.android.com/reference/android/graphics/Bitmap.html#getAllocationByteCount()
This can help in case of low heap memory scenarios.

@koral--
Copy link
Owner

koral-- commented Sep 25, 2016

There is method with that name (based on Bitmap): http://static.javadoc.io/pl.droidsonroids.gif/android-gif-drawable/1.2.2/pl/droidsonroids/gif/GifDrawable.html#getAllocationByteCount--
but it counts only memory allocated for pixels (point 1. and 3. if any) but not for metadata (number of frames, frame durations, canvas size etc.) .
It seems to be possible to add new method like getMaxAllocationByteCount() which counts maximum possible space, including p. 3. even if that buffer is not currently allocated because frame using that method wasn't encountered yet.

Even if input source is mutable (eg. file) and is modified during animation it won't change possible maximum because metadata (including disposal methods) is only read at loading time. Just added issue to track that featue: https://github.com/koral--/android-gif-drawable/issues/348

BTW when checking this I noticed a mismatch in linked javadoc, I'll fix it as well.

@AndroidDeveloperLB
Copy link
Author

I don't understand. Can you please consider adding this function to check how much (heap) memory would a gif file take ?

@koral--
Copy link
Owner

koral-- commented Sep 25, 2016

Yes, I said that I'll try to add that function. Progress can be tracked in issue #348.

@AndroidDeveloperLB
Copy link
Author

OK. Say, does WebP also support animation?
If so, how's the support for this on Android? Can this library also handle
it? Maybe even support older Android versions?

On Sun, Sep 25, 2016 at 10:59 PM, Karol Wrótniak [email protected]
wrote:

Yes, I said that I'll try to add that function. Progress can be tracked in
issue #348 https://github.com/koral--/android-gif-drawable/issues/348.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/koral--/android-gif-drawable/issues/342#issuecomment-249442979,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFG_1nwZMwl548yY-eZHyzkL6nYEo3Zlks5qttKQgaJpZM4J8cPF
.

@koral--
Copy link
Owner

koral-- commented Sep 25, 2016

Yes, WebP can be animated.
It should work in WebView.
This library currently does not support WebP but it is on roadmap.
Older Android versions was supported in the past:

  • 1.1.17 is the last version supporting API 8 (Froyo)
  • 1.0.12 is the last version supporting API 4 (Donut)

There is no plan to lower minimum API level.

@AndroidDeveloperLB
Copy link
Author

"Older Android versions was supported in the past"
I'm talking about WebP ...

On Mon, Sep 26, 2016 at 1:10 AM, Karol Wrótniak [email protected]
wrote:

Yes, WebP can be animated.
It should work in WebView.
This library currently does not support WebP but it is on roadmap.
Older Android versions was supported in the past:

  • 1.1.17 is the last version supporting API 8 (Froyo)
  • 1.0.12 is the last version supporting API 4 (Donut)

There is no plan to lower minimum API level.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/koral--/android-gif-drawable/issues/342#issuecomment-249449904,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFG_1uOZI8JWOd1Ds2oXJ9Bo7WcA6xu4ks5qtvFVgaJpZM4J8cPF
.

@koral--
Copy link
Owner

koral-- commented Sep 25, 2016

I don't understand. Are you asking starting from which version Android supports WebP natively?

@AndroidDeveloperLB
Copy link
Author

Webp animation . Not just image. The docs don't talk about it. Also I
couldn't find how to create them

On Sep 26, 2016 02:21, "Karol Wrótniak" [email protected] wrote:

I don't understand. Are you asking starting from which version Android
supports WebP natively?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/koral--/android-gif-drawable/issues/342#issuecomment-249453184,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFG_1toHq4Oot3QzHnTdotUx3OYt7fcxks5qtwHtgaJpZM4J8cPF
.

@koral--
Copy link
Owner

koral-- commented Sep 26, 2016

Creation should be possible using gif2webp, webpmux and libwebp api

@AndroidDeveloperLB
Copy link
Author

Nice.
But still, from which API does Android support animated WebP ? It only says about transparency...
BTW, speeaking of tools for WebP, I've created this tool, to help developers switch to WebP instead of PNG and JPEG:
https://github.com/AndroidDeveloperLB/WebpifyYourAndroidApp

@koral--
Copy link
Owner

koral-- commented Sep 26, 2016

I don't know either from which API does Android support animated WebP. Indeed there is no such information in docs.
The easy way to know that is just to check it on emulators with various API levels.

Interesting tool. I also see your tickets on android issue tracker. I'm curious if Google adds WebP converter or support for WebP 9-patches.

@AndroidDeveloperLB
Copy link
Author

The 9-patches WebP isn't supported on any API, as far as I know.
How did you find about the issue I've written about it (here: https://code.google.com/p/android/issues/detail?id=201704 ) ?

@koral--
Copy link
Owner

koral-- commented Sep 26, 2016

I've recently searched for WebP related issues and remembered your email.

@AndroidDeveloperLB
Copy link
Author

But I never wrote my email here. Anyway, thank you for all the help.

@koral--
Copy link
Owner

koral-- commented Sep 26, 2016

In README of WebpifyYourAndroidApp there is a link to issue tracker with the same reporter email.

@AndroidDeveloperLB
Copy link
Author

Oh... Right you are

On Sep 27, 2016 02:07, "Karol Wrótniak" [email protected] wrote:

In README of WebpifyYourAndroidApp there is a link to issue tracker with
the same reporter email.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/koral--/android-gif-drawable/issues/342#issuecomment-249723384,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFG_1lEWX3Ry5ACxC1I1pYE8_OgGWem3ks5quFASgaJpZM4J8cPF
.

@koral--
Copy link
Owner

koral-- commented Oct 9, 2016

@AndroidDeveloperLB
Copy link
Author

Nice. Thank you.
So it will return the max memory the gif will take, before actually loading&showing it, right?
So that whoever is about to load the gif, will know if the app has enough memory to load&show it.

@koral--
Copy link
Owner

koral-- commented Oct 12, 2016

Currently it only works for already created GifDrawables but I'll add it also for GifAnimationMetadata so it may be checked as you said - before loading.

@AndroidDeveloperLB
Copy link
Author

Nice!

@koral--
Copy link
Owner

koral-- commented Nov 2, 2016

Just added GifAnimationMetadata#getDrawableAllocationByteCount(Bitmap, int).
In this case optional reusable Bitmap and sample size can be passed.
So to know allocation byte count prior to decoding whole GIF you can use code like that:

GifAnimationMetaData metaData = new GifAnimationMetaData(...);
long expectedDrawableByteCount = metaData.getMetadataAllocationByteCount() + metaData.getDrawableAllocationByteCount(null, 1);

@AndroidDeveloperLB
Copy link
Author

What's the bitmap parameter? It already belongs to a gif file...
Is the sample size for handling various densities, or it's already done automatically?

@koral--
Copy link
Owner

koral-- commented Nov 2, 2016

There should be GifDrawable not Bitmap (already corrected).
This parameter is related to GifDrawableBuilder#with(). You can reuse old instance of GifDrawable to avoid allocating new Bitmap. That old instance may use larger bitmap than new one. This is equivalent of BitmapFactory.Options#inBitmap. If you are not reusing anything you can pass null.

Sample size is related to GifOptions#setInSampleSize. This is equivalent of BitmapFactory.Options#inSampleSize.
Sample size is for handling GIF with large canvases (significantly larger than needed in UI), by default it is equal to 1 (no subsampling). Eg. if GIF has canvas 4096x4096 px but you need to display only small thumbnail you can set sample size to value larger than 1 to avoid allocation of 64MB bitmap.

@AndroidDeveloperLB
Copy link
Author

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants