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.afayear.android.client.activity.DualPaneActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    super.onCreate(savedInstanceState);
    final Resources res = getResources();
    final int orientation = res.getConfiguration().orientation;
    final int layout;
    final boolean is_large_screen = res.getBoolean(R.bool.is_large_screen);
    mDualPaneInPortrait = mPreferences.getBoolean(PREFERENCE_KEY_DUAL_PANE_IN_PORTRAIT, is_large_screen);
    mDualPaneInLandscape = mPreferences.getBoolean(PREFERENCE_KEY_DUAL_PANE_IN_LANDSCAPE, is_large_screen);
    switch (orientation) {
    case Configuration.ORIENTATION_LANDSCAPE:
        layout = mDualPaneInLandscape || shouldForceEnableDualPaneMode() ? getDualPaneLayoutRes()
                : getNormalLayoutRes();//from ww  w  .  j a v  a2s .co  m
        break;
    case Configuration.ORIENTATION_PORTRAIT:
        layout = mDualPaneInPortrait || shouldForceEnableDualPaneMode() ? getDualPaneLayoutRes()
                : getNormalLayoutRes();
        break;
    default:
        layout = getNormalLayoutRes();
        break;
    }
    setContentView(layout);
    if (mSlidingPane != null) {
        mSlidingPane.setRightPaneBackground(getPaneBackground());
    }
    final FragmentManager fm = getSupportFragmentManager();
    fm.addOnBackStackChangedListener(this);
    if (savedInstanceState != null) {
        final Fragment left_pane_fragment = fm.findFragmentById(PANE_LEFT);
        final View main_view = findViewById(R.id.main);
        final boolean left_pane_used = left_pane_fragment != null && left_pane_fragment.isAdded();
        if (main_view != null) {
            final int visibility = left_pane_used ? View.GONE : View.VISIBLE;
            main_view.setVisibility(visibility);
        }
    }
}

From source file:com.example.androidmapsv2.MainActivity.java

private void getVistas() {
    lblPosicion = (TextView) this.findViewById(R.id.lblPosicion);
    // Obtengo la referencia al mapa.
    FragmentManager gestorFragmentos = getSupportFragmentManager();
    SupportMapFragment fragmentoMapa = (SupportMapFragment) gestorFragmentos.findFragmentById(R.id.map);
    mapa = fragmentoMapa.getMap();//  w w  w .  j  a  v a  2 s. c o m
    // Coloco el mapa en mi posicin actual.
    mapa.setMyLocationEnabled(true);
    // Establezco el tipo de mapa que se mostrar.
    mapa.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
    // Establezco la configuracin de la interfaz del mapa.
    mapa.getUiSettings().setZoomControlsEnabled(true);
    mapa.getUiSettings().setCompassEnabled(true);
    mapa.getUiSettings().setMyLocationButtonEnabled(true);
    mapa.getUiSettings().setRotateGesturesEnabled(true);
    mapa.getUiSettings().setScrollGesturesEnabled(true);
    mapa.getUiSettings().setTiltGesturesEnabled(true);
    mapa.getUiSettings().setZoomGesturesEnabled(true);
    // Aado la capa de trfico.
    mapa.setTrafficEnabled(true);
    // Hago que sea la propia actividad la que responda cuando se pulse
    // sobre el mapa, cuando se haga click largo, cuando se pulse sobre un
    // marcador, cuando se desplace un marcador y cuando se pulse sobre la
    // ventana de informacin de un marcador.
    mapa.setOnMapClickListener(this);
    mapa.setOnMapLongClickListener(this);
    mapa.setOnMarkerClickListener(this);
    mapa.setOnMarkerDragListener(this);
    mapa.setOnInfoWindowClickListener(this);
    // Creo y establezco el adaptador que debe utilizarse para la info de
    // los marcadores.
    mapa.setInfoWindowAdapter(new AdaptadorInfo());
}

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

