Android- Display Global Application Information - android

I am working on an application that has several states that matter to the user, online vs offline, how far out of date the local application database is, et cetera. I understand that both non-persistent and persistent notifications are available in android, and might be appropriate in this scenario. However, in our organization's iOS application, there is an 'information bar'.
I realize that this is somewhat of a departure from material design. Is this even possible? I'd like to extend the App Bar in some way as opposed to creating a fragment that I add to every activity if possible.

Try any of the following
1) Replace the action bar with toolbar and customize the design on your own and handle it.
2) Create the separate layout file with the above design and then include it in any screen using the tag <include/>

You can do this a custom Toolbar class or with Fragments. For the later option, each activity will have the user information at the top, either as a view or a fragment. The "normal app stuff" will be a FrameLayout which can hold one fragment at a time. See the Fragment tutorials on http://developer.android.com.

There aren't really hooks for extending the toolbar- in fact Google has deprecated a lot of stuff it used to be able to do (such as tabs in the toolbar). Your best bet is to use a custom fragment at the top of every Activity.

Related

Navigation hierarchy on Android?

I've recently been looking into the navigation system that Android uses with as intention to port my iOS app that uses an UITabBarController containing multiple UINavigationControllers. To replace the tab bar (which is not available on Android) I settled on using the built in DrawerLayout.
From what I've read, navigation in Android is generally done by creating an Intent, providing it with extras and then just replacing the current activity. This automatically makes sure the back button works, and optionally the back button in the top left if enabled.
However, I am not sure how to implement this way of navigation with the navigation drawer. The tutorial tells me to create a DrawerLayout containing a FrameLayout and a ListLayout where the FrameLayout will contain the actual application and the ListLayout will contain the navigation. This would mean that when I use the method described above to "navigate", it would replace the activity and thus removing the drawer.
What would be the best way to implement what I want (basic navigation with back button support while maintaining a global drawer navigation menu)? The possible options I can come up with is always keeping the same activity and dynamically replacing the FrameLayout, but that would mean a lot of boilerplate to render and possibly a hack to support the back button (and there would be no animations :(). The other option would be to just render the drawer on every activity (via subclassing or something), but that would mean that if the user navigates a lot the back button "stack" would become quite large.
I have tried to explain what I need in as much detail as possible, but it is quite hard to explain the concept. Basically, I want something similar to the UINavigationControllers in the UITabBarController.
You can either have one Activity with one NavigationDrawer and present the user with different views by switching Fragments back and forth within that one Activity. You would use the FragmentManager to switch between different Fragments.
Or you can use multiple Activities that all have a NavigationDrawer.
Second option might sound more difficult but it really isn't. You create a base Activity that all your Activities inherit from and all let them have their own NavigationDrawer, no problem.
Sure there's something in between or something completely different, but that's the most straightforward approaches I can think of.
The tutorial you've probably used (the one with the planets) is imho a bit misleading because it assumes a very basic app structure. If you have only little different 'screens' that might work, for a very complex application it's not suitable (again, in my opinion).
I've always opted for the second option because handling the navigation / backstack is just easier with Activities / Intents.
There's loads of different flags that you can set to your Intent to influence their navigation behaviour.
Also see this and that documentation. These documents might have been written when the NavigationDrawer pattern was not all that common but they are still useful.

Swipe to finish Activity pattern

I have seen this pattern on both Tumblr and Telegram apps.
When you are in a detail view (Searching for a Hashtag on Tumblr or in a conversation on Telegram) and swipe from left to right (like if you were going to pull a Navigation Drawer) you can see the previous activity come up from there. If you release it, the Activity is finished.
How is this behavior implemented?
[Disclaimer: the following dissertation was written after just one hour or so examining Telegram's source code, so it may contain important flaws or mistakes. Feel free to comment]
The case of Telegram looks to be quite different from what Teovald says. In Telegram's case it is not a fixed image. You can check this by having for instance an open chat where someone is writing half swiped. You will see that both the "chat activity" and the "list of chats activity" are updated in real time, which could not be the case if the effect were accomplished by using a static image.
Since Telegram is open sourced, you can have a look at its code base to figure out how it is actually done.
After examining the code myself for a while, it looks like what they do is not a visual trick. In fact, its a trick which goes far beyond doing small trickery to fake some visual effect. Whatever the case, it smells like some non-standard stuff.
First of all, you can have a look at Telegram's manifest file to see that they only define three activities (LaunchActivity, IntroActivity and PopupNotificationActivity)... three activities! Anyone using Telegram would agree that the application seems to have more than three activities, so whatever they are doing it looks like in practice they only have a single activity running at the same time (LaunchActivity), which through some mechanism shows different "activity like" content.
Indeed, if you go to LaunchActivity you will see that it inherits from a so called ActionBarActivity, which would be the base class for all real activities in Telegram (although in practice only LaunchActivity seems to extend it). This activity seems to take care of implementing, along with other classes, the action bar. Yes, that means that Telegram does not use the standard action bar, nor defines any kind of wrapper to use a "mock" version on Android < 11 and the real version on Android >= 11. It's quite twisted, but you can have a look at their implementation of the action bar (class ActionBar as well as other dependent classes) and see that they are literally creating a raw FrameLayout and embedding it to emulate the action bar. This means, among other things, that they do not inflate XML resources to define the action bar for each "activity", they populate it by hand instead. Very cumbersome and very non-standard, which in my opinion makes Telegram kind of weak regarding improvements of the action bar in future versions of Android.
Now, the thing that concerns me the most is that they are completely ignoring the Android's activities and fragments system, rolling out their own version. To be precise it's not like they are ignoring Android's activities and fragments altogether, but they are using some techniques that (in my humble opinion) would be frowned upon by probably most of Android developers out there.
If you look at ActionBarActivity you will see that it extends a regular Android Activity. It removes (via its theme, and also programatically) the standard action bar and title of the activity in the onCreate() method (this confirms that they use their own customized version of the action bar). But most importantly, they define a "stack" of "fragments". A "fragment" here is not what one understands by "Android fragment", but some weird version they rolled out too to implement the concept of "fragment". They use the BaseFragment class to define a "fragment", which is basically a class that creates its view via a callback (just as Android's fragments do), and which defines some "life cycle" methods such as onPause() and onFragmentDestroy(). Then you can see that what we would consider to be regular Android activities is actually implemented via this weird mechanism of BaseFragments. For instance, the "chat activity" is implemented by the ChatActivity class, however this does not inherit from Android's Activity, but from BaseFragment instead.
So to summarize what I have explained so far, Telegram seems to be an application running a single activity (LaunchActivity, which in turn inherits from ActionBarActivity), which implements a customized action bar and a weird "fragment" framework which emulates regular Android activities, at least at the visual level.
Now, if you look at the onTouchEvent() method of the ActionBarActivity class, this seems to be the one in charge of implementing the core algorithm of the "swipe to dismiss" effect. This tracks the user's finger and moves the view of the fake fragment accordingly. When the user lifts the finger, if the condition to dismiss the "fragment" is true (backAnimation is false), the fragment is removed: when the animation ends, the onSlideAnimationEnd() method is called, which will then remove the "fragment" from the fragment stack kept by the ActionBarActivity class.
So, in short, Telegram accomplishes the "swipe to dismiss" effect by implementing a funky "fragments" system in which what seems to be an Activity is a raw view modeled via a subclass of BaseFragment. This forces them to roll out their own version of the action bar, and also to follow some very weird and "non-standard" Android techniques.
I did not actually know that Telegram was implemented this way, so at this moment I am kind of disappointed. I was expecting them to access some hidden Android APIs, which of course would be wrong, but at least it would not be so cumbersome and ugly as implementing their own action bar and "fragments" system. From now on, to me, Telegram's code will be a reference of what you must not ever do in Android.
Like any good visual feature, it is a trick :-) .
If you use the UI Automator tool to dump the screen content while in a middle of one of these back slides, you can see that the 'old fragment' is in fact just an image view.
It is only when the slide is finished that the previous fragment/activity is brought from the back stack.
I have just implemented this, check it out here
SwipeFinishableActivity.
Generally speaking, you need a translucent top activity so that when you drag the top activity you can see the second top one below. And you should track your touch event to move your views in your activities.

Dynamically change the content/layout/flow controlled via server

I am new to android development, and we have a very specific requirement.
We need to change the content/layout/flow of the app on the fly. For e.g. we have a layout which consists of some images, textarea and textboxes. There might be a request coming to change the textarea to a textbox.
We thought about this and are thinking to provide the apk with a json/xml which will contain all these changes.
My question is will it be possible to re-draw the objects again dynamically and change the content?
Yes this is possible. You can dynamically design what has to be displayed in your Activity UI screen. If you feel there are only 2 or 3 different UI screens that would be repeatedly used, then you can have XMLs for these screens and you can just change their labels in OnCreate() of Activity class before rendering. LayoutInflater class would be helpful here.
When you design a Android Application with Activities and Fragments your XML layout definition is always static. If you want a true dynamic layout structure you should use a Web View with a HTML content pointing some URL.
As Rahul says, another approach is to manage the "default cases". For me that is the standard way to design an Android Application.
The dynamic content (values) can be done with a simple http call to server you can get values for your views.
The navigation could be handled by switching Intents, but, definitively you have to associate these intents to UI elements like buttons in the most cases, and ¿How you can do that if your layout is changing over time?.
I think, that the WebView could be a very easy solution for your problem.

switch to a new activity, instead of switching fragments, when jfeinstein10's slidingmenu list item is clicked

I have seen a few questions raised on this topic (for e.g.: https://github.com/jfeinstein10/SlidingMenu/issues/5) but I am still unclear. I hope somebody can clarify this.
Context:
See https://github.com/jfeinstein10/SlidingMenu
I have an android app that organizes screens by activities and fragments (i.e.) each screen is an activity containing one or more fragments.
The new requirement is to add a sliding menu (similar to what this library provides).
Issue:
It appears from the examples and discussion that the right model would be to have just 1 MAIN ACTIVITY that will then switch in/out fragments belonging to the different screens. In fact the author mentions in the above thread: "If you were to launch Activities based upon the list selection, then you would not have the behavior where you swap the views that you're talking about. " and also "You can't put an Activity into the above view. That doesn't really make sense when you think about what an Activity is. ".
Why doesn't it make sense? Obviously, I am missing the point here.
Question:
Given that my project already contains multiple activities (one corresponding to each screen), is my only option then to re-organize the project to have JUST 1 MAIN ACTIVITY, in order to use this library? Or alternatively, is there any way to launch a new activity when a list item in the sliding menu is clicked, and still observe the sliding menu behavior, [EDIT- added the last part to be more clear] or in other words, on how exactly to use this library within my existing app design.
Thanks in advance
First, you can't have an Activity inside another and activities are completely different from views as stated in the docs:
An activity is a single, focused thing that the user can do.
Now, to answer your question, it all depends on how you want your app to behave. You could have your activities with the sliding menu implement the onClosedListener and switch to the selected activity from there. This will give you the animation of closing the menu before switching activities. It will also give you a weird effect since every time you select something from your menu you'll see the animation of a new activity coming to the front.
I think the best approach would be to have a "common purpose" between all your sliding menu options. For example, in one of my projects I have to allow the users to select between lists of different types of data. When the user selects anything from the menu, I load a new list fragment into the right corner where he may choose the item he wants to view or edit. That's the app entry point and also the only place were I have a sliding menu in my app. It is pretty much the same for every app that implements this UI design pattern. Look at google+, currents and youtube where the side menu lets you choose which feed or content to show. Once a user makes a selection, just open a new activity for the selected item (a g+ post, a video, a news article, a tweet or whatever it is).
Your app doesn't have to have lists of different data or anything like that to use the sliding menu, but keep in mind that the activity with the sliding menu should have a clear, focused goal with respect to its functionality and purpose. Having a sliding menu because many other apps have one is a bad choice, you should use it with a specific objective. Also keep in mind that applying the sliding menu everywhere would interfere with the platform's navigation pattern and lead to an overall bad user experience since it wouldn't behave as the other apps.
It doesn't make sense to place an Activity into the above view because the Activity is the main controller for the view of each screen. The Activity also shows views and keeps track of Fragments (which in turn are mini controllers, with or without their own views). So placing an Activity in the above view would mean that you would place an Activity in an Activity... Wich is impossible.
From what I can derive from your text I think it would be wise to read through the Android developer guide on Activities and Fragment again (http://developer.android.com/guide/components/activities.html) to get a better understanding of how the concept of Android works.
Now to your question:
I am not clear on what you are trying to achieve but if you want your app, with menu to behave like, say, the Google+ app then one way of doing it is to implement a base class that extends the Activity class (or what ever base Activity used in your project) and let the base set the SlidingMenu. Then you would simple extend your base Activity in each of the Activities that are supposed to have a menu.
You could also do it the way you describe it, but then you would end up with a classic example of a God object (http://en.wikipedia.org/wiki/God_object). It's a neat way to practice your Fragment juggling skills and switching between Fragments instead of starting new Activities does have it's use cases, but I still wouldn't recommend it for a project with more then a few views.
Here is the answer that came closest to the issue I had - http://www.verious.com/article/polishing-the-sliding-app-menu/. Scroll down to the bottom of the page to see the last section titled "Using the fly-in app menu between Activities". This is one option if you have a lot of activities in your existing app and want to avoid extensive re-factoring. I haven't tried this out yet but its worth being aware of.

Android Layout Fragment/Activity Confusion

I am making my first android application with the ActionBarSherlock.
The application will always have an action bar consisting of 3 tabs (first tab selected by default).
The app could be extended for use with a tablet.
I have been searching the web, and following the android development guides, however I am finding a few things confusing.
The first tab screen will be a list view with a list of items, onitemselected should send the user to a screen which features more details about that item.
When should I use a fragment? Should each tab be a fragment?
Or, should each tab call a new activity, which consists of fragments?
And, if using fragments, should I place them in different classes, or embed them within an activity??
Appreciate any help, thanks.
you should probably read these two links first.
http://android-developers.blogspot.com/2011/09/preparing-for-handsets.html
http://android-developers.blogspot.com/2011/02/android-30-fragments-api.html
If you plan to make an app that work on both phone and tablet. It is a good idea to use a fragment, and then use a shell activity to wrap that fragment.
My experience with Fragments is mostly on ViewPager, so I am not entirely sure if it applies here.
In Android, you should use Fragments as much as possible. As a general rule of thumb, imagine you are translating the UI from phones to tablets, elements that can stay together in the same configuration should be a Fragment.
There is a Fragment subclass called ListFragment, so you might want to look into that for your first tab. (ListFragment is for Fragment like ListActivity is for Activity)
There is also a tutorial I found to deal with fragments. Did not really look into it but I hope it helps.
http://android.codeandmagic.org/2011/07/android-tabs-with-fragments/
As for ActionBar / ActionBarSherlock, I have absolutely no experience withit so someone might want to add to that.

Categories

Resources