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:il.co.togetthere.LoginActivity.java

@SuppressLint("InlinedApi")
@Override//from w  w  w .  ja  va  2s .c o  m
public void onCreate(Bundle savedInstanceState) {

    // Hide the status bar.
    //View decorView = getWindow().getDecorView();
    //int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
    //decorView.setSystemUiVisibility(uiOptions); 

    // Remember that you should never show the action bar if the
    // status bar is hidden, so hide that too if necessary.
    android.app.ActionBar actionBar = getActionBar();
    actionBar.hide();

    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);
    }

    setContentView(R.layout.activity_login);

    //initialize db credentialis for registering user
    clientManager = new AmazonClientManager(this);

    // Configure the Facebook login button
    buttonLoginFacebook = (LoginButton) findViewById(R.id.button_login_facebook);
    buttonLoginFacebook.setBackgroundResource(R.drawable.button_login_facebook);
    buttonLoginFacebook.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
    buttonLoginFacebook.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
        @Override
        public void onUserInfoFetched(GraphUser user) {
            LoginActivity.this.facebookUser = user;
            LoginActivity.user.init(user); //set facebook user in user
            //TelephonyManager tMgr =  (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
            //LoginActivity.user.setPhone(tMgr.getLine1Number());

            if (user != null) {
                LoginActivity.user.syncDB();
                continuteToNextScreen();
            }

            // It's possible that we were waiting for this.user to be populated in order to post a
            // status update.
            handlePendingAction();
        }
    });

    // Configure the Google login button
    buttonLoginGoogle = (Button) findViewById(R.id.button_login_google);
    buttonLoginGoogle.setBackgroundResource(R.drawable.button_login_google);
    buttonLoginGoogle.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
    buttonLoginGoogle.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Toast.makeText(getApplicationContext(), "Google+ support is coming soon...", Toast.LENGTH_SHORT)
                    .show();
        }
    });

    // Configure the Twitter login button
    buttonLoginTwitter = (Button) findViewById(R.id.button_login_twitter);
    buttonLoginTwitter.setBackgroundResource(R.drawable.button_login_twitter);
    buttonLoginTwitter.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
    buttonLoginTwitter.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Toast.makeText(getApplicationContext(), "Twitter support is coming soon...", Toast.LENGTH_SHORT)
                    .show();
        }
    });

    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);
            }
        }
    });

    // Can we present the share dialog for regular links?
    canPresentShareDialog = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.SHARE_DIALOG);
    // Can we present the share dialog for photos?
    canPresentShareDialogWithPhotos = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.PHOTOS);
}

From source file:com.BeatYourRecord.HelloFacebookSampleActivity.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);
    }/*  w  ww  .  j a va  2s.  c o  m*/

    setContentView(R.layout.main6);

    loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
        @Override
        public void onUserInfoFetched(GraphUser user) {
            HelloFacebookSampleActivity.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);
            }
        }
    });

    canPresentShareDialog = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.SHARE_DIALOG);
}

From source file:de.tum.mw.lfe.drtrc.MainActivity.java

private void refreshMyResultView() {
    FragmentManager fragmentManager = getSupportFragmentManager();
    Fragment f = fragmentManager.findFragmentById(R.id.container);
    int sec = f.getArguments().getInt(ARG_SECTION_NUMBER);
    MyViewAdapter a = null;//from   w w  w  . ja  v  a 2s .c  om
    if (sec == FRAGMENT_MYVIEW) {
        a = (MyViewAdapter) ((MyViewFragment) f).getAdapter();
        a.notifyDataSetChanged();
        //a.clear();
        //a.addAll(mDataItems);
    }
}

From source file:ch.corten.aha.worldclock.WorldClockActivity.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) {
        ClockListFragment list = new ClockListFragment();
        fm.beginTransaction().add(android.R.id.content, list).commit();
    }//from  www .  jav a  2  s.  c  o m
}

From source file:com.google.blockly.android.BlocklyActivityHelper.java

/**
 * Creates the Views and Fragments before the BlocklyController is constructed.  Override to
 * load a custom View hierarchy.  Responsible for assigning {@link #mWorkspaceFragment}, and
 * optionally, {@link #mToolboxBlockList} and {@link #mTrashBlockList}. This base
 * implementation attempts to acquire references to:
 * <ul>//from  w w w.  jav  a2  s.  c om
 *   <li>the {@link WorkspaceFragment} with id {@link R.id#blockly_workspace}, assigned to
 *   {@link #mWorkspaceFragment}.</li>
 *   <li>the toolbox {@link CategorySelectorFragment} with id {@link R.id#blockly_categories},
 *   assigned to {@link #mCategoryFragment}.</li>
 *   <li>the toolbox {@link FlyoutFragment} with id {@link R.id#blockly_toolbox_ui},
 *   assigned to {@link #mToolboxBlockList}.</li>
 *   <li>the trash {@link FlyoutFragment} with id {@link R.id#blockly_trash_ui}, assigned to
 *   {@link #mTrashBlockList}.</li>
 * </ul>
 * Only the workspace fragment is required. The activity layout can choose not to include the
 * other fragments, and subclasses that override this method can leave the field null if that
 * are not used.
 * <p/>
 * This methods is always called once from the constructor before {@link #mController} is
 * instantiated.
 */
