Java Code Examples for com.google.android.gms.maps.SupportMapFragment#newInstance()
The following examples show how to use
com.google.android.gms.maps.SupportMapFragment#newInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MapFragment.java From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_map, null); getActivity().setTitle("Map"); if (mapFragment == null) { mapFragment = SupportMapFragment.newInstance(); mapFragment.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(GoogleMap googleMap) { LatLng latLng = new LatLng(latitude, longitude); googleMap.addMarker(new MarkerOptions().position(latLng) .title("Singapore")); googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng)); googleMap.setMinZoomPreference(15.0f); googleMap.setMaxZoomPreference(20.0f); } }); } getChildFragmentManager().beginTransaction().replace(R.id.map, mapFragment).commit(); return view; }
Example 2
Source File: GeneralActivity.java From GitJourney with Apache License 2.0 | 6 votes |
@Override public Fragment getItem(int position) { Log.v(TAG, "getItem, position = " + position); // getItem is called to instantiate the fragment for the given page. // Return a PlaceholderFragment (defined as a static inner class below). switch (position) { case 0: return FeedListFragment.newInstance(); case 1: return RepositoriesListFragment.newInstance(); case 2: return FollowingListFragment.newInstance(); case 3: return FollowersListFragment.newInstance(); case 4: return StarsListFragment.newInstance(); case 5: LocationsReadyCallback callback = new LocationsReadyCallback(GeneralActivity.this); SupportMapFragment fragment = SupportMapFragment.newInstance(); fragment.getMapAsync(callback); return fragment; } return PlaceholderFragment.newInstance(position + 1); }
Example 3
Source File: ProgrammaticDemoActivity.java From android-samples with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // It isn't possible to set a fragment's id programmatically so we set a tag instead and // search for it using that. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentByTag(MAP_FRAGMENT_TAG); // We only create a fragment if it doesn't already exist. if (mapFragment == null) { // To programmatically add the map, we first create a SupportMapFragment. mapFragment = SupportMapFragment.newInstance(); // Then we add it using a FragmentTransaction. FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); fragmentTransaction.add(android.R.id.content, mapFragment, MAP_FRAGMENT_TAG); fragmentTransaction.commit(); } mapFragment.getMapAsync(this); }
Example 4
Source File: MapInPagerDemoActivity.java From android-samples with Apache License 2.0 | 5 votes |
@Override public Fragment getItem(int position) { switch (position) { case 0: case 1: return new TextFragment(); case 2: return SupportMapFragment.newInstance(); default: return null; } }
Example 5
Source File: MainFragment.java From AndroidSlidingUpPanel-foursquare-map-demo with Apache License 2.0 | 4 votes |
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); mLocation = getArguments().getParcelable(ARG_LOCATION); if (mLocation == null) { mLocation = getLastKnownLocation(false); } mMapFragment = SupportMapFragment.newInstance(); FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction(); fragmentTransaction.add(R.id.mapContainer, mMapFragment, "map"); fragmentTransaction.commit(); ArrayList<String> testData = new ArrayList<String>(100); for (int i = 0; i < 100; i++) { testData.add("Item " + i); } // show white bg if there are not too many items // mWhiteSpaceView.setVisibility(View.VISIBLE); // ListView approach /*mListView.addHeaderView(mTransparentHeaderView); mListView.setAdapter(new ArrayAdapter<String>(getActivity(), R.layout.simple_list_item, testData)); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mSlidingUpPanelLayout.collapsePane(); } });*/ mHeaderAdapter = new HeaderAdapter(getActivity(), testData, this); mListView.setItemAnimator(null); final LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()); layoutManager.setOrientation(LinearLayoutManager.VERTICAL); mListView.setLayoutManager(layoutManager); mListView.setAdapter(mHeaderAdapter); mGoogleApiClient = new GoogleApiClient.Builder(getActivity()) .addApi(LocationServices.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); setUpMapIfNeeded(); }