private void loadCardDetails() {

    final FragmentManager fm = getSupportFragmentManager();

    final FragmentTransaction ft = fm.beginTransaction();

    final Fragment details = fm.findFragmentById(R.id.card_details_fragment);
    if (details != null) {
        mCardDetailsFragment = (CardDetailsFragment) details;
    } else {//from ww  w  .ja v  a  2  s.  c  o  m
        mCardDetailsFragment = CardDetailsFragment.newInstance(mCard);

        ft.replace(R.id.card_details_fragment, mCardDetailsFragment);
    }

    ft.commit();
}

From source file:net.freifunk.android.discover.map.GmapsFragment.java

private void createMapFragmentIfNeeded() {
    FragmentManager fm = getChildFragmentManager();
    mapFragment = (SupportMapFragment) fm.findFragmentById(R.id.container);
    if (mapFragment == null) {
        mapFragment = createMapFragment();
        FragmentTransaction tx = fm.beginTransaction();
        tx.add(R.id.container, mapFragment);
        tx.commit();/*from  w  ww  .j  a  va2  s.c  o m*/
    }
}

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

private boolean isModuleViewFragmentAPlaceholder() {
    FragmentManager fragmentManager = getSupportFragmentManager();
    ModuleViewThingyFragment fragment = (ModuleViewThingyFragment) fragmentManager
            .findFragmentById(R.id.module_view_fragment_container);
    return fragment != null && fragment instanceof ModuleViewPlaceholderFragment;
}

From source file:com.ultramegasoft.flavordex2.EntryListActivity.java

@Override
public void onBackPressed() {
    if (mTwoPane) {
        final FragmentManager fm = getSupportFragmentManager();
        Fragment fragment = fm.findFragmentById(R.id.entry_detail_container);
        if (fragment instanceof ViewEntryFragment) {
            if (!((ViewEntryFragment) fragment).onBackButtonPressed()) {
                fragment = fm.findFragmentById(R.id.entry_list);
                if (fragment instanceof EntryListFragment) {
                    ((EntryListFragment) fragment).clearSelection();
                } else {
                    final ActionBar actionBar = getSupportActionBar();
                    if (actionBar != null) {
                        actionBar.setSubtitle(null);
                    }/* w  w w  .  j  a va2  s . c o  m*/
                    onItemSelected(-1, null, 0);
                }
            }
            return;
        } else if (fragment instanceof EntrySearchFragment) {
            fm.beginTransaction().setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE)
                    .replace(R.id.entry_detail_container, mWelcomeFragment).commit();
            return;
        }
    }
    super.onBackPressed();
}

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

private ModuleViewPlaceholderFragment getModuleViewPlacholderFragment() {
    FragmentManager fragmentManager = getSupportFragmentManager();
    ModuleViewThingyFragment fragment = (ModuleViewThingyFragment) fragmentManager
            .findFragmentById(R.id.module_view_fragment_container);

    if (fragment instanceof ModuleViewPlaceholderFragment) {
        return (ModuleViewPlaceholderFragment) fragment;
    } else {//w w  w  .ja  v  a2  s.  c  o m
        return null;
    }
}

From source file:it.angelic.soulissclient.TagDetailActivity.java

