ANDROID: Possible to load an Activity into a SlidingDrawer view? - android

I'm searching all over but cannot seem to find a answer to this.
I have my main HomeActivity view which contains a SlidingDrawer in the main.xml layout. The sliding drawer works fine. What I'd like to do though is that when the SlidingDrawer is opened, I want to launch a new activity in the sliding drawer view, and when the drawer closes it drops a result.
So in theory I'm looking at launching an activity with the startActivityForResult method and when the SlidingDrawer closes, processing the result? Is this at all possible or am I out to lunch?

I have recently given this some thought and although actually having the activity itself display inside the SlidingDrawer contents is impossible, theoretically you could simulate this buy copying the layout you are going to, and putting that as the contents, then as soon as the sliding drawer is done, go to the new activity. I haven't tried this myself but it might actually look nice. It won't be perfect but I think it could work.
Another way is to merge both those activities into one and use the sliding drawer to show the other layout.
Anybody have any better ideas I'd love to hear them also!

Related

How to keep Bottom Navigation View after opening an Activity from Fragment?

I'm a beguinner with Android programming, and in my app I have a Bottom Navigation View with 3 fragments.
One of those fragments has a button that allows the user to open another Activity to listen to music. But whenever the Activity is opened using Intents, the Bottom Navigation View from the previous screens disappears.
Can I open an Activity from a Fragment, but still have the Bottom Navigation View active?
Below is attached a link with an image of the mock-up I've made, hope it helps to clarify the question:
Thank you in advance for trying to help me out!
Reason
Well I guess (because I have no clue about your code base) the bottom navigation bar is a part of the main activity in which the fragments are being contained. When you are starting a new activity, the main activity with the bottom navigation goes as the music player layout loads.
Recommended Solution
Instead of keeping the music player as an activity make it a fragment and load in the view you are using as the fragment container in the main activity.
Another Way round (Not recommended)
Make another view of the bottom navigation bar in the music player activity and map the actions of the button click to load the main activity.
It might be a bit time taking and buggy initially but with debugging and testing, you can make it work.
But again its not a good option.

Bottom Navigation with Activity

I have an application where it is required to persist the bottom navigation across multiple screen. Now naturally bottom navigation works well with fragments but the problem is that my other fragments also have other screens to call which is usually delegated back to the handling activity.
With said, when i tried implementing the bottom navigation with fragments the activity becomes a God Activity where it handles all fragments.
So my solution was to start an activity instead. But the problem with this approach is that every start of the activity the activity transition makes it obvious an activity is being started. I tried setting off the activity transition to avoid this but now Im left with a very static page which just suddenly changes. I still want my views to animate smoothly between screen changes.
Can someone give me an advice here. Heres what I would want to achieve in summary:
1) make it seem the bottom navigation was not changed/moved (and hopefull still have the shifting animation if possible)
2) animate smoothly between screen changes
3) also still have the capability of having shared element transition if possible.
Please help me here. Thank you so much in advance.

Back button behavior differs depending on whether I entered activity from the nav drawer or from a UI element

