Keep d-pad focus changes within current fragment - java

I have an android app that primary receives input using a d-pad (up, down, left, right, OK, back)
The app runs on a TV so uses fragments to separate sections.
I would like to keep directional buttons from focusing views in other fragments. And handle directional buttons differently depending on what fragment is set as the "current"
What would be the most elegant solution to this?
also, Fragments are dynamically changed at runtime.

When the d-pad is the only means of navigation for a user, such as on some Google TV's, then it's not a good idea to stop the navigation at the edge of a fragment. How I solved this, is by allowing cross-border navigation and laying out elements so that the navigation is not awkward and works by finding the path automatically (after all, there does not seem to be a way to statically provide the next element to focus on in each direction, when in another fragment).
Like you I'm looking for reference advice on how to deal with fragments and navigation on Google TV.

Related

Fragment that covers bottom navigation and loads smoothly

My app uses a Bottom Navigation, which is tied to a NavController. I want to load a fragment that creates a new item in my app, so I want the fragment to take up the part of the screen used by the bottom navigation. I am trying to make my app consistent with Google's, so I am using a fast entry animation from the bottom.
However, by default, the NavController loads in the NavHostFragment which is above the BottomNavigationView, so the Bottom Navigation is shown with any fragment. I tried using the Google's suggested method to Listen for navigation events. However this sets the BottomNavigationView to gine before the fragment navigation takes places, shifting the current fragment downward, giving a stutter effect on navigation.
What makes things worse is that it seems with just about any complexity of the target fragment, it takes a moment to inflate the layout of the new fragment, so the BottomNavigationView disappears, the app pauses for a moment while inflating, and then it is too late for the animation and the fragment stutters into existence.
What is the right approach for this?
Try setting the exit transition of the every those Fragments from which another fragment(which creates new item) is loaded like this:
setExitTransition(new Hold());
Basically, this holds the current fragment until next one is loaded.
Note: If you do not find Hold class in your current implementation, you might need to use the alpha version of MaterialComponents.
implementation 'com.google.android.material:material:1.3.0-alpha01'

I don't understand how to organise my fragments

I have realised an NFC reader application
So i have 3 activities :
MainActivity, which is an activity who contains a Button. If button is clicked, the scan is activated and the user can put his NFC tag against the device to detect it.
WebActivity, who is launched if the NFC tag contains and URL (and open a WebView) or if the user want to launch WebActivity by himself
HistoryActivity, who gonna contains a list of every scans.
Now, I would like to swipe activity with a finger gesture. according to my research on Internet. I need fragments and ViewPager.
But every example that I saw is bases on ONE activity and multiple fragments.
But in my case, I have to create 3 fragments (one per activity), right ?
And I really don't know how to manage my fragment. I mean, what to put inside ?
All I want to do is create a transition/animation while changing activity... That's crazy
This is too broad of a question but hopefully my answer will steer you in right direction.
You should definitely go with single activity/multiple fragments model. Aside of recommendations by Google, you could use navigation components, deep linking much easier then without single activity.
Yes you should be using ViewPager for the purpose (and likely your implementation of FragmentPagerAdapter as well) however I do not understand what kind of swiping will you be doing
Reading your setup, I would suggest to use bottom view with 2 items (good example is here https://github.com/android/architecture-components-samples/tree/master/NavigationAdvancedSample/app/src/main/java/com/example/android/navigationadvancedsample). 2nd one would show history, first one would offer a button that activates your action, and then displays fragment with your WebView.
As a side effect of such implementation, you'd be able to go back from 2nd bottom view item to whatever first one holds - by pressing system back button - which I think is nice touch.
UPDATE to "swiping takes place anytime. " comment:
You could have single activity, ViewPager with 2 fragments. First fragment would display a button, 2nd fragment would display a history. You could freely swipe between them, as you want to. However to me it does not make sense to put WebView screen into this. WebView screen is result of action (NFC detection) and it should probably display as full screen, without any chance of swiping between main/history and itself. Hope it helps or I'm missing some important piece of info you did not share.

How to make side menu using browse fragment like netflix in android tv?

Attached screenshot of netflix app with left side menu I am able to develop a side menu with customized icon and header in it. I want, when the focus comes on header fragment it should expand on top of row fragment, that is not collapsing the row fragment, the same as Netflix and hotstar are doing. How can I achieve it?
unfortunately, the HeaderSupportFragment used in the BrowseSupportFragment is not configurable enough to achieve this kind of design. Leanback is great to build quickly and easily media browser app but when it comes to "complex" design, it's easier to use custom component.
The major difference also here, is that the left menu of the BrowseSupportFragment show each rows header name displayed in the screen (that's why it's called HeaderSupportFragment). Here you want to show different entries like search, home, settings, etc.
To make this kind of view, I would suggest creating your own custom view and use a basic Fragment. I followed this tutorial which can be useful to handle menu open/close animation (I mixed it with a ConstraintLayout to simplify the animation and I made the menu overlap the rest of the screen instead of moving everything.)
See the tutorial: https://medium.com/building-for-android-tv/building-for-android-tv-episode-3-381e041dfec7

How should I structure bottom navigation in Android coming from iOS background?

Some background:
Coming from an iOS background, using UITabbarController is very common and straight forward. Each Tab in the tab controller will change the current view to another UIViewController, and each of these UIViewControllers can have its own NavigationController (which kind of acts as a back stack). So whenever I switch tab, I would resume to the state where I left off.
Now I want to implement the same thing in Android, but it seems like the use of ViewController is different in Android. After digging around, I read that instead of using Activity like UIViewController, I should use Activity to act more like NavigationController, and use Fragments (which is deprecated)
to act as UIViewController instead.
However my question is:
Should I be implementing multiple Activities for Bottom Navigation? When I click on each item in the Bottom Navigation should I use an Intent to change Activity? Because from my understanding, using Intent to change Activity will add the new Activity to an Activity back stack, which would prevent me from switching back to whichever Activity I want. If someone could, Please tell me what is the "right" way (if there is one) to structure Bottom Navigation. Thank you all in advance.
You can use fragments as UIs, And Use a BottomNavigationView in your activity or you can use some libraries.
Here is a library for better customization: https://github.com/ittianyu/BottomNavigationViewEx
Native Method:
https://medium.com/#hitherejoe/exploring-the-android-design-support-library-bottom-navigation-drawer-548de699e8e0
In Android you should use Viewpager, tablayout and Fragments. Just search for its tutorials. there are lots of them on internet

Designing two column Android application - switching views?

I am building a two column application for Android and I'm wondering how to do the navigation. The left column is the navigation bar. The right one is the content view. Both of them are LinearLayouts.
I have a different activity for all the options. How do I implement my menu into these? It is the same for all the activities (except the current one is highlighted), so copying the same code multiple times seems waste and makes it harder to change it later because I would have to change all the files.
I also have to change the title for every activity.
The typical answer would be Fragments. Here's a great tutorial on that topic.
However, depending on the triviality of your requirements, you could also consider using a horizontal LinearLayout containing your two original LinearLayouts.
in my opinion you should use fragments for your columns.
http://developer.android.com/guide/components/fragments.html
you Should use Fragment control for this. you can call content Fragments on right side (Content View) area with the click on leftSide(Content item/Index) .
I feel you should follow this link.
http://developer.android.com/training/multiscreen/screensizes.html
Am not sure but hopes u asked for the same.
Thanks..

Categories