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:gr.scify.newsum.ui.Facebook.java

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

    if ((getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_NORMAL
            & (getResources().getConfiguration().screenLayout
                    & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_SMALL) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    }/* w  w  w  .j  a  va 2 s  . c  o m*/

    SharedPreferences userlang = getSharedPreferences("lang", 0);
    String newlang = userlang.getString("lang", Locale.getDefault().getLanguage());
    // Changed getApplicationContext() to "this"
    Setlanguage.updateLanguage(this, newlang);

    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.facebook);

    Bundle extras = getIntent().getExtras();
    summaryF = extras.getString("summaryF");

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

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

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

From source file:nz.ac.otago.psyanlab.common.PaleActivity.java

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

    // Get and initialise user delegate.
    if (getIntent().hasExtra(Args.USER_DELEGATE)) {
        mUserDelegate = getIntent().getParcelableExtra(Args.USER_DELEGATE);
        mUserDelegate.init(this);
    } else {//from w  w  w .  jav  a 2s  .c o  m
        throw new IllegalStateException("User delegate must be provided.");
    }

    // Initialise action bar.
    ActionBar actionBar = getActionBar();
    String title = mUserDelegate.getUserName();
    if (TextUtils.isEmpty(title)) {
        title = getString(R.string.app_name);
        actionBar.setDisplayHomeAsUpEnabled(false);
    } else {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    actionBar.setTitle(title);

    // Initialise fragments.
    FragmentManager fm = getSupportFragmentManager();

    // List fragment.
    mPaleListFragment = (PaleListFragment) fm.findFragmentById(R.id.pale_list_fragment);
    mPaleListFragment.setUserDelegate(mUserDelegate);
    mPaleListFragment.setActivateOnItemClick(true);
    // if (savedInstanceState == null) {
    // mPaleListFragment.setActivatedPosition(0);
    // }

    // Detail fragment.
    mPaleDetailFragment = (PaleDetailFragment) fm.findFragmentById(R.id.pale_detail_fragment);
    if (savedInstanceState != null) {
        updateExperimentDelegate(
                savedInstanceState.<UserExperimentDelegateI>getParcelable(Args.USER_EXPERIMENT_DELEGATE));
    }

    // Initialise sliding container.
    mSlidingContainer = (SlidingPaneLayout) findViewById(R.id.sliding_container);
    mSlidingContainer
            .setParallaxDistance((int) getResources().getDimension(R.dimen.sliding_container_parallax));
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            if (mSlidingContainer.isSlideable()) {
                mSlidingContainer.setShadowResource(R.drawable.opal_list_background);
                mSlidingContainer.invalidate();
            } else {
                mSlidingContainer.setShadowResource(R.drawable.opal_list_background_flat);
                mSlidingContainer.invalidate();
            }
        }
    }, 100);
}

From source file:com.facebook.samples.hellofacebook.MapFriends.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);

    getKeyHash();//from ww w. j  a v  a  2s . c om

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

    setContentView(R.layout.main);

    LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setReadPermissions(
            Arrays.asList("user_friends", "user_location", "friends_location", "friends_hometown"));
    loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
        @Override
        public void onUserInfoFetched(GraphUser user) {
            MapFriends.this.user = user;
            updateUI();
        }
    });

    profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture);
    greeting = (TextView) findViewById(R.id.greeting);

    gotoMapButton = (Button) findViewById(R.id.gotoMap);
    gotoMapButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent intent = new Intent(MapFriends.this, MapDetails.class);
            startActivity(intent);
        }
    });

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

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

From source file:com.mifos.mifosxdroid.online.DashboardActivity.java

private void addOnBackStackChangedListener() {
    if (getSupportFragmentManager() == null) {
        return;//  w ww.  j av a2s. co  m
    }
    getSupportFragmentManager().addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
        @Override
        public void onBackStackChanged() {
            FragmentManager fragmentManager = getSupportFragmentManager();
            Fragment fragment = fragmentManager.findFragmentById(R.id.container);
            if (fragment instanceof CreateNewClientFragment) {
                setActionBarTitle(R.string.create_client);
                setMenuCreateClient(false);
                setMenuCreateCentre(true);
                setMenuCreateGroup(true);
            } else if (fragment instanceof CreateNewGroupFragment) {
                setActionBarTitle(R.string.create_group);
                setMenuCreateClient(true);
                setMenuCreateCentre(true);
                setMenuCreateGroup(false);
            } else if (fragment instanceof CreateNewCenterFragment) {
                setActionBarTitle(R.string.create_center);
                setMenuCreateClient(true);
                setMenuCreateCentre(false);
                setMenuCreateGroup(true);
            }
        }
    });

}

