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

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

Introduction

In this page you can find the example usage for android.support.v4.app FragmentManager beginTransaction.

Prototype

public abstract FragmentTransaction beginTransaction();

Source Link

Document

Start a series of edit operations on the Fragments associated with this FragmentManager.

Usage

From source file:com.cypress.cysmart.GATTDBFragments.GattDetailsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.gattdb_details, container, false);
    this.mContainer = container;
    mApplication = (CySmartApplication) getActivity().getApplication();
    mServiceName = (TextView) rootView.findViewById(R.id.txtservicename);
    mHexValue = (TextView) rootView.findViewById(R.id.txthex);
    mCharacteristiceName = (TextView) rootView.findViewById(R.id.txtcharatrname);
    mBtnnotify = (TextView) rootView.findViewById(R.id.txtnotify);
    mBtnIndicate = (TextView) rootView.findViewById(R.id.txtindicate);
    mBtnread = (TextView) rootView.findViewById(R.id.txtread);
    mBtnwrite = (TextView) rootView.findViewById(R.id.txtwrite);
    mAsciivalue = (TextView) rootView.findViewById(R.id.txtascii);
    mTimevalue = (TextView) rootView.findViewById(R.id.txttime);
    mDatevalue = (TextView) rootView.findViewById(R.id.txtdate);
    backbtn = (ImageView) rootView.findViewById(R.id.imgback);
    mProgressDialog = new ProgressDialog(getActivity());
    /**/*from  ww w . j  a  v a2  s  .co  m*/
     * Soft back button listner
     */
    backbtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().onBackPressed();

        }
    });
    btn_descriptor = (Button) rootView.findViewById(R.id.characteristic_descriptors);
    if (mApplication.getBluetoothgattcharacteristic().getDescriptors().size() == 0) {
        btn_descriptor.setVisibility(View.GONE);
    }
    /**
     * Descriptor button listner
     */
    btn_descriptor.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            /**
             * Passing the characteristic details to GattDetailsFragment and
             * adding that fragment to the view
             */
            Bundle bundle = new Bundle();
            bundle.putString(Constants.GATTDB_SELECTED_SERVICE, mServiceName.getText().toString());
            bundle.putString(Constants.GATTDB_SELECTED_CHARACTERISTICE,
                    mCharacteristiceName.getText().toString());
            FragmentManager fragmentManager = getFragmentManager();
            GattDescriptorFragment gattDescriptorFragment = new GattDescriptorFragment().create();
            gattDescriptorFragment.setArguments(bundle);
            fragmentManager.beginTransaction().add(R.id.container, gattDescriptorFragment).addToBackStack(null)
                    .commit();
        }
    });
    RelativeLayout parent = (RelativeLayout) rootView.findViewById(R.id.parent);
    parent.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

        }
    });
    /**
     * button listeners
     */
    mBtnread.setOnClickListener(this);
    mBtnnotify.setOnClickListener(this);
    mBtnIndicate.setOnClickListener(this);
    mBtnwrite.setOnClickListener(this);

    mServiceName.setSelected(true);
    mCharacteristiceName.setSelected(true);
    mAsciivalue.setSelected(true);
    mHexValue.setSelected(true);

    // Getting the characteristics from the application
    mReadCharacteristic = mApplication.getBluetoothgattcharacteristic();
    mNotifyCharacteristic = mApplication.getBluetoothgattcharacteristic();
    Bundle bundle = this.getArguments();
    if (bundle != null) {
        mServiceName.setText(bundle.getString(Constants.GATTDB_SELECTED_SERVICE));
        mCharacteristiceName.setText(bundle.getString(Constants.GATTDB_SELECTED_CHARACTERISTICE));
    }
    startNotifyText = getResources().getString(R.string.gatt_services_notify);
    stopNotifyText = getResources().getString(R.string.gatt_services_stop_notify);
    startIndicateText = getResources().getString(R.string.gatt_services_indicate);
    stopIndicateText = getResources().getString(R.string.gatt_services_stop_indicate);
    UIbuttonvisibility();
    setHasOptionsMenu(true);
    /**
     * Check for HID Service
     */
    BluetoothGattService mBluetoothGattService = mReadCharacteristic.getService();
    if (mBluetoothGattService.getUuid().toString()
            .equalsIgnoreCase(GattAttributes.HUMAN_INTERFACE_DEVICE_SERVICE)) {
        showHIDWarningMessage();
    }
    Logger.i("Notification status---->" + mIsNotifyEnabled);
    return rootView;
}