I created a NavigationDrawerFragment, which is actually just a slightly modified version of the code Android Studio generates.
I have a Dashboard activity that contains NavigationDrawerFragment and that can launch several other activities, each of which also contain the NavigationDrawerFragment. Let's call one of these activities Foo.
If I enter Foo from the Dashboard using the Dashboard's nav drawer, then open Foo's nav drawer, the back button will correctly close the nav drawer. HOWEVER, if I entered Foo using a UI element (that was in place before I implemented a nav drawer), then open Foo's nav drawer, the back button returns to the Dashboard activity rather than closing the nav drawer.
I can't figure out why this is occuring. For the NavigationDrawerFragment I have an ItemClickListener and for the UI element I have a ClickListener, but in both situations I am launching a new Foo activity using an intent.
I am wondering if there is something being set that I just don't realize, and if I have control over that something.
I know that I could override onBackPressed to check for the drawer being open (as shown here), but that feels hacky as there is obviously some behavior happening here that I am not aware of.
Edit: This has something to do with ActionBar-PullToRefresh. I removed it from Foo and the nav drawer works correctly.
Edit 2: I was wrong about pull-to-refresh, as #adneal pointed out. There must have been a coincidence that made me think that. I ended up overriding onBackPressed and conditionally checking if the drawer is open or not. Also as #adneal pointed out, the problem has to do with focus. I am still so very curious as to how the focus could be different when launching the activities the same way, but from different places.
So, I'm fairly certain I understand what's going on, but I'm still unsure about why it only seem to happen when you use a View.OnClicklistener. Maybe there's a little more to your code that I don't know about or maybe I overlooked something in those regards.
But the reason you're having this problem is due to how Android handles the View.onKey... event. DrawerLayout overrides View.onKeyDown and View.onKeyUp, checking each time if you're pressing the "back" button so it can determine whether or not to close the drawer. But this event isn't taking place, in your case, because the AdapterView you have set will take the focus away from the DrawerLayout after you call AdapterView.setAdpater.
How to fix it
Short of copying over the DrawerLayout source and modifying it, which you could definitely do; it's only one class, I would recommend converting each Foo Activity into a Fragment, then use the FrameLayout you typically place when creating a DrawerLayout to display them. You should create a NavigationDrawerActivity instead of a Fragment to host everything.
This has to do with the way DrawerLayout is laid out, in that it has to use MeasureSpec.EXACTLY. In other words, when you place your NavigationDrawerFragment ontop of your Foo layout, it takes up the entire space. If you called View.setFocusableInTouchMode after you set your ListAdapter in Foo, the DrawerLayout would work like it should, but the AdapterView wouldn't scroll anymore. And you can't toggle that focus based on the open or closed position of the DrawerLayout, because either way it takes up the entire space and always return true in View.onTouchEvent.
Or just override Activity.onBackPressed, which really isn't as "hacky" as you may think, but I understand what you mean.
At any rate, I hope this is clear and/or helpful at the very least. Took me a little bit to reproduce your problem, but after I did it didn't take long to rule out the pull-to-refresh library. In short, I think it's a focus issue. Prove me wrong.
Source
You can view the source for the DrawerLayout here to look over how it handles the "back" event
You can see here how AdapterView.checkFocus works
You can see here in ListView (GridView is the same), when AdapterView.checkFocus is called

Transition when switching Activity out of SlidingMenu (J.Feinstein)

I am an android newbie and I am trying to create an Android App with three Activities: a Homescreen, a listview and a detailview.
I integrated J. Feinstein's Sliding Menu in my Homescreen and filled it with a ListView to display my different categories (Restaurants, Bars, Culture, whatever). When I click one of my List Items, the new Activity gets created and Pops up. However, I want the Activity to replace the old one while the SlidingMenu stays on top and then gently slides away. I saw this behaviour in the Example App but I cant quite find the bit of code that holds the answer to my question. Hope anyone can help :)
The sample app uses fragment transactions instead of starting new activities to change the content. As far as I know, that is the only way to do the two actions – close sliding menu and change content – simultaneously.

Avoid Tabs from disappearing when searching

i've got a tabbed layout, and on one of the tabs i have a search functionality. When the user makes a new search, i need to show the results. However, doing so involves starting another activity to handle the search results.
this causes the tabs at the bottom to disappear. The user can get the tabs back by clicking on the 'back' button. But somehow, in the context of my application this can be a bit counter-intuitive and seems to be break the common layout flow.
is there any way to prevent the tabs from disappearing when invoking the search from one of the tabs?
thanks for any help/suggestions.
as far as i can understand your problem, You are not using tabs then you are using buttons. see some tabhost tutorials on how to create a tabbed activity. what you are doing is launching a new activity instead of just switching a tab in the existing one.
Also the other things you can look for are activity groups.
Hope this helps you somehow.

Categories

Resources