List of usage examples for android.support.v4.app FragmentManager findFragmentById
public abstract Fragment findFragmentById(int id);
From source file:com.openatk.rockapp.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); dbHelper = new DatabaseHelper(this); FragmentManager fm = getSupportFragmentManager(); SupportMapFragment f = (SupportMapFragment) fm.findFragmentById(R.id.map); if (savedInstanceState == null) { // First incarnation of this activity. f.setRetainInstance(true);//from w w w .j a v a2 s . co m } else { // Reincarnated activity. The obtained map is the same map instance // in the previous // activity life cycle. There is no need to reinitialize it. map = f.getExtendedMap(); } checkGPS(); mCurrentRockSelected = Rock.BLANK_ROCK_ID; slideMenu = (RockMenu) findViewById(R.id.rock_edit_layout); slideMenu.setDBHelper(dbHelper); slideMenu.setListener(this); mapBroadcastReciever = new MapBroadcastReciever(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); mRockState = prefs.getInt("mRockState", STATE_ROCKS_NOT_PICKED_UP); // Restore state from savedInstanceState if (savedInstanceState != null) { mCurrentRockSelected = savedInstanceState.getInt("rock_edit.currentRock", Rock.BLANK_ROCK_ID); switch (savedInstanceState.getInt("state", STATE_DEFAULT)) { case STATE_ROCK_EDIT: // Get RockId and restore view states for setState() Log.d("MainActivity", "Editing rock:" + Integer.toString(mCurrentRockSelected)); SQLiteDatabase database = dbHelper.getReadableDatabase(); Rock theRock = Rock.getRockById(database, mCurrentRockSelected); database.close(); dbHelper.close(); theRock.setListener(this); slideMenu.editRock(theRock); break; } Log.d("MainActivity", "Startup State:" + Integer.toString(savedInstanceState.getInt("state", STATE_DEFAULT))); // Restore previous state setState(savedInstanceState.getInt("state", STATE_DEFAULT)); } else { // Otherwise set default initial state setState(STATE_DEFAULT); // TODO Zoom all markers (rocks) mRockState = STATE_ROCKS_NOT_PICKED_UP; } setUpMapIfNeeded(); }
From source file:com.example.android.honeypad.ui.HomeActivity.java
/** * This method controls both fragments, instructing them to display a * certain note./* w w w . j a v a2s. c o m*/ * * @param noteUri The {@link Uri} of the note to show. To create a new note, * pass {@code null}. */ private void showNote(final Uri noteUri) { if (mTwoPaneView) { // check if the NoteEditFragment has been added FragmentManager fm = getSupportFragmentManager(); NoteEditFragment edit = (NoteEditFragment) fm.findFragmentByTag(NOTE_EDIT_TAG); final boolean editNoteAdded = (edit != null); if (editNoteAdded) { if (edit.mCurrentNote != null && edit.mCurrentNote.equals(noteUri)) { // clicked on the currently selected note return; } NoteEditFragment editFrag = (NoteEditFragment) fm.findFragmentByTag(NOTE_EDIT_TAG); if (noteUri != null) { // load an existing note editFrag.loadNote(noteUri); NoteListFragment list = (NoteListFragment) fm.findFragmentById(R.id.list); list.setActivatedNote(Long.valueOf(noteUri.getLastPathSegment())); } else { // creating a new note - clear the form & list // activation if (editNoteAdded) { editFrag.clear(); } NoteListFragment list = (NoteListFragment) fm.findFragmentById(R.id.list); list.clearActivation(); } } else { // add the NoteEditFragment to the container FragmentTransaction ft = fm.beginTransaction(); edit = new NoteEditFragment(); ft.add(R.id.note_detail_container, edit, NOTE_EDIT_TAG); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.commit(); edit.loadNote(noteUri); } } else { startActivity(new Intent(NoteEditFragment.ACTION_VIEW_NOTE, noteUri)); } }
From source file:com.hubdub.meetr.activities.PickFriendsActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.pick_friends_activity); ParseObject.registerSubclass(Events.class); FragmentManager fm = getSupportFragmentManager(); if (savedInstanceState == null) { // First time through, we create our fragment programmatically. final Bundle args = getIntent().getExtras(); friendPickerFragment = new FriendPickerFragment(args); fm.beginTransaction().add(R.id.friend_picker_fragment, friendPickerFragment).commit(); } else {//from w w w. ja va2s. c o m // Subsequent times, our fragment is recreated by the framework and already has saved and // restored its state, so we don't need to specify args again. (In fact, this might be // incorrect if the fragment was modified programmatically since it was created.) friendPickerFragment = (FriendPickerFragment) fm.findFragmentById(R.id.friend_picker_fragment); } friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() { @Override public void onError(PickerFragment<?> fragment, FacebookException error) { PickFriendsActivity.this.onError(error); } }); // friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() { // @Override // public void onDoneButtonClicked(PickerFragment<?> fragment) { // // We just store our selection in the Application for other activities to look at. // MeetrApplication application = (MeetrApplication) getApplication(); // application.setSelectedUsers(friendPickerFragment.getSelection()); // setResult(RESULT_OK, null); // finish(); // } // }); }
From source file:com.nextgis.mobile.activity.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // initialize the default settings PreferenceManager.setDefaultValues(this, R.xml.preferences_general, false); PreferenceManager.setDefaultValues(this, R.xml.preferences_map, false); PreferenceManager.setDefaultValues(this, R.xml.preferences_location, false); PreferenceManager.setDefaultValues(this, R.xml.preferences_tracks, false); if (!mPreferences.getBoolean(SettingsConstants.KEY_PREF_INTRO, false)) { startActivity(new Intent(this, IntroActivity.class)); finish();// w ww. java 2 s. c om return; } setContentView(R.layout.activity_main); mMessageReceiver = new MessageReceiver(); mToolbar = (Toolbar) findViewById(R.id.main_toolbar); setSupportActionBar(mToolbar); if (null != getSupportActionBar()) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); } DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerLayout.setStatusBarBackgroundColor(ControlHelper.getColor(this, R.attr.colorPrimaryDark)); FragmentManager fm = getSupportFragmentManager(); mMapFragment = (MapFragment) fm.findFragmentById(R.id.map); mMapFragment.getUndoRedoOverlay().setTopToolbar(mToolbar); mMapFragment.getEditLayerOverlay().setTopToolbar(mToolbar); mMapFragment.getEditLayerOverlay().setBottomToolbar(getBottomToolbar()); MainApplication app = (MainApplication) getApplication(); mLayersFragment = (LayersFragment) fm.findFragmentById(R.id.layers); if (mLayersFragment != null && null != mLayersFragment.getView()) { mLayersFragment.getView().setBackgroundColor(ContextCompat.getColor(this, R.color.color_grey_050)); // Set up the drawer. mLayersFragment.setUp(R.id.layers, drawerLayout, (MapDrawable) app.getMap()); } LayerFillProgressDialogFragment progressFragment = (LayerFillProgressDialogFragment) fm .findFragmentByTag(TAG_FRAGMENT_PROGRESS); if (progressFragment == null) { progressFragment = new LayerFillProgressDialogFragment(); fm.beginTransaction().add(progressFragment, TAG_FRAGMENT_PROGRESS).commit(); } if (!hasPermissions()) { String[] permissions = new String[] { Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.GET_ACCOUNTS, Manifest.permission.WRITE_EXTERNAL_STORAGE }; requestPermissions(R.string.permissions, R.string.requested_permissions, PERMISSIONS_REQUEST, permissions); } ApkDownloader.check(this, false); }
From source file:com.bangz.shotrecorder.RecordActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_recorder); ActionBar bar = getSupportActionBar(); bar.setDisplayHomeAsUpEnabled(true); strModeNames = getResources().getStringArray(R.array.mode_names); strModeValNames = getResources().getStringArray(R.array.mode_value_names); mMode = MODE.COMSTOCK;// w ww . ja v a 2s. c om setDigitFont(); initButtonsListener(); TextView v = (TextView) findViewById(R.id.textTIME); v.setText("------"); FragmentManager fm = getSupportFragmentManager(); SplitListFragment splitfragment = (SplitListFragment) fm.findFragmentById(R.id.splitlist); mSplitAdapter = new SplitArrayAdapter(this, mSplitManager.getSplits()); splitfragment.setListAdapter(mSplitAdapter); if (savedInstanceState == null) { Intent intent = getIntent(); if (intent.getBooleanExtra(EXTRA_STARTFROMNOTIFY, false)) { mState = STATE_RECORDING; int mode = intent.getIntExtra(RecordService.EXTRA_MODE, 0); Log.d(TAG, "get mode in RecordActivity from service mode = " + mode); mMode = MODE.values()[mode]; mSampleRate = intent.getIntExtra(RecordService.EXTRA_SAMPLERATE, 44100); mChannels = intent.getIntExtra(RecordService.EXTRA_CHANNLES, AudioFormat.CHANNEL_IN_MONO); mEncoding = intent.getIntExtra(RecordService.EXTRA_ENCODDING, AudioFormat.ENCODING_PCM_16BIT); mMaxShots = intent.getIntExtra(RecordService.EXTRA_MAXSHOT, 0); mMaxParTime = intent.getIntExtra(RecordService.EXTRA_MAXPARTIME, 0) / 1000.0f; mCaptureSize = intent.getIntExtra(RecordService.EXTRA_CAPTURESIZE, 0); mMaxRecordTime = intent.getIntExtra(RecordService.EXTRA_MAXRECORDTIME, 5 * 60); } } updateMode(); updateStatus(); }
From source file:com.heinrichreimersoftware.materialdrawer.DrawerActivity.java
private void switchFragment(Fragment fragment) { FragmentManager fragmentManager = getSupportFragmentManager(); if (fragmentManager.findFragmentById(R.id.mdFrame) == fragment) return;// ww w .j ava 2 s . co m FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_NONE); if (fragmentManager.findFragmentById(R.id.mdFrame) != null) { fragmentTransaction.replace(R.id.mdFrame, fragment); } else { ((ViewGroup) findViewById(R.id.mdFrame)).removeAllViews(); fragmentTransaction.add(R.id.mdFrame, fragment); } fragmentTransaction.commit(); }
From source file:org.akop.crosswords.activity.SubscriptionActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FragmentManager fm = getSupportFragmentManager(); if (savedInstanceState == null) { fm.beginTransaction().add(R.id.container, new SubscriptionFragment()).commit(); } else {/*from w ww. java 2 s . c om*/ mTitle = savedInstanceState.getString("title"); mSubtitle = savedInstanceState.getString("subtitle"); } if (mTitle != null) { updateActionBar(); } Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() { @Override public void onBackStackChanged() { FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.container); if (fragment instanceof TitledFragment) { TitledFragment tf = (TitledFragment) fragment; mTitle = tf.getTitle(); mSubtitle = tf.getSubtitle(); updateActionBar(); } } }); }
From source file:org.appcelerator.titanium.util.TiUIHelper.java
public static FragmentTransaction transactionFragment(final Fragment fragment, final View container, final FragmentActivity activity) { FragmentManager manager = activity.getSupportFragmentManager(); Fragment tabFragment = manager.findFragmentById(android.R.id.tabcontent); // check if is opened inside an actionbar tab, which is // another fragment if (tabFragment != null) { manager = tabFragment.getChildFragmentManager(); }//from w ww . jav a 2 s . c o m FragmentTransaction transaction = null; transaction = manager.beginTransaction(); transaction.add(container.getId(), fragment); transaction.commit(); return transaction; }
From source file:org.appcelerator.titanium.util.TiUIHelper.java
public static FragmentTransaction removeFragment(final Fragment fragment, final View container, final FragmentActivity activity) { FragmentManager manager = activity.getSupportFragmentManager(); Fragment tabFragment = manager.findFragmentById(android.R.id.tabcontent); // check if is opened inside an actionbar tab, which is // another fragment if (tabFragment != null) { manager = tabFragment.getChildFragmentManager(); }/*from w w w .j a va2s. c om*/ FragmentTransaction transaction = null; transaction = manager.beginTransaction(); transaction.remove(fragment); transaction.commitAllowingStateLoss(); return transaction; }
From source file:in.co.madhur.mapmylocation.activity.PickFriendsActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.pick_friends_activity); FragmentManager fm = getSupportFragmentManager(); if (savedInstanceState == null) { // First time through, we create our fragment programmatically. final Bundle args = getIntent().getExtras(); friendPickerFragment = new FriendPickerFragment(args); fm.beginTransaction().add(R.id.friend_picker_fragment, friendPickerFragment).commit(); } else {/* ww w . j ava 2 s .com*/ // Subsequent times, our fragment is recreated by the framework and // already has saved and // restored its state, so we don't need to specify args again. (In // fact, this might be // incorrect if the fragment was modified programmatically since it // was created.) friendPickerFragment = (FriendPickerFragment) fm.findFragmentById(R.id.friend_picker_fragment); } friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() { @Override public void onError(PickerFragment<?> fragment, FacebookException error) { PickFriendsActivity.this.onError(error); } }); friendPickerFragment.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() { @Override public void onDoneButtonClicked(PickerFragment<?> fragment) { // We just store our selection in the Application for // other activities to look at. App application = (App) getApplication(); application.setSelectedUsers(friendPickerFragment.getSelection()); setResult(RESULT_OK, null); finish(); } }); }