Map View and Fragments (4.0-wip)

746 views
Skip to first unread message

Kekoa Vincent

unread,
Jan 13, 2012, 4:28:22 PM1/13/12
to ActionBarSherlock
First off, I've only been using ABS for a few days and I'm very
impressed, I really appreciate the time you(Jake et. al) have put into
this project, it is making my life a lot easier.

I got my project working with v3.5 but decided to stay bleeding edge
with your 4.0-wip branch, seeing as development is so active. So I
switched everything over to the new way you have your classes
organized(of course fixed some references), and so far so good(builds
and runs great).

Ran into an issue with getting my Activity to subclass
SherlockActivity, MapActivity, and FragmentActivity(from support
package). I solved it by creating my own SherlockMapActivity, which
is a copy of SherlockActivity that extends FragmentActivity, which
then extends MapActivity(since I'm building support lib from source I
can do that).

It works, but seems a little hacky and when ABS updates I have to
recreate my class and when the support library changes, I'll have to
merge changes as well. I would love to just include the support
library jar, but right now I don't see how to accomplish this without
modifying support library's FragmentActivity.

Do you already have a solution(either concrete, or mentally) for this
situation? MapView in a Fragment(using Navigation Tabs) already has a
few caveats, but I think I have it worked out, just want to know if
there is a cleaner way.

Thanks,

Kekoa

Jake Wharton

unread,
Jan 14, 2012, 1:43:10 AM1/14/12
to actionba...@googlegroups.com
Yes I had assumed that this was going to come up sooner or later. Especially since I made the mistake of allowing this in v3.x.