From source file:org.connectbot.EditHostActivity.java

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

    mHostDb = HostDatabase.get(this);
    mPubkeyDb = PubkeyDatabase.get(this);

    mTerminalConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName className, IBinder service) {
            TerminalManager bound = ((TerminalManager.TerminalBinder) service).getService();
            mBridge = bound.getConnectedBridge(mHost);
        }//w w w  .j  a va2s  .c  o m

        public void onServiceDisconnected(ComponentName name) {
            mBridge = null;
        }
    };

    long hostId = getIntent().getLongExtra(EXTRA_EXISTING_HOST_ID, NO_HOST_ID);
    mIsCreating = hostId == NO_HOST_ID;
    mHost = mIsCreating ? null : mHostDb.findHostById(hostId);

    // Note that the lists must be explicitly declared as ArrayLists because Bundle only accepts
    // ArrayLists of Strings.
    ArrayList<String> pubkeyNames = new ArrayList<>();
    ArrayList<String> pubkeyValues = new ArrayList<>();

    // First, add default pubkey names and values (e.g., "use any" and "don't use any").
    TypedArray defaultPubkeyNames = getResources().obtainTypedArray(R.array.list_pubkeyids);
    for (int i = 0; i < defaultPubkeyNames.length(); i++) {
        pubkeyNames.add(defaultPubkeyNames.getString(i));
    }
    TypedArray defaultPubkeyValues = getResources().obtainTypedArray(R.array.list_pubkeyids_value);
    for (int i = 0; i < defaultPubkeyValues.length(); i++) {
        pubkeyValues.add(defaultPubkeyValues.getString(i));
    }

    // Now, add pubkeys which have been added by the user.
    for (CharSequence cs : mPubkeyDb.allValues(PubkeyDatabase.FIELD_PUBKEY_NICKNAME)) {
        pubkeyNames.add(cs.toString());
    }
    for (CharSequence cs : mPubkeyDb.allValues("_id")) {
        pubkeyValues.add(cs.toString());
    }

    setContentView(R.layout.activity_edit_host);
    FragmentManager fm = getSupportFragmentManager();
    HostEditorFragment fragment = (HostEditorFragment) fm.findFragmentById(R.id.fragment_container);

    if (fragment == null) {
        fragment = HostEditorFragment.newInstance(mHost, pubkeyNames, pubkeyValues);
        getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, fragment).commit();
    }

    defaultPubkeyNames.recycle();
    defaultPubkeyValues.recycle();
}

From source file:com.afayear.android.client.activity.DualPaneActivity.java

@Override
public void onBackStackChanged() {
    if (isDualPaneMode()) {
        final FragmentManager fm = getSupportFragmentManager();
        final int count = fm.getBackStackEntryCount();
        final Fragment left_pane_fragment = fm.findFragmentById(PANE_LEFT);
        final Fragment right_pane_fragment = fm.findFragmentById(PANE_RIGHT);
        final View main_view = findViewById(R.id.main);
        final boolean left_pane_used = left_pane_fragment != null && left_pane_fragment.isAdded();
        final boolean right_pane_used = right_pane_fragment != null && right_pane_fragment.isAdded();
        if (count > 0) {
            final BackStackEntry entry = fm.getBackStackEntryAt(count - 1);
            if (entry == null)
                return;
            final Fragment fragment = BackStackEntryTrojan.getFragmentInBackStackRecord(entry);
            if (fragment instanceof Panes.Right) {
                showRightPane();//from  w  ww .ja  v a  2 s . c o m
            } else if (fragment instanceof Panes.Left) {
                showLeftPane();
            }
        } else {
            if (fm.findFragmentById(R.id.main) != null || left_pane_used) {
                showLeftPane();
            } else if (right_pane_used) {
                showRightPane();
            }
        }
        if (main_view != null) {
            final int visibility = left_pane_used ? View.GONE : View.VISIBLE;
            // Visibility changed, so start animation.
            if (main_view.getVisibility() != visibility) {
                final Animation anim = AnimationUtils.loadAnimation(this,
                        left_pane_used ? android.R.anim.fade_out : android.R.anim.fade_in);
                main_view.startAnimation(anim);
            }
            main_view.setVisibility(visibility);
        }
    }
}

