Example usage for android.app FragmentTransaction replace

List of usage examples for android.app FragmentTransaction replace

Introduction

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

Prototype

public abstract FragmentTransaction replace(@IdRes int containerViewId, Fragment fragment);

Source Link

Document

Calls #replace(int,Fragment,String) with a null tag.

Usage

From source file:com.android.calendar.SearchActivity.java

private void showEventInfo(EventInfo event) {
    if (mShowEventDetailsWithAgenda) {
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction ft = fragmentManager.beginTransaction();

        mEventInfoFragment = new EventInfoFragment(this, event.id, event.startTime.toMillis(false),
                event.endTime.toMillis(false), event.getResponse(), false,
                EventInfoFragment.DIALOG_WINDOW_STYLE, null /* No reminders to explicitly pass in. */);
        ft.replace(R.id.agenda_event_info, mEventInfoFragment);
        ft.commit();/*from  ww  w  .j a  v a  2  s.c o  m*/
    } else {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, event.id);
        intent.setData(eventUri);
        intent.setClass(this, EventInfoActivity.class);
        intent.putExtra(EXTRA_EVENT_BEGIN_TIME, event.startTime != null ? event.startTime.toMillis(true) : -1);
        intent.putExtra(EXTRA_EVENT_END_TIME, event.endTime != null ? event.endTime.toMillis(true) : -1);
        startActivity(intent);
    }
    mCurrentEventId = event.id;
}

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);// w  w w.j a  v  a  2 s .  c  o  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:itcr.gitsnes.MainActivity.java

/** Inflates mainFrame/ListView with the next params from advanced_search layout:
 *      - name: if name isn't null// www. j a v  a  2 s .  c o m
 *      - category: if category is different to empty
 */
public void searching(View view) {
    EditText name = (EditText) this.findViewById(R.id.src_name);
    EditText category = (EditText) this.findViewById(R.id.src_category);

    MasterGames new_fragment = new MasterGames(json_arr);
    new_fragment.setQname(name.getText().toString());
    new_fragment.setQcat(category.getText().toString());

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

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.placeholder, new_fragment);
    transaction.addToBackStack(null);
    transaction.commit();

}

From source file:itcr.gitsnes.MainActivity.java

public void goList(MenuItem item) {
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);//from ww w.j a  v  a2s  .c om
    String input = new BackendHandler().readJSON();
    try {
        json_arr = new JSONArray(input);
    } catch (JSONException e) {
        Log.i(TAG, e.toString());
    }

    RelativeLayout rl = (RelativeLayout) this.findViewById(R.id.mainback);
    rl.setBackgroundColor(Color.parseColor("#009f28"));
    authButton.setVisibility(View.INVISIBLE);
    MasterGames new_fragment = new MasterGames(json_arr);
    new_fragment.setQtype("all");

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.placeholder, new_fragment);
    transaction.addToBackStack(null);
    transaction.commit();

}

From source file:itcr.gitsnes.MainActivity.java

/**
 *  Method to go mainFrame/*from  ww  w. j ava  2 s . c o m*/
 */
public void back_stage() {
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    String input = new BackendHandler().readJSON();
    try {
        json_arr = new JSONArray(input);
    } catch (JSONException e) {
        Log.i(TAG, e.toString());
        Log.i(TAG, e.toString());
    }

    RelativeLayout rl = (RelativeLayout) this.findViewById(R.id.mainback);
    rl.setBackgroundColor(Color.parseColor("#009f28"));
    authButton.setVisibility(View.INVISIBLE);
    MasterGames new_fragment = new MasterGames(json_arr);
    new_fragment.setQtype("all");

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.placeholder, new_fragment);
    transaction.addToBackStack(null);
    transaction.commit();

}

From source file:itcr.gitsnes.MainActivity.java

public void adminMenu(MenuItem item) {

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);/*  w w  w  .j  a  v a  2s .  c  o m*/
    String input = new BackendHandler().readJSON();
    try {
        json_arr = new JSONArray(input);
    } catch (JSONException e) {
        Log.i(TAG, e.toString());
    }

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

    AdminFrame new_fragment = new AdminFrame(json_arr);
    new_fragment.setQtype("all");

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.placeholder, new_fragment);
    transaction.addToBackStack(null);
    transaction.commit();

}

From source file:itcr.gitsnes.MainActivity.java

/** Create a frame with the favorites games of the user
 * call moreliked GET method *///from  w  w w.  j a va 2  s .c o  m
public void getFavorites(MenuItem item) {
    /* Async mode*/
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    /* Build json*/
    String input = new BackendHandler().getFavorites();
    try {
        json_arr = new JSONArray(input);
    } catch (JSONException e) {
        Log.i(TAG, e.toString());
    }
    /* Commit fragment transaction (master view)*/
    RelativeLayout rl = (RelativeLayout) this.findViewById(R.id.mainback);
    rl.setBackgroundColor(Color.parseColor("#70d4b0"));
    authButton.setVisibility(View.INVISIBLE);
    MasterGames new_fragment = new MasterGames(json_arr);
    new_fragment.setQtype("all");

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.placeholder, new_fragment);
    transaction.addToBackStack(null);
    transaction.commit();
}

From source file:itcr.gitsnes.MainActivity.java

/** Create a frame with the favorites games of the user
 * call recomended GET method *//*from  w w w. j a  v  a  2  s .  c  o m*/
public void getRecomended(MenuItem item) {
    /* Async mode*/
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    /* Build json*/
    String input = new BackendHandler().get_Recommended(new KeyStore().getCurrent_user());
    try {
        json_arr = new JSONArray(input);
    } catch (JSONException e) {
        Log.i(TAG, e.toString());
    }
    /* Commit fragment transaction (master view)*/
    RelativeLayout rl = (RelativeLayout) this.findViewById(R.id.mainback);
    rl.setBackgroundColor(Color.parseColor("#e7df00"));
    authButton.setVisibility(View.INVISIBLE);
    MasterGames new_fragment = new MasterGames(json_arr);
    new_fragment.setQtype("all");

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.placeholder, new_fragment);
    transaction.addToBackStack(null);
    transaction.commit();

}

From source file:com.ithinkbest.taipeiok.NavigationDrawerActivity.java

private void selectItem(int position) {
    // update the main content by replacing fragments
    Fragment fragment = TaipeiFragment.newInstance(position);

    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction ft = fragmentManager.beginTransaction();
    ft.replace(R.id.content_frame, fragment);
    ft.commit();//from  ww  w .  j  a va 2s .c  o m

    // update selected item title, then close the drawer
    setTitle(mPlanetTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:cmput301.f13t01.readstory.ReadFragmentActivity.java

/**
 * Using a fragment manager, this function creates and commits a new
 * ReadFragmentView fragment to be displayed for this view. This replaces
 * whatever the old fragment is, thus giving the readers a new view on the
 * new content.//from  w w w .  j a  va2 s .c  o  m
 * 
 * @param storyId
 *            the UUID of the story
 * @param fragmentId
 *            the story fragment to be displayed
 */
public void commitFragment(Integer fragmentId) {
    if (fragmentId == null) {
        return;
    }

    this.fragmentId = fragmentId;
    // prepare for the fragment
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    // prepare bundle to pass arguments
    Bundle bundle = new Bundle();
    bundle.putInt(getResources().getString(R.string.destination_id), fragmentId);

    // create the fragment and pass the bundle to the fragment
    ReadFragmentView newFragment = new ReadFragmentView();
    newFragment.setArguments(bundle);
    fragmentTransaction.replace(R.id.read_fragment_activity, newFragment);
    fragmentTransaction.commit();
}