From source file:biz.easymenu.easymenung.ReviewPlaceFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.reviewandplace, container, false);
    tlf = (TableLayout) v.findViewById(R.id.tableFixed);
    tlc = (TableLayout) v.findViewById(R.id.tableCarte);
    pbar = (ProgressBar) v.findViewById(R.id.pBarOrder);
    btnSend = (Button) v.findViewById(R.id.btnSend);
    btnSend.setOnClickListener(new View.OnClickListener() {

        @Override/* w w w.j a va  2  s.co  m*/
        public void onClick(View v) {

            FragmentManager fm = getActivity().getSupportFragmentManager();
            FragmentTransaction ft;
            ConfirmDialog f = new ConfirmDialog(getResources().getString(R.string.confirm) + "?",
                    getResources().getString(R.string.yes), getResources().getString(R.string.notyet),
                    new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            FragmentManager fm = getActivity().getSupportFragmentManager();
                            FragmentTransaction ft;
                            Fragment prev = fm.findFragmentByTag("confirmDialog");
                            ft = fm.beginTransaction();
                            if (prev != null) {
                                ft.remove(prev);
                                ft.commit();
                            }
                            pbar.setVisibility(View.VISIBLE);
                            new Thread(new SendOrderRun()).start();
                        }

                    }, new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            FragmentManager fm = getActivity().getSupportFragmentManager();
                            FragmentTransaction ft;
                            Fragment prev = fm.findFragmentByTag("confirmDialog");
                            ft = fm.beginTransaction();
                            if (prev != null) {
                                ft.remove(prev);
                                ft.commit();
                            }
                        }
                    });

            Fragment prev = fm.findFragmentByTag("confirmDialog");
            ft = fm.beginTransaction();
            if (prev != null) {
                ft.remove(prev);
                ft.commit();
            }
            f.show(ft, "confirmDialog");
        }
    });

    new Thread(new BillItemsRun()).start();
    return v;
}

From source file:com.cerema.cloud2.ui.activity.FileActivity.java

/**
 * Show loading dialog/*from  www .  j a  v  a 2  s  .  c o  m*/
 */
public void showLoadingDialog(String message) {
    // grant that only one waiting dialog is shown
    dismissLoadingDialog();
    // Construct dialog
    LoadingDialog loading = new LoadingDialog(message);
    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    loading.show(ft, DIALOG_WAIT_TAG);

}

From source file:com.dirkgassen.wator.ui.activity.MainActivity.java

/**
 * Shows the "new world" fragment if it was hidden.
 * @return {@code true} if the fragment was not visible; {@code false} otherwise
 *///from ww w.  j a v  a2 s.c om
synchronized private boolean showNewWorldFragment() {
    if (newWorldView.getVisibility() == View.GONE) {
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        Fragment newWorldFragment = new NewWorld();
        ft.add(R.id.new_world_fragment_container, newWorldFragment, NEW_WORLD_FRAGMENT_TAG);
        ft.commit();
        fm.executePendingTransactions();
        newWorldView.startAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_in_down));
        newWorldView.setVisibility(View.VISIBLE);
        return true;
    }
    return false;
}

From source file:com.androzic.MainActivity.java

private void selectItem(int position) {
    if (mDrawerAdapter.getSelectedItem() == position)
        return;/*from   w  ww  .  j  av  a  2s  . c  om*/

    DrawerItem item = mDrawerItems.get(position);
    // Actions
    if (item.type == DrawerItem.ItemType.INTENT) {
        if (position > 0)
            startActivity(item.intent);
    }
    // Fragments
    else if (item.type == DrawerItem.ItemType.FRAGMENT) {
        FragmentManager fm = getSupportFragmentManager();
        if (fm.getBackStackEntryCount() > 0) {
            fm.popBackStackImmediate(0, FragmentManager.POP_BACK_STACK_INCLUSIVE);
        }
        FragmentTransaction ft = fm.beginTransaction();
        Fragment parent = fm.findFragmentById(R.id.content_frame);
        if (parent != null) {
            ft.detach(parent);
        }
        Fragment fragment = fm.findFragmentByTag(item.name);
        if (fragment != null) {
            ft.attach(fragment);
        } else {
            ft.add(R.id.content_frame, item.fragment, item.name);
        }
        ft.commit();
        // update selected item and title, then close the drawer
        updateDrawerUI(item, position);
    } else if (item.type == DrawerItem.ItemType.ACTION) {
        Log.e(TAG, "ACTION");
        runOnUiThread(item.action);
    }
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:cc.softwarefactory.lokki.android.fragments.MapViewFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) { // This method guarantees that the fragment is loaded in the parent activity!

    Log.e(TAG, "onActivityCreated");
    super.onActivityCreated(savedInstanceState);

    FragmentManager fm = getChildFragmentManager();
    fragment = (SupportMapFragment) fm.findFragmentById(R.id.map);
    if (fragment == null) {
        fragment = SupportMapFragment.newInstance();
        //fragment = SupportMapFragment.newInstance(new GoogleMapOptions().useViewLifecycleInFragment(true)); // The map is destroyed when fragment is destroyed. Releasing memory
        fm.beginTransaction().replace(R.id.map, fragment).commit();
    }//from w  w  w  . j a  v  a  2s. c  om

    //setHasOptionsMenu(true);
}