protected void onCreateFragments() {
    FragmentManager fragmentManager = mActivity.getSupportFragmentManager();
    mWorkspaceFragment = (WorkspaceFragment) fragmentManager.findFragmentById(R.id.blockly_workspace);
    mToolboxBlockList = (BlockListUI) fragmentManager.findFragmentById(R.id.blockly_toolbox_ui);
    mCategoryFragment = (CategorySelectorFragment) fragmentManager.findFragmentById(R.id.blockly_categories);
    mTrashBlockList = (BlockListUI) fragmentManager.findFragmentById(R.id.blockly_trash_ui);

    if (mTrashBlockList != null) {
        // TODO(#14): Make trash list a drop location.
    }
}

From source file:edu.upenn.tempmaniac.AccountActivityNew.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    currentLocation = new Location("") {
        {//  w w  w  .j a v  a  2s.c  om
            GPSTracker mGPS = new GPSTracker(AccountActivityNew.this);
            double mLat = 0;
            double mLong = 0;
            if (mGPS.canGetLocation) {

                mLat = mGPS.getLatitude();
                mLong = mGPS.getLongitude();
                Log.v("gps handler:", "latitude: " + mLat + ", Longitude: " + mLong);
            } else {
                Log.v("gps handler:", "no response");
            }
            setLatitude(mLat);
            setLongitude(mLong);
        }
    };

    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY);
        pendingAction = PendingAction.valueOf(name);
    }

    setContentView(R.layout.account_new);

    loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {

        public void onUserInfoFetched(GraphUser user) {
            AccountActivityNew.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();
        }
    });

    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() {

        public void onBackStackChanged() {
            if (fm.getBackStackEntryCount() == 0) {
                // We need to re-show our UI.
                controlsContainer.setVisibility(View.VISIBLE);
            }
        }
    });
}

From source file:org.bicsi.canada2014.FacebookPost.FacebookPostActivity.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);
    }/*  w  w  w .j ava 2s  . 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) {
            FacebookPostActivity.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);
            }
        }
    });

    canPresentShareDialog = FacebookDialog.canPresentShareDialog(this,
            FacebookDialog.ShareDialogFeature.SHARE_DIALOG);
}

From source file:com.gdgdevfest.android.apps.devfestbcn.ui.tablet.SessionsSandboxMultiPaneActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    UIUtils.tryTranslateHttpIntent(this);
    BeamUtils.tryUpdateIntentFromBeam(this);

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_sessions_sandbox);

    final FragmentManager fm = getSupportFragmentManager();
    mTracksDropdownFragment = (TracksDropdownFragment) fm.findFragmentById(R.id.fragment_tracks_dropdown);

    mSlidingPaneLayout = (SlidingPaneLayout) findViewById(R.id.sliding_pane_layout);

    // Offset the left pane by its full width and left margin when collapsed
    // (ViewPager-like presentation)
    mSlidingPaneLayout.setParallaxDistance(getResources().getDimensionPixelSize(R.dimen.sliding_pane_width)
            + getResources().getDimensionPixelSize(R.dimen.multipane_padding));
    mSlidingPaneLayout.setSliderFadeColor(getResources().getColor(R.color.sliding_pane_content_fade));

    routeIntent(getIntent(), savedInstanceState != null);

    if (savedInstanceState != null) {
        if (mFullUI) {
            int viewType = savedInstanceState.getInt(STATE_VIEW_TYPE);
            getSupportActionBar().setSelectedNavigationItem(viewType);
        }//from   ww w  . j  a  va2 s.  c  o m

        mDetailFragment = fm.findFragmentById(R.id.fragment_container_detail);
        updateDetailBackground();
    }

    // This flag prevents onTabSelected from triggering extra master pane reloads
    // unless it's actually being triggered by the user (and not automatically by
    // the system)
    mInitialTabSelect = false;

    mImageLoader = new ImageLoader(this, R.drawable.person_image_empty)
            .setMaxImageSize(getResources().getDimensionPixelSize(R.dimen.speaker_image_size))
            .setFadeInImage(UIUtils.hasHoneycombMR1());

    EasyTracker.getInstance().setContext(this);
}

From source file:com.murrayc.galaxyzoo.app.ClassifyFragment.java

/** Show, or hide, the child fragments.
 */// w w  w  . j a v a 2s .co  m
private void showChildFragments(final boolean show) {
    //If we are showing the loading view then we should hide the other fragments,
    //and vice-versa.
    final FragmentManager fragmentManager = getChildFragmentManager();
    final FragmentTransaction transaction = fragmentManager.beginTransaction();
    final Fragment fragmentSubject = fragmentManager.findFragmentById(R.id.child_fragment_subject);
    if (fragmentSubject != null) {
        if (show) {
            transaction.show(fragmentSubject);
        } else {
            transaction.hide(fragmentSubject);
        }
    }

    final Fragment fragmentQuestion = fragmentManager.findFragmentById(R.id.child_fragment_question);
    if (fragmentQuestion != null) {
        if (show) {
            transaction.show(fragmentQuestion);
        } else {
            transaction.hide(fragmentQuestion);
        }
    }

    transaction.commit();
}

From source file:com.actionbarsherlock.sample.demos.app.LoaderThrottleSupport.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) {
        ThrottledLoaderListFragment list = new ThrottledLoaderListFragment();
        fm.beginTransaction().add(android.R.id.content, list).commit();
    }/*www.j av  a  2s .  c om*/
}