public void showDetails(int pos) {
    Bundle bundle = new Bundle();
    bundle.putInt("key", pos);
    List<SoulissTypical> typicalList = collected.getAssignedTypicals();
    android.support.v4.app.FragmentManager manager = getSupportFragmentManager();
    // Check what fragment is currently shown, replace if needed.
    Fragment details = manager.findFragmentById(R.id.detailPane);
    Fragment NewFrag = null;/*from   w  w  w.  ja  va2  s  .com*/
    // Istanzia e ci mette l'indice
    if (typicalList.get(pos).isSensor())
        NewFrag = T5nSensorFragment.newInstance(pos, typicalList.get(pos));
    else if (typicalList.get(pos) instanceof SoulissTypical16AdvancedRGB)
        NewFrag = T16RGBAdvancedFragment.newInstance(pos, typicalList.get(pos));
    else if (typicalList.get(pos) instanceof SoulissTypical19AnalogChannel)
        NewFrag = T19SingleChannelLedFragment.newInstance(pos, typicalList.get(pos));
    else if (typicalList.get(pos) instanceof SoulissTypical31Heating)
        NewFrag = T31HeatingFragment.newInstance(pos, typicalList.get(pos));
    else if (typicalList.get(pos) instanceof SoulissTypical11DigitalOutput
            || typicalList.get(pos) instanceof SoulissTypical12DigitalOutputAuto)
        NewFrag = T1nGenericLightFragment.newInstance(pos, typicalList.get(pos));
    else if (typicalList.get(pos) instanceof SoulissTypical41AntiTheft
            || typicalList.get(pos) instanceof SoulissTypical42AntiTheftPeer
            || typicalList.get(pos) instanceof SoulissTypical43AntiTheftLocalPeer)
        NewFrag = T4nFragment.newInstance(pos, typicalList.get(pos));
    FragmentTransaction ft = manager.beginTransaction();

    if (NewFrag != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            //details.setSharedElementReturnTransition(TransitionInflater.from(this).inflateTransition(android.R.transition.move));
            //details.setExitTransition(TransitionInflater.from(this).inflateTransition(android.R.transition.fade));

            // Create new fragment to add (Fragment B)
            // NewFrag.setSharedElementEnterTransition(TransitionInflater.from(this).inflateTransition(android.R.transition.move));
            NewFrag.setEnterTransition(
                    TransitionInflater.from(this).inflateTransition(android.R.transition.explode));

            // Our shared element (in Fragment A)
            ImageView mProductImage = (ImageView) details.getView().findViewById(R.id.card_thumbnail_image2);
            TextView mProductText = (TextView) findViewById(R.id.TextViewTypicalsTitle);

            AppBarLayout.Behavior beh = new AppBarLayout.Behavior();

            // Add Fragment B
            manager.beginTransaction().replace(R.id.detailPane, NewFrag).addToBackStack("transaction")
                    .addSharedElement(mProductText, "hero_title").commit();//NOT WORK
            //.addSharedElement(mProductText, "ToolbarText");
        } else {
            // if (opzioni.isAnimationsEnabled())
            //     ft.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left);
            ft.replace(R.id.detailPane, NewFrag);
            ft.addToBackStack(null);
            // ft.remove(details);
            //ft.add(NewFrag,"BOH");
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
            ft.commit();
        }
    } else {
        Toast.makeText(getApplicationContext(), "No detail to show", Toast.LENGTH_SHORT).show();
    }

}

From source file:com.example.minigameapp.NewLogin.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);
    }//from  w w w .  j  a v a2s  .c  om

    setContentView(R.layout.new_login);

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

    }

    // 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:com.g_node.gca.map.MapActivity.java

