Example usage for android.app FragmentTransaction commit

List of usage examples for android.app FragmentTransaction commit

Introduction

In this page you can find the example usage for android.app FragmentTransaction commit.

Prototype

public abstract int commit();

Source Link

Document

Schedules a commit of this transaction.

Usage

From source file:by.zatta.pilight.MainActivity.java

private void openFragment(BaseFragment mBaseFragment2) {
    Log.v(TAG, "openFragment");
    if (mBaseFragment2 != null) {
        FragmentManager fm = getFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        fm.popBackStack();/*w  w  w.ja  va 2s  .  com*/
        ft.replace(R.id.fragment_main, mBaseFragment2, mBaseFragment2.getName());
        ft.commit();
    }
}

From source file:rocks.stalin.android.app.ui.MusicPlayerActivity.java

private void navigateToBrowser(String mediaId) {
    Log.d(TAG, "navigateToBrowser, mediaId=" + mediaId);
    MediaBrowserFragment fragment = getBrowseFragment();

    if (fragment == null || !TextUtils.equals(fragment.getMediaId(), mediaId)) {
        fragment = new MediaBrowserFragment();
        fragment.setMediaId(mediaId);/*www .ja va  2s. co  m*/
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.setCustomAnimations(R.animator.slide_in_from_right, R.animator.slide_out_to_left,
                R.animator.slide_in_from_left, R.animator.slide_out_to_right);
        transaction.replace(R.id.container, fragment, FRAGMENT_TAG);
        // If this is not the top level media (root), we add it to the fragment back stack,
        // so that actionbar toggle and Back will work appropriately:
        if (mediaId != null) {
            transaction.addToBackStack(null);
        }
        transaction.commit();
    }
}

From source file:com.vst.functionframework.ui.SupportActivity.java

/**
 * Fragment?//w  w  w .  j av a2  s .c  o  m
 *
 * @param resView        ??
 * @param targetFragment ??Fragment
 */
public void changeFragment(int resView, SupportFragment targetFragment) {
    if (targetFragment.equals(currentSupportFragment)) {
        return;
    }
    android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    if (!targetFragment.isAdded()) {
        transaction.add(resView, targetFragment, targetFragment.getClass().getName());
    }
    if (targetFragment.isHidden()) {
        transaction.show(targetFragment);
        targetFragment.onChange();
    }
    if (currentSupportFragment != null && currentSupportFragment.isVisible()) {
        transaction.hide(currentSupportFragment);
    }
    currentSupportFragment = targetFragment;
    transaction.commit();
}

From source file:com.prasanna.android.stacknetwork.QuestionActivity.java

private void displayPostCommentFragment(String title, long id, int viewPagerPosition, String fragmentTag,
        String defaultText) {//  ww  w .j a v a2 s. com
    postCommentFragment = new PostCommentFragment();
    postCommentFragment.setPostId(id);
    postCommentFragment.setViewPagerPosition(viewPagerPosition);
    postCommentFragment.setTitle(title);
    postCommentFragment.setResultReceiver(resultReceiver);

    if (commentsDraft.get(fragmentTag) != null)
        postCommentFragment.setDraftText(commentsDraft.get(fragmentTag));

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.fragmentContainer, postCommentFragment, fragmentTag);
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    transaction.addToBackStack(fragmentTag);
    transaction.commit();
}

