List of usage examples for android.support.v4.app FragmentManager beginTransaction
public abstract FragmentTransaction beginTransaction();
From source file:com.app.blockydemo.ui.fragment.FormulaEditorFragment.java
private void showFormulaEditorVariableListFragment(String tag, int actionbarResId) { FragmentManager fragmentManager = ((FragmentActivity) context).getSupportFragmentManager(); Fragment fragment = fragmentManager.findFragmentByTag(tag); if (fragment == null) { fragment = new FormulaEditorVariableListFragment(); Bundle bundle = new Bundle(); bundle.putString(FormulaEditorVariableListFragment.ACTION_BAR_TITLE_BUNDLE_ARGUMENT, context.getString(actionbarResId)); bundle.putString(FormulaEditorVariableListFragment.FRAGMENT_TAG_BUNDLE_ARGUMENT, tag); fragment.setArguments(bundle);// w w w. j ava 2 s. c om fragmentManager.beginTransaction().add(R.id.script_fragment_container, fragment, tag).commit(); } ((FormulaEditorVariableListFragment) fragment).setAddButtonListener(getActivity()); ((FormulaEditorVariableListFragment) fragment).showFragment(context); }
From source file:com.android.test.uibench.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent();/* w w w . j av a 2s . c om*/ String path = intent.getStringExtra(EXTRA_PATH); if (path == null) { path = ""; } else { // not root level, display where we are in the hierarchy setTitle(path); } FragmentManager fm = getSupportFragmentManager(); if (fm.findFragmentById(android.R.id.content) == null) { ListFragment listFragment = new ListFragment() { @Override @SuppressWarnings("unchecked") public void onListItemClick(ListView l, View v, int position, long id) { Map<String, Object> map = (Map<String, Object>) l.getItemAtPosition(position); Intent intent = (Intent) map.get("intent"); startActivity(intent); } @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); getListView().setTextFilterEnabled(true); } }; listFragment.setListAdapter(new SimpleAdapter(this, getData(path), android.R.layout.simple_list_item_1, new String[] { "title" }, new int[] { android.R.id.text1 })); fm.beginTransaction().add(android.R.id.content, listFragment).commit(); } }
From source file:appathon.history.PickerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.pickers);/* w w w . ja va2s . c o m*/ Bundle args = getIntent().getExtras(); FragmentManager manager = getSupportFragmentManager(); Fragment fragmentToShow = null; if (savedInstanceState == null) { friendPickerFragment = new FriendPickerFragment(args); friendPickerFragment.setFriendPickerType(FriendPickerFragment.FriendPickerType.TAGGABLE_FRIENDS); } else { friendPickerFragment = (FriendPickerFragment) manager.findFragmentById(R.id.picker_fragment); ; } friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() { @Override public void onError(PickerFragment<?> fragment, FacebookException error) { PickerActivity.this.onError(error); } }); friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() { @Override public void onDoneButtonClicked(PickerFragment<?> fragment) { finishActivity(); } }); fragmentToShow = friendPickerFragment; manager.beginTransaction().replace(R.id.picker_fragment, fragmentToShow).commit(); }
From source file:com.androzic.MainActivity.java
@Override public void addFragment(Fragment fragment, String tag) { FragmentManager fm = getSupportFragmentManager(); // Get topmost fragment Fragment parent;/*from w w w . j a va2 s .c om*/ if (fm.getBackStackEntryCount() > 0) { FragmentManager.BackStackEntry bse = fm.getBackStackEntryAt(fm.getBackStackEntryCount() - 1); parent = fm.findFragmentByTag(bse.getName()); } else { parent = fm.findFragmentById(R.id.content_frame); } FragmentTransaction ft = fm.beginTransaction(); // Detach parent ft.detach(parent); // Add new fragment to back stack ft.add(R.id.content_frame, fragment, tag); ft.addToBackStack(tag); ft.commit(); }
From source file:com.cypress.cysmart.CommonFragments.ProfileScanningFragment.java
private void prepareSensorHubData(List<BluetoothGattService> gattServices) { boolean mGattSet = false; boolean mSensorHubSet = false; if (gattServices == null) return;/*from www . j a v a2 s . c om*/ // Clear all array list before entering values. gattServiceData.clear(); gattServiceMasterData.clear(); gattServiceSensorHubData.clear(); // Loops through available GATT Services. for (BluetoothGattService gattService : gattServices) { HashMap<String, BluetoothGattService> currentServiceData = new HashMap<String, BluetoothGattService>(); String uuid = gattService.getUuid().toString(); // Optimization code for SensorHub Profile if (uuid.equalsIgnoreCase(GattAttributes.LINK_LOSS_SERVICE) || uuid.equalsIgnoreCase(GattAttributes.TRANSMISSION_POWER_SERVICE) || uuid.equalsIgnoreCase(GattAttributes.IMMEDIATE_ALERT_SERVICE) || uuid.equalsIgnoreCase(GattAttributes.BAROMETER_SERVICE) || uuid.equalsIgnoreCase(GattAttributes.ACCELEROMETER_SERVICE) || uuid.equalsIgnoreCase(GattAttributes.ANALOG_TEMPERATURE_SERVICE) || uuid.equalsIgnoreCase(GattAttributes.BATTERY_SERVICE) || uuid.equalsIgnoreCase(GattAttributes.DEVICE_INFORMATION_SERVICE)) { currentServiceData.put(LIST_UUID, gattService); gattServiceMasterData.add(currentServiceData); if (!gattServiceSensorHubData.contains(currentServiceData)) { gattServiceSensorHubData.add(currentServiceData); } if (!mSensorHubSet && uuid.equalsIgnoreCase(GattAttributes.BAROMETER_SERVICE)) { mSensorHubSet = true; gattServiceData.add(currentServiceData); } } // Optimization code for GATTDB else if (uuid.equalsIgnoreCase(GattAttributes.GENERIC_ACCESS_SERVICE) || uuid.equalsIgnoreCase(GattAttributes.GENERIC_ATTRIBUTE_SERVICE)) { currentServiceData.put(LIST_UUID, gattService); gattdbServiceData.add(currentServiceData); if (!mGattSet) { mGattSet = true; gattServiceData.add(currentServiceData); } } else { currentServiceData.put(LIST_UUID, gattService); gattServiceMasterData.add(currentServiceData); gattServiceData.add(currentServiceData); } } application.setGattServiceMasterData(gattServiceMasterData); application.setGattServiceData(gattServiceData); // All service discovered and optimized.Dismiss the alert dialog if (gattdbServiceData.size() > 0) { mConnectHandler.removeCallbacksAndMessages(null); if (mpdia != null && mpdia.isShowing()) { mpdia.dismiss(); } /** * Setting the handler flag to false. adding new fragment * ProfileControlFragment to the view */ HANDLER_FLAG = false; if (receiverEnabled) { getActivity().unregisterReceiver(mGattUpdateReceiver); receiverEnabled = false; FragmentManager fragmentManager = getFragmentManager(); ProfileControlFragment profileControlFragment = new ProfileControlFragment().create(mDeviceName, mDeviceAddress); fragmentManager.beginTransaction() .add(R.id.container, profileControlFragment, Constants.PROFILE_CONTROL_FRAGMENT_TAG) .addToBackStack(null).commit(); } } }
From source file:com.cypress.cysmart.CommonFragments.ProfileScanningFragment.java
/** * Prepare GATTServices data./*from w ww . jav a2 s. c om*/ * * @param gattServices */ private void prepareData(List<BluetoothGattService> gattServices) { boolean mFindmeSet = false; boolean mProximitySet = false; boolean mGattSet = false; if (gattServices == null) return; // Clear all array list before entering values. gattServiceData.clear(); gattServiceFindMeData.clear(); gattServiceMasterData.clear(); // Loops through available GATT Services. for (BluetoothGattService gattService : gattServices) { HashMap<String, BluetoothGattService> currentServiceData = new HashMap<String, BluetoothGattService>(); String uuid = gattService.getUuid().toString(); // Optimization code for FindMe Profile if (uuid.equalsIgnoreCase(GattAttributes.IMMEDIATE_ALERT_SERVICE)) { currentServiceData.put(LIST_UUID, gattService); gattServiceMasterData.add(currentServiceData); if (!gattServiceFindMeData.contains(currentServiceData)) { gattServiceFindMeData.add(currentServiceData); } if (!mFindmeSet) { mFindmeSet = true; gattServiceData.add(currentServiceData); } } // Optimization code for Proximity Profile else if (uuid.equalsIgnoreCase(GattAttributes.LINK_LOSS_SERVICE) || uuid.equalsIgnoreCase(GattAttributes.TRANSMISSION_POWER_SERVICE)) { currentServiceData.put(LIST_UUID, gattService); gattServiceMasterData.add(currentServiceData); if (!gattServiceProximityData.contains(currentServiceData)) { gattServiceProximityData.add(currentServiceData); } if (!mProximitySet) { mProximitySet = true; gattServiceData.add(currentServiceData); } } // Optimization code for GATTDB else if (uuid.equalsIgnoreCase(GattAttributes.GENERIC_ACCESS_SERVICE) || uuid.equalsIgnoreCase(GattAttributes.GENERIC_ATTRIBUTE_SERVICE)) { currentServiceData.put(LIST_UUID, gattService); gattdbServiceData.add(currentServiceData); if (!mGattSet) { mGattSet = true; gattServiceData.add(currentServiceData); } } else { currentServiceData.put(LIST_UUID, gattService); gattServiceMasterData.add(currentServiceData); gattServiceData.add(currentServiceData); } } application.setGattServiceData(gattServiceData); application.setGattServiceMasterData(gattServiceMasterData); // All service discovered and optimized.Dismiss the alert dialog if (gattdbServiceData.size() > 0) { mConnectHandler.removeCallbacksAndMessages(null); if (mpdia != null && mpdia.isShowing()) { mpdia.dismiss(); } /** * Setting the handler flag to false. adding new fragment * ProfileControlFragment to the view */ HANDLER_FLAG = false; if (receiverEnabled) { Logger.e("unregisterReceiver---->"); getActivity().unregisterReceiver(mGattUpdateReceiver); receiverEnabled = false; FragmentManager fragmentManager = getFragmentManager(); ProfileControlFragment profileControlFragment = new ProfileControlFragment().create(mDeviceName, mDeviceAddress); fragmentManager.beginTransaction() .add(R.id.container, profileControlFragment, Constants.PROFILE_CONTROL_FRAGMENT_TAG) .addToBackStack(null).commit(); } } }
From source file:com.cypress.cysmart.CommonFragments.ProfileScanningFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. switch (item.getItemId()) { case R.id.log: // DataLogger File file = new File(Environment.getExternalStorageDirectory() + File.separator + "CySmart" + File.separator + Utils.GetDate() + ".txt"); String path = file.getAbsolutePath(); Bundle bundle = new Bundle(); bundle.putString(Constants.DATA_LOGGER_FILE_NAAME, path); bundle.putBoolean(Constants.DATA_LOGGER_FLAG, false); /**//ww w . j a va2 s . co m * Adding new fragment DataLoggerFragment to the view */ FragmentManager fragmentManager = getFragmentManager(); Fragment currentFragment = fragmentManager.findFragmentById(R.id.container); DataLoggerFragment dataloggerfragment = new DataLoggerFragment().create(currentFragment.getTag()); dataloggerfragment.setArguments(bundle); fragmentManager.beginTransaction().add(R.id.container, dataloggerfragment).addToBackStack(null) .commit(); return true; case R.id.share: // Share HomePageActivity.containerView.invalidate(); View v1 = getActivity().getWindow().getDecorView().getRootView(); Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); String temporaryPath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "CySmart" + File.separator + "file.jpg"; File filetoshare = new File(temporaryPath); if (filetoshare.exists()) { filetoshare.delete(); } try { filetoshare.createNewFile(); Utils.screenShotMethod(v1); Logger.i("temporaryPath>" + temporaryPath); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(temporaryPath))); shareIntent.setType("image/jpg"); startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to))); } catch (IOException e) { e.printStackTrace(); } return true; case R.id.clearcache: showWarningMessage(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.appybite.customer.AllowedHotels.java
public void removeFragment(Fragment fg) { if (fg == null) return;/* w ww . j a v a2s . co m*/ FragmentManager fm = getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.remove(fg); ft.commit(); }
From source file:com.appybite.customer.AllowedHotels.java
public void addFragment(Fragment fg) { if (fg == null) return;/*from w w w .j a v a 2 s .co m*/ FragmentManager fm = getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.setCustomAnimations(R.anim.fade_short, R.anim.hold); ft.add(R.id.fl_fragment_corner, fg); ft.commit(); }
From source file:com.appybite.customer.AllowedHotels.java
public void showFragment(Fragment fg) { if (fg == null) return;/* w w w . ja v a 2 s .co m*/ FragmentManager fm = getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.setCustomAnimations(R.anim.fade_short, R.anim.hold); ft.show(fg); ft.commit(); }