Example usage for android.app FragmentManager findFragmentById

List of usage examples for android.app FragmentManager findFragmentById

Introduction

In this page you can find the example usage for android.app FragmentManager findFragmentById.

Prototype

public abstract Fragment findFragmentById(int id);

Source Link

Document

Finds a fragment that was identified by the given id either when inflated from XML or as the container ID when added in a transaction.

Usage

From source file:com.example.zenkig.halomap.HaloMapsActivity.java

/**
 * Sets up the map if it is possible to do so (i.e., the Google Play services APK is correctly
 * installed) and the map has not already been instantiated.. This will ensure that we only ever
 * call {@link #setUpMap()} once when {@link #mMap} is not null.
 * <p/>/*from   w  ww  .  j a v  a 2 s.  c  o  m*/
 * If it isn't installed {@link SupportMapFragment} (and
 * {@link com.google.android.gms.maps.MapView MapView}) will show a prompt for the user to
 * install/update the Google Play services APK on their device.
 * <p/>
 * A user can return to this FragmentActivity after following the prompt and correctly
 * installing/updating/enabling the Google Play services. Since the FragmentActivity may not
 * have been completely destroyed during this process (it is likely that it would only be
 * stopped or paused), {@link #onCreate(Bundle)} may not be called again so we should call this
 * method in {@link #onResume()} to guarantee that it will be called.
 */
private void setUpMapIfNeeded() {
    // Do a null check to confirm that we have not already instantiated the map.
    if (mMap == null) {
        // Try to obtain the map from the SupportMapFragment.

        FragmentManager myFragmentManager = getFragmentManager();
        MapFragment myMapFragment = (MapFragment) myFragmentManager.findFragmentById(R.id.map);
        mMap = myMapFragment.getMap();

        // Check if we were successful in obtaining the map.
        if (mMap != null) {
            setUpMap();
        }
    }
}

From source file:fr.cph.chicago.activity.BusBoundActivity.java

@Override
public final void onStart() {
    super.onStart();
    FragmentManager fm = getFragmentManager();
    mMapFragment = (MapFragment) fm.findFragmentById(R.id.map);
    GoogleMapOptions options = new GoogleMapOptions();
    CameraPosition camera = new CameraPosition(NearbyFragment.CHICAGO, 7, 0, 0);
    options.camera(camera);//www. j a  va 2 s. c om
    mMapFragment = MapFragment.newInstance(options);
    mMapFragment.setRetainInstance(true);
    fm.beginTransaction().replace(R.id.map, mMapFragment).commit();
}

From source file:com.vishnuvalleru.travelweatheralertsystem.MainActivity.java

@SuppressLint("NewApi")
@Override/*from w  ww.  j a  v  a  2 s  .  c o m*/
protected void onCreate(Bundle savedInstanceState) {
    Bundle b = getIntent().getExtras();
    String fromLocation = b.getString("from");
    String toLocation = b.getString("to");
    Geocoder coder = new Geocoder(this);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    try {
        ArrayList<Address> frmAddresses = (ArrayList<Address>) coder.getFromLocationName(fromLocation, 50);
        ArrayList<Address> toAddresses = (ArrayList<Address>) coder.getFromLocationName(toLocation, 50);
        for (Address add : frmAddresses) {
            src_long = add.getLongitude();
            src_lat = add.getLatitude();
        }
        for (Address add : toAddresses) {
            dest_long = add.getLongitude();
            dest_lat = add.getLatitude();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    LatLng srcLatLng = new LatLng(src_lat, src_long);
    LatLng destLatLng = new LatLng(dest_lat, dest_long);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    FragmentManager myFragmentManager = getFragmentManager();
    MapFragment myMapFragment = (MapFragment) myFragmentManager.findFragmentById(R.id.map);

    myMap = myMapFragment.getMap();
    myMap.setInfoWindowAdapter(new PopupAdapter(getLayoutInflater()));
    myMap.setOnMapClickListener(new OnMapClickListener() {

        @Override
        public void onMapClick(LatLng point) {
            // Drawing marker on the map
            drawMarker(point);
        }
    });

    // Enabling MyLocation in Google Map
    myMap.setMyLocationEnabled(true);
    myMap.getUiSettings().setZoomControlsEnabled(true);
    myMap.getUiSettings().setCompassEnabled(true);
    myMap.getUiSettings().setMyLocationButtonEnabled(true);
    myMap.getUiSettings().setAllGesturesEnabled(true);
    myMap.setTrafficEnabled(true);
    myMap.animateCamera(CameraUpdateFactory.newLatLngZoom(destLatLng, 6));
    markerOptions = new MarkerOptions();

    drawMarker(srcLatLng);
    drawMarker(destLatLng);

    connectAsyncTask _connectAsyncTask = new connectAsyncTask();
    _connectAsyncTask.execute();
}

From source file:fr.cph.chicago.core.activity.BusMapActivity.java

@Override
public final void onStart() {
    super.onStart();
    if (mapFragment == null) {
        final FragmentManager fm = getFragmentManager();
        mapFragment = (MapFragment) fm.findFragmentById(R.id.map);
        final GoogleMapOptions options = new GoogleMapOptions();
        final CameraPosition camera = new CameraPosition(Util.CHICAGO, 10, 0, 0);
        options.camera(camera);//from w w  w  .  ja  v a  2s. c o m
        mapFragment = MapFragment.newInstance(options);
        mapFragment.setRetainInstance(true);
        fm.beginTransaction().replace(R.id.map, mapFragment).commit();
    }
}

From source file:com.artitk.licensefragment.example.MainActivity.java

@Override
public void onNavigationDrawerItemSelected(int position) {
    //        if (true) return;
    FragmentManager fragmentManager = getFragmentManager();
    Fragment fragment;//w  ww.  jav  a2 s  .  c  o m

    ArrayList<Integer> licenseIds = new ArrayList<>();
    licenseIds.add(LicenseID.GSON);
    licenseIds.add(LicenseID.RETROFIT);

    switch (position) {
    case 0:
        if (fragmentManager.findFragmentById(R.id.container) instanceof ScrollViewLicenseFragment)
            return;
        fragment = ScrollViewLicenseFragment.newInstance(licenseIds); // Call newInstance() using parameter ArrayList<Integer>
        break;
    case 1:
        if (fragmentManager.findFragmentById(R.id.container) instanceof ListViewLicenseFragment)
            return;
        fragment = ListViewLicenseFragment.newInstance(new int[] { LicenseID.PICASSO }) // Call newInstance() using parameter array
                .withLicenseChain(false); // Disable license chain
        break;
    case 2:
        if (fragmentManager.findFragmentById(R.id.container) instanceof RecyclerViewLicenseFragment)
            return;
        ArrayList<License> licenses = new ArrayList<>();
        licenses.add(new License(this, "Test Library 1", LicenseType.MIT_LICENSE, "2000-2001", "Test Owner 1"));
        licenses.add(new License(this, "Test Library 2", LicenseType.GPL_30, "2002", "Test Owner 2"));
        licenses.add(new License(this, "Test Library 3", LicenseType.EPL_10, "2003", "Test Owner 3"));
        licenses.add(new License(this, "Custom License 1", R.raw.wtfpl, "2004", "Test Owner 3"));
        licenses.add(new License(this, "Custom License 2", R.raw.x11, "2005", "Test Owner 4"));
        fragment = RecyclerViewLicenseFragment.newInstance() // Call newInstance() using without parameter
                .setLog(true) // Enable Log
                .withLicenseChain(true) // Enable license chain (default)
                .addLicense(new int[] { LicenseID.PICASSO }) // Add array (same call newInstance)
                .addLicense(licenseIds) // Add ArrayList<Integer> (same call newInstance)
                .addCustomLicense(licenses) // Add Custom License
                .setCustomUI(new CustomUI() // Set Custom UI
                        .setTitleBackgroundColor(Color.parseColor("#7fff7f"))
                        .setTitleTextColor(getResources().getColor(android.R.color.holo_green_dark))
                        .setLicenseBackgroundColor(Color.rgb(127, 223, 127)).setLicenseTextColor(Color.DKGRAY));
        break;
    default:
        return;
    }

    //        ((LicenseFragmentBase) fragment).setLog(true);

    // update the main content by replacing fragments
    fragmentManager.beginTransaction().replace(R.id.container, fragment).commit();

    fragmentId = position + 1;
}

From source file:com.slidinglayersample.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_layout);

    //        getPrefs();
    bindViews();//from   w  w  w .  j  av  a  2  s  . c  o  m
    initState();

    FragmentManager fragmentManager = getFragmentManager();
    Fragment fragment = fragmentManager.findFragmentById(R.id.content_frame);

    if (fragment == null) {
        fragment = new MainFragment();

        fragmentManager.beginTransaction().add(R.id.content_frame, fragment).commit();
    }

    Button t1 = (Button) findViewById(R.id.txtProfile);
    t1.setText(User.getCurrentUser().getName() + "\n" + User.getCurrentUser().getEmail());

}

From source file:com.thanu.schoolbustracker.RouteActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_route);

    Intent intent = getIntent();/*from ww w . j a  va2 s .c  o  m*/
    Bundle bundle = intent.getExtras();
    name = bundle.getString("uname");

    FragmentManager myFragmentManager = getFragmentManager();
    MapFragment myMapFragment = (MapFragment) myFragmentManager.findFragmentById(R.id.map);
    modifyRoute = (Button) findViewById(R.id.btnModifyRoute);

    myMap = myMapFragment.getMap();

    if (myMap != null) {

        myMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        myMap.getUiSettings().setCompassEnabled(false);
        myMap.getUiSettings().setRotateGesturesEnabled(true);
        myMap.getUiSettings().setScrollGesturesEnabled(true);
        myMap.getUiSettings().setZoomControlsEnabled(true);
        myMap.getUiSettings().setZoomGesturesEnabled(true);
        LatLng location = new LatLng(6.796923, 79.922433);
        CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(6.796923, 79.922433));
        myMap.moveCamera(center);
        CameraPosition cameraPosition = new CameraPosition.Builder().target(location) // Sets the center of the map to Mountain
                // View
                .zoom(10) // Sets the zoom
                .bearing((float) 112.5) // Sets the orientation of the
                // camera to east
                .tilt(30) // Sets the tilt of the camera to 30 degrees
                .build(); // Creates a CameraPosition from the builder
        myMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

        // Opening the sharedPreferences object
        sharedPreferences = getSharedPreferences("location", 0);

        // Getting number of locations already stored
        locationCount = sharedPreferences.getInt("locationCount", 0);

        // Getting stored zoom level if exists else return 0
        String zoom = sharedPreferences.getString("zoom", "0");

        // If locations are already saved
        if (locationCount != 0) {

            String lat = "";
            String lng = "";

            // Iterating through all the locations stored
            for (int i = 0; i < locationCount; i++) {

                // Getting the latitude of the i-th location
                lat = sharedPreferences.getString("lat" + i, "0");

                // Getting the longitude of the i-th location
                lng = sharedPreferences.getString("lng" + i, "0");

                // Drawing marker on the map
                drawMarker(new LatLng(Double.parseDouble(lat), Double.parseDouble(lng)));
            }

            // Moving CameraPosition to last clicked position
            myMap.moveCamera(CameraUpdateFactory
                    .newLatLng(new LatLng(Double.parseDouble(lat), Double.parseDouble(lng))));

            // Setting the zoom level in the map on last position is clicked
            myMap.animateCamera(CameraUpdateFactory.zoomTo(Float.parseFloat(zoom)));
        }

        modifyRoute.setOnClickListener(this);
        myMap.setOnMapClickListener(this);
        myMap.setOnMapLongClickListener(this);
        myMap.setOnMarkerClickListener(this);
    }

    markerClicked = false;

    if (name.equalsIgnoreCase("Admin")) {
        modifyRoute.setEnabled(true);
    }
}

