Fragments for Google Maps add on?

Showing 1-13 of 13 messages
Fragments for Google Maps add on? Pete Doyle 3/3/11 7:48 PM
Anyone know if / when the Google Maps add-on will support the new Fragments api?  

Also, any chance of a version that works with the static library released today?
Re: [android-developers] Fragments for Google Maps add on? Dianne Hackborn 3/3/11 9:37 PM
Sorry, nothing scheduled.  There is nothing preventing you from writing a little code to put MapView in your own fragment, is there?

On Thu, Mar 3, 2011 at 7:48 PM, Pete Doyle <pete...@gmail.com> wrote:
Anyone know if / when the Google Maps add-on will support the new Fragments api?  

Also, any chance of a version that works with the static library released today?

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-d...@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en



--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

Re: [android-developers] Fragments for Google Maps add on? Mark Murphy 3/4/11 4:07 AM
On Fri, Mar 4, 2011 at 12:37 AM, Dianne Hackborn <hac...@android.com> wrote:
> Sorry, nothing scheduled.  There is nothing preventing you from writing a
> little code to put MapView in your own fragment, is there?

The bigger issue is that MapView has to be in a MapActivity, and there
may be some problems there:

http://stackoverflow.com/questions/5109336/mapview-in-a-fragment-honeycomb

I have not yet tried this personally, as I was waiting for the
backwards-compatibility library before diving headlong into fragments
(and many thanks for that library!).

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android 3.0 Programming Books: http://commonsware.com/books

Re: [android-developers] Fragments for Google Maps add on? Pete Doyle 3/7/11 12:37 PM
Sweet, so it turns out you can make the Activity which manages your Fragments extend MapActivity.

Then you can make a MapFragment with a MapView.  Seems to work so far.

Thanks to Valentin here:
http://stackoverflow.com/questions/5109336/mapview-in-a-fragment-honeycomb


