Example usage for android.support.v4.app FragmentManager findFragmentById

List of usage examples for android.support.v4.app FragmentManager findFragmentById

Introduction

In this page you can find the example usage for android.support.v4.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.eleybourn.bookcatalogue.filechooser.FileChooser.java

/**
 * Initialize this activity// www. jav  a 2 s.  c o  m
 */
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.setContentView(R.layout.file_chooser_base);

    // Determine the dialog type
    Bundle extras = getIntent().getExtras();
    if (extras == null) {
        mIsSaveDialog = false;
    } else {
        String mode = extras.getString(EXTRA_MODE);
        if (mode == null)
            mIsSaveDialog = false;
        else
            mIsSaveDialog = mode.equals(EXTRA_MODE_SAVE_AS);
    }

    // Get and display the fragment
    FragmentManager fragmentManager = getSupportFragmentManager();
    if (findViewById(R.id.browser_fragment) != null
            && fragmentManager.findFragmentById(R.id.browser_fragment) == null) {
        // Create the browser
        FileChooserFragment frag = getChooserFragment();
        // frag.setArguments(getIntent().getExtras());
        getSupportFragmentManager().beginTransaction().replace(R.id.browser_fragment, frag).commit();
    }

    // Handle 'Cancel' button
    findViewById(R.id.cancel).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });

    // Handle Open/Save button
    Button confirm = (Button) findViewById(R.id.confirm);

    if (mIsSaveDialog) {
        confirm.setText(R.string.save);
        confirm.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                handleSave();
            }
        });

    } else {
        confirm.setText(R.string.open);
        confirm.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                handleOpen();
            }
        });
    }

}

From source file:com.pseudosudostudios.jdd.activities.WinActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_win);
    printFacebookInfo();//ww  w.j  a va  2s.  co m

    FragmentManager fm = getSupportFragmentManager();
    fragment = (ScoreFragment) fm.findFragmentById(R.id.scoreFragment);

    fragment.setDisplays(getIntent().getExtras());
}

From source file:io.soramitsu.iroha.view.activity.MainActivity.java

private void initBottomNavigationView() {
    binding.bottomNavigation.setOnNavigationItemSelectedListener(item -> {
        allClearNavigationMenuChecked();
        if (!item.isChecked()) {
            binding.navigation.getMenu().getItem(0).setChecked(true);
            switch (item.getItemId()) {
            case R.id.action_receipt:
                Log.d(TAG, "onNavigationItemSelected: Receiver");
                binding.toolbar.setTitle(getString(R.string.receive));
                switchFragment(assetReceiveFragment, AssetReceiveFragment.TAG);
                break;
            case R.id.action_wallet:
                Log.d(TAG, "onNavigationItemSelected: Wallet");
                binding.toolbar.setTitle(getString(R.string.wallet));
                switchFragment(walletFragment, WalletFragment.TAG);
                break;
            case R.id.action_sender:
                Log.d(TAG, "onNavigationItemSelected: Sender");
                binding.toolbar.setTitle(getString(R.string.send));
                switchFragment(assetSenderFragment, AssetSenderFragment.TAG);
                break;
            }/*from  w  w  w .j a  va  2 s .c  o m*/
        } else {
            Log.d(TAG, "onNavigationItemSelected: Top?!");
            final FragmentManager manager = getSupportFragmentManager();
            final Fragment fragment = manager.findFragmentById(R.id.container);
            if (fragment instanceof MainActivityListener) {
                ((MainActivityListener) fragment).onNavigationItemClicked();
            }
        }
        return true;
    });
}

From source file:com.bangz.shotrecorder.RecordDetailActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.record_detail);

    final Intent intent = getIntent();

    final String action = intent.getAction();

    if (Intent.ACTION_EDIT.equals(action)) {

        mUri = intent.getData();/* w  w w .  j av  a 2  s.c o m*/

    } else {
        Log.e(TAG, "Unknown Action, exiting");
        finish();
        return;
    }

    ActionBar bar = getSupportActionBar();
    bar.setDisplayHomeAsUpEnabled(true);

    ImageView imageView = (ImageView) findViewById(R.id.imgEditDescript);
    imageView.setOnClickListener(this);

    FragmentManager fm = getSupportFragmentManager();
    SplitListFragment splitfragment = (SplitListFragment) fm.findFragmentById(R.id.splitlist);
    mSplitAdapter = new SplitArrayAdapter(this, mManager.getSplits());
    splitfragment.setListAdapter(mSplitAdapter);

    LoaderManager lm = getSupportLoaderManager();
    lm.initLoader(1, null, this);
}

From source file:com.swetha.easypark.GoogleDirectionsActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mapdirections);
    StrictMode.setThreadPolicy(//from w  w  w  .  j a  va2  s  .  c  o m
            new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork() // StrictMode is most commonly used to catch accidental disk or network access on the application's main thread
                    .penaltyLog().build());
    Log.i("GoogleDirectionsActivity", "Inside Oncreate");

    Intent theIntent = getIntent();
    tolat = theIntent.getDoubleExtra(GetParkingLots.LATITUDE, Constants.doubleDefaultValue);
    tolng = theIntent.getDoubleExtra(GetParkingLots.LONGITUDE, Constants.doubleDefaultValue);

    toPosition = new LatLng(tolat, tolng);

    Log.i("GoogleDirectionsActivity",
            "After Setting tolat, tolng, toPosition" + tolat + "\n" + tolng + "\n" + toPosition);

    md = new GetDirections();
    Log.i("GoogleDirectionsActivity", "After calling GetDirctions constructor");

    FragmentManager fm = getSupportFragmentManager();
    Log.i("GoogleDirectionsActivity", "After creating fragmentManager" + fm);
    SupportMapFragment supportMapfragment = ((SupportMapFragment) fm.findFragmentById(R.id.drivingdirections));

    Log.i("GoogleDirectionsActivity", "After creating SupportMapFragment" + supportMapfragment);
    mMap = supportMapfragment.getMap();
    Log.i("GoogleDirectionsActivity", "After getting map");

    mMap.setMyLocationEnabled(true);
    Log.i("GoogleDirectionsActivity", "After  setMyLocationEnabled");
    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    Log.i("GoogleDirectionsActivity", "After  locationManager");
    Criteria criteria = new Criteria();

    // Getting the name of the provider that meets the criteria
    provider = locationManager.getBestProvider(criteria, true);

    if (provider != null && !provider.equals("")) {

        // Get the location from the given provider 
        location = locationManager.getLastKnownLocation(provider);

        locationManager.requestLocationUpdates(provider, 500, 1, GoogleDirectionsActivity.this);

        if (location != null) {

            fromlat = location.getLatitude();
            fromlng = location.getLongitude();
        }

        else {
            fromlat = GetParkingLots.latitude;
            fromlng = GetParkingLots.longitude;
        }

    } else {
        Toast.makeText(getBaseContext(), "No Provider Found", Toast.LENGTH_SHORT).show();
        finish();
    }
    Log.e("GoogleDirectionsActivity", "After  setting location");
    fromPosition = new LatLng(fromlat, fromlng);
    LatLng coordinates = new LatLng(fromlat, fromlng);
    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(coordinates, 16));

    mMap.addMarker(new MarkerOptions().position(fromPosition).title("Start"));
    mMap.addMarker(new MarkerOptions().position(toPosition).title("End"));

    Document doc = md.getDocument(fromPosition, toPosition, Constants.MODE_DRIVING);
    String duration = md.getDurationText(doc);

    tv_duration = (TextView) findViewById(R.id.tv_time);
    tv_duration.setText("Estimated driving time:" + duration);

    ArrayList<LatLng> directionPoint = md.getDirection(doc);

    PolylineOptions rectLine = new PolylineOptions().width(6).color(Color.RED);

    for (int i = 0; i < directionPoint.size(); i++) {
        rectLine.add(directionPoint.get(i));
    }

    mMap.addPolyline(rectLine);
}

From source file:nl.atcomputing.spacetravelagency.fragments.PlaceOrderFragment.java

private void hideMapFragment() {
    FragmentManager fragmentManager = getFragmentManager();
    Fragment fragment = fragmentManager.findFragmentById(R.id.map);
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.hide(fragment);//from w w  w .j a v  a  2 s. c  o  m
    fragmentTransaction.commit();
}

From source file:nl.atcomputing.spacetravelagency.fragments.PlaceOrderFragment.java

private void showMapFragment() {
    FragmentManager fragmentManager = getFragmentManager();

    Fragment fragment = fragmentManager.findFragmentById(R.id.map);
    fragment.setRetainInstance(true);/*from  w  ww. j a v a2 s.  c  o  m*/

    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.show(fragment);
    fragmentTransaction.commit();
}

From source file:edu.mit.mobile.android.livingpostcards.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    setTitle(""); // as we use the logo
    super.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        mSavedCurrentTab = savedInstanceState.getInt(INSTANCE_CURRENT_TAB, NO_SAVED_TAB);
    }/*from w  w  w  .j a v  a  2 s .c  o m*/

    final FragmentManager fm = getSupportFragmentManager();

    // start off with any fragments in a detached state
    final Fragment f = fm.findFragmentById(android.R.id.content);
    if (f != null && !f.isDetached()) {
        final FragmentTransaction ft = fm.beginTransaction();
        ft.detach(f);
        ft.commit();
    }
}

From source file:edu.mit.mobile.android.livingpostcards.MainActivity.java

/**
 * Replaces the current fragment with the splash screen. Removes any tabs.
 *///from w  w  w .  java 2  s .  co m
private void showSplash() {
    final FragmentManager fm = getSupportFragmentManager();
    final FragmentTransaction ft = fm.beginTransaction();
    final Fragment f = fm.findFragmentById(android.R.id.content);

    if (f == null || !(f instanceof NoAccountFragment)) {
        final NoAccountFragment f2 = new NoAccountFragment();

        ft.replace(android.R.id.content, f2, TAG_SPLASH);
        ft.commit();
    }

    final ActionBar actionBar = getSupportActionBar();
    if (ActionBar.NAVIGATION_MODE_STANDARD != actionBar.getNavigationMode()) {
        actionBar.removeAllTabs();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    }
}

From source file:com.money.manager.ex.AccountListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    // take intent send
    Intent intent = getIntent();/*from  w  w  w  .  j ava  2 s.c  om*/
    if (intent != null && !(TextUtils.isEmpty(intent.getAction()))) {
        mAction = intent.getAction();
    }
    FragmentManager fm = getSupportFragmentManager();
    // attach fragment to activity
    if (fm.findFragmentById(android.R.id.content) == null) {
        fm.beginTransaction().add(android.R.id.content, listFragment, FRAGMENTTAG).commit();
    }
}