Currently, the compat lib plugin maven module consists of only the three files that need changed. During the generate-sources phase (the one that occurs immediately before compilation if you're not a maven user), a plugin explodes the binary compat lib .jar's classes into the destination directory. Then, when compilation occurs, our three source files overwrite the original three that were exploded from the .jar.

I chose to do it this way so that I would only have to perform merges on 3 files when a new version is released which should make my life a lot easier and that process a lot quicker.

Now, that being said, it would be trivial to clone this module into a compat-lib-map folder and modify the FragmentActivity's class declaration to extend from MapActivity. Do I want to do this and distribute it, however, is the question.

Ideally there would be an even more efficient way where duplicating the sources wasn't required, it would only copy everything from the normal compat-lib plugin and replace the class declaration.

I will have to think on this over the weekend. Maybe we'll get lucky and get a proper MapFragment with the next revision of the compat lib (since it was alluded to in one of the developer chats) and the whole thing will be moot!

---
Jake Wharton
http://about.me/jakewharton

maku

unread,
Jan 23, 2012, 2:37:42 AM1/23/12
to ActionBarSherlock
Hi,

I'm new with ABS and would like to start with V4.0...

Now I need to use FragmentActivity class together with ABS.
For me it is not clear how to do this....

Is the way to extend FragmentActivity and to override methode like in
com.actionbarsherlock.app.SherlockActivity???

TIA
Martin

On 14 Jan., 07:43, Jake Wharton <jakewhar...@gmail.com> wrote:
> Yes I had assumed that this was going to come up sooner or later.
> Especially since I made the mistake of allowing this in v3.x.
>
> Currently, the compat lib plugin maven module consists of only the three
> files that need changed. During the generate-sources phase (the one that
> occurs immediately before compilation if you're not a maven user), a plugin
> explodes the binary compat lib .jar's classes into the destination
> directory. Then, when compilation occurs, our three source files overwrite
> the original three that were exploded from the .jar.
>
> I chose to do it this way so that I would only have to perform merges on 3
> files when a new version is released which should make my life a lot easier
> and that process a lot quicker.
>
> Now, that being said, it would be trivial to clone this module into a
> compat-lib-map folder and modify the FragmentActivity's class declaration
> to extend from MapActivity. Do I want to do this and distribute it,
> however, is the question.
>
> Ideally there would be an even more efficient way where duplicating the
> sources wasn't required, it would only copy everything from the normal
> compat-lib plugin and replace the class declaration.
>
> I will have to think on this over the weekend. Maybe we'll get lucky and
> get a proper MapFragment with the next revision of the compat lib (since it
> was alluded to in one of the developer chats) and the whole thing will be
> moot!
>
> ---
> Jake Whartonhttp://about.me/jakewharton

Jake Wharton

unread,
Jan 23, 2012, 8:11:15 AM1/23/12
to actionba...@googlegroups.com
There is a compat lib plugin for ActionBarSherlock available for download on the beta site which provides fragment support.

Michael Basil

unread,
Jan 25, 2012, 12:53:25 PM1/25/12
to ActionBarSherlock
Would be great to have some sort of support for MapFragments in
ActionBarSherlock. It's really slowly my progress on updating my app
to include the ActionBar using this library.

I'm surprised that Google have just ignored the problem since so many
apps include map functionality, but they have just started charging
for use of the Javascript Maps API so maybe map usage is costing them
too much.

-----------------------
Michael Basil
Intrications.com

Jake Wharton

unread,
Jan 25, 2012, 10:14:45 PM1/25/12
to actionba...@googlegroups.com
Reto Meier alluded to the fact that the maps team was working on something and that it was a problem that needed solving. I expect that we'll see something in the next few months (hopefully sooner).

Unfortunately there's no easy way to support this without massive changes in the compatibility library which is not something I'm prepared to maintain for v4. It actually should have never happened with v3.x.

Version 4 of ActionBarSherlock supports creating your own base activities or not even using a base activity altogether and just using the ActionBarSherlock class directly which will allow you to use alternate versions of the support library which allow for using MapView. Take a look at the 'Static Attachment' example in the demo samples for v4 to see how this static attachment works if you're interested.

Jack Gao

unread,
Feb 16, 2012, 11:12:28 AM2/16/12
to actionba...@googlegroups.com
Hi, Jake

Does that means if I wanted to have fragment support, I should use the compat lib plugin, not the library?

Jake Wharton

unread,
Feb 16, 2012, 11:15:30 AM2/16/12
to actionba...@googlegroups.com
Fragments are provided by the support-lib plugin for v4.0. You also need the library when using it.

Jack Gao

unread,
Feb 16, 2012, 8:28:40 PM2/16/12
to actionba...@googlegroups.com
I found there is no getSupportFragmentManager() in SherlockActivity, do I have to extend FragmentActivity to have fragment support?

Jake Wharton

unread,
Feb 16, 2012, 8:53:22 PM2/16/12
to actionba...@googlegroups.com
Yes. The Sherlock* classes just extend from whatever the "*" part is.

zheng

unread,
Feb 16, 2012, 9:08:39 PM2/16/12
to actionba...@googlegroups.com
In the onCreate() method, how to get the ActionBar, is it just like 3.5.1 that uses getSupportActionBar() method?
-- 
zheng
Sent with Sparrow

Jake Wharton

unread,
Feb 16, 2012, 9:10:20 PM2/16/12
to actionba...@googlegroups.com
Precisely. Samples for fragments and such will come with the final release.

Jack

unread,
Feb 16, 2012, 9:19:23 PM2/16/12
to actionba...@googlegroups.com
Can't override onCreateOptionsMenu(Menu menu) method to create optionsMenu, it saids it's final, what's the alternative method to create menu in 4.0 now?

-- 
zheng
Sent with Sparrow

Jake Wharton

unread,
Feb 16, 2012, 9:20:22 PM2/16/12
to actionba...@googlegroups.com
Same method signature. Different imports. Use com.actionbarsherlock.view.* for menu-related stuff.

Jack

unread,
Feb 16, 2012, 9:23:08 PM2/16/12
to actionba...@googlegroups.com
And need getSupportMenuInflater() to get the inflater then?

-- 
Jack
Sent with Sparrow

Jake Wharton

unread,
Feb 16, 2012, 11:56:40 PM2/16/12
to actionba...@googlegroups.com
Yes. We no longer extend the built in classes so we can't use the normal inflater anymore.

Jack

unread,
Feb 17, 2012, 12:57:47 AM2/17/12
to actionba...@googlegroups.com
Really need a simple example about how to user ABS 4.0 with fragments

-- 
Jack
Sent with Sparrow

Jake Wharton

unread,
Feb 17, 2012, 11:28:32 AM2/17/12
to actionba...@googlegroups.com
It's coming in the next few days and will definitely be in before the next release candidate.

Jack

unread,
Feb 17, 2012, 11:50:43 AM2/17/12
to actionba...@googlegroups.com
That's great! Thanks for your great work!

-- 
Jack
Sent with Sparrow

Lshanu NearKheel

unread,
Dec 28, 2012, 12:01:15 PM12/28/12
to actionba...@googlegroups.com
Hey Jack, Is it possible to have a tabwidget inside is a mapfragment? Please reply ASAP.. Thanks dude.. 
Reply all
Reply to author
Forward
0 new messages