Office Hours Transcript: 2021-08-07

Tad joined

hello, Tad!

 

how can I help you today?

Hey Mark!

 

I have two questions.

 

The first has to do with trying to figure out why my implementation using WindowsInsetsController for API 30 and greater isn’t working correctly.

 

I’m trying to show/hide the actionbar based on a tap on the screen.

 

Here is the code:

 
        Timber.d("Lifecycle: mShowPart2Runnable running");
        //if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
        //    getWindow().setDecorFitsSystemWindows(true);
        //    WindowInsetsController controller = getWindow().getInsetsController();
        //    if ( controller != null ) {
        //        controller.show(WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars());
        //    }
        //} else {
            // Delayed display of UI elements
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
            ActionBar actionBar = getSupportActionBar();
            if (actionBar != null) {
                actionBar.show();
            }
        //}
 

I have it commented out, because when it is uncommented, it doesn’t work.

 

I get the animation as if it is trying to show something, but it is just black.

 

Can I upload a pic here?

 

I have a screenshot

this service dose not support images, though if you uploaded it somewhere else you could link to it here

Suggestion where?

I have not used one of those services

I thought you gave me a link to one sometime back.

 

OK hang on, I’ll see if I can do it on my dropbox account

that might have been pastebin.com or something for text

 

I don’t see where in your commented-out code you are actually trying to show something – your ActionBar logic is purely in the else

 

bear in mind that I have not yet had a need for WindowInsetsController, so I’m limied to just guessing

 

er, limited

 

And here is what it looks like when the new API is used on a device running 30:

what are you expecting to appear there? it is not the ActionBar, as you are not showing it in the if block

The options menu

 

Do I specify that some different way for 30?

well… again, you do not appear to be showing your ActionBar for your if branch

I guess I am not sure how the windowInsetsController is supposed to show the action bar

 

there is not .Type for it

 

there is a Type.systemBars() but that didn’t work either

let’s flip this around: if you comment out actionBar.show() in your else block, do you get the same black bar effect?

Hang on

 

I have to fire up my AVD again

 

As an aside, do you think my builds would go faster if I could have some flavor that would try to build an .aab every time?

 

One line of code - 90 second build time.

 

that would NOT try to build an .aab every time

 

OK yes - same behavior with the action bar commented out

 

So you are thinking to ignore the WindowInsetsController entirely and just use the same code approach for the options menu?

if you do your actionBar.show() for both the if and the else – such as by having it below the end of the else – does your WindowInsetsController code now work?

I’ll try, one sec

 

Yep, that worked! So I guess the WindowsInsetsController is not for controlling the action bar, is that the take-away?

it handles spacing, but the action bar is independent of either technique that you are using

 

so, if you need to show() it for one, you need to show() it for both

ok

 

I’m going to tee up another pair of screenshots for my next question

 

OK - so I am implementing a drawing canvas in my app for people to draw shapes, enter text, etc.

 

I want to also allow them to drop in various images like emojis, stickies, etc.

 

My first attempt was to implement a custom EditText per various examples to allow images to be given to my EditText per the Android GBoard using the various examples out there.

 

I have this all working.

 

However, I don’t want the user to be able to type text and also choose an image/emoji/stickie.

 

I want them to EITHER type text, or choose an image.

 

So I need there to be some way to either turn the text input off on the standard keyboard and leave only the image types of buttons, or create a custom IME that only has those buttons.

 

The advantage of the former, is that the keyboard already does what I want vis a vis the images.

 

The problem as I see it with the latter, is that I don’t know how to connect the various emoji, bitmoji, smiley faces, etc. to a custom IME, or know where to go get that info.

more importantly, you cannot force the user to use the IME

Right

 

Here is a sub-30 aPI softw keyboard, where I’ve highlighted what buttons I want them to be using: https://www.dropbox.com/s/jaa050p92r4p741/Android_8_ImageEditText.jpg?dl=0

and implementing an IME has privacy/security ramifications, requires special actions in the Settings app, etc.

 

bear in mind that not everyone uses that keyboard

it is not even necessarily available on all devices

 

and even where it is available, it is not necessarily the default

 

the point behind an EditText is to get text – whether the user has the ability to do anything else is going to vary

Hmmmm…ok, is there a way I can figure out how to launch the chooser for those types of things, and build my own independent panel?

I don’t think that there is way to open the system keyboard picker, though I can’t completely rule it out

I agree with you on the EditText thing - it just seemed a convenient place to start since what I want them to be able to choose for images seems "built-in"

let’s flip it around: why are you concerned about both text and images at the same time?

And if a customer has loaded other keyboards, it would then automatically be shown to them.

 

I am not at all concerned about that at the same time.

that is not what you wrote earlier: "I want them to EITHER type text, or choose an image."

I wasn’t clear - I didn’t mean at the same time.

 

