When there are multiple Fragments on the screen, how do I tell when the user interacts in ANY way with a specific one of the Fragments? Perhaps they tap a button, scroll a list, tab through fields, anything.
I had thought perhaps I would get an onClick/onTouch/onFocusChanged listener on the Fragment/FrameLayout containing the Fragment/root Layout of the Fragment UI, but they don't fire.
I'll try setting a variety of manual triggers, like "if the user clicks this button or scrolls this view or this field gains focus, then the user has interacted with this Fragment" but obviously that's more complex and highly prone to inaccurate behavior.
Not sure why I need this? Here's the use case:
Think of Gmail on a tablet: in landscape, the inbox is shown on the left and the first message on the right. If I tap a different message, it is displayed on the right. If I rotate to portrait, it will show the message I had last selected.
If I start in portrait, it will show the inbox.
Now here's the real trick: let's say I start in landscape, showing inbox on the left, the first message on the right. If I immediately rotate the device to portrait. But if I interact with the pane on the right (say, scrolling the email message) and then rotate the device, it will show that first message. Gmail guesses whether I was more interested in the inbox or the email and shows that.
My challenge is doing something similar in an app. When I'm rotating from landscape (showing two panes) to portrait (showing one pane) I'm not sure whether to show the list view or the default detail view. If I could tell if the user interacted with the detail view in some way (via keyboard or touchscreen) then I know to show that.
In the end, I could not find any good, clean way to work this.
Instead, for every individual way the user could interact with the Fragment--touching a ListView, clicking a Button and so on--I would fire off a message to the Activity (using a Listener interface the Activity implements, of course).
Then the Activity tracks whether or not the user has interacted with the default Fragment, making sure to save and restore that value.
It's messy, but it's all I could come up with. :/
Related
I have a activity themed like a dialog and I have it setup so that it finishes when the user click outside.
this.setFinishOnTouchOutside(true);
As expected when the user clicks outside, it finishes. The activity is marked as floating activity and is only shown on top of the phone.
Now, if the user click on any other part of screen like the phone button/contact button on home screen, then the activity gets finished, but the user has to click on phone/contact app icon again to open phone/conatct app.
What I want is that if user click outside my activity, then the action must be performed as if the activity is not at all present on screen. Something like notification, which does not prevent user from doing other other tasks.
The only way you might be able to do this is by using a hidden WindowManager.LayoutParams flag, FLAG_SLIPPERY.
This allows touches starting on your View to continue to whatever View is below when the touch leaves your View but remains on the screen. However, I don't think this will work.
Android prevents you from touching "through" a touchable Window because it assumes that Window should be receiving the TouchEvent. Android also prevents you from programmatically "touching" the screen (without root or system access), most likely for security reasons.
I dug through AOSP for a while and found this.
Reading the comments, it's possible to infer that, while what you see doesn't take up the whole screen, the Activity's Window does. So, while nothing in your Activity is clicked, the Window is still overlaying everything, just with a transparent background, and is dealing with the touches that aren't passed to your Activity's UI. This brings us back to the "touching through" issue.
The biggest problem of StackNavigator is that components won't be unmounted, i.e., componentWillUnmount() won't be invoked.
But I need this component stage to unbind event, or to do other things. And that's why I started using DrawerNavigator.
But this brings another issue which StackNavigator would solve automatically.
I have a component which loads data from the server. In this component, I just show the summery, and whenever a user clicks on that, another component appears to show details. That means there are two components (screen). So, a user navigates to detail screen, (AppNavigator.router.getStateForAction(NavigationActions.navigate({routeName: action.route}), currentState);) and then he/she pressed (hardware) back button, as I override the default behavior of this event (close the app), he/she will navigate to list screen. Now, the problem is, say he/she was in 15th data, now when he/she navigated from detail screen, the scrollbar is in first data! Had I used StackNavigator, the scrollbar would have been in 15th data.
I implemented this using ScrollView, and FlatList. Used onMomentumScrollEnd props to get more data from the server.
So, how can I solve this, the scrollbar should be placed where it was last time, and at the same time get the feature of componetWillUnmount?
I have an app that works in the following way:
Upper part of the screen is the 'primary' part of the app, the actual content that the user can interact with is displayed here.
Lower part of the screen (maybe 1/4 of the screen height or so) is a navigation wheel. The user can turn this wheel to change the upper part of the display. When turned the entire upper part is replaced by something else.
These two part are implemented using fragments. The lower part (navigation wheel) is just a static fragment that displays a view hierarchy that can be rotated. The upper part (content display area) is a fragment as well, but it can be switched to other fragments when the wheel is turned.
Now what I want is that when the app starts, we are displaying a free content section, however when the user turns the wheel to one of the other content sections a window pops up to block the content display area, saying "buy this mode on Google Play." This popup should obviously block the content area behind it, so the user can see some of the display area behind the popup, but he/she cannot interact with it before he/she has completed the Google Play transaction. It would be nice if the views of the content area could be greyed out as well. The navigation wheel in the bottom of the screen however should not be blocked so that the user is able to navigate back to where he/she came from or further on to another content section. How can I make a popup that blocks the top view hierarchy from interaction but leaves the lower one intact?
As far as I know it is not possible to use the PopupWindow class to create a popup that will only block some of the screen behind it. It seems to always block it all.
Here is an of illustration the design. 'P' for paid and 'F' for free. On the second screen the app should ignore any press on the content section (behind the grey window), but the navigation wheel should still be able to turn.
Thank you.
On the second screen the app should ignore any press on the content
section (behind the grey window), but the navigation wheel should
still be able to turn.
You could make an overlay and set it up to eat all touch events(either by setting a OnTouchListener on it or by using a custom layout with the onTouch() method overriden to return true) and put it on top of your normal fragment content. This way the actual content will be visible underneath but will not receive any touch events. You could also add some content to your overlay right like in your image.
Also, as the overlay will only cover the paid fragment the wheel at the bottom will be touchable by the user(I don't know how that wheel actually interacts with your fragments so the approach above might not work).
I've made a small rudimentary sample as an example(you can find it here).
It would be nice if the views of the content area could be greyed out
as well.
You could make a recursive method to traverse the view hierarchy of your paid fragment and call View.setEnabled(false) on the views it meets.
Seems overly complicated to me.. I cannot imagine the design..
I would create a different fragment to be triggered if the user has purchased the item, with a different interaction, like a Dialog to be shown at every click, or something like that.
In pseudocode:
if wheel.position == 4
if itemPurchased
showFullFragment
else
showMockFragment
Create a default fragment with one button, that opens the right page of Google Play to buy the content. Then, every time the navigation wheel is turned, you decide in your code if you show the fragment with content (when user has finished the Google Play transaction) or you show the default fragment with just the button to Google Play.
Only one thing: Google Play is asynchronous. There might be some time when the user actually has finished the transaction but Google Play didn't inform your App, yet.
If the transaction was initiated you must decide if you show the content without having to 100% clarity that the user actually paid, or if you show a blank fragment. In any way, you should not show the button again, because that would confuse the user ("I paid! Why do I need to go to Google Play again???")
I'm implementing a not-so-standard navigational menu that is accessible from every screen in my app. That is to say, from every screen in my app, I can pop up a menu that will let me choose an entirely different area of the app to navigate directly to.
I have several screens that I call edit screens. They are screens where the user had chosen an item from a list of items and are able to then edit the data for that item. I do not wish for these screens to remain on the Activity stack if the user then uses the menu to navigate to some other area of the app.
This is easy enough. I can simply call "finish()" before navigating away. However, there are a couple places where it is possible to access a nested edit screen. Meaning the edit screen the user is currently on is a child of a parent edit screen. I want both off the Activity stack.
Can anyone think of a slick way to do this? The only way I can think of is to always use startActivityForResult and pass back some identifier that tells the screen to kill itself the next time it resumes.
The current Android YouTube application provides helpful hints for navigating the user interface. For example: the first time the user switches between tabs while a video is playing, a small "tooltip" with an arrow pops up and says "You can also switch between tabs by swiping left and right." or something to that effect. Is there a way to mimic the look and functionality of this tooltip?
The best way I could think of doing that is having something in a preferences file and when the user triggers a certain event (pressing a tab in Youtube rather than swiping) it brings up a custom view or even a Toast message. Then, after the tooltip is triggered, set the specific tag in the preferences file as triggered.