List of usage examples for android.app FragmentTransaction remove
public abstract FragmentTransaction remove(Fragment fragment);
From source file:com.android.deskclock.timer.TimerFullScreenFragment.java
private void onLabelPressed(TimerObj t) { final FragmentTransaction ft = getFragmentManager().beginTransaction(); final Fragment prev = getFragmentManager().findFragmentByTag("label_dialog"); if (prev != null) { ft.remove(prev); }/* ww w .j ava2s . co m*/ ft.addToBackStack(null); // Create and show the dialog. final LabelDialogFragment newFragment = LabelDialogFragment.newInstance(t, t.mLabel, getTag()); newFragment.show(ft, "label_dialog"); }
From source file:org.akvo.caddisfly.sensor.colorimetry.liquid.ColorimetryLiquidActivity.java
@Override public void onFinishDiagnosticResultDialog(boolean retry, boolean cancelled, String result, boolean isCalibration) { mResultFragment.dismiss();//www .j a va2 s .c o m if (mHighLevelsFound && !isCalibration) { mCameraFragment.dismiss(); sound.playShortResource(R.raw.beep_long); String title = CaddisflyApp.getApp().getCurrentTestInfo().getName(); String message; //todo: remove hard coding of dilution levels switch (mDilutionLevel) { case 0: message = String.format(getString(R.string.tryWithDilutedSample), 2); break; case 1: message = String.format(getString(R.string.tryWithDilutedSample), 5); break; default: message = EMPTY_STRING; } ResultDialogFragment mResultDialogFragment = ResultDialogFragment.newInstance(title, result, mDilutionLevel, message, CaddisflyApp.getApp().getCurrentTestInfo().getUnit()); final FragmentTransaction ft = getFragmentManager().beginTransaction(); Fragment fragment = getFragmentManager().findFragmentByTag(RESULT_DIALOG_TAG); if (fragment != null) { ft.remove(fragment); } mResultDialogFragment.setCancelable(false); mResultDialogFragment.show(ft, RESULT_DIALOG_TAG); } else if (retry) { mCameraFragment.dismiss(); initializeTest(); } else { releaseResources(); if (cancelled) { setResult(Activity.RESULT_CANCELED); } else { setResultIntent(); } finish(); } }
From source file:org.alfresco.mobile.android.application.fragments.browser.ChildrenBrowserFragment.java
public void createFolder() { FragmentTransaction ft = getFragmentManager().beginTransaction(); Fragment prev = getFragmentManager().findFragmentByTag(CreateFolderDialogFragment.TAG); if (prev != null) { ft.remove(prev); }/*from w w w.j a va2 s. c o m*/ ft.addToBackStack(null); // Create and show the dialog. AddFolderDialogFragment.newInstance(parentFolder).show(ft, CreateFolderDialogFragment.TAG); }
From source file:by.zatta.pilight.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { /*/*from w w w . ja va 2s . c o m*/ * The action bar home/up should open or close the drawer. ActionBarDrawerToggle will take care of this. */ publishList(); if (mDrawerToggle.onOptionsItemSelected(item)) { return true; } FragmentManager fm = getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); switch (item.getItemId()) { case R.id.menu_about: openDialogFragment(AboutDialog.newInstance()); return true; case R.id.menu_settings: Fragment pref = fm.findFragmentByTag("prefs"); if (pref == null) { ft.replace(R.id.fragment_main, new PrefFragment(), "prefs"); fm.popBackStack(); ft.addToBackStack(null); ft.commit(); } else { ft.remove(fm.findFragmentByTag("prefs")); ft.commit(); fm.popBackStack(); } return true; default: break; } // Handle your other action bar items... return super.onOptionsItemSelected(item); }
From source file:org.akvo.caddisfly.sensor.colorimetry.liquid.ColorimetryLiquidActivity.java
private void showResult(@NonNull byte[] data, double result, String resultText) { // Get the average color across the results int color = SwatchHelper.getAverageColor(mResults); // If calibrating then finish if successful if (mIsCalibration && color != Color.TRANSPARENT) { Intent resultIntent = new Intent(getIntent()); setResult(Activity.RESULT_OK, resultIntent); resultIntent.putExtra(SensorConstants.COLOR, color); sound.playShortResource(R.raw.done); PreferencesUtil.setInt(this, R.string.totalSuccessfulCalibrationsKey, PreferencesUtil.getInt(this, R.string.totalSuccessfulCalibrationsKey, 0) + 1); if (AppPreferences.isSaveImagesOn()) { saveImageForDiagnostics(data, resultText); }//from ww w . j a va 2s.c om if (AppPreferences.isDiagnosticMode()) { showDiagnosticResultDialog(false, resultText, color, true); } else { (new Handler()).postDelayed(new Runnable() { public void run() { finish(); } }, DELAY_MILLIS); } } else { // If no result then display error message if (result < 0 || color == Color.TRANSPARENT) { if (AppPreferences.isSaveImagesOn()) { saveImageForDiagnostics(data, resultText); } if (AppPreferences.isDiagnosticMode()) { sound.playShortResource(R.raw.err); PreferencesUtil.setInt(this, R.string.totalFailedTestsKey, PreferencesUtil.getInt(this, R.string.totalFailedTestsKey, 0) + 1); showDiagnosticResultDialog(true, EMPTY_STRING, color, mIsCalibration); } else { if (mIsCalibration) { showError(String.format(TWO_SENTENCE_FORMAT, getString(R.string.chamberNotFound), getString(R.string.checkChamberPlacement)), ImageUtil.getBitmap(data)); PreferencesUtil.setInt(this, R.string.totalFailedCalibrationsKey, PreferencesUtil.getInt(this, R.string.totalFailedCalibrationsKey, 0) + 1); } else { PreferencesUtil.setInt(this, R.string.totalFailedTestsKey, PreferencesUtil.getInt(this, R.string.totalFailedTestsKey, 0) + 1); showError(String.format(TWO_SENTENCE_FORMAT, getString(R.string.errorTestFailed), getString(R.string.checkChamberPlacement)), ImageUtil.getBitmap(data)); } } } else { if (AppPreferences.isSaveImagesOn()) { saveImageForDiagnostics(data, resultText); } if (AppPreferences.isDiagnosticMode()) { sound.playShortResource(R.raw.done); showDiagnosticResultDialog(false, resultText, color, false); PreferencesUtil.setInt(this, R.string.totalSuccessfulTestsKey, PreferencesUtil.getInt(this, R.string.totalSuccessfulTestsKey, 0) + 1); } else { String title = CaddisflyApp.getApp().getCurrentTestInfo().getName(); String message = EMPTY_STRING; if (mHighLevelsFound && mDilutionLevel < 2) { sound.playShortResource(R.raw.beep_long); switch (mDilutionLevel) { case 0: message = String.format(getString(R.string.tryWithDilutedSample), 2); break; case 1: message = String.format(getString(R.string.tryWithDilutedSample), 5); break; default: message = EMPTY_STRING; } } else { sound.playShortResource(R.raw.done); } PreferencesUtil.setInt(this, R.string.totalSuccessfulTestsKey, PreferencesUtil.getInt(this, R.string.totalSuccessfulTestsKey, 0) + 1); ResultDialogFragment mResultDialogFragment = ResultDialogFragment.newInstance(title, resultText, mDilutionLevel, message, CaddisflyApp.getApp().getCurrentTestInfo().getUnit()); final FragmentTransaction ft = getFragmentManager().beginTransaction(); Fragment fragment = getFragmentManager().findFragmentByTag(RESULT_DIALOG_TAG); if (fragment != null) { ft.remove(fragment); } mResultDialogFragment.setCancelable(false); mResultDialogFragment.show(ft, RESULT_DIALOG_TAG); } } } }
From source file:com.door43.translationstudio.ui.dialogs.BackupDialog.java
/** * this is to fix old method which when called in onResume() would create a * second dialog overlaying the first. The first was actually not removed. * Doing a commit after the remove() and starting a second FragmentTransaction * seems to fix the duplicate dialog bug. * * @param dialog/*from ww w .j ava 2 s . c om*/ * @param tag */ private void showDialogFragment(android.app.DialogFragment dialog, String tag) { FragmentTransaction backupFt = getFragmentManager().beginTransaction(); Fragment backupPrev = getFragmentManager().findFragmentByTag(tag); if (backupPrev != null) { backupFt.remove(backupPrev); backupFt.commit(); // apply the remove backupFt = getFragmentManager().beginTransaction(); // start a new transaction } backupFt.addToBackStack(null); dialog.show(backupFt, tag); }
From source file:org.akvo.caddisfly.sensor.colorimetry.liquid.ColorimetryLiquidActivity.java
private void startTest() { mResults = new ArrayList<>(); mWaitingForStillness = false;// w w w . j a v a 2 s . com mIsFirstResult = true; mShakeDetector.setMinShakeAcceleration(1); mShakeDetector.setMaxShakeDuration(MAX_SHAKE_DURATION_2); mSensorManager.registerListener(mShakeDetector, mAccelerometer, SensorManager.SENSOR_DELAY_UI); (new AsyncTask<Void, Void, Void>() { @Nullable @Override protected Void doInBackground(Void... params) { return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); mCameraFragment = CameraDialogFragment.newInstance(); mCameraFragment.setPictureTakenObserver(new CameraDialogFragment.PictureTaken() { @Override public void onPictureTaken(@NonNull byte[] bytes, boolean completed) { Bitmap bitmap = ImageUtil.getBitmap(bytes); Display display = getWindowManager().getDefaultDisplay(); int rotation; switch (display.getRotation()) { case Surface.ROTATION_0: rotation = DEGREES_90; break; case Surface.ROTATION_180: rotation = DEGREES_270; break; case Surface.ROTATION_270: rotation = DEGREES_180; break; case Surface.ROTATION_90: default: rotation = 0; break; } bitmap = ImageUtil.rotateImage(bitmap, rotation); TestInfo testInfo = CaddisflyApp.getApp().getCurrentTestInfo(); Bitmap croppedBitmap; if (testInfo.isUseGrayScale()) { croppedBitmap = ImageUtil.getCroppedBitmap(bitmap, ColorimetryLiquidConfig.SAMPLE_CROP_LENGTH_DEFAULT, false); if (croppedBitmap != null) { croppedBitmap = ImageUtil.getGrayscale(croppedBitmap); } } else { croppedBitmap = ImageUtil.getCroppedBitmap(bitmap, ColorimetryLiquidConfig.SAMPLE_CROP_LENGTH_DEFAULT, true); } //Ignore the first result as camera may not have focused correctly if (!mIsFirstResult) { if (croppedBitmap != null) { getAnalyzedResult(croppedBitmap); } else { showError( String.format(TWO_SENTENCE_FORMAT, getString(R.string.chamberNotFound), getString(R.string.checkChamberPlacement)), ImageUtil.getBitmap(bytes)); mCameraFragment.stopCamera(); mCameraFragment.dismiss(); return; } } mIsFirstResult = false; if (completed) { analyzeFinalResult(bytes, croppedBitmap); mCameraFragment.dismiss(); } else { sound.playShortResource(R.raw.beep); } } }); acquireWakeLock(); delayRunnable = new Runnable() { @Override public void run() { final FragmentTransaction ft = getFragmentManager().beginTransaction(); Fragment prev = getFragmentManager().findFragmentByTag("cameraDialog"); if (prev != null) { ft.remove(prev); } ft.addToBackStack(null); try { mCameraFragment.show(ft, "cameraDialog"); mCameraFragment.takePictures(AppPreferences.getSamplingTimes(), ColorimetryLiquidConfig.DELAY_BETWEEN_SAMPLING); } catch (Exception e) { Timber.e(e); finish(); } } }; delayHandler.postDelayed(delayRunnable, ColorimetryLiquidConfig.DELAY_BETWEEN_SAMPLING); } }).execute(); }
From source file:cz.metaverse.android.bilingualreader.ReaderActivity.java
/** * Remove panel, but don't close the application if no panel is left. *//*w ww . j av a2 s .c o m*/ public void removePanel(SplitPanel p) { Log.d(LOG, "ReaderActivity.removePanelWithoutClosing"); FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); fragmentTransaction.remove(p); fragmentTransaction.commit(); panelCount--; // Rethinks what menu items to display invalidateOptionsMenu(); }
From source file:com.hit.jj.mapshow.RoutingActivity.java
/** * Updates the UI after a successful rest response has been received. *///from w w w .j a v a 2 s .c o m void updateUI() { dialog.dismiss(); img_cancel.setVisibility(View.VISIBLE); FragmentManager fm = getFragmentManager(); if (fm.findFragmentByTag("Nav Drawer") == null) { FragmentTransaction ft = fm.beginTransaction(); RoutingListFragment frag = new RoutingListFragment(this); ft.add(frag, "Nav Drawer"); ft.commit(); } else { FragmentTransaction ft = fm.beginTransaction(); ft.remove(fm.findFragmentByTag("Nav Drawer")); RoutingListFragment frag = new RoutingListFragment(this); ft.add(frag, "Nav Drawer"); ft.commit(); } //img_showDirections.setVisibility(View.VISIBLE); }
From source file:com.orbar.pxdemo.ImageView.FivePXImageFragment.java
@Override public void onDestroyView() { Log.d(TAG, "onDestroyView"); super.onDestroyView(); Fragment fragment = (getFragmentManager().findFragmentById(R.id.map)); FragmentTransaction ft = getActivity().getFragmentManager().beginTransaction(); ft.remove(fragment); ft.commit();// www . j a v a2 s . c om }