I would actually prefer that my drawing panel had a text widget just for text, and a separate widget to insert stickies, emojies, etc.

then perhaps you should not be using an EditText for the image options

Right - it was a starting point, because it seemed the various keyboards had it conveniently there.

 

And in the samples I’ve seen, when they choose an image, it doesn’t go into the EditText anyway - it goes into some other component (WebView, ImageView, etc.)

 

That’s what my little test app was doing

it’s more that from a UX standpoint, if a user chooses an "add an image" option, and you pop up an EditText, as as user, my reaction would be 🤔

The idea would be if they choose an image, an input field would show but I had hoped to then show a limited soft keyboard showing ONLY those image options

you don’t have that kind of power, sorry

So any ideas about how to essentially do the same picker that is underlying the GBoard that launches the stickies, emjoies, etc. choices?

I’m no expert in this space, but it feels like there are umpteen zillion "sticker packs" out there

And just tie it to a custom button, instead of a keyboard

I assume that there is some sort of specification for what those are like

 

so, I’d be looking into what other apps do that have user-supplied sticker packs

 

I’d create a stock sticker pack for the app using Creative Commons-licensed images

 

and give the user the ability to import/attach/whatever other sticker packs

 

from there, figure out how one uses the contents of a sticker pack, and offer a UI for browsing it (e.g., RecyclerView with GridLayoutManager)

Yeah, I get it.

really, the #1 advantage for you with GBoard is that the content is already kinda-sorta licensed

kinda-sorta?

I say "kinda-sorta" as I’m really uncertain what the ramifications are for users using those things and publicly distributing the results, at least for non-Google-created stuff that GBoard offers, like the GIFs

 

it’s the sort of thing that I’d want to talk about with an attorney with expertise in copyright law

 

of course, allowing user-supplied sticker packs has the same ramifications

 

so, you might start with your own sticker pack (with clearly legal content) and expand from there when you’re ready

Sounds like a plan.

 

Thanks!

but, all of this depends on the nature of your app – if the content is only ever consumed by the user on their device, my copyright concerns start to fall away

No - this is for adding to playlist content that they would then share with family.

 

So the concern is relevant

 

Similar to how a chat app works in this sense.

my primary consulting client has limited this sort of thing to just emojis, largely over this sort of licensing concern

Interesting - and that was on the basis of talking to a copyright attorney?

I assume legal counsel was involved, but this is a decent-sized company, so that’s a few layers up the org chart from where I usually help

OK - btw, did you see my other "Aside" question about trying to improve build speed?

yes, and I was starting to type a comment there, but then the main thread kinda took over

Do you think the fact that I have this set up as an .aab build is causing a slowdown?

I don’t know that there is a way to control that on a flavor basis, though I can’t rule it out

I couldn’t find a way through just Googling

how are you building/running the app that is causing it to create AABs in the first place? usually, I see that as something you expressly have to do, not as a side effect of just running the app from the IDE

But I’m not kidding - just uncommenting the lines for what we discussed earlier took almost 90 seconds to get through the build process.

 

I don’t know actually that it is doing that on just a standard compile/run

 

I was just theorizing

 

AFAIK, Run from the IDE just creates an APK, because in the end, that’s all the device/emulator needs

 

AABs are for distribution to a wide range of devices, with differing hardware and language configurations

I have a pretty decent laptop here - 32GB ram, quad 4, etc. etc.

 

I’ve noticed things getting incrementally slower with the later Android Studio releases, I’m on 4.2.2 at this point

 

Actually - 2020.3.1 now

when you do the build in Android Studio, where does the Build pane say the time is being taken up?

I’ll do a full one and let you know, then do a 1 line code change and do the same.

 

(full rebuild is 3-4 minutes)

 

ok this one actually went much faster.

 

I’m looking at the build analyzer now, what should I focus on?

 

Tasks impacting build duration?

possibly – I haven’t actually played with that yet, I was thinking more of the Build Output pane and the times shown there

 

but presumably that "tasks impacting build duration" thing is good

Yeah, compileDebugJavaWithJavac is 12%

 

On the one line of code (I just deleted an empty space), that same task took 54.%% of the time

 

Looks like the annotations processor for Realm is a hog also

 

Not much I can do about either of those I guess

the % implies that perhaps Gradle was able to skip some other tasks where it could tell that the inputs had not changed

 

Realm might be able to get more sophisticated with their annotation processor in time

 

I know that Google has been pressuring annotation processor developers to take steps to help with this sort of thing

OH yeah - it skipped a bunch of tasks the second time.

 

69 actionable tasks, 6 executed, 63 up to date

but, overall, Build Output and Build Analyzer should help you at least figure out who to blame, and perhaps they can do more for certain aspects of your build

Makes sense.

 

OK - gonna jump, thanks as always!

you’re welcome!