From source file:com.example.sans.myapplication.Utility.MainActivity.java

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

    shares = getSharedPreferences("SHARES", 0);

    Client client = new Client();

    loc_array = "";

    RequestParams params = new RequestParams();
    params.put("id", shares.getInt("ID", -1));
    params.put("loc_array", loc_array);

    client.addHeader("Authorization", shares.getString("ACCESS_TOKEN", ""));

    client.post("driver/updateLocation", params, new JsonHttpResponseHandler());

    Fragment newFragment = new OrderListFragment();
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.frame, newFragment);
    transaction.addToBackStack(null);/*from   w  w w. j  a v  a 2  s. co m*/
    transaction.commit();

    LocationRequest lr = LocationRequest.create();
    lr.setInterval(1000);
    lr.setFastestInterval(500);
    lr.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    stored_locations = new ArrayList<Location>();

    controller = (AppController) getApplication();

    controller.startGetStatus();
    controller.startAquireOrder();

    // Initializing Toolbar and setting it as the actionbar
    toolbar = (Toolbar) findViewById(R.id.toolbar);

    order_num = (TextView) toolbar.findViewById(R.id.order_num);

    order_num.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            nav = true;
            Intent i = new Intent(MainActivity.this, MenuItemActivity.class);
            i.putExtra("MENU_ITEM", R.id.timetable);
            MainActivity.this.startActivity(i);
        }
    });

    toolbar.findViewById(R.id.toolbar_calendar).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            nav = true;
            Intent i = new Intent(MainActivity.this, MenuItemActivity.class);
            i.putExtra("MENU_ITEM", R.id.timetable);
            MainActivity.this.startActivity(i);
        }
    });
    setSupportActionBar(toolbar);

    //Initializing NavigationView
    navigationView = (NavigationView) findViewById(R.id.navigation_view);

    //Location
    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    ll = new myLocationListener();

    startLocationUpdates();

    //Setting Navigation View Item Selected Listener to handle the item click of the navigation menu

    header = navigationView.inflateHeaderView(R.layout.header);
    JSONObject driver_data = null;
    try {
        driver_data = new JSONObject(shares.getString("DRIVER_DATA", "ERROR"));
    } catch (JSONException e) {
        e.printStackTrace();
    }

    TextView driver_name_header = (TextView) header.findViewById(R.id.username);
    TextView car_id_header = (TextView) header.findViewById(R.id.car_id);
    final ImageView pp_header = (ImageView) header.findViewById(R.id.profile_image);

    try {
        car_id_header.setText(driver_data.getString("license"));
        driver_name_header.setText(driver_data.getString("name"));
        client = new Client();
        client.get(driver_data.getString("image"),
                new FileAsyncHttpResponseHandler(MainActivity.this.getApplicationContext()) {
                    @Override
                    public void onFailure(int i, Header[] headers, Throwable throwable, File file) {

                    }

                    @Override
                    public void onSuccess(int statusCode, Header[] headers, final File response) {

                        MainActivity.this.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Bitmap image = BitmapFactory.decodeFile(response.getPath());

                                pp_header.setImageBitmap(image);

                            }
                        });

                    }

                });
    } catch (JSONException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
        SharedPreferences.Editor editor = shares.edit();

        final Client client1 = new Client();
        RequestParams params1 = new RequestParams();

        editor.putBoolean("ONLINE", false);
        editor.putBoolean("LOGIN", false);
        editor.commit();
        Intent intent = getApplicationContext().getPackageManager()
                .getLaunchIntentForPackage(getApplicationContext().getPackageName());
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
    }

    header.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent i = new Intent(MainActivity.this, MenuItemActivity.class);
            i.putExtra("MENU_ITEM", 0);
            MainActivity.this.startActivity(i);
            drawerLayout.closeDrawers();
        }
    });

    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {

        // This method will trigger on item Click of navigation menu
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {

            //Checking if the item is in checked state or not, if not make it in checked state

            nav = true;

            menuItem.setChecked(false);

            //Closing drawer on item click
            drawerLayout.closeDrawers();

            FragmentManager fragmentManager = getFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            Fragment fragment;
            //Check to see which item was being clicked and perform appropriate action
            switch (menuItem.getItemId()) {
            case R.id.timetable:
            case R.id.service:
            case R.id.history:
            case R.id.mission:
            case R.id.points:
            case R.id.notice:
                Intent i = new Intent(MainActivity.this, MenuItemActivity.class);
                i.putExtra("MENU_ITEM", menuItem.getItemId());
                MainActivity.this.startActivity(i);
                break;
            case R.id.login:
                Toast.makeText(getApplicationContext(), "Logout Selected", Toast.LENGTH_SHORT).show();
                SharedPreferences.Editor editor = shares.edit();

                final Client client = new Client();
                RequestParams params = new RequestParams();
                params.put("id", shares.getInt("ID", 0));
                params.put("status", 999);
                client.post("driver/setStatus", params, new JsonHttpResponseHandler());

                editor.putBoolean("ONLINE", false);
                editor.putBoolean("LOGIN", false);
                editor.commit();
                Intent intent = getApplicationContext().getPackageManager()
                        .getLaunchIntentForPackage(getApplicationContext().getPackageName());
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
                break;
            default:
                Toast.makeText(getApplicationContext(), "Somethings Wrong", Toast.LENGTH_SHORT).show();
                break;

            }
            return false;
        }
    });

    // Initializing Drawer Layout and ActionBarToggle
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer);
    ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar,
            R.string.openDrawer, R.string.closeDrawer) {

        @Override
        public void onDrawerClosed(View drawerView) {
            // Code here will be triggered once the drawer closes as we dont want anything to happen so we leave this blank
            super.onDrawerClosed(drawerView);
            drawerLayout.setSelected(false);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            // Code here will be triggered once the drawer open as we dont want anything to happen so we leave this blank

            super.onDrawerOpened(drawerView);
        }
    };

    //Setting the actionbarToggle to drawer layout
    drawerLayout.setDrawerListener(actionBarDrawerToggle);

    //calling sync state is necessay or else your hamburger icon wont show up
    actionBarDrawerToggle.syncState();

}

