List of usage examples for android.support.v4.app FragmentManager findFragmentById
public abstract Fragment findFragmentById(int id);
From source file:com.hro.museapp.map.ClusteringMapActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.cluster_map); listType = getIntent().getIntExtra("type", TYPE_ALL); ActionBar actionBar = getActionBar(); actionBar.setHomeButtonEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); FragmentManager fm = getSupportFragmentManager(); SupportMapFragment f = (SupportMapFragment) fm.findFragmentById(R.id.map); map = f.getExtendedMap();//from www . j a v a 2 s .co m gps = new GPSTracker(ClusteringMapActivity.this); //gps = PlacesLoader.getGPS(); // mapView = (MapView) this.findViewById(R.id.map); float cameraZoom = 8; LatLng cameraLatLng = new LatLng(52.281602, 5.503235); if (savedInstanceState != null) { double savedLat = savedInstanceState.getDouble("lat"); double savedLng = savedInstanceState.getDouble("lng"); cameraLatLng = new LatLng(savedLat, savedLng); cameraZoom = savedInstanceState.getFloat("zoom", 12); } map.moveCamera(CameraUpdateFactory.newLatLngZoom(cameraLatLng, cameraZoom)); map.setClustering(new ClusteringSettings().iconDataProvider(new DemoIconProvider(getResources())) .addMarkersDynamically(true)); map.setMyLocationEnabled(true); map.setInfoWindowAdapter(new InfoWindowAdapter() { private TextView tv; { tv = new TextView(ClusteringMapActivity.this); tv.setTextColor(Color.BLACK); } private Collator collator = Collator.getInstance(); private Comparator<Marker> comparator = new Comparator<Marker>() { public int compare(Marker lhs, Marker rhs) { String leftTitle = lhs.getTitle(); String rightTitle = rhs.getTitle(); if (leftTitle == null && rightTitle == null) { return 0; } if (leftTitle == null) { return 1; } if (rightTitle == null) { return -1; } return collator.compare(leftTitle, rightTitle); } }; @Override public View getInfoWindow(Marker marker) { return null; } @Override public View getInfoContents(Marker marker) { if (marker.isCluster()) { List<Marker> markers = marker.getMarkers(); int i = 0; String text = ""; while (i < 3 && markers.size() > 0) { Marker m = Collections.min(markers, comparator); String title = m.getTitle(); if (title == null) { break; } text += title + "\n"; markers.remove(m); i++; } if (text.length() == 0) { text = "Markers with mutable data"; } else if (markers.size() > 0) { text += "and " + markers.size() + " more..."; } else { text = text.substring(0, text.length() - 1); } tv.setText(text); return tv; } else { String title = marker.getTitle(); tv.setText(title); return tv; } } }); map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() { @Override public void onInfoWindowClick(Marker marker) { if (marker.isCluster()) { List<Marker> markers = marker.getMarkers(); Builder builder = LatLngBounds.builder(); for (Marker m : markers) { builder.include(m.getPosition()); } LatLngBounds bounds = builder.build(); map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, getResources().getDimensionPixelSize(R.dimen.padding))); } else { // String title = marker.getTitle(); // String mid = MarkerGenerator.mapPlaceToId.get(title); String mid = (String) marker.getData(); Intent in = new Intent(getApplicationContext(), ShowPlaceActivity.class); // sending mid to next activity in.putExtra(MarkerGenerator.TAG_MID, mid); // starting new activity and expecting some response back startActivityForResult(in, 100); } } }); // MarkerGenerator.addMarkers(map); new AddMarkersInBackground().execute(); }
From source file:com.github.kanata3249.ffxieq.android.EquipmentSetEditActivity.java
/** Called when the activity is first created. */ @Override//from www . j a v a 2 s .c om public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.equipmentseteditactivity); notifyDatasetChanged(); FragmentManager fm = getSupportFragmentManager(); FFXIEQFragment.OnDatasetChangedListener listener = new FFXIEQFragment.OnDatasetChangedListener() { @Override public void notifyDatasetChanged() { EquipmentSetEditActivity.this.notifyDatasetChanged(); } }; { EquipmentSetEditFragment fragment = (EquipmentSetEditFragment) fm.findFragmentById(R.id.CharacterEdit); if (fragment != null) fragment.setOnDatasetChangedListener(listener); } { MagicSetEditFragment fragment = (MagicSetEditFragment) fm.findFragmentById(R.id.MagicEdit); if (fragment != null) fragment.setOnDatasetChangedListener(listener); } { CharacterStatusFragment fragment = (CharacterStatusFragment) fm.findFragmentById(R.id.CharacterStatus); if (fragment != null) fragment.setOnDatasetChangedListener(listener); } { BasicEditFragment fragment = (BasicEditFragment) fm.findFragmentById(R.id.BasicEdit); if (fragment != null) fragment.setOnDatasetChangedListener(listener); } }
From source file:com.facebook.samples.hellofacebook.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); if (savedInstanceState != null) { String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY); pendingAction = PendingAction.valueOf(name); }/*from w w w. j av a2 s . c o m*/ setContentView(R.layout.main); loginButton = (LoginButton) findViewById(R.id.login_button); loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() { @Override public void onUserInfoFetched(GraphUser user) { MainActivity.this.user = user; updateUI(); // It's possible that we were waiting for this.user to be populated in order to post a // status update. handlePendingAction(); } }); profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture); greeting = (TextView) findViewById(R.id.greeting); postStatusUpdateButton = (Button) findViewById(R.id.postStatusUpdateButton); postStatusUpdateButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickPostStatusUpdate(); } }); postPhotoButton = (Button) findViewById(R.id.postPhotoButton); postPhotoButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickPostPhoto(); } }); pickFriendsButton = (Button) findViewById(R.id.pickFriendsButton); pickFriendsButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickPickFriends(); } }); pickPlaceButton = (Button) findViewById(R.id.pickPlaceButton); pickPlaceButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickPickPlace(); } }); controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container); final FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.fragment_container); if (fragment != null) { // If we're being re-created and have a fragment, we need to a) hide the main UI controls and // b) hook up its listeners again. controlsContainer.setVisibility(View.GONE); if (fragment instanceof FriendPickerFragment) { setFriendPickerListeners((FriendPickerFragment) fragment); } else if (fragment instanceof PlacePickerFragment) { setPlacePickerListeners((PlacePickerFragment) fragment); } } // Listen for changes in the back stack so we know if a fragment got popped off because the user // clicked the back button. fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() { @Override public void onBackStackChanged() { if (fm.getBackStackEntryCount() == 0) { // We need to re-show our UI. controlsContainer.setVisibility(View.VISIBLE); } } }); }
From source file:com.google.android.apps.santatracker.presentquest.ProfileActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_profile); // [ANALYTICS] mAnalytics = FirebaseAnalytics.getInstance(this); MeasurementManager.recordScreenView(mAnalytics, getString(R.string.analytics_screen_pq_profile)); // Config//from w w w .j a va2 s. c om mConfig = new Config(); // Get the current user mUser = User.get(); // Preferences mPrefs = new PreferencesUtil(this); mAvatarView = (ImageView) findViewById(R.id.profile_user_image); mLevelTextView = (TextView) findViewById(R.id.text_current_level); // Make text santa-style FontHelper.makeLobster((TextView) findViewById(R.id.text_workshops), false); // Set up lock text ((TextView) findViewById(R.id.workshop_2_lock_text)) .setText(getString(R.string.unlock_at_level, User.WORKSHOP_2_LEVEL)); ((TextView) findViewById(R.id.workshop_3_lock_text)) .setText(getString(R.string.unlock_at_level, User.WORKSHOP_3_LEVEL)); // Get position passed in if (getIntent() != null && getIntent().getParcelableExtra(EXTRA_LAST_LOCATION) != null) { mLatLng = getIntent().getParcelableExtra(EXTRA_LAST_LOCATION); } // Click listeners mAvatarView.setOnClickListener(this); findViewById(R.id.button_edit_1).setOnClickListener(this); findViewById(R.id.button_edit_2).setOnClickListener(this); findViewById(R.id.button_edit_3).setOnClickListener(this); findViewById(R.id.arrow_left).setOnClickListener(this); findViewById(R.id.arrow_right).setOnClickListener(this); // Get map fragments FragmentManager fm = getSupportFragmentManager(); mMaps[0] = (SupportMapFragment) fm.findFragmentById(R.id.map_workshop_1); mMaps[1] = (SupportMapFragment) fm.findFragmentById(R.id.map_workshop_2); mMaps[2] = (SupportMapFragment) fm.findFragmentById(R.id.map_workshop_3); // Load workshops loadWorkshops(); // Load map fragments for (int i = 0; i < MAX_WORKSHOPS; i++) { mListeners[i] = new WorkshopMapListener(this, mWorkshops[i]); mMaps[i].getMapAsync(mListeners[i]); } setUserProgress(); }
From source file:com.licenta.android.licenseapp.location.MapFragment.java
@Nullable @Override/*w w w . j a v a2s . c o m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_maps, container, false); FragmentManager fragmentManager = getChildFragmentManager(); // Obtain the SupportMapFragment and get notified when the map is ready to be used. mSupportMapFragment = (SupportMapFragment) fragmentManager.findFragmentById(R.id.map_container); if (mSupportMapFragment == null) { FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); mSupportMapFragment = SupportMapFragment.newInstance(); fragmentTransaction.replace(R.id.map_container, mSupportMapFragment).commit(); } mSupportMapFragment.getMapAsync(this); Button eventBtn = (Button) view.findViewById(R.id.event_btn); eventBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getGeofencesList(); } }); Button showBtn = (Button) view.findViewById(R.id.show_btn); showBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onShow(v); } }); Button clearBtn = (Button) view.findViewById(R.id.clear_btn); clearBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onClear(v); } }); // Create an instance of GoogleAPIClient. if (mGoogleApiClient == null) { mGoogleApiClient = new GoogleApiClient.Builder(getActivity()).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).addApi(LocationServices.API).build(); } return view; }
From source file:com.rubika.aotalk.recipebook.FragmentActivityRecipes.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //super.setTheme(R.style.Theme_AOTalkTheme_Light); FragmentManager fm = getSupportFragmentManager(); if (fm.findFragmentById(android.R.id.content) == null) { fm.beginTransaction().add(android.R.id.content, DataListFragment.newInstance(null)).commit(); }/*from ww w .j av a2 s.co m*/ }
From source file:com.murrayc.galaxyzoo.app.ClassifyFragment.java
private void addOrUpdateChildFragments() { showLoadingInProgress(false);/*from w ww . j a v a 2 s . c om*/ final Bundle arguments = new Bundle(); //TODO? arguments.putString(ARG_USER_ID, // getUserId()); //Obtained in the super class. arguments.putString(ItemFragment.ARG_ITEM_ID, getItemId()); //Add, or update, the nested child fragments. //This can only be done programmatically, not in the layout XML. //See http://developer.android.com/about/versions/android-4.2.html#NestedFragments final FragmentManager fragmentManager = getChildFragmentManager(); SubjectFragment fragmentSubject = (SubjectFragment) fragmentManager .findFragmentById(R.id.child_fragment_subject); if (fragmentSubject == null) { fragmentSubject = new SubjectFragment(); fragmentSubject.setArguments(arguments); fragmentManager.beginTransaction().replace(R.id.child_fragment_subject, fragmentSubject).commit(); } else { //TODO: Is there some more standard method to do this, //to trigger the Fragments' onCreate()? fragmentSubject.setItemId(getItemId()); //We don't wipe the inverted state (setInverted()) because this can happen after rotation, //not just when starting a new classification. fragmentSubject.update(); } QuestionFragment fragmentQuestion = (QuestionFragment) fragmentManager .findFragmentById(R.id.child_fragment_question); if (fragmentQuestion == null) { fragmentQuestion = new QuestionFragment(); fragmentQuestion.setArguments(arguments); fragmentManager.beginTransaction().replace(R.id.child_fragment_question, fragmentQuestion).commit(); } else { //TODO: Is there some more standard method to do this, //to trigger the Fragments' onCreate()? fragmentQuestion.setGroupId(null); //Avoid any chance of us using the wrong groups's decision tree. fragmentQuestion.setItemId(getItemId()); //This will trigger a later UI update of the fragment. } }
From source file:com.oneteam.framework.android.ui.impl.fragment.AbstractMapFragment.java
/** * @param savedInstanceState/*from www. ja va 2 s . c o m*/ */ protected void showMap() { showProgress(); FragmentManager fmanager = getFragmentManager(); Fragment fragment = fmanager.findFragmentById(mMapFragmentId); SupportMapFragment supportMapfragment = (SupportMapFragment) fragment; mGoogleMap = supportMapfragment.getMap(); mGoogleMap.getUiSettings().setCompassEnabled(true); mGoogleMap.setMyLocationEnabled(true); mGoogleMap.getUiSettings().setMyLocationButtonEnabled(true); MapInfoWindowAdapter infoWindowAdapter = new MapInfoWindowAdapter(mInflater, this); mGoogleMap.setInfoWindowAdapter(infoWindowAdapter); if (mMarkerClickableEnabled) { mGoogleMap.setOnInfoWindowClickListener(this); } if (mCurrentLocation != null) { mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mCurrentLocation, 15)); mGoogleMap.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null); } hideProgress(); }
From source file:com.jana.android.ui.fragment.AbstractMapFragment.java
protected void showMap() { showProgress();/*from www . j ava 2 s . c o m*/ FragmentManager fmanager = getFragmentManager(); Fragment fragment = fmanager.findFragmentById(mMapFragmentId); if (fragment == null) { Logger.e("No fragment is set for holding Map"); return; } SupportMapFragment supportMapfragment = (SupportMapFragment) fragment; mGoogleMap = supportMapfragment.getMap(); mGoogleMap.getUiSettings().setCompassEnabled(true); mGoogleMap.setMyLocationEnabled(true); mGoogleMap.getUiSettings().setMyLocationButtonEnabled(true); MapInfoWindowAdapter infoWindowAdapter = new MapInfoWindowAdapter(mInflater, this); mGoogleMap.setInfoWindowAdapter(infoWindowAdapter); if (mMarkerClickableEnabled) { mGoogleMap.setOnInfoWindowClickListener(this); } if (mCurrentLocation != null) { mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mCurrentLocation, 15)); mGoogleMap.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null); } hideProgress(); }
From source file:com.actionbarsherlock.sample.demos.app.LoaderCustomSupport.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FragmentManager fm = getSupportFragmentManager(); // Create the list fragment and add it as our sole content. if (fm.findFragmentById(android.R.id.content) == null) { AppListFragment list = new AppListFragment(); fm.beginTransaction().add(android.R.id.content, list).commit(); }// www . j av a 2 s .co m }