From source file:com.andrada.sitracker.ui.fragment.PublicationInfoFragment.java

@Click(R.id.publication_rating_block)
void voteForPubClicked() {
    if (currentRecord != null && getActivity() != null) {
        AnalyticsHelper.getInstance().sendView(Constants.GA_SCREEN_RATING_DIALOG);
        FragmentManager fm = this.getActivity().getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        Fragment prev = fm.findFragmentByTag(RatePublicationDialog.FRAGMENT_TAG);
        if (prev != null) {
            ft.remove(prev);// w  w  w. j a v  a2 s.  c  o  m
        }
        ft.addToBackStack(null);
        RatePublicationDialog dg;
        if (currentRecord.getVoteDate() != null && !TextUtils.isEmpty(currentRecord.getVoteCookie())) {
            dg = RatePublicationDialog_.builder().publicationUrl(currentRecord.getUrl())
                    .currentRating(currentRecord.getMyVote()).votingCookie(currentRecord.getVoteCookie())
                    .build();
        } else {
            dg = RatePublicationDialog_.builder().publicationUrl(currentRecord.getUrl()).build();
        }
        dg.show(ft, AboutDialog.FRAGMENT_TAG);

    }
}

From source file:com.dirkgassen.wator.ui.activity.MainActivity.java

/**
 * Hides the "new world" fragment if it was showing.
 * @return {@code true} if the fragment was visible; {@code false} otherwise
 *//*from w  w w . j  a  va2s  .co m*/
synchronized private boolean hideNewWorldFragment() {
    if (newWorldView.getVisibility() != View.GONE) {
        Animation animation = AnimationUtils.loadAnimation(this, R.anim.slide_out_up);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                // Nothing to do here
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                FragmentManager fm = getSupportFragmentManager();
                Fragment fragment = fm.findFragmentByTag(NEW_WORLD_FRAGMENT_TAG);
                FragmentTransaction ft = fm.beginTransaction();
                ft.remove(fragment);
                ft.commit();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                // Nothing to do here
            }
        });
        newWorldView.startAnimation(animation);
        newWorldView.setVisibility(View.GONE);

        View viewWithFocus = getCurrentFocus();
        if (viewWithFocus != null) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(viewWithFocus.getWindowToken(), 0);
        }
        return true;
    }
    return false;
}

From source file:com.app.blockydemo.ui.fragment.FormulaEditorFragment.java

private void showFormulaEditorListFragment(String tag, int actionbarResId) {
    FragmentManager fragmentManager = ((FragmentActivity) context).getSupportFragmentManager();
    Fragment fragment = fragmentManager.findFragmentByTag(tag);

    if (fragment == null) {
        fragment = new FormulaEditorListFragment();
        Bundle bundle = new Bundle();
        bundle.putString(FormulaEditorListFragment.ACTION_BAR_TITLE_BUNDLE_ARGUMENT,
                context.getString(actionbarResId));
        bundle.putString(FormulaEditorListFragment.FRAGMENT_TAG_BUNDLE_ARGUMENT, tag);
        fragment.setArguments(bundle);//from   www  . j a va 2s.c  om
        fragmentManager.beginTransaction().add(R.id.script_fragment_container, fragment, tag).commit();
    }
    ((FormulaEditorListFragment) fragment).showFragment(context);
}

From source file:com.app.blockydemo.ui.fragment.FormulaEditorFragment.java

private void showFormulaEditorScriptListFragment(String tag, int actionbarResId) {
    FragmentManager fragmentManager = ((FragmentActivity) context).getSupportFragmentManager();
    Fragment fragment = fragmentManager.findFragmentByTag(tag);

    if (fragment == null) {
        fragment = new FormulaEditorScriptListFragment();
        Bundle bundle = new Bundle();
        bundle.putString(FormulaEditorScriptListFragment.ACTION_BAR_TITLE_BUNDLE_ARGUMENT,
                context.getString(actionbarResId));
        bundle.putString(FormulaEditorScriptListFragment.FRAGMENT_TAG_BUNDLE_ARGUMENT, tag);
        fragment.setArguments(bundle);//from   w w  w . j  a va 2s  . co m
        fragmentManager.beginTransaction().add(R.id.script_fragment_container, fragment, tag).commit();
    }
    ((FormulaEditorScriptListFragment) fragment).showFragment(context);
}