From source file:it.gmariotti.cardslib.demo.extras.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.demo_extras_activity_main);

    // The attacher should always be created in the Activity's onCreate
    //mPullToRefreshAttacher = PullToRefreshAttacher.get(this);

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout_extras);

    mDrawer.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    _initMenu();// w w w.  ja v  a 2s .c  om
    mDrawerToggle = new CustomActionBarDrawerToggle(this, mDrawer);
    mDrawer.setDrawerListener(mDrawerToggle);

    // ---------------------------------------------------------------
    // ...
    String base64EncodedPublicKey = IabUtil.key;

    // compute your public key and store it in base64EncodedPublicKey
    mHelper = new IabHelper(this, base64EncodedPublicKey);
    mHelper.enableDebugLogging(true);

    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        public void onIabSetupFinished(IabResult result) {
            if (!result.isSuccess()) {
                // Oh noes, there was a problem.
                Log.d(TAG, "Problem setting up In-app Billing: " + result);
            }

            // Have we been disposed of in the meantime? If so, quit.
            if (mHelper == null)
                return;

            // Hooray, IAB is fully set up!
            IabUtil.getInstance().retrieveData(mHelper);
        }
    });
    //-----------------------------------------------------------------
    //BaseFragment baseFragment = null;
    if (savedInstanceState != null) {
        mSelectedFragment = savedInstanceState.getInt(BUNDLE_SELECTEDFRAGMENT);

        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        if (fragmentManager.findFragmentById(R.id.fragment_main_extras) == null)
            mBaseFragment = selectFragment(mSelectedFragment);
        //if (mBaseFragment==null)
        //    mBaseFragment = selectFragment(mSelectedFragment);
    } else {
        mBaseFragment = new PicassoFragment();
        openFragment(mBaseFragment);
    }

    //-----------------------------------------------------------------
}