From source file:com.abhijitvalluri.android.fitnotifications.HomeActivity.java

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

    // Set a Toolbar to replace the ActionBar.
    mToolbar = (Toolbar) findViewById(R.id.home_toolbar);
    setSupportActionBar(mToolbar);/*from  w ww  . j a  v  a2 s . c  o  m*/

    LAUNCH_ACTIVITY_ANIM_BUNDLE = ActivityOptions
            .makeCustomAnimation(HomeActivity.this, R.transition.left_in, R.transition.left_out).toBundle();

    // Initialize settings to defaults

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerToggle = new SmoothDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open,
            R.string.drawer_close);

    mDrawerLayout.addDrawerListener(mDrawerToggle);

    mNavDrawer = (NavigationView) findViewById(R.id.navDrawer);
    setupDrawerContent(mNavDrawer);

    PreferenceManager.setDefaultValues(this, R.xml.main_settings, false);
    mPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    Fragment frag = new HomeFragment();

    // Add a new fragment to the appropriate view element
    FragmentManager fragmentManager = getSupportFragmentManager();
    if (fragmentManager.findFragmentById(R.id.flContent) == null) {
        fragmentManager.beginTransaction().add(R.id.flContent, frag).commit();
    }

    if (mPreferences.getInt(getString(R.string.version_key), 0) < Constants.VERSION_CODE
            && mPreferences.getBoolean(getString(R.string.done_first_launch_key), false)) {
        // App has been updated
        AppSelectionsStore store = AppSelectionsStore.get(this);
        List<AppSelection> appSelections = store.getAppSelections();

        for (AppSelection selection : appSelections) {
            if (selection.getStartTime() == 0 && (selection.getStopTime() == 1439)
                    || selection.getStopTime() == 0) {
                // Default setting should be 11:59pm for end time.
                selection.setStopTimeHour(23);
                selection.setStopTimeMinute(59);
                store.updateAppSelection(selection);
            }
        }

        mNavDrawer.setCheckedItem(R.id.nav_whats_new);
        setTitle(R.string.whats_new);
        frag = InfoFragment.newInstance(getString(R.string.whats_new_text));
        fragmentManager.beginTransaction().replace(R.id.flContent, frag).commit();

        mPreferences.edit().putInt(getString(R.string.version_key), Constants.VERSION_CODE).apply();
    }

    if (!mPreferences.getBoolean(getString(R.string.done_first_launch_key), false)) { // This is the first launch
        startActivityForResult(new Intent(HomeActivity.this, AppIntroActivity.class),
                APP_INTRO_FIRST_LAUNCH_INTENT, LAUNCH_ACTIVITY_ANIM_BUNDLE);
    }

}

From source file:com.qubling.sidekick.ui.module.ModuleSearchActivity.java

private ModuleSearchFragment getModuleSearchFragment() {
    FragmentManager fragmentManager = getSupportFragmentManager();
    return (ModuleSearchFragment) fragmentManager.findFragmentById(R.id.module_search_fragment);
}

From source file:it.sasabz.android.sasabus.fragments.OnlineSelectFragment.java

public void getConnectionList(XMLStation from, XMLStation to, String datetime) {
    progress.dismiss();/*from w  w  w .  j  av  a  2s  .co  m*/
    //Intent showConnection = new Intent(getContext(), OnlineShowFragment.class);
    Fragment fragment = new OnlineShowFragment(from, to, datetime);
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction ft = fragmentManager.beginTransaction();

    Fragment old = fragmentManager.findFragmentById(R.id.onlinefragment);
    if (old != null) {
        ft.remove(old);
    }
    ft.add(R.id.onlinefragment, fragment);
    ft.disallowAddToBackStack();
    ft.commit();
    fragmentManager.executePendingTransactions();
}

From source file:com.google.android.apps.muzei.settings.SettingsActivity.java

private void updateRenderLocally(boolean renderLocally) {
    if (mRenderLocally == renderLocally) {
        return;/*from  w ww. j a  v a 2  s.c  o  m*/
    }

    mRenderLocally = renderLocally;

    final View uiContainer = findViewById(R.id.container);
    final ViewGroup localRenderContainer = (ViewGroup) findViewById(R.id.local_render_container);

    FragmentManager fm = getSupportFragmentManager();
    Fragment localRenderFragment = fm.findFragmentById(R.id.local_render_container);
    if (mRenderLocally) {
        if (localRenderFragment == null) {
            fm.beginTransaction()
                    .add(R.id.local_render_container, MuzeiRendererFragment.createInstance(false, false))
                    .commit();
        }
        if (localRenderContainer.getAlpha() == 1) {
            localRenderContainer.setAlpha(0);
        }
        localRenderContainer.setVisibility(View.VISIBLE);
        localRenderContainer.animate().alpha(1).setDuration(2000).withEndAction(null);
        uiContainer.setBackgroundColor(0x00000000); // for ripple touch feedback
    } else {
        if (localRenderFragment != null) {
            fm.beginTransaction().remove(localRenderFragment).commit();
        }
        localRenderContainer.animate().alpha(0).setDuration(1000).withEndAction(new Runnable() {
            @Override
            public void run() {
                localRenderContainer.setVisibility(View.GONE);
            }
        });
        uiContainer.setBackground(null);
    }
}