List of usage examples for android.support.v4.app FragmentManager findFragmentById
public abstract Fragment findFragmentById(int id);
From source file:org.dmfs.webcal.fragments.CalendarItemFragment.java
@Override public View onCreateItemView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View returnView = inflater.inflate(R.layout.fragment_calendar_item, container, false); // TODO: don't put the progress indicator into the header view View progressView = inflater.inflate(R.layout.progress_indicator, null, false); mProgressBar = (ProgressBar) progressView.findViewById(android.R.id.progress); mListView = (ListView) returnView.findViewById(android.R.id.list); mListView.addHeaderView(progressView); mListView.setOnItemClickListener(this); mListView.setHeaderDividersEnabled(false); mListAdapter = new EventListAdapter(inflater.getContext(), null); mListView.setAdapter(mSectionAdapter = new SectionTitlesAdapter(inflater.getContext(), mListAdapter, new SectionIndexer() { @Override//from www .j a va 2 s. c o m public String getSectionTitle(int index) { Time start = new Time(TimeZone.getDefault().getID()); start.set(index & 0x00ff, (index >> 8) & 0x00ff, (index >> 16) & 0x0ffff); return DateUtils.formatDateTime(getActivity(), start.toMillis(true), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_ABBREV_WEEKDAY); } @Override public int getSectionIndex(Object object) { Cursor cursor = (Cursor) object; Time start = new Time( cursor.getString(cursor.getColumnIndex(WebCalReaderContract.Events.TIMZONE))); start.set(cursor.getLong(cursor.getColumnIndex(WebCalReaderContract.Events.DTSTART))); boolean allday = cursor .getInt(cursor.getColumnIndex(WebCalReaderContract.Events.IS_ALLDAY)) == 1; start.allDay = allday; // we return an encoded date as index return (start.year << 16) + (start.month << 8) + start.monthDay; } }, R.layout.events_preview_list_section_header)); FragmentManager fm = getChildFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); mTitleFragment = (CalendarTitleFragment) fm.findFragmentById(R.id.calendar_title_fragment_container); if (mTitleFragment == null) { mTitleFragment = CalendarTitleFragment.newInstance(); ft.replace(R.id.calendar_title_fragment_container, mTitleFragment); } if (!ft.isEmpty()) { ft.commit(); } LoaderManager lm = getLoaderManager(); lm.initLoader(LOADER_CALENDAR_ITEM, null, this); lm.initLoader(LOADER_SUBSCRIBED_CALENDAR, null, this); lm.initLoader(LOADER_SUBSCRIPTION, null, this); // set this to true, so the menu is cleared automatically when leaving the fragment, otherwise the star icon will stay visible setHasOptionsMenu(true); return returnView; }
From source file:com.latenight.testapp.PickFriendsActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); 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 {/*from w ww. j av a 2 s . 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. FingerBangerApplication application = (FingerBangerApplication) getApplication(); Log.d("Users", "Setting Selected Users"); application.setSelectedUsers(friendPickerFragment.getSelection()); setResult(RESULT_OK, null); finish(); } }); }
From source file:net.bither.activity.hot.NetworkMonitorActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); overridePendingTransition(R.anim.slide_in_right, 0); setContentView(R.layout.network_monitor_content); // final ActionBar actionBar = getSupportActionBar(); // actionBar.setDisplayHomeAsUpEnabled(true); final ViewPager pager = (ViewPager) findViewById(R.id.network_monitor_pager); final FragmentManager fm = getSupportFragmentManager(); if (pager != null) { final ViewPagerTabs pagerTabs = (ViewPagerTabs) findViewById(R.id.network_monitor_pager_tabs); pagerTabs.addTabLabels(R.string.network_monitor_peer_list_title, R.string.network_monitor_block_list_title); final PagerAdapter pagerAdapter = new PagerAdapter(fm); pager.setAdapter(pagerAdapter);//from w w w . j a v a2 s. c o m pager.setOnPageChangeListener(pagerTabs); pager.setPageMargin(2); pager.setPageMarginDrawable(R.color.bg); peerListFragment = new PeerListFragment(); blockListFragment = new BlockListFragment(); } else { peerListFragment = (PeerListFragment) fm.findFragmentById(R.id.peer_list_fragment); blockListFragment = (BlockListFragment) fm.findFragmentById(R.id.block_list_fragment); } // flTitleBar = (FrameLayout) findViewById(R.id.fl_title_bar); ibtnBack = (ImageButton) findViewById(R.id.ibtn_back); ibtnBack.setOnClickListener(new IBackClickListener()); }
From source file:com.example.it3197_casestudy.ui_logic.PickFriendsActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); 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 {//from w ww. j a va2 s .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. FriendPickerApplication application = (FriendPickerApplication) getApplication(); application.setSelectedUsers(friendPickerFragment.getSelection()); setResult(RESULT_OK, null); finish(); } }); }
From source file:cc.mintcoin.wallet.ui.NetworkMonitorActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.network_monitor_content); final ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); final ViewPager pager = (ViewPager) findViewById(R.id.network_monitor_pager); final FragmentManager fm = getSupportFragmentManager(); if (pager != null) { final ViewPagerTabs pagerTabs = (ViewPagerTabs) findViewById(R.id.network_monitor_pager_tabs); pagerTabs.addTabLabels(R.string.network_monitor_peer_list_title, R.string.network_monitor_block_list_title); final PagerAdapter pagerAdapter = new PagerAdapter(fm); pager.setAdapter(pagerAdapter);//from www .jav a 2 s . c o m pager.setOnPageChangeListener(pagerTabs); pager.setPageMargin(2); pager.setPageMarginDrawable(R.color.bg_less_bright); peerListFragment = new PeerListFragment(); blockListFragment = new BlockListFragment(); } else { peerListFragment = (PeerListFragment) fm.findFragmentById(R.id.peer_list_fragment); blockListFragment = (BlockListFragment) fm.findFragmentById(R.id.block_list_fragment); } }
From source file:com.mybitcoin.wallet.ui.NetworkMonitorActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.network_monitor_content); /*final ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true);*/ final ViewPager pager = (ViewPager) findViewById(R.id.network_monitor_pager); final FragmentManager fm = getSupportFragmentManager(); if (pager != null) { final ViewPagerTabs pagerTabs = (ViewPagerTabs) findViewById(R.id.network_monitor_pager_tabs); pagerTabs.addTabLabels(R.string.network_monitor_peer_list_title, R.string.network_monitor_block_list_title); final PagerAdapter pagerAdapter = new PagerAdapter(fm); pager.setAdapter(pagerAdapter);/*from w w w . j a v a 2s.co m*/ pager.setOnPageChangeListener(pagerTabs); pager.setPageMargin(2); pager.setPageMarginDrawable(R.color.bg_less_bright); peerListFragment = new PeerListFragment(); blockListFragment = new BlockListFragment(); } else { peerListFragment = (PeerListFragment) fm.findFragmentById(R.id.peer_list_fragment); blockListFragment = (BlockListFragment) fm.findFragmentById(R.id.block_list_fragment); } }
From source file:com.bangz.shotrecorder.RecordActivity.java
private void OnMessageLaps(Message msg) { if (msg.arg1 == RecordService.EVENT_ARRIVED) { if (mService != null) { try { Message msgreturn = Message.obtain(null, RecordService.MSG_LAPS, mSplitManager.getNumbers(), 0); msgreturn.replyTo = mMessenger; mService.send(msgreturn); } catch (RemoteException e) { }/*from ww w. j a v a 2 s . c o m*/ } } else { long[] events = (long[]) msg.obj; for (long e : events) { mSplitManager.append(e); mSplitAdapter.notifyDataSetChanged(); FragmentManager fm = getSupportFragmentManager(); SplitListFragment splitfragment = (SplitListFragment) fm.findFragmentById(R.id.splitlist); splitfragment.getListView().smoothScrollToPosition(mSplitManager.getNumbers() - 1); mbModified = true; } mCurrentSplitIndex = mSplitManager.getNumbers() - 1; UpdateCurrentSplitView(mCurrentSplitIndex); SetShareIntent(); } }
From source file:com.lancefluger.activitys.PickFriendsActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); 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 {//from w w w .j av a2 s . 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.setOnSelectionChangedListener(new PickerFragment.OnSelectionChangedListener() { public void onSelectionChanged(PickerFragment<?> fragment) { //Return if two friends are chosen since this is tic-tac-toe if (friendPickerFragment.getSelection().size() == 2) { // We just store our selection in the Application for other activities to look at. FriendPickerApplication application = (FriendPickerApplication) getApplication(); application.setSelectedUsers(friendPickerFragment.getSelection()); setResult(RESULT_OK, null); finish(); } } }); // Facebook fragment has done button, reconsider its usage 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. FriendPickerApplication application = (FriendPickerApplication) getApplication(); application.setSelectedUsers(friendPickerFragment.getSelection()); setResult(RESULT_OK, null); finish(); } }); }
From source file:com.ultramegasoft.flavordex2.fragment.EntrySearchFragment.java
/** * Set the category to search.//from w w w . j a v a 2 s . co m */ private void setCategory() { final FragmentManager fm = getChildFragmentManager(); final CatListAdapter.Category cat = (CatListAdapter.Category) mSpnCat.getSelectedItem(); final Bundle args = getArguments(); if (fm.findFragmentById(R.id.search_form) != null && (args != null ? args.getLong(ARG_CAT_ID, -1) : -1) == cat.id) { return; } if (args != null) { args.putLong(ARG_CAT_ID, cat.id); } final Fragment fragment; switch (cat.name) { case FlavordexApp.CAT_BEER: fragment = new BeerSearchFormFragment(); break; case FlavordexApp.CAT_COFFEE: fragment = new CoffeeSearchFormFragment(); break; case FlavordexApp.CAT_WHISKEY: fragment = new WhiskeySearchFormFragment(); break; case FlavordexApp.CAT_WINE: fragment = new WineSearchFormFragment(); break; default: fragment = new SearchFormFragment(); } fragment.setArguments(args); fm.beginTransaction().replace(R.id.search_form, fragment).commit(); }
From source file:at.fhooe.mcm.saap.facebook.HelloFacebookSampleActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); locationClient = new LocationClient(this, this, this); if (savedInstanceState != null) { String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY); pendingAction = PendingAction.valueOf(name); }/*w w w. j av a2 s . c om*/ setContentView(R.layout.main); loginButton = (LoginButton) findViewById(R.id.login_button); // loginButton.setFragment(this); loginButton.setReadPermissions(Arrays.asList("user_location", "user_birthday", "user_likes,", "user_interests", "user_activities", "user_friends", "user_actions.books")); loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() { @Override public void onUserInfoFetched(GraphUser user) { HelloFacebookSampleActivity.this.user = user; updateUI(); // It's possible that we were waiting for this.user to // be populated in order to post a // status update. handlePendingAction(); } }); profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture); greeting = (TextView) findViewById(R.id.greeting); userTextView = (TextView) findViewById(R.id.userTextView); queryInterestsButton = (Button) findViewById(R.id.queryInterests); queryInterestsButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickQueryActivities(); } }); showActivitiesButton = (Button) findViewById(R.id.showActivities); showActivitiesButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickShowActivities(); } }); pickFriendsButton = (Button) findViewById(R.id.pickFriendsButton); pickFriendsButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickPickFriends(); } }); pickPlaceButton = (Button) findViewById(R.id.pickPlaceButton); pickPlaceButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickPickPlace(); } }); controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container); final FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.fragment_container); if (fragment != null) { // If we're being re-created and have a fragment, we need to a) hide // the main UI controls and // b) hook up its listeners again. controlsContainer.setVisibility(View.GONE); if (fragment instanceof FriendPickerFragment) { setFriendPickerListeners((FriendPickerFragment) fragment); } else if (fragment instanceof PlacePickerFragment) { setPlacePickerListeners((PlacePickerFragment) fragment); } } // Listen for changes in the back stack so we know if a fragment got // popped off because the user // clicked the back button. fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() { @Override public void onBackStackChanged() { if (fm.getBackStackEntryCount() == 0) { // We need to re-show our UI. controlsContainer.setVisibility(View.VISIBLE); } } }); // Can we present the share dialog for regular links? canPresentShareDialog = FacebookDialog.canPresentShareDialog(this, FacebookDialog.ShareDialogFeature.SHARE_DIALOG); // Can we present the share dialog for photos? canPresentShareDialogWithPhotos = FacebookDialog.canPresentShareDialog(this, FacebookDialog.ShareDialogFeature.PHOTOS); // init database if not initialized if (db == null) { //add activities db = new SQLiteHelper(getApplicationContext()); } }