How can I detect tab focus changes in an android TabLayout? - java

I have a ViewPager set up with a TabLayout at the top. The app is running on a device with physical d-pad directional keys that can be used to move the control focus.
How can I detect when the focus is moved to specific tabs in the TabLayout?
I can see the Tab highlight when the focus is received, but I am unable to find any events that might allow me to detect this.
Also, TabSelected doesn't work, as it doesn't fire until the center key of the d-pad is pressed to "select" the focused tab.

You can add custom view to your tab, and then setOnFocusChangeListener for this view.

Related

How to make overlay receive touch events without consuming the touch for the other apps?

I'm currently trying to make a utility overlay similar to Facebook Messenger chatheads in which you can move the view around the screen. When you click the view, it expands into a more complex layout. However, the problem is if I set the LayoutParams' flag to WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, the apps behind receive the touch events while my overlay doesn't receive any touch events at all. But if I remove that flag, the overlay receives the touches but it blocks the touch. Meaning I can't even open the app drawer since the touches are being blocked.
I am using a fullscreen transparent Activity as background so I can move my overlay "widget" around it.
Is there any way I can make it so that it doesn't block touch events. Even if I don't set it to fullscreen, as long as I don't have the FLAG_NOT_TOUCHABLE flag, my overlay completely blocks all screen touches.
Please Remove this flag
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
with this flag
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
see this link https://medium.com/#kevalpatel2106/create-chat-heads-like-facebook-messenger-32f7f1a62064

(Accessibility) Change auto focus to other component when using TalkBack

With the TalkBack setting enabled, the accessibility focus shifts to the hamburger icon automatically. (makes sense since it's the upperleft component in the screen).
When a user opens my app with TalkBack enabled, I want the focus to automatically select the text in the toolbar. This way, the name of the screen is spoken out loud, instead of the drawer action.
I have added an example below:
Use this code below on your toolbar (title) object.
android:accessibilityTraversalBefore="#id/drawer"
That will solve your problem.
I managed to set the focus manually on another component by simply adding the the following field:
android:accessibilityTraversalBefore="#id/idOfTheComponentThatHasTheAutoFocus"
In this way, you make sure that this component will be called first in the traversal order.

Prevent Keyboard layout hiding toolbar but reveal scroll content

Best description for my issue was at
Keyboard layout hiding android action bar?
And I will paste-quote here:
"I have this problem also but the difference is, i have a list above my edittext and can't use a scrolling container. If I use adjustResize when the edittext is focused it appears above the list and the last items from the list get obscured (list is not pushed up). If I don't use adjustResize on the other hand, when the edittext is focused it pushes everything up but the acionbar is hidden and also I cannot scroll to the top of the list. Can someone share a solution for this? "
So
I have a toolbar
then a chat content
and then a bottom bar for sending a message (editText and a button)
Now, when I tap on an ediText, and soft keyb opens up, I do NOT want my toolbar to collapse and hide, but I do want my chat content to scroll up, so above the bottom entry I will see the last messages from chat content (in listView).
I've tried a number of combinations for Activity adjustResize or adjustPan, but none of them was working. Even wrapped toolbar in CoordinatorLayout and AppBarLayout, but still, no results. Either my content gets pushed/scrolled correctly but toolbar hides OR toolbar stays but softKeyboard overlaps last couple of messages.
The solution I share is a workaround. I had implemented a function scroll(), to scroll my content if a new message arrives, so that was one function I implemented before. I was missing the other part and that is, detect when a softKeyboard was open so I can scroll my content.
That was easy to find here on
How to check visibility of software keyboard in Android?
I hope someone will find this workaround useful and sleep at least a couple more hours.
Note:
Animation of sliding content up is not consistent with softKeyboard sliding up. After keyboard is opened, then I do scroll, which is not in-sync. It is just a snap. But I don't care about that until I find a better solution for orchestrating this event using a native Android component or layout.
The easiest and best solution to all of the above is to simply use the following:
listView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);

Codename One - autoscroll the screen

In a Codename One GUI builder app when I navigate back to my Main form, the screen is always shown at the top.
How can I get the screen to auto scroll down to the part I want and retain its previous scroll?
I'm assuming that this is a GUI builder app.
Normally this should be seamless as the UI will scroll to the last focused component but if you don't have focusable elements this might be harder. You can store the scroll Y value on the exitForm event and restore it the beforeShow event using something like:
f.addShowListener((e) -> f.scrollY(yValue));

Android: Convert a normal menu to slider menu? (With minimal coding)

I have an app with a normal menu i.e. the common old menu that shows up at the bottom of the screen when the menu button is pressed. But it is a problem in some phones where there is no hard menu button.
I want to switch to slider menu with a menu icon on top. Is there an easy way to do this (I mean a way where code change would be minimum) retaining the existing functionality? Or will i have to go about coding the slider menu from scratch?
Any example code of a similar situation would really help.
I have an app with a normal menu i.e. the common old menu that shows up at the bottom of the screen when the menu button is pressed
Normally, that "menu" will appear as the overflow on devices with an action bar that either:
do not have a MENU button, or
run Android 4.4+
But it is a problem in some phones where there is no hard menu button.
Make sure that your app has an action bar.
I want to switch to slider menu with a menu icon on top
The options menu/action-bar-with-overflow is unrelated to the "slider menu". They serve different roles. Please read the design guidelines for a navigation drawer (a.k.a., "slider menu").
Is there an easy way to do this (I mean a way where code change would be minimum) retaining the existing functionality?
No, because they are not related.

Categories