0

This topic is a following of my last one: How to mirror a fragment to a presentation in Android?

I managed to duplicate my fragment on the external display by using the library "Presentation" from CommonsWare Android Components (CWAC).

However, it resizes the initial fragment to optimize the user experience of the presentation (it is better displayed on the external screen than the device) but in my case, I would like the opposite.

Therefor, I searched in the library where it resizes the original fragment, and it appears it's in the class AspectLockedFrameLayout.java and more precisely, in the method void onMeasure(int widthSpec, int heightSpec).

I tried to not modify lockedWidth and lockedHeight (by putting them in commentary) and it seems to work: the initial fragment is not resized and the displaying suits me.

However, the app crashes when I connect the external display before having launched the app and it's a bit annoying.

After a lot of tests, I found that in the class MirroringFrameLayout.java and in the method public void draw(Canvas canvas), the variable bmp is null and then, crash.

Do you know where is the problem and how to solve it?

Thanks a lot,

Best regards.

Community
  • 1
  • 1
azn0viet
  • 140
  • 1
  • 1
  • 9

1 Answers1

0

I cannot readily debug code that I cannot see.

A quick glance at the current MirroringFrameLayout indicates that your problem is coming because draw() is being triggered without a Bitmap having been created in initBitmap(). That could be because there is no mirror, or because draw() is getting called before any of the following methods are called:

  • onSizeChanged()
  • onPreDraw()
  • onScrollChanged()

If you are able to reproduce this problem in umodified versions of the library, file an issue with a project that demonstrates the issue (or other instructions for reproducing it), and I can try to address it.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks for your answer, I really appreciate your help. Sorry for this delay, I spent some time to learn how to publish a project and it's now ok : https://github.com/azn0viet/presentation The only thing I modified is what I said above. Should I create an issue and just put the link of the project? Thanks ! – azn0viet Feb 09 '15 at 17:16
  • @azn0viet: "Should I create an issue and just put the link of the project?" -- no. To repeat the last paragraph of my answer, just with more boldface: if you are able to reproduce this problem in **umodified versions of the library**, file an issue with a project that demonstrates the issue (or other instructions for reproducing it), and I can try to address it. – CommonsWare Feb 09 '15 at 17:22
  • Hello and thanks for your answer. I really don't understand what is needed, I'm sorry for wasting your time. So if I understand well, you need an unmodified version of your library. I use these sources : https://github.com/commonsguy/cwac-presentation with the Activity "MirrorPresentationActivity.java". It works very well, no problem with your version. But when I modify the class above, I get the crash as I describe it before. Is it that, that you need? – azn0viet Feb 10 '15 at 13:20
  • @azn0viet: Then the problem lies in your modifications. I gave you some suggestions as to the source of your problem in my answer. If I had to guess, something about your changes is either triggering an early `draw()` call or is delaying/eliminating the other calls that should happen before it. In particular, `onPreDraw()` really should be called before `draw()`, unless some `draw()` call is happening before `onAttachedToWindow()` and its registration of the `OnPreDrawListener`. You will need to put in the breakpoints and figure out what calls are being made when and why. – CommonsWare Feb 10 '15 at 13:29
  • Hello and thanks for your advices. I will search around them ! Have a nice weekend. – azn0viet Feb 13 '15 at 12:38