From source file:com.richtodd.android.quiltdesign.app.QuiltEditActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_quilt_edit);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    m_quiltNameArgument = getIntent().getStringExtra(ARG_QUILT_NAME);

    if (savedInstanceState != null) {
        m_saveAsQuiltName = savedInstanceState.getString("saveAsQuiltName");
    }/* w  w  w.  ja  v a2s .com*/

    ActionBar ab = getActionBar();
    ab.setTitle("Edit Quilt");
    ab.setSubtitle(getCurrentQuiltName());

    FragmentManager fm = getFragmentManager();

    // Create color settings fragment.
    {
        Fragment fragment = fm.findFragmentById(R.id.layout_quiltEditFragment);
        if (fragment == null) {
            fragment = QuiltEditFragment.create(m_quiltNameArgument);
            fm.beginTransaction().add(R.id.layout_quiltEditFragment, fragment).commit();
        }
    }

    m_layout_blocks = (NestedLinearLayout) findViewById(R.id.layout_blocks);

    populateLayoutBlocks();
}

From source file:com.notriddle.budget.EnvelopesActivity.java

@Override
public void onBackPressed() {
    FragmentManager fragmentManager = getFragmentManager();
    if (mDrawerLayout.isDrawerOpen(mNavDrawer)) {
        mDrawerLayout.closeDrawers();//from   ww w . ja  v a  2 s.c o m
    } else if (fragmentManager.getBackStackEntryCount() != 0) {
        fragmentManager.popBackStackImmediate();
        configureFragment(fragmentManager.findFragmentById(R.id.content_frame));
    } else {
        super.onBackPressed();
    }
}