--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-d...@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Fragments for Google Maps add on? Streets Of Boston 4/25/11 4:18 PM
The option from Valentin in stackoverflow doesn't work well with the compatibility library. This is what i did to make it MapActivity work with Fragments using the compatibility library (it is not the best solution, but it seems to work so far):
 
  1. Use the source of the compatibililty library (just copy android/* into your project's source dir).
  2. Rename (don't refactor!) FragmentActivity.java into AFragmentActivity.java (rename file and class-name).
  3. Create a new java file FragmentActivity.java. Make it an interface (see below).
  4. Have AFragmentActivity implement FragmentActivity.
    public class AFragmentActivity extends Activity implements FragmentActivity ... 
    1. Fix the compiler errors that will happen.
    2. instead of .mFragments, use getFragments()
    3. instead of mHandler, use getHandler()
    4. add casts that will cast FragmentActivity into Context or Activity where necessary.
    5. etc.
  5. After all compiler errors have been fixed, make a copy of AFragmentActivity.java and call it AFragmentMapActivity.java and have it extend MapActivity
    public abstract class AFragmentMapActivity extends MapActivity implements FragmentActivity ...
Now you can have a MapView in a regular fragment as long as that fragment is hosted inside a AFragmentMapActivity.
 
Source of the FragmentActivity interface (without the imports and such):
package android.support.v4.app;
...
...
public interface FragmentActivity {
 public ClassLoader getClassLoader();
 public View findViewById(int mViewId);
 public Context getApplicationContext();
 public Resources getResources();
 public Window getWindow();     
 public LayoutInflater getLayoutInflater();
 public boolean isFinishing();
 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo);
 
 public FragmentManagerImpl getFragments();
 public Handler getHandler();
 
 public LoaderManagerImpl getLoaderManager(int mIndex, boolean mLoadersStarted, boolean b);
 public CharSequence getText(int mBreadCrumbTitleRes);
 public void invalidateFragmentIndex(int mIndex);
 public void onAttachFragment(Fragment f);
 public void startActivityFromFragment(Fragment fragment, Intent intent, int i);
 public void supportInvalidateOptionsMenu();
}
 
Re: [android-developers] Fragments for Google Maps add on? lbendlin 4/25/11 4:36 PM
This would not change the limitation that an application can only have one MapActivity, right?
Re: [android-developers] Fragments for Google Maps add on? Streets Of Boston 4/25/11 5:16 PM
You're right. That's still the same (btw, the docs say you can have multiple MapActivities per app, as long as they are in different processes "... Only one MapActivity is supported per process ...").
 
The post above describes how you can have a MapView in a Fragment using the V4 compatibility library's sources.
I was interested in this, because I'd like to use the LoaderManager getting data from the web to display on a map.
 
Re: Fragments for Google Maps add on? Daniel Smith 4/29/11 12:42 PM
Hay, I’m curious if you could share the source code of the two file
you are talking about here and maybe a usage example...

Thanks,

Dan

On Apr 25, 6:18 pm, Streets Of Boston <flyingdutc...@gmail.com> wrote:
> The option from Valentin in stackoverflow doesn't work well with the *compatibility
> library*. This is what i did to make it MapActivity work with Fragments
> using the compatibility library (it is not the best solution, but it seems
> to work so far):
>
>    1. Use the source of the compatibililty library (just copy android/* into
>    your project's source dir).
>    2. Rename (don't refactor!) FragmentActivity.java into
>    AFragmentActivity.java (rename file and class-name).
>    3. Create a new java file FragmentActivity.java. Make it an interface
>    (see below).
>    4. Have AFragmentActivity implement FragmentActivity.
>    *public class AFragmentActivity extends Activity implements
>    FragmentActivity ... *
>     1. Fix the compiler errors that will happen.
>       2. instead of .mFragments, use getFragments()
>       3. instead of mHandler, use getHandler()
>       4. add casts that will cast FragmentActivity into Context or Activity
>       where necessary.
>       5. etc.
>       5. After all compiler errors have been fixed, make a copy of
>    AFragmentActivity.java and call it AFragmentMapActivity.java and have it
>    extend MapActivity
>    *public abstract class AFragmentMapActivity extends MapActivity
>    implements FragmentActivity ...*
>
> Now you can have a MapView in a regular fragment as long as that fragment is
> hosted inside a AFragmentMapActivity.
>
> Source of the FragmentActivity interface (without the imports and such):
> *package android.support.v4.app;*
> *...*
> *...*
> *public interface FragmentActivity {
>  public ClassLoader getClassLoader();
>  public View findViewById(int mViewId);
>  public Context getApplicationContext();
>  public Resources getResources();
>  public Window getWindow();      
>  public LayoutInflater getLayoutInflater();
>  public boolean isFinishing();
>  public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo
> menuInfo);*
> **
> * public FragmentManagerImpl getFragments();
>  public Handler getHandler();*
> **
> * public LoaderManagerImpl getLoaderManager(int mIndex, boolean
> mLoadersStarted, boolean b);
>  public CharSequence getText(int mBreadCrumbTitleRes);
>  public void invalidateFragmentIndex(int mIndex);
>  public void onAttachFragment(Fragment f);
>  public void startActivityFromFragment(Fragment fragment, Intent intent, int
> i);
>  public void supportInvalidateOptionsMenu();
>
>
>
> }*- Hide quoted text -
>
> - Show quoted text -
Re: Fragments for Google Maps add on? Streets Of Boston 4/30/11 4:04 PM
The new contents of FragmentActivity.java are in my earlier post.
 
The AFragmentActivity.java is a copy of the original FragmentActivity.java with these additional changes:
  • public class AFragmentActivity extends Activity implements FragmentActivity
  • Then fix the compiler errors from the change above (i.e. implement missing methods that are defined by the FragmentActivity). This is pretty trivial.
The AFragmentMapActivity is a copy of the AFragmentActivity with these additional changes:
  • public abstract class AFragmentMapActivity extends MapActivity implements FragmentActivity
Then you'll find that other source files in the compatibility have some compiler errors. These are trivial to fix. Mostly adding (Context) or (Activity) casts and calling '.getFragments()' instead of '.mFragments' and such.
 
Here is a usage example:
public class Main extends AFragmentMapActivity {
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
 @Override
 protected boolean isRouteDisplayed() {
  return false;
 }
}
 
public class MapFragment extends Fragment {
 private View    fragmentView;
 private MapView mapView;
 
 @Override
 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        fragmentView = inflater.inflate(R.layout.map, container, false);
        mapView = (MapView)fragmentView.findViewById(R.id.mapview);
        
        return fragmentView;
 }
}

And the layout main.xml has a <fragment> in there that refers to MapFragment.

 

 
     
     
  •  

  •  
Re: Fragments for Google Maps add on? Daniel Smith 5/2/11 11:13 AM
I'm still having issues. I'm using the honeycombgallery sample from
the android site and am tring to remove the ImageView fragment (that
shows the image in the bottom right) and replace it with a
AFragmentMapActivity.

The samples Main uses multiple fragments and I would like to continue
doing that but with the replacement of one of them to a
AFragmentMapActivity.

The sample works if i have the mainactivity extend from
AFragmentActivity and leave all original fragments in place but when I
try to extend from AFragmentMapActivity and replace the ImageView
fragment with a MapActivity AFragmentMapActivity  I can't get things
to work.

Would you have any pointers as to how I could change the code to make
this example work?



On Apr 30, 6:04 pm, Streets Of Boston <flyingdutc...@gmail.com> wrote:
> The new contents of FragmentActivity.java are in my earlier post.
>
> The AFragmentActivity.java is a copy of the original FragmentActivity.java
> with these additional changes:
>
>    - public class AFragmentActivity extends Activity *implements
>    FragmentActivity*
>    - Then fix the compiler errors from the change above (i.e. implement
>    missing methods that are defined by the FragmentActivity). This is pretty
>    trivial.
>
> The AFragmentMapActivity is a copy of the AFragmentActivity with these
> additional changes:
>
>    - public abstract class AFragmentMapActivity extends *Map*Activity
>    implements FragmentActivity
>
> Then you'll find that other source files in the compatibility have some
> compiler errors. These are trivial to fix. Mostly adding (Context) or
> (Activity) casts and calling '.getFragments()' instead of '.mFragments' and
> such.
>
> Here is a usage example:
> *public class Main extends AFragmentMapActivity {
>
>     /** Called when the activity is first created. */
>     @Override
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.main);
>     }*
> * @Override
>  protected boolean isRouteDisplayed() {
>   return false;
>  }
>
> }*
>
> *public class MapFragment extends Fragment {
>  private View    fragmentView;
>  private MapView mapView;*
> *
>  @Override
>  public View onCreateView(LayoutInflater inflater, ViewGroup container,
> Bundle savedInstanceState) {
>         fragmentView = inflater.inflate(R.layout.map, container, false);
>         mapView = (MapView)fragmentView.findViewById(R.id.mapview);
>
>         return fragmentView;
>  }*
> *}*
>
> And the layout main.xml has a <fragment> in there that refers to *
> MapFragment*.
> *
>
> *
>
>    -  
>    -
Re: [android-developers] Re: Fragments for Google Maps add on? Daniel Smith 5/2/11 6:09 AM

