Created
March 4, 2013 21:10
-
-
Save theSociableme/5085700 to your computer and use it in GitHub Desktop.
MapsFragment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created with IntelliJ IDEA. | |
* | |
* @author Mark Wagner | |
* Date: 2/28/13 | |
* Time: 10:08 AM | |
*/ | |
public class MapsFragment extends SherlockFragment { | |
Button mHotelMapButton; | |
Button mExhibitorButton; | |
GoogleMapFragment mGoogleMapFragment; | |
ScaleImageViewFragment mScaleImageViewFragment; | |
static boolean mShowingGoogleMap = true; | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
if (savedInstanceState != null) { | |
mShowingGoogleMap = savedInstanceState.getBoolean("showingGoogleMap"); | |
} | |
mGoogleMapFragment = new GoogleMapFragment(); | |
mScaleImageViewFragment = new ScaleImageViewFragment(); | |
} | |
@Override | |
public void onSaveInstanceState(Bundle outState) { | |
super.onSaveInstanceState(outState); | |
outState.putBoolean("showingGoogleMap", mShowingGoogleMap); | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
View view = inflater.inflate(R.layout.maps_fragment, null); | |
mHotelMapButton = (Button) view.findViewById(R.id.hotel_button); | |
mExhibitorButton = (Button) view.findViewById(R.id.exhititor_map_button); | |
mExhibitorButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
mShowingGoogleMap = false; | |
showExhibitorFragment(); | |
} | |
}); | |
mHotelMapButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
mShowingGoogleMap = true; | |
showGoogleMapFragment(); | |
} | |
}); | |
return view; | |
} | |
@Override | |
public void onPause() { | |
super.onPause(); | |
getChildFragmentManager().beginTransaction() | |
.remove(mGoogleMapFragment) | |
.remove(mScaleImageViewFragment).commit(); | |
} | |
@Override | |
public void onResume() { | |
super.onResume(); | |
if(mShowingGoogleMap){ | |
showGoogleMapFragment(); | |
}else{ | |
showExhibitorFragment(); | |
} | |
} | |
private void showExhibitorFragment(){ | |
getChildFragmentManager().beginTransaction() | |
.replace(R.id.fragment_placeholder, mScaleImageViewFragment, "scaleImage") | |
.commit(); | |
} | |
private void showGoogleMapFragment(){ | |
getChildFragmentManager().beginTransaction() | |
.replace(R.id.fragment_placeholder, mGoogleMapFragment, "mapFragment") | |
.commit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment