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.mjhram.geodata.GpsMainActivity.java

protected synchronized void buildGoogleApiClient() {
    FragmentManager fm = getSupportFragmentManager();
    SupportMapFragment mapFragment = (SupportMapFragment) fm.findFragmentById(R.id.location_map);
    mapFragment.setRetainInstance(true);
    mapFragment.getMapAsync(this);
    mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this)
            .addApi(LocationServices.API).build();
}

From source file:com.jefftharris.passwdsafe.FileListActivity.java

/**
 * Change the view of the activity// w  w w .  j  av  a2  s. co m
 */
private void doChangeView(ChangeMode mode, Fragment filesFrag, Fragment syncFrag) {
    boolean clearBackStack = false;
    boolean supportsBack = false;
    switch (mode) {
    case VIEW_FILES_INIT: {
        clearBackStack = true;
        break;
    }
    case VIEW_ABOUT:
    case VIEW_FILES:
    case VIEW_PREFERENCES: {
        supportsBack = true;
        break;
    }
    }

    FragmentManager fragMgr = getSupportFragmentManager();
    FragmentTransaction txn = fragMgr.beginTransaction();
    txn.setTransitionStyle(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

    if (clearBackStack) {
        //noinspection StatementWithEmptyBody
        while (fragMgr.popBackStackImmediate()) {
            // Clear back stack
        }
    }

    if (filesFrag != null) {
        txn.replace(R.id.files, filesFrag);
    } else {
        Fragment currFrag = fragMgr.findFragmentById(R.id.files);
        if ((currFrag != null) && currFrag.isAdded()) {
            txn.remove(currFrag);
        }
    }

    if (syncFrag != null) {
        txn.replace(R.id.sync, syncFrag);
    } else {
        Fragment currFrag = fragMgr.findFragmentById(R.id.sync);
        if ((currFrag != null) && currFrag.isAdded()) {
            txn.remove(currFrag);
        }
    }

    if (supportsBack) {
        txn.addToBackStack(null);
    }

    txn.commit();
}

From source file:com.drawn.drawn.PickFriendsActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pick_friends_activity);

    Bundle extras = getIntent().getExtras();
    final String datosJSON = extras.getString("data");

    FragmentManager fm = getSupportFragmentManager();

    if (savedInstanceState == null) {
        // First time through, we create our fragment programmatically.
        final Bundle args = getIntent().getExtras();
        friendPickerFragment = new FriendPickerFragment(args);
        fm.beginTransaction().add(R.id.friend_picker_fragment, friendPickerFragment).commit();
    } else {//from   www.ja  v  a 2 s .c o  m
        // Subsequent times, our fragment is recreated by the framework and already has saved and
        // restored its state, so we don't need to specify args again. (In fact, this might be
        // incorrect if the fragment was modified programmatically since it was created.)
        friendPickerFragment = (FriendPickerFragment) fm.findFragmentById(R.id.friend_picker_fragment);
    }

    friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
        @Override
        public void onError(PickerFragment<?> fragment, FacebookException error) {
            PickFriendsActivity.this.onError(error);
        }
    });

    //Se pide el User ID a Facebook
    Session session = ParseFacebookUtils.getSession();
    if (session != null && session.isOpened()) {
        requestUserID();
    }

    friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {
        @Override
        public void onDoneButtonClicked(PickerFragment<?> fragment) {
            // We just store our selection in the Application for other activities to look at.
            //Application application =  getApplication();
            //((Object) application).setSelectedUsers(friendPickerFragment.getSelection());
            List<GraphUser> batos = friendPickerFragment.getSelection();

            //Se suben los datos de la lista a Parse, solo para debugeo
            ParseUser current = ParseUser.getCurrentUser();

            for (int i = 0; i < batos.size(); i++) {
                ParseObject datos = new ParseObject("Datos");
                datos.put("user_id_destino", batos.get(i).getId());
                datos.put("destino_nombre", batos.get(i).getName());
                datos.put("origen", id_current_user);
                datos.put("origen_nombre", name_current_user + " " + last_current_user);

                datos.put("sketchData", datosJSON);

                datos.saveInBackground();
            }

            setResult(RESULT_OK, null);

            Intent intent2 = new Intent(getBaseContext(), SentActivity.class);
            startActivity(intent2);

            finish();
        }
    });
}

From source file:com.fusionx.lightirc.ui.IRCActivity.java

private void setUpSlidingMenu(final FragmentManager manager) {
    mUserSlidingMenu = (SlidingMenu) findViewById(R.id.user_sliding_menu);
    mUserSlidingMenu.setContent(R.layout.view_pager_fragment);
    mUserSlidingMenu.setMenu(R.layout.sliding_menu_fragment_userlist);
    mUserSlidingMenu.setShadowDrawable(R.drawable.shadow);
    mUserSlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
    mUserSlidingMenu.setTouchmodeMarginThreshold(10);
    mUserSlidingMenu.setMode(SlidingMenu.RIGHT);
    mUserSlidingMenu.setBehindWidthRes(R.dimen.user_menu_sliding_width);

    mUserListFragment = (UserListFragment) manager.findFragmentById(R.id.userlist_fragment);

    mUserSlidingMenu.setOnOpenListener(new SlidingMenu.OnOpenListener() {
        @Override// ww w.ja  v a 2  s. com
        public void onOpen() {
            mUserListFragment.onMenuOpened(getServer().getUserChannelInterface()
                    .getChannelIfExists(mIRCPagerFragment.getCurrentTitle()));
            onUserListDisplayed();
        }
    });
    mUserSlidingMenu.setOnCloseListener(new SlidingMenu.OnCloseListener() {
        @Override
        public void onClose() {
            getSupportActionBar()
                    .setSubtitle(MiscUtils.getStatusString(IRCActivity.this, getServer().getStatus()));
            mUserListFragment.onClose();
        }
    });

    setUpActionsFragment();
}

From source file:com.paranoid.gerrit.GerritControllerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    mTheme = Prefs.getCurrentThemeID(this);
    setTheme(mTheme);// w w w .j  a  v a  2  s.  c  o  m

    super.onCreate(savedInstanceState);

    // check if caller has a gerrit instance start screen preference
    String suppliedGerritInstance = getIntent().getStringExtra(GERRIT_INSTANCE);
    if (suppliedGerritInstance != null && !suppliedGerritInstance.isEmpty()
            && suppliedGerritInstance.contains("http")) {
        // just set the prefs and allow normal loading
        Prefs.setCurrentGerrit(this, suppliedGerritInstance);
    }

    GoogleAnalytics googleAnalytics = GoogleAnalytics.getInstance(this);

    String trackingId = getString(R.string.ga_trackingId);
    Tracker tracker = googleAnalytics.getTracker(trackingId);
    googleAnalytics.getLogger().setLogLevel(Logger.LogLevel.VERBOSE);
    tracker.send(MapBuilder.createAppView().build());

    // keep a log of what ROM our users run
    EasyTracker easyTracker = EasyTracker.getInstance(this);
    easyTracker.send(MapBuilder.createEvent(AnalyticsConstants.GA_APP_OPEN, // Event category (required)
            AnalyticsConstants.GA_ROM_VERSION, // Event action (required)
            ROMHelper.determineRom(this), // Event label
            null) // Event value (long)
            .build());
    // note this screen as viewed
    easyTracker.send(MapBuilder.createAppView().build());

    // Keep track of what theme is being used
    easyTracker.send(MapBuilder.createEvent(AnalyticsConstants.GA_APP_OPEN,
            AnalyticsConstants.GA_THEME_SET_ON_OPEN, Prefs.getCurrentTheme(this), null).build());
    // note this screen as viewed
    easyTracker.send(MapBuilder.createAppView().build());

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.main);

    FragmentManager fm = getSupportFragmentManager();
    if (findViewById(R.id.change_detail_fragment) != null) {
        // The detail container view will be present only in the
        // large-screen layouts (res/values-large and
        // res/values-sw600dp). If this view is present, then the
        // activity should be in two-pane mode.
        mTwoPane = true;
        mChangeDetail = (PatchSetViewerFragment) fm.findFragmentById(R.id.change_detail_fragment);
    }
    Prefs.setTabletMode(this, mTwoPane);

    mChangeList = (ChangeListFragment) fm.findFragmentById(R.id.change_list_fragment);

    mGerritWebsite = Prefs.getCurrentGerrit(this);

    /* Initially set the current Gerrit globally here.
     *  We can rely on callbacks to know when they change */
    GerritURL.setGerrit(Prefs.getCurrentGerrit(this));
    GerritURL.setProject(Prefs.getCurrentProject(this));

    // Don't register listeners here. It is registered in onResume instead.
    mChangeListener = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String changeid = intent.getStringExtra(PatchSetViewerFragment.CHANGE_ID);
            String status = intent.getStringExtra(PatchSetViewerFragment.STATUS);
            boolean expand = intent.getBooleanExtra(PatchSetViewerFragment.EXPAND_TAG, false);
            onChangeSelected(changeid, status, expand);
        }
    };

    handleIntent(this.getIntent());
}

From source file:it.geosolutions.android.map.MapsActivity.java

/**
 * Creates/Restore the layer switcher or restore the old one and add
 * all other menu /*from   w ww  .j a v a 2  s.co m*/
 * @param savedInstanceState
 * @param layerManager
 */
private void setupLeftMenu(Bundle savedInstanceState, MultiSourceOverlayManager layerManager) {
    //work on fragment management
    FragmentManager fManager = getSupportFragmentManager();
    LayerSwitcherFragment osf;
    if (savedInstanceState != null) {
        osf = (LayerSwitcherFragment) fManager.findFragmentById(R.id.left_drawer_container);
        if (osf == null) {
            Log.e("MAPSACTIVITY", "unable to restore layer switcher");
        }
        layerManager.setLayerChangeListener(osf);
        layerManager.restoreInstanceState(savedInstanceState);

    } else {

        layerManager.defaultInit();
        MSMMap map = SpatialDbUtils.mapFromDb();
        layerManager.loadMap(map);
        //setup left drawer fragments
        osf = new LayerSwitcherFragment();
        layerManager.setLayerChangeListener(osf);
        FragmentTransaction fragmentTransaction = fManager.beginTransaction();
        fragmentTransaction.add(R.id.left_drawer_container, osf);
        GenericMenuFragment other = new GenericMenuFragment();
        fragmentTransaction.add(R.id.left_drawer_container_bottom, other);
        fragmentTransaction.commit();

    }
}

From source file:com.detroitteatime.autocarfinder.Main.java

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

    mainLayout = (LinearLayout) this.getLayoutInflater().inflate(R.layout.main, null);

    setContentView(mainLayout);// w ww  .jav a 2  s  .c om

    // Possible work around for market launches. See
    // http://code.google.com/p/android/issues/detail?id=2373
    // for more details. Essentially, the market launches the main activity
    // on top of other activities.
    // we never want this to happen. Instead, we check if we are the root
    // and if not, we finish.
    if (!isTaskRoot()) {
        final Intent intent = getIntent();
        final String intentAction = intent.getAction();
        if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction != null
                && intentAction.equals(Intent.ACTION_MAIN)) {
            // Log.w("My Code",
            // "Main Activity is not the root.  Finishing Main Activity instead of launching.");
            finish();
            return;
        }
    }

    // set up buttons
    start = (Button) findViewById(R.id.start);

    manual = (Button) findViewById(R.id.manual);
    // progress = (ProgressBar) findViewById(R.id.progressBar1);

    start.setOnClickListener(this);
    start.getBackground().setColorFilter(Color.parseColor(COLOR), PorterDuff.Mode.MULTIPLY);

    manual.setOnClickListener(this);
    manual.getBackground().setColorFilter(Color.parseColor(COLOR), PorterDuff.Mode.MULTIPLY);

    monitor = (FrameLayout) findViewById(R.id.frameLayout1);

    data1 = this.getSharedPreferences("storage", 0);
    editor1 = data1.edit();

    // firstTime = data1.getBoolean("first_time", true);

    editor1.putBoolean("first_time", false);
    editor1.commit();

    pi = PendingIntent.getActivity(this, 0, new Intent(this, Main.class), 0);

    data1 = getSharedPreferences("storage", 0);
    editor1 = data1.edit();

    // set a global layout listener which will be called when the layout
    // pass is completed and the view is drawn

    FragmentManager myFragmentManager = getSupportFragmentManager();
    mySupportMapFragment = (SupportMapFragment) myFragmentManager.findFragmentById(R.id.map);

    if (MapsInitializer.initialize(this) != ConnectionResult.SUCCESS) {
        Toast.makeText(this, "Map failed to initialize.", Toast.LENGTH_SHORT).show();

    }

    map = mySupportMapFragment.getMap();

    manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    // Define the criteria how to select the locatioin provider -> use
    // default
    criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    provider = manager.getBestProvider(criteria, false);
    manager.requestLocationUpdates(provider, 1000, 1, this);

    navigate = (Button) findViewById(R.id.navigate);
    navigate.setOnClickListener(this);

    type = (Button) findViewById(R.id.satellite);
    type.setOnClickListener(this);

}

From source file:com.pacoapp.paco.ui.MyExperimentsActivity.java

@SuppressLint("NewApi")
@Override//from www.  ja v  a  2s . c  om
protected void onCreate(Bundle savedInstanceState) {
    Log.info("MyExperimentsActivity onCreate");
    super.onCreate(savedInstanceState);
    mainLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.activity_current_experiments, null);
    setContentView(mainLayout);

    // TODO would this work if it is in the Systemchangereceiver ?
    new RingtoneUtil(this).installPacoBarkRingtone();

    userPrefs = new UserPreferences(this);
    progressBar = (ProgressBar) findViewById(R.id.findExperimentsProgressBar);

    FragmentManager supportFragmentManager = getSupportFragmentManager();
    mNavigationDrawerFragment = (NavigationDrawerFragment) supportFragmentManager
            .findFragmentById(R.id.navigation_drawer);

    list = (ListView) findViewById(R.id.find_experiments_list);
    list.setBackgroundColor(333);
    experimentProviderUtil = new ExperimentProviderUtil(this);

    // Set up the drawer.

    invitationLayout = (LinearLayout) findViewById(R.id.announcementLayout);
    invitationExperimentName = (TextView) findViewById(R.id.invitationExperimentNameTextView);
    invitationContactTextView = (TextView) findViewById(R.id.invitationContactTextView);
    invitationCloseButton = (ImageButton) findViewById(R.id.invitationAnnouncementCloseButton);
}

From source file:com.coffeecups.testproject.PickFriendsActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pick_friends_activity);

    FragmentManager fm = getSupportFragmentManager();

    if (savedInstanceState == null) {
        // First time through, we create our fragment programmatically.
        final Bundle args = getIntent().getExtras();
        friendPickerFragment = new FriendPickerFragment(args);
        // friendPickerFragment.getView().findViewById(R.id.com_facebook_picker_top_bar).setVisibility(View.GONE);
        fm.beginTransaction().add(R.id.friend_picker_fragment, friendPickerFragment).commit();
    } else {//from   w w w.  j a v a  2 s  .com
        // Subsequent times, our fragment is recreated by the framework and
        // already has saved and
        // restored its state, so we don't need to specify args again. (In
        // fact, this might be
        // incorrect if the fragment was modified programmatically since it
        // was created.)
        friendPickerFragment = (FriendPickerFragment) fm.findFragmentById(R.id.friend_picker_fragment);
    }

    friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() {
        @Override
        public void onError(PickerFragment<?> fragment, FacebookException error) {
            PickFriendsActivity.this.onError(error);
        }
    });

    friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {
        @Override
        public void onDoneButtonClicked(PickerFragment<?> fragment) {
            // We just store our selection in the Application for
            // other activities to look at.
            FriendPickerApplication application = (FriendPickerApplication) getApplication();
            application.setSelectedUsers(friendPickerFragment.getSelection());

            setResult(RESULT_OK, null);
            finish();
        }
    });
}

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

public void reloadAllFragment() {
    FragmentManager fragmentManager = MainActivity.this.getSupportFragmentManager();
    if (fragmentManager != null) {
        // content
        Fragment fragment = fragmentManager.findFragmentById(R.id.fragmentContent);
        if (fragment != null)
            fragment.onResume();/*from   ww  w  .j  a va  2  s . co m*/
        // check if is dual panel
        if (isDualPanel()) {
            fragment = fragmentManager.findFragmentById(R.id.fragmentDetail);
            if (fragment != null)
                fragment.onResume();
        }
    }
}