From source file:by.zatta.pilight.MainActivity.java

@Override
public void onLanguageListener(String language) {
    makeLocale(language);//w  ww  .  j  av  a 2s .  c  om
    invalidateOptionsMenu();
    initMenu();
    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    fm.popBackStack();
    ft.replace(R.id.fragment_main, new PrefFragment(), "prefs");
    ft.addToBackStack(null);
    ft.commit();
}

From source file:itcr.gitsnes.MainActivity.java

public void add_games(MenuItem item) {
    AddGame new_fragment = new AddGame();
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.placeholder, new_fragment);
    transaction.addToBackStack(null);//from  ww w. j a v  a2 s  .  co  m
    transaction.commit();

    RelativeLayout rl = (RelativeLayout) this.findViewById(R.id.mainback);
    rl.setBackgroundColor(Color.parseColor("#0099cc"));
    authButton.setVisibility(View.INVISIBLE);

}

From source file:itcr.gitsnes.MainActivity.java

public void advanced_query(MenuItem item) {

    SearchFrame new_fragment = new SearchFrame();
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.placeholder, new_fragment);
    transaction.addToBackStack(null);//  w  ww  .j  a  va2s . com
    transaction.commit();

    RelativeLayout rl = (RelativeLayout) this.findViewById(R.id.mainback);
    rl.setBackgroundColor(Color.parseColor("#ff8800"));
    authButton.setVisibility(View.INVISIBLE);

}

From source file:com.prasanna.android.stacknetwork.QuestionActivity.java

private void showCommentFragment(long postId, ArrayList<Comment> comments) {
    String fragmentTag = postId + "-" + StringConstants.COMMENTS;
    commentFragment = findFragmentByTag(fragmentTag, CommentFragment.class);

    if (commentFragment == null) {
        commentFragment = new CommentFragment();
        commentFragment.setComments(comments);
        commentFragment.setResultReceiver(resultReceiver);

        String currentViewPagerFragmentTag = "android:switcher:" + R.id.viewPager + ":"
                + viewPager.getCurrentItem();

        OnCommentChangeListener onCommentChangeListener = (OnCommentChangeListener) getFragmentManager()
                .findFragmentByTag(currentViewPagerFragmentTag);

        if (onCommentChangeListener != null)
            commentFragment.setOnCommentChangeListener(onCommentChangeListener);
    }//from  w w  w  .  j  a  v a2  s  .co  m

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.fragmentContainer, commentFragment, fragmentTag);
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    transaction.addToBackStack(fragmentTag);
    transaction.commit();
}

From source file:com.bayapps.android.robophish.ui.MusicPlayerActivity.java

private void navigateToBrowser(String title, String subtitle, String mediaId) {
    LogHelper.d(TAG, "navigateToBrowser, mediaId=" + mediaId);
    MediaBrowserFragment fragment = getBrowseFragment();

    if (fragment == null || !TextUtils.equals(fragment.getMediaId(), mediaId)) {
        fragment = new MediaBrowserFragment();
        fragment.setMediaId(title, subtitle, mediaId);
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.setCustomAnimations(R.animator.slide_in_from_right, R.animator.slide_out_to_left,
                R.animator.slide_in_from_left, R.animator.slide_out_to_right);
        transaction.replace(R.id.container, fragment, FRAGMENT_TAG);
        // If this is not the top level media (root), we add it to the fragment back stack,
        // so that actionbar toggle and Back will work appropriately:
        if (mediaId != null) {
            transaction.addToBackStack(null);
        }//from   w  w  w  .ja  va  2  s  . c  o  m
        transaction.commit();
    }
}