public void locationMarkers() {
    /*//from  ww w.j a  v  a 2 s .  c  om
     * Implement Location Markers
     */
    BufferedReader jsonReader = new BufferedReader(
            new InputStreamReader(this.getResources().openRawResource(R.raw.map)));
    StringBuilder jsonBuilder = new StringBuilder();
    try {
        for (String line = null; (line = jsonReader.readLine()) != null;) {
            jsonBuilder.append(line).append("\n");
        }

        JSONTokener tokener = new JSONTokener(jsonBuilder.toString());
        JSONArray jsonArray = new JSONArray(tokener);

        for (int index = 0; index < jsonArray.length(); index++) {

            JSONObject jsonObject = jsonArray.getJSONObject(index);
            /*
             * getting Latitude
             */
            double getLat = jsonObject.getJSONObject("point").getDouble("lat");
            /*
             * getting Longitude
             */
            double getLng = jsonObject.getJSONObject("point").getDouble("long");
            /*
             * getting Location Type
             */
            int gettype = jsonObject.getInt("type");
            /*
             * getting zoomto value
             */
            int getZoomto = 1;
            if (jsonObject.has("zoomto")) {
                getZoomto = jsonObject.getInt("zoomto");
            }
            /*
             * Venue name
             */
            String name = jsonObject.getString("name");
            LatLng myLoc = new LatLng(getLat, getLng);
            if (getZoomto == 1) {
                /*
                 * Adding only food and venue coordinates for automatic zoom
                 * level
                 */
                allCoordinates.add(myLoc);
            }
            FragmentManager fmanager = getSupportFragmentManager();
            Fragment fragment = fmanager.findFragmentById(R.id.map);
            SupportMapFragment supportmapfragment = (SupportMapFragment) fragment;
            supportMap = supportmapfragment.getMap();
            if (supportMap != null) {
                /*
                 * implementing different colors markers for different
                 * location's
                 */
                switch (gettype) {
                case 0:
                    /*
                     * Conference Venue Marker
                     */
                    supportMap.addMarker(new MarkerOptions().position(myLoc).title(name)
                            .icon(BitmapDescriptorFactory.fromResource(R.drawable.conference)));
                    break;
                case 1:
                    /*
                     * University Marker
                     */
                    supportMap.addMarker(new MarkerOptions().position(myLoc).title(name)
                            .icon(BitmapDescriptorFactory.fromResource(R.drawable.university)));
                    break;
                case 2:
                    /*
                     * Hotel -1 Marker
                     */
                    supportMap.addMarker(new MarkerOptions().position(myLoc).title(name)
                            .icon(BitmapDescriptorFactory.fromResource(R.drawable.hotel_1)));
                    break;
                case 3:
                    /*
                     * Hotel -2 Marker
                     */
                    supportMap.addMarker(new MarkerOptions().position(myLoc).title(name)
                            .icon(BitmapDescriptorFactory.fromResource(R.drawable.hotel_2)));
                    break;
                case 4:
                    /*
                     * Transport Marker
                     */
                    supportMap.addMarker(new MarkerOptions().position(myLoc).title(name)
                            .icon(BitmapDescriptorFactory.fromResource(R.drawable.transport)));
                    break;
                case 5:
                    /*
                     * Food Marker
                     */
                    supportMap.addMarker(new MarkerOptions().position(myLoc).title(name)
                            .icon(BitmapDescriptorFactory.fromResource(R.drawable.food)));
                    break;

                default:
                    break;
                }
            }

        }

        /*
         * Automatic zoom level
         */
        LatLngBounds.Builder builder = new LatLngBounds.Builder();
        for (LatLng m : allCoordinates) {
            builder = builder.include(m);
        }
        LatLngBounds bounds = builder.build();
        CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds,
                this.getResources().getDisplayMetrics().widthPixels
                        - (int) (this.getResources().getDisplayMetrics().widthPixels * 0.1),
                this.getResources().getDisplayMetrics().heightPixels
                        - (int) (this.getResources().getDisplayMetrics().heightPixels * 0.1),
                50);
        /*
         * Move Camera
         */
        supportMap.moveCamera(cu);
        /*
         * Set My Current Location Enable
         */
        supportMap.setMyLocationEnabled(true);
        supportMap.getUiSettings().setMyLocationButtonEnabled(true);
        /*
         * Set Compass Enable
         */
        supportMap.getUiSettings().setCompassEnabled(true);
        /*
         * Set Manual ZoomControl Enable
         */
        supportMap.getUiSettings().setZoomControlsEnabled(false);
    } catch (FileNotFoundException e) {
        Log.e("jsonFile", "file not found");
    } catch (IOException e) {
        Log.e("jsonFile", "ioerror");
    } catch (JSONException e) {
        Log.e("jsonFile", Log.getStackTraceString(e));
    }

}