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.orbar.pxdemo.MainActivity.java

@Override
public void onBackPressed() {
    FragmentManager fragmentManager = getFragmentManager();

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

    if (fragment != null && fragment instanceof BackPressedListener) {
        if (((BackPressedListener) fragment).onBackPressed()) {
            super.onBackPressed();
        }/*from w  w  w  .j a va2 s  . c om*/
    } else {
        super.onBackPressed();
    }

}

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

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

    m_blockNameArgument = getIntent().getStringExtra(ARG_BLOCK_NAME);

    if (savedInstanceState != null) {
        m_saveAsBlockName = savedInstanceState.getString("saveAsBlockName");
        m_theme = (Theme) savedInstanceState.getParcelable("theme");
    }/*from  w  w w.  j  a  v  a  2s  .  co  m*/

    ActionBar ab = getActionBar();
    ab.setTitle("Edit Block");
    ab.setSubtitle(getCurrentBlockName());

    FragmentManager fm = getFragmentManager();

    // Create color settings fragment.
    {
        Fragment f = fm.findFragmentById(R.id.layout_blockEditFragment);
        if (f == null) {
            f = BlockEditFragment.create(m_blockNameArgument);
            fm.beginTransaction().add(R.id.layout_blockEditFragment, f).commit();
        }
    }

    m_themeView = (ThemeView) findViewById(R.id.themeView);
    m_themeView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Swatch swatch = (Swatch) m_themeView.getItemAtPosition(position);
            BlockEditFragment fragment = getBlockEditFragment();
            if (fragment != null) {
                fragment.setColor(swatch.getColor());
            }

        }
    });
    m_themeView.setTheme(m_theme);

    m_button_setColor = (Button) findViewById(R.id.button_setColor);
    m_button_setColor.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            chooseColor();
        }
    });

    m_button_addPiece = (Button) findViewById(R.id.button_addPiece);
    m_button_addPiece.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            BlockEditFragment fragment = getBlockEditFragment();
            int color = fragment.getColor();
            PaperPiecedBlockPiece piece = fragment.addPiece(color);
            onPieceSelected(fragment, piece);
        }
    });

    m_button_deletePiece = (Button) findViewById(R.id.button_deletePiece);
    m_button_deletePiece.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            BlockEditFragment fragment = getBlockEditFragment();
            fragment.deletePiece();
            onPieceSelected(fragment, null);
        }
    });

    ImageView button_refreshTheme = (ImageView) findViewById(R.id.button_refreshTheme);
    button_refreshTheme.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            refreshTheme();
        }
    });

    ImageView button_selectTheme = (ImageView) findViewById(R.id.button_selectTheme);
    button_selectTheme.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            chooseTheme();
        }
    });
}

From source file:me.raatiniemi.worker.presentation.settings.view.SettingsActivity.java

@Override
public void onBackPressed() {
    FragmentManager fragmentManager = getFragmentManager();

    // Depending on which fragment is contained within the
    // container, the back button will behave differently.
    Fragment fragment = fragmentManager.findFragmentById(R.id.fragment_container);
    Class<SettingsFragment> settings = SettingsFragment.class;
    if (!settings.equals(fragment.getClass())) {
        fragmentManager.popBackStack();//  w  w  w.  j a  v a2  s  . c o  m
    } else {
        super.onBackPressed();
    }
}

From source file:com.eutectoid.dosomething.PickerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pickers);//from  ww  w  . j a  v  a  2s  .  c  o m

    Bundle args = getIntent().getExtras();
    FragmentManager manager = getFragmentManager();
    Fragment fragmentToShow = null;
    Uri intentUri = getIntent().getData();

    if (FRIEND_PICKER.equals(intentUri)) {
        if (savedInstanceState == null) {
            friendPickerFragment = new FriendPickerFragment();
            friendPickerFragment.setSettingsFromBundle(args);
            friendPickerFragment.setFriendPickerType(FriendPickerFragment.FriendPickerType.TAGGABLE_FRIENDS);
        } else {
            friendPickerFragment = (FriendPickerFragment) manager.findFragmentById(R.id.picker_fragment);
            ;
        }

        friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
            @Override
            public void onError(PickerFragment fragment, FacebookException error) {
                PickerActivity.this.onError(error);
            }
        });
        friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {
            @Override
            public void onDoneButtonClicked(PickerFragment fragment) {
                finishActivity();
            }
        });
        fragmentToShow = friendPickerFragment;

    } else if (PLACE_PICKER.equals(intentUri)) {
        if (savedInstanceState == null) {
            placePickerFragment = new PlacePickerFragment();
            placePickerFragment.setSettingsFromBundle(args);
        } else {
            placePickerFragment = (PlacePickerFragment) manager.findFragmentById(R.id.picker_fragment);
        }
        placePickerFragment.setOnSelectionChangedListener(new PickerFragment.OnSelectionChangedListener() {
            @Override
            public void onSelectionChanged(PickerFragment fragment) {
                finishActivity(); // call finish since you can only pick one place
            }
        });
        placePickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
            @Override
            public void onError(PickerFragment fragment, FacebookException error) {
                PickerActivity.this.onError(error);
            }
        });
        placePickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {
            @Override
            public void onDoneButtonClicked(PickerFragment fragment) {
                finishActivity();
            }
        });
        fragmentToShow = placePickerFragment;
    } else {
        // Nothing to do, finish
        setResult(RESULT_CANCELED);
        finish();
        return;
    }

    manager.beginTransaction().replace(R.id.picker_fragment, fragmentToShow).commit();
}