Thanks for the response this all makes perfect sense. I've. Made the changes and hope to try it out today some time.

Thanks again... 

Dan

On Apr 30, 2011 6:05 PM, "Streets Of Boston" <flying...@gmail.com> wrote:
> The new contents of FragmentActivity.java are in my earlier post.
>
> The AFragmentActivity.java is a copy of the original FragmentActivity.java
> with these additional changes:
>
> - public class AFragmentActivity extends Activity *implements
> FragmentActivity*
> - Then fix the compiler errors from the change above (i.e. implement
> missing methods that are defined by the FragmentActivity). This is pretty
> trivial.
>
> The AFragmentMapActivity is a copy of the AFragmentActivity with these
> additional changes:
>
> - public abstract class AFragmentMapActivity extends *Map*Activity
> implements FragmentActivity
>
> Then you'll find that other source files in the compatibility have some
> compiler errors. These are trivial to fix. Mostly adding (Context) or
> (Activity) casts and calling '.getFragments()' instead of '.mFragments' and
> such.
>
> Here is a usage example:
> *public class Main extends AFragmentMapActivity {

>
> /** Called when the activity is first created. */
> @Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.main);
> }*
> * @Override

> protected boolean isRouteDisplayed() {
> return false;
> }
> }*
>
> *public class MapFragment extends Fragment {
> private View fragmentView;
> private MapView mapView;*
> *
> @Override
> public View onCreateView(LayoutInflater inflater, ViewGroup container,
> Bundle savedInstanceState) {
> fragmentView = inflater.inflate(R.layout.map, container, false);
> mapView = (MapView)fragmentView.findViewById(R.id.mapview);
>
> return fragmentView;
> }*
> *}*

>
> And the layout main.xml has a <fragment> in there that refers to *
> MapFragment*.
> *
>
> *
>
>
>
>
> -
> -
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-d...@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
Re: Fragments for Google Maps add on? Streets Of Boston 5/2/11 2:15 PM
You cannot replace a fragment (e.g. your ImageView fragment) directly with an activity (in your case a subclass of AFragmentMapActivity). Don't confuse Activities with Fragments.

Have your main Activity, that hosts the Map fragment (and possibly other fragments as well), extend AFragmentMapActivity. In my example that is 'Main'.
Then inflate in your main Activity a layout with a <fragment> that contains a MapView. In my example that is 'MapFragment'.

Re: [android-developers] Re: Fragments for Google Maps add on? Daniel Smith 5/3/11 11:45 AM

Thanks for all your input I did get it working.

Dan

On May 2, 2011 4:16 PM, "Streets Of Boston" <flying...@gmail.com> wrote:
> You cannot replace a *fragment *(e.g. your ImageView fragment) directly with
> an *activity *(in your case a subclass of AFragmentMapActivity). Don't
> confuse Activities with Fragments.
>
> Have your main Activity, that hosts the Map fragment (and possibly other
> fragments as well), extend AFragmentMapActivity. In my example that is
> 'Main'.
> Then inflate in your main Activity a layout with a <fragment> that contains
> a MapView. In my example that is 'MapFragment'.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-d...@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en