From source file:systems.soapbox.ombuds.client.ui.NetworkMonitorActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.network_monitor_content);
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    super.setAnimateOnPause(true);

    final ViewPager pager = (ViewPager) findViewById(R.id.network_monitor_pager);

    final FragmentManager fm = getFragmentManager();

    if (pager != null) {
        final ViewPagerTabs pagerTabs = (ViewPagerTabs) findViewById(R.id.network_monitor_pager_tabs);
        pagerTabs.addTabLabels(R.string.network_monitor_peer_list_title,
                R.string.network_monitor_block_list_title);

        final PagerAdapter pagerAdapter = new PagerAdapter(fm);

        pager.setAdapter(pagerAdapter);//from ww  w.j a v  a  2s .  c o m
        pager.setOnPageChangeListener(pagerTabs);
        pager.setPageMargin(2);
        pager.setPageMarginDrawable(R.color.bg_less_bright);

        peerListFragment = new PeerListFragment();
        blockListFragment = new BlockListFragment();
    } else {
        peerListFragment = (PeerListFragment) fm.findFragmentById(R.id.peer_list_fragment);
        blockListFragment = (BlockListFragment) fm.findFragmentById(R.id.block_list_fragment);
    }
}

From source file:metrocasas.projectsgt.MainActivity.java

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();/*from   w w w.j  a  v a2s.c om*/
        mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
            @Override
            public void onCameraChange(CameraPosition cameraPosition) {
                q.setEnabled(false);
            }
        });
        mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
            @Override
            public void onMapClick(LatLng latLng) {
                q.setEnabled(true);
            }
        });
        if (ContextCompat.checkSelfPermission(this,
                android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            mMap.setMyLocationEnabled(true);
            mMap.getUiSettings().setZoomControlsEnabled(true);
        }
        // Check if we were successful in obtaining the map.
        if (mMap != null) {
            setUpMap();
        }
    }
}

From source file:biz.wiz.android.wallet.ui.NetworkMonitorActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.network_monitor_content);

    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    final ViewPager pager = (ViewPager) findViewById(R.id.network_monitor_pager);

    final FragmentManager fm = getFragmentManager();

    if (pager != null) {
        final ViewPagerTabs pagerTabs = (ViewPagerTabs) findViewById(R.id.network_monitor_pager_tabs);
        pagerTabs.addTabLabels(R.string.network_monitor_peer_list_title,
                R.string.network_monitor_block_list_title);

        final PagerAdapter pagerAdapter = new PagerAdapter(fm);

        pager.setAdapter(pagerAdapter);// w w w. j a va 2 s.  c  om
        pager.setOnPageChangeListener(pagerTabs);
        pager.setPageMargin(2);
        pager.setPageMarginDrawable(R.color.bg_less_bright);

        peerListFragment = new PeerListFragment();
        blockListFragment = new BlockListFragment();
    } else {
        peerListFragment = (PeerListFragment) fm.findFragmentById(R.id.peer_list_fragment);
        blockListFragment = (BlockListFragment) fm.findFragmentById(R.id.block_list_fragment);
    }
}

From source file:com.jforce.chapelhillnextbus.HomeActivity.java

public void mapFabClick(View view) {

    FragmentManager fragmentManager = getFragmentManager();

    MapFragment fragment = (MapFragment) fragmentManager.findFragmentById(R.id.content_frame);

    fragment.fabClick();/*from   ww  w .ja  v a  2  s. c  om*/

}

From source file:com.jforce.chapelhillnextbus.HomeActivity.java

public void mapBackFromRoutes(View view) {

    FragmentManager fragmentManager = getFragmentManager();

    MapFragment fragment = (MapFragment) fragmentManager.findFragmentById(R.id.content_frame);

    fragment.backFromRoutes();//from  w w w  .  j av  a  2s .  c  o  m

}

From source file:com.jforce.chapelhillnextbus.HomeActivity.java

public void onRefresh() {

    new Handler().postDelayed(new Runnable() {
        @Override// w w  w . j  a v a2 s.  co m
        public void run() {

            FragmentManager fm = getFragmentManager();
            Fragment ofragment = fm.findFragmentById(R.id.content_frame);

            PredictionsFragment fragment = (PredictionsFragment) ofragment;

            int navLevel = fragment.getNavigationLevel();

            if (navLevel == fragment.LEVEL_DIRECTION) {
                fragment.directionClick();
            } else if (navLevel == fragment.LEVEL_STOP) {
                fragment.stopClick();
            } else if (navLevel == fragment.LEVEL_PREDICTION) {
                fragment.cancelRefresh();
                fragment.scheduleRefresh();
            } else {

                fragment.routeClick();

            }

            SwipeRefreshLayout swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
            swipeLayout.setRefreshing(false);